castlecraft_engineer.authorization.base_service
¶
castlecraft_engineer.authorization.base_service
¶
AuthorizationError
¶
Bases: Exception
Custom exception for authorization failures.
Source code in src/castlecraft_engineer/authorization/base_service.py
AuthorizationService
¶
Bases: ABC
Abstract interface for authorization checks. Implementations connect to engines like Casbin, OPA, SpiceDB, etc.
Source code in src/castlecraft_engineer/authorization/base_service.py
check_permission(subject_id, required_permissions, provided_permissions=None, context=None)
abstractmethod
async
¶
Checks if the subject has the required permissions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject_id
|
Optional[str]
|
Identifier of the user/service performing the action. Can be None for anonymous checks if supported by the policy. |
required |
required_permissions
|
List[Permission]
|
A list of Permission objects declared by the handler via the @ctx decorator. |
required |
provided_permissions
|
Optional[List[str]]
|
Optional list of permissions the subject possesses. |
None
|
context
|
Optional[Dict[str, Any]]
|
Optional dictionary containing additional data for policy evaluation. |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if authorized. |
Raises:
Type | Description |
---|---|
AuthorizationError
|
If the check fails. This is often preferred over returning False to halt execution clearly. |
NotImplementedError
|
If the method is not implemented. |