-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Security Solution] [Cases] Swimlane Connector for Cases #100086
Merged
cnasikas
merged 119 commits into
elastic:master
from
stephmilovic:field_mapping_connector
Jun 23, 2021
Merged
Changes from 24 commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
85fe84e
Adding swimlane connector
joshswimlane cf2eb78
Merge branch 'master' of github.com:elastic/kibana into field_mapping…
XavierM 3bb04dc
clean up + rm rejectUnauthorized
XavierM badc8f3
Merge 3bb04dc0aac098e591937592287a411de66a19fb into 639f8290ffcb28560…
XavierM b76f426
Merge branch 'master' of github.com:elastic/kibana into field_mapping…
XavierM d243b0e
Merge b76f426a86cca6bd74f45363f8858d930715158e into d111c27808e16f961…
XavierM 9a2f02e
Merge branch 'field_mapping_connector_2' into field_mapping_connector
stephmilovic 9c7ce14
wip
stephmilovic 440fa5e
better types
stephmilovic 9d9662f
cases maps
stephmilovic fa1f749
fix types
stephmilovic 796712c
working on fields
stephmilovic 377fd0a
can push case to swimlane
stephmilovic 9384d9f
Merge branch 'master' into field_mapping_connector
stephmilovic 6e699b3
working well
stephmilovic 1acf2fa
fixed jest
stephmilovic 19a2da7
fixing
stephmilovic e92dd16
made connector better
stephmilovic 9595350
fix and add func tests
stephmilovic 45be23a
Merge branch 'master' into field_mapping_connector
stephmilovic 1bab00d
jsx
stephmilovic b527f54
schema fix
stephmilovic 617328f
fix type in test
stephmilovic 2f23cb4
Minor improvements
cnasikas b3e2ff6
Adding swimlane docs
jonathan-buttner 410036e
Improve type
cnasikas 060531a
Fix case connector schema
cnasikas dcaab5b
Move getApplicatio to the backend
cnasikas 439ecff
Prevent prototype polution from fields
cnasikas a4f27d1
Add tests
cnasikas 34dee16
Revert commit dcaab5b0f5f
cnasikas 32d76d7
Fixing logout issue
jonathan-buttner a180758
Merge branch 'master' into field_mapping_connector
kibanamachine b51be9f
Minor improvements
cnasikas a532b41
Merge branch 'field_mapping_connector' of github.com:stephmilovic/kib…
cnasikas abba08c
Prevent prototype polution from fields
cnasikas e15c83c
Add description field
cnasikas 97892b2
Make alert name optional
cnasikas aff1000
Change case mapping
cnasikas 15e442f
Remove cases fields UI
cnasikas 2a3ccf2
Delete comments from incident
cnasikas 4cd8a46
Clear fields if needed
cnasikas 9c28c13
Change reset to configure API
cnasikas dd1a32d
Improve components
cnasikas 671b968
Merge branch 'master' into field_mapping_connector
kibanamachine d64875e
Lazy load svg icon
cnasikas bf6bdb6
Improve step status
cnasikas 5f03f75
Fix params, api, & schema
cnasikas ba8c671
Create connector types
cnasikas 851c880
Small fixes
cnasikas bf1f493
Show warning when mapping is empty
cnasikas ee23c03
Remove case name from fields
cnasikas 9790343
Show connector card
cnasikas a2efccf
Remove unecessary code
cnasikas ef4f3b9
Show warning message when connector is not of type cases
cnasikas f28e4f5
Show warning message when connector is not of type alerts
cnasikas 1a68b0e
Remove optional from target mapping field
cnasikas 79c8bfd
Fix types
cnasikas e33403f
Improve order
cnasikas a237cb0
Fix tests
cnasikas 2c39f9b
Merge branch 'master' into field_mapping_connector
kibanamachine fbbd762
Improve responses
cnasikas 2c72b6d
Small fixes
cnasikas e9f5a57
Fix integration tests
cnasikas b8f2c0d
Update readme
cnasikas f7b8871
Switch to button group
cnasikas bd062c2
Better translation for required fields
cnasikas 835f62b
Change buttons width
cnasikas 68fc3ef
Compress buttons
cnasikas cc7d41f
Make case id required
cnasikas bc9ac93
Rename to rule name
cnasikas 26d3523
Fix translation
cnasikas ed87bc4
Add alert id field
cnasikas 2ab916b
Reorder fields
cnasikas d0d4f77
Fixes
cnasikas b283be8
Fix validation
cnasikas a83e7d5
Add alert id to params
cnasikas 5edc02d
Show mapping if any of the required fields is missing
cnasikas e21eb4e
Add tests
cnasikas 9f1ff56
Merge branch 'master' into field_mapping_connector
cnasikas 0b7eeb6
Fix creation of default mapping
cnasikas 1a98afc
Merge branch 'master' into field_mapping_connector
cnasikas 6d29a7b
Hide alert id and alert name
cnasikas 34e08da
Async validation
cnasikas d51a24f
Improve field step status
cnasikas 63a5bb5
Fix tests
cnasikas 4b8e2bb
Switch to http server
cnasikas 89633e0
Merge branch 'master' into field_mapping_connector
cnasikas 110baf2
Merge branch 'master' into field_mapping_connector
cnasikas 3eb39e9
Switch to new mapping
cnasikas 36aa3b8
Improve callout message
cnasikas f4771de
Add help text to alert source
cnasikas 762c095
Improve helpers
cnasikas a8b9462
Improve tests
cnasikas cc5b10a
Improve messages
cnasikas aa79a78
Fix bug when using connector of type all
cnasikas 2e3aa1c
Fix bug when creating connector
cnasikas f33ec56
Merge branch 'master' into field_mapping_connector
cnasikas 18c37d7
Add cases_fields tests
cnasikas 57ac290
Improve docs
cnasikas 0e91329
Fix docs
cnasikas d3677d1
Remove alert source
cnasikas 17ffdd5
Add more tests
cnasikas ab0fa38
Fix tests
cnasikas ae4a85d
Improve error message
cnasikas f110d0c
Merge branch 'master' into field_mapping_connector
cnasikas cf9a26e
Merge branch 'master' into field_mapping_connector
kibanamachine fc46dcf
Merge branch 'master' into field_mapping_connector
kibanamachine 223b334
Close server after the end of tests
cnasikas 2672be7
Add status code to error messages
cnasikas 6f6ba26
PR feedback
cnasikas ae9b807
Merge branch 'field_mapping_connector' of github.com:stephmilovic/kib…
cnasikas c048432
Merge branch 'master' of github.com:elastic/kibana into field_mapping…
jonathan-buttner c129d22
Fix readme
cnasikas 3d7d894
Add more tests for helpers
cnasikas 72f6202
PR feedback
cnasikas cf6f927
Hide error message with css
cnasikas e16a51d
Merge branch 'field_mapping_connector' of github.com:stephmilovic/kib…
cnasikas 2bf467a
Merge branch 'master' into field_mapping_connector
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
96 changes: 96 additions & 0 deletions
96
x-pack/plugins/actions/server/builtin_action_types/swimlane/api.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,96 @@ | ||
/* | ||
* 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 { api } from './api'; | ||
import { ExternalService } from './types'; | ||
import { externalServiceMock, recordResponseCreate, recordResponseUpdate } from './mocks'; | ||
import { Logger } from '@kbn/logging'; | ||
let mockedLogger: jest.Mocked<Logger>; | ||
const params = { | ||
alertName: 'alert name', | ||
caseName: 'case name', | ||
severity: 'critical', | ||
alertSource: 'elastic', | ||
caseId: '123456', | ||
comments: 'some comments', | ||
}; | ||
describe('api', () => { | ||
let externalService: jest.Mocked<ExternalService>; | ||
|
||
beforeEach(() => { | ||
externalService = externalServiceMock.create(); | ||
}); | ||
|
||
describe('createRecord', () => { | ||
test('it creates a record correctly with a comment', async () => { | ||
const res = await api.createRecord({ | ||
externalService, | ||
logger: mockedLogger, | ||
params: { | ||
alertName: 'alert name', | ||
caseName: 'case name', | ||
severity: 'critical', | ||
alertSource: 'elastic', | ||
caseId: '123456', | ||
comments: 'some comments', | ||
}, | ||
}); | ||
expect(res).toEqual(recordResponseCreate); | ||
}); | ||
}); | ||
|
||
describe('pushToService', () => { | ||
test('it pushes a new record', async () => { | ||
const res = await api.pushToService({ | ||
externalService, | ||
logger: mockedLogger, | ||
params: { | ||
incident: { | ||
...params, | ||
externalId: null, | ||
}, | ||
comments: [], | ||
}, | ||
}); | ||
expect(externalService.createComment).not.toHaveBeenCalled(); | ||
expect(externalService.createRecord).toHaveBeenCalled(); | ||
expect(externalService.updateRecord).not.toHaveBeenCalled(); | ||
expect(res).toEqual(recordResponseCreate); | ||
}); | ||
test('it pushes a new record with a comment', async () => { | ||
await api.pushToService({ | ||
externalService, | ||
logger: mockedLogger, | ||
params: { | ||
incident: { | ||
...params, | ||
externalId: null, | ||
}, | ||
comments: [{ comment: 'some comments', commentId: '123' }], | ||
}, | ||
}); | ||
expect(externalService.createComment).toHaveBeenCalled(); | ||
}); | ||
test('updates existing record', async () => { | ||
const res = await api.pushToService({ | ||
externalService, | ||
logger: mockedLogger, | ||
params: { | ||
incident: { | ||
...params, | ||
externalId: '1234', | ||
}, | ||
comments: [{ comment: 'some comments', commentId: '123' }], | ||
}, | ||
}); | ||
expect(externalService.createComment).toHaveBeenCalled(); | ||
expect(externalService.createRecord).not.toHaveBeenCalled(); | ||
expect(externalService.updateRecord).toHaveBeenCalled(); | ||
expect(res).toEqual(recordResponseUpdate); | ||
}); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/actions/server/builtin_action_types/swimlane/api.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,57 @@ | ||
/* | ||
* 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 { | ||
CreateRecordApiHandlerArgs, | ||
ExternalServiceIncidentResponse, | ||
ExternalServiceApi, | ||
Incident, | ||
PushToServiceApiHandlerArgs, | ||
} from './types'; | ||
|
||
const createRecordHandler = async ({ | ||
externalService, | ||
params, | ||
}: CreateRecordApiHandlerArgs): Promise<ExternalServiceIncidentResponse> => { | ||
return await externalService.createRecord({ incident: { ...params, externalId: null } }); | ||
}; | ||
|
||
const pushToServiceHandler = async ({ | ||
externalService, | ||
params, | ||
}: PushToServiceApiHandlerArgs): Promise<ExternalServiceIncidentResponse> => { | ||
const { comments } = params; | ||
let res: ExternalServiceIncidentResponse; | ||
const incident: Incident = params.incident; | ||
if (incident.externalId != null) { | ||
res = await externalService.updateRecord({ | ||
incidentId: incident.externalId, | ||
incident, | ||
}); | ||
} else { | ||
res = await externalService.createRecord({ incident }); | ||
} | ||
|
||
const createdDate = new Date().toISOString(); | ||
|
||
if (comments && Array.isArray(comments) && comments.length > 0) { | ||
for (const currentComment of comments) { | ||
await externalService.createComment({ | ||
incidentId: res.id, | ||
comment: currentComment, | ||
createdDate, | ||
}); | ||
} | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
export const api: ExternalServiceApi = { | ||
createRecord: createRecordHandler, | ||
pushToService: pushToServiceHandler, | ||
}; |
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/actions/server/builtin_action_types/swimlane/helpers.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,76 @@ | ||
/* | ||
* 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 { MappingConfigType } from './types'; | ||
import { getBodyForEventAction } from './helpers'; | ||
|
||
describe('Create Record Mapping', () => { | ||
let mappingConfig: MappingConfigType; | ||
const appId = '45678'; | ||
|
||
beforeAll(() => { | ||
mappingConfig = { | ||
alertSourceConfig: { | ||
id: 'adnjls', | ||
name: 'Alert Source', | ||
key: 'alert-source', | ||
fieldType: 'text', | ||
}, | ||
severityConfig: { | ||
id: 'adnlas', | ||
name: 'Severity', | ||
key: 'severity', | ||
fieldType: 'text', | ||
}, | ||
alertNameConfig: { | ||
id: 'adnfls', | ||
name: 'Alert Name', | ||
key: 'alert-name', | ||
fieldType: 'text', | ||
}, | ||
caseIdConfig: { | ||
id: 'a6sst', | ||
name: 'Case Id', | ||
key: 'case-id-name', | ||
fieldType: 'text', | ||
}, | ||
caseNameConfig: { | ||
id: 'a6fst', | ||
name: 'Case Name', | ||
key: 'case-name', | ||
fieldType: 'text', | ||
}, | ||
commentsConfig: { | ||
id: 'a6fdf', | ||
name: 'Comments', | ||
key: 'comments', | ||
fieldType: 'text', | ||
}, | ||
}; | ||
}); | ||
|
||
test('Mapping is Successful', () => { | ||
const params = { | ||
alertName: 'Alert Name', | ||
severity: 'Critical', | ||
alertSource: 'Elastic', | ||
caseName: 'Case Name', | ||
caseId: 'es3456789', | ||
comments: 'This is a comment', | ||
externalId: null, | ||
}; | ||
const data = getBodyForEventAction(appId, mappingConfig, params); | ||
expect(data?.values?.[mappingConfig.alertSourceConfig?.id ?? 0]).toEqual(params.alertSource); | ||
expect(data?.values?.[mappingConfig.alertNameConfig.id]).toEqual(params.alertName); | ||
// @ts-ignore | ||
expect(data?.values?.[mappingConfig.caseNameConfig.id]).toEqual(params.caseName); | ||
expect(data?.values?.[mappingConfig.caseIdConfig?.id ?? 0]).toEqual(params.caseId); | ||
// @ts-ignore | ||
expect(data?.values?.[mappingConfig.commentsConfig.id]).toEqual(params.comments); | ||
expect(data?.values?.[mappingConfig?.severityConfig?.id ?? 0]).toEqual(params.severity); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This README Swimlane info looks good, but what about the rest of the connector documentation - are you going to add it in the separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a stab at the docs here: b3e2ff6
Is there a way to preview them so that the images load 🤔 ?