diff --git a/evalai/get_token.py b/evalai/get_token.py index b841ea1d6..bb36d83a1 100644 --- a/evalai/get_token.py +++ b/evalai/get_token.py @@ -1,10 +1,8 @@ import click -import os -from click import echo, style +from click import echo -from evalai.utils.config import AUTH_TOKEN_PATH -import json +from evalai.utils.auth import get_user_auth_token @click.group(invoke_without_command=True) @@ -12,21 +10,5 @@ def get_token(): """ Get the EvalAI token. """ - if not os.path.exists(AUTH_TOKEN_PATH): - echo( - style( - "\nThe authentication token json file doesn't exist at the required path. " - "Please download the file from the Profile section of the EvalAI webapp and " - "place it at ~/.evalai/token.json or use evalai -t to add it.\n\n", - bold=True, - fg="red", - ) - ) - else: - with open(AUTH_TOKEN_PATH, "r") as fr: - try: - data = fr.read() - tokendata = json.loads(data) - echo("Current token is {}".format(tokendata["token"])) - except (OSError, IOError) as e: - echo(e) + token = get_user_auth_token() + echo("Current token is {0}".format(token)) diff --git a/evalai/utils/auth.py b/evalai/utils/auth.py index e18f41bbc..2227d7b69 100644 --- a/evalai/utils/auth.py +++ b/evalai/utils/auth.py @@ -68,7 +68,7 @@ def get_user_auth_token(): style( "\nThe authentication token json file doesn't exists at the required path. " "Please download the file from the Profile section of the EvalAI webapp and " - "place it at ~/.evalai/token.json\n", + "place it at ~/.evalai/token.json or use evalai set_token to add it.\n", bold=True, fg="red", ) diff --git a/tests/test_auth.py b/tests/test_auth.py index ab5cde3a0..67b10300d 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -38,7 +38,7 @@ def test_get_user_auth_token_when_file_does_not_exist(self): expected = ( "\nThe authentication token json file doesn't exists at the required path. " "Please download the file from the Profile section of the EvalAI webapp and " - "place it at ~/.evalai/token.json\n\n" + "place it at ~/.evalai/token.json or use evalai set_token to add it.\n\n" ) runner = CliRunner() result = runner.invoke(challenges)