From 2c58bd82e31a0b4851be3c239421c92244a946ba Mon Sep 17 00:00:00 2001 From: Yaroslav Drachenko Date: Thu, 24 Aug 2023 19:02:02 +0300 Subject: [PATCH] CR-20133 -- fix docs (#837) --- .../cli/commands/context/context.sdk.spec.js | 9 ++++- .../context/create/helm-repo/types/s3.cmd.js | 38 +++++++++++++------ package.json | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/interface/cli/commands/context/context.sdk.spec.js b/lib/interface/cli/commands/context/context.sdk.spec.js index 27fbd0bde..854a260d4 100644 --- a/lib/interface/cli/commands/context/context.sdk.spec.js +++ b/lib/interface/cli/commands/context/context.sdk.spec.js @@ -6,7 +6,6 @@ const request = require('requestretry'); jest.mock('../../../../logic/entities/Context'); - const DEFAULT_RESPONSE = request.__defaultResponse(); describe('context commands', () => { @@ -80,7 +79,13 @@ describe('context commands', () => { describe('s3', () => { it('should handle creation', async () => { const cmd = require('./create/helm-repo/types/s3.cmd'); - const argv = { name: 'some name', bucket: 'some bucket' }; + const argv = { + name: 'some name', + bucket: 'some bucket', + 'aws-access-key-id': 'test-id', + 'aws-secret-access-key': 'test-secret', + 'aws-default-region': 'test-region', + }; await cmd.handler(argv); await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line }); diff --git a/lib/interface/cli/commands/context/create/helm-repo/types/s3.cmd.js b/lib/interface/cli/commands/context/create/helm-repo/types/s3.cmd.js index 3c0d511b4..93d09ad1b 100644 --- a/lib/interface/cli/commands/context/create/helm-repo/types/s3.cmd.js +++ b/lib/interface/cli/commands/context/create/helm-repo/types/s3.cmd.js @@ -37,19 +37,14 @@ const command = new Command({ builder: (yargs) => { yargs .option(AWS.keyId.cliFlag, { - describe: 'Amazon access key id', - default: process.env[AWS.keyId.awsEnvVar], - required: true, + describe: `Amazon access key id [default: ${AWS.keyId.awsEnvVar} env]`, + }) .option(AWS.secretKey.cliFlag, { - describe: 'Amazon access secret key with permissions to the bucket', - default: process.env[AWS.secretKey.awsEnvVar], - required: true, + describe: `Amazon access secret key with permissions to the bucket [default: ${AWS.secretKey.awsEnvVar} env]`, }) .option(AWS.region.cliFlag, { - describe: 'Amazon default region', - default: process.env[AWS.region.awsEnvVar], - required: true, + describe: `Amazon default region [default: ${AWS.region.awsEnvVar} env]`, }) .option('bucket', { describe: 'Name of the bucket', @@ -58,6 +53,25 @@ const command = new Command({ return yargs; }, handler: async (argv) => { + const awsKeyId = argv[AWS.keyId.cliFlag] || process.env[AWS.keyId.awsEnvVar]; + const awsSecretKey = argv[AWS.secretKey.cliFlag] || process.env[AWS.secretKey.awsEnvVar]; + const awsRegion = argv[AWS.region.cliFlag] || process.env[AWS.region.awsEnvVar]; + if (!awsKeyId) { + throw new CFError({ + message: `Either ${AWS.keyId.awsEnvVar} env, or --${AWS.keyId.cliFlag} option is required`, + }); + } + if (!awsSecretKey) { + throw new CFError({ + message: `Either ${AWS.secretKey.awsEnvVar} env, or --${AWS.secretKey.cliFlag} option is required`, + }); + } + if (!awsRegion) { + throw new CFError({ + message: `Either ${AWS.region.awsEnvVar} env, or --${AWS.region.cliFlag} option is required`, + }); + } + let bucket = ''; if (argv.bucket.startsWith('s3://')) { ({ bucket } = argv); @@ -76,9 +90,9 @@ const command = new Command({ data: { repositoryUrl: bucket, variables: { - [AWS.keyId.awsEnvVar]: argv[AWS.keyId.cliFlag], - [AWS.secretKey.awsEnvVar]: argv[AWS.secretKey.cliFlag], - [AWS.region.awsEnvVar]: argv[AWS.region.cliFlag], + [AWS.keyId.awsEnvVar]: awsKeyId, + [AWS.secretKey.awsEnvVar]: awsSecretKey, + [AWS.region.awsEnvVar]: awsRegion, }, }, }, diff --git a/package.json b/package.json index dca918731..d7f7a20f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.84.9", + "version": "0.84.10", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,