Fix bug w/ keep policies up to date setting (#116974)

Previously, we were only honoring the "keep policies up to date"
setting for policies generated during preconfiguration. This fix ensure
we honor it for all policies.

Closes #116435
This commit is contained in:
Kyle Pollich 2021-11-01 13:43:38 -04:00 committed by GitHub
parent f65b3f694f
commit d703f53412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,7 +20,11 @@ import type {
PreconfigurationError,
PreconfiguredOutput,
} from '../../common';
import { AGENT_POLICY_SAVED_OBJECT_TYPE, normalizeHostsForAgents } from '../../common';
import {
AGENT_POLICY_SAVED_OBJECT_TYPE,
SO_SEARCH_LIMIT,
normalizeHostsForAgents,
} from '../../common';
import {
PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE,
PRECONFIGURATION_LATEST_KEYWORD,
@ -33,7 +37,7 @@ import { ensurePackagesCompletedInstall } from './epm/packages/install';
import { bulkInstallPackages } from './epm/packages/bulk_install_packages';
import { agentPolicyService, addPackageToAgentPolicy } from './agent_policy';
import type { InputsOverride } from './package_policy';
import { overridePackageInputs } from './package_policy';
import { overridePackageInputs, packagePolicyService } from './package_policy';
import { appContextService } from './app_context';
import type { UpgradeManagedPackagePoliciesResult } from './managed_package_policies';
import { upgradeManagedPackagePolicies } from './managed_package_policies';
@ -349,14 +353,16 @@ export async function ensurePreconfiguredPackagesAndPolicies(
}
}
const fulfilledPolicyPackagePolicyIds = fulfilledPolicies
.filter(({ policy }) => policy?.package_policies)
.flatMap<string>(({ policy }) => policy?.package_policies as string[]);
// Handle automatic package policy upgrades for managed packages and package with
// the `keep_policies_up_to_date` setting enabled
const allPackagePolicyIds = await packagePolicyService.listIds(soClient, {
page: 1,
perPage: SO_SEARCH_LIMIT,
});
const packagePolicyUpgradeResults = await upgradeManagedPackagePolicies(
soClient,
esClient,
fulfilledPolicyPackagePolicyIds
allPackagePolicyIds.items
);
return {