mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
move enabled check into it's own mixin, and cleaned up how you disable a plugin
This commit is contained in:
parent
e920bca051
commit
049c029764
5 changed files with 28 additions and 21 deletions
|
@ -28,7 +28,10 @@ module.exports = class KbnServer {
|
|||
// find plugins and set this.plugins
|
||||
require('./plugins/scan'),
|
||||
|
||||
// make sure that all plugins expect the current version of Kibana
|
||||
// disable the plugins that are disabled through configuration
|
||||
require('./plugins/check_enabled'),
|
||||
|
||||
// disable the plugins that are incompatible with the current version of Kibana
|
||||
require('./plugins/check_version'),
|
||||
|
||||
// tell the config we are done loading plugins
|
||||
|
|
15
src/server/plugins/check_enabled.js
Normal file
15
src/server/plugins/check_enabled.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import toPath from 'lodash/internal/toPath';
|
||||
|
||||
export default async function (kbnServer, server, config) {
|
||||
const { plugins } = kbnServer;
|
||||
|
||||
for (let plugin of plugins) {
|
||||
const enabledInConfig = config.get([...toPath(plugin.configPrefix), 'enabled']);
|
||||
|
||||
if (!enabledInConfig) {
|
||||
plugins.disable(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
|
@ -24,7 +24,7 @@ export default async function (kbnServer, server, config) {
|
|||
if (!compatibleWithKibana(kbnServer, plugin)) {
|
||||
const message = `Plugin "${name}" was disabled because it expected Kibana version "${version}", and found "${kbnServer.version}".`;
|
||||
warningMessages.add(message);
|
||||
plugins.delete(plugin);
|
||||
plugins.disable(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import _ from 'lodash';
|
||||
import toPath from 'lodash/internal/toPath';
|
||||
import Joi from 'joi';
|
||||
import Bluebird, { attempt, fromNode } from 'bluebird';
|
||||
import { basename, resolve } from 'path';
|
||||
|
@ -68,7 +67,7 @@ module.exports = class Plugin {
|
|||
this.externalPreInit = opts.preInit || _.noop;
|
||||
this.externalInit = opts.init || _.noop;
|
||||
this.configPrefix = opts.configPrefix || this.id;
|
||||
this.getConfigSchema = opts.config || _.noop;
|
||||
this.getExternalConfigSchema = opts.config || _.noop;
|
||||
this.preInit = _.once(this.preInit);
|
||||
this.init = _.once(this.init);
|
||||
this[extendInitFns] = [];
|
||||
|
@ -95,16 +94,11 @@ module.exports = class Plugin {
|
|||
};
|
||||
}
|
||||
|
||||
async readConfigSchema() {
|
||||
let schema = await this.getConfigSchema(Joi);
|
||||
async getConfigSchema() {
|
||||
let schema = await this.getExternalConfigSchema(Joi);
|
||||
return schema || defaultConfigSchema;
|
||||
}
|
||||
|
||||
get enabled() {
|
||||
const { config } = this.kbnServer;
|
||||
return config.get([...toPath(this.configPrefix), 'enabled']);
|
||||
}
|
||||
|
||||
async preInit() {
|
||||
return await this.externalPreInit(this.kbnServer.server);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ let byIdCache = Symbol('byIdCache');
|
|||
let pluginApis = Symbol('pluginApis');
|
||||
|
||||
async function addPluginConfig(pluginCollection, plugin) {
|
||||
const configSchema = await plugin.readConfigSchema();
|
||||
const configSchema = await plugin.getConfigSchema();
|
||||
let { config } = pluginCollection.kbnServer;
|
||||
config.extendSchema(plugin.configPrefix, configSchema);
|
||||
}
|
||||
|
@ -44,19 +44,14 @@ module.exports = class Plugins extends Collection {
|
|||
throw new TypeError('unexpected plugin export ' + inspect(plugin));
|
||||
}
|
||||
|
||||
await this.add(plugin);
|
||||
if (!plugin.enabled) this.delete(plugin);
|
||||
await addPluginConfig(this, plugin);
|
||||
this.add(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
async add(plugin) {
|
||||
await addPluginConfig(this, plugin);
|
||||
super.add(plugin);
|
||||
}
|
||||
|
||||
delete(plugin) {
|
||||
async disable(plugin) {
|
||||
removePluginConfig(this, plugin);
|
||||
super.delete(plugin);
|
||||
this.delete(plugin);
|
||||
}
|
||||
|
||||
get byId() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue