-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose decoded cloudId components from the cloud plugin's contract #159442
Changes from 11 commits
dc08921
607fb45
80934be
d08de8c
6e23426
65057b9
f2b91d5
e0dc1cc
296beda
2485859
093ea96
fdc5d6c
b38b74f
cdb183f
e8e2e1b
772b6b8
df14feb
a5c8579
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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 const parseDeploymentIdFromDeploymentUrlMock = jest.fn(); | ||
|
||
jest.doMock('../common/parse_deployment_id_from_deployment_url', () => { | ||
return { | ||
parseDeploymentIdFromDeploymentUrl: parseDeploymentIdFromDeploymentUrlMock, | ||
}; | ||
}); | ||
|
||
export const decodeCloudIdMock = jest.fn(); | ||
|
||
jest.doMock('../common/decode_cloud_id', () => { | ||
return { | ||
decodeCloudId: decodeCloudIdMock, | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,12 @@ | |
|
||
import React, { FC } from 'react'; | ||
import type { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public'; | ||
|
||
import { registerCloudDeploymentMetadataAnalyticsContext } from '../common/register_cloud_deployment_id_analytics_context'; | ||
import { getIsCloudEnabled } from '../common/is_cloud_enabled'; | ||
import { parseDeploymentIdFromDeploymentUrl } from '../common/parse_deployment_id_from_deployment_url'; | ||
import { ELASTIC_SUPPORT_LINK, CLOUD_SNAPSHOTS_PATH } from '../common/constants'; | ||
import { decodeCloudId, type DecodedCloudId } from '../common/decode_cloud_id'; | ||
import type { CloudSetup, CloudStart } from './types'; | ||
import { getFullCloudUrl } from './utils'; | ||
|
||
export interface CloudConfigType { | ||
|
@@ -24,81 +26,6 @@ export interface CloudConfigType { | |
is_elastic_staff_owned?: boolean; | ||
} | ||
|
||
export interface CloudStart { | ||
/** | ||
* A React component that provides a pre-wired `React.Context` which connects components to Cloud services. | ||
*/ | ||
CloudContextProvider: FC<{}>; | ||
/** | ||
* `true` when Kibana is running on Elastic Cloud. | ||
*/ | ||
isCloudEnabled: boolean; | ||
/** | ||
* Cloud ID. Undefined if not running on Cloud. | ||
*/ | ||
cloudId?: string; | ||
/** | ||
* The full URL to the deployment management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
deploymentUrl?: string; | ||
/** | ||
* The full URL to the user profile page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
profileUrl?: string; | ||
/** | ||
* The full URL to the organization management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
organizationUrl?: string; | ||
} | ||
|
||
export interface CloudSetup { | ||
/** | ||
* Cloud ID. Undefined if not running on Cloud. | ||
*/ | ||
cloudId?: string; | ||
/** | ||
* This value is the same as `baseUrl` on ESS but can be customized on ECE. | ||
*/ | ||
cname?: string; | ||
/** | ||
* This is the URL of the Cloud interface. | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* The full URL to the deployment management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
deploymentUrl?: string; | ||
/** | ||
* The full URL to the user profile page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
profileUrl?: string; | ||
/** | ||
* The full URL to the organization management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
organizationUrl?: string; | ||
/** | ||
* This is the path to the Snapshots page for the deployment to which the Kibana instance belongs. The value is already prepended with `deploymentUrl`. | ||
*/ | ||
snapshotsUrl?: string; | ||
/** | ||
* `true` when Kibana is running on Elastic Cloud. | ||
*/ | ||
isCloudEnabled: boolean; | ||
/** | ||
* When the Cloud Trial ends/ended for the organization that owns this deployment. Only available when running on Elastic Cloud. | ||
*/ | ||
trialEndDate?: Date; | ||
/** | ||
* `true` if the Elastic Cloud organization that owns this deployment is owned by an Elastician. Only available when running on Elastic Cloud. | ||
*/ | ||
isElasticStaffOwned?: boolean; | ||
/** | ||
* Registers CloudServiceProviders so start's `CloudContextProvider` hooks them. | ||
* @param contextProvider The React component from the Service Provider. | ||
*/ | ||
registerCloudService: (contextProvider: FC) => void; | ||
} | ||
|
||
interface CloudUrls { | ||
deploymentUrl?: string; | ||
profileUrl?: string; | ||
|
@@ -127,11 +54,21 @@ export class CloudPlugin implements Plugin<CloudSetup> { | |
is_elastic_staff_owned: isElasticStaffOwned, | ||
} = this.config; | ||
|
||
let decodedId: DecodedCloudId | undefined; | ||
if (id) { | ||
decodedId = decodeCloudId(id); | ||
} | ||
|
||
return { | ||
cloudId: id, | ||
deploymentId: parseDeploymentIdFromDeploymentUrl(this.config.deployment_url), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the |
||
cname, | ||
baseUrl, | ||
...this.getCloudUrls(), | ||
elasticsearchUrl: decodedId?.elasticsearchUrl, | ||
kibanaUrl: decodedId?.kibanaUrl, | ||
cloudHost: decodedId?.host, | ||
cloudDefaultPort: decodedId?.defaultPort, | ||
trialEndDate: trialEndDate ? new Date(trialEndDate) : undefined, | ||
isElasticStaffOwned, | ||
isCloudEnabled: this.isCloudEnabled, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import type { FC } from 'react'; | ||
|
||
export interface CloudStart { | ||
/** | ||
* A React component that provides a pre-wired `React.Context` which connects components to Cloud services. | ||
*/ | ||
CloudContextProvider: FC<{}>; | ||
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took this opportunity to move the browser-side contracts to a dedicated file, given they started to become quite big. |
||
/** | ||
* `true` when Kibana is running on Elastic Cloud. | ||
*/ | ||
isCloudEnabled: boolean; | ||
/** | ||
* Cloud ID. Undefined if not running on Cloud. | ||
*/ | ||
cloudId?: string; | ||
/** | ||
* The full URL to the deployment management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
deploymentUrl?: string; | ||
/** | ||
* The full URL to the user profile page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
profileUrl?: string; | ||
/** | ||
* The full URL to the organization management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
organizationUrl?: string; | ||
/** | ||
* The full URL to the elasticsearch cluster. | ||
*/ | ||
elasticsearchUrl?: string; | ||
/** | ||
* The full URL to the Kibana deployment. | ||
*/ | ||
kibanaUrl?: string; | ||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, is there a difference between this and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is. The url decrypted from the cloudId is
|
||
} | ||
|
||
export interface CloudSetup { | ||
/** | ||
* Cloud ID. Undefined if not running on Cloud. | ||
*/ | ||
cloudId?: string; | ||
/** | ||
* The deployment's ID. Only available when running on Elastic Cloud. | ||
*/ | ||
deploymentId?: string; | ||
/** | ||
* This value is the same as `baseUrl` on ESS but can be customized on ECE. | ||
*/ | ||
cname?: string; | ||
/** | ||
* This is the URL of the Cloud interface. | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* The full URL to the deployment management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
deploymentUrl?: string; | ||
/** | ||
* The full URL to the user profile page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
profileUrl?: string; | ||
/** | ||
* The full URL to the organization management page on Elastic Cloud. Undefined if not running on Cloud. | ||
*/ | ||
organizationUrl?: string; | ||
/** | ||
* This is the path to the Snapshots page for the deployment to which the Kibana instance belongs. The value is already prepended with `deploymentUrl`. | ||
*/ | ||
snapshotsUrl?: string; | ||
/** | ||
* The full URL to the elasticsearch cluster. | ||
*/ | ||
elasticsearchUrl?: string; | ||
/** | ||
* The full URL to the Kibana deployment. | ||
*/ | ||
kibanaUrl?: string; | ||
/** | ||
* {host} from the deployment url https://<deploymentId>.<application>.<host><?:port> | ||
*/ | ||
cloudHost?: string; | ||
/** | ||
* {port} from the deployment url https://<deploymentId>.<application>.<host><?:port> | ||
*/ | ||
cloudDefaultPort?: string; | ||
Comment on lines
+78
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming is hard. I went with those, but I'm open to better suggestions (or better TSDoc) |
||
/** | ||
* `true` when Kibana is running on Elastic Cloud. | ||
*/ | ||
isCloudEnabled: boolean; | ||
/** | ||
* When the Cloud Trial ends/ended for the organization that owns this deployment. Only available when running on Elastic Cloud. | ||
*/ | ||
trialEndDate?: Date; | ||
/** | ||
* `true` if the Elastic Cloud organization that owns this deployment is owned by an Elastician. Only available when running on Elastic Cloud. | ||
*/ | ||
isElasticStaffOwned?: boolean; | ||
/** | ||
* Registers CloudServiceProviders so start's `CloudContextProvider` hooks them. | ||
* @param contextProvider The React component from the Service Provider. | ||
*/ | ||
registerCloudService: (contextProvider: FC) => void; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved, pretty much without any modifications, to the
cloud
plugin. Tell me if you think anything within the method should be changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't add a comment in that line. Should we use a different logger to replace all
console.debug
entries?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, we have the client-side loggers now! will do.