Skip to content

Commit

Permalink
Deprecate tribe settings in 6.x (#25548)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover authored Nov 13, 2018
1 parent 16b43de commit 25a3892
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 18 deletions.
15 changes: 14 additions & 1 deletion src/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@ export default function (kibana) {
sslVerify(),
rename('tribe.ssl.ca', 'tribe.ssl.certificateAuthorities'),
rename('tribe.ssl.cert', 'tribe.ssl.certificate'),
sslVerify('tribe')
sslVerify('tribe'),
(settings = {}, log) => {
const tribe = get(settings, 'tribe');
if (!tribe) {
return;
}

const tribeKeys = Object.keys(tribe);
if (tribeKeys.length > 0) {
const keyList = tribeKeys.map(k => `"elasticsearch.tribe.${k}"`).join(',');
log(`Config keys [${keyList}] are deprecated. Tribe nodes will be removed in 7.0 and should be replaced ` +
`with Cross-Cluster-Search.`);
}
}
];
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
* under the License.
*/

import { Deprecations } from '../../../deprecation';
import expect from 'expect.js';
import index from '../index';
import { Deprecations } from '../../deprecation';
import index from './index';
import { compact, noop, set } from 'lodash';
import sinon from 'sinon';

describe('plugins/elasticsearch', function () {
describe('#deprecations()', function () {
let transformDeprecations;

before(function () {
beforeAll(function () {
const Plugin = function (options) {
this.deprecations = options.deprecations;
};
Expand All @@ -40,6 +38,32 @@ describe('plugins/elasticsearch', function () {
};
});

describe('tribe.*', () => {
let log;

beforeEach(() => log = jest.fn());

it(`doesn't log when there are no settings`, () => {
transformDeprecations(null, log);
expect(log).not.toHaveBeenCalled();
});

it(`doesn't log when there are no tribe settings`, () => {
transformDeprecations({}, log);
expect(log).not.toHaveBeenCalled();
});

it(`doesn't log when there are empty tribe settings`, () => {
transformDeprecations({ tribe: {} }, log);
expect(log).not.toHaveBeenCalled();
});

it(`logs when there are any tribe settings`, () => {
transformDeprecations({ tribe: { url: '' } }, log);
expect(log).toHaveBeenCalled();
});
});

[null, 'tribe'].forEach((basePath) => {
const getKey = (path) => {
return compact([basePath, path]).join('.');
Expand All @@ -50,7 +74,7 @@ describe('plugins/elasticsearch', function () {
let sslSettings;

beforeEach(function () {
settings = {};
settings = { tribe: { username: '' } };
sslSettings = {};
set(settings, getKey('ssl'), sslSettings);
});
Expand All @@ -59,43 +83,49 @@ describe('plugins/elasticsearch', function () {
sslSettings.verify = false;

transformDeprecations(settings);
expect(sslSettings.verificationMode).to.be('none');
expect(sslSettings.verify).to.be(undefined);
expect(sslSettings.verificationMode).toBe('none');
expect(sslSettings.verify).toBe(undefined);
});

it('should log when deprecating verify from false', function () {
sslSettings.verify = false;

const log = sinon.spy();
const log = jest.fn();
transformDeprecations(settings, log);
expect(log.calledOnce).to.be(true);
const expLogMsg = `Config key "${getKey('ssl.verify')}" is deprecated. It has been replaced with ` +
`"${getKey('ssl.verificationMode')}"`;
expect(log).toHaveBeenCalledWith(expLogMsg);
});

it('sets verificationMode to full when verify is true', function () {
sslSettings.verify = true;

transformDeprecations(settings);
expect(sslSettings.verificationMode).to.be('full');
expect(sslSettings.verify).to.be(undefined);
expect(sslSettings.verificationMode).toBe('full');
expect(sslSettings.verify).toBe(undefined);
});

it('should log when deprecating verify from true', function () {
sslSettings.verify = true;

const log = sinon.spy();
const log = jest.fn();
transformDeprecations(settings, log);
expect(log.calledOnce).to.be(true);
const expLogMsg = `Config key "${getKey('ssl.verify')}" is deprecated. It has been replaced with ` +
`"${getKey('ssl.verificationMode')}"`;
expect(log).toHaveBeenCalledWith(expLogMsg);
});

it(`shouldn't set verificationMode when verify isn't present`, function () {
transformDeprecations(settings);
expect(sslSettings.verificationMode).to.be(undefined);
expect(sslSettings.verificationMode).toBe(undefined);
});

it(`shouldn't log when verify isn't present`, function () {
const log = sinon.spy();
const log = jest.fn();
transformDeprecations(settings, log);
expect(log.called).to.be(false);
const expLogMsg = `Config key "${getKey('ssl.verify')}" is deprecated. It has been replaced with ` +
`"${getKey('ssl.verificationMode')}"`;
expect(log).not.toHaveBeenCalledWith(expLogMsg);
});
});
});
Expand Down

0 comments on commit 25a3892

Please sign in to comment.