Skip to content

Commit

Permalink
CR-20133 -- fix docs (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslav-codefresh authored Aug 24, 2023
1 parent 1ec341d commit 2c58bd8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
9 changes: 7 additions & 2 deletions lib/interface/cli/commands/context/context.sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const request = require('requestretry');

jest.mock('../../../../logic/entities/Context');


const DEFAULT_RESPONSE = request.__defaultResponse();

describe('context commands', () => {
Expand Down Expand Up @@ -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
});
Expand Down
38 changes: 26 additions & 12 deletions lib/interface/cli/commands/context/create/helm-repo/types/s3.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand All @@ -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,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.84.9",
"version": "0.84.10",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 2c58bd8

Please sign in to comment.