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

[RAM] Use AAD When Running Action #161213

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0bd9cc7
first commit
jcger Jul 4, 2023
18f6b19
Merge branch 'main' of github.com:jcger/kibana into 158183-execution-…
jcger Jul 4, 2023
39e7854
Merge branch 'main' of github.com:elastic/kibana into 158183-executio…
XavierM Sep 14, 2023
8770756
Merge branch 'main' of github.com:elastic/kibana into 158183-executio…
XavierM Sep 14, 2023
e09c812
almost there + full plumbing for useAlertDataForTemplate
XavierM Sep 18, 2023
92a3551
clean up + move aad switch to a generic position
XavierM Sep 20, 2023
045576e
space between switch and form
jcger Sep 20, 2023
ff98eb1
fix jest tests
jcger Sep 20, 2023
c6a018c
update snapshot
jcger Sep 20, 2023
eac5015
add feature flags and autocomplete compont to triggers_actions_ui
jcger Sep 21, 2023
597b06d
fix test
jcger Sep 21, 2023
a3ac65c
fix tests
jcger Sep 21, 2023
4f1a43e
fix tests
jcger Sep 21, 2023
abdd1aa
fix tests
jcger Sep 21, 2023
c61caa6
Merge branch 'main' into 158183-execution-handler-refactor
jcger Sep 21, 2023
2d67457
rollback ff init and catch error
jcger Sep 21, 2023
78e00dd
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 21, 2023
6905044
catch switch ff error
jcger Sep 25, 2023
3d33741
Merge branch '158183-execution-handler-refactor' of github.com:jcger/…
jcger Sep 25, 2023
25cd6e3
fix test
jcger Sep 25, 2023
a8a891e
Merge branch 'main' of github.com:jcger/kibana into 158183-execution-…
jcger Sep 25, 2023
c214fa5
Merge branch 'main' into 158183-execution-handler-refactor
jcger Sep 25, 2023
e6216f3
rollback state
jcger Sep 25, 2023
c277450
Merge branch '158183-execution-handler-refactor' of github.com:jcger/…
jcger Sep 25, 2023
24d3ccb
fix test
jcger Sep 26, 2023
ea05545
Merge branch 'main' of github.com:jcger/kibana into 158183-execution-…
jcger Sep 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const actionSchema = schema.object({
params: schema.recordOf(schema.string(), schema.maybe(schema.any()), { defaultValue: {} }),
frequency: schema.maybe(actionFrequencySchema),
alerts_filter: schema.maybe(actionAlertsFilterSchema),
use_alert_data_for_template: schema.maybe(schema.boolean()),
});

