Skip to content

Commit

Permalink
Change naming for sub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 29, 2020
1 parent 796d344 commit 8e6713a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 76 deletions.
31 changes: 15 additions & 16 deletions x-pack/plugins/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ Table of Contents
- [`config`](#config-6)
- [`secrets`](#secrets-6)
- [`params`](#params-6)
- [`actionParams (pushToService)`](#actionparams-pushtoservice)
- [`subActionParams (pushToService)`](#subactionparams-pushtoservice)
- [Jira](#jira)
- [`config`](#config-7)
- [`secrets`](#secrets-7)
- [`params`](#params-7)
- [`actionParams (pushToService)`](#actionparams-pushtoservice-1)
- [`subActionParams (pushToService)`](#subactionparams-pushtoservice-1)
- [Command Line Utility](#command-line-utility)

## Terminology
Expand Down Expand Up @@ -149,8 +149,8 @@ This is the primary function for an action type. Whenever the action needs to ex
| actionId | The action saved object id that the action type is executing for. |
| config | The decrypted configuration given to an action. This comes from the action saved object that is partially or fully encrypted within the data store. If you would like to validate the config before being passed to the executor, define `validate.config` within the action type. |
| params | Parameters for the execution. These will be given at execution time by either an alert or manually provided when calling the plugin provided execute function. |
| services.callCluster(path, opts) | Use this to do Elasticsearch queries on the cluster Kibana connects to. This function is the same as any other `callCluster` in Kibana but runs in the context of the user who is calling the action when security is enabled.|
| services.getScopedCallCluster | This function scopes an instance of CallCluster by returning a `callCluster(path, opts)` function that runs in the context of the user who is calling the action when security is enabled. This must only be called with instances of CallCluster provided by core.|
| services.callCluster(path, opts) | Use this to do Elasticsearch queries on the cluster Kibana connects to. This function is the same as any other `callCluster` in Kibana but runs in the context of the user who is calling the action when security is enabled. |
| services.getScopedCallCluster | This function scopes an instance of CallCluster by returning a `callCluster(path, opts)` function that runs in the context of the user who is calling the action when security is enabled. This must only be called with instances of CallCluster provided by core. |
| services.savedObjectsClient | This is an instance of the saved objects client. This provides the ability to do CRUD on any saved objects within the same space the alert lives in.<br><br>The scope of the saved objects client is tied to the user in context calling the execute API or the API key provided to the execute plugin function (only when security isenabled). |
| services.log(tags, [data], [timestamp]) | Use this to create server logs. (This is the same function as server.log) |

Expand Down Expand Up @@ -489,12 +489,12 @@ The ServiceNow action uses the [V2 Table API](https://developer.servicenow.com/a

### `params`

| Property | Description | Type |
| ------------ | -------------------------------------------------------------------------------- | ------ |
| action | The action to perform. It can be `pushToService`, `handshake`, and `getIncident` | string |
| actionParams | The parameters of the action | object |
| Property | Description | Type |
| --------------- | ------------------------------------------------------------------------------------ | ------ |
| subAction | The sub action to perform. It can be `pushToService`, `handshake`, and `getIncident` | string |
| subActionParams | The parameters of the sub action | object |

#### `actionParams (pushToService)`
#### `subActionParams (pushToService)`

| Property | Description | Type |
| ----------- | -------------------------------------------------------------------------------------------------------------------------- | --------------------- |
Expand All @@ -504,10 +504,9 @@ The ServiceNow action uses the [V2 Table API](https://developer.servicenow.com/a
| comments | The comments of the case. A comment is of the form `{ commentId: string, version: string, comment: string }` | object[] _(optional)_ |
| externalId | The id of the incident in ServiceNow . If presented the incident will be update. Otherwise a new incident will be created. | string _(optional)_ |


---

## Jira
## Jira

ID: `.jira`

Expand All @@ -529,12 +528,12 @@ The Jira action uses the [V2 API](https://developer.atlassian.com/cloud/jira/pla

### `params`

| Property | Description | Type |
| ------------ | -------------------------------------------------------------------------------- | ------ |
| action | The action to perform. It can be `pushToService`, `handshake`, and `getIncident` | string |
| actionParams | The parameters of the action | object |
| Property | Description | Type |
| --------------- | ------------------------------------------------------------------------------------ | ------ |
| subAction | The sub action to perform. It can be `pushToService`, `handshake`, and `getIncident` | string |
| subActionParams | The parameters of the sub action | object |

#### `actionParams (pushToService)`
#### `subActionParams (pushToService)`

| Property | Description | Type |
| ----------- | ------------------------------------------------------------------------------------------------------------------- | --------------------- |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export const ExecutorActionParams = {
export const ExecutorActionParamsSchema = schema.object(ExecutorActionParams);

export const ExecutorParamsSchema = schema.object({
action: ExecutorActionSchema,
actionParams: ExecutorActionParamsSchema,
subAction: ExecutorActionSchema,
subActionParams: ExecutorActionParamsSchema,
});
12 changes: 6 additions & 6 deletions x-pack/plugins/actions/server/builtin_action_types/case/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const createConnectorExecutor = ({
} = execOptions.config as ConnectorPublicConfigurationType;

const params = execOptions.params as ExecutorParams;
const { action, actionParams } = params;
const { comments, externalId, ...restParams } = actionParams;
const { subAction, subActionParams } = params;
const { comments, externalId, ...restParams } = subActionParams;

const mapping = buildMap(configurationMapping);
const externalCase = mapParams(restParams as ExecutorActionParams, mapping);
Expand All @@ -89,14 +89,14 @@ export const createConnectorExecutor = ({
secrets: execOptions.secrets,
});

if (!api[action]) {
throw new Error('[Action][Connector] Unsupported action type');
if (!api[subAction]) {
throw new Error('[Action][Connector] Unsupported subAction type');
}

const data = await api[action]({
const data = await api[subAction]({
externalService,
mapping,
params: { ...actionParams, externalCase },
params: { ...subActionParams, externalCase },
});

return {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/siem/public/containers/case/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ describe('Case Configuration API', () => {
await pushToService(connectorId, casePushParams, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`/api/action/${connectorId}/_execute`, {
method: 'POST',
body: JSON.stringify({ params: { action: 'pushToService', actionParams: casePushParams } }),
body: JSON.stringify({
params: { subAction: 'pushToService', subActionParams: casePushParams },
}),
signal: abortCtrl.signal,
});
});
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/siem/public/containers/case/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export const pushToService = async (
`${ACTION_URL}/${connectorId}/_execute`,
{
method: 'POST',
body: JSON.stringify({ params: { action: 'pushToService', actionParams: casePushParams } }),
body: JSON.stringify({
params: { subAction: 'pushToService', subActionParams: casePushParams },
}),
signal,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export default function jiraTest({ getService }: FtrProviderContext) {
email: 'elastic@elastic.co',
},
params: {
action: 'pushToService',
actionParams: {
subAction: 'pushToService',
subActionParams: {
caseId: '123',
title: 'a title',
description: 'a description',
Expand Down Expand Up @@ -326,7 +326,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [action]: expected at least one defined value but got [undefined]',
'error validating action params: [subAction]: expected at least one defined value but got [undefined]',
});
});
});
Expand All @@ -336,33 +336,33 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.post(`/api/action/${simulatedActionId}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: { action: 'non-supported' },
params: { subAction: 'non-supported' },
})
.then((resp: any) => {
expect(resp.body).to.eql({
actionId: simulatedActionId,
status: 'error',
retry: false,
message:
'error validating action params: [action]: types that failed validation:\n- [action.0]: expected value to equal [getIncident]\n- [action.1]: expected value to equal [pushToService]\n- [action.2]: expected value to equal [handshake]',
'error validating action params: [subAction]: types that failed validation:\n- [subAction.0]: expected value to equal [getIncident]\n- [subAction.1]: expected value to equal [pushToService]\n- [subAction.2]: expected value to equal [handshake]',
});
});
});

it('should handle failing with a simulated success without actionParams', async () => {
it('should handle failing with a simulated success without subActionParams', async () => {
await supertest
.post(`/api/action/${simulatedActionId}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: { action: 'pushToService' },
params: { subAction: 'pushToService' },
})
.then((resp: any) => {
expect(resp.body).to.eql({
actionId: simulatedActionId,
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.caseId]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.caseId]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -372,15 +372,15 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.post(`/api/action/${simulatedActionId}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: { action: 'pushToService', actionParams: {} },
params: { subAction: 'pushToService', subActionParams: {} },
})
.then((resp: any) => {
expect(resp.body).to.eql({
actionId: simulatedActionId,
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.caseId]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.caseId]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -392,7 +392,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.send({
params: {
...mockJira.params,
actionParams: {
subActionParams: {
caseId: 'success',
},
},
Expand All @@ -403,7 +403,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.title]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.title]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -415,7 +415,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.send({
params: {
...mockJira.params,
actionParams: {
subActionParams: {
caseId: 'success',
title: 'success',
},
Expand All @@ -427,7 +427,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.createdAt]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.createdAt]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -439,8 +439,8 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.send({
params: {
...mockJira.params,
actionParams: {
...mockJira.params.actionParams,
subActionParams: {
...mockJira.params.subActionParams,
caseId: 'success',
title: 'success',
createdAt: 'success',
Expand All @@ -455,7 +455,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.comments.0.commentId]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.comments.0.commentId]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -467,8 +467,8 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.send({
params: {
...mockJira.params,
actionParams: {
...mockJira.params.actionParams,
subActionParams: {
...mockJira.params.subActionParams,
caseId: 'success',
title: 'success',
createdAt: 'success',
Expand All @@ -483,7 +483,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.comments.0.comment]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.comments.0.comment]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -495,8 +495,8 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.send({
params: {
...mockJira.params,
actionParams: {
...mockJira.params.actionParams,
subActionParams: {
...mockJira.params.subActionParams,
caseId: 'success',
title: 'success',
createdAt: 'success',
Expand All @@ -511,7 +511,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [actionParams.comments.0.createdAt]: expected value of type [string] but got [undefined]',
'error validating action params: [subActionParams.comments.0.createdAt]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -525,8 +525,8 @@ export default function jiraTest({ getService }: FtrProviderContext) {
.send({
params: {
...mockJira.params,
actionParams: {
...mockJira.params.actionParams,
subActionParams: {
...mockJira.params.subActionParams,
comments: [],
},
},
Expand Down
Loading

0 comments on commit 8e6713a

Please sign in to comment.