Skip to content

Commit

Permalink
Ensure we account for cluster level settings when looking for configu…
Browse files Browse the repository at this point in the history
…red actions (#19121) (#19226)
  • Loading branch information
chrisronline authored May 18, 2018
1 parent 7e0e77b commit 85c6542
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ describe('settings module', () => {
describe('when upstream JSON contains a configured action type', () => {
it('returns the correct Settings instance', () => {
const upstreamJson = {
persistent: {
xpack: {
notification: {
email: {
account: {
foo: {},
bar: {}
},
default_account: 'bar'
}
}
}
},
defaults: {
xpack: {
notification: {
Expand All @@ -49,6 +62,8 @@ describe('settings module', () => {
expect(actionTypes.email.enabled).to.be(true);
expect(actionTypes.email.accounts.scooby.default).to.be(true);
expect(actionTypes.email.accounts.scrappy).to.be.an('object');
expect(actionTypes.email.accounts.foo).to.be.an('object');
expect(actionTypes.email.accounts.bar).to.be.an('object');
});
});
});
Expand Down
16 changes: 14 additions & 2 deletions x-pack/plugins/watcher/server/models/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { get } from 'lodash';
import { merge } from 'lodash';
import { ACTION_TYPES } from '../../../common/constants';

function isEnabledByDefault(actionType) {
Expand Down Expand Up @@ -47,9 +47,21 @@ function getAccounts({ account, default_account: defaultAccount }) {
}, {});
}

function getNotifications(json) {
if (!json) {
return {};
}
return Object.values(json).reduce((accum, value) => {
if (value.hasOwnProperty('xpack') && value.xpack.hasOwnProperty('notification')) {
accum = merge(accum, value.xpack.notification);
}
return accum;
}, {});
}


function getActionTypesSettings(upstreamJson) {
const upstreamActionTypes = get(upstreamJson, 'defaults.xpack.notification', {});
const upstreamActionTypes = getNotifications(upstreamJson);

// Initialize settings for known action types
const actionTypes = Object.keys(ACTION_TYPES).reduce((types, typeName) => {
Expand Down

0 comments on commit 85c6542

Please sign in to comment.