Easily Retrieve the Raw API Key from a View #102
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.
Figured that this would be an easy one to get my feet wet.
Solves #98 as suggested in the issue.
This turns
get_key
on theBaseHasAPIKey
permission class into a@classmethod
which will allow a view or viewset to access the raw API key usingHasAPIKey.get_key(request)
.This will not break backwards compatibility if someone has done
HasAPIKey().get_key(request)
because Python will automatically convert the instance and pass the appropriatecls
type.Compat Annotation
In order for
scripts/check
to run, I had to add the-> Generator
to thenullcontext
context manager. Not sure if this is a standalone issue or what, but it can't hurt others....I hope.Testing
Note: the following text will be removed before merging the PR.
I am trying to understand the test fixtures, but I cannot figure out how to have the
create_request
fixture set up the request correctly for my view to parse the API key.The following is what I'm attempting to do. The
HasAPIKey.get_key(request)
though is either returning None or the entire header. What's the correct argument tocreate_request
for it to pass my custom key without mangling it?