Example #1
0
    def create_tags(self, req, metadata_tags, namespace):
        tag_factory = self.gateway.get_metadef_tag_factory(req.context)
        tag_repo = self.gateway.get_metadef_tag_repo(req.context)
        try:
            tag_list = []
            for metadata_tag in metadata_tags.tags:
                tag_list.append(tag_factory.new_tag(
                    namespace=namespace, **metadata_tag.to_dict()))
            tag_repo.add_tags(tag_list)
            tag_list_out = [MetadefTag(**{'name': db_metatag.name})
                            for db_metatag in tag_list]
            metadef_tags = MetadefTags()
            metadef_tags.tags = tag_list_out
        except exception.Forbidden as e:
            LOG.debug("User not permitted to create metadata tags 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 metadef_tags
Example #2
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

            tag_repo = self.gateway.get_metadef_tag_repo(req.context)
            if marker:
                metadef_tag = tag_repo.get(namespace, marker)
                marker = metadef_tag.tag_id

            db_metatag_list = tag_repo.list(
                marker=marker, limit=limit, sort_key=sort_key,
                sort_dir=sort_dir, filters=filters)

            tag_list = [MetadefTag(**{'name': db_metatag.name})
                        for db_metatag in db_metatag_list]

            metadef_tags = MetadefTags()
            metadef_tags.tags = tag_list
        except exception.Forbidden as e:
            LOG.debug("User not permitted to retrieve metadata tags "
                      "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(utils.exception_to_str(e))
            raise webob.exc.HTTPInternalServerError()

        return metadef_tags
Example #3
0
    def index(self,
              req,
              namespace,
              marker=None,
              limit=None,
              sort_key='created_at',
              sort_dir='desc',
              filters=None):
        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): This is just a "do you have permission to
            # list tags" check. Each object is checked against
            # get_metadef_tag below.
            api_policy.MetadefAPIPolicy(
                req.context, md_resource=namespace_obj,
                enforcer=self.policy).get_metadef_tags()

            filters = filters or dict()
            filters['namespace'] = namespace

            tag_repo = self.gateway.get_metadef_tag_repo(
                req.context, authorization_layer=False)
            if marker:
                metadef_tag = tag_repo.get(namespace, marker)
                marker = metadef_tag.tag_id

            db_metatag_list = tag_repo.list(marker=marker,
                                            limit=limit,
                                            sort_key=sort_key,
                                            sort_dir=sort_dir,
                                            filters=filters)

            tag_list = [
                MetadefTag(**{'name': db_metatag.name})
                for db_metatag in db_metatag_list
            ]

            metadef_tags = MetadefTags()
            metadef_tags.tags = tag_list
        except exception.Forbidden as e:
            LOG.debug(
                "User not permitted to retrieve metadata tags "
                "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_tags
Example #4
0
    def create_tags(self, req, metadata_tags, namespace):
        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)

        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_tags()

            tag_list = []
            for metadata_tag in metadata_tags.tags:
                tag_list.append(
                    tag_factory.new_tag(namespace=namespace,
                                        **metadata_tag.to_dict()))
            tag_repo.add_tags(tag_list)
            tag_list_out = [
                MetadefTag(**{'name': db_metatag.name})
                for db_metatag in tag_list
            ]
            metadef_tags = MetadefTags()
            metadef_tags.tags = tag_list_out
        except exception.Forbidden as e:
            LOG.debug(
                "User not permitted to create metadata tags 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 metadef_tags