mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
reworked logic to remove config when deleting a plugin from plugin_collection
This commit is contained in:
parent
2802410573
commit
2f52be62ae
2 changed files with 33 additions and 19 deletions
|
@ -89,17 +89,14 @@ module.exports = class Plugin {
|
|||
};
|
||||
}
|
||||
|
||||
async readConfig() {
|
||||
async readConfigSchema() {
|
||||
let schema = await this.getConfigSchema(Joi);
|
||||
let { config } = this.kbnServer;
|
||||
config.extendSchema(this.configPrefix, schema || defaultConfigSchema);
|
||||
return schema || defaultConfigSchema;
|
||||
}
|
||||
|
||||
if (config.get([...toPath(this.configPrefix), 'enabled'])) {
|
||||
return true;
|
||||
} else {
|
||||
config.removeSchema(this.configPrefix);
|
||||
return false;
|
||||
}
|
||||
get enabled() {
|
||||
const { config } = this.kbnServer;
|
||||
return config.get([...toPath(this.configPrefix), 'enabled']);
|
||||
}
|
||||
|
||||
async preInit() {
|
||||
|
|
|
@ -2,11 +2,23 @@
|
|||
import PluginApi from './plugin_api';
|
||||
import { inspect } from 'util';
|
||||
import { get, indexBy } from 'lodash';
|
||||
import toPath from 'lodash/internal/toPath';
|
||||
import Collection from '../../utils/collection';
|
||||
|
||||
let byIdCache = Symbol('byIdCache');
|
||||
let pluginApis = Symbol('pluginApis');
|
||||
|
||||
async function addPluginConfig(pluginCollection, plugin) {
|
||||
const configSchema = await plugin.readConfigSchema();
|
||||
let { config } = pluginCollection.kbnServer;
|
||||
config.extendSchema(plugin.configPrefix, configSchema);
|
||||
}
|
||||
|
||||
function removePluginConfig(pluginCollection, plugin) {
|
||||
let { config } = pluginCollection.kbnServer;
|
||||
config.removeSchema(plugin.configPrefix);
|
||||
}
|
||||
|
||||
module.exports = class Plugins extends Collection {
|
||||
|
||||
constructor(kbnServer) {
|
||||
|
@ -27,21 +39,26 @@ module.exports = class Plugins extends Collection {
|
|||
// clear the byIdCache
|
||||
this[byIdCache] = null;
|
||||
|
||||
for (let product of output) {
|
||||
|
||||
if (product instanceof api.Plugin) {
|
||||
let plugin = product;
|
||||
this.add(plugin);
|
||||
|
||||
let enabled = await plugin.readConfig();
|
||||
if (!enabled) this.delete(plugin);
|
||||
continue;
|
||||
for (let plugin of output) {
|
||||
if (!plugin instanceof api.Plugin) {
|
||||
throw new TypeError('unexpected plugin export ' + inspect(plugin));
|
||||
}
|
||||
|
||||
throw new TypeError('unexpected plugin export ' + inspect(product));
|
||||
await this.add(plugin);
|
||||
if (!plugin.enabled) this.delete(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
async add(plugin) {
|
||||
await addPluginConfig(this, plugin);
|
||||
super.add(plugin);
|
||||
}
|
||||
|
||||
delete(plugin) {
|
||||
removePluginConfig(this, plugin);
|
||||
super.delete(plugin);
|
||||
}
|
||||
|
||||
get byId() {
|
||||
return this[byIdCache] || (this[byIdCache] = indexBy([...this], 'id'));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue