Skip to content

Commit

Permalink
[Fleet] Fix POLICY_CHANGE action creation for new policy
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Oct 20, 2020
1 parent 770bc4c commit 28f52b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export const createAgentPolicyHandler: RequestHandler<
});
}

await agentPolicyService.createFleetPolicyChangeAction(soClient, agentPolicy.id);

const body: CreateAgentPolicyResponse = {
item: agentPolicy,
};
Expand Down Expand Up @@ -185,6 +187,7 @@ export const copyAgentPolicyHandler: RequestHandler<
user: user || undefined,
}
);

const body: CopyAgentPolicyResponse = { item: agentPolicy };
return response.ok({
body,
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { agentPolicyUpdateEventHandler } from './agent_policy_update';
import { getSettings } from './settings';
import { normalizeKuery, escapeSearchQueryPhrase } from './saved_object';
import { getFullAgentPolicyKibanaConfig } from '../../common/services/full_agent_policy_kibana_config';
import { isAgentsSetup } from './agents/setup';

const SAVED_OBJECT_TYPE = AGENT_POLICY_SAVED_OBJECT_TYPE;

Expand Down Expand Up @@ -287,6 +288,8 @@ class AgentPolicyService {
throw new Error('Copied agent policy not found');
}

await this.createFleetPolicyChangeAction(soClient, newAgentPolicy.id);

return updatedAgentPolicy;
}

Expand Down Expand Up @@ -433,6 +436,11 @@ class AgentPolicyService {
soClient: SavedObjectsClientContract,
agentPolicyId: string
) {
// If Agents is not setup skip the creation of POLICY_CHANGE agent actions
// the action will be created during the fleet setup
if (!isAgentsSetup(soClient)) {
return;
}
const policy = await agentPolicyService.getFullAgentPolicy(soClient, agentPolicyId);
if (!policy || !policy.revision) {
return;
Expand Down

0 comments on commit 28f52b6

Please sign in to comment.