-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
index.js
104 lines (92 loc) · 3.51 KB
/
index.js
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { resolve } from 'path';
import dedent from 'dedent';
import {
XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS
} from '../../server/lib/constants';
import { getXpackConfigWithDeprecated } from '../telemetry/common/get_xpack_config_with_deprecated';
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import { replaceInjectedVars } from './server/lib/replace_injected_vars';
import { setupXPackMain } from './server/lib/setup_xpack_main';
import { xpackInfoRoute, settingsRoute } from './server/routes/api/v1';
import { has } from 'lodash';
function movedToTelemetry(configPath) {
return (settings, log) => {
if (has(settings, configPath)) {
log(`Config key ${configPath} is deprecated. Use "xpack.telemetry.${configPath}" instead.`);
}
};
}
export { callClusterFactory } from './server/lib/call_cluster_factory';
export const xpackMain = (kibana) => {
return new kibana.Plugin({
id: 'xpack_main',
configPrefix: 'xpack.xpack_main',
publicDir: resolve(__dirname, 'public'),
require: ['elasticsearch'],
config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
telemetry: Joi.object({
config: Joi.string().default(),
enabled: Joi.boolean().default(),
url: Joi.string().default(),
}).default(), // deprecated
xpack_api_polling_frequency_millis: Joi.number().default(XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS),
}).default();
},
uiCapabilities(server) {
const featuresPlugin = server.newPlatform.setup.plugins.features;
if (!featuresPlugin) {
throw new Error('New Platform XPack Features plugin is not available.');
}
return featuresPlugin.getFeaturesUICapabilities();
},
uiExports: {
hacks: [
'plugins/xpack_main/hacks/check_xpack_info_change',
],
replaceInjectedVars,
injectDefaultVars(server) {
const config = server.config();
return {
telemetryEnabled: getXpackConfigWithDeprecated(config, 'telemetry.enabled'),
activeSpace: null,
spacesEnabled: config.get('xpack.spaces.enabled'),
};
},
__webpackPluginProvider__(webpack) {
return new webpack.BannerPlugin({
banner: dedent`
/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements.
* Licensed under the Elastic License; you may not use this file except in compliance with the Elastic License. */
`,
raw: true,
});
},
},
init(server) {
const featuresPlugin = server.newPlatform.setup.plugins.features;
if (!featuresPlugin) {
throw new Error('New Platform XPack Features plugin is not available.');
}
mirrorPluginStatus(server.plugins.elasticsearch, this, 'yellow', 'red');
featuresPlugin.registerLegacyAPI({
xpackInfo: setupXPackMain(server),
savedObjectTypes: server.savedObjects.types
});
// register routes
xpackInfoRoute(server);
settingsRoute(server, this.kbnServer);
},
deprecations: () => [
movedToTelemetry('telemetry.config'),
movedToTelemetry('telemetry.url'),
movedToTelemetry('telemetry.enabled'),
],
});
};