-
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
Merged
pgayvallet
merged 18 commits into
elastic:main
from
pgayvallet:kbn-138813-decode-cloud-id
Jun 13, 2023
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dc08921
add urls to cloud browser contracts
pgayvallet 607fb45
adapt fleet usages
pgayvallet 80934be
adapt other usages
pgayvallet d08de8c
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 6e23426
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 65057b9
adapt unit tests
pgayvallet f2b91d5
add deploymentId to public contract
pgayvallet e0dc1cc
update the mocks
pgayvallet 296beda
add unit tests for plugin
pgayvallet 2485859
remove from start contract given unused for now
pgayvallet 093ea96
Merge remote-tracking branch 'upstream/main' into kbn-138813-decode-c…
pgayvallet fdc5d6c
fix snapshot
pgayvallet b38b74f
Merge remote-tracking branch 'upstream/main' into kbn-138813-decode-c…
pgayvallet cdb183f
Merge remote-tracking branch 'upstream/main' into kbn-138813-decode-c…
pgayvallet e8e2e1b
use real logger
pgayvallet 772b6b8
Merge remote-tracking branch 'upstream/main' into kbn-138813-decode-c…
pgayvallet df14feb
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine a5c8579
also adapt server-side call
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -161,13 +98,20 @@ export class CloudPlugin implements Plugin<CloudSetup> { | |
|
||
const { deploymentUrl, profileUrl, organizationUrl } = this.getCloudUrls(); | ||
|
||
let decodedId: DecodedCloudId | undefined; | ||
if (this.config.id) { | ||
decodedId = decodeCloudId(this.config.id); | ||
} | ||
|
||
return { | ||
CloudContextProvider, | ||
isCloudEnabled: this.isCloudEnabled, | ||
cloudId: this.config.id, | ||
deploymentUrl, | ||
profileUrl, | ||
organizationUrl, | ||
elasticsearchUrl: decodedId?.elasticsearchUrl, | ||
kibanaUrl: decodedId?.kibanaUrl, | ||
}; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.