Skip to content

Commit

Permalink
add forced control to update and upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Jul 13, 2022
1 parent fbce8d9 commit 81b8982
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ class PackagePolicyService implements PackagePolicyServiceInterface {
const oldPackagePolicy = await this.get(soClient, id);
const { version, ...restOfPackagePolicy } = packagePolicy;

if (packagePolicyUpdate.is_managed && !options?.force) {
throw new PackagePolicyRestrictionRelatedError(`Cannot update package policy ${id}`);
}

if (!oldPackagePolicy) {
throw new Error('Package policy not found');
}
Expand Down Expand Up @@ -611,7 +615,7 @@ class PackagePolicyService implements PackagePolicyServiceInterface {
soClient: SavedObjectsClientContract,
esClient: ElasticsearchClient,
ids: string[],
options?: { user?: AuthenticatedUser },
options?: { user?: AuthenticatedUser; force?: boolean },
packagePolicy?: PackagePolicy,
pkgVersion?: string
): Promise<UpgradePackagePolicyResponse> {
Expand All @@ -627,6 +631,10 @@ class PackagePolicyService implements PackagePolicyServiceInterface {
pkgVersion
));

if (packagePolicy.is_managed && !options?.force) {
throw new PackagePolicyRestrictionRelatedError(`Cannot upgrade package policy ${id}`);
}

await this.doUpgrade(soClient, esClient, id, packagePolicy!, result, packageInfo, options);
} catch (error) {
result.push({
Expand Down

0 comments on commit 81b8982

Please sign in to comment.