Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] transform plugin deprecations before checking for unused settings #21294

Merged
merged 8 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/server/config/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@
import { difference } from 'lodash';
import { transformDeprecations } from './transform_deprecations';
import { unset, formatListAsProse, getFlattenedObject } from '../../utils';
import { createTransform, Deprecations } from '../../deprecation';


const getFlattenedKeys = object => (
Object.keys(getFlattenedObject(object))
);

const getUnusedConfigKeys = (disabledPluginSpecs, rawSettings, configValues) => {
const settings = transformDeprecations(rawSettings);
const getUnusedConfigKeys = (plugins, disabledPluginSpecs, rawSettings, configValues) => {
// transform deprecated core settings
let settings = transformDeprecations(rawSettings);

// transform deprecated plugin settings
plugins.forEach(({ spec }) => {
const deprecationsProvider = spec.getDeprecationsProvider();
if (!deprecationsProvider) return;
settings = createTransform(deprecationsProvider(Deprecations))(settings);
spalger marked this conversation as resolved.
Show resolved Hide resolved
});

// remove config values from disabled plugins
for (const spec of disabledPluginSpecs) {
Expand All @@ -52,7 +62,7 @@ export default function (kbnServer, server, config) {
return kbnServer.config;
});

const unusedKeys = getUnusedConfigKeys(kbnServer.disabledPluginSpecs, kbnServer.settings, config.get())
const unusedKeys = getUnusedConfigKeys(kbnServer.plugins, kbnServer.disabledPluginSpecs, kbnServer.settings, config.get())
.map(key => `"${key}"`);

if (!unusedKeys.length) {
Expand Down
26 changes: 25 additions & 1 deletion src/server/config/complete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('server/config completeMixin()', function () {
settings = {},
configValues = {},
disabledPluginSpecs = [],
plugins = [],
} = options;

const server = {
Expand All @@ -48,7 +49,8 @@ describe('server/config completeMixin()', function () {
settings,
server,
config,
disabledPluginSpecs
disabledPluginSpecs,
plugins
};

const callCompleteMixin = () => {
Expand Down Expand Up @@ -220,6 +222,28 @@ describe('server/config completeMixin()', function () {
callCompleteMixin();
sinon.assert.calledOnce(transformDeprecations);
});

it('should transform deprecated plugin settings', () => {
const { callCompleteMixin } = setup({
settings: {
foo1: 'bar'
},
configValues: {
foo2: 'bar'
},
plugins: [
{
spec: {
getDeprecationsProvider() {
return ({ rename }) => [rename('foo1', 'foo2')];
}
}
}
],
});

expect(callCompleteMixin).not.toThrowError();
});
});

describe('disabled plugins', () => {
Expand Down