Skip to content

Commit

Permalink
[7.x] [Security Solutions][Case] Settings per case per connector (#77327
Browse files Browse the repository at this point in the history
) (#79716)

Co-authored-by: Xavier Mouligneau <[email protected]>
Co-authored-by: Steph Milovic <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
4 people authored Oct 6, 2020
1 parent 570f2d2 commit 0bc3a79
Show file tree
Hide file tree
Showing 154 changed files with 8,612 additions and 959 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ describe('api', () => {

expect(externalService.createIncident).toHaveBeenCalledWith({
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
description:
'Incident description (created at 2020-04-27T10:59:46.202Z by Elastic User)',
summary: 'Incident title (created at 2020-04-27T10:59:46.202Z by Elastic User)',
Expand Down Expand Up @@ -233,6 +237,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
description:
'Incident description (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
summary: 'Incident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
Expand Down Expand Up @@ -443,6 +451,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
summary: 'Incident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
description:
'description from jira \r\nIncident description (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
Expand Down Expand Up @@ -480,6 +492,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
description:
'description from jira \r\nIncident description (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
},
Expand Down Expand Up @@ -516,6 +532,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
summary:
'title from jira \r\nIncident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
description:
Expand Down Expand Up @@ -553,7 +573,12 @@ describe('api', () => {
});
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {},
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
},
});
});

Expand Down Expand Up @@ -587,6 +612,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
summary: 'Incident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
},
});
Expand Down Expand Up @@ -622,6 +651,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
summary: 'Incident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
description:
'Incident description (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
Expand Down Expand Up @@ -659,6 +692,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
description:
'Incident description (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
},
Expand Down Expand Up @@ -695,6 +732,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
summary:
'title from jira \r\nIncident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
description:
Expand Down Expand Up @@ -733,6 +774,10 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
labels: ['kibana', 'elastic'],
priority: 'High',
issueType: '10006',
parent: null,
summary:
'title from jira \r\nIncident title (updated at 2020-04-27T10:59:46.202Z by Elastic User)',
},
Expand Down
16 changes: 15 additions & 1 deletion x-pack/plugins/actions/server/builtin_action_types/jira/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,25 @@ const pushToServiceHandler = async ({
defaultPipes,
});

