Skip to content

Commit

Permalink
Fixes according review
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Apr 27, 2020
1 parent c1083d2 commit e7d9332
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ USAGE
OPTIONS
-d, --destination=destination
[default: ~] Destination where to store Che certificate.
Destination where to store Che CA certificate.
If the destination is a file (might not exist), then the certificate will be saved there in PEM
format.
If the destination is a directory, then cheCA.crt file will be created there with Che
Expand Down
4 changes: 2 additions & 2 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ export class CheHelper {
async retrieveEclipseCheCaCert(cheNamespace: string): Promise<string> {
const cheCaSecret = await this.kube.getSecret(CHE_ROOT_CA_SECRET_NAME, cheNamespace)
if (!cheCaSecret) {
throw new Error('Local Che CA self-signed certificate not found. Are you using self-signed certificate?')
throw new Error('Che CA self-signed certificate not found. Are you using self-signed certificate?')
}

if (cheCaSecret.data && cheCaSecret.data['ca.crt']) {
return Buffer.from(cheCaSecret.data['ca.crt'], 'base64').toString('ascii')
}

throw new Error(`Secret "${CHE_ROOT_CA_SECRET_NAME}" has invalid format.`)
throw new Error(`Secret "${CHE_ROOT_CA_SECRET_NAME}" has invalid format: "ca.crt" key not found in data.`)
}

async cheK8sURL(namespace = ''): Promise<string> {
Expand Down
12 changes: 6 additions & 6 deletions src/commands/cacert/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export default class Export extends Command {
}),
destination: string({
char: 'd',
description: `Destination where to store Che certificate.
description: `Destination where to store Che CA certificate.
If the destination is a file (might not exist), then the certificate will be saved there in PEM format.
If the destination is a directory, then ${DEFAULT_CA_CERT_FILE_NAME} file will be created there with Che certificate in PEM format.
If this option is ommited, then Che certificate will be stored in user's home directory as ${DEFAULT_CA_CERT_FILE_NAME}`,
env: 'CHE_CA_CERT_LOCATION',
default: '~'
default: ''
}),
}

Expand All @@ -54,7 +54,7 @@ export default class Export extends Command {
const apiTasks = new ApiTasks()
const tasks = new Listr([], { renderer: 'silent' })

const targetFile = this.prepareTarget(flags.destination)
const targetFile = this.getTargetFile(flags.destination)

tasks.add(platformTasks.preflightCheckTasks(flags, this))
tasks.add(apiTasks.testApiTasks(flags, this))
Expand All @@ -73,16 +73,16 @@ export default class Export extends Command {
/**
* Handles certificate target location and returns string which points to the target file.
*/
private prepareTarget(destinaton: string): string {
if (destinaton === '~') {
private getTargetFile(destinaton: string): string {
if (!destinaton) {
return path.join(os.homedir(), DEFAULT_CA_CERT_FILE_NAME)
}

if (fs.existsSync(destinaton)) {
return fs.lstatSync(destinaton).isDirectory() ? path.join(destinaton, DEFAULT_CA_CERT_FILE_NAME) : destinaton
}

throw new Error('Given certificate path doesn\'t exist.')
this.error(`Given path "${destinaton}" doesn\'t exist.`)
}

}

0 comments on commit e7d9332

Please sign in to comment.