diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 132d30f1..49b8c4e2 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.8.4 +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 8672466a..c244e006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [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/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..5dc6ad1d 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 refresh of user API token without prompts.", +) @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..a4b96ab5 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 refresh of user API token without prompts.", +) @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..f263cd11 100644 --- a/cloudsmith_cli/data/VERSION +++ b/cloudsmith_cli/data/VERSION @@ -1 +1 @@ -1.8.4 +1.8.6