Skip to content

Commit

Permalink
Update Cloud plugin to handle new config in kibana.yml (elastic#95569)
Browse files Browse the repository at this point in the history
* Handle cloud urls from kibana.yml

* Add types to utils params

* Update utils

* address nits

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
ryankeairns and kibanamachine authored Mar 31, 2021
1 parent 7ef8be6 commit b301d41
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
*/

import { i18n } from '@kbn/i18n';

export const cloudPasswordAndResetLink = i18n.translate(
'home.tutorials.common.cloudInstructions.passwordAndResetLink',
{
defaultMessage:
'Where {passwordTemplate} is the password of the `elastic` user.' +
`\\{#config.cloud.resetPasswordUrl\\}
Forgot the password? [Reset in Elastic Cloud](\\{config.cloud.resetPasswordUrl\\}).
\\{/config.cloud.resetPasswordUrl\\}`,
`\\{#config.cloud.profileUrl\\}
Forgot the password? [Reset in Elastic Cloud](\\{config.cloud.baseUrl\\}\\{config.cloud.profileUrl\\}).
\\{/config.cloud.profileUrl\\}`,
values: { passwordTemplate: '`<password>`' },
}
);
7 changes: 5 additions & 2 deletions x-pack/plugins/cloud/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ function createSetupMock() {
return {
cloudId: 'mock-cloud-id',
isCloudEnabled: true,
resetPasswordUrl: 'reset-password-url',
accountUrl: 'account-url',
cname: 'cname',
baseUrl: 'base-url',
deploymentUrl: 'deployment-url',
profileUrl: 'profile-url',
organizationUrl: 'organization-url',
};
}

Expand Down
40 changes: 28 additions & 12 deletions x-pack/plugins/cloud/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import { getIsCloudEnabled } from '../common/is_cloud_enabled';
import { ELASTIC_SUPPORT_LINK } from '../common/constants';
import { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
import { createUserMenuLinks } from './user_menu_links';
import { getFullCloudUrl } from './utils';

export interface CloudConfigType {
id?: string;
resetPasswordUrl?: string;
deploymentUrl?: string;
accountUrl?: string;
cname?: string;
base_url?: string;
profile_url?: string;
deployment_url?: string;
organization_url?: string;
}

interface CloudSetupDependencies {
Expand All @@ -30,10 +33,12 @@ interface CloudStartDependencies {

export interface CloudSetup {
cloudId?: string;
cloudDeploymentUrl?: string;
cname?: string;
baseUrl?: string;
deploymentUrl?: string;
profileUrl?: string;
organizationUrl?: string;
isCloudEnabled: boolean;
resetPasswordUrl?: string;
accountUrl?: string;
}

export class CloudPlugin implements Plugin<CloudSetup> {
Expand All @@ -46,33 +51,44 @@ export class CloudPlugin implements Plugin<CloudSetup> {
}

public setup(core: CoreSetup, { home }: CloudSetupDependencies) {
const { id, resetPasswordUrl, deploymentUrl } = this.config;
const {
id,
cname,
profile_url: profileUrl,
organization_url: organizationUrl,
deployment_url: deploymentUrl,
base_url: baseUrl,
} = this.config;
this.isCloudEnabled = getIsCloudEnabled(id);

if (home) {
home.environment.update({ cloud: this.isCloudEnabled });
if (this.isCloudEnabled) {
home.tutorials.setVariable('cloud', { id, resetPasswordUrl });
home.tutorials.setVariable('cloud', { id, baseUrl, profileUrl });
}
}

return {
cloudId: id,
cloudDeploymentUrl: deploymentUrl,
cname,
baseUrl,
deploymentUrl: getFullCloudUrl(baseUrl, deploymentUrl),
profileUrl: getFullCloudUrl(baseUrl, profileUrl),
organizationUrl: getFullCloudUrl(baseUrl, organizationUrl),
isCloudEnabled: this.isCloudEnabled,
};
}

public start(coreStart: CoreStart, { security }: CloudStartDependencies) {
const { deploymentUrl } = this.config;
const { deployment_url: deploymentUrl, base_url: baseUrl } = this.config;
coreStart.chrome.setHelpSupportUrl(ELASTIC_SUPPORT_LINK);
if (deploymentUrl) {
if (baseUrl && deploymentUrl) {
coreStart.chrome.setCustomNavLink({
title: i18n.translate('xpack.cloud.deploymentLinkLabel', {
defaultMessage: 'Manage this deployment',
}),
euiIconType: 'arrowLeft',
href: deploymentUrl,
href: getFullCloudUrl(baseUrl, deploymentUrl),
});
}

Expand Down
11 changes: 6 additions & 5 deletions x-pack/plugins/cloud/public/user_menu_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
import { i18n } from '@kbn/i18n';
import { UserMenuLink } from '../../security/public';
import { CloudConfigType } from '.';
import { getFullCloudUrl } from './utils';

export const createUserMenuLinks = (config: CloudConfigType): UserMenuLink[] => {
const { resetPasswordUrl, accountUrl } = config;
const { profile_url: profileUrl, organization_url: organizationUrl, base_url: baseUrl } = config;
const userMenuLinks = [] as UserMenuLink[];

if (resetPasswordUrl) {
if (baseUrl && profileUrl) {
userMenuLinks.push({
label: i18n.translate('xpack.cloud.userMenuLinks.profileLinkText', {
defaultMessage: 'Profile',
}),
iconType: 'user',
href: resetPasswordUrl,
href: getFullCloudUrl(baseUrl, profileUrl),
order: 100,
setAsProfile: true,
});
}

if (accountUrl) {
if (baseUrl && organizationUrl) {
userMenuLinks.push({
label: i18n.translate('xpack.cloud.userMenuLinks.accountLinkText', {
defaultMessage: 'Account & Billing',
}),
iconType: 'gear',
href: accountUrl,
href: getFullCloudUrl(baseUrl, organizationUrl),
order: 200,
});
}
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/cloud/public/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export function getFullCloudUrl(baseUrl: string | undefined, dirPath: string | undefined) {
if (baseUrl && dirPath) {
return `${baseUrl}${dirPath}`;
}

return '';
}
16 changes: 10 additions & 6 deletions x-pack/plugins/cloud/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
id: schema.maybe(schema.string()),
apm: schema.maybe(apmConfigSchema),
resetPasswordUrl: schema.maybe(schema.string()),
deploymentUrl: schema.maybe(schema.string()),
accountUrl: schema.maybe(schema.string()),
cname: schema.maybe(schema.string()),
base_url: schema.maybe(schema.string()),
profile_url: schema.maybe(schema.string()),
deployment_url: schema.maybe(schema.string()),
organization_url: schema.maybe(schema.string()),
});

export type CloudConfigType = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<CloudConfigType> = {
exposeToBrowser: {
id: true,
resetPasswordUrl: true,
deploymentUrl: true,
accountUrl: true,
cname: true,
base_url: true,
profile_url: true,
deployment_url: true,
organization_url: true,
},
schema: configSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const mockKibanaValues = {
charts: chartPluginMock.createStartContract(),
cloud: {
isCloudEnabled: false,
cloudDeploymentUrl: 'https://cloud.elastic.co/deployments/some-id',
deployment_url: 'https://cloud.elastic.co/deployments/some-id',
},
history: mockHistory,
navigateToUrl: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const SetupGuideLayout: React.FC<Props> = ({
}) => {
const { cloud } = useValues(KibanaLogic);
const isCloudEnabled = Boolean(cloud.isCloudEnabled);
const cloudDeploymentLink = cloud.cloudDeploymentUrl || '';
const cloudDeploymentLink = cloud.deploymentUrl || '';

return (
<EuiPage className="setupGuide">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const DataTierAllocationField: FunctionComponent<Props> = ({ phase, descr

const hasNodeAttrs = Boolean(Object.keys(nodesByAttributes ?? {}).length);
const isCloudEnabled = cloud?.isCloudEnabled ?? false;
const cloudDeploymentUrl = cloud?.cloudDeploymentUrl;
const cloudDeploymentUrl = cloud?.deploymentUrl;

const renderNotice = () => {
switch (allocationType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
EuiIcon,
EuiLoadingSpinner,
EuiPopover,
EuiText,
} from '@elastic/eui';
import React, { Component } from 'react';
import type { Observable, Subscription } from 'rxjs';
Expand Down Expand Up @@ -128,7 +127,7 @@ export class SecurityNavControl extends Component<Props, State> {
const userMenuLinkMenuItems = userMenuLinks
.sort(({ order: orderA = Infinity }, { order: orderB = Infinity }) => orderA - orderB)
.map(({ label, iconType, href }: UserMenuLink) => ({
name: <EuiText>{label}</EuiText>,
name: label,
icon: <EuiIcon type={iconType} size="m" />,
href,
'data-test-subj': `userMenuLink__${label}`,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@
"home.tutorials.common.auditbeatStatusCheck.successText": "データを受信しました",
"home.tutorials.common.auditbeatStatusCheck.text": "Auditbeat からデータを受け取ったことを確認してください。",
"home.tutorials.common.auditbeatStatusCheck.title": "ステータス",
"home.tutorials.common.cloudInstructions.passwordAndResetLink": "{passwordTemplate}が「Elastic」ユーザーのパスワードです。\\{#config.cloud.resetPasswordUrl\\}\n パスワードを忘れた場合[Elastic Cloudでリセット] (\\{config.cloud.resetPasswordUrl\\}) 。\n \\{/config.cloud.resetPasswordUrl\\}",
"home.tutorials.common.cloudInstructions.passwordAndResetLink": "{passwordTemplate}が「Elastic」ユーザーのパスワードです。\\{#config.cloud.base_url\\}\\{#config.cloud.profile_url\\}\n パスワードを忘れた場合[Elastic Cloudでリセット] (\\{#config.cloud.base_url\\}\\{config.cloud.profile_url\\}) 。\n \\{#config.cloud.base_url\\}\\{/config.cloud.profile_url\\}",
"home.tutorials.common.filebeat.cloudInstructions.gettingStarted.title": "はじめに",
"home.tutorials.common.filebeat.premCloudInstructions.gettingStarted.title": "はじめに",
"home.tutorials.common.filebeat.premInstructions.gettingStarted.title": "はじめに",
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@
"home.tutorials.common.auditbeatStatusCheck.successText": "已成功接收数据",
"home.tutorials.common.auditbeatStatusCheck.text": "确认从 Auditbeat 收到数据",
"home.tutorials.common.auditbeatStatusCheck.title": "状态",
"home.tutorials.common.cloudInstructions.passwordAndResetLink": "其中 {passwordTemplate} 是用户 `elastic` 的密码。\\{#config.cloud.resetPasswordUrl\\}\n 忘了密码?[在 Elastic Cloud 中重置](\\{config.cloud.resetPasswordUrl\\})。\n \\{/config.cloud.resetPasswordUrl\\}",
"home.tutorials.common.cloudInstructions.passwordAndResetLink": "其中 {passwordTemplate} 是用户 `elastic` 的密码。\\{#config.cloud.base_url\\}\\{#config.cloud.profile_url\\}\n 忘了密码?[在 Elastic Cloud 中重置](\\{#config.cloud.base_url\\}\\{config.cloud.profile_url\\})。\n \\{#config.cloud.base_url\\}\\{/config.cloud.profile_url\\}",
"home.tutorials.common.filebeat.cloudInstructions.gettingStarted.title": "入门",
"home.tutorials.common.filebeat.premCloudInstructions.gettingStarted.title": "入门",
"home.tutorials.common.filebeat.premInstructions.gettingStarted.title": "入门",
Expand Down

0 comments on commit b301d41

Please sign in to comment.