restish.guard¶
Resource and method guards (the basis of access control).
This module consists of a decorator (guard) and a resource wrapper (GuardResource) that iterate through a list of checker functions before allowing access to the application.
A checker function is a callable that takes the request and the object being protected as the two positional arguments. The checker function should raise an HTTP exception to block access.
For example, the following checker tests if the request contains the name of an authenticated user as the REMOTE_USER:
- def authenticated_checker(request, obj):
- if request.environ.get(‘REMOTE_USER’) is None:
- raise guard.GuardError(“No authenticated user.”)
- exception restish.guard.GuardError(message)¶
Bases: exceptions.Exception
Guard check failure.
- message¶
- class restish.guard.GuardResource(resource, *checkers, **kwargs)¶
Bases: object
Resource wrapper that guards access to a resource by calling each checker before calling the wrapped resource’s methods.
- resource_child(request, segments)¶
- Check the guard methods and raise error handler if errors
- restish.guard.guard(*checkers, **kwargs)¶
Decorator that guards a function by calling each checker function before calling the decorated function.
The only requirement is that the decorated function takes the request as the first positional arg.