Ensure we account for cluster level settings when looking for configured actions (#19121)

This commit is contained in:
Chris Roberson 2018-05-18 15:19:05 -04:00 committed by GitHub
parent f3ea67e30f
commit 5edf2c0beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View file

@ -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: {
@ -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');
});
});
});

View file

@ -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) {
@ -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) => {