From 0290e0050b789cc82a4905b32823e230fc3b2281 Mon Sep 17 00:00:00 2001 From: Colin Moynes <77994705+colinmoynes@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:25:16 +0100 Subject: [PATCH 1/3] Ceng 567 fix sso auth token refresh workflow (#218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added --force parameter to auth and tokens refresh commands * Bump version: 1.8.4 → 1.8.5 --- .bumpversion.cfg | 2 +- CHANGELOG.md | 7 ++++ Dockerfile | 2 +- cloudsmith_cli/cli/commands/auth.py | 53 ++++++++++++++++++--------- cloudsmith_cli/cli/commands/tokens.py | 20 ++++++++-- cloudsmith_cli/data/VERSION | 2 +- 6 files changed, 62 insertions(+), 24 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 132d30f1..87a2e715 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.8.4 +current_version = 1.8.5 commit = True tag = True parse = (?P\d+)\.(?P\d+)\.(?P\d+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8672466a..aabd4ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [1.8.5] - 2025-10-16 + +### Added + +- Added `--force` parameter to the Auth command to be used in conjunction with `--token` to refresh tokens without interactive prompts i.e automatic. +- Added `--force` parameter to the Tokens refresh command to automaticlly refresh without an interactive prompt. + ## [1.8.4] - 2025-10-06 ### Added diff --git a/Dockerfile b/Dockerfile index cb414582..53b957ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,4 @@ RUN mkdir -p /opt/cloudsmith \ && chmod +x /opt/cloudsmith/cloudsmith # Default command -ENTRYPOINT [ "cloudsmith" ] \ No newline at end of file +ENTRYPOINT [ "cloudsmith" ] diff --git a/cloudsmith_cli/cli/commands/auth.py b/cloudsmith_cli/cli/commands/auth.py index 1de75caf..69f4e510 100644 --- a/cloudsmith_cli/cli/commands/auth.py +++ b/cloudsmith_cli/cli/commands/auth.py @@ -31,11 +31,18 @@ is_flag=True, help="Retrieve a user API token after successful authentication.", ) +@click.option( + "-f", + "--force", + default=False, + is_flag=True, + help="Force create a user API token after successful authentication.", +) @decorators.common_cli_config_options @decorators.common_cli_output_options @decorators.initialise_api @click.pass_context -def authenticate(ctx, opts, owner, token): +def authenticate(ctx, opts, owner, token, force): """Authenticate to Cloudsmith using the org's SAML setup.""" owner = owner[0].strip("'[]'") api_host = opts.api_config.host @@ -75,18 +82,22 @@ def authenticate(ctx, opts, owner, token): try: api_token = user.create_user_token_saml() click.echo(f"New token value: {click.style(api_token.key, fg='magenta')}") - create, has_errors = create_config_files(ctx, opts, api_key=api_token.key) - new_config_messaging(has_errors, opts, create, api_key=api_token.key) - return + + if not token: + create, has_errors = create_config_files( + ctx, opts, api_key=api_token.key + ) + new_config_messaging(has_errors, opts, create, api_key=api_token.key) except exceptions.ApiException as exc: if exc.status == 400: - if "User has already created an API key" in exc.detail: - click.confirm( - "User already has a token. Would you like to recreate it?", - abort=True, - ) - else: - raise + if not force: + if "User has already created an API key" in exc.detail: + click.confirm( + "User already has a token. Would you like to recreate it?", + abort=True, + ) + else: + raise context_msg = "Failed to refresh the token!" with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): @@ -98,15 +109,23 @@ def authenticate(ctx, opts, owner, token): f"Created: {click.style(t.created, fg='green')}, " f"slug_perm: {click.style(t.slug_perm, fg='cyan')}" ) - token_slug = click.prompt( - "Please enter the slug_perm of the token you would like to refresh" - ) - click.echo(f"Refreshing token {token_slug}... ", nl=False) + if not force: + token_slug = click.prompt( + "Please enter the slug_perm of the token you would like to refresh" + ) + click.echo(f"Refreshing token {token_slug}... ", nl=False) + else: + # Use the first available slug_perm for simplicity + token_slug = api_tokens[0].slug_perm + click.echo(f"Refreshing token {token_slug}... ", nl=False) + with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): with maybe_spinner(opts): new_token = user.refresh_user_token(token_slug) click.secho("OK", fg="green") click.echo(f"New token value: {click.style(new_token.key, fg='magenta')}") - create, has_errors = create_config_files(ctx, opts, api_key=new_token.key) - new_config_messaging(has_errors, opts, create, api_key=new_token.key) + + if not force: + create, has_errors = create_config_files(ctx, opts, api_key=new_token.key) + new_config_messaging(has_errors, opts, create, api_key=new_token.key) diff --git a/cloudsmith_cli/cli/commands/tokens.py b/cloudsmith_cli/cli/commands/tokens.py index 480a1f06..6b40f542 100644 --- a/cloudsmith_cli/cli/commands/tokens.py +++ b/cloudsmith_cli/cli/commands/tokens.py @@ -44,12 +44,19 @@ def list_tokens(ctx, opts): "token_slug", required=False, ) +@click.option( + "-f", + "--force", + default=False, + is_flag=True, + help="Force create a user API token after successful authentication.", +) @decorators.common_cli_config_options @decorators.common_cli_output_options @decorators.common_api_auth_options @decorators.initialise_api @click.pass_context -def refresh(ctx, opts, token_slug): +def refresh(ctx, opts, token_slug, force): """Refresh a specific API token by its slug.""" context_msg = "Failed to refresh the token!" @@ -59,9 +66,14 @@ def refresh(ctx, opts, token_slug): api_tokens = api.list_user_tokens() click.echo("Current tokens:") print_tokens(api_tokens) - token_slug = click.prompt( - "Please enter the slug_perm of the token you would like to refresh" - ) + if not force: + token_slug = click.prompt( + "Please enter the slug_perm of the token you would like to refresh" + ) + else: + # Use the first available slug_perm for simplicity + token_slug = api_tokens[0].slug_perm + click.echo(f"Refreshing token {token_slug}... ", nl=False) click.echo(f"Refreshing token {token_slug}... ", nl=False) with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): diff --git a/cloudsmith_cli/data/VERSION b/cloudsmith_cli/data/VERSION index bfa363e7..8decb929 100644 --- a/cloudsmith_cli/data/VERSION +++ b/cloudsmith_cli/data/VERSION @@ -1 +1 @@ -1.8.4 +1.8.5 From d5cf1d38979d7c0f296075fd06cb8517cf3a556b Mon Sep 17 00:00:00 2001 From: Colin Moynes <77994705+colinmoynes@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:03:25 +0100 Subject: [PATCH 2/3] Ceng 567 fix parameter description (#219) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added --force parameter to auth and tokens refresh * Bump version: 1.8.4 → 1.8.5 * Fixed --force parameter descriptions --- cloudsmith_cli/cli/commands/auth.py | 2 +- cloudsmith_cli/cli/commands/tokens.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudsmith_cli/cli/commands/auth.py b/cloudsmith_cli/cli/commands/auth.py index 69f4e510..5dc6ad1d 100644 --- a/cloudsmith_cli/cli/commands/auth.py +++ b/cloudsmith_cli/cli/commands/auth.py @@ -36,7 +36,7 @@ "--force", default=False, is_flag=True, - help="Force create a user API token after successful authentication.", + help="Force refresh of user API token without prompts.", ) @decorators.common_cli_config_options @decorators.common_cli_output_options diff --git a/cloudsmith_cli/cli/commands/tokens.py b/cloudsmith_cli/cli/commands/tokens.py index 6b40f542..a4b96ab5 100644 --- a/cloudsmith_cli/cli/commands/tokens.py +++ b/cloudsmith_cli/cli/commands/tokens.py @@ -49,7 +49,7 @@ def list_tokens(ctx, opts): "--force", default=False, is_flag=True, - help="Force create a user API token after successful authentication.", + help="Force refresh of user API token without prompts.", ) @decorators.common_cli_config_options @decorators.common_cli_output_options From 31e3df977ef32e408d869709e3d88d51cec2b7b1 Mon Sep 17 00:00:00 2001 From: Colin Moynes <77994705+colinmoynes@users.noreply.github.com> Date: Thu, 16 Oct 2025 13:52:03 +0100 Subject: [PATCH 3/3] 1.8.6 changelog (#220) * Updated changelog for v1.8.6 --- .bumpversion.cfg | 2 +- CHANGELOG.md | 6 +++++- cloudsmith_cli/data/VERSION | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 87a2e715..49b8c4e2 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.8.5 +current_version = 1.8.6 commit = True tag = True parse = (?P\d+)\.(?P\d+)\.(?P\d+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aabd4ad5..c244e006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] -## [1.8.5] - 2025-10-16 +## [1.8.6] - 2025-10-16 ### Added - Added `--force` parameter to the Auth command to be used in conjunction with `--token` to refresh tokens without interactive prompts i.e automatic. - Added `--force` parameter to the Tokens refresh command to automaticlly refresh without an interactive prompt. +## [1.8.5] - 2025-10-16 + +### Added + ## [1.8.4] - 2025-10-06 ### Added diff --git a/cloudsmith_cli/data/VERSION b/cloudsmith_cli/data/VERSION index 8decb929..f263cd11 100644 --- a/cloudsmith_cli/data/VERSION +++ b/cloudsmith_cli/data/VERSION @@ -1 +1 @@ -1.8.5 +1.8.6