Skip to content

Commit 0290e00

Browse files
authored
Ceng 567 fix sso auth token refresh workflow (#218)
* added --force parameter to auth and tokens refresh commands * Bump version: 1.8.4 → 1.8.5
1 parent 76c4dfe commit 0290e00

6 files changed

Lines changed: 62 additions & 24 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.8.4
2+
current_version = 1.8.5
33
commit = True
44
tag = True
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [1.8.5] - 2025-10-16
11+
12+
### Added
13+
14+
- Added `--force` parameter to the Auth command to be used in conjunction with `--token` to refresh tokens without interactive prompts i.e automatic.
15+
- Added `--force` parameter to the Tokens refresh command to automaticlly refresh without an interactive prompt.
16+
1017
## [1.8.4] - 2025-10-06
1118

1219
### Added

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ RUN mkdir -p /opt/cloudsmith \
1515
&& chmod +x /opt/cloudsmith/cloudsmith
1616

1717
# Default command
18-
ENTRYPOINT [ "cloudsmith" ]
18+
ENTRYPOINT [ "cloudsmith" ]

cloudsmith_cli/cli/commands/auth.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@
3131
is_flag=True,
3232
help="Retrieve a user API token after successful authentication.",
3333
)
34+
@click.option(
35+
"-f",
36+
"--force",
37+
default=False,
38+
is_flag=True,
39+
help="Force create a user API token after successful authentication.",
40+
)
3441
@decorators.common_cli_config_options
3542
@decorators.common_cli_output_options
3643
@decorators.initialise_api
3744
@click.pass_context
38-
def authenticate(ctx, opts, owner, token):
45+
def authenticate(ctx, opts, owner, token, force):
3946
"""Authenticate to Cloudsmith using the org's SAML setup."""
4047
owner = owner[0].strip("'[]'")
4148
api_host = opts.api_config.host
@@ -75,18 +82,22 @@ def authenticate(ctx, opts, owner, token):
7582
try:
7683
api_token = user.create_user_token_saml()
7784
click.echo(f"New token value: {click.style(api_token.key, fg='magenta')}")
78-
create, has_errors = create_config_files(ctx, opts, api_key=api_token.key)
79-
new_config_messaging(has_errors, opts, create, api_key=api_token.key)
80-
return
85+
86+
if not token:
87+
create, has_errors = create_config_files(
88+
ctx, opts, api_key=api_token.key
89+
)
90+
new_config_messaging(has_errors, opts, create, api_key=api_token.key)
8191
except exceptions.ApiException as exc:
8292
if exc.status == 400:
83-
if "User has already created an API key" in exc.detail:
84-
click.confirm(
85-
"User already has a token. Would you like to recreate it?",
86-
abort=True,
87-
)
88-
else:
89-
raise
93+
if not force:
94+
if "User has already created an API key" in exc.detail:
95+
click.confirm(
96+
"User already has a token. Would you like to recreate it?",
97+
abort=True,
98+
)
99+
else:
100+
raise
90101

91102
context_msg = "Failed to refresh the token!"
92103
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
@@ -98,15 +109,23 @@ def authenticate(ctx, opts, owner, token):
98109
f"Created: {click.style(t.created, fg='green')}, "
99110
f"slug_perm: {click.style(t.slug_perm, fg='cyan')}"
100111
)
101-
token_slug = click.prompt(
102-
"Please enter the slug_perm of the token you would like to refresh"
103-
)
104112

105-
click.echo(f"Refreshing token {token_slug}... ", nl=False)
113+
if not force:
114+
token_slug = click.prompt(
115+
"Please enter the slug_perm of the token you would like to refresh"
116+
)
117+
click.echo(f"Refreshing token {token_slug}... ", nl=False)
118+
else:
119+
# Use the first available slug_perm for simplicity
120+
token_slug = api_tokens[0].slug_perm
121+
click.echo(f"Refreshing token {token_slug}... ", nl=False)
122+
106123
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
107124
with maybe_spinner(opts):
108125
new_token = user.refresh_user_token(token_slug)
109126
click.secho("OK", fg="green")
110127
click.echo(f"New token value: {click.style(new_token.key, fg='magenta')}")
111-
create, has_errors = create_config_files(ctx, opts, api_key=new_token.key)
112-
new_config_messaging(has_errors, opts, create, api_key=new_token.key)
128+
129+
if not force:
130+
create, has_errors = create_config_files(ctx, opts, api_key=new_token.key)
131+
new_config_messaging(has_errors, opts, create, api_key=new_token.key)

cloudsmith_cli/cli/commands/tokens.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ def list_tokens(ctx, opts):
4444
"token_slug",
4545
required=False,
4646
)
47+
@click.option(
48+
"-f",
49+
"--force",
50+
default=False,
51+
is_flag=True,
52+
help="Force create a user API token after successful authentication.",
53+
)
4754
@decorators.common_cli_config_options
4855
@decorators.common_cli_output_options
4956
@decorators.common_api_auth_options
5057
@decorators.initialise_api
5158
@click.pass_context
52-
def refresh(ctx, opts, token_slug):
59+
def refresh(ctx, opts, token_slug, force):
5360
"""Refresh a specific API token by its slug."""
5461
context_msg = "Failed to refresh the token!"
5562

@@ -59,9 +66,14 @@ def refresh(ctx, opts, token_slug):
5966
api_tokens = api.list_user_tokens()
6067
click.echo("Current tokens:")
6168
print_tokens(api_tokens)
62-
token_slug = click.prompt(
63-
"Please enter the slug_perm of the token you would like to refresh"
64-
)
69+
if not force:
70+
token_slug = click.prompt(
71+
"Please enter the slug_perm of the token you would like to refresh"
72+
)
73+
else:
74+
# Use the first available slug_perm for simplicity
75+
token_slug = api_tokens[0].slug_perm
76+
click.echo(f"Refreshing token {token_slug}... ", nl=False)
6577

6678
click.echo(f"Refreshing token {token_slug}... ", nl=False)
6779
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):

cloudsmith_cli/data/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.4
1+
1.8.5

0 commit comments

Comments
 (0)