Skip to content

Commit

Permalink
review changes to check_version
Browse files Browse the repository at this point in the history
  • Loading branch information
BigFunger committed Sep 15, 2016
1 parent 5da33ad commit 2802410
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ target
/esvm
.htpasswd
.eslintcache
/plugins
/plugins/
data
disabledPlugins
webpackstats.json
Expand Down
32 changes: 19 additions & 13 deletions src/server/plugins/check_version.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import pluginInit from './plugin_init';
import { cleanVersion, versionSatisfies } from '../../utils/version';
import _ from 'lodash';
import { get } from 'lodash';

module.exports = async function (kbnServer, server, config) {
function compatibleWithKibana(kbnServer, pluginVersion) {
//core plugins have a version of 'kibana' and are always compatible
if (pluginVersion === 'kibana') return true;

const cleanPluginVersion = cleanVersion(pluginVersion);
const kibanaVersion = cleanVersion(kbnServer.version);

return versionSatisfies(cleanPluginVersion, kibanaVersion);
}

export default async function (kbnServer, server, config) {
//because a plugin pack can contain more than one actual plugin, (for example x-pack)
//we make sure that the warning messages are unique
const warningMessages = new Set();
const plugins = kbnServer.plugins;

Expand All @@ -11,21 +22,16 @@ module.exports = async function (kbnServer, server, config) {
// the version of kibana down to the patch level. If these two versions need
// to diverge, they can specify a kibana.version to indicate the version of
// kibana the plugin is intended to work with.
const version = _.get(plugin, 'pkg.kibana.version', _.get(plugin, 'pkg.version'));
const name = _.get(plugin, 'pkg.name');

if (version === 'kibana') continue;
const version = get(plugin, 'pkg.kibana.version', get(plugin, 'pkg.version'));
const name = get(plugin, 'pkg.name');

if (!versionSatisfies(
cleanVersion(version),
cleanVersion(kbnServer.version))) {
warningMessages.add(`Plugin "${name}" expected Kibana version "${version}" and was disabled.`);
if (!compatibleWithKibana(kbnServer, version)) {
const message = `Plugin "${name}" was disabled because it expected Kibana version "${version}", and found "${kbnServer.version}".`;
warningMessages.add(message);
plugins.delete(plugin);
}
}

//because a plugin pack can contain more than one actual plugin, (for example x-pack)
//we make sure that the warning messages are unique
for (let message of warningMessages) {
server.log(['warning'], message);
}
Expand Down

0 comments on commit 2802410

Please sign in to comment.