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

Add support for multiple servers in config #59

Open
yanokwa opened this issue Dec 13, 2023 · 1 comment
Open

Add support for multiple servers in config #59

yanokwa opened this issue Dec 13, 2023 · 1 comment

Comments

@yanokwa
Copy link
Member

yanokwa commented Dec 13, 2023

I work with lots of different servers and it's a pain to constantly edit .pyodk_config.toml. I'd love to be able to switch profiles on the fly.

Given this .pyodk_config.toml, I'd like to be able to call Client(profile="demo") to use the demo url/user/pass and Client(profile="test") to use the test profile.

[demo]
base_url = "https://demo.getodk.cloud"
username = "alice"
password = "bob"

[default]
base_url = "https://www.example.com"
username = "my_user"
password = "my_password"
default_project_id = 123

[test]
base_url = "https://test.getodk.cloud"
username = "foo"
password = "bar"

Note that I have [default] for the default profile. Our docs for the single server config currently uses [central], so maybe if there is only one profile, that is the default regardless of what the header is. If there are two or more, then the default needs to be called [default]. Then we can update the docs to use [default].

@lindsay-stevens
Copy link
Contributor

It's possible to do this kind of thing by specifying the config paths in the Client constructor, or via env vars:

Setting environment variables PYODK_CONFIG_FILE and PYODK_CACHE_FILE
Init arguments: Client(config_path="my_config.toml", cache_path="my_cache.toml").

So for 3 different servers the calls might look like:
Client(config_path="pyodk_default_config.toml", cache_path="pyodk_default_cache.toml")
Client(config_path="pyodk_demo_config.toml", cache_path="pyodk_demo_cache.toml")
Client(config_path="pyodk_test_config.toml", cache_path="pyodk_test_cache.toml")

Using separate files somewhat reduces the risk of accidentally copying credentials to somewhere they shouldn't be, and allows use of file system access controls with automation (e.g. script A user can see conf A files).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants