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 63ccf3414f1ee..58ca17231decc 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) { @@ -53,6 +67,7 @@ export class PolicyWatcher { return; } + // @todo: actually page and fetch them ALL try { packagePolicies = ( await this.policyService.list(this.soClient, { diff --git a/x-pack/plugins/security_solution/server/plugin.ts b/x-pack/plugins/security_solution/server/plugin.ts index 11db90061b603..c4876e0813df9 100644 --- a/x-pack/plugins/security_solution/server/plugin.ts +++ b/x-pack/plugins/security_solution/server/plugin.ts @@ -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