Skip to content

Commit

Permalink
Add licensing conditional logic on server
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Dec 7, 2020
1 parent 83150e4 commit cc5dc15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
18 changes: 14 additions & 4 deletions x-pack/plugins/stack_alerts/server/alert_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ 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;
data: Promise<StackAlertsStartDeps['triggersActionsUi']['data']>;
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);
});
}
3 changes: 2 additions & 1 deletion x-pack/plugins/stack_alerts/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AlertingBuiltinsPlugin

public async setup(
core: CoreSetup<StackAlertsStartDeps>,
{ alerts, features }: StackAlertsDeps
{ alerts, features, licensing }: StackAlertsDeps
): Promise<void> {
features.registerKibanaFeature(BUILT_IN_ALERTS_FEATURE);

Expand All @@ -30,6 +30,7 @@ export class AlertingBuiltinsPlugin
.getStartServices()
.then(async ([, { triggersActionsUi }]) => triggersActionsUi.data),
alerts,
licensing,
});
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/stack_alerts/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cc5dc15

Please sign in to comment.