Skip to content

Commit

Permalink
add pdp api and list role assignment api from pdp
Browse files Browse the repository at this point in the history
  • Loading branch information
RazcoDev committed Apr 11, 2024
1 parent b719aec commit 88f13ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
18 changes: 1 addition & 17 deletions permit/pdp_api/pdp_api_client.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
from ..config import PermitConfig
from .condition_set_rules import ConditionSetRulesApi
from .condition_sets import ConditionSetsApi
from .deprecated import DeprecatedApi
from .environments import EnvironmentsApi
from .projects import ProjectsApi
from .relationship_tuples import RelationshipTuplesApi
from .resource_action_groups import ResourceActionGroupsApi
from .resource_actions import ResourceActionsApi
from .resource_attributes import ResourceAttributesApi
from .resource_instances import ResourceInstancesApi
from .resource_relations import ResourceRelationsApi
from .resource_roles import ResourceRolesApi
from .resources import ResourcesApi
from .role_assignments import RoleAssignmentsApi
from .roles import RolesApi
from .tenants import TenantsApi
from .users import UsersApi


class PermitApiClient(DeprecatedApi):
class PermitPdpApiClient:
def __init__(self, config: PermitConfig):
"""
Constructs a new instance of the PdpApiClient class with the specified SDK configuration.
Expand Down
17 changes: 15 additions & 2 deletions permit/permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .config import PermitConfig
from .enforcement.enforcer import Action, CheckQuery, Enforcer, Resource, User
from .logger import configure_logger
from .pdp_api.base import BasePdpPermitApi
from .pdp_api.pdp_api_client import PermitPdpApiClient
from .utils.context import Context


Expand All @@ -22,7 +22,7 @@ def __init__(self, config: Optional[PermitConfig] = None, **options):
self._enforcer = Enforcer(self._config)
self._api = PermitApiClient(self._config)
self._elements = ElementsApi(self._config)
self. _pdp_api = BasePdpPermitApi(self._config)
self. _pdp_api = PermitPdpApiClient(self._config)
logger.debug(
"Permit SDK initialized with config:\n${}",
json.dumps(self._config.dict(exclude={"api_context"})),
Expand Down Expand Up @@ -65,6 +65,19 @@ def elements(self) -> ElementsApi:
"""
return self._elements

@property
def pdp_api(self) -> PermitPdpApiClient:
"""
Access the Permit PDP API using this property.
Usage example:
permit = Permit(token="<YOUR_API_KEY>")
await permit.pdp_api.role_assignments.list()
"""
return self._pdp_api


async def bulk_check(
self,
checks: list[CheckQuery],
Expand Down
4 changes: 4 additions & 0 deletions tests/test_rbac_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ async def test_permission_check_e2e(permit: Permit):

print_break()

logger.info("testing list role assignments")
assert permit.pdp_api.role_assignments.list()
print_break()

logger.info("changing the user roles")

# change the user role - assign admin role
Expand Down

0 comments on commit 88f13ec

Please sign in to comment.