-
Notifications
You must be signed in to change notification settings - Fork 46
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
Rework auth/api_token parameters #201
Conversation
Thanks, @shoeffner, that looks great! I agree with the changes made to allow passing either 'auth' or 'api_token'. I just tested it locally, and it works perfectly 🙌 |
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.
I didn't run the code or even look at it very closely but I'm happy there are tests and the PR seems reasonable to me.
I'm leaving a few tiny suggestions for docs.
Thanks for the PR, @shoeffner! ❤️
@@ -64,6 +65,7 @@ optional = true | |||
black = "^24.3.0" | |||
radon = "^6.0.1" | |||
mypy = "^1.9.0" | |||
types-jsonschema = "^4.23.0" |
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.
Out of curiosity, where is this used?
I'm asking because upstream we've been trying to improve JSON Schema support:
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.
In utils, jsonschema.validate is used:
pyDataverse/pyDataverse/utils.py
Line 8 in 3b6fe06
from jsonschema import validate |
jsonschema is not typed, so mypy requires the type stubs for it. When you run mypy on the code you will get the respective error.
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.
I had a look, the call chain is: pyDataverse.models.(Dataset|DVObject).validate_json
-> pyDataverse.utils.validate_data
-> jsonschema.validate
.
There are also four schema.json files checked in at pyDataverse/schemas/json (which is not a package though, so one would need the filepaths to validate against them).
The function is not called automatically and supposed to be usable by consumers of the package, the validate_json functions are tested in test_datafile.py, test_dataset.py, and test_dataverse.py. The paths to the schemas are declared in the conftest.py.
The SWORD API returns an empty string for 401 Unauthorized. This would cause the usual response handling of extracting the error message from the JSON to raise, so we except that in that case. Resolves review comment on gdcc#201.
@shoeffner, due to the merge of the |
I'll take a look, thanks for letting me know! |
This way, they use the class names and base URLs, instead of being specified for each class.
This test verifies that parameter ?key is not used. Otherwise, it will occur in error messages, which might lead to an unwanted disclosure of the key, e.g., when sharing log messages.
- Add custom httpx.Auth implementation for Dataverse API Tokens - Add custom httpx.Auth implementation for Dataverse Bearer Token - Add auth to docs
It is still possible to use the api_token parameter. In this case assume an API token was copied from the user profile of a Dataverse instance. If both are specified, an api_token and an explicit auth method, warn the user and use the auth method. Closes gdcc#192.
Instead, if required, use multiple instances of each API implementation.
Also add types-jsonschema as a lint dependency.
The SWORD API returns an empty string for 401 Unauthorized. This would cause the usual response handling of extracting the error message from the JSON to raise, so we except that in that case. Resolves review comment on gdcc#201.
Alright, I rebased everything and resolved one incompatibility with #203, which I didn't pay attention to during the rebase. Should work now. |
@shoeffner, thanks a lot - Merging! |
Describe your environment
On host:
Inside container:
Follow best practices
put_request
.Describe the PR
isinstance(..., ("".__class__, "".__class__))
with the much more legible and equivalent (as far as I can tell)isinstance(..., str)
.auth
on individual functions in favor of generating multiple API objects with different auth methods.False
, but there was one call defaulting toTrue
(get_access
) and this would not catch code explicitly settingauth=False
on the callsite. So I decided to introduce a new default argument and show a warning if it is overwritten. Happy to discuss this decision – I have never done such an orderly deprecation before, so this is my first try :)Api.__str__
methods into the PR. As I scrolled by, I saw that they essentially could be removed and just theApi.__str__
method itself should useself.__class__.__name__
to get a similar result. However, the DataAccessApi will not printDataAccessApi: ...
instead of the previousData Access API: ...
– the same applies for the others. However, this felt to be more in spirit with the docstring (which I then also updated slightly). If that's not so nice, we can move that to its own PR or even drop that commit entirely.self.base_url = None
assignment in api.py, and the pyproject.toml) for mypy.params
properly due to the name change of params -> headers.api.py
into sub-modules #189 easier.Closes #ISSUE_NUMBER
to the end of this pull requestTesting
Commits
Closes #ISSUE_NUMBER
in your commit messages to auto-close the issue that it fixes (if such).Others
Documentation contribution
Code contribution
Note that this PR depends on other PRs which should be reviewed and decided/acted upon first, I can also rebase/merge the changes into this branch afterwards.
In particular:
Closes #192 .