Skip to content

Commit

Permalink
Migrate legacy maps licensing (x-pack/tilemap) to NP (elastic#63539)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Aaron Caldwell committed Apr 17, 2020
1 parent 19ed395 commit ae1e9d3
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 133 deletions.
16 changes: 8 additions & 8 deletions src/plugins/maps_legacy/public/__tests__/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,32 @@ 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' });
});

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' });
});
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/maps_legacy/public/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export class ServiceSettings {
return origin === ORIGIN.EMS && this._showZoomMessage;
}

enableZoomMessage() {
this._showZoomMessage = true;
}

disableZoomMessage() {
this._showZoomMessage = false;
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -40,7 +39,6 @@ module.exports = function(kibana) {
reporting(kibana),
spaces(kibana),
security(kibana),
tilemap(kibana),
dashboardMode(kibana),
logstash(kibana),
beats(kibana),
Expand Down
31 changes: 0 additions & 31 deletions x-pack/legacy/plugins/tilemap/index.js

This file was deleted.

This file was deleted.

This file was deleted.

32 changes: 0 additions & 32 deletions x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js

This file was deleted.

File renamed without changes.
8 changes: 8 additions & 0 deletions x-pack/plugins/maps_legacy_licensing/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "mapsLegacyLicensing",
"version": "8.0.0",
"kibanaVersion": "kibana",
"server": false,
"ui": true,
"requiredPlugins": ["licensing", "mapsLegacy"]
}
11 changes: 11 additions & 0 deletions x-pack/plugins/maps_legacy_licensing/public/index.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions x-pack/plugins/maps_legacy_licensing/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -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) {}
}
7 changes: 1 addition & 6 deletions x-pack/test/licensing_plugin/legacy/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ae1e9d3

Please sign in to comment.