Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 18d27df

Browse files
committed
add set_apikey function
1 parent 58c7026 commit 18d27df

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

paperspace/login.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ def apikey():
102102
return ''
103103

104104

105+
def set_apikey(apikey):
106+
paperspace_dir = os.path.expanduser('~/.paperspace')
107+
config_path = os.path.join(paperspace_dir, 'config.json')
108+
if not os.path.exists(paperspace_dir):
109+
os.makedirs(paperspace_dir)
110+
config_data = {}
111+
112+
# update config.PAPERSPACE_API_KEY
113+
config.PAPERSPACE_API_KEY = apikey
114+
115+
# save api key
116+
config_data['apiKey'] = apikey
117+
with open(config_path, 'w') as outfile:
118+
json.dump(config_data, outfile, indent=2, sort_keys=True)
119+
outfile.write('\n')
120+
121+
return True
122+
123+
105124
def logout():
106125
paperspace_dir = os.path.expanduser('~/.paperspace')
107126
config_path = os.path.join(paperspace_dir, 'config.json')

0 commit comments

Comments
 (0)