Skip to content

Commit

Permalink
[Maps] Always check license at plugin startup (#87873) (#88739)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
thomasneirynck and kibanamachine authored Feb 11, 2021
1 parent dc8fec2 commit 6643748
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
46 changes: 29 additions & 17 deletions x-pack/plugins/maps/public/licensed_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,40 @@ export const LICENCED_FEATURES_DETAILS: Record<LICENSED_FEATURES, LicensedFeatur

let licenseId: string | undefined;
let isGoldPlus: boolean = false;

let isEnterprisePlus: boolean = false;

export const getLicenseId = () => licenseId;
export const getIsGoldPlus = () => isGoldPlus;

export const getIsEnterprisePlus = () => isEnterprisePlus;

let licensingPluginStart: LicensingPluginStart;
let initializeLicense: (value: unknown) => void;
const licenseInitialized = new Promise((resolve) => {
initializeLicense = resolve;
});
export const whenLicenseInitialized = async (): Promise<void> => {
await licenseInitialized;
};

export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) {
const license = await licensingPlugin.refresh();
updateLicenseState(license);

licensingPluginStart = licensingPlugin;
licensingPluginStart.license$.subscribe(updateLicenseState);

initializeLicense(undefined);
}

function updateLicenseState(license: ILicense) {
const gold = license.check(APP_ID, 'gold');
isGoldPlus = gold.state === 'valid';

const enterprise = license.check(APP_ID, 'enterprise');
isEnterprisePlus = enterprise.state === 'valid';

licenseId = license.uid;
}

export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) {
for (const licensedFeature of Object.values(LICENSED_FEATURES)) {
licensingPlugin.featureUsage.register(
Expand All @@ -54,20 +80,6 @@ export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup)
}
}

let licensingPluginStart: LicensingPluginStart;
export function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) {
licensingPluginStart = licensingPlugin;
licensingPluginStart.license$.subscribe((license: ILicense) => {
const gold = license.check(APP_ID, 'gold');
isGoldPlus = gold.state === 'valid';

const enterprise = license.check(APP_ID, 'enterprise');
isEnterprisePlus = enterprise.state === 'valid';

licenseId = license.uid;
});
}

export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) {
if (!licensingPluginStart) {
// eslint-disable-next-line no-console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { copyPersistentState } from '../../../reducers/util';
import { getBreadcrumbs } from './get_breadcrumbs';
import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../reducers/ui';
import { createBasemapLayerDescriptor } from '../../../classes/layers/create_basemap_layer_descriptor';
import { whenLicenseInitialized } from '../../../licensed_features';

export class SavedMap {
private _attributes: MapSavedObjectAttributes | null = null;
Expand Down Expand Up @@ -88,6 +89,8 @@ export class SavedMap {
}

async whenReady() {
await whenLicenseInitialized();

if (!this._mapEmbeddableInput) {
this._attributes = {
title: '',
Expand Down

0 comments on commit 6643748

Please sign in to comment.