-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Migrate user actions connector ID (#108272)
* Making progress * Fleshing out the extraction logic * Finishing migration logic and starting more tests * Finishing migration unit tests * Making progress on services * Finishing transform to es schema * Finishing transform functionality and unit tests * reverting migration data updates * Cleaning up type errors * fixing test error * Working migration tests * Refactoring retrieval of connector fields * Refactoring connector id in and tests in frontend * Fixing tests and finished refactoring parse string * Fixing integration test * Fixing integration tests * Removing some duplicate code and updating test name * Fixing create connector user action bug * Addressing feedback and logging error * Moving parsing function to common * Fixing type errors * Fixing type errors * Addressing feedback * Fixing lint errors Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
6f2815a
commit 10ac814
Showing
57 changed files
with
7,895 additions
and
1,140 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
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
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.