This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
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.
Add support for getting tokens from files that OpenRobot-CLI supports
- Loading branch information
1 parent
ba306b8
commit e0a1f8e
Showing
4 changed files
with
28 additions
and
1 deletion.
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
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
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,20 @@ | ||
import os | ||
import json | ||
|
||
def get_token_from_file(): | ||
# OpenRobot-CLI uses this method for storing the tokens. | ||
# It gets it from ~/.openrobot/api/cridentials.json first. | ||
# If the token key or the file/folder can't be found, it will try to get the token from the OPENROBOT_API_TOKEN env. | ||
# If any of the above fails, it will return None. | ||
|
||
try: | ||
dir = os.path.expanduser("~/.openrobot") | ||
|
||
with open(f'{dir}/api/cridentials.json', 'r') as f: | ||
cridentials = json.load(f) | ||
|
||
token = cridentials['token'] | ||
except: | ||
token = os.environ.get('OPENROBOT_API_TOKEN') | ||
|
||
return token |