forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Actions] Migrate cases configuration object (elastic#77998)
Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Gidi Meir Morris <[email protected]>
- Loading branch information
1 parent
d9dfc5f
commit 5736ae8
Showing
9 changed files
with
2,780 additions
and
21 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
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/actions/server/saved_objects/migrations.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,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import uuid from 'uuid'; | ||
import { getMigrations } from './migrations'; | ||
import { RawAction } from '../types'; | ||
import { SavedObjectUnsanitizedDoc } from 'kibana/server'; | ||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/mocks'; | ||
import { migrationMocks } from 'src/core/server/mocks'; | ||
|
||
const context = migrationMocks.createContext(); | ||
const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup(); | ||
|
||
describe('7.10.0', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
encryptedSavedObjectsSetup.createMigration.mockImplementation( | ||
(shouldMigrateWhenPredicate, migration) => migration | ||
); | ||
}); | ||
|
||
test('rename cases configuration object', () => { | ||
const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0']; | ||
const action = getMockData({}); | ||
expect(migration710(action, context)).toMatchObject({ | ||
...action, | ||
attributes: { | ||
...action.attributes, | ||
config: { | ||
incidentConfiguration: { mapping: [] }, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
function getMockData( | ||
overwrites: Record<string, unknown> = {} | ||
): SavedObjectUnsanitizedDoc<RawAction> { | ||
return { | ||
attributes: { | ||
name: 'abc', | ||
actionTypeId: '123', | ||
config: { casesConfiguration: { mapping: [] } }, | ||
secrets: {}, | ||
...overwrites, | ||
}, | ||
id: uuid.v4(), | ||
type: 'action', | ||
}; | ||
} |
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,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
SavedObjectMigrationMap, | ||
SavedObjectUnsanitizedDoc, | ||
SavedObjectMigrationFn, | ||
} from '../../../../../src/core/server'; | ||
import { RawAction } from '../types'; | ||
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server'; | ||
|
||
export function getMigrations( | ||
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup | ||
): SavedObjectMigrationMap { | ||
return { '7.10.0': renameCasesConfigurationObject(encryptedSavedObjects) }; | ||
} | ||
|
||
const renameCasesConfigurationObject = ( | ||
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup | ||
): SavedObjectMigrationFn<RawAction, RawAction> => { | ||
return encryptedSavedObjects.createMigration<RawAction, RawAction>( | ||
(doc): doc is SavedObjectUnsanitizedDoc<RawAction> => | ||
!!doc.attributes.config?.casesConfiguration, | ||
(doc: SavedObjectUnsanitizedDoc<RawAction>): SavedObjectUnsanitizedDoc<RawAction> => { | ||
const { casesConfiguration, ...restConfiguration } = doc.attributes.config; | ||
|
||
return { | ||
...doc, | ||
attributes: { | ||
...doc.attributes, | ||
config: { | ||
...restConfiguration, | ||
incidentConfiguration: casesConfiguration, | ||
}, | ||
}, | ||
}; | ||
} | ||
); | ||
}; |
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
54 changes: 54 additions & 0 deletions
54
x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.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,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { getUrlPrefix } from '../../../common/lib'; | ||
import { FtrProviderContext } from '../../../common/ftr_provider_context'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function createGetTests({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
|
||
describe('migrations', () => { | ||
before(async () => { | ||
await esArchiver.load('actions'); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload('actions'); | ||
}); | ||
|
||
it('7.10.0 migrates the `casesConfiguration` to be the `incidentConfiguration` in `config`', async () => { | ||
const response = await supertest.get( | ||
`${getUrlPrefix(``)}/api/actions/action/791a2ab1-784a-46ea-aa68-04c837e5da2d` | ||
); | ||
|
||
expect(response.status).to.eql(200); | ||
expect(response.body.config).key('incidentConfiguration'); | ||
expect(response.body.config).not.key('casesConfiguration'); | ||
expect(response.body.config.incidentConfiguration).to.eql({ | ||
mapping: [ | ||
{ | ||
actionType: 'overwrite', | ||
source: 'title', | ||
target: 'summary', | ||
}, | ||
{ | ||
actionType: 'overwrite', | ||
source: 'description', | ||
target: 'description', | ||
}, | ||
{ | ||
actionType: 'append', | ||
source: 'comments', | ||
target: 'comments', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.