mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Security] siem to securitySolution SO migration (#68776)
This commit is contained in:
parent
646a212b7b
commit
f7398f086b
4 changed files with 102 additions and 0 deletions
57
src/core/server/ui_settings/saved_objects/migrations.test.ts
Normal file
57
src/core/server/ui_settings/saved_objects/migrations.test.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { SavedObjectUnsanitizedDoc } from 'kibana/server';
|
||||
import { migrations } from './migrations';
|
||||
|
||||
describe('ui_settings 7.9.0 migrations', () => {
|
||||
const migration = migrations['7.9.0'];
|
||||
|
||||
test('returns doc on empty object', () => {
|
||||
expect(migration({} as SavedObjectUnsanitizedDoc)).toEqual({
|
||||
references: [],
|
||||
});
|
||||
});
|
||||
test('properly renames siem attributes to securitySolution', () => {
|
||||
const doc = {
|
||||
type: 'config',
|
||||
id: '8.0.0',
|
||||
attributes: {
|
||||
buildNum: 9007199254740991,
|
||||
'siem:defaultAnomalyScore': 59,
|
||||
'siem:enableNewsFeed': false,
|
||||
},
|
||||
references: [],
|
||||
updated_at: '2020-06-09T20:18:20.349Z',
|
||||
migrationVersion: {},
|
||||
};
|
||||
expect(migration(doc)).toEqual({
|
||||
type: 'config',
|
||||
id: '8.0.0',
|
||||
attributes: {
|
||||
buildNum: 9007199254740991,
|
||||
'securitySolution:defaultAnomalyScore': 59,
|
||||
'securitySolution:enableNewsFeed': false,
|
||||
},
|
||||
references: [],
|
||||
updated_at: '2020-06-09T20:18:20.349Z',
|
||||
migrationVersion: {},
|
||||
});
|
||||
});
|
||||
});
|
42
src/core/server/ui_settings/saved_objects/migrations.ts
Normal file
42
src/core/server/ui_settings/saved_objects/migrations.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { SavedObjectUnsanitizedDoc, SavedObjectSanitizedDoc } from 'kibana/server';
|
||||
|
||||
export const migrations = {
|
||||
'7.9.0': (doc: SavedObjectUnsanitizedDoc<any>): SavedObjectSanitizedDoc<any> => ({
|
||||
...doc,
|
||||
...(doc.attributes && {
|
||||
attributes: Object.keys(doc.attributes).reduce(
|
||||
(acc, key) =>
|
||||
key.startsWith('siem:')
|
||||
? {
|
||||
...acc,
|
||||
[key.replace('siem', 'securitySolution')]: doc.attributes[key],
|
||||
}
|
||||
: {
|
||||
...acc,
|
||||
[key]: doc.attributes[key],
|
||||
},
|
||||
{}
|
||||
),
|
||||
}),
|
||||
references: doc.references || [],
|
||||
}),
|
||||
};
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
import { SavedObjectsType } from '../../saved_objects';
|
||||
import { migrations } from './migrations';
|
||||
|
||||
export const uiSettingsType: SavedObjectsType = {
|
||||
name: 'config',
|
||||
|
@ -46,4 +47,5 @@ export const uiSettingsType: SavedObjectsType = {
|
|||
return `Advanced Settings [${obj.id}]`;
|
||||
},
|
||||
},
|
||||
migrations,
|
||||
};
|
||||
|
|
|
@ -94,6 +94,7 @@ export default function ({ getService }) {
|
|||
buildNum: 8467,
|
||||
defaultIndex: '91200a00-9efd-11e7-acb3-3dab96693fab',
|
||||
},
|
||||
migrationVersion: resp.body.saved_objects[2].migrationVersion,
|
||||
references: [],
|
||||
},
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue