Utilities
This section shows general objects and helper functions that are used with this package.
Permission Test Utilities
Resource
- class balderhub.auth.lib.utils.BaseResource
Bases:
ABCThis is the base class for all resource types.
- exception DoesNotExistError
Bases:
ResourceEnterErrorException that is raised if a resource does not exist.
- exception NoPermissionError
Bases:
ResourceEnterErrorException that is raised if the user has no permission to access a resource.
- exception ResourceEnterError
Bases:
ExceptionBase exception for all errors that occur when entering a resource.
- exception UnauthorizedError
Bases:
ResourceEnterErrorException that is raised if the user is not authorized to access a resource.
- class balderhub.auth.lib.utils.Resource
Bases:
BaseResourceThis class represents a resolved resource.
- class balderhub.auth.lib.utils.UnresolvedResource(**kwargs)
Bases:
BaseResource,ABCThis is the base class for all unresolved resource types.
- class Parameter
Bases:
objectBase class for parameters that are used to resolve an unresolved resource.
Operation
- class balderhub.auth.lib.utils.Operation(resource: Resource, action: Action)
Bases:
objectThis class represents an operation, which is a combination of a resource and an action.
- exception DoesNotExistError
Bases:
OperationEnterErrorException that is raised if the peration does not exist.
- exception NoPermissionError
Bases:
OperationEnterErrorException that is raised if the user has no permission to perform the action on the resource.
- exception OperationEnterError
Bases:
ExceptionBase exception for all errors that occur when executing an operation.
- exception UnauthorizedError
Bases:
OperationEnterErrorException that is raised if the user is not authorized to perform the action on the resource.
- class balderhub.auth.lib.utils.OperationList(iterable: Iterable[OperationT] | None = None)
Bases:
objectThis class represents a list of operations.
- append(operation: OperationT)
Appends an operation to the list.
- Parameters:
operation – the operation to append
- extend(other: OperationList)
Extends the list with the operations from another OperationList.
- Parameters:
other – the other OperationList to extend this list with
Action
- class balderhub.auth.lib.utils.Action
Bases:
objectbase class for actions
Rules
- class balderhub.auth.lib.utils.ResourceRule(resource: Resource | UnresolvedResource, actions: list[balderhub.auth.lib.utils.action.Action], rule: Callable[[Parameter], bool] | None = None)
Bases:
objectThis class represents a rule for a resource and a list of actions that are allowed for this resource.
- property actions: list[balderhub.auth.lib.utils.action.Action]
returns a copy of the list of actions of this rule
- copy() ResourceRule
creates a deep copy of this rule
- flatten() ResourceRuleList
Converts this rule into a ResourceRuleList where every ResourceRule has exactly one Action.
- Returns:
a ResourceRuleList containing the flattened rules
- resolve(parameter: Parameter | None = None) OperationList | None
Resolves the rule with the given parameter.
If the resource is a resolved resource, the parameter must be None. If the resource is an unresolved resource, the parameter can be provided. If a parameter is provided, the rule function is called with the parameter. If the rule function returns False, None is returned. Otherwise, the unresolved resource is resolved with the parameter and an OperationList containing the resolved resource and the actions is returned.
- Parameters:
parameter – the parameter for the unresolved resource
- Returns:
an OperationList containing the resolved operations or None if the rule does not match
- property resource: Resource | UnresolvedResource
returns the resource of this rule
- class balderhub.auth.lib.utils.ResourceRuleList(iterable: Iterable[ResourceRule] | None = None)
Bases:
objectThis class represents a list of resource rules.
- append(rule: ResourceRule)
Appends a resource rule to the list.
- Parameters:
rule – the resource rule to append
- extend(other: ResourceRuleList)
Extends the list with the rules from another ResourceRuleList.
- Parameters:
other – the other ResourceRuleList to extend this list with
- filter_for_resolved_only()
Filters the list for rules with resolved resources only.
- Returns:
a new ResourceRuleList containing only the rules with resolved resources
- filter_for_unresolved_only()
Filters the list for rules with unresolved resources only.
- Returns:
a new ResourceRuleList containing only the rules with unresolved resources
- flatten() ResourceRuleList
Goes through every list item and converts it to a list of ResourceRules with exactly one Action :return: a flatten ResourceRuleList, where every ResourceRule has exactly one Action
- flatten_and_group_by_resource_and_action() dict[balderhub.auth.lib.utils.resource.Resource, dict[balderhub.auth.lib.utils.action.Action, balderhub.auth.lib.utils.resource_rule.ResourceRule]]
Flattens the rules and groups them by resource and action.
- Returns:
a dictionary where the keys are resources and the values are dictionaries where the keys are actions and the values are the corresponding resource rules
- property rules: list[balderhub.auth.lib.utils.resource_rule.ResourceRule]
returns the list of rules