def show(self, req, namespace): try: filters = {'namespace': namespace} rs_type_repo = self.gateway.get_metadef_resource_type_repo( req.context) db_resource_type_list = rs_type_repo.list(filters=filters) resource_type_list = [ResourceTypeAssociation.to_wsme_model( resource_type) for resource_type in db_resource_type_list] resource_types = ResourceTypeAssociations() resource_types.resource_type_associations = resource_type_list 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(e) raise webob.exc.HTTPInternalServerError(e) return resource_types
def show(self, req, namespace): 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): Here we are just checking if user is # authorized to view/list metadef resource types or not. # Each resource_type is checked against # get_metadef_resource_type below. api_policy.MetadefAPIPolicy( req.context, md_resource=namespace_obj, enforcer=self.policy).list_metadef_resource_types() filters = {'namespace': namespace} rs_type_repo = self.gateway.get_metadef_resource_type_repo( req.context, authorization_layer=False) db_type_list = rs_type_repo.list(filters=filters) rs_type_list = [ ResourceTypeAssociation.to_wsme_model(rs_type) for rs_type in db_type_list if api_policy.MetadefAPIPolicy( req.context, md_resource=rs_type.namespace, enforcer=self.policy).check('get_metadef_resource_type') ] resource_types = ResourceTypeAssociations() resource_types.resource_type_associations = rs_type_list except exception.Forbidden as e: LOG.debug( "User not permitted to retrieve metadata resource types " "within '%s' namespace", namespace) raise webob.exc.HTTPForbidden(explanation=e.msg) except exception.NotFound as e: raise webob.exc.HTTPNotFound(explanation=e.msg) return resource_types
def show(self, req, namespace): try: filters = {"namespace": namespace} rs_type_repo = self.gateway.get_metadef_resource_type_repo(req.context) db_resource_type_list = rs_type_repo.list(filters=filters) resource_type_list = [ ResourceTypeAssociation.to_wsme_model(resource_type) for resource_type in db_resource_type_list ] resource_types = ResourceTypeAssociations() resource_types.resource_type_associations = resource_type_list except exception.Forbidden as e: LOG.debug("User not permitted to retrieve metadata resource types " "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(e) return resource_types
def show(self, req, namespace): try: filters = {'namespace': namespace} rs_type_repo = self.gateway.get_metadef_resource_type_repo( req.context) db_resource_type_list = rs_type_repo.list(filters=filters) resource_type_list = [ResourceTypeAssociation.to_wsme_model( resource_type) for resource_type in db_resource_type_list] resource_types = ResourceTypeAssociations() resource_types.resource_type_associations = resource_type_list except exception.Forbidden as e: LOG.debug("User not permitted to retrieve metadata resource types " "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(e) return resource_types