Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): saves email_id when logged in with auth_token #288

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading