[Osquery] [Fix] Fix redundant policy revision update after osquery integration is added (#146959)

This commit is contained in:
Tomasz Ciecierski 2022-12-05 11:04:16 +01:00 committed by GitHub
parent 156bfe40e7
commit 18ee502642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
},
],
}
);
})
);
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', []);
}
if (packsContainingShardForPolicy.length) {
await Promise.all(
map(packsContainingShardForPolicy, (pack) => {
set(draft, `inputs[0].config.osquery.value.packs.${pack.attributes.name}`, {
shard: 100,
queries: convertSOQueriesToPackConfig(pack.attributes.queries),
});
});
packsClient.update(
packSavedObjectType,
pack.id,
{},
{
references: [
...pack.references,
{
id: packagePolicy.policy_id,
name: agentPolicies[packagePolicy.policy_id]?.name,
type: AGENT_POLICY_SAVED_OBJECT_TYPE,
},
],
}
);
})
);
return draft;
})
);
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),
});
});
return draft;
})
);
}
};