How to use the webob.exc.HTTPNotFound function in WebOb

To help you get started, we’ve selected a few WebOb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / glance / glance / registry / api / v1 / members.py View on Github external
"can_share": [True|False]
            }}

        If "can_share" is provided, the member's ability to share is
        set accordingly.  If it is not provided, existing memberships
        remain unchanged and new memberships default to False.
        """
        self._check_can_access_image_members(req.context)

        # Make sure the image exists
        try:
            image = self.db_api.image_get(req.context, image_id)
        except exception.NotFound:
            msg = _("Image %(id)s not found") % {'id': image_id}
            LOG.warn(msg)
            raise webob.exc.HTTPNotFound(msg)
        except exception.Forbidden:
            # If it's private and doesn't belong to them, don't let on
            # that it exists
            msg = _LW("Access denied to image %(id)s but returning"
                      " 'not found'") % {'id': image_id}
            LOG.warn(msg)
            raise webob.exc.HTTPNotFound()

        # Can they manipulate the membership?
        if not self.is_image_sharable(req.context, image):
            msg = (_LW("User lacks permission to share image %(id)s") %
                   {'id': image_id})
            LOG.warn(msg)
            msg = _("No permission to share that image")
            raise webob.exc.HTTPForbidden(msg)
github tmetsch / occi-os / api / compute / computeresource.py View on Github external
def delete(self, entity, extras):
        """
        Deletes the referenced VM.
        """
        msg = _('Removing representation of virtual machine with id: %s') % \
                                                            entity.identifier
        LOG.info(msg)

        context = extras['nova_ctx']
        uid = entity.attributes['occi.core.id']

        try:
            instance = self.compute_api.get(context, uid)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        if FLAGS.reclaim_instance_interval:
            self.compute_api.soft_delete(context, instance)
        else:
            self.compute_api.delete(context, instance)
github openstack / cinder / cinder / api / openstack / wsgi.py View on Github external
def _process_stack(self, request, action, action_args,
                       content_type, body, accept):
        """Implement the processing stack."""

        # Get the implementing method
        try:
            meth, extensions = self.get_method(request, action,
                                               content_type, body)
        except (AttributeError, TypeError):
            return Fault(webob.exc.HTTPNotFound())
        except KeyError as ex:
            msg = (_("There is no such action: %s. Verify the request body "
                     "and Content-Type header and try again.") % ex.args[0])
            return Fault(webob.exc.HTTPBadRequest(explanation=msg))
        except exception.MalformedRequestBody:
            msg = _("Malformed request body")
            return Fault(webob.exc.HTTPBadRequest(explanation=msg))

        if body:
            decoded_body = encodeutils.safe_decode(body, errors='ignore')
            msg = ("Action: '%(action)s', calling method: %(meth)s, body: "
                   "%(body)s") % {'action': action,
                                  'body': decoded_body,
                                  'meth': meth.__name__}
            LOG.debug(strutils.mask_password(msg))
        else:
github openstack / nova / nova / api / openstack / compute / networks_associate.py View on Github external
def _disassociate_project_only(self, req, id, body):
        context = req.environ['nova.context']
        context.can(na_policies.BASE_POLICY_NAME)
        try:
            self.network_api.associate(context, id, project=None)
        except exception.NetworkNotFound:
            msg = _("Network not found")
            raise exc.HTTPNotFound(explanation=msg)
        except NotImplementedError:
            common.raise_feature_not_supported()
github openstack / manila / manila / api / v2 / share_replicas.py View on Github external
def _get_replicas(self, req, is_detail=False):
        """Returns list of replicas."""
        context = req.environ['manila.context']

        share_id = req.params.get('share_id')
        if share_id:
            try:
                replicas = db.share_replicas_get_all_by_share(
                    context, share_id)
            except exception.NotFound:
                msg = _("Share with share ID %s not found.") % share_id
                raise exc.HTTPNotFound(explanation=msg)
        else:
            replicas = db.share_replicas_get_all(context)

        limited_list = common.limited(replicas, req)
        if is_detail:
            replicas = self._view_builder.detail_list(req, limited_list)
        else:
            replicas = self._view_builder.summary_list(req, limited_list)

        return replicas
github openstack / nova / nova / api / openstack / compute / certificates.py View on Github external
def show(self, req, id):
        """Return certificate information."""
        context = req.environ['nova.context']
        context.can(cert_policies.POLICY_ROOT % 'show')
        if id != 'root':
            msg = _("Only root certificate can be retrieved.")
            # TODO(oomichi): This seems a HTTPBadRequest case because of the
            # above message. This will be changed with a microversion in the
            # future.
            common.raise_feature_not_supported(msg=msg)
        try:
            cert = self.cert_rpcapi.fetch_ca(context,
                                             project_id=context.project_id)
        except exception.CryptoCAFileNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        return {'certificate': _translate_certificate_view(cert)}
github obeattie / pylons / pylons / wsgiapp.py View on Github external
def dispatch(self, controller, environ, start_response):
        """Dispatches to a controller, will instantiate the controller
        if necessary.
        
        Override this to change how the controller dispatch is handled.
        
        """
        log_debug = self.log_debug
        if not controller:
            if log_debug:
                log.debug("No controller found, returning 404 HTTP Not Found")
            return HTTPNotFound()(environ, start_response)

        # If it's a class, instantiate it
        if hasattr(controller, '__bases__'):
            if log_debug:
                log.debug("Controller appears to be a class, instantiating")
            controller = controller()
            controller._pylons_log_debug = log_debug
        
        # Add a reference to the controller app located
        environ['pylons.controller'] = controller
        
        # Controller is assumed to handle a WSGI call
        if log_debug:
            log.debug("Calling controller class with WSGI interface")
        return controller(environ, start_response)
github ianb / seeitsaveit / seeit-services / seeitservices / mapper.py View on Github external
    @wsgify
    def __call__(self, req):
        for i, (prefix, match) in enumerate(self.matchers):
            if req.path_info == prefix and not req.path_info.endswith('/'):
                return Response(
                    status=301,
                    location=req.url + '/')
            if req.path_info.startswith(prefix + '/'):
                req.script_name += prefix
                req.path_info = req.path_info[len(prefix):]
                return match
            if prefix == '/':
                return match
        return exc.HTTPNotFound('No route')
github openstack / nova / nova / api / openstack / compute / server_groups.py View on Github external
def show(self, req, id):
        """Return data about the given server group."""
        context = _authorize_context(req, 'show')
        try:
            sg = objects.InstanceGroup.get_by_uuid(context, id)
        except nova.exception.InstanceGroupNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        return {'server_group': self._format_server_group(context, sg, req)}
github openstack / manila / manila / api / v1 / share_manage.py View on Github external
if parameter not in data:
                msg = _("Required parameter %s not found") % parameter
                raise exc.HTTPUnprocessableEntity(explanation=msg)
            if not data.get(parameter):
                msg = _("Required parameter %s is empty") % parameter
                raise exc.HTTPUnprocessableEntity(explanation=msg)

        if not share_utils.extract_host(data['service_host'], 'pool'):
            msg = _("service_host parameter should contain pool.")
            raise exc.HTTPBadRequest(explanation=msg)

        try:
            utils.validate_service_host(
                context, share_utils.extract_host(data['service_host']))
        except exception.ServiceNotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))
        except exception.PolicyNotAuthorized as e:
            raise exc.HTTPForbidden(explanation=six.text_type(e))
        except exception.AdminRequired as e:
            raise exc.HTTPForbidden(explanation=six.text_type(e))
        except exception.ServiceIsDown as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e))

        data['share_type_id'] = self._get_share_type_id(
            context, data.get('share_type'))

        return data