From e7836e145eea18a66cc16afffc1ad858ded6c0b9 Mon Sep 17 00:00:00 2001 From: pzl Date: Tue, 24 Nov 2020 14:45:11 -0500 Subject: [PATCH] start/stop subscription mgmt --- .../server/endpoint/lib/policy/license_watch.ts | 16 +++++++++++++++- .../plugins/security_solution/server/plugin.ts | 13 +++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/server/endpoint/lib/policy/license_watch.ts b/x-pack/plugins/security_solution/server/endpoint/lib/policy/license_watch.ts index 63ccf3414f1eeb8..2ac3681ef3ce43a 100644 --- a/x-pack/plugins/security_solution/server/endpoint/lib/policy/license_watch.ts +++ b/x-pack/plugins/security_solution/server/endpoint/lib/policy/license_watch.ts @@ -3,6 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + +import { Subscription } from 'rxjs'; + import { KibanaRequest, Logger, @@ -21,7 +24,8 @@ import { licenseService } from '../../../lib/license/license'; export class PolicyWatcher { private logger: Logger; private soClient: SavedObjectsClientContract; - private policyService?: PackagePolicyServiceInterface; + private policyService: PackagePolicyServiceInterface; + private subscription: Subscription | undefined; constructor( policyService: PackagePolicyServiceInterface, soStart: SavedObjectsServiceStart, @@ -44,6 +48,16 @@ export class PolicyWatcher { return soStart.getScopedClient(fakeRequest, { excludedWrappers: ['security'] }); } + public start() { + this.subscription = licenseService.getLicenseInformation$()?.subscribe(this.watch.bind(this)); + } + + public stop() { + if (this.subscription) { + this.subscription.unsubscribe(); + } + } + public async watch(license: ILicense) { let packagePolicies: PackagePolicy[]; if (!this.policyService) { diff --git a/x-pack/plugins/security_solution/server/plugin.ts b/x-pack/plugins/security_solution/server/plugin.ts index 52d989267acef59..1d2ba2d8b368c42 100644 --- a/x-pack/plugins/security_solution/server/plugin.ts +++ b/x-pack/plugins/security_solution/server/plugin.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Observable } from 'rxjs'; +import { Observable, Subscription } from 'rxjs'; import { first } from 'rxjs/operators'; import { i18n } from '@kbn/i18n'; import LRU from 'lru-cache'; @@ -128,6 +128,7 @@ export class Plugin implements IPlugin; + private policyWatcher: PolicyWatcher; private manifestTask: ManifestTask | undefined; private exceptionsCache: LRU; @@ -371,9 +372,12 @@ export class Plugin implements IPlugin