|
4 | 4 |
|
5 | 5 | # TODO: this function is copy-pasted from login.py; |
6 | 6 | # there is something weird going one with imports in __init__.py and I'm unable to import apikey now |
7 | | -def apikey(): |
8 | | - paperspace_dir = os.path.expanduser('~/.paperspace') |
9 | | - config_path = os.path.join(paperspace_dir, 'config.json') |
| 7 | +def get_api_key(config_dir_path, config_file_name): |
| 8 | + paperspace_dir = os.path.expanduser(config_dir_path) |
| 9 | + config_path = os.path.join(paperspace_dir, config_file_name) |
10 | 10 | if os.path.exists(config_path): |
11 | 11 | config_data = json.load(open(config_path)) |
12 | 12 | if config_data and 'apiKey' in config_data: |
13 | 13 | return config_data['apiKey'] |
14 | 14 | return '' |
15 | 15 |
|
16 | 16 |
|
17 | | -_DEFAULT_PAPERSPACE_API_KEY = apikey() |
18 | 17 | _DEFAULT_CONFIG_HOST = "https://api.paperspace.io" |
19 | 18 | _DEFAULT_CONFIG_LOG_HOST = "https://logs.paperspace.io" |
20 | 19 | _DEFAULT_CONFIG_EXPERIMENTS_HOST = "https://services.paperspace.io/experiments/v1/" # TODO: validate this |
| 20 | +_DEFAULT_CONFIG_DIR_PATH = "~/.paperspace" |
| 21 | +_DEFAULT_CONFIG_FILE_NAME = os.path.expanduser("config.json") |
21 | 22 |
|
22 | 23 |
|
23 | 24 | class config(object): |
24 | 25 | DEBUG = os.environ.get("PAPERSPACE_CLI_DEBUG") in ("true", "1") |
25 | | - PAPERSPACE_API_KEY = os.environ.get("PAPERSPACE_API_KEY", _DEFAULT_PAPERSPACE_API_KEY) |
26 | 26 | CONFIG_HOST = os.environ.get("PAPERSPACE_CONFIG_HOST", _DEFAULT_CONFIG_HOST) |
27 | 27 | CONFIG_LOG_HOST = os.environ.get("PAPERSPACE_CONFIG_LOG_HOST", _DEFAULT_CONFIG_LOG_HOST) |
28 | 28 | CONFIG_EXPERIMENTS_HOST = os.environ.get("PAPERSPACE_CONFIG_EXPERIMENTS_HOST", _DEFAULT_CONFIG_EXPERIMENTS_HOST) |
| 29 | + CONFIG_DIR_PATH = os.path.expanduser(os.environ.get("PAPERSPACE_CONFIG_PATH", _DEFAULT_CONFIG_DIR_PATH)) |
| 30 | + CONFIG_FILE_NAME = os.environ.get("PAPERSPACE_CONFIG_FILE_NAME", _DEFAULT_CONFIG_FILE_NAME) |
| 31 | + PAPERSPACE_API_KEY = os.environ.get("PAPERSPACE_API_KEY", get_api_key(CONFIG_DIR_PATH, CONFIG_FILE_NAME)) |
0 commit comments