diff --git a/lib/interface/cli/commands/context/get.cmd.js b/lib/interface/cli/commands/context/get.cmd.js index 2b2b947ae..4c9cc6da7 100644 --- a/lib/interface/cli/commands/context/get.cmd.js +++ b/lib/interface/cli/commands/context/get.cmd.js @@ -24,18 +24,25 @@ const command = new Command({ .option('type', { describe: 'Context type', choices: [ - 'config', 'git.bitbucket-server', 'git.bitbucket', 'git.github', 'git.gitlab', - 'git.stash', 'helm-repository', 'secret-yaml', 'secret', 'storage.gc', 'storage.s3', 'yaml', - 'secret-store.kubernetes', 'secret-store.kubernetes-runtime', + 'config', 'git.bitbucket-server', 'git.bitbucket', 'git.github', 'git.github-app', + 'git.codefresh-github-app', 'git.gitlab', 'git.stash', 'helm-repository', 'secret-yaml', 'secret', + 'storage.gc', 'storage.s3', 'yaml', 'secret-store.kubernetes', 'secret-store.kubernetes-runtime', ], }) .option('decrypt', { describe: 'Either to show decoded credentials or not', }) .option('prepare', { - describe: 'Activate tokens in case its invalid', + describe: 'Activate tokens in case its invalid. It\'s supported only for types: ' + + '`git.codefresh-github-app`, `git.github-app` and `git.bitbucket` (OAuth2)', + }) + .option('force-prepare', { + describe: 'Refresh the token even if the current token is still valid. Unlike `--prepare`, ' + + 'which only refreshes expired tokens, this flag forces a token refresh unconditionally. ' + + 'It\'s supported only for `git.bitbucket` (OAuth2)', }) .example('codefresh get context NAME', 'Get context NAME') + .example('codefresh get context NAME --prepare', 'Get context by NAME and active token if it\'s expired') .example('codefresh get contexts', 'Get all contexts') .example('codefresh get context --decrypt', 'Get all contexts with credentials decrypted') .example('codefresh get context --type secret', 'Get all secret contexts') @@ -50,10 +57,13 @@ const command = new Command({ } data.decrypt = argv.decrypt || undefined; data.prepare = argv.prepare || undefined; + data.forcePrepare = argv['force-prepare'] || undefined; let contexts = []; if (!_.isEmpty(names)) { - if (data.prepare) { + if (data.forcePrepare) { + contexts = await Promise.map(names, name => sdk.contexts.prepare({ name, forceRefresh: true })); + } else if (data.prepare) { contexts = await Promise.map(names, name => sdk.contexts.prepare({ name })); } else { contexts = await Promise.map(names, name => sdk.contexts.get({ name, decrypt: data.decrypt })); diff --git a/openapi.json b/openapi.json index d3932dac6..667cb8362 100644 --- a/openapi.json +++ b/openapi.json @@ -3128,7 +3128,16 @@ }, "required": true, "description": "Name" - }], + }, + { + "in": "query", + "name": "forceRefresh", + "schema": { + "type": "boolean" + }, + "description": "Refresh the token even if the current token is still valid" + } + ], "summary": "Get", "x-sdk-interface": "contexts.prepare" } diff --git a/package.json b/package.json index 3fb6f5cf3..d84e185cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "1.0.6", + "version": "1.1.0", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,