Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] add on-prem EMS config #82525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c8ed09f
add boilerplate
thomasneirynck Nov 3, 2020
a9d871e
backfill settings
thomasneirynck Nov 3, 2020
0eb01e3
backfill everywhere
thomasneirynck Nov 3, 2020
0bbd273
add test coverage
thomasneirynck Nov 3, 2020
9ad682c
small edits
thomasneirynck Nov 3, 2020
1a5b486
Merge branch 'master' of github.com:elastic/kibana into maps/add_ems_…
thomasneirynck Nov 4, 2020
fe0fc20
make types explicit
thomasneirynck Nov 4, 2020
03800ae
add override behavior
thomasneirynck Nov 4, 2020
accecad
remove imports
thomasneirynck Nov 4, 2020
d0c57ec
extract config from type-def
thomasneirynck Nov 4, 2020
01576a0
expose setting client-side
thomasneirynck Nov 5, 2020
34eb5fc
Merge branch 'master' of github.com:elastic/kibana into maps/add_ems_…
thomasneirynck Nov 5, 2020
bcaba55
dont use on-prem settings in visualizations
thomasneirynck Nov 5, 2020
5124fd5
move ems-settings outside OSS
thomasneirynck Nov 5, 2020
18e05ed
move mirrored getters
thomasneirynck Nov 5, 2020
f4399d1
move isEnabled
thomasneirynck Nov 5, 2020
223c9b1
allow on-prem to override settings
thomasneirynck Nov 5, 2020
987b3c8
add license check
thomasneirynck Nov 5, 2020
c8e2ce6
disable in legacy viz
thomasneirynck Nov 6, 2020
dd8fe10
fix tests/remove mirrored methods
thomasneirynck Nov 6, 2020
ec375fd
type check
thomasneirynck Nov 6, 2020
d9a297a
move to common
thomasneirynck Nov 6, 2020
cfb5bf1
also use settings ont he server
thomasneirynck Nov 6, 2020
55cc931
export from common
thomasneirynck Nov 6, 2020
3de1b89
Merge branch 'master' of github.com:elastic/kibana into maps/add_ems_…
thomasneirynck Nov 6, 2020
9bba67d
respond to license changes on the server
thomasneirynck Nov 6, 2020
04bf9bb
Merge branch 'master' of github.com:elastic/kibana into maps/add_ems_…
thomasneirynck Nov 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/plugins/maps_legacy/common/ems_defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Default config for the elastic hosted EMS endpoints
export const DEFAULT_EMS_FILE_API_URL = 'https://vector.maps.elastic.co';
export const DEFAULT_EMS_TILE_API_URL = 'https://tiles.maps.elastic.co';
export const DEFAULT_EMS_LANDING_PAGE_URL = 'https://maps.elastic.co/v7.10';
export const DEFAULT_EMS_FONT_LIBRARY_URL =
'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf';
20 changes: 20 additions & 0 deletions src/plugins/maps_legacy/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './ems_defaults';
19 changes: 15 additions & 4 deletions src/plugins/maps_legacy/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ import { schema, TypeOf } from '@kbn/config-schema';
import { configSchema as tilemapSchema } from '../tile_map/config';
import { configSchema as regionmapSchema } from '../region_map/config';

import {
DEFAULT_EMS_FONT_LIBRARY_URL,
DEFAULT_EMS_LANDING_PAGE_URL,
DEFAULT_EMS_TILE_API_URL,
DEFAULT_EMS_FILE_API_URL,
} from './common/ems_defaults';

export const configSchema = schema.object({
includeElasticMapsService: schema.boolean({ defaultValue: true }),
proxyElasticMapsServiceInMaps: schema.boolean({ defaultValue: false }),
tilemap: tilemapSchema,
regionmap: regionmapSchema,
manifestServiceUrl: schema.string({ defaultValue: '' }),
emsFileApiUrl: schema.string({ defaultValue: 'https://vector.maps.elastic.co' }),
emsTileApiUrl: schema.string({ defaultValue: 'https://tiles.maps.elastic.co' }),
emsLandingPageUrl: schema.string({ defaultValue: 'https://maps.elastic.co/v7.10' }),

emsUrl: schema.string({ defaultValue: '' }),

emsFileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_FILE_API_URL }),
emsTileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_TILE_API_URL }),
emsLandingPageUrl: schema.string({ defaultValue: DEFAULT_EMS_LANDING_PAGE_URL }),
emsFontLibraryUrl: schema.string({
defaultValue: 'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf',
defaultValue: DEFAULT_EMS_FONT_LIBRARY_URL,
}),

