Skip to content

Commit

Permalink
move enabled check into it's own mixin, and cleaned up how you disabl…
Browse files Browse the repository at this point in the history
…e a plugin
  • Loading branch information
BigFunger committed Sep 16, 2016
1 parent e920bca commit 049c029
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/server/kbn_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/server/plugins/check_enabled.js
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion src/server/plugins/check_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/server/plugins/plugin.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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] = [];
Expand All @@ -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);
}
Expand Down
15 changes: 5 additions & 10 deletions src/server/plugins/plugin_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 049c029

Please sign in to comment.