Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions languages/python/oso/oso/oso.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ def authorize_request(self, actor: _Actor, request: _Request) -> None:
if not self.query_rule_once("allow_request", actor, request):
raise self.forbidden_error()

def authorized_roles(
self,
actor: _Actor,
resource: _Resource,
) -> Set[Any]:
"""Determine the roles ``actor`` has on ``resource``.

Collects all roles of the actor in the Polar policy for the given
combination of actor and resource.

:param actor: The actor for whom to collect roles.

:param resource: The resource being accessed.

:return: A set containing all assigned roles.
"""
results = self.query_rule("has_role", actor, Variable("role"), resource)
return {result.get("bindings").get("role") for result in results}

def authorized_actions(
self, actor: _Actor, resource: _Resource, allow_wildcard: bool = False
) -> Set[Any]:
Expand Down