Skip to content

Commit b71624d

Browse files
authored
feat: add --force-prepare option get context command (#907)
## What ## Why ## Notes
1 parent 7a5a487 commit b71624d

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,25 @@ const command = new Command({
2424
.option('type', {
2525
describe: 'Context type',
2626
choices: [
27-
'config', 'git.bitbucket-server', 'git.bitbucket', 'git.github', 'git.gitlab',
28-
'git.stash', 'helm-repository', 'secret-yaml', 'secret', 'storage.gc', 'storage.s3', 'yaml',
29-
'secret-store.kubernetes', 'secret-store.kubernetes-runtime',
27+
'config', 'git.bitbucket-server', 'git.bitbucket', 'git.github', 'git.github-app',
28+
'git.codefresh-github-app', 'git.gitlab', 'git.stash', 'helm-repository', 'secret-yaml', 'secret',
29+
'storage.gc', 'storage.s3', 'yaml', 'secret-store.kubernetes', 'secret-store.kubernetes-runtime',
3030
],
3131
})
3232
.option('decrypt', {
3333
describe: 'Either to show decoded credentials or not',
3434
})
3535
.option('prepare', {
36-
describe: 'Activate tokens in case its invalid',
36+
describe: 'Activate tokens in case its invalid. It\'s supported only for types: '
37+
+ '`git.codefresh-github-app`, `git.github-app` and `git.bitbucket` (OAuth2)',
38+
})
39+
.option('force-prepare', {
40+
describe: 'Refresh the token even if the current token is still valid. Unlike `--prepare`, '
41+
+ 'which only refreshes expired tokens, this flag forces a token refresh unconditionally. '
42+
+ 'It\'s supported only for `git.bitbucket` (OAuth2)',
3743
})
3844
.example('codefresh get context NAME', 'Get context NAME')
45+
.example('codefresh get context NAME --prepare', 'Get context by NAME and active token if it\'s expired')
3946
.example('codefresh get contexts', 'Get all contexts')
4047
.example('codefresh get context --decrypt', 'Get all contexts with credentials decrypted')
4148
.example('codefresh get context --type secret', 'Get all secret contexts')
@@ -50,10 +57,13 @@ const command = new Command({
5057
}
5158
data.decrypt = argv.decrypt || undefined;
5259
data.prepare = argv.prepare || undefined;
60+
data.forcePrepare = argv['force-prepare'] || undefined;
5361

5462
let contexts = [];
5563
if (!_.isEmpty(names)) {
56-
if (data.prepare) {
64+
if (data.forcePrepare) {
65+
contexts = await Promise.map(names, name => sdk.contexts.prepare({ name, forceRefresh: true }));
66+
} else if (data.prepare) {
5767
contexts = await Promise.map(names, name => sdk.contexts.prepare({ name }));
5868
} else {
5969
contexts = await Promise.map(names, name => sdk.contexts.get({ name, decrypt: data.decrypt }));

openapi.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,16 @@
31283128
},
31293129
"required": true,
31303130
"description": "Name"
3131-
}],
3131+
},
3132+
{
3133+
"in": "query",
3134+
"name": "forceRefresh",
3135+
"schema": {
3136+
"type": "boolean"
3137+
},
3138+
"description": "Refresh the token even if the current token is still valid"
3139+
}
3140+
],
31323141
"summary": "Get",
31333142
"x-sdk-interface": "contexts.prepare"
31343143
}

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": "1.0.6",
3+
"version": "1.1.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)