Skip to content

Commit

Permalink
Fix unenroll outputs shape (elastic#142895)
Browse files Browse the repository at this point in the history
(cherry picked from commit e794156)
  • Loading branch information
joshdover committed Oct 6, 2022
1 parent bc6b0dc commit 3853c5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
11 changes: 7 additions & 4 deletions x-pack/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ export interface Agent extends AgentBase {
access_api_key?: string;
// @deprecated
default_api_key_history?: FleetServerAgent['default_api_key_history'];
outputs?: Array<{
api_key_id: string;
to_retire_api_key_ids?: FleetServerAgent['default_api_key_history'];
}>;
outputs?: Record<
string,
{
api_key_id: string;
to_retire_api_key_ids?: FleetServerAgent['default_api_key_history'];
}
>;
status?: AgentStatus;
packages: string[];
sort?: Array<number | string | null>;
Expand Down
16 changes: 12 additions & 4 deletions x-pack/plugins/fleet/server/services/agents/unenroll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,22 @@ describe('invalidateAPIKeysForAgents', () => {
id: 'defaultApiKeyHistory2',
},
],
outputs: [
{
outputs: {
output1: {
api_key_id: 'outputApiKey1',
to_retire_api_key_ids: [{ id: 'outputApiKeyRetire1' }, { id: 'outputApiKeyRetire2' }],
},
{
output2: {
api_key_id: 'outputApiKey2',
},
],
output3: {
api_key_id: 'outputApiKey3',
to_retire_api_key_ids: [
// Somes Fleet Server agents don't have an id here (probably a bug)
{ retired_at: 'foo' },
],
},
},
} as any,
]);

Expand All @@ -353,6 +360,7 @@ describe('invalidateAPIKeysForAgents', () => {
'outputApiKeyRetire1',
'outputApiKeyRetire2',
'outputApiKey2',
'outputApiKey3',
]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,16 @@ export async function invalidateAPIKeysForAgents(agents: Agent[]) {
agent.default_api_key_history.forEach((apiKey) => keys.push(apiKey.id));
}
if (agent.outputs) {
agent.outputs.forEach((output) => {
Object.values(agent.outputs).forEach((output) => {
if (output.api_key_id) {
keys.push(output.api_key_id);
}
if (output.to_retire_api_key_ids) {
output.to_retire_api_key_ids.forEach((apiKey) => keys.push(apiKey.id));
Object.values(output.to_retire_api_key_ids).forEach((apiKey) => {
if (apiKey?.id) {
keys.push(apiKey.id);
}
});
}
});
}
Expand Down

0 comments on commit 3853c5f

Please sign in to comment.