mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 00:01:48 +08:00

* CloudMigrations: Create resource dependency map to validate snapshot request * CloudMigrations: Validate resource types dependencies in create snapshot request * CloudMigrations: Update service interface to pass parsed resource types for creation * CloudMigrations: Conditionally append resource to snapshot if enabled * CloudMigrations: Add /cloudmigration/resources/dependencies endpoint * CloudMigrations: Properly filter dashboards and folders from snapshot
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import { BaseQueryFn, EndpointDefinition } from '@reduxjs/toolkit/query';
|
|
|
|
import { getLocalPlugins } from 'app/features/plugins/admin/api';
|
|
import { LocalPlugin } from 'app/features/plugins/admin/types';
|
|
|
|
import { handleRequestError } from '../../../api/createBaseQuery';
|
|
|
|
import { generatedAPI } from './endpoints.gen';
|
|
|
|
export * from './endpoints.gen';
|
|
|
|
export const cloudMigrationAPI = generatedAPI
|
|
.injectEndpoints({
|
|
endpoints: (build) => ({
|
|
// Manually written because the Swagger specifications for the plugins endpoint do not exist
|
|
getLocalPluginList: build.query<LocalPlugin[], void>({
|
|
queryFn: async () => {
|
|
try {
|
|
const list = await getLocalPlugins();
|
|
return { data: list };
|
|
} catch (error) {
|
|
return handleRequestError(error);
|
|
}
|
|
},
|
|
}),
|
|
}),
|
|
})
|
|
.enhanceEndpoints({
|
|
addTagTypes: [
|
|
'cloud-migration-token',
|
|
'cloud-migration-session',
|
|
'cloud-migration-snapshot',
|
|
'cloud-migration-resource-dependencies',
|
|
],
|
|
|
|
endpoints: {
|
|
// Cloud-side - create token
|
|
getCloudMigrationToken: {
|
|
providesTags: ['cloud-migration-token'],
|
|
},
|
|
createCloudMigrationToken: {
|
|
invalidatesTags: ['cloud-migration-token'],
|
|
},
|
|
deleteCloudMigrationToken: {
|
|
invalidatesTags: ['cloud-migration-token'],
|
|
},
|
|
|
|
// On-prem session management (entering token)
|
|
getSessionList: {
|
|
providesTags: ['cloud-migration-session'] /* should this be a -list? */,
|
|
},
|
|
getSession: {
|
|
providesTags: ['cloud-migration-session'],
|
|
},
|
|
createSession: {
|
|
invalidatesTags: ['cloud-migration-session'],
|
|
},
|
|
deleteSession: {
|
|
invalidatesTags: ['cloud-migration-session', 'cloud-migration-snapshot'],
|
|
},
|
|
|
|
// Snapshot management
|
|
getShapshotList: {
|
|
providesTags: ['cloud-migration-snapshot'],
|
|
},
|
|
getSnapshot: {
|
|
providesTags: ['cloud-migration-snapshot'],
|
|
},
|
|
createSnapshot: {
|
|
invalidatesTags: ['cloud-migration-snapshot'],
|
|
},
|
|
uploadSnapshot: {
|
|
invalidatesTags: ['cloud-migration-snapshot'],
|
|
},
|
|
|
|
// Resource dependencies
|
|
getResourceDependencies: {
|
|
providesTags: ['cloud-migration-resource-dependencies'],
|
|
},
|
|
|
|
getDashboardByUid: suppressErrorsOnQuery,
|
|
getLibraryElementByUid: suppressErrorsOnQuery,
|
|
getLocalPluginList: suppressErrorsOnQuery,
|
|
},
|
|
});
|
|
|
|
function suppressErrorsOnQuery<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType>(
|
|
endpoint: EndpointDefinition<QueryArg, BaseQuery, TagTypes, ResultType>
|
|
) {
|
|
if (!endpoint.query) {
|
|
return;
|
|
}
|
|
|
|
const originalQuery = endpoint.query;
|
|
endpoint.query = (...args) => {
|
|
const baseQuery = originalQuery(...args);
|
|
baseQuery.showErrorAlert = false;
|
|
return baseQuery;
|
|
};
|
|
}
|
|
|
|
export const { useGetLocalPluginListQuery } = cloudMigrationAPI;
|