Skip to content

Commit 57e97ac

Browse files
committed
Handle cloud urls from kibana.yml
1 parent 8961f85 commit 57e97ac

12 files changed

Lines changed: 71 additions & 36 deletions

File tree

src/plugins/home/server/tutorials/instructions/cloud_instructions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
*/
88

99
import { i18n } from '@kbn/i18n';
10-
1110
export const cloudPasswordAndResetLink = i18n.translate(
1211
'home.tutorials.common.cloudInstructions.passwordAndResetLink',
1312
{
1413
defaultMessage:
1514
'Where {passwordTemplate} is the password of the `elastic` user.' +
16-
`\\{#config.cloud.resetPasswordUrl\\}
17-
Forgot the password? [Reset in Elastic Cloud](\\{config.cloud.resetPasswordUrl\\}).
18-
\\{/config.cloud.resetPasswordUrl\\}`,
15+
`\\{#config.cloud.profile_url\\}
16+
Forgot the password? [Reset in Elastic Cloud](\\{config.cloud.base_url\\}\\{config.cloud.profile_url\\}).
17+
\\{/config.cloud.profile_url\\}`,
1918
values: { passwordTemplate: '`<password>`' },
2019
}
2120
);

x-pack/plugins/cloud/public/mocks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ function createSetupMock() {
99
return {
1010
cloudId: 'mock-cloud-id',
1111
isCloudEnabled: true,
12-
resetPasswordUrl: 'reset-password-url',
13-
accountUrl: 'account-url',
12+
cname: 'cname',
13+
baseUrl: 'base-url',
14+
deploymentUrl: 'deployment-url',
15+
profileUrl: 'profile-url',
16+
organizationUrl: 'organization-url',
1417
};
1518
}
1619

