Skip to content

Commit

Permalink
Add snapshotsUrl to Cloud plugin public interface. (#110328)
Browse files Browse the repository at this point in the history
* Add unit tests for Cloud plugin setup interface.
  • Loading branch information
cjcenizal authored Sep 1, 2021
1 parent f58865c commit cf8ab3b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugins/cloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/cloud/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
59 changes: 59 additions & 0 deletions x-pack/plugins/cloud/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
16 changes: 12 additions & 4 deletions x-pack/plugins/cloud/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,6 +54,7 @@ export interface CloudSetup {
deploymentUrl?: string;
profileUrl?: string;
organizationUrl?: string;
snapshotsUrl?: string;
isCloudEnabled: boolean;
}

Expand All @@ -80,6 +81,7 @@ export class CloudPlugin implements Plugin<CloudSetup> {
deployment_url: deploymentUrl,
base_url: baseUrl,
} = this.config;

this.isCloudEnabled = getIsCloudEnabled(id);

if (home) {
Expand All @@ -89,13 +91,19 @@ export class CloudPlugin implements Plugin<CloudSetup> {
}
}

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,
};
}
Expand Down

0 comments on commit cf8ab3b

Please sign in to comment.