Skip to content

Commit 7c4a77e

Browse files
context credentials decryption flag redone (#233)
1 parent c55e043 commit 7c4a77e

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

lib/interface/cli/commands/context/get.cmd.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ const command = new Command({
2727
describe: 'Context type',
2828
choices: ['config', 'secret', 'helm-repository', 'yaml', 'secret-yaml', 'git'],
2929
})
30+
.option('decrypt', {
31+
describe: 'Either to show decoded credentials or not',
32+
})
3033
.example('codefresh get context NAME', 'Get context NAME')
3134
.example('codefresh get contexts', 'Get all contexts')
35+
.example('codefresh get context --decrypt', 'Get all contexts with credentials decrypted')
3236
.example('codefresh get context --type secret', 'Get all secret contexts')
3337
.example('codefresh get context --type git.github', 'Get all git based contexts for github kind')
3438
.example('codefresh get context --type helm-repository', 'Get all helm-repository contexts');
@@ -39,11 +43,12 @@ const command = new Command({
3943
if (argv.type) {
4044
data.type = argv.type;
4145
}
46+
data.decrypt = argv.decrypt;
4247

4348
let contexts = [];
4449
if (!_.isEmpty(names)) {
4550
for (const name of names) {
46-
const currContext = await context.getContextByName(name);
51+
const currContext = await context.getContextByName(name, data.decrypt);
4752
contexts.push(currContext);
4853
}
4954
} else {

lib/interface/functional/context/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ const TYPE_CHOICES = [
1919
'secret-yaml',
2020
];
2121

22-
const getContext = async (name) => {
22+
const getContext = async (name, decrypt = false) => {
2323
if (!name) {
2424
throw new CFError('Name must be provided');
2525
}
2626

2727
try {
28-
return context.getContextByName(name);
28+
return context.getContextByName(name, decrypt);
2929
} catch (err) {
3030
throw new CFError({
3131
cause: err,
@@ -34,8 +34,8 @@ const getContext = async (name) => {
3434
}
3535
};
3636

37-
const getAllContexts = async (type = null) => {
38-
const data = {};
37+
const getAllContexts = async (type = null, decrypt = false) => {
38+
const data = { decrypt };
3939
if (type) {
4040
data.type = type;
4141
}

lib/logic/api/context.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ const applyByName = async (name, data) => {
4646
return sendHttpRequest(options);
4747
};
4848

49-
const getContextByName = async (name) => {
49+
const getContextByName = async (name, decrypt) => {
5050
const options = {
5151
url: `/api/contexts/${name}`,
5252
method: 'GET',
53+
qs: { decrypt: decrypt || undefined }, // falsy resolves to decryption, undefined not
5354
};
5455

5556
const context = await sendHttpRequest(options);
@@ -61,7 +62,10 @@ const getContexts = async (info) => {
6162
const userOptions = {
6263
url: '/api/contexts',
6364
method: 'GET',
64-
qs: _.pick(info, 'type'),
65+
qs: {
66+
type: info.type,
67+
decrypt: info.decrypt || undefined, // falsy resolves to decryption, undefined not
68+
},
6569
};
6670

6771
const result = await sendHttpRequest(userOptions);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.8.87",
3+
"version": "0.8.88",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)