Skip to content

Commit

Permalink
fix: print only Dex credentials if DevWorkspace enabled (#1983)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Jan 26, 2022
1 parent 19d1728 commit 71ce103
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
return ideURL.replace(/\/[^/|.]*\/[^/|.]*$/g, '\/dashboard\/#\/ide$&')
buildDashboardURL(cheUrl: string): string {
return cheUrl.endsWith('/') ? `${cheUrl}dashboard/` : `${cheUrl}/dashboard/`
}

/**
Expand Down
29 changes: 10 additions & 19 deletions src/api/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -156,26 +155,18 @@ export namespace VersionHelper {
*/
export async function getCheVersion(flags: any): Promise<string> {
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 ''
}

/**
Expand Down
14 changes: 2 additions & 12 deletions src/commands/server/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = {
Expand All @@ -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))}`)
}
}
6 changes: 3 additions & 3 deletions src/tasks/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/api/che.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand Down

0 comments on commit 71ce103

Please sign in to comment.