export const createBodySchema = schema.object({
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/common/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface RuleAction {
params: RuleActionParams;
frequency?: RuleActionFrequency;
alertsFilter?: AlertsFilter;
useAlertDataForTemplate?: boolean;
}

export interface AggregateOptions {
Expand Down
19 changes: 17 additions & 2 deletions x-pack/plugins/alerting/server/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { v4 as uuidV4 } from 'uuid';
import { isEmpty } from 'lodash';
import { AADAlert } from '@kbn/alerts-as-data-utils';
import { MutableAlertInstanceMeta } from '@kbn/alerting-state-types';
import { AlertHit, CombinedSummarizedAlerts } from '../types';
import {
Expand Down Expand Up @@ -35,7 +36,7 @@ export type PublicAlert<
Context extends AlertInstanceContext = AlertInstanceContext,
ActionGroupIds extends string = DefaultActionGroupId
> = Pick<
Alert<State, Context, ActionGroupIds>,
Alert<State, Context, ActionGroupIds, AADAlert>,
| 'getContext'
| 'getState'
| 'getUuid'
Expand All @@ -49,13 +50,15 @@ export type PublicAlert<
export class Alert<
State extends AlertInstanceState = AlertInstanceState,
Context extends AlertInstanceContext = AlertInstanceContext,
ActionGroupIds extends string = never
ActionGroupIds extends string = never,
AlertAsData extends AADAlert = AADAlert
> {
private scheduledExecutionOptions?: ScheduledExecutionOptions<State, Context, ActionGroupIds>;
private meta: MutableAlertInstanceMeta;
private state: State;
private context: Context;
private readonly id: string;
private alertAsData: AlertAsData | undefined;

constructor(id: string, { state, meta = {} }: RawAlertInstance = {}) {
this.id = id;
Expand All @@ -77,6 +80,18 @@ export class Alert<
return this.meta.uuid!;
}

isAlertAsData() {
return this.alertAsData !== undefined;
}

setAlertAsData(alertAsData: AlertAsData) {
this.alertAsData = alertAsData;
}

getAlertAsData() {
return this.alertAsData;
}

getStart(): string | null {
return this.state.start ? `${this.state.start}` : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const createRuleDataSchema = schema.object({
),
uuid: schema.maybe(schema.string()),
alertsFilter: schema.maybe(actionAlertsFilterSchema),
useAlertDataForTemplate: schema.maybe(schema.boolean()),
}),
{ defaultValue: [] }
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const actionDomainSchema = schema.object({
params: actionParamsSchema,
frequency: schema.maybe(actionFrequencySchema),
alertsFilter: schema.maybe(actionDomainAlertsFilterSchema),
useAlertDataAsTemplate: schema.maybe(schema.boolean()),
});

/**
Expand All @@ -89,4 +90,5 @@ export const actionSchema = schema.object({
params: actionParamsSchema,
frequency: schema.maybe(actionFrequencySchema),
alertsFilter: schema.maybe(actionAlertsFilterSchema),
useAlertDataForTemplate: schema.maybe(schema.boolean()),
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const actionsSchema = schema.arrayOf(
),
})
),
use_alert_data_for_template: schema.maybe(schema.boolean()),
}),
{ defaultValue: [] }
);
59 changes: 35 additions & 24 deletions x-pack/plugins/alerting/server/routes/lib/rewrite_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@ export const rewriteActionsReq = (
): NormalizedAlertAction[] => {
if (!actions) return [];

return actions.map(({ frequency, alerts_filter: alertsFilter, ...action }) => {
return {
...action,
...(frequency
? {
frequency: {
...omit(frequency, 'notify_when'),
notifyWhen: frequency.notify_when,
},
}
: {}),
...(alertsFilter ? { alertsFilter } : {}),
};
});
return actions.map(
({
frequency,
alerts_filter: alertsFilter,
use_alert_data_for_template: useAlertDataForTemplate,
...action
}) => {
return {
...action,
useAlertDataForTemplate,
...(frequency
? {
frequency: {
...omit(frequency, 'notify_when'),
notifyWhen: frequency.notify_when,
},
}
: {}),
...(alertsFilter ? { alertsFilter } : {}),
};
}
);
};

export const rewriteActionsRes = (actions?: RuleAction[]) => {
Expand All @@ -37,14 +45,17 @@ export const rewriteActionsRes = (actions?: RuleAction[]) => {
notify_when: notifyWhen,
});
if (!actions) return [];
return actions.map(({ actionTypeId, frequency, alertsFilter, ...action }) => ({
...action,
connector_type_id: actionTypeId,
...(frequency ? { frequency: rewriteFrequency(frequency) } : {}),
...(alertsFilter
? {
alerts_filter: alertsFilter,
}
: {}),
}));
return actions.map(
({ actionTypeId, frequency, alertsFilter, useAlertDataForTemplate, ...action }) => ({
...action,
connector_type_id: actionTypeId,
use_alert_data_for_template: useAlertDataForTemplate,
...(frequency ? { frequency: rewriteFrequency(frequency) } : {}),
...(alertsFilter
? {
alerts_filter: alertsFilter,
}
: {}),
})
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ describe('createRuleRoute', () => {
},
connector_type_id: 'test',
uuid: '123-456',
use_alert_data_for_template: false,
},
],
};
Expand Down Expand Up @@ -198,6 +199,7 @@ describe('createRuleRoute', () => {
"params": Object {
"foo": true,
},
"useAlertDataForTemplate": undefined,
},
],
"alertTypeId": "1",
Expand Down Expand Up @@ -314,6 +316,7 @@ describe('createRuleRoute', () => {
"params": Object {
"foo": true,
},
"useAlertDataForTemplate": undefined,
},
],
"alertTypeId": "1",
Expand Down Expand Up @@ -431,6 +434,7 @@ describe('createRuleRoute', () => {
"params": Object {
"foo": true,
},
"useAlertDataForTemplate": undefined,
},
],
"alertTypeId": "1",
Expand Down Expand Up @@ -548,6 +552,7 @@ describe('createRuleRoute', () => {
"params": Object {
"foo": true,
},
"useAlertDataForTemplate": undefined,
},
],
"alertTypeId": "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@ import type { RuleParams } from '../../../../../../application/rule/types';
const transformCreateBodyActions = (actions: CreateRuleActionV1[]): CreateRuleData['actions'] => {
if (!actions) return [];

return actions.map(({ frequency, alerts_filter: alertsFilter, ...action }) => {
return {
group: action.group,
id: action.id,
params: action.params,
actionTypeId: action.actionTypeId,
...(action.uuid ? { uuid: action.uuid } : {}),
...(frequency
? {
frequency: {
summary: frequency.summary,
throttle: frequency.throttle,
notifyWhen: frequency.notify_when,
},
}
: {}),
...(alertsFilter ? { alertsFilter } : {}),
};
});
return actions.map(
({
frequency,
alerts_filter: alertsFilter,
use_alert_data_for_template: useAlertDataForTemplate,
...action
}) => {
return {
group: action.group,
id: action.id,
params: action.params,
actionTypeId: action.actionTypeId,
useAlertDataForTemplate,
...(action.uuid ? { uuid: action.uuid } : {}),
...(frequency
? {
frequency: {
summary: frequency.summary,
throttle: frequency.throttle,
notifyWhen: frequency.notify_when,
},
}
: {}),
...(alertsFilter ? { alertsFilter } : {}),
};
}
);
};

export const transformCreateBody = <Params extends RuleParams = never>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ export const transformRuleToRuleResponse = <Params extends RuleParams = never>(
consumer: rule.consumer,
schedule: rule.schedule,
actions: rule.actions.map(
({ group, id, actionTypeId, params, frequency, uuid, alertsFilter }) => ({
({
group,
id,
actionTypeId,
params,
frequency,
uuid,
alertsFilter,
useAlertDataForTemplate,
}) => ({
group,
id,
params,
connector_type_id: actionTypeId,
use_alert_data_for_template: useAlertDataForTemplate ?? false,
...(frequency
? {
frequency: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe('updateRuleRoute', () => {
"params": Object {
"baz": true,
},
"useAlertDataForTemplate": undefined,
"uuid": "1234-5678",
},
],
Expand Down
Loading