Allow request hooks to return a response to return immediately#150
Allow request hooks to return a response to return immediately#150mishaschwartz wants to merge 1 commit into
Conversation
|
@mishaschwartz As a few examples, https://github.com/bird-house/birdhouse-deploy/blob/master/birdhouse/components/weaver/config/magpie/weaver_hooks.py.template uses them to modify the request/response contents (and even create extra permissions if needed) based on the identified user. From the perspective of Twitcher, technically, it does not know "user" and it is not its role. Twitcher enforces the decision (PEP). Magpie makes the decision (PDP) since it knows the resources. |
|
@mishaschwartz I would like to consider other things just to make sure we don't maintain many ways to do similar procedures. What does the Otherwise, wouldn't there be a way to invoke the |
Yes I'm setting this up as a service hook. But the hooks are invoked by the At the point where
There's conditional logic there... some calls will return a request and then the request will get passed to the upstream service and others will return a response immediately.
The hooks aren't actually invoked for the verify calls right now. If you think that's a better solution then I'm happy to move this logic to the verify endpoint instead. |
This feature allows a request hook to completely skip sending the request to the upstream service and return a response immediately.
Right now, if I want to deny access to the upstream service within a request hook I can raise a (python) error which will return a 500 status response to the user. This 500 error has a generic error message and body which may or may not appropriately convey the reason for the error.
With this change I can instead return a
pyramid.responses.Responseobject directly from the request hook. This will return the response to the user which allows me to customize the status code, body, headers, etc. This makes the response much more informative to the user.My specific use case:
/users/<username>/some/other/resource/)joeto be able to access paths that start with/users/joe/but deny everyone else/users/<username>for each user that gets create, I could even try to automate this with cowbird