Skip to content

Commit

Permalink
[Security] siem to securitySolution SO migration (#68776)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Jun 15, 2020
1 parent 646a212 commit f7398f0
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/core/server/ui_settings/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 42 additions & 0 deletions src/core/server/ui_settings/saved_objects/migrations.ts
Original file line number Diff line number Diff line change
@@ -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 || [],
}),
};
2 changes: 2 additions & 0 deletions src/core/server/ui_settings/saved_objects/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { SavedObjectsType } from '../../saved_objects';
import { migrations } from './migrations';

export const uiSettingsType: SavedObjectsType = {
name: 'config',
Expand Down Expand Up @@ -46,4 +47,5 @@ export const uiSettingsType: SavedObjectsType = {
return `Advanced Settings [${obj.id}]`;
},
},
migrations,
};
1 change: 1 addition & 0 deletions test/api_integration/apis/saved_objects/bulk_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default function ({ getService }) {
buildNum: 8467,
defaultIndex: '91200a00-9efd-11e7-acb3-3dab96693fab',
},
migrationVersion: resp.body.saved_objects[2].migrationVersion,
references: [],
},
],
Expand Down

0 comments on commit f7398f0

Please sign in to comment.