Update Cloud plugin to handle new config in kibana.yml (#95569)

* 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>
This commit is contained in:
Ryan Keairns 2021-03-31 07:49:50 -05:00 committed by GitHub
parent 7ef8be6031
commit b301d416b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 72 additions and 36 deletions

View file

@ -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>`' },
}
);

View file

@ -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',
};
}

View file

@ -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 {
@ -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> {
@ -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),
});
}

View file

@ -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,
});
}

View file

@ -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 '';
}

View file

@ -22,9 +22,11 @@ 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>;
@ -32,9 +34,11 @@ 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,
};

View file

@ -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(),

View file

@ -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">

View file

@ -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) {

View file

@ -15,7 +15,6 @@ import {
EuiIcon,
EuiLoadingSpinner,
EuiPopover,
EuiText,
} from '@elastic/eui';
import React, { Component } from 'react';
import type { Observable, Subscription } from 'rxjs';
@ -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}`,

View file

@ -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": "はじめに",

View file

@ -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": "入门",