From 578489aa60225789eba74d5141dbe15e06b273df Mon Sep 17 00:00:00 2001 From: Esteban Beltran Date: Mon, 12 Jul 2021 09:38:47 +0200 Subject: [PATCH] Migration early exit if key not found --- .../security_solution/to_v7_15_0.ts | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_15_0.ts b/x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_15_0.ts index 804572a9969ff8..e820cb47132a69 100644 --- a/x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_15_0.ts +++ b/x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_15_0.ts @@ -13,27 +13,30 @@ import type { PackagePolicy } from '../../../../common'; export const migratePackagePolicyToV7150: SavedObjectMigrationFn = ( packagePolicyDoc ) => { + if (packagePolicyDoc.attributes.package?.name !== 'endpoint') { + return packagePolicyDoc; + } + const updatedPackagePolicyDoc: SavedObjectUnsanitizedDoc = cloneDeep( packagePolicyDoc ); - if (packagePolicyDoc.attributes.package?.name === 'endpoint') { - const input = updatedPackagePolicyDoc.attributes.inputs[0]; - const memory = { - mode: 'off', - // This value is based on license. - // For the migration, we add 'true', our license watcher will correct it, if needed, when the app starts. - supported: true, - }; - const memoryPopup = { - message: '', - enabled: false, - }; - if (input && input.config) { - const policy = input.config.policy.value; - policy.windows.memory_protection = memory; - policy.windows.popup.memory_protection = memoryPopup; - } + const input = updatedPackagePolicyDoc.attributes.inputs[0]; + const memory = { + mode: 'off', + // This value is based on license. + // For the migration, we add 'true', our license watcher will correct it, if needed, when the app starts. + supported: true, + }; + const memoryPopup = { + message: '', + enabled: false, + }; + if (input && input.config) { + const policy = input.config.policy.value; + + policy.windows.memory_protection = memory; + policy.windows.popup.memory_protection = memoryPopup; } return updatedPackagePolicyDoc;