mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* [Alerting] migrate es query legacy rule params * [Discover] add closing bracket * [Discover] apply suggestions * [Discover] resolve comments * [Discover] change version * [Discover] apply suggestions * [Discover] apply suggestions
116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
* 2.0.
|
|
*/
|
|
|
|
import type {
|
|
Logger,
|
|
SavedObject,
|
|
SavedObjectsExportTransformContext,
|
|
SavedObjectsServiceSetup,
|
|
} from '@kbn/core/server';
|
|
import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
|
|
import { MigrateFunctionsObject } from '@kbn/kibana-utils-plugin/common';
|
|
import { alertMappings } from './mappings';
|
|
import { getMigrations } from './migrations';
|
|
import { transformRulesForExport } from './transform_rule_for_export';
|
|
import { RawRule } from '../types';
|
|
import { getImportWarnings } from './get_import_warnings';
|
|
import { isRuleExportable } from './is_rule_exportable';
|
|
import { RuleTypeRegistry } from '../rule_type_registry';
|
|
export { partiallyUpdateAlert } from './partially_update_alert';
|
|
|
|
export const AlertAttributesExcludedFromAAD = [
|
|
'scheduledTaskId',
|
|
'muteAll',
|
|
'mutedInstanceIds',
|
|
'updatedBy',
|
|
'updatedAt',
|
|
'executionStatus',
|
|
'monitoring',
|
|
'snoozeEndTime',
|
|
];
|
|
|
|
// useful for Pick<RawAlert, AlertAttributesExcludedFromAADType> which is a
|
|
// type which is a subset of RawAlert with just attributes excluded from AAD
|
|
|
|
// useful for Pick<RawAlert, AlertAttributesExcludedFromAADType>
|
|
export type AlertAttributesExcludedFromAADType =
|
|
| 'scheduledTaskId'
|
|
| 'muteAll'
|
|
| 'mutedInstanceIds'
|
|
| 'updatedBy'
|
|
| 'updatedAt'
|
|
| 'executionStatus'
|
|
| 'monitoring'
|
|
| 'snoozeEndTime';
|
|
|
|
export function setupSavedObjects(
|
|
savedObjects: SavedObjectsServiceSetup,
|
|
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup,
|
|
ruleTypeRegistry: RuleTypeRegistry,
|
|
logger: Logger,
|
|
isPreconfigured: (connectorId: string) => boolean,
|
|
getSearchSourceMigrations: () => MigrateFunctionsObject
|
|
) {
|
|
savedObjects.registerType({
|
|
name: 'alert',
|
|
hidden: true,
|
|
namespaceType: 'multiple-isolated',
|
|
convertToMultiNamespaceTypeVersion: '8.0.0',
|
|
migrations: getMigrations(encryptedSavedObjects, getSearchSourceMigrations(), isPreconfigured),
|
|
mappings: alertMappings,
|
|
management: {
|
|
displayName: 'rule',
|
|
importableAndExportable: true,
|
|
getTitle(ruleSavedObject: SavedObject<RawRule>) {
|
|
return `Rule: [${ruleSavedObject.attributes.name}]`;
|
|
},
|
|
onImport(ruleSavedObjects) {
|
|
return {
|
|
warnings: getImportWarnings(ruleSavedObjects),
|
|
};
|
|
},
|
|
onExport<RawRule>(
|
|
context: SavedObjectsExportTransformContext,
|
|
objects: Array<SavedObject<RawRule>>
|
|
) {
|
|
return transformRulesForExport(objects);
|
|
},
|
|
isExportable<RawRule>(ruleSavedObject: SavedObject<RawRule>) {
|
|
return isRuleExportable(ruleSavedObject, ruleTypeRegistry, logger);
|
|
},
|
|
},
|
|
});
|
|
|
|
savedObjects.registerType({
|
|
name: 'api_key_pending_invalidation',
|
|
hidden: true,
|
|
namespaceType: 'agnostic',
|
|
mappings: {
|
|
properties: {
|
|
apiKeyId: {
|
|
type: 'keyword',
|
|
},
|
|
createdAt: {
|
|
type: 'date',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Encrypted attributes
|
|
encryptedSavedObjects.registerType({
|
|
type: 'alert',
|
|
attributesToEncrypt: new Set(['apiKey']),
|
|
attributesToExcludeFromAAD: new Set(AlertAttributesExcludedFromAAD),
|
|
});
|
|
|
|
// Encrypted attributes
|
|
encryptedSavedObjects.registerType({
|
|
type: 'api_key_pending_invalidation',
|
|
attributesToEncrypt: new Set(['apiKeyId']),
|
|
});
|
|
}
|