-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to store evalai authentication token(#116)
- Loading branch information
1 parent
d3e75d8
commit b272489
Showing
4 changed files
with
49 additions
and
0 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ source = evalai/ | |
exclude_lines = | ||
import | ||
@click.* | ||
main.add_command([a-z]*?) | ||
|
||
omit = | ||
*/python?.?/* | ||
|
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import click | ||
import os | ||
import validators | ||
|
||
from click import echo, style | ||
|
||
from evalai.utils.config import (AUTH_TOKEN_DIR, | ||
AUTH_TOKEN_PATH, | ||
LEN_OF_TOKEN,) | ||
|
||
|
||
@click.group(invoke_without_command=True) | ||
@click.argument('add_token') | ||
def token(add_token): | ||
""" | ||
View and configure the EvalAI Token. | ||
""" | ||
""" | ||
Invoked by `evalai token <your_token_here>`. | ||
""" | ||
if add_token is not None: | ||
if validators.length(add_token, min=LEN_OF_TOKEN, max=LEN_OF_TOKEN): | ||
if not os.path.exists(AUTH_TOKEN_DIR): | ||
os.makedirs(AUTH_TOKEN_DIR) | ||
with open(AUTH_TOKEN_PATH, 'w+') as fw: | ||
try: | ||
fw.write(add_token) | ||
except (OSError, IOError) as e: | ||
echo(e) | ||
echo(style("Token successfully set!", bold=True)) | ||
else: | ||
echo(style("Error: Invalid Length. Enter a valid token of length: {}".format(LEN_OF_TOKEN), bold=True)) | ||
else: | ||
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 <token> to add it.\n\n", bold=True)) | ||
else: | ||
with open(AUTH_TOKEN_PATH, 'r') as fr: | ||
try: | ||
data = fr.read() | ||
echo(style("Current token: {}".format(data), bold=True)) | ||
except (OSError, IOError) as e: | ||
echo(e) |
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
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