From cc5dc15be861d5686f64aabdb160566d69804368 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 7 Dec 2020 16:25:36 -0700 Subject: [PATCH] Add licensing conditional logic on server --- .../stack_alerts/server/alert_types/index.ts | 18 ++++++++++++++---- x-pack/plugins/stack_alerts/server/plugin.ts | 3 ++- x-pack/plugins/stack_alerts/server/types.ts | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/stack_alerts/server/alert_types/index.ts b/x-pack/plugins/stack_alerts/server/alert_types/index.ts index 21a7ffc481323..52f166f5f5809 100644 --- a/x-pack/plugins/stack_alerts/server/alert_types/index.ts +++ b/x-pack/plugins/stack_alerts/server/alert_types/index.ts @@ -9,6 +9,8 @@ import { AlertingSetup, StackAlertsStartDeps } from '../types'; import { register as registerIndexThreshold } from './index_threshold'; import { register as registerGeoThreshold } from './geo_threshold'; import { register as registerGeoContainment } from './geo_containment'; +import { LicensingPluginSetup } from '../../../licensing/server'; +import { STACK_ALERTS_FEATURE_ID } from '../../common'; interface RegisterAlertTypesParams { logger: Logger; @@ -16,8 +18,16 @@ interface RegisterAlertTypesParams { alerts: AlertingSetup; } -export function registerBuiltInAlertTypes(params: RegisterAlertTypesParams) { - registerIndexThreshold(params); - registerGeoThreshold(params); - registerGeoContainment(params); +export function registerBuiltInAlertTypes( + params: RegisterAlertTypesParams & { licensing: LicensingPluginSetup } +) { + params.licensing.license$.subscribe((license) => { + const { state } = license.check(STACK_ALERTS_FEATURE_ID, 'gold'); + const hasGoldLicense = state === 'valid'; + if (hasGoldLicense) { + registerGeoThreshold(params); + registerGeoContainment(params); + } + registerIndexThreshold(params); + }); } diff --git a/x-pack/plugins/stack_alerts/server/plugin.ts b/x-pack/plugins/stack_alerts/server/plugin.ts index 66ac9e455e8b6..8c0c4820f7b7d 100644 --- a/x-pack/plugins/stack_alerts/server/plugin.ts +++ b/x-pack/plugins/stack_alerts/server/plugin.ts @@ -20,7 +20,7 @@ export class AlertingBuiltinsPlugin public async setup( core: CoreSetup, - { alerts, features }: StackAlertsDeps + { alerts, features, licensing }: StackAlertsDeps ): Promise { features.registerKibanaFeature(BUILT_IN_ALERTS_FEATURE); @@ -30,6 +30,7 @@ export class AlertingBuiltinsPlugin .getStartServices() .then(async ([, { triggersActionsUi }]) => triggersActionsUi.data), alerts, + licensing, }); } diff --git a/x-pack/plugins/stack_alerts/server/types.ts b/x-pack/plugins/stack_alerts/server/types.ts index e37596e8ff970..aaf8257899ea1 100644 --- a/x-pack/plugins/stack_alerts/server/types.ts +++ b/x-pack/plugins/stack_alerts/server/types.ts @@ -13,11 +13,13 @@ export { AlertExecutorOptions, } from '../../alerts/server'; import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server'; +import { LicensingPluginSetup } from '../../licensing/server'; // this plugin's dependendencies export interface StackAlertsDeps { alerts: AlertingSetup; features: FeaturesPluginSetup; + licensing: LicensingPluginSetup; } export interface StackAlertsStartDeps {