"""Util methods to make auth of RAP endpoints easier.""" from uuid import UUID from pdp.constants.constants import IDENTITY_RESOURCE_DELIMITER from pdp.fastapi.schemas.identity import Resource, TenantRoles def build_identity_resource_from_tenant_role( identity_uuid: UUID, tenant_role: TenantRoles, ) -> Resource: """Build Identity resource for check resources operation using tenant_role.""" return Resource( resource_id=f"{identity_uuid}{IDENTITY_RESOURCE_DELIMITER}{tenant_role.tenant_uuid}", # noqa: E501 resource_type="identity", attributes={ "tenant": { "tenant_uuid": str(tenant_role.tenant_uuid), "tenant_type": tenant_role.tenant_type.value, }, "identity_uuid": str(identity_uuid), }, ) def get_tenant_uuid_from_identity_resource_id(resource_id: str) -> UUID: """Parse identity resource_id to get the tenant_uuid. Note, we expect that this function will only be used in conjunction with build_identity_resource_from_tenant_role. """ return UUID(resource_id.split(IDENTITY_RESOURCE_DELIMITER)[1])