Skip to content

Commit

Permalink
fix(auth): saves email_id when logged in with auth_token (#288)
Browse files Browse the repository at this point in the history
This commit fixes the issue where email_id of the user is not saved when
rio auth login --auth-token TOKEN is invoked.

Wrike Ticket: https://www.wrike.com/open.htm?id=1329601684
  • Loading branch information
pallabpain authored Mar 25, 2024
1 parent 6eb340b commit 5fb1bbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 3 additions & 4 deletions riocli/auth/login.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Rapyuta Robotics
# Copyright 2024 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@
get_token,
select_organization,
select_project,
validate_token,
validate_and_set_token,
)
from riocli.constants import Colors, Symbols
from riocli.utils.context import get_root_context
Expand Down Expand Up @@ -66,9 +66,8 @@ def login(
ctx = get_root_context(ctx)

if auth_token:
if not validate_token(auth_token):
if not validate_and_set_token(ctx, auth_token):
raise SystemExit(1)
ctx.obj.data['auth_token'] = auth_token
else:
if interactive:
email = email or click.prompt('Email')
Expand Down
12 changes: 7 additions & 5 deletions riocli/auth/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Rapyuta Robotics
# Copyright 2024 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -143,11 +143,10 @@ def get_token(


@with_spinner(text='Validating token...')
def validate_token(token: str, spinner=None) -> bool:
def validate_and_set_token(ctx: click.Context, token: str, spinner=None) -> bool:
"""Validates an auth token."""
config = Configuration()
if 'environment' in config.data:
os.environ['RIO_CONFIG'] = config.filepath
if 'environment' in ctx.obj.data:
os.environ['RIO_CONFIG'] = ctx.obj.filepath

client = Client(auth_token=token)

Expand All @@ -156,6 +155,9 @@ def validate_token(token: str, spinner=None) -> bool:
spinner.text = click.style(
'Token belongs to user {}'.format(user.email_id),
fg=Colors.CYAN)
# Save the token and user email_id in the context
ctx.obj.data['auth_token'] = token
ctx.obj.data['email_id'] = user.email_id
spinner.ok(Symbols.INFO)
return True
except UnauthorizedError:
Expand Down

0 comments on commit 5fb1bbe

Please sign in to comment.