From cf8ab3bb119672b93904286a7e3844b2ed0b5c38 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 1 Sep 2021 14:42:01 -0700 Subject: [PATCH] Add snapshotsUrl to Cloud plugin public interface. (#110328) * Add unit tests for Cloud plugin setup interface. --- x-pack/plugins/cloud/README.md | 6 +++ x-pack/plugins/cloud/common/constants.ts | 5 ++ x-pack/plugins/cloud/public/plugin.test.ts | 59 ++++++++++++++++++++++ x-pack/plugins/cloud/public/plugin.ts | 16 ++++-- 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/cloud/README.md b/x-pack/plugins/cloud/README.md index 0e0a1c773979a..77f73a3eaea01 100644 --- a/x-pack/plugins/cloud/README.md +++ b/x-pack/plugins/cloud/README.md @@ -30,6 +30,12 @@ This is the path to the Cloud deployment management page for the deployment to w **Example:** `{baseUrl}/deployments/bfdad4ef99a24212a06d387593686d63` +### `snapshotsUrl` + +This is the path to the Snapshots page for the deployment to which the Kibana instance belongs. The value is already prepended with `deploymentUrl`. + +**Example:** `{deploymentUrl}/elasticsearch/snapshots` + ### `profileUrl` This is the path to the Cloud User Profile page. The value is already prepended with `baseUrl`. diff --git a/x-pack/plugins/cloud/common/constants.ts b/x-pack/plugins/cloud/common/constants.ts index 8d054addc9ce2..f2009223f8ac1 100644 --- a/x-pack/plugins/cloud/common/constants.ts +++ b/x-pack/plugins/cloud/common/constants.ts @@ -6,3 +6,8 @@ */ export const ELASTIC_SUPPORT_LINK = 'https://support.elastic.co/'; + +/** + * This is the page for managing your snapshots on Cloud. + */ +export const CLOUD_SNAPSHOTS_PATH = 'elasticsearch/snapshots/'; diff --git a/x-pack/plugins/cloud/public/plugin.test.ts b/x-pack/plugins/cloud/public/plugin.test.ts index 9b3ddc8e7294e..835a52cb814c8 100644 --- a/x-pack/plugins/cloud/public/plugin.test.ts +++ b/x-pack/plugins/cloud/public/plugin.test.ts @@ -141,6 +141,65 @@ describe('Cloud Plugin', () => { expect(initializeFullStoryMock).not.toHaveBeenCalled(); }); }); + + describe('interface', () => { + const setupPlugin = () => { + const initContext = coreMock.createPluginInitializerContext({ + id: 'cloudId', + cname: 'cloud.elastic.co', + base_url: 'https://cloud.elastic.co', + deployment_url: '/abc123', + profile_url: '/user/settings/', + organization_url: '/account/', + }); + const plugin = new CloudPlugin(initContext); + + const coreSetup = coreMock.createSetup(); + const setup = plugin.setup(coreSetup, {}); + + return { setup }; + }; + + it('exposes isCloudEnabled', () => { + const { setup } = setupPlugin(); + expect(setup.isCloudEnabled).toBe(true); + }); + + it('exposes cloudId', () => { + const { setup } = setupPlugin(); + expect(setup.cloudId).toBe('cloudId'); + }); + + it('exposes baseUrl', () => { + const { setup } = setupPlugin(); + expect(setup.baseUrl).toBe('https://cloud.elastic.co'); + }); + + it('exposes deploymentUrl', () => { + const { setup } = setupPlugin(); + expect(setup.deploymentUrl).toBe('https://cloud.elastic.co/abc123'); + }); + + it('exposes snapshotsUrl', () => { + const { setup } = setupPlugin(); + expect(setup.snapshotsUrl).toBe('https://cloud.elastic.co/abc123/elasticsearch/snapshots/'); + }); + + it('exposes profileUrl', () => { + const { setup } = setupPlugin(); + expect(setup.profileUrl).toBe('https://cloud.elastic.co/user/settings/'); + }); + + it('exposes organizationUrl', () => { + const { setup } = setupPlugin(); + expect(setup.organizationUrl).toBe('https://cloud.elastic.co/account/'); + }); + + it('exposes cname', () => { + const { setup } = setupPlugin(); + expect(setup.cname).toBe('cloud.elastic.co'); + }); + }); }); describe('#start', () => { diff --git a/x-pack/plugins/cloud/public/plugin.ts b/x-pack/plugins/cloud/public/plugin.ts index 16c11d569c5f7..29befcee397dd 100644 --- a/x-pack/plugins/cloud/public/plugin.ts +++ b/x-pack/plugins/cloud/public/plugin.ts @@ -20,7 +20,7 @@ import type { SecurityPluginStart, } from '../../security/public'; import { getIsCloudEnabled } from '../common/is_cloud_enabled'; -import { ELASTIC_SUPPORT_LINK } from '../common/constants'; +import { ELASTIC_SUPPORT_LINK, CLOUD_SNAPSHOTS_PATH } from '../common/constants'; import { HomePublicPluginSetup } from '../../../../src/plugins/home/public'; import { createUserMenuLinks } from './user_menu_links'; import { getFullCloudUrl } from './utils'; @@ -54,6 +54,7 @@ export interface CloudSetup { deploymentUrl?: string; profileUrl?: string; organizationUrl?: string; + snapshotsUrl?: string; isCloudEnabled: boolean; } @@ -80,6 +81,7 @@ export class CloudPlugin implements Plugin { deployment_url: deploymentUrl, base_url: baseUrl, } = this.config; + this.isCloudEnabled = getIsCloudEnabled(id); if (home) { @@ -89,13 +91,19 @@ export class CloudPlugin implements Plugin { } } + const fullCloudDeploymentUrl = getFullCloudUrl(baseUrl, deploymentUrl); + const fullCloudProfileUrl = getFullCloudUrl(baseUrl, profileUrl); + const fullCloudOrganizationUrl = getFullCloudUrl(baseUrl, organizationUrl); + const fullCloudSnapshotsUrl = `${fullCloudDeploymentUrl}/${CLOUD_SNAPSHOTS_PATH}`; + return { cloudId: id, cname, baseUrl, - deploymentUrl: getFullCloudUrl(baseUrl, deploymentUrl), - profileUrl: getFullCloudUrl(baseUrl, profileUrl), - organizationUrl: getFullCloudUrl(baseUrl, organizationUrl), + deploymentUrl: fullCloudDeploymentUrl, + profileUrl: fullCloudProfileUrl, + organizationUrl: fullCloudOrganizationUrl, + snapshotsUrl: fullCloudSnapshotsUrl, isCloudEnabled: this.isCloudEnabled, }; }