Skip to content
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

Allow reading and writing shared config file #20

Open
bkircher opened this issue Apr 14, 2022 · 4 comments · May be fixed by #23
Open

Allow reading and writing shared config file #20

bkircher opened this issue Apr 14, 2022 · 4 comments · May be fixed by #23
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@bkircher
Copy link
Contributor

We want to create a new config file that is shared across the different libraries and tools that use the gridscale API: gridscale/terraform-provider-gridscale#183

For this we need to have a function that reads that config file into an internal representation and probably also a function that writes such a config file if it does not yet exists.

See gridscale/terraform-provider-gridscale#183 for the format of the file and file paths on the different platforms.

@bkircher bkircher added enhancement New feature or request good first issue Good for newcomers labels Apr 14, 2022
@bkircher bkircher assigned bkircher and BoxG11 and unassigned bkircher Apr 14, 2022
@BoxG11
Copy link
Contributor

BoxG11 commented Apr 14, 2022

I'm looking at examples.py to get an idea now of what to do.
This is how it currently works:

#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"

This then uses configuration.py from gs_api_client to create the authentication settings. Should this be changed to populate X-Auth-Token and X-Auth-UserId from the yaml file? Then only the project would have to be specified in the examples.py

@BoxG11
Copy link
Contributor

BoxG11 commented Apr 15, 2022

a first draft: https://github.com/gridscale/gridscale_api_client_python/commit/acb07f79e4526a67225c027a3b7a9c099dcd1b49.

Works on Mac but I can only check next week if the paths are formatted correctly on linux and windows. Happy easter.

@bkircher
Copy link
Contributor Author

bkircher commented Apr 22, 2022

Hey. Thanks for the work ❤️ and sorry for being a bit unresponsive! 😔

As a quick feed back on that branch:

First, can you drop the additions under .idea/ please? I have no objections adding editorconfig, IDE files, whatever if they make sense but if we do we should do it in a separate branch and PR and get the right people to review (like other PyCharm users 🙂 ).

Now to the nitty-gritty, the changes in configloader.py. Let's do it step by step.

  1. Can you make load_config return a list of dicts whereas the keys are as follows?
{
"name": str
"user_id": str
"token": str
"url": str
}

This makes load_config always return a list (possible empty) of all projects that are defined by the user. It does not need to concern itself which one is default or "active" or so.

  1. Since we're parsing YAML we need to add pyyaml as dependency (setup.py or dev-requirements.txt or both)

  2. We should start by writing a small test to define an interface and the basic behavior. I took the freedom to do this here (2c62062) in your branch. You can run pytest to see the result. It currently fails. Maybe try to make it green without changing the test?

@bkircher
Copy link
Contributor Author

Ah, just saw another "formality". Can you make sure that you follow git commit message rules? See here for a nice writeup:
https://cbea.ms/git-commit/#seven-rules

In your case, use imperative language and capitalization and punctuation. You might also want to configure your git config in a way that it shows your real name and email:

$ git config user.name "Jonathan Lutterbeck"
$ git config user.email [email protected]

@BoxG11 BoxG11 linked a pull request May 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants