"""PDP authorization utilities.""" from ddtrace import tracer from flask import g from python_pdp_sdk.resource_getters.base import ForwardKwargsGetter from blacklist_manager.config import pdp_authorization_backend from blacklist_manager.constants import error @tracer.wrap() def pdp_authorize_resource_without_attributes( resource_id: int, resource_type: str, action: str ) -> bool: """Authorize a resource with empty attributes.""" authorized = pdp_authorization_backend.is_authorized( action=action, resource_id=resource_id, resource_type=resource_type, resource_getter=ForwardKwargsGetter() ) if not authorized: g.log.warn( error.ERROR_MESSAGE_UNAUTHORIZED_ACCESS, resources={ 'identity_id': g.request_context.jwt_identity_id, 'resource_id': resource_id, 'resource_type': resource_type, 'auth_response': authorized } ) return False return True