-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cases] Migrate user actions connector ID #108272
Merged
jonathan-buttner
merged 44 commits into
elastic:master
from
jonathan-buttner:migrate-ua-connector-id
Sep 20, 2021
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
001d5f8
Making progress
jonathan-buttner a693539
Fleshing out the extraction logic
jonathan-buttner 8756963
Finishing migration logic and starting more tests
jonathan-buttner d2f6c63
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner a145ef6
Finishing migration unit tests
jonathan-buttner e2cd0e9
Making progress on services
jonathan-buttner fe673ad
Finishing transform to es schema
jonathan-buttner b4bd652
Finishing transform functionality and unit tests
jonathan-buttner 79fe37f
reverting migration data updates
jonathan-buttner 3c55ad9
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 0280916
Cleaning up type errors
jonathan-buttner 4c3407c
fixing test error
jonathan-buttner 8e10d92
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 01a42e9
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 510fd76
Working migration tests
jonathan-buttner 311f21d
Refactoring retrieval of connector fields
jonathan-buttner 7dbe51c
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 9051b14
Refactoring connector id in and tests in frontend
jonathan-buttner 297c2d0
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 2bda621
Fixing tests and finished refactoring parse string
jonathan-buttner 5f4f4f8
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner d08d495
Fixing integration test
jonathan-buttner a149ec8
Fixing integration tests
jonathan-buttner 7b09642
Removing some duplicate code and updating test name
jonathan-buttner 3fcf158
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner d45de7b
Fixing create connector user action bug
jonathan-buttner 258c6c2
Addressing feedback and logging error
jonathan-buttner 43cc5e8
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 463a9a0
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 5379a07
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner bd4ffe4
Merge branch 'master' into migrate-ua-connector-id
kibanamachine 646cf65
Merge branch 'master' into migrate-ua-connector-id
kibanamachine 02aa71b
Merge branch 'master' into migrate-ua-connector-id
kibanamachine 64f0d56
Merge branch 'master' into migrate-ua-connector-id
kibanamachine 785d7a8
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner ffd5d6f
Moving parsing function to common
jonathan-buttner a09fbd1
Fixing type errors
jonathan-buttner 4d467b5
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 2b9efd0
Fixing type errors
jonathan-buttner cf7319b
Merge branch 'master' into migrate-ua-connector-id
kibanamachine ed559de
Addressing feedback
jonathan-buttner 63545be
Merge branch 'master' of github.com:elastic/kibana into migrate-ua-co…
jonathan-buttner 25c8fa4
Fixing lint errors
jonathan-buttner f3473b7
Merge branch 'master' into migrate-ua-connector-id
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,14 +84,22 @@ export const ConnectorTypeFieldsRt = rt.union([ | |
ConnectorSwimlaneTypeFieldsRt, | ||
]); | ||
|
||
/** | ||
* This type represents the connector's format when it is encoded within a user action. | ||
*/ | ||
export const CaseUserActionConnectorRt = rt.intersection([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type just lacks the |
||
rt.type({ name: rt.string }), | ||
ConnectorTypeFieldsRt, | ||
]); | ||
|
||
export const CaseConnectorRt = rt.intersection([ | ||
rt.type({ | ||
id: rt.string, | ||
name: rt.string, | ||
}), | ||
ConnectorTypeFieldsRt, | ||
CaseUserActionConnectorRt, | ||
]); | ||
|
||
export type CaseUserActionConnector = rt.TypeOf<typeof CaseUserActionConnectorRt>; | ||
export type CaseConnector = rt.TypeOf<typeof CaseConnectorRt>; | ||
export type ConnectorTypeFields = rt.TypeOf<typeof ConnectorTypeFieldsRt>; | ||
export type ConnectorJiraTypeFields = rt.TypeOf<typeof ConnectorJiraTypeFieldsRt>; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export function isCreateConnector(action?: string, actionFields?: string[]): boolean { | ||
return action === 'create' && actionFields != null && actionFields.includes('connector'); | ||
} | ||
|
||
export function isUpdateConnector(action?: string, actionFields?: string[]): boolean { | ||
return action === 'update' && actionFields != null && actionFields.includes('connector'); | ||
} | ||
|
||
export function isPush(action?: string, actionFields?: string[]): boolean { | ||
return action === 'push-to-service' && actionFields != null && actionFields.includes('pushed'); | ||
} |
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './parsers'; |
86 changes: 86 additions & 0 deletions
86
x-pack/plugins/cases/public/common/user_actions/parsers.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,86 @@ | ||
/* | ||
* 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 { ConnectorTypes, noneConnectorId } from '../../../common'; | ||
import { parseStringAsConnector, parseStringAsExternalService } from './parsers'; | ||
|
||
describe('user actions utility functions', () => { | ||
describe('parseStringAsConnector', () => { | ||
it('return null if the data is null', () => { | ||
expect(parseStringAsConnector('', null)).toBeNull(); | ||
}); | ||
|
||
it('return null if the data is not a json object', () => { | ||
expect(parseStringAsConnector('', 'blah')).toBeNull(); | ||
}); | ||
|
||
it('return null if the data is not a valid connector', () => { | ||
expect(parseStringAsConnector('', JSON.stringify({ a: '1' }))).toBeNull(); | ||
}); | ||
|
||
it('return null if id is null but the data is a connector other than none', () => { | ||
expect( | ||
parseStringAsConnector( | ||
null, | ||
JSON.stringify({ type: ConnectorTypes.jira, name: '', fields: null }) | ||
) | ||
).toBeNull(); | ||
}); | ||
|
||
it('return the id as the none connector if the data is the none connector', () => { | ||
expect( | ||
parseStringAsConnector( | ||
null, | ||
JSON.stringify({ type: ConnectorTypes.none, name: '', fields: null }) | ||
) | ||
).toEqual({ id: noneConnectorId, type: ConnectorTypes.none, name: '', fields: null }); | ||
}); | ||
|
||
it('returns a decoded connector with the specified id', () => { | ||
expect( | ||
parseStringAsConnector( | ||
'a', | ||
JSON.stringify({ type: ConnectorTypes.jira, name: 'hi', fields: null }) | ||
) | ||
).toEqual({ id: 'a', type: ConnectorTypes.jira, name: 'hi', fields: null }); | ||
}); | ||
}); | ||
|
||
describe('parseStringAsExternalService', () => { | ||
it('returns null when the data is null', () => { | ||
expect(parseStringAsExternalService('', null)).toBeNull(); | ||
}); | ||
|
||
it('returns null when the data is not valid json', () => { | ||
expect(parseStringAsExternalService('', 'blah')).toBeNull(); | ||
}); | ||
|
||
it('returns null when the data is not a valid external service object', () => { | ||
expect(parseStringAsExternalService('', JSON.stringify({ a: '1' }))).toBeNull(); | ||
}); | ||
|
||
it('returns the decoded external service with the connector_id field added', () => { | ||
const externalServiceInfo = { | ||
connector_name: 'name', | ||
external_id: '1', | ||
external_title: 'title', | ||
external_url: 'abc', | ||
pushed_at: '1', | ||
pushed_by: { | ||
username: 'a', | ||
email: '[email protected]', | ||
full_name: 'a', | ||
}, | ||
}; | ||
|
||
expect(parseStringAsExternalService('500', JSON.stringify(externalServiceInfo))).toEqual({ | ||
...externalServiceInfo, | ||
connector_id: '500', | ||
}); | ||
}); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/cases/public/common/user_actions/parsers.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,77 @@ | ||
/* | ||
* 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 { | ||
CaseUserActionConnectorRt, | ||
CaseConnector, | ||
ConnectorTypes, | ||
noneConnectorId, | ||
CaseFullExternalService, | ||
CaseUserActionExternalServiceRt, | ||
} from '../../../common'; | ||
|
||
export const parseStringAsConnector = ( | ||
id: string | null, | ||
encodedData: string | null | ||
): CaseConnector | null => { | ||
if (encodedData == null) { | ||
return null; | ||
} | ||
|
||
const decodedConnector = parseString(encodedData); | ||
|
||
if (!CaseUserActionConnectorRt.is(decodedConnector)) { | ||
return null; | ||
} | ||
|
||
if (id == null && decodedConnector.type === ConnectorTypes.none) { | ||
return { | ||
...decodedConnector, | ||
id: noneConnectorId, | ||
}; | ||
} else if (id == null) { | ||
return null; | ||
} else { | ||
// id does not equal null or undefined and the connector type does not equal none | ||
// so return the connector with its id | ||
return { | ||
...decodedConnector, | ||
id, | ||
}; | ||
} | ||
}; | ||
|
||
const parseString = (params: string | null): unknown | null => { | ||
if (params == null) { | ||
return null; | ||
} | ||
|
||
try { | ||
return JSON.parse(params); | ||
} catch { | ||
return null; | ||
} | ||
}; | ||
|
||
export const parseStringAsExternalService = ( | ||
id: string | null, | ||
encodedData: string | null | ||
): CaseFullExternalService => { | ||
if (encodedData == null) { | ||
return null; | ||
} | ||
|
||
const decodedExternalService = parseString(encodedData); | ||
if (!CaseUserActionExternalServiceRt.is(decodedExternalService)) { | ||
return null; | ||
} | ||
|
||
return { | ||
...decodedExternalService, | ||
connector_id: id, | ||
}; | ||
}; |
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.
These will be populated with the connector ids extracted from the
newValue
andoldValue
fields.