x-pack/plugins/cloud/public/plugin.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import { getIsCloudEnabled } from '../common/is_cloud_enabled';
1212
import { ELASTIC_SUPPORT_LINK } from '../common/constants';
1313
import { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
1414
import { createUserMenuLinks } from './user_menu_links';
15+
import { getFullCloudUrl } from './utils';
1516

1617
export interface CloudConfigType {
1718
id?: string;
18-
resetPasswordUrl?: string;
19-
deploymentUrl?: string;
20-
accountUrl?: string;
19+
cname?: string;
20+
base_url?: string;
21+
profile_url?: string;
22+
deployment_url?: string;
23+
organization_url?: string;
2124
}
2225

2326
interface CloudSetupDependencies {
@@ -30,10 +33,12 @@ interface CloudStartDependencies {
3033

3134
export interface CloudSetup {
3235
cloudId?: string;
33-
cloudDeploymentUrl?: string;
36+
cname?: string;
37+
baseUrl?: string;
38+
deploymentUrl?: string;
39+
profileUrl?: string;
40+
organizationUrl?: string;
3441
isCloudEnabled: boolean;
35-
resetPasswordUrl?: string;
36-
accountUrl?: string;
3742
}
3843

3944
export class CloudPlugin implements Plugin<CloudSetup> {
@@ -46,33 +51,39 @@ export class CloudPlugin implements Plugin<CloudSetup> {
4651
}
4752

4853
public setup(core: CoreSetup, { home }: CloudSetupDependencies) {
49-
const { id, resetPasswordUrl, deploymentUrl } = this.config;
54+
// eslint-disable-next-line @typescript-eslint/naming-convention
55+
const { id, cname, profile_url, organization_url, deployment_url, base_url } = this.config;
5056
this.isCloudEnabled = getIsCloudEnabled(id);
5157

5258
if (home) {
5359
home.environment.update({ cloud: this.isCloudEnabled });
5460
if (this.isCloudEnabled) {
55-
home.tutorials.setVariable('cloud', { id, resetPasswordUrl });
61+
home.tutorials.setVariable('cloud', { id, base_url, profile_url });
5662
}
5763
}
5864

5965
return {
6066
cloudId: id,
61-
cloudDeploymentUrl: deploymentUrl,
67+
cname,
68+
baseUrl: base_url,
69+
deploymentUrl: getFullCloudUrl(base_url, deployment_url),
70+
profileUrl: getFullCloudUrl(base_url, profile_url),
71+
organizationUrl: getFullCloudUrl(base_url, organization_url),
6272
isCloudEnabled: this.isCloudEnabled,
6373
};
6474
}
6575

6676
public start(coreStart: CoreStart, { security }: CloudStartDependencies) {
67-
const { deploymentUrl } = this.config;
77+
// eslint-disable-next-line @typescript-eslint/naming-convention
78+
const { deployment_url, base_url } = this.config;
6879
coreStart.chrome.setHelpSupportUrl(ELASTIC_SUPPORT_LINK);
69-
if (deploymentUrl) {
80+
if (base_url && deployment_url) {
7081
coreStart.chrome.setCustomNavLink({
7182
title: i18n.translate('xpack.cloud.deploymentLinkLabel', {
7283
defaultMessage: 'Manage this deployment',
7384
}),
7485
euiIconType: 'arrowLeft',
75-
href: deploymentUrl,
86+
href: getFullCloudUrl(base_url, deployment_url),
7687
});
7788
}
7889

x-pack/plugins/cloud/public/user_menu_links.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,32 @@
88
import { i18n } from '@kbn/i18n';
99
import { UserMenuLink } from '../../security/public';
1010
import { CloudConfigType } from '.';
11+
import { getFullCloudUrl } from './utils';
1112

1213
export const createUserMenuLinks = (config: CloudConfigType): UserMenuLink[] => {
13-
const { resetPasswordUrl, accountUrl } = config;
14+
// eslint-disable-next-line @typescript-eslint/naming-convention
15+
const { profile_url, organization_url, base_url } = config;
1416
const userMenuLinks = [] as UserMenuLink[];
1517

16-
if (resetPasswordUrl) {
18+
if (base_url && profile_url) {
1719
userMenuLinks.push({
1820
label: i18n.translate('xpack.cloud.userMenuLinks.profileLinkText', {
1921
defaultMessage: 'Profile',
2022
}),
2123
iconType: 'user',
22-
href: resetPasswordUrl,
24+
href: getFullCloudUrl(base_url, profile_url),
2325
order: 100,
2426
setAsProfile: true,
2527
});
2628
}
2729

28-
if (accountUrl) {
30+
if (base_url && organization_url) {
2931
userMenuLinks.push({
3032
label: i18n.translate('xpack.cloud.userMenuLinks.accountLinkText', {
3133
defaultMessage: 'Account & Billing',
3234
}),
3335
iconType: 'gear',
34-
href: accountUrl,
36+
href: getFullCloudUrl(base_url, organization_url),
3537
order: 200,
3638
});
3739
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
export function getFullCloudUrl(baseUrl, dirPath) {
9+
let fullCloudUrl = '';
10+
11+
if (baseUrl && dirPath) {
12+
fullCloudUrl = baseUrl.concat(dirPath);
13+
} else {
14+
throw new Error(`Both a baseUrl and dirPath must be passed to the getFullCloudUrl function.`);
15+
}
16+
return fullCloudUrl;
17+
}

x-pack/plugins/cloud/server/config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@ const configSchema = schema.object({
2222
enabled: schema.boolean({ defaultValue: true }),
2323
id: schema.maybe(schema.string()),
2424
apm: schema.maybe(apmConfigSchema),
25-
resetPasswordUrl: schema.maybe(schema.string()),
26-
deploymentUrl: schema.maybe(schema.string()),
27-
accountUrl: schema.maybe(schema.string()),
25+
cname: schema.maybe(schema.string()),
26+
base_url: schema.maybe(schema.string()),
27+
profile_url: schema.maybe(schema.string()),
28+
deployment_url: schema.maybe(schema.string()),
29+
organization_url: schema.maybe(schema.string()),
2830
});
2931

3032
export type CloudConfigType = TypeOf<typeof configSchema>;
3133

3234
export const config: PluginConfigDescriptor<CloudConfigType> = {
3335
exposeToBrowser: {
3436
id: true,
35-
resetPasswordUrl: true,
36-
deploymentUrl: true,
37-
accountUrl: true,
37+
cname: true,
38+
base_url: true,
39+
profile_url: true,
40+
deployment_url: true,
41+
organization_url: true,
3842
},
3943
schema: configSchema,
4044
};

x-pack/plugins/enterprise_search/public/applications/__mocks__/kibana_logic.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const mockKibanaValues = {
1414
charts: chartPluginMock.createStartContract(),
1515
cloud: {
1616
isCloudEnabled: false,
17-
cloudDeploymentUrl: 'https://cloud.elastic.co/deployments/some-id',
17+
deployment_url: 'https://cloud.elastic.co/deployments/some-id',
1818
},
1919
history: mockHistory,
2020
navigateToUrl: jest.fn(),

x-pack/plugins/enterprise_search/public/applications/shared/setup_guide/setup_guide.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const SetupGuideLayout: React.FC<Props> = ({
5050
}) => {
5151
const { cloud } = useValues(KibanaLogic);
5252
const isCloudEnabled = Boolean(cloud.isCloudEnabled);
53-
const cloudDeploymentLink = cloud.cloudDeploymentUrl || '';
53+
const cloudDeploymentLink = cloud.deploymentUrl || '';
5454

5555
return (
5656
<EuiPage className="setupGuide">

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/data_tier_allocation_field/data_tier_allocation_field.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const DataTierAllocationField: FunctionComponent<Props> = ({ phase, descr
6060

6161
const hasNodeAttrs = Boolean(Object.keys(nodesByAttributes ?? {}).length);
6262
const isCloudEnabled = cloud?.isCloudEnabled ?? false;
63-
const cloudDeploymentUrl = cloud?.cloudDeploymentUrl;
63+
const cloudDeploymentUrl = cloud?.deploymentUrl;
6464

6565
const renderNotice = () => {
6666
switch (allocationType) {

x-pack/plugins/security/public/nav_control/nav_control_component.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
EuiIcon,
1616
EuiLoadingSpinner,
1717
EuiPopover,
18-
EuiText,
1918
} from '@elastic/eui';
2019
import React, { Component } from 'react';
2120
import type { Observable, Subscription } from 'rxjs';
@@ -128,7 +127,7 @@ export class SecurityNavControl extends Component<Props, State> {
128127
const userMenuLinkMenuItems = userMenuLinks
129128
.sort(({ order: orderA = Infinity }, { order: orderB = Infinity }) => orderA - orderB)
130129
.map(({ label, iconType, href }: UserMenuLink) => ({
131-
name: <EuiText>{label}</EuiText>,
130+
name: label,
132131
icon: <EuiIcon type={iconType} size="m" />,
133132
href,
134133
'data-test-subj': `userMenuLink__${label}`,

0 commit comments

Comments
 (0)