emsTileLayerId: schema.object({
bright: schema.string({ defaultValue: 'road_map' }),
desaturated: schema.string({ defaultValue: 'road_map_desaturated' }),
Expand Down
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"configPath": ["map"],
"ui": true,
"server": true,
"extraPublicDirs": ["common"],
"requiredBundles": ["kibanaReact", "charts"]
}
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export {
mapTooltipProvider,
};

export * from '../common';
export * from './common/types';
export { ORIGIN } from './common/constants/origin';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/maps_legacy/public/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class ServiceSettings {
allServices.push(tmsService);
}

if (this._mapConfig.includeElasticMapsService) {
if (this._mapConfig.includeElasticMapsService && !this._mapConfig.emsUrl) {
const servicesFromManifest = await this._emsClient.getTMSServices();
const strippedServiceFromManifest = await Promise.all(
servicesFromManifest
Expand Down
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const config: PluginConfigDescriptor<MapsLegacyConfig> = {
tilemap: true,
regionmap: true,
manifestServiceUrl: true,
emsUrl: true,
emsFileApiUrl: true,
emsTileApiUrl: true,
emsLandingPageUrl: true,
Expand Down
221 changes: 221 additions & 0 deletions x-pack/plugins/maps/common/ems_settings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*
* 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 { EMSSettings, IEMSConfig } from './ems_settings';
import {
DEFAULT_EMS_FILE_API_URL,
DEFAULT_EMS_FONT_LIBRARY_URL,
DEFAULT_EMS_LANDING_PAGE_URL,
DEFAULT_EMS_TILE_API_URL,
} from '../../../../src/plugins/maps_legacy/common';

const IS_ENTERPRISE_PLUS = () => true;

describe('EMSSettings', () => {
const mockConfig: IEMSConfig = {
includeElasticMapsService: true,
proxyElasticMapsServiceInMaps: false,
emsUrl: '',
emsFileApiUrl: DEFAULT_EMS_FILE_API_URL,
emsTileApiUrl: DEFAULT_EMS_TILE_API_URL,
emsLandingPageUrl: DEFAULT_EMS_LANDING_PAGE_URL,
emsFontLibraryUrl: DEFAULT_EMS_FONT_LIBRARY_URL,
isEMSEnabled: true,
};

describe('isEMSEnabled/isOnPrem', () => {
test('should validate defaults', () => {
const emsSettings = new EMSSettings(mockConfig, IS_ENTERPRISE_PLUS);
expect(emsSettings.isEMSEnabled()).toBe(true);
expect(emsSettings.isOnPrem()).toBe(false);
});

test('should validate if on-prem is turned on', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.isEMSEnabled()).toBe(true);
expect(emsSettings.isOnPrem()).toBe(true);
});

test('should not validate if ems turned off', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
includeElasticMapsService: false,
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.isEMSEnabled()).toBe(false);
expect(emsSettings.isOnPrem()).toBe(false);
});

test('should work if ems is turned off, but on-prem is turned on', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
includeElasticMapsService: false,
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.isEMSEnabled()).toBe(true);
expect(emsSettings.isOnPrem()).toBe(true);
});

describe('when license is turned off', () => {
test('should not be enabled', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
},
},
() => false
);
expect(emsSettings.isEMSEnabled()).toBe(false);
expect(emsSettings.isOnPrem()).toBe(true);
});
});
});

describe('emsUrl setting', () => {
describe('when emsUrl is not set', () => {
test('should respect defaults', () => {
const emsSettings = new EMSSettings(mockConfig, IS_ENTERPRISE_PLUS);
expect(emsSettings.getEMSFileApiUrl()).toBe(DEFAULT_EMS_FILE_API_URL);
expect(emsSettings.getEMSTileApiUrl()).toBe(DEFAULT_EMS_TILE_API_URL);
expect(emsSettings.getEMSFontLibraryUrl()).toBe(DEFAULT_EMS_FONT_LIBRARY_URL);
expect(emsSettings.getEMSLandingPageUrl()).toBe(DEFAULT_EMS_LANDING_PAGE_URL);
});
test('should apply overrides', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsFileApiUrl: 'https://file.foobar',
emsTileApiUrl: 'https://tile.foobar',
emsFontLibraryUrl: 'https://tile.foobar/font',
emsLandingPageUrl: 'https://maps.foobar/v7.666',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://file.foobar');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://tile.foobar');
expect(emsSettings.getEMSFontLibraryUrl()).toBe('https://tile.foobar/font');
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://maps.foobar/v7.666');
});
});

describe('when emsUrl is set', () => {
test('should override defaults', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

describe('internal settings overrides (the below behavior is not publically supported, but aids internal debugging use-cases)', () => {
test(`should override internal emsFileApiUrl`, () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsFileApiUrl: 'https://file.foobar',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://file.foobar');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

test(`should override internal emsTileApiUrl`, () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsTileApiUrl: 'https://tile.foobar',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://tile.foobar');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

test('should override internal emsFontLibraryUrl', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsFontLibraryUrl: 'https://maps.foobar/fonts',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe('https://maps.foobar/fonts');
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

test('should override internal emsLandingPageUrl', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsLandingPageUrl: 'https://maps.foobar',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://maps.foobar');
});
});
});
});
});
Loading