-
Notifications
You must be signed in to change notification settings - Fork 1
Enhancement/20 allow reading and writing shared config file #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
acb07f7
09ef4af
2c62062
05c3775
415112c
6aed011
d7d1915
3566688
a658543
5fe3df0
ebc5df8
cf0f739
4a3b790
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ rope | |
black | ||
pytest | ||
pytest-mock | ||
pyyaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
projects: | ||
- name: default | ||
userId: user123 | ||
token: pass123 | ||
url: https://api.gridscale.io | ||
- name: something-else | ||
userId: user456 | ||
token: pass456 | ||
url: https://api.gridscale.io |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import shutil | ||
import sys | ||
import os.path | ||
import pathlib | ||
import yaml | ||
|
||
|
||
def default_config_path(): | ||
""" | ||
|
||
this checks the operation system of the user. | ||
this is used to determine the standard save location for the global gridscale config file. | ||
|
||
""" | ||
#check if os is linux | ||
if(sys.platform in ("linux", "linux2")): | ||
path = "~/.config/gridscale" | ||
path = os.path.expanduser(path) | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
#check if os is windows | ||
elif(sys.platform in ("win32", "cygwin", "msys")): | ||
path = "%APPDATA%\gridscale" | ||
path = os.path.expanduser(path) | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
#check if os is mac os | ||
elif(sys.platform in ("darwin", "os2", "os2emx")): | ||
path = "~/Library/Application Support/gridscale" | ||
path = os.path.expanduser(path) | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
else: | ||
raise RuntimeError("Operating system not supported") | ||
|
||
return path | ||
|
||
|
||
def create_config(path): | ||
""" | ||
this will copy the currently used config file in the standard folder | ||
""" | ||
syspath = default_config_path() + "/config.yaml" | ||
shutil.copyfile(path, syspath) | ||
|
||
|
||
def load_config(path): | ||
""" | ||
First checking "path" to match minimum length and other requirements. | ||
|
||
Then it opens the specified config file and returns all keys which include token and UserId. | ||
""" | ||
# opens specified file to retrieve config tokens | ||
if isinstance(path, (pathlib.Path, str)): | ||
assert path | ||
with open(f"{path}", 'r') as stream: | ||
data = yaml.safe_load(stream) | ||
# return list of dictionaries for all projects | ||
for value in data.values(): | ||
return (value) | ||
else: | ||
raise AssertionError |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
from pprint import pprint | ||
from uuid import uuid4 | ||
import os | ||
from index_by.key import index_by_key | ||
from configloader import load_config | ||
|
||
from gs_api_client import SyncGridscaleApiClient, GridscaleApiClient, models | ||
from gs_api_client import Configuration | ||
|
@@ -16,11 +18,12 @@ | |
# api_config.debug = True | ||
api_config.host = 'https://api.gridscale.io' | ||
|
||
#TODO: Insert your API token and User ID | ||
api_config.api_key['X-Auth-Token'] = "AUTH_TOKEN" | ||
api_config.api_key['X-Auth-UserId'] = "USER_UUID" | ||
# api_config.debug = True | ||
|
||
#TODO: Change filename | ||
configfile = load_config("config.yaml") | ||
api_config.api_key['X-Auth-Token'] = configfile[0].get("token") | ||
api_config.api_key['X-Auth-UserId'] = configfile[0].get("userId") | ||
api_config.debug = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this shouldn't be debug per default |
||
|
||
print('-' * 80) | ||
client = SyncGridscaleApiClient(configuration=api_config, http_info=False) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
projects: | ||
- name: default | ||
userId: user123 | ||
token: pass123 | ||
url: https://api.gridscale.io | ||
|
||
- name: something-else | ||
userId: user456 | ||
token: pass456 | ||
url: https://api.gridscale.io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change the filename?