Exemple #1
0
 def index(self, req, namespace, marker=None, limit=None,
           sort_key='created_at', sort_dir='desc', filters=None):
     try:
         filters = filters or dict()
         filters['namespace'] = namespace
         object_repo = self.gateway.get_metadef_object_repo(req.context)
         db_metaobject_list = object_repo.list(
             marker=marker, limit=limit, sort_key=sort_key,
             sort_dir=sort_dir, filters=filters)
         object_list = [MetadefObject.to_wsme_model(
             db_metaobject,
             get_object_href(namespace, db_metaobject),
             self.obj_schema_link) for db_metaobject in db_metaobject_list]
         metadef_objects = MetadefObjects()
         metadef_objects.objects = object_list
     except exception.Forbidden as e:
         LOG.debug("User not permitted to retrieve metadata objects within "
                   "'%s' namespace", namespace)
         raise webob.exc.HTTPForbidden(explanation=e.msg)
     except exception.NotFound as e:
         raise webob.exc.HTTPNotFound(explanation=e.msg)
     except Exception as e:
         LOG.error(encodeutils.exception_to_unicode(e))
         raise webob.exc.HTTPInternalServerError()
     return metadef_objects
Exemple #2
0
    def index(self,
              req,
              namespace,
              marker=None,
              limit=None,
              sort_key='created_at',
              sort_dir='desc',
              filters=None):
        try:
            ns_repo = self.gateway.get_metadef_namespace_repo(
                req.context, authorization_layer=False)
            try:
                namespace_obj = ns_repo.get(namespace)
            except exception.Forbidden:
                # NOTE (abhishekk): Returning 404 Not Found as the
                # namespace is outside of this user's project
                msg = _("Namespace %s not found") % namespace
                raise exception.NotFound(msg)

            # NOTE(abhishekk): This is just a "do you have permission to
            # list objects" check. Each object is checked against
            # get_metadef_object below.
            api_policy.MetadefAPIPolicy(
                req.context, md_resource=namespace_obj,
                enforcer=self.policy).get_metadef_objects()

            filters = filters or dict()
            filters['namespace'] = namespace
            object_repo = self.gateway.get_metadef_object_repo(
                req.context, authorization_layer=False)

            db_metaobject_list = object_repo.list(marker=marker,
                                                  limit=limit,
                                                  sort_key=sort_key,
                                                  sort_dir=sort_dir,
                                                  filters=filters)

            object_list = [
                MetadefObject.to_wsme_model(obj,
                                            get_object_href(namespace, obj),
                                            self.obj_schema_link)
                for obj in db_metaobject_list if api_policy.MetadefAPIPolicy(
                    req.context,
                    md_resource=obj.namespace,
                    enforcer=self.policy).check('get_metadef_object')
            ]

            metadef_objects = MetadefObjects()
            metadef_objects.objects = object_list
        except exception.Forbidden as e:
            LOG.debug(
                "User not permitted to retrieve metadata objects within "
                "'%s' namespace", namespace)
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        return metadef_objects