-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting] System action types and helpers (#167871)
In this PR: - Creation of types for the system actions - Creation of a helper function to detect if it is a system action or not - Use the `isSystemAction` in the executor to determine if an action is a system action - Pass the `isSystemConnector` utility function from the actions plugin to the rules factory - Create test utils to help test system actions and connector adapters ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
Showing
24 changed files
with
427 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/alerting/common/system_actions/is_system_action.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { RuleSystemAction, RuleActionTypes, RuleDefaultAction } from '../rule'; | ||
import { isSystemAction } from './is_system_action'; | ||
|
||
describe('isSystemAction', () => { | ||
const defaultAction: RuleDefaultAction = { | ||
actionTypeId: '.test', | ||
uuid: '111', | ||
group: 'default', | ||
id: '1', | ||
params: {}, | ||
type: RuleActionTypes.DEFAULT, | ||
}; | ||
|
||
const systemAction: RuleSystemAction = { | ||
id: '1', | ||
uuid: '123', | ||
params: { 'not-exist': 'test' }, | ||
actionTypeId: '.test', | ||
type: RuleActionTypes.SYSTEM, | ||
}; | ||
|
||
it('returns true if it is a system action', () => { | ||
expect(isSystemAction(systemAction)).toBe(true); | ||
}); | ||
|
||
it('returns false if it is not a system action', () => { | ||
expect(isSystemAction(defaultAction)).toBe(false); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/alerting/common/system_actions/is_system_action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { AsApiContract } from '@kbn/actions-plugin/common'; | ||
import { RuleAction, RuleSystemAction, RuleActionTypes } from '../rule'; | ||
|
||
type GetSystemActionType<T> = T extends RuleAction | ||
? RuleSystemAction | ||
: AsApiContract<RuleSystemAction>; | ||
|
||
export const isSystemAction = ( | ||
action: RuleAction | AsApiContract<RuleAction> | ||
): action is GetSystemActionType<typeof action> => action.type === RuleActionTypes.SYSTEM; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.