Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update API call to use inventory V2 #5196

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ const fetchCollectorPluginUpdate = async (): Promise<CollectorModel> => {
version: collectorFormState.version,
upgrade_mode: collectorFormState.autoUpgrade ? 'AUTO' : 'MANUAL',
};
return SpaceConnector.clientV2.inventory.collector.updatePlugin<CollectorUpdatePluginParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.updatePlugin<CollectorUpdatePluginParameters, CollectorModel>(params);
};
const fetchCollectorUpdate = async (): Promise<CollectorModel> => {
if (!collectorFormState.collectorId) throw new Error('collector_id is required');
const params: CollectorUpdateParameters = {
collector_id: collectorFormState.collectorId,
tags: collectorFormState.tags,
};
return SpaceConnector.clientV2.inventory.collector.update<CollectorUpdateParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.update<CollectorUpdateParameters, CollectorModel>(params);
};
const getRepositoryPlugin = async (pluginId: string) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const handleClickCreateButton = async () => {
exclude_service_accounts: collectorFormState.serviceAccounts,
};
Object.assign(params.secret_filter ?? {}, serviceAccountParams);
const res:CollectorModel = await SpaceConnector.clientV2.inventory.collector.create<CollectorCreateParameters, CollectorModel>(params);
const res:CollectorModel = await SpaceConnector.clientV2.inventoryV2.collector.create<CollectorCreateParameters, CollectorModel>(params);
state.createdCollectorId = res?.collector_id;
state.visibleCreateCompleteModal = true;
showSuccessMessage(i18n.t('INVENTORY.COLLECTOR.CREATE.ALT_S_CREATE_COLLECTOR'), '');
Expand All @@ -166,7 +166,7 @@ const handleConfirmCreateCollector = async () => {
state.collectLoading = true;
// After the collector created, if the user clicks the collect button, the collector will be executed.
if (state.createdCollectorId) {
await SpaceConnector.clientV2.inventory.collector.collect<CollectorCollectParameters, JobModel>({
await SpaceConnector.clientV2.inventoryV2.collector.collect<CollectorCollectParameters, JobModel>({
collector_id: state.createdCollectorId,
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const handleClickConfirm = async () => {

state.loading = true;
try {
await SpaceConnector.clientV2.inventory.collector.collect<CollectorCollectParameters, JobModel>({
await SpaceConnector.clientV2.inventoryV2.collector.collect<CollectorCollectParameters, JobModel>({
collector_id: collectorDataModalState.selectedCollector.collector_id,
secret_id: collectorDataModalState.selectedSecret?.secret_id,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const fetchUpdateCollectorName = async (): Promise<CollectorModel> => {
collector_id: collectorFormState.collectorId,
name: collectorFormState.name,
};
return SpaceConnector.clientV2.inventory.collector.update<CollectorUpdateParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.update<CollectorUpdateParameters, CollectorModel>(params);
};

const handleUpdateIsValid = (value: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const fetchCollectorPluginUpdate = async (): Promise<CollectorModel> => {
collector_id: collectorFormState.collectorId,
options: collectorFormState.options,
};
return SpaceConnector.clientV2.inventory.collector.updatePlugin<CollectorUpdatePluginParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.updatePlugin<CollectorUpdatePluginParameters, CollectorModel>(params);
};
const handleClickEdit = () => {
state.isEditMode = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const fetchCollectorUpdate = async (): Promise<CollectorModel> => {
hours: collectorFormState.scheduleHours,
},
};
return SpaceConnector.clientV2.inventory.collector.update<CollectorUpdateParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.update<CollectorUpdateParameters, CollectorModel>(params);
};

const handleClickEdit = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const fetchCollectorUpdate = async (): Promise<CollectorModel> => {
service_accounts: [],
};
Object.assign(params.secret_filter ?? {}, serviceAccountParams);
return SpaceConnector.clientV2.inventory.collector.update<CollectorUpdateParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.update<CollectorUpdateParameters, CollectorModel>(params);
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>
<p-json-schema-form :schema="state.schema"
:form-data="collectorFormState.options"
:language="$store.state.user.language"
:language="state.language"
use-fixed-menu-style
reset-on-schema-change
uniform-width
Expand Down Expand Up @@ -76,6 +76,8 @@ import type {
GetPluginMetadataResponse,
} from '@/schema/plugin/plugin/api-verbs/get-plugin-metadata';

import { useUserStore } from '@/store/user/user-store';

import ErrorHandler from '@/common/composables/error/errorHandler';

import { red } from '@/styles/colors';
Expand All @@ -87,6 +89,7 @@ import {

const collectorFormStore = useCollectorFormStore();
const collectorFormState = collectorFormStore.state;
const userStore = useUserStore();

const props = defineProps<{
hasMetadata?: boolean; // MEMO: if true, use metadata(state.schema) of collectorFormState.originCollector. And if false, call api for get metadata(state.schema).
Expand All @@ -101,6 +104,7 @@ const state = reactive({
isLoadFailed: false,
pluginId: computed<string|undefined>(() => collectorFormState.repositoryPlugin?.plugin_id),
schema: null as null|JsonSchema|object,
language: computed<string|undefined>(() => userStore.state.language),
});

const fetchGetPluginMetadata = (provider: string|undefined): Promise<GetPluginMetadataResponse> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const fetchCollectorUpdate = async (): Promise<CollectorModel> => {
state: collectorFormState.schedulePower ? 'ENABLED' : 'DISABLED',
},
};
return SpaceConnector.clientV2.inventory.collector.update<CollectorUpdateParameters, CollectorModel>(params);
return SpaceConnector.clientV2.inventoryV2.collector.update<CollectorUpdateParameters, CollectorModel>(params);
};

const handleChangeToggle = async (value: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const handleChange = async (options: any = {}) => {
const getJobTasks = async () => {
state.loading = true;
try {
const res = await SpaceConnector.clientV2.inventory.jobTask.list<JobTaskListParameters, ListResponse<JobTaskModel>>({
const res = await SpaceConnector.clientV2.inventoryV2.jobTask.list<JobTaskListParameters, ListResponse<JobTaskModel>>({
query: getQuery(),
job_id: props.jobId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type { ServiceAccountModel } from '@/schema/identity/service-account/mode
import type { TrustedAccountModel } from '@/schema/identity/trusted-account/model';
import { i18n } from '@/translations';

import { useUserStore } from '@/store/user/user-store';

import type { Tag } from '@/common/components/forms/tags-input-group/type';
import TagsInput from '@/common/components/inputs/TagsInput.vue';
import { useFormValidator } from '@/common/composables/form-validator';
Expand All @@ -34,6 +36,7 @@ const props = withDefaults(defineProps<Props>(), {
mode: 'CREATE',
});

const userStore = useUserStore();
const serviceAccountPageStore = useServiceAccountPageStore();
const serviceAccountPageGetters = serviceAccountPageStore.getters;

Expand Down Expand Up @@ -85,6 +88,7 @@ const state = reactive({
&& (serviceAccountPageGetters.isTrustedAccount ? true : (state.isProjectFormValid || state.originForm?.projectForm?.selectedProjectId))
&& state.isTagsValid
&& (isEmpty(props.schema) ? true : state.isCustomSchemaFormValid))),
language: computed<string|undefined>(() => userStore.state.language),
});

/* Util */
Expand Down Expand Up @@ -166,7 +170,7 @@ watch(() => state.originForm, (originForm) => {
class="p-json-schema-form"
:form-data.sync="state.customSchemaForm"
:schema="props.schema"
:language="$store.state.user.language"
:language="state.language"
@validate="handleAccountValidate"
/>
<p-field-group v-if="!serviceAccountPageGetters.isTrustedAccount"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const apiQuery = new ApiQueryHelper();
const getJob = async () => {
try {
apiQuery.setFilters([{ k: 'job_id', v: props.jobId, o: '=' }]);
const { results } = await SpaceConnector.clientV2.inventory.job.list({
const { results } = await SpaceConnector.clientV2.inventoryV2.job.list({
query: apiQuery.data,
});
state.job = results[0] || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ defineExpose({ setPathFrom });
const getCollector = async (): Promise<CollectorModel|null> => {
state.loading = true;
try {
return await SpaceConnector.clientV2.inventory.collector.get<CollectorGetParameters, CollectorModel>({
return await SpaceConnector.clientV2.inventoryV2.collector.get<CollectorGetParameters, CollectorModel>({
collector_id: props.collectorId,
});
} catch (e) {
Expand All @@ -156,7 +156,7 @@ const getCollector = async (): Promise<CollectorModel|null> => {
}
};

const fetchDeleteCollector = async () => (collectorFormState.collectorId ? SpaceConnector.clientV2.inventory.collector.delete<CollectorDeleteParameters>({
const fetchDeleteCollector = async () => (collectorFormState.collectorId ? SpaceConnector.clientV2.inventoryV2.collector.delete<CollectorDeleteParameters>({
collector_id: collectorFormState.collectorId,
}) : undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const handleChangePagination = () => {
const getJobs = async () => {
state.loading = true;
try {
const res = await SpaceConnector.clientV2.inventory.job.list<JobListParameters, ListResponse<JobModel>>({ query: getQuery() });
const res = await SpaceConnector.clientV2.inventoryV2.job.list<JobListParameters, ListResponse<JobModel>>({ query: getQuery() });
state.totalCount = res.total_count ?? 0;
state.items = (res.results ?? []).map((job) => {
const collector = storeState.collectors[job.collector_id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const handleSelectedProvider = (providerName: string) => {
const collectorCountApiQueryHelper = new ApiQueryHelper().setCountOnly();
const fetchCollectorCount = async () => {
try {
const { total_count } = await SpaceConnector.clientV2.inventory.collector.list<CollectorListParameters, ListResponse<CollectorModel>>({
const { total_count } = await SpaceConnector.clientV2.inventoryV2.collector.list<CollectorListParameters, ListResponse<CollectorModel>>({
query: collectorCountApiQueryHelper.data,
});
state.hasCollectorList = (total_count ?? 0) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useAppContextStore } from '@/store/app-context/app-context-store';
import { useAllReferenceStore } from '@/store/reference/all-reference-store';
import type { ProviderReferenceMap } from '@/store/reference/provider-reference-store';
import type { TrustedAccountReferenceMap } from '@/store/reference/trusted-account-reference-store';
import { useUserStore } from '@/store/user/user-store';

import { showSuccessMessage } from '@/lib/helper/notice-alert-helper';

Expand All @@ -50,6 +51,7 @@ const serviceAccountSchemaStore = useServiceAccountSchemaStore();
const serviceAccountPageStore = useServiceAccountPageStore();
const serviceAccountPageFormState = serviceAccountPageStore.formState;
const appContextStore = useAppContextStore();
const userStore = useUserStore();

const props = defineProps<{
provider?: string;
Expand All @@ -61,6 +63,7 @@ const allReferenceStore = useAllReferenceStore();
const storeState = reactive({
providers: computed<ProviderReferenceMap>(() => allReferenceStore.getters.provider),
trustedAccounts: computed<TrustedAccountReferenceMap>(() => allReferenceStore.getters.trustedAccount),
language: computed<string|undefined>(() => userStore.state.language),
});

const state = reactive({
Expand Down Expand Up @@ -261,7 +264,7 @@ const handleRouteToServiceAccountDetailPage = () => {
<template #contents>
<p-markdown :markdown="state.description"
:data="state.description"
:language="$store.state.user.language"
:language="storeState.language"
class="!p-0"
/>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const apiQuery = new ApiQueryHelper();
const getJob = async () => {
try {
apiQuery.setFilters([{ k: 'job_id', v: props.jobId, o: '=' }]);
const { results } = await SpaceConnector.clientV2.inventory.job.list({
const { results } = await SpaceConnector.clientV2.inventoryV2.job.list({
query: apiQuery.data,
});
state.job = results[0] || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ defineExpose({ setPathFrom });
const getCollector = async (): Promise<CollectorModel|null> => {
state.loading = true;
try {
return await SpaceConnector.clientV2.inventory.collector.get<CollectorGetParameters, CollectorModel>({
return await SpaceConnector.clientV2.inventoryV2.collector.get<CollectorGetParameters, CollectorModel>({
collector_id: props.collectorId,
});
} catch (e) {
Expand All @@ -239,7 +239,7 @@ const getCollector = async (): Promise<CollectorModel|null> => {
}
};

const fetchDeleteCollector = async () => (collectorFormState.collectorId ? SpaceConnector.clientV2.inventory.collector.delete<CollectorDeleteParameters>({
const fetchDeleteCollector = async () => (collectorFormState.collectorId ? SpaceConnector.clientV2.inventoryV2.collector.delete<CollectorDeleteParameters>({
collector_id: collectorFormState.collectorId,
}) : undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const handleChangePagination = () => {
const getJobs = async () => {
state.loading = true;
try {
const res = await SpaceConnector.clientV2.inventory.job.list<JobListParameters, ListResponse<JobModel>>({ query: getQuery() });
const res = await SpaceConnector.clientV2.inventoryV2.job.list<JobListParameters, ListResponse<JobModel>>({ query: getQuery() });
state.totalCount = res.total_count ?? 0;
state.items = (res.results ?? []).map((job) => {
const collector = storeState.collectors[job.collector_id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const handleSelectedProvider = (providerName: string) => {
const collectorCountApiQueryHelper = new ApiQueryHelper().setCountOnly();
const fetchCollectorCount = async () => {
try {
const { total_count } = await SpaceConnector.clientV2.inventory.collector.list<CollectorListParameters, ListResponse<CollectorModel>>({
const { total_count } = await SpaceConnector.clientV2.inventoryV2.collector.list<CollectorListParameters, ListResponse<CollectorModel>>({
query: collectorCountApiQueryHelper.data,
});
state.hasCollectorList = (total_count ?? 0) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const useCollectorDataModalStore = defineStore('collector-data-modal', {
async getJobs(collectorId: string) {
this.initLoading = true;
try {
const { results } = await SpaceConnector.clientV2.inventory.job.list<JobListParameters, ListResponse<JobModel>>({ collector_id: collectorId });
const { results } = await SpaceConnector.clientV2.inventoryV2.job.list<JobListParameters, ListResponse<JobModel>>({ collector_id: collectorId });
if ((results ?? []).length > 0 && results) {
if (this.selectedSecret) {
const filteredJobs = results.filter((job) => job.secret_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useCollectorDetailPageStore = defineStore('page-collector-detail',
const action = {
fetchCollector: async (collectorId: string) => {
try {
state.collector = await SpaceConnector.clientV2.inventory.collector.get<CollectorGetParameters, CollectorModel>({
state.collector = await SpaceConnector.clientV2.inventoryV2.collector.get<CollectorGetParameters, CollectorModel>({
collector_id: collectorId,
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const useCollectorJobStore = defineStore('collector-job', {
allJobsCountQueryHelper.setFilters([
{ k: 'collector_id', v: this.collector.collector_id, o: '=' },
]);
const { total_count } = await SpaceConnector.clientV2.inventory.job.list({
const { total_count } = await SpaceConnector.clientV2.inventoryV2.job.list({
query: allJobsCountQueryHelper.data,
});
this.allJobsCount = total_count ?? 0;
Expand All @@ -65,7 +65,7 @@ export const useCollectorJobStore = defineStore('collector-job', {
{ k: 'collector_id', v: this.collector.collector_id, o: '=' },
{ k: 'created_at', v: fiveDaysAgo, o: '>' },
]);
const { results } = await SpaceConnector.clientV2.inventory.job.list<JobListParameters, ListResponse<JobModel>>({
const { results } = await SpaceConnector.clientV2.inventoryV2.job.list<JobListParameters, ListResponse<JobModel>>({
query: jobQueryHelper.data,
});
this.recentJobs = results ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useCollectorPageStore = defineStore('page-collector', () => {
},
async getCollectorJobs(ids) {
try {
const { results } = await SpaceConnector.clientV2.inventory.job.analyze({
const { results } = await SpaceConnector.clientV2.inventoryV2.job.analyze({
query: {
filter: [
{
Expand Down Expand Up @@ -123,15 +123,15 @@ export const useCollectorPageStore = defineStore('page-collector', () => {
},
async getJobs() {
try {
const res = await SpaceConnector.clientV2.inventory.job.list();
const res = await SpaceConnector.clientV2.inventoryV2.job.list();
state.recentJobs = res.results;
} catch (e) {
ErrorHandler.handleError(e);
}
},
async updateCollectorSchedule(params) {
try {
const response = await SpaceConnector.clientV2.inventory.collector.update<CollectorUpdateParameters, CollectorModel>(params);
const response = await SpaceConnector.clientV2.inventoryV2.collector.update<CollectorUpdateParameters, CollectorModel>(params);
const updatedCollectorIndex = state.collectors.findIndex((collector) => collector.collector_id === response.collector_id);
state.collectors[updatedCollectorIndex] = response;
showSuccessMessage(i18n.t('INVENTORY.COLLECTOR.ALT_S_UPDATE_SCHEDULE'), '');
Expand Down
Loading
Loading