mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
Adding comments and making it so plugins can publish config settings
This commit is contained in:
parent
2ef713170e
commit
29a10dba59
6 changed files with 72 additions and 16 deletions
|
@ -6,10 +6,19 @@ _.mixin(require('lodash-deep'));
|
|||
|
||||
function Config(schema, config) {
|
||||
config = config || {};
|
||||
this.schema = Joi.compile(schema || {});
|
||||
this.schema = schema || Joi.object({}).default();
|
||||
this.reset(config);
|
||||
}
|
||||
|
||||
Config.prototype.extendSchema = function (key, schema) {
|
||||
var additionalSchema = {};
|
||||
if (!this.has(key)) {
|
||||
additionalSchema[key] = schema;
|
||||
this.schema = this.schema.keys(additionalSchema);
|
||||
this.reset(this.config);
|
||||
}
|
||||
};
|
||||
|
||||
Config.prototype.reset = function (obj) {
|
||||
var results = Joi.validate(obj, this.schema);
|
||||
if (results.error) {
|
||||
|
|
|
@ -1,9 +1,21 @@
|
|||
var Promise = require('bluebird');
|
||||
var registerPlugins = require('./register_plugins');
|
||||
var requirePlugins = require('./require_plugins');
|
||||
var logging = require('../logging/');
|
||||
var registerPluginConfigs = require('./register_plugin_configs');
|
||||
|
||||
module.exports = function (externalPlugins) {
|
||||
// require all the internal plugins then concat witht the external
|
||||
// plugins passed in from the start method.
|
||||
var plugins = requirePlugins().concat(externalPlugins);
|
||||
return logging(this).then(function (server) {
|
||||
registerPlugins(server, plugins);
|
||||
// setup logging then register the plugins
|
||||
return logging(this)
|
||||
// Setup the config schema for the plugins
|
||||
.then(function (server) {
|
||||
return registerPluginConfigs(server, plugins);
|
||||
})
|
||||
// Register the plugins
|
||||
.then(function (server) {
|
||||
return registerPlugins(server, plugins);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -9,6 +9,9 @@ function Plugin(options) {
|
|||
this.init = function (server, options) {
|
||||
return Promise.reject(new Error('You must override the init function for plugins'));
|
||||
};
|
||||
this.config = function (Joi) {
|
||||
return Joi.object({}).default();
|
||||
};
|
||||
_.assign(this, options);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,14 @@ var checkDependencies = require('./check_dependencies');
|
|||
var status = require('../status');
|
||||
var addStaticsForPublic = require('./add_statics_for_public');
|
||||
|
||||
function checkForCircularDependency(tasks) {
|
||||
/**
|
||||
* Check to see if there are any circular dependencies for the task tree
|
||||
* @param {array} plugins an array of plugins
|
||||
* @returns {type} description
|
||||
*/
|
||||
function checkForCircularDependency(plugins) {
|
||||
var deps = {};
|
||||
tasks.forEach(function (task) {
|
||||
plugins.forEach(function (task) {
|
||||
deps[task.name] = [];
|
||||
if (task.require) deps[task.name] = task.require;
|
||||
});
|
||||
|
@ -24,6 +29,11 @@ module.exports = function (server, plugins) {
|
|||
var finished = false;
|
||||
var todo = plugins.concat();
|
||||
|
||||
/**
|
||||
* Checks to see if all the tasks are completed for an array of dependencies
|
||||
* @param {array} tasks An array of plugin names
|
||||
* @returns {boolean} if all the tasks are done this it will return true
|
||||
*/
|
||||
function allDone(tasks) {
|
||||
var done = _.keys(results);
|
||||
return tasks.every(function (dep) {
|
||||
|
@ -31,6 +41,15 @@ module.exports = function (server, plugins) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a plugin with the Kibana server
|
||||
*
|
||||
* This includes setting up the status object and setting the reference to
|
||||
* the plugin's server
|
||||
*
|
||||
* @param {object} plugin The plugin to register
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function registerPlugin(plugin) {
|
||||
var config = server.config();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
@ -40,7 +59,7 @@ module.exports = function (server, plugins) {
|
|||
Promise.try(plugin.init, [server, options], plugin).nodeify(next);
|
||||
};
|
||||
register.attributes = { name: plugin.name };
|
||||
var options = config[plugin.name] || {};
|
||||
var options = config.get(plugin.name) || {};
|
||||
server.register({ register: register, options: options }, function (err) {
|
||||
if (err) return reject(err);
|
||||
plugin.status.green('Ready');
|
||||
|
|
|
@ -45,16 +45,6 @@ module.exports = new kibana.Plugin({
|
|||
}
|
||||
});
|
||||
|
||||
// server.route({
|
||||
// method: 'GET',
|
||||
// path: '/status/{param*}',
|
||||
// handler: {
|
||||
// directory: {
|
||||
// path: join(__dirname, 'public')
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/status/health',
|
||||
|
|
|
@ -187,6 +187,29 @@ describe('lib/config/config', function () {
|
|||
|
||||
});
|
||||
|
||||
describe('#extendSchema(key, schema)', function () {
|
||||
var config;
|
||||
beforeEach(function () {
|
||||
config = new Config(schema);
|
||||
});
|
||||
|
||||
it('should allow you to extend the schema at the top level', function () {
|
||||
var newSchema = Joi.object({ test: Joi.boolean().default(true) }).default();
|
||||
config.extendSchema('myTest', newSchema);
|
||||
expect(config.get('myTest.test')).to.be(true);
|
||||
});
|
||||
|
||||
it('should NOT allow you to extend the schema if somethign else is there', function () {
|
||||
var newSchema = Joi.object({ test: Joi.boolean().default(true) }).default();
|
||||
config.extendSchema('test', newSchema);
|
||||
var run = function () {
|
||||
config.get('test.test');
|
||||
};
|
||||
expect(run).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue