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

alerting/transformActionParams does not handle arrays #44057

Closed
pmuellr opened this issue Aug 27, 2019 · 1 comment · Fixed by #44094
Closed

alerting/transformActionParams does not handle arrays #44057

pmuellr opened this issue Aug 27, 2019 · 1 comment · Fixed by #44094
Assignees

Comments

@pmuellr
Copy link
Member

pmuellr commented Aug 27, 2019

current version of code:

import Mustache from 'mustache';
import { isPlainObject } from 'lodash';
import { AlertActionParams, State, Context } from '../types';
export function transformActionParams(params: AlertActionParams, state: State, context: Context) {
const result: AlertActionParams = {};
for (const [key, value] of Object.entries(params)) {
if (isPlainObject(value)) {
result[key] = transformActionParams(value as AlertActionParams, state, context);
} else if (typeof value !== 'string') {
result[key] = value;
} else {
result[key] = Mustache.render(value, { context, state });
}
}
return result;
}

Arrays end up getting treated as objects, where the indices become string keys. Those objects end up failing schema validation.

On a lark, I re-wrote the function like this, which seemed to work for my purpose, but didn't run any tests:

import Mustache from 'mustache';
import { isString, cloneDeep } from 'lodash';
import { AlertActionParams, State, Context } from '../types';

export function transformActionParams(params: AlertActionParams, state: State, context: Context) {
  return cloneDeep(params, value => {
    if (!isString(value)) return;

    return Mustache.render(value, { context, state });
  });
}
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

pmuellr added a commit to pmuellr/kibana that referenced this issue Aug 27, 2019
fixes elastic#44057

Prior to this fix, values inside an array were not subject to the
mustache transform.
pmuellr added a commit that referenced this issue Aug 27, 2019
* Fixes alert mustache templating with arrays

fixes #44057

Prior to this fix, values inside an array were not subject to the
mustache transform.
pmuellr added a commit to pmuellr/kibana that referenced this issue Aug 27, 2019
* Fixes alert mustache templating with arrays

fixes elastic#44057

Prior to this fix, values inside an array were not subject to the
mustache transform.
simianhacker pushed a commit to simianhacker/kibana that referenced this issue Aug 27, 2019
* Fixes alert mustache templating with arrays

fixes elastic#44057

Prior to this fix, values inside an array were not subject to the
mustache transform.
pmuellr added a commit that referenced this issue Aug 27, 2019
* Fixes alert mustache templating with arrays

fixes #44057

Prior to this fix, values inside an array were not subject to the
mustache transform.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants