-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathmanagement_sections_service.ts
94 lines (80 loc) · 2.98 KB
/
management_sections_service.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
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { createGetterSetter } from '@kbn/kibana-utils-plugin/public';
import { ManagementSection, RegisterManagementSectionArgs } from './utils';
import {
IngestSection,
DataSection,
InsightsAndAlertingSection,
SecuritySection,
KibanaSection,
StackSection,
} from './components/management_sections';
import {
ManagementSectionId,
SectionsServiceSetup,
SectionsServiceStartDeps,
DefinedSections,
ManagementSectionsStartPrivate,
} from './types';
const [getSectionsServiceStartPrivate, setSectionsServiceStartPrivate] =
createGetterSetter<ManagementSectionsStartPrivate>('SectionsServiceStartPrivate');
export { getSectionsServiceStartPrivate };
export class ManagementSectionsService {
definedSections: DefinedSections;
constructor() {
// Note on adding sections - sections can be defined in a plugin and exported as a contract
// It is not necessary to define all sections here, although we've chose to do it for discovery reasons.
this.definedSections = {
ingest: this.registerSection(IngestSection),
data: this.registerSection(DataSection),
insightsAndAlerting: this.registerSection(InsightsAndAlertingSection),
security: this.registerSection(SecuritySection),
kibana: this.registerSection(KibanaSection),
stack: this.registerSection(StackSection),
};
}
private sections: Map<ManagementSectionId | string, ManagementSection> = new Map();
private getAllSections = () => [...this.sections.values()];
private registerSection = (section: RegisterManagementSectionArgs) => {
if (this.sections.has(section.id)) {
throw Error(`ManagementSection '${section.id}' already registered`);
}
const newSection = new ManagementSection(section);
this.sections.set(section.id, newSection);
return newSection;
};
setup(): SectionsServiceSetup {
return {
register: this.registerSection,
section: {
...this.definedSections,
},
};
}
start({ capabilities }: SectionsServiceStartDeps) {
this.getAllSections().forEach((section) => {
if (capabilities.management.hasOwnProperty(section.id)) {
const sectionCapabilities = capabilities.management[section.id];
section.apps.forEach((app) => {
const capabilitiesId = app.capabilitiesId || app.id;
if (
sectionCapabilities.hasOwnProperty(capabilitiesId) &&
sectionCapabilities[capabilitiesId] !== true
) {
app.disable();
}
});
}
});
setSectionsServiceStartPrivate({
getSectionsEnabled: () => this.getAllSections().filter((section) => section.enabled),
});
return {};
}
}