Beispiel #1
0
 def _get_rbac_policy(self, context, id):
     object_type = self._get_object_type(context, id)
     rbac_class = rbac_obj.RBACBaseObject.get_type_class_map()[object_type]
     _rbac_obj = rbac_class.get_object(context, id=id)
     if not _rbac_obj:
         raise ext_rbac.RbacPolicyNotFound(id=id, object_type=object_type)
     return _rbac_obj
Beispiel #2
0
 def _get_rbac_policy(self, context, id):
     object_type = self._get_object_type(context, id)
     dbmodel = models.get_type_model_map()[object_type]
     try:
         return model_query.query_with_hooks(
             context, dbmodel).filter(dbmodel.id == id).one()
     except exc.NoResultFound:
         raise ext_rbac.RbacPolicyNotFound(id=id, object_type=object_type)
Beispiel #3
0
    def _get_object_type(self, context, entry_id):
        """Scans all RBAC tables for an ID to figure out the type.

        This will be an expensive operation as the number of RBAC tables grows.
        The result is cached since object types cannot be updated for a policy.
        """
        if entry_id in self.object_type_cache:
            return self.object_type_cache[entry_id]
        for otype, model in models.get_type_model_map().items():
            if (context.session.query(model).filter(
                    model.id == entry_id).first()):
                self.object_type_cache[entry_id] = otype
                return otype
        raise ext_rbac.RbacPolicyNotFound(id=entry_id, object_type='unknown')
Beispiel #4
0
    def _get_object_type(self, context, entry_id):
        """Scans all RBAC tables for an ID to figure out the type.

        This will be an expensive operation as the number of RBAC tables grows.
        The result is cached since object types cannot be updated for a policy.
        """
        if entry_id in self.object_type_cache:
            return self.object_type_cache[entry_id]
        for otype, rbac_class in \
                rbac_obj.RBACBaseObject.get_type_class_map().items():
            if rbac_class.count(context, id=entry_id):
                self.object_type_cache[entry_id] = otype
                return otype
        raise ext_rbac.RbacPolicyNotFound(id=entry_id, object_type='unknown')