[Security Solution][Endpoint][Admin] Fixes bug where license watch updates policy in fleet (#93691)

This commit is contained in:
Candace Park 2021-03-05 08:35:24 -05:00 committed by GitHub
parent d0b6891abf
commit bf1dcb7679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,10 +30,10 @@ import { isAtLeast, LicenseService } from '../../../../common/license/license';
export class PolicyWatcher {
private logger: Logger;
private soClient: SavedObjectsClientContract;
private esClient: ElasticsearchClient;
private policyService: PackagePolicyServiceInterface;
private subscription: Subscription | undefined;
private soStart: SavedObjectsServiceStart;
constructor(
policyService: PackagePolicyServiceInterface,
soStart: SavedObjectsServiceStart,
@ -41,9 +41,9 @@ export class PolicyWatcher {
logger: Logger
) {
this.policyService = policyService;
this.soClient = this.makeInternalSOClient(soStart);
this.esClient = esStart.client.asInternalUser;
this.logger = logger;
this.soStart = soStart;
}
/**
@ -89,7 +89,7 @@ export class PolicyWatcher {
};
do {
try {
response = await this.policyService.list(this.soClient, {
response = await this.policyService.list(this.makeInternalSOClient(this.soStart), {
page: page++,
perPage: 100,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`,
@ -119,12 +119,17 @@ export class PolicyWatcher {
license
);
try {
await this.policyService.update(this.soClient, this.esClient, policy.id, updatePolicy);
await this.policyService.update(
this.makeInternalSOClient(this.soStart),
this.esClient,
policy.id,
updatePolicy
);
} catch (e) {
// try again for transient issues
try {
await this.policyService.update(
this.soClient,
this.makeInternalSOClient(this.soStart),
this.esClient,
policy.id,
updatePolicy