Skip to content

Commit

Permalink
[Osquery] [Fix] Fix redundant policy revision update after osquery in…
Browse files Browse the repository at this point in the history
…tegration is added (#146959)
  • Loading branch information
tomsonpl authored Dec 5, 2022
1 parent 156bfe4 commit 18ee502
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions x-pack/plugins/osquery/server/lib/update_global_packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,46 @@ export const updateGlobalPacksCreateCallback = async (
});
});

await Promise.all(
map(packsContainingShardForPolicy, (pack) => {
packsClient.update(
packSavedObjectType,
pack.id,
{},
{
references: [
...pack.references,
{
id: packagePolicy.policy_id,
name: agentPolicies[packagePolicy.policy_id]?.name,
type: AGENT_POLICY_SAVED_OBJECT_TYPE,
},
],
if (packsContainingShardForPolicy.length) {
await Promise.all(
map(packsContainingShardForPolicy, (pack) => {
packsClient.update(
packSavedObjectType,
pack.id,
{},
{
references: [
...pack.references,
{
id: packagePolicy.policy_id,
name: agentPolicies[packagePolicy.policy_id]?.name,
type: AGENT_POLICY_SAVED_OBJECT_TYPE,
},
],
}
);
})
);

await packagePolicyService?.update(
packsClient,
esClient,
packagePolicy.id,
produce<PackagePolicy>(packagePolicy, (draft) => {
unset(draft, 'id');
if (!has(draft, 'inputs[0].streams')) {
set(draft, 'inputs[0].streams', []);
}
);
})
);
await packagePolicyService?.update(
packsClient,
esClient,
packagePolicy.id,
produce<PackagePolicy>(packagePolicy, (draft) => {
unset(draft, 'id');
if (!has(draft, 'inputs[0].streams')) {
set(draft, 'inputs[0].streams', []);
}

map(packsContainingShardForPolicy, (pack) => {
set(draft, `inputs[0].config.osquery.value.packs.${pack.attributes.name}`, {
shard: 100,
queries: convertSOQueriesToPackConfig(pack.attributes.queries),
map(packsContainingShardForPolicy, (pack) => {
set(draft, `inputs[0].config.osquery.value.packs.${pack.attributes.name}`, {
shard: 100,
queries: convertSOQueriesToPackConfig(pack.attributes.queries),
});
});
});

return draft;
})
);
return draft;
})
);
}
};

0 comments on commit 18ee502

Please sign in to comment.