示例#1
0
    def update(self, req, metadata_tag, namespace, tag_name):
        meta_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            metadef_tag = meta_repo.get(namespace, tag_name)
            metadef_tag._old_name = metadef_tag.name
            metadef_tag.name = wsme_utils._get_value(
                metadata_tag.name)
            updated_metadata_tag = meta_repo.save(metadef_tag)
        except exception.Invalid as e:
            msg = (_("Couldn't update metadata tag: %s")
                   % encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.Forbidden as e:
            LOG.debug("User not permitted to update metadata tag '%s' "
                      "within '%s' namespace", tag_name, namespace)
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(updated_metadata_tag)
示例#2
0
    def create(self, req, namespace, tag_name):
        tag_factory = self.gateway.get_metadef_tag_factory(req.context)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context)
        tag_name_as_dict = {'name': tag_name}
        try:
            new_meta_tag = tag_factory.new_tag(
                namespace=namespace,
                **tag_name_as_dict)
            tag_repo.add(new_meta_tag)
        except exception.Invalid as e:
            msg = (_("Couldn't create metadata tag: %s")
                   % encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.Forbidden as e:
            LOG.debug("User not permitted to create metadata tag 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.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(new_meta_tag)
示例#3
0
    def create(self, req, namespace, tag_name):
        tag_factory = self.gateway.get_metadef_tag_factory(req.context)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context)
        tag_name_as_dict = {'name': tag_name}
        try:
            self.schema.validate(tag_name_as_dict)
        except exception.InvalidObject as e:
            raise webob.exc.HTTPBadRequest(explanation=e.msg)
        try:
            new_meta_tag = tag_factory.new_tag(
                namespace=namespace,
                **tag_name_as_dict)
            tag_repo.add(new_meta_tag)
        except exception.Invalid as e:
            msg = (_("Couldn't create metadata tag: %s")
                   % encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.Forbidden as e:
            LOG.debug("User not permitted to create metadata tag 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.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(new_meta_tag)
示例#4
0
    def show(self, req, namespace, tag_name):
        meta_tag_repo = self.gateway.get_metadef_tag_repo(
            req.context, authorization_layer=False)
        ns_repo = self.gateway.get_metadef_namespace_repo(
            req.context, authorization_layer=False)
        try:
            namespace_obj = ns_repo.get(namespace)
        except (exception.Forbidden, exception.NotFound):
            # NOTE (abhishekk): Returning 404 Not Found as the
            # namespace is outside of this user's project
            msg = _("Namespace %s not found") % namespace
            raise webob.exc.HTTPNotFound(explanation=msg)

        try:
            # NOTE(abhishekk): Metadef tags are associated with
            # namespace, so made provision to pass namespace here
            # for visibility check
            api_policy.MetadefAPIPolicy(
                req.context, md_resource=namespace_obj,
                enforcer=self.policy).get_metadef_tag()

            metadef_tag = meta_tag_repo.get(namespace, tag_name)
            return MetadefTag.to_wsme_model(metadef_tag)
        except exception.Forbidden as e:
            LOG.debug(
                "User not permitted to show metadata tag '%s' "
                "within '%s' namespace", tag_name, namespace)
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
示例#5
0
    def update(self, req, metadata_tag, namespace, tag_name):
        meta_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            metadef_tag = meta_repo.get(namespace, tag_name)
            metadef_tag._old_name = metadef_tag.name
            metadef_tag.name = wsme_utils._get_value(
                metadata_tag.name)
            updated_metadata_tag = meta_repo.save(metadef_tag)
        except exception.Invalid as e:
            msg = (_("Couldn't update metadata tag: %s")
                   % encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.Forbidden as e:
            LOG.debug("User not permitted to update metadata tag '%s' "
                      "within '%s' namespace", tag_name, namespace)
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(updated_metadata_tag)
示例#6
0
 def show(self, req, namespace, tag_name):
     meta_tag_repo = self.gateway.get_metadef_tag_repo(req.context)
     try:
         metadef_tag = meta_tag_repo.get(namespace, tag_name)
         return MetadefTag.to_wsme_model(metadef_tag)
     except exception.Forbidden as e:
         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(utils.exception_to_str(e))
         raise webob.exc.HTTPInternalServerError()
示例#7
0
 def show(self, req, namespace, tag_name):
     meta_tag_repo = self.gateway.get_metadef_tag_repo(req.context)
     try:
         metadef_tag = meta_tag_repo.get(namespace, tag_name)
         return MetadefTag.to_wsme_model(metadef_tag)
     except exception.Forbidden as e:
         LOG.debug("User not permitted to show metadata tag '%s' "
                   "within '%s' namespace", tag_name, 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()
示例#8
0
 def show(self, req, namespace, tag_name):
     meta_tag_repo = self.gateway.get_metadef_tag_repo(req.context)
     try:
         metadef_tag = meta_tag_repo.get(namespace, tag_name)
         return MetadefTag.to_wsme_model(metadef_tag)
     except exception.Forbidden as e:
         LOG.debug("User not permitted to show metadata tag '%s' "
                   "within '%s' namespace", tag_name, 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()
示例#9
0
    def update(self, req, metadata_tag, namespace, tag_name):
        meta_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            metadef_tag = meta_repo.get(namespace, tag_name)
            metadef_tag.name = wsme_utils._get_value(metadata_tag.name)
            updated_metadata_tag = meta_repo.save(metadef_tag)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(utils.exception_to_str(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(updated_metadata_tag)
示例#10
0
    def create(self, req, namespace, tag_name):
        tag_factory = self.gateway.get_metadef_tag_factory(
            req.context, authorization_layer=False)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context,
                                                     authorization_layer=False)
        ns_repo = self.gateway.get_metadef_namespace_repo(
            req.context, authorization_layer=False)
        try:
            namespace_obj = ns_repo.get(namespace)
        except (exception.Forbidden, exception.NotFound):
            # NOTE (abhishekk): Returning 404 Not Found as the
            # namespace is outside of this user's project
            msg = _("Namespace %s not found") % namespace
            raise webob.exc.HTTPNotFound(explanation=msg)

        tag_name_as_dict = {'name': tag_name}
        try:
            self.schema.validate(tag_name_as_dict)
        except exception.InvalidObject as e:
            raise webob.exc.HTTPBadRequest(explanation=e.msg)
        try:
            # NOTE(abhishekk): Metadef tags is created for Metadef namespaces
            # Here we are just checking if user is authorized to create metadef
            # tag or not.
            api_policy.MetadefAPIPolicy(
                req.context, md_resource=namespace_obj,
                enforcer=self.policy).add_metadef_tag()

            new_meta_tag = tag_factory.new_tag(namespace=namespace,
                                               **tag_name_as_dict)
            tag_repo.add(new_meta_tag)
        except exception.Invalid as e:
            msg = (_("Couldn't create metadata tag: %s") %
                   encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.Forbidden as e:
            LOG.debug(
                "User not permitted to create metadata tag 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.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)

        return MetadefTag.to_wsme_model(new_meta_tag)
示例#11
0
    def create(self, req, metadata_tag, namespace):
        tag_factory = self.gateway.get_metadef_tag_factory(req.context)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            new_meta_tag = tag_factory.new_tag(namespace=namespace,
                                               **metadata_tag.to_dict())
            tag_repo.add(new_meta_tag)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(utils.exception_to_str(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(new_meta_tag)
示例#12
0
    def update(self, req, metadata_tag, namespace, tag_name):
        meta_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            metadef_tag = meta_repo.get(namespace, tag_name)
            metadef_tag.name = wsme_utils._get_value(
                metadata_tag.name)
            updated_metadata_tag = meta_repo.save(metadef_tag)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(utils.exception_to_str(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(updated_metadata_tag)
示例#13
0
    def create(self, req, namespace, tag_name):
        tag_factory = self.gateway.get_metadef_tag_factory(req.context)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context)
        tag_name_as_dict = {"name": tag_name}
        try:
            new_meta_tag = tag_factory.new_tag(namespace=namespace, **tag_name_as_dict)
            tag_repo.add(new_meta_tag)
        except exception.Forbidden as e:
            LOG.debug("User not permitted to create metadata tag 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.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(utils.exception_to_str(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(new_meta_tag)
示例#14
0
    def create(self, req, metadata_tag, namespace):
        tag_factory = self.gateway.get_metadef_tag_factory(req.context)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            new_meta_tag = tag_factory.new_tag(
                namespace=namespace,
                **metadata_tag.to_dict())
            tag_repo.add(new_meta_tag)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)
        except Exception as e:
            LOG.error(utils.exception_to_str(e))
            raise webob.exc.HTTPInternalServerError()

        return MetadefTag.to_wsme_model(new_meta_tag)
示例#15
0
    def update(self, req, metadata_tag, namespace, tag_name):
        meta_repo = self.gateway.get_metadef_tag_repo(
            req.context, authorization_layer=False)
        ns_repo = self.gateway.get_metadef_namespace_repo(
            req.context, authorization_layer=False)
        try:
            namespace_obj = ns_repo.get(namespace)
        except (exception.Forbidden, exception.NotFound):
            # NOTE (abhishekk): Returning 404 Not Found as the
            # namespace is outside of this user's project
            msg = _("Namespace %s not found") % namespace
            raise webob.exc.HTTPNotFound(explanation=msg)

        try:
            # NOTE(abhishekk): Metadef tags is created for Metadef namespaces
            # Here we are just checking if user is authorized to update metadef
            # tag or not.
            api_policy.MetadefAPIPolicy(
                req.context, md_resource=namespace_obj,
                enforcer=self.policy).modify_metadef_tag()

            metadef_tag = meta_repo.get(namespace, tag_name)
            metadef_tag._old_name = metadef_tag.name
            metadef_tag.name = wsme_utils._get_value(metadata_tag.name)
            updated_metadata_tag = meta_repo.save(metadef_tag)
        except exception.Invalid as e:
            msg = (_("Couldn't update metadata tag: %s") %
                   encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.Forbidden as e:
            LOG.debug(
                "User not permitted to update metadata tag '%s' "
                "within '%s' namespace", tag_name, namespace)
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except exception.Duplicate as e:
            raise webob.exc.HTTPConflict(explanation=e.msg)

        return MetadefTag.to_wsme_model(updated_metadata_tag)