Support authentication without a config file #125
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #123
What has been done to verify that this works as intended?
I have added the test class
TestClientDirectCredentialswhich runs a simple integration test to verify the new authentication implementation succeeds. There is also a test which verifies the logic for when errors are expected to be raised.Following the testing instructions, those tests passed. For the same reason as why the other test class in
tests/test_client.pyare skipped by default (quoted below), I've also skipped this test class by default.Why is this the best possible solution? Were any other approaches considered?
We also tested out a workaround on our end which was wrapping the
Clientin a context manager such that temporary files would be generated to dump credentials during use and then removed upon exit. This felt cumbersome in practice, and we have some concerns about this approach related to race conditions and security risks (see issue).We don't see any significant downsides to allowing direct passing of
base_url,username, andpasswordinto the instantiation ofClient. One consideration is that multiple ways of authenticating could feel less straightforward for users of the library. This is hopefully mitigitated by the defensive implentation that a config file is used XOR credentials files are directly passed in.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Intentional change:
Clientdirectly withbase_url,username, andpasswordinstead of providing a TOML config file.Unchanged behavior:
Client()using.pyodk_config.tomlfrom the home directory) remains intact.Regression risk:
Do we need any specific form for testing your changes? If so, please attach one.
No specific form is needed; any Central instance with accessible credentials is sufficient to verify authentication. The tests can be run by removing the
@skipdecorator on the class.Does this change require updates to documentation? If so, please file an issue here and include the link below.
I updated the README.md to show the new direct initialization option. Are there additional docs to be updated?
Issue link: #123
Before submitting this PR, please make sure you have:
testspython -m unittestand verified all tests passruff format pyodk testsandruff check pyodk teststo lint code