def resource_allowed(enforcer, context, resource_allowed_action, target={}):
    """Check whether 'resource_allowed_action' is allowed by 'enforcer' for
    the given context.
    """
    credentials = context.to_policy_values()
    if 'tenant_id' not in credentials:
        credentials['tenant_id'] = credentials.get('project_id', None)
    if 'is_admin' not in credentials:
        credentials['is_admin'] = context.is_admin
    if not target:
        target = {'project_id': context.tenant, 'user_id': context.user,
            'tenant_id': context.tenant}
    return enforcer.enforce(resource_allowed_action, target, credentials)
