grafana/scripts/generate-alerting-rtk-apis.ts

80 lines
2.5 KiB
TypeScript
Raw Normal View History

/**
* To generate alerting k8s APIs, run:
* `npx rtk-query-codegen-openapi ./scripts/generate-alerting-rtk-apis.ts`
*/
import { ConfigFile } from '@rtk-query/codegen-openapi';
import { accessSync } from 'fs';
const schemaFile = '../data/alerting/openapi.json';
try {
// Check we have the OpenAPI before generating alerting RTK APIs,
// as this is currently a manual process
accessSync(schemaFile);
} catch (e) {
console.error('\nCould not find OpenAPI definition.\n');
console.error(
'Please visit /openapi/v3/apis/notifications.alerting.grafana.app/v0alpha1 and save the OpenAPI definition to data/alerting/openapi.json\n'
);
throw e;
}
const config: ConfigFile = {
schemaFile,
apiFile: '',
tag: true,
outputFiles: {
'../public/app/features/alerting/unified/openapi/timeIntervalsApi.gen.ts': {
apiFile: '../public/app/features/alerting/unified/api/alertingApi.ts',
apiImport: 'alertingApi',
filterEndpoints: [
'listNamespacedTimeInterval',
'createNamespacedTimeInterval',
'deleteNamespacedTimeInterval',
'replaceNamespacedTimeInterval',
],
exportName: 'generatedTimeIntervalsApi',
flattenArg: false,
},
'../public/app/features/alerting/unified/openapi/receiversApi.gen.ts': {
apiFile: '../public/app/features/alerting/unified/api/alertingApi.ts',
apiImport: 'alertingApi',
filterEndpoints: [
'listNamespacedReceiver',
'createNamespacedReceiver',
'readNamespacedReceiver',
'deleteNamespacedReceiver',
'replaceNamespacedReceiver',
],
exportName: 'generatedReceiversApi',
flattenArg: false,
},
'../public/app/features/alerting/unified/openapi/templatesApi.gen.ts': {
apiFile: '../public/app/features/alerting/unified/api/alertingApi.ts',
apiImport: 'alertingApi',
filterEndpoints: [
'listNamespacedTemplateGroup',
'createNamespacedTemplateGroup',
'readNamespacedTemplateGroup',
'replaceNamespacedTemplateGroup',
'deleteNamespacedTemplateGroup',
],
exportName: 'generatedTemplatesApi',
Alerting: Consume k8s API for notification policies tree (#96147) * Add basic usage of K8s API for notification policies * Add permissions checks for navtree for routes * Add and update permissions for routing tree logic * Add capability to skip calling contact points hook * Conditionally show list of mute timings depending on permissions * Conditionally link to mute timings if user can see at least one * Add work in progress k8s handlers for routing tree * Update notification policy hooks * Wire up policies to permissions better (conditionally calling APIs) * Add additional checks for whether to show grafana AM * Add permission checks to access control * Remove accidental permissions after rebase * Update types and const for k8s routes * Improve statefulness and reset routing tree in tests * Update notif policy tests to check k8s and config API * Fix type assertion * Move non-grafana test out of .each * Make failure case safer * Override tag invalidation for notification policies API * Pass in error and add new error alert component * Add basic mock server conflict check * Add test to check user can save after a conflict * Add logic to allow reloading policies if changed by another user * Fix test * Update translations in Modals * Add ViewAlertGroups ability * Tweak provisioning logic and memoize AM config response * Update snapshots for useAbilities * Update result destructure * Use enums for provenance in routingtrees * Use consistent memoisation * Fix _metadata for vanilla AM * useAsync for error / update state * move k8s api error handling to separate file * use cause for error codes * Use `supported` bools from Alertmanager abilities and clarify default policy --------- Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com> Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2024-11-26 21:46:39 +08:00
},
'../public/app/features/alerting/unified/openapi/routesApi.gen.ts': {
apiFile: '../public/app/features/alerting/unified/api/alertingApi.ts',
apiImport: 'alertingApi',
filterEndpoints: [
'listNamespacedRoutingTree',
'replaceNamespacedRoutingTree',
'deleteCollectionNamespacedRoutingTree',
],
exportName: 'generatedRoutesApi',
flattenArg: false,
},
},
};
export default config;