-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.ts
110 lines (102 loc) · 3.29 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* 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,
SavedObjectsTypeMappingDefinition,
} from 'kibana/server';
import mappings from './mappings.json';
import { getMigrations } from './migrations';
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
import { transformRulesForExport } from './transform_rule_for_export';
import { RawAlert } 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',
];
// 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';
export function setupSavedObjects(
savedObjects: SavedObjectsServiceSetup,
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup,
ruleTypeRegistry: RuleTypeRegistry,
logger: Logger,
isPreconfigured: (connectorId: string) => boolean
) {
savedObjects.registerType({
name: 'alert',
hidden: true,
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
migrations: getMigrations(encryptedSavedObjects, isPreconfigured),
mappings: mappings.alert as SavedObjectsTypeMappingDefinition,
management: {
importableAndExportable: true,
getTitle(ruleSavedObject: SavedObject<RawAlert>) {
return `Rule: [${ruleSavedObject.attributes.name}]`;
},
onImport(ruleSavedObjects) {
return {
warnings: getImportWarnings(ruleSavedObjects),
};
},
onExport<RawAlert>(
context: SavedObjectsExportTransformContext,
objects: Array<SavedObject<RawAlert>>
) {
return transformRulesForExport(objects);
},
isExportable<RawAlert>(ruleSavedObject: SavedObject<RawAlert>) {
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']),
});
}