Skip to content

Commit

Permalink
Migrate package policies
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Nov 11, 2020
1 parent 87a3ce1 commit 9cce417
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import { SavedObjectsServiceSetup, SavedObjectsType } from 'kibana/server';
import { flowRight } from 'lodash';
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
import { migratePackagePolicyToV7110 } from '../../../security_solution/common';
import { migratePackagePolicyToV7110 as endpointMigratePackagePolicyToV7110 } from '../../../security_solution/common';
import {
OUTPUT_SAVED_OBJECT_TYPE,
AGENT_POLICY_SAVED_OBJECT_TYPE,
Expand All @@ -27,6 +28,7 @@ import {
migrateSettingsToV7100,
migrateAgentActionToV7100,
} from './migrations/to_v7_10_0';
import { migratePackagePolicyToV7110 } from './migrations/to_v7_11_0';

/*
* Saved object types and mappings
Expand Down Expand Up @@ -270,7 +272,7 @@ const getSavedObjectTypes = (
},
migrations: {
'7.10.0': migratePackagePolicyToV7100,
'7.11.0': migratePackagePolicyToV7110,
'7.11.0': flowRight(migratePackagePolicyToV7110, endpointMigratePackagePolicyToV7110),
},
},
[PACKAGES_SAVED_OBJECT_TYPE]: {
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/migrations/to_v7_11_0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 { SavedObjectMigrationFn } from 'kibana/server';
import { PackagePolicy } from '../../types';

export const migratePackagePolicyToV7110: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
) => {
packagePolicyDoc.attributes.inputs = packagePolicyDoc.attributes.inputs.map((input) => ({
...input,
id: `${input.type}-${packagePolicyDoc.id}`,
}));

return packagePolicyDoc;
};

0 comments on commit 9cce417

Please sign in to comment.