Skip to content

Commit

Permalink
Add agent action SO migration for policy change actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Sep 23, 2020
1 parent 807c4b9 commit 894c61e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/ingest_manager/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
migrateEnrollmentApiKeysToV7100,
migratePackagePolicyToV7100,
migrateSettingsToV7100,
migrateAgentActionToV7100,
} from './migrations/to_v7_10_0';

/*
Expand Down Expand Up @@ -107,6 +108,9 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
created_at: { type: 'date' },
},
},
migrations: {
'7.10.0': migrateAgentActionToV7100,
},
},
[AGENT_EVENT_SAVED_OBJECT_TYPE]: {
name: AGENT_EVENT_SAVED_OBJECT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PackagePolicy,
EnrollmentAPIKey,
Settings,
AgentAction,
} from '../../types';

export const migrateAgentToV7100: SavedObjectMigrationFn<
Expand Down Expand Up @@ -92,3 +93,18 @@ export const migrateSettingsToV7100: SavedObjectMigrationFn<

return settingsDoc;
};

export const migrateAgentActionToV7100: SavedObjectMigrationFn<AgentAction, AgentAction> = (
agentActionDoc
) => {
// @ts-expect-error
if (agentActionDoc.attributes.type === 'CONFIG_CHANGE') {
agentActionDoc.attributes.type = 'POLICY_CHANGE';
if (agentActionDoc.attributes.data?.config) {
agentActionDoc.attributes.data.policy = agentActionDoc.attributes.data.config;
delete agentActionDoc.attributes.data.config;
}
}

return agentActionDoc;
};

0 comments on commit 894c61e

Please sign in to comment.