Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for get allowed roles in Python #1675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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