Skip to content

Commit acc41ff

Browse files
committed
Refactor: made security plugin a dep for the cloud plugin
1 parent 68e1faa commit acc41ff

File tree

15 files changed

+221
-128
lines changed

15 files changed

+221
-128
lines changed

x-pack/plugins/cloud/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "8.0.0",
44
"kibanaVersion": "kibana",
55
"configPath": ["xpack", "cloud"],
6-
"optionalPlugins": ["usageCollection", "home"],
6+
"optionalPlugins": ["usageCollection", "home", "security"],
77
"server": true,
88
"ui": true
99
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { PluginInitializerContext } from '../../../../src/core/public';
88
import { CloudPlugin } from './plugin';
99

10-
export { CloudSetup } from './plugin';
10+
export { CloudSetup, CloudConfigType } from './plugin';
1111
export function plugin(initializerContext: PluginInitializerContext) {
1212
return new CloudPlugin(initializerContext);
1313
}

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/public';
88
import { i18n } from '@kbn/i18n';
9+
import { SecurityPluginStart } from '../../security/public';
910
import { getIsCloudEnabled } from '../common/is_cloud_enabled';
1011
import { ELASTIC_SUPPORT_LINK } from '../common/constants';
1112
import { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
13+
import { createUserMenuLinks } from './user_menu_links';
1214

13-
interface CloudConfigType {
15+
export interface CloudConfigType {
1416
id?: string;
1517
resetPasswordUrl?: string;
1618
deploymentUrl?: string;
@@ -22,6 +24,10 @@ interface CloudSetupDependencies {
2224
home?: HomePublicPluginSetup;
2325
}
2426

27+
interface CloudStartDependencies {
28+
security?: SecurityPluginStart;
29+
}
30+
2531
export interface CloudSetup {
2632
cloudId?: string;
2733
cloudDeploymentUrl?: string;
@@ -33,33 +39,32 @@ export interface CloudSetup {
3339

3440
export class CloudPlugin implements Plugin<CloudSetup> {
3541
private config!: CloudConfigType;
42+
private isCloudEnabled: boolean;
3643

3744
constructor(private readonly initializerContext: PluginInitializerContext) {
3845
this.config = this.initializerContext.config.get<CloudConfigType>();
46+
this.isCloudEnabled = false;
3947
}
4048

4149
public async setup(core: CoreSetup, { home }: CloudSetupDependencies) {
42-
const { id, resetPasswordUrl, deploymentUrl, accountUrl, securityUrl } = this.config;
43-
const isCloudEnabled = getIsCloudEnabled(id);
50+
const { id, resetPasswordUrl, deploymentUrl } = this.config;
51+
this.isCloudEnabled = getIsCloudEnabled(id);
4452

4553
if (home) {
46-
home.environment.update({ cloud: isCloudEnabled });
47-
if (isCloudEnabled) {
54+
home.environment.update({ cloud: this.isCloudEnabled });
55+
if (this.isCloudEnabled) {
4856
home.tutorials.setVariable('cloud', { id, resetPasswordUrl });
4957
}
5058
}
5159

5260
return {
5361
cloudId: id,
5462
cloudDeploymentUrl: deploymentUrl,
55-
isCloudEnabled,
56-
resetPasswordUrl,
57-
accountUrl,
58-
securityUrl,
63+
isCloudEnabled: this.isCloudEnabled,
5964
};
6065
}
6166

62-
public start(coreStart: CoreStart) {
67+
public start(coreStart: CoreStart, { security }: CloudStartDependencies) {
6368
const { deploymentUrl } = this.config;
6469
coreStart.chrome.setHelpSupportUrl(ELASTIC_SUPPORT_LINK);
6570
if (deploymentUrl) {
@@ -71,5 +76,10 @@ export class CloudPlugin implements Plugin<CloudSetup> {
7176
href: deploymentUrl,
7277
});
7378
}
79+
80+
if (security && this.isCloudEnabled) {
81+
const userMenuLinks = createUserMenuLinks(this.config);
82+
security.navControlService.setUserMenuLinks(userMenuLinks);
83+
}
7484
}
7585
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { UserMenuLink } from '../../security/public';
9+
import { CloudConfigType } from '.';
10+
11+
export const createUserMenuLinks = (config: CloudConfigType): UserMenuLink[] => {
12+
const { resetPasswordUrl, accountUrl, securityUrl } = config;
13+
const userMenuLinks = [] as UserMenuLink[];
14+
15+
if (resetPasswordUrl) {
16+
userMenuLinks.push({
17+
label: i18n.translate('xpack.cloud.userMenuLinks.profileLinkText', {
18+
defaultMessage: 'Cloud profile',
19+
}),
20+
iconType: 'logoCloud',
21+
href: resetPasswordUrl,
22+
order: 100,
23+
});
24+
}
25+
26+
if (accountUrl) {
27+
userMenuLinks.push({
28+
label: i18n.translate('xpack.cloud.userMenuLinks.accountLinkText', {
29+
defaultMessage: 'Account',
30+
}),
31+
iconType: 'gear',
32+
href: accountUrl,
33+
order: 200,
34+
});
35+
}
36+
37+
if (securityUrl) {
38+
userMenuLinks.push({
39+
label: i18n.translate('xpack.cloud.userMenuLinks.securityLinkText', {
40+
defaultMessage: 'Security',
41+
}),
42+
iconType: 'lock',
43+
href: securityUrl,
44+
order: 300,
45+
});
46+
}
47+
48+
return userMenuLinks;
49+
};

x-pack/plugins/security/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"kibanaVersion": "kibana",
55
"configPath": ["xpack", "security"],
66
"requiredPlugins": ["data", "features", "licensing", "taskManager", "securityOss"],
7-
"optionalPlugins": ["home", "management", "usageCollection", "cloud"],
7+
"optionalPlugins": ["home", "management", "usageCollection"],
88
"server": true,
99
"ui": true,
1010
"requiredBundles": [

x-pack/plugins/security/public/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
export { SecurityPluginSetup, SecurityPluginStart };
1717
export { AuthenticatedUser } from '../common/model';
1818
export { SecurityLicense, SecurityLicenseFeatures } from '../common/licensing';
19+
export { UserMenuLink } from '../public/nav_control';
1920

2021
export const plugin: PluginInitializer<
2122
SecurityPluginSetup,

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { authenticationMock } from './authentication/index.mock';
88
import { createSessionTimeoutMock } from './session/session_timeout.mock';
99
import { licenseMock } from '../common/licensing/index.mock';
10+
import { navControlServiceMock } from './nav_control/index.mock';
1011

1112
function createSetupMock() {
1213
return {
@@ -15,7 +16,13 @@ function createSetupMock() {
1516
license: licenseMock.create(),
1617
};
1718
}
19+
function createStartMock() {
20+
return {
21+
navControlService: navControlServiceMock.createStart(),
22+
};
23+
}
1824

1925
export const securityMock = {
2026
createSetup: createSetupMock,
27+
createStart: createStartMock,
2128
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { SecurityNavControlServiceStart } from '.';
8+
9+
export const navControlServiceMock = {
10+
createStart: (): jest.Mocked<SecurityNavControlServiceStart> => ({
11+
getUserMenuLinks$: jest.fn(),
12+
setUserMenuLinks: jest.fn(),
13+
}),
14+
};

x-pack/plugins/security/public/nav_control/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export { SecurityNavControlService } from './nav_control_service';
7+
export { SecurityNavControlService, SecurityNavControlServiceStart } from './nav_control_service';
8+
export { UserMenuLink } from './nav_control_component';

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
.euiPopoverTitle {
33
text-transform: none;
44
}
5-
6-
.securityNavControlComponent__logoutLink {
7-
border-top: $euiBorderThin;
8-
}
95
}

0 commit comments

Comments
 (0)