From 057530c47744cff650714e50756b6406d7ad1518 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 26 Jan 2022 10:17:54 +0200 Subject: [PATCH] fix: print only Dex credentials if DevWorkspace enabled Signed-off-by: Anatolii Bazko --- src/api/che.ts | 4 ++-- src/api/version.ts | 29 ++++++++++------------------- src/commands/server/status.ts | 14 ++------------ src/tasks/che.ts | 6 +++--- test/api/che.test.ts | 6 +++--- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/src/api/che.ts b/src/api/che.ts index 4a8346112..3ba3f7bc9 100644 --- a/src/api/che.ts +++ b/src/api/che.ts @@ -140,8 +140,8 @@ export class CheHelper { throw new Error(`ERR_ROUTE_NO_EXIST - No route ${route_names} in namespace ${namespace}`) } - async buildDashboardURL(ideURL: string): Promise { - return ideURL.replace(/\/[^/|.]*\/[^/|.]*$/g, '\/dashboard\/#\/ide$&') + buildDashboardURL(cheUrl: string): string { + return cheUrl.endsWith('/') ? `${cheUrl}dashboard/` : `${cheUrl}/dashboard/` } /** diff --git a/src/api/version.ts b/src/api/version.ts index 1ca6141ef..d5212e8c3 100644 --- a/src/api/version.ts +++ b/src/api/version.ts @@ -18,8 +18,7 @@ import * as path from 'path' import * as semver from 'semver' import { CHECTL_REPO, CheGithubClient, ECLIPSE_CHE_INCUBATOR_ORG } from '../api/github-client' import { CHECTL_PROJECT_NAME } from '../constants' -import { CheTasks } from '../tasks/che' -import { getClusterClientCommand, getProjectName, getProjectVersion, isKubernetesPlatformFamily } from '../util' +import { getProjectName, getProjectVersion, isKubernetesPlatformFamily, sleep } from '../util' import { ChectlContext } from './context' import { KubeHelper } from './kube' import execa = require('execa') @@ -156,26 +155,18 @@ export namespace VersionHelper { */ export async function getCheVersion(flags: any): Promise { const kube = new KubeHelper(flags) - const cheTasks = new CheTasks(flags) - const cheCluster = await kube.getCheCluster(flags.chenamespace) - if (cheCluster && cheCluster.spec.server.cheFlavor !== 'che') { - return cheCluster.status.cheVersion - } + for (let i = 0; i < 10; i++) { + const cheCluster = await kube.getCheCluster(flags.chenamespace) + if (cheCluster) { + if (cheCluster.status.cheVersion) { + return cheCluster.status.cheVersion + } + } - const chePodList = await kube.getPodListByLabel(flags.chenamespace, cheTasks.cheSelector) - const [chePodName] = chePodList.map(pod => pod.metadata && pod.metadata.name) - if (!chePodName) { - return 'UNKNOWN' + await sleep(1000) // wait a bit, operator has not updated version yet } - const command = getClusterClientCommand() - const args = ['exec', chePodName, '--namespace', flags.chenamespace, 'cat', CHE_POD_MANIFEST_FILE] - try { - const { stdout } = await execa(command, args, { timeout: 60000 }) - return stdout.split('\n').filter(value => value.startsWith(CHE_PREFFIX_VERSION)).map(value => value.substring(CHE_PREFFIX_VERSION.length))[0] - } catch { - return 'UNKNOWN' - } + return '' } /** diff --git a/src/commands/server/status.ts b/src/commands/server/status.ts index 152d7c234..da7636451 100644 --- a/src/commands/server/status.ts +++ b/src/commands/server/status.ts @@ -15,14 +15,12 @@ import { cli } from 'cli-ux' import { CheHelper } from '../../api/che' import { ChectlContext } from '../../api/context' -import { KubeHelper } from '../../api/kube' import { VersionHelper } from '../../api/version' import { cheNamespace, CHE_TELEMETRY } from '../../common-flags' import { DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants' import { findWorkingNamespace } from '../../util' export default class Status extends Command { - // Implementation-Version it is a property from Manifest.ml inside of che server pod which indicate Eclipse Che build version. static description = 'Status Eclipse Che server' static flags: flags.Input = { @@ -36,20 +34,12 @@ export default class Status extends Command { flags.chenamespace = await findWorkingNamespace(flags) await ChectlContext.init(flags, this) - const kube = new KubeHelper(flags) - const che = new CheHelper(flags) - let openshiftOauth = 'No' - await this.config.runHook(DEFAULT_ANALYTIC_HOOK_NAME, { command: Status.id, flags }) - const cr = await kube.getCheCluster(flags.chenamespace) - if (cr && cr.spec && cr.spec.auth && cr.spec.auth.openShiftoAuth && await kube.isOpenShift()) { - openshiftOauth = 'Yes' - } + const che = new CheHelper(flags) const cheVersion = await VersionHelper.getCheVersion(flags) cli.log(`Eclipse Che Version : ${cheVersion}`) - cli.log(`Eclipse Che Url : ${await che.cheURL(flags.chenamespace)}`) - cli.log(`OpenShift OAuth enabled: ${openshiftOauth}\n`) + cli.log(`Eclipse Che Url : ${che.buildDashboardURL(await che.cheURL(flags.chenamespace))}`) } } diff --git a/src/tasks/che.ts b/src/tasks/che.ts index f1842282f..51fd6c164 100644 --- a/src/tasks/che.ts +++ b/src/tasks/che.ts @@ -635,14 +635,14 @@ export class CheTasks { const messages: string[] = [] const version = await VersionHelper.getCheVersion(flags) - messages.push(`Eclipse Che ${version.trim()} has been successfully deployed.`) + messages.push(`Eclipse Che '${version.trim()}' has been successfully deployed.`) messages.push(`Documentation : ${DOC_LINK}`) if (DOC_LINK_RELEASE_NOTES) { messages.push(`Release Notes : ${DOC_LINK_RELEASE_NOTES}`) } messages.push(OUTPUT_SEPARATOR) - const cheUrl = await this.che.cheURL(flags.chenamespace) + const cheUrl = this.che.buildDashboardURL(await this.che.cheURL(flags.chenamespace)) messages.push(`Users Dashboard : ${cheUrl}`) const cr = await this.kube.getCheCluster(flags.chenamespace) @@ -669,7 +669,7 @@ export class CheTasks { messages.push(`HTPasswd user credentials : "${user}:${password}".`) } } - } else { + } else if (!isDevWorkspaceEnabled(ctx)) { messages.push('Admin user login : "admin:admin". NOTE: must change after first login.') } messages.push(OUTPUT_SEPARATOR) diff --git a/test/api/che.test.ts b/test/api/che.test.ts index 31261ad2e..575168cd8 100644 --- a/test/api/che.test.ts +++ b/test/api/che.test.ts @@ -114,9 +114,9 @@ describe('Eclipse Che helper', () => { describe('buildDashboardURL', () => { fancy .it('builds the Dashboard URL of a workspace given the IDE link', async () => { - let ideURL = 'https://che-che.192.168.64.40.nip.io/che/name-with-dashes' - let dashboardURL = 'https://che-che.192.168.64.40.nip.io/dashboard/#/ide/che/name-with-dashes' - let res = await ch.buildDashboardURL(ideURL) + let cheURL = 'https://che-che.192.168.64.40.nip.io' + let dashboardURL = 'https://che-che.192.168.64.40.nip.io/dashboard/' + let res = await ch.buildDashboardURL(cheURL) expect(res).to.equal(dashboardURL) }) })