Skip to content

Commit

Permalink
retry policy update && use incoming license object for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pzl committed Nov 25, 2020
1 parent ef99277 commit 6113014
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isEndpointPolicyValidForLicense,
unsetPolicyFeaturesAboveLicenseLevel,
} from '../../../../common/license/policy_config';
import { isAtLeast } from '../../../../common/license/license';
import { licenseService } from '../../../lib/license/license';

export class PolicyWatcher {
Expand Down Expand Up @@ -66,6 +67,10 @@ export class PolicyWatcher {
}

public async watch(license: ILicense) {
if (isAtLeast(license, 'platinum')) {
return;
}

let page = 1;
let response: {
items: PackagePolicy[];
Expand All @@ -86,14 +91,25 @@ export class PolicyWatcher {
);
return;
}
response.items.forEach((policy) => {
response.items.forEach(async (policy) => {
const policyConfig = policy.inputs[0].config?.policy.value;
if (!isEndpointPolicyValidForLicense(policyConfig, licenseService)) {
if (!isEndpointPolicyValidForLicense(policyConfig, license)) {
policy.inputs[0].config!.policy.value = unsetPolicyFeaturesAboveLicenseLevel(
policyConfig,
licenseService
license
);
this.policyService.update(this.soClient, policy.id, policy);
try {
await this.policyService.update(this.soClient, policy.id, policy);
} catch (e) {
// try again for transient issues
try {
await this.policyService.update(this.soClient, policy.id, policy);
} catch (ee) {
this.logger.warn(
`Unable to remove platinum features from policy ${policy.id}: ${ee.message}`
);
}
}
}
});
} while (response.page * response.perPage < response.total);
Expand Down

0 comments on commit 6113014

Please sign in to comment.