-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
index.js
148 lines (136 loc) · 5.3 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* 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_DEFAULT_ADMIN_EMAIL_UI_SETTING,
XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS
} from '../../server/lib/constants';
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 { getLocalizationUsageCollector } from './server/lib/get_localization_usage_collector';
import { createTelemetryUsageCollector } from './server/lib/telemetry';
import { uiCapabilitiesForFeatures } from './server/lib/ui_capabilities_for_features';
import {
xpackInfoRoute,
featuresRoute,
settingsRoute,
} from './server/routes/api/v1';
import { telemetryRoute } from './server/routes/api/v2';
import {
CONFIG_TELEMETRY,
getConfigTelemetryDesc,
} from './common/constants';
import mappings from './mappings.json';
import { i18n } from '@kbn/i18n';
export { callClusterFactory } from './server/lib/call_cluster_factory';
import { registerOssFeatures } from './server/lib/register_oss_features';
/**
* Determine if Telemetry is enabled.
*
* @param {Object} config Kibana configuration object.
*/
function isTelemetryEnabled(config) {
return config.get('xpack.xpack_main.telemetry.enabled');
}
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` is used internally and not intended to be set
config: Joi.string().default(Joi.ref('$defaultConfigPath')),
enabled: Joi.boolean().default(true),
url: Joi.when('$dev', {
is: true,
then: Joi.string().default('https://telemetry-staging.elastic.co/xpack/v2/send'),
otherwise: Joi.string().default('https://telemetry.elastic.co/xpack/v2/send')
}),
}).default(),
xpack_api_polling_frequency_millis: Joi.number().default(XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS),
}).default();
},
uiCapabilities(server) {
return uiCapabilitiesForFeatures(server.plugins.xpack_main);
},
uiExports: {
managementSections: ['plugins/xpack_main/views/management'],
uiSettingDefaults: {
[CONFIG_TELEMETRY]: {
name: i18n.translate('xpack.main.telemetry.telemetryConfigTitle', {
defaultMessage: 'Telemetry opt-in'
}),
description: getConfigTelemetryDesc(),
value: false,
readonly: true,
},
[XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING]: {
name: i18n.translate('xpack.main.uiSettings.adminEmailTitle', {
defaultMessage: 'Admin email'
}),
// TODO: change the description when email address is used for more things?
description: i18n.translate('xpack.main.uiSettings.adminEmailDescription', {
defaultMessage:
'Recipient email address for X-Pack admin operations, such as Cluster Alert email notifications from Monitoring.'
}),
type: 'string', // TODO: Any way of ensuring this is a valid email address?
value: null
}
},
savedObjectSchemas: {
telemetry: {
isNamespaceAgnostic: true,
},
},
injectDefaultVars(server) {
const config = server.config();
return {
telemetryUrl: config.get('xpack.xpack_main.telemetry.url'),
telemetryEnabled: isTelemetryEnabled(config),
telemetryOptedIn: null,
activeSpace: null,
spacesEnabled: config.get('xpack.spaces.enabled'),
};
},
hacks: [
'plugins/xpack_main/hacks/check_xpack_info_change',
'plugins/xpack_main/hacks/telemetry_opt_in',
'plugins/xpack_main/hacks/telemetry_trigger',
],
replaceInjectedVars,
__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,
});
},
mappings,
},
init(server) {
mirrorPluginStatus(server.plugins.elasticsearch, this, 'yellow', 'red');
setupXPackMain(server);
const { types: savedObjectTypes } = server.savedObjects;
registerOssFeatures(server.plugins.xpack_main.registerFeature, savedObjectTypes);
// register routes
xpackInfoRoute(server);
telemetryRoute(server);
settingsRoute(server, this.kbnServer);
featuresRoute(server);
// usage collection
server.usage.collectorSet.register(getLocalizationUsageCollector(server));
server.usage.collectorSet.register(createTelemetryUsageCollector(server));
}
});
};