incident = transformFields<PushToServiceApiParams, ExternalServiceParams, Incident>({
const transformedFields = transformFields<
PushToServiceApiParams,
ExternalServiceParams,
Incident
>({
params,
fields,
currentIncident,
});

const { priority, labels, issueType, parent } = params;
incident = {
summary: transformedFields.summary,
description: transformedFields.description,
priority,
labels,
issueType,
parent,
};
} else {
const { title, description, priority, labels, issueType, parent } = params;
incident = { summary: title, description, priority, labels, issueType, parent };
Expand Down
34 changes: 24 additions & 10 deletions x-pack/plugins/actions/server/builtin_action_types/jira/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ export const createExternalService = (
return fields;
};

const createErrorMessage = (errors: ResponseError) => {
const createErrorMessage = (errorResponse: ResponseError | null | undefined): string => {
if (errorResponse == null) {
return '';
}

const { errorMessages, errors } = errorResponse;

if (errors == null) {
return '';
}

if (Array.isArray(errorMessages) && errorMessages.length > 0) {
return `${errorMessages.join(', ')}`;
}

return Object.entries(errors).reduce((errorMessage, [, value]) => {
const msg = errorMessage.length > 0 ? `${errorMessage} ${value}` : value;
return msg;
Expand Down Expand Up @@ -154,7 +168,7 @@ export const createExternalService = (
i18n.NAME,
`Unable to get incident with id ${id}. Error: ${
error.message
} Reason: ${createErrorMessage(error.response?.data?.errors ?? {})}`
} Reason: ${createErrorMessage(error.response?.data)}`
)
);
}
Expand Down Expand Up @@ -207,7 +221,7 @@ export const createExternalService = (
getErrorMessage(
i18n.NAME,
`Unable to create incident. Error: ${error.message}. Reason: ${createErrorMessage(
error.response?.data?.errors ?? {}
error.response?.data
)}`
)
);
Expand Down Expand Up @@ -249,7 +263,7 @@ export const createExternalService = (
i18n.NAME,
`Unable to update incident with id ${incidentId}. Error: ${
error.message
}. Reason: ${createErrorMessage(error.response?.data?.errors ?? {})}`
}. Reason: ${createErrorMessage(error.response?.data)}`
)
);
}
Expand Down Expand Up @@ -280,7 +294,7 @@ export const createExternalService = (
i18n.NAME,
`Unable to create comment at incident with id ${incidentId}. Error: ${
error.message
}. Reason: ${createErrorMessage(error.response?.data?.errors ?? {})}`
}. Reason: ${createErrorMessage(error.response?.data)}`
)
);
}
Expand All @@ -302,7 +316,7 @@ export const createExternalService = (
getErrorMessage(
i18n.NAME,
`Unable to get capabilities. Error: ${error.message}. Reason: ${createErrorMessage(
error.response?.data?.errors ?? {}
error.response?.data
)}`
)
);
Expand Down Expand Up @@ -342,7 +356,7 @@ export const createExternalService = (
getErrorMessage(
i18n.NAME,
`Unable to get issue types. Error: ${error.message}. Reason: ${createErrorMessage(
error.response?.data?.errors ?? {}
error.response?.data
)}`
)
);
Expand Down Expand Up @@ -388,7 +402,7 @@ export const createExternalService = (
getErrorMessage(
i18n.NAME,
`Unable to get fields. Error: ${error.message}. Reason: ${createErrorMessage(
error.response?.data?.errors ?? {}
error.response?.data
)}`
)
);
Expand All @@ -415,7 +429,7 @@ export const createExternalService = (
getErrorMessage(
i18n.NAME,
`Unable to get issues. Error: ${error.message}. Reason: ${createErrorMessage(
error.response?.data?.errors ?? {}
error.response?.data
)}`
)
);
Expand All @@ -439,7 +453,7 @@ export const createExternalService = (
getErrorMessage(
i18n.NAME,
`Unable to get issue with id ${id}. Error: ${error.message}. Reason: ${createErrorMessage(
error.response?.data?.errors ?? {}
error.response?.data
)}`
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ export interface Fields {
[key: string]: string | string[] | { name: string } | { key: string } | { id: string };
}
export interface ResponseError {
[k: string]: string;
errorMessages: string[] | null | undefined;
errors: { [k: string]: string } | null | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ describe('api', () => {

expect(externalService.createIncident).toHaveBeenCalledWith({
incident: {
incidentTypes: [1001],
severityCode: 6,
description:
'Incident description (created at 2020-06-03T15:09:13.606Z by Elastic User)',
name: 'Incident title (created at 2020-06-03T15:09:13.606Z by Elastic User)',
Expand Down Expand Up @@ -175,6 +177,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
description:
'Incident description (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
name: 'Incident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
Expand Down Expand Up @@ -298,6 +302,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
name: 'Incident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
description:
'description from ibm resilient \r\nIncident description (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
Expand Down Expand Up @@ -335,6 +341,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
description:
'description from ibm resilient \r\nIncident description (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
},
Expand Down Expand Up @@ -371,6 +379,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
name:
'title from ibm resilient \r\nIncident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
description:
Expand Down Expand Up @@ -408,7 +418,10 @@ describe('api', () => {
});
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {},
incident: {
incidentTypes: [1001],
severityCode: 6,
},
});
});

Expand Down Expand Up @@ -442,6 +455,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
name: 'Incident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
},
});
Expand Down Expand Up @@ -477,6 +492,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
name: 'Incident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
description:
'Incident description (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
Expand Down Expand Up @@ -514,6 +531,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
description:
'Incident description (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
},
Expand Down Expand Up @@ -550,6 +569,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
name:
'title from ibm resilient \r\nIncident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
description:
Expand Down Expand Up @@ -588,6 +609,8 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledWith({
incidentId: 'incident-3',
incident: {
incidentTypes: [1001],
severityCode: 6,
name:
'title from ibm resilient \r\nIncident title (updated at 2020-06-03T15:09:13.606Z by Elastic User)',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,23 @@ const pushToServiceHandler = async ({
defaultPipes,
});

incident = transformFields<PushToServiceApiParams, ExternalServiceParams, Incident>({
const transformedFields = transformFields<
PushToServiceApiParams,
ExternalServiceParams,
Incident
>({
params,
fields,
currentIncident,
});

const { incidentTypes, severityCode } = params;
incident = {
name: transformedFields.name,
description: transformedFields.description,
incidentTypes,
severityCode,
};
} else {
const { title, description, incidentTypes, severityCode } = params;
incident = { name: title, description, incidentTypes, severityCode };
Expand Down
Loading

0 comments on commit 0bc3a79

Please sign in to comment.