-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(login): prevent duplicate api-token names (#3)
- Loading branch information
1 parent
359e3f2
commit 69c49a6
Showing
2 changed files
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,11 @@ def main(ctx: click.Context): | |
type=click.Choice(['staging', 'production']), | ||
default='production' | ||
) | ||
def login(environment): | ||
@click.option( | ||
'-t', '--token-name', help='the name of the api tokern created for this client', | ||
default='pollination-apps-cli', | ||
) | ||
def login(environment: str, token_name: str): | ||
"""login to pollination""" | ||
|
||
ctx = Context.from_file() | ||
|
@@ -41,7 +45,15 @@ def login(environment): | |
client = ctx.client | ||
client.set_host(env.api_host) | ||
client.set_jwt(jwt) | ||
ctx.api_token = client.create_api_token() | ||
user = client.get_account() | ||
if client.api_token_name_exists(name=token_name): | ||
This comment has been minimized.
Sorry, something went wrong. |
||
raise click.ClickException( | ||
f'Login Failed -> API Token name {token_name} is already taken. ' | ||
'You can either:\n' | ||
f'\t1. delete it from the web application at https://app.pollination.cloud/{user.username}?tab=settings\n' | ||
'\t2. choose a new name by using the --token-name/-t flag' | ||
) | ||
ctx.api_token = client.create_api_token(name=token_name) | ||
This comment has been minimized.
Sorry, something went wrong.
mostaphaRoudsari
Member
|
||
ctx.save() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey @AntoineDao! In this case, can we retrieve the existing token instead of raising an error? That will avoid asking the user to manually delete the token and try to create a new one.