mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Migrate legacy maps licensing (x-pack/tilemap) to NP (#63539)
* Move logic to NP and add basic plugin structure * Remove unused server-side licensing logic and old index * Set license in maps_legacy via new plugin * Change add to set for service settings queryParams function * Fix accidentally changed emsClient method call * Require at least a basic license * Type updates * Remove unneeded legacy license test * Remove unused headers in test
This commit is contained in:
parent
c13a026b01
commit
f179ec4069
12 changed files with 84 additions and 133 deletions
|
@ -143,24 +143,24 @@ describe('service_settings (FKA tilemaptest)', function() {
|
|||
}
|
||||
|
||||
it('accepts an object', async () => {
|
||||
serviceSettings.addQueryParams({ foo: 'bar' });
|
||||
serviceSettings.setQueryParams({ foo: 'bar' });
|
||||
tilemapServices = await serviceSettings.getTMSServices();
|
||||
await assertQuery({ foo: 'bar' });
|
||||
});
|
||||
|
||||
it('merged additions with previous values', async () => {
|
||||
// ensure that changes are always additive
|
||||
serviceSettings.addQueryParams({ foo: 'bar' });
|
||||
serviceSettings.addQueryParams({ bar: 'stool' });
|
||||
serviceSettings.setQueryParams({ foo: 'bar' });
|
||||
serviceSettings.setQueryParams({ bar: 'stool' });
|
||||
tilemapServices = await serviceSettings.getTMSServices();
|
||||
await assertQuery({ foo: 'bar', bar: 'stool' });
|
||||
});
|
||||
|
||||
it('overwrites conflicting previous values', async () => {
|
||||
// ensure that conflicts are overwritten
|
||||
serviceSettings.addQueryParams({ foo: 'bar' });
|
||||
serviceSettings.addQueryParams({ bar: 'stool' });
|
||||
serviceSettings.addQueryParams({ foo: 'tstool' });
|
||||
serviceSettings.setQueryParams({ foo: 'bar' });
|
||||
serviceSettings.setQueryParams({ bar: 'stool' });
|
||||
serviceSettings.setQueryParams({ foo: 'tstool' });
|
||||
tilemapServices = await serviceSettings.getTMSServices();
|
||||
await assertQuery({ foo: 'tstool', bar: 'stool' });
|
||||
});
|
||||
|
@ -168,7 +168,7 @@ describe('service_settings (FKA tilemaptest)', function() {
|
|||
it('when overridden, should continue to work', async () => {
|
||||
mapConfig.emsFileApiUrl = emsFileApiUrl2;
|
||||
mapConfig.emsTileApiUrl = emsTileApiUrl2;
|
||||
serviceSettings.addQueryParams({ foo: 'bar' });
|
||||
serviceSettings.setQueryParams({ foo: 'bar' });
|
||||
tilemapServices = await serviceSettings.getTMSServices();
|
||||
await assertQuery({ foo: 'bar' });
|
||||
});
|
||||
|
@ -292,7 +292,7 @@ describe('service_settings (FKA tilemaptest)', function() {
|
|||
|
||||
describe('File layers', function() {
|
||||
it('should load manifest (all props)', async function() {
|
||||
serviceSettings.addQueryParams({ foo: 'bar' });
|
||||
serviceSettings.setQueryParams({ foo: 'bar' });
|
||||
const fileLayers = await serviceSettings.getFileLayers();
|
||||
expect(fileLayers.length).to.be(18);
|
||||
const assertions = fileLayers.map(async function(fileLayer) {
|
||||
|
|
|
@ -69,6 +69,10 @@ export class ServiceSettings {
|
|||
return origin === ORIGIN.EMS && this._showZoomMessage;
|
||||
}
|
||||
|
||||
enableZoomMessage() {
|
||||
this._showZoomMessage = true;
|
||||
}
|
||||
|
||||
disableZoomMessage() {
|
||||
this._showZoomMessage = false;
|
||||
}
|
||||
|
@ -148,11 +152,12 @@ export class ServiceSettings {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add optional query-parameters to all requests
|
||||
* Set optional query-parameters for all requests
|
||||
*
|
||||
* @param additionalQueryParams
|
||||
*/
|
||||
addQueryParams(additionalQueryParams) {
|
||||
setQueryParams(additionalQueryParams) {
|
||||
// Functions more as a "set" than an "add" in ems-client
|
||||
this._emsClient.addQueryParams(additionalQueryParams);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import { graph } from './legacy/plugins/graph';
|
|||
import { monitoring } from './legacy/plugins/monitoring';
|
||||
import { reporting } from './legacy/plugins/reporting';
|
||||
import { security } from './legacy/plugins/security';
|
||||
import { tilemap } from './legacy/plugins/tilemap';
|
||||
import { dashboardMode } from './legacy/plugins/dashboard_mode';
|
||||
import { logstash } from './legacy/plugins/logstash';
|
||||
import { beats } from './legacy/plugins/beats_management';
|
||||
|
@ -40,7 +39,6 @@ module.exports = function(kibana) {
|
|||
reporting(kibana),
|
||||
spaces(kibana),
|
||||
security(kibana),
|
||||
tilemap(kibana),
|
||||
dashboardMode(kibana),
|
||||
logstash(kibana),
|
||||
beats(kibana),
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
|
||||
import { inspectSettings } from './server/lib/inspect_settings';
|
||||
import { resolve } from 'path';
|
||||
|
||||
export const tilemap = kibana => {
|
||||
return new kibana.Plugin({
|
||||
id: 'tilemap',
|
||||
configPrefix: 'xpack.tilemap',
|
||||
require: ['xpack_main', 'vis_type_vislib'],
|
||||
publicDir: resolve(__dirname, 'public'),
|
||||
uiExports: {
|
||||
hacks: ['plugins/tilemap/vis_type_enhancers/update_tilemap_settings'],
|
||||
},
|
||||
init: function(server) {
|
||||
const thisPlugin = this;
|
||||
const xpackMainPlugin = server.plugins.xpack_main;
|
||||
mirrorPluginStatus(xpackMainPlugin, thisPlugin);
|
||||
xpackMainPlugin.status.once('green', () => {
|
||||
xpackMainPlugin.info
|
||||
.feature(thisPlugin.id)
|
||||
.registerLicenseCheckResultsGenerator(inspectSettings);
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
|
||||
import { npSetup } from 'ui/new_platform';
|
||||
|
||||
const tileMapPluginInfo = xpackInfo.get('features.tilemap');
|
||||
|
||||
if (tileMapPluginInfo && (tileMapPluginInfo.license.active || tileMapPluginInfo.license.valid)) {
|
||||
const { serviceSettings } = npSetup.plugins.mapsLegacy;
|
||||
serviceSettings.addQueryParams({ license: tileMapPluginInfo.license.uid });
|
||||
serviceSettings.disableZoomMessage();
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { inspectSettings } from '../../../server/lib/inspect_settings';
|
||||
|
||||
describe('inspectSettings', function() {
|
||||
it('should propagate x-pack info', function() {
|
||||
const mockSettings = {
|
||||
isAvailable: () => true,
|
||||
license: {
|
||||
getUid: () => 'foobar',
|
||||
isActive: () => true,
|
||||
isOneOf: () => true,
|
||||
},
|
||||
};
|
||||
|
||||
const licenseInfo = inspectSettings(mockSettings);
|
||||
expect(licenseInfo.license.uid).to.equal('foobar');
|
||||
expect(licenseInfo.license.active).to.equal(true);
|
||||
expect(licenseInfo.license.valid).to.equal(true);
|
||||
});
|
||||
|
||||
it('should break when unavailable info', function() {
|
||||
const mockSettings = {
|
||||
isAvailable: () => false,
|
||||
};
|
||||
|
||||
const licenseInfo = inspectSettings(mockSettings);
|
||||
expect(licenseInfo).to.have.property('message');
|
||||
expect(typeof licenseInfo.message === 'string').to.be.ok();
|
||||
});
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export function inspectSettings(xpackInfo) {
|
||||
if (!xpackInfo || !xpackInfo.isAvailable()) {
|
||||
return {
|
||||
message:
|
||||
'You cannot use the Tilemap Plugin because license information is not available at this time.',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*Propagate these settings to the client
|
||||
*/
|
||||
return {
|
||||
license: {
|
||||
uid: xpackInfo.license.getUid(),
|
||||
active: xpackInfo.license.isActive(),
|
||||
valid: xpackInfo.license.isOneOf([
|
||||
'trial',
|
||||
'standard',
|
||||
'basic',
|
||||
'gold',
|
||||
'platinum',
|
||||
'enterprise',
|
||||
]),
|
||||
},
|
||||
};
|
||||
}
|
8
x-pack/plugins/maps_legacy_licensing/kibana.json
Normal file
8
x-pack/plugins/maps_legacy_licensing/kibana.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"id": "mapsLegacyLicensing",
|
||||
"version": "8.0.0",
|
||||
"kibanaVersion": "kibana",
|
||||
"server": false,
|
||||
"ui": true,
|
||||
"requiredPlugins": ["licensing", "mapsLegacy"]
|
||||
}
|
11
x-pack/plugins/maps_legacy_licensing/public/index.ts
Normal file
11
x-pack/plugins/maps_legacy_licensing/public/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { MapsLegacyLicensing } from './plugin';
|
||||
|
||||
export function plugin() {
|
||||
return new MapsLegacyLicensing();
|
||||
}
|
49
x-pack/plugins/maps_legacy_licensing/public/plugin.ts
Normal file
49
x-pack/plugins/maps_legacy_licensing/public/plugin.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
|
||||
import { LicensingPluginSetup, ILicense } from '../../licensing/public';
|
||||
|
||||
/**
|
||||
* These are the interfaces with your public contracts. You should export these
|
||||
* for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces.
|
||||
* @public
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface MapsLegacyLicensingSetupDependencies {
|
||||
licensing: LicensingPluginSetup;
|
||||
mapsLegacy: any;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface MapsLegacyLicensingStartDependencies {}
|
||||
|
||||
export type MapsLegacyLicensingSetup = ReturnType<MapsLegacyLicensing['setup']>;
|
||||
export type MapsLegacyLicensingStart = ReturnType<MapsLegacyLicensing['start']>;
|
||||
|
||||
export class MapsLegacyLicensing
|
||||
implements Plugin<MapsLegacyLicensingSetup, MapsLegacyLicensingStart> {
|
||||
public setup(core: CoreSetup, plugins: MapsLegacyLicensingSetupDependencies) {
|
||||
const {
|
||||
licensing,
|
||||
mapsLegacy: { serviceSettings },
|
||||
} = plugins;
|
||||
if (licensing) {
|
||||
licensing.license$.subscribe((license: ILicense) => {
|
||||
const { uid, isActive } = license;
|
||||
if (isActive && license.hasAtLeast('basic')) {
|
||||
serviceSettings.setQueryParams({ license: uid });
|
||||
serviceSettings.disableZoomMessage();
|
||||
} else {
|
||||
serviceSettings.setQueryParams({ license: undefined });
|
||||
serviceSettings.enableZoomMessage();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public start(core: CoreStart, plugins: MapsLegacyLicensingStartDependencies) {}
|
||||
}
|
|
@ -50,14 +50,9 @@ export default function(ftrContext: FtrProviderContext) {
|
|||
await scenario.startBasic();
|
||||
await scenario.waitForPluginToDetectLicenseUpdate();
|
||||
|
||||
const { body: legacyBasicLicense, header: legacyBasicLicenseHeaders } = await supertest
|
||||
.get('/api/xpack/v1/info')
|
||||
.expect(200);
|
||||
const { body: legacyBasicLicense } = await supertest.get('/api/xpack/v1/info').expect(200);
|
||||
expect(legacyBasicLicense.license?.type).to.be('basic');
|
||||
expect(legacyBasicLicense.features).to.have.property('security');
|
||||
expect(legacyBasicLicenseHeaders['kbn-xpack-sig']).to.not.be(
|
||||
legacyInitialLicenseHeaders['kbn-xpack-sig']
|
||||
);
|
||||
|
||||
// banner shown only when license expired not just deleted
|
||||
await testSubjects.missingOrFail('licenseExpiredBanner');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue