예제 #1
0
 def __call__(self, environ, start_response):
     # All requests but '/' require admin.
     if environ['PATH_INFO'] != '/':
         context = environ['placement.context']
         # TODO(cdent): Using is_admin everywhere (except /) is
         # insufficiently flexible for future use case but is
         # convenient for initial exploration.
         if not policy.placement_authorize(context, 'placement'):
             raise webob.exc.HTTPForbidden(
                 _('admin required'),
                 json_formatter=util.json_error_formatter)
     # Check that an incoming request with a content-length
     # header also has a content-type header. If not raise a 400.
     if int(environ.get('CONTENT_LENGTH', 0)):
         if 'CONTENT_TYPE' not in environ:
             raise webob.exc.HTTPBadRequest(
                 _('content-type header required'),
                 json_formatter=util.json_error_formatter)
     try:
         return dispatch(environ, start_response, self._map)
     # Trap the NotFound exceptions raised by the objects used
     # with the API and transform them into webob.exc.HTTPNotFound.
     except exception.NotFound as exc:
         raise webob.exc.HTTPNotFound(
             exc, json_formatter=util.json_error_formatter)
     # Trap the HTTPNotFound that can be raised by dispatch()
     # when no route is found. The exception is passed through to
     # the FaultWrap middleware without causing an alarming log
     # message.
     except webob.exc.HTTPNotFound:
         raise
     except Exception as exc:
         LOG.exception("Uncaught exception")
         raise
예제 #2
0
파일: handler.py 프로젝트: zhchwolf/nova
 def __call__(self, environ, start_response):
     # All requests but '/' require admin.
     if environ['PATH_INFO'] != '/':
         context = environ['placement.context']
         # TODO(cdent): Using is_admin everywhere (except /) is
         # insufficiently flexible for future use case but is
         # convenient for initial exploration.
         if not policy.placement_authorize(context, 'placement'):
             raise webob.exc.HTTPForbidden(
                 _('admin required'),
                 json_formatter=util.json_error_formatter)
     # Check that an incoming request with a content-length header
     # that is an integer > 0 and not empty, also has a content-type
     # header that is not empty. If not raise a 400.
     clen = environ.get('CONTENT_LENGTH')
     try:
         if clen and (int(clen) > 0) and not environ.get('CONTENT_TYPE'):
             raise webob.exc.HTTPBadRequest(
                 _('content-type header required when content-length > 0'),
                 json_formatter=util.json_error_formatter)
     except ValueError as exc:
         raise webob.exc.HTTPBadRequest(
             _('content-length header must be an integer'),
             json_formatter=util.json_error_formatter)
     try:
         return dispatch(environ, start_response, self._map)
     # Trap the NotFound exceptions raised by the objects used
     # with the API and transform them into webob.exc.HTTPNotFound.
     except exception.NotFound as exc:
         raise webob.exc.HTTPNotFound(
             exc, json_formatter=util.json_error_formatter)
예제 #3
0
파일: handler.py 프로젝트: amadev/nova
 def __call__(self, environ, start_response):
     # All requests but '/' require admin.
     if environ['PATH_INFO'] != '/':
         context = environ['placement.context']
         # TODO(cdent): Using is_admin everywhere (except /) is
         # insufficiently flexible for future use case but is
         # convenient for initial exploration.
         if not policy.placement_authorize(context, 'placement'):
             raise webob.exc.HTTPForbidden(
                 _('admin required'),
                 json_formatter=util.json_error_formatter)
     # Check that an incoming write-oriented request method has
     # the required content-type header. If not raise a 400. If
     # this doesn't happen here then webob.dec.wsgify (elsewhere
     # in the stack) will raise an uncaught KeyError. Since that
     # is such a generic exception we cannot merely catch it
     # here, we need to avoid it ever happening.
     # TODO(cdent): Move this and the auth checking above into
     # middleware. It shouldn't be here. This is for dispatch not
     # validation or authorization.
     request_method = environ['REQUEST_METHOD'].upper()
     if request_method in ('POST', 'PUT', 'PATCH'):
         if 'CONTENT_TYPE' not in environ:
             raise webob.exc.HTTPBadRequest(
                 _('content-type header required'),
                 json_formatter=util.json_error_formatter)
     try:
         return dispatch(environ, start_response, self._map)
     # Trap the NotFound exceptions raised by the objects used
     # with the API and transform them into webob.exc.HTTPNotFound.
     except exception.NotFound as exc:
         raise webob.exc.HTTPNotFound(
             exc, json_formatter=util.json_error_formatter)
     # Trap the HTTPNotFound that can be raised by dispatch()
     # when no route is found. The exception is passed through to
     # the FaultWrap middleware without causing an alarming log
     # message.
     except webob.exc.HTTPNotFound:
         raise
     except Exception as exc:
         LOG.exception(_LE("Uncaught exception"))
         raise
예제 #4
0
 def __call__(self, environ, start_response):
     # All requests but '/' require admin.
     if environ['PATH_INFO'] != '/':
         context = environ['placement.context']
         # TODO(cdent): Using is_admin everywhere (except /) is
         # insufficiently flexible for future use case but is
         # convenient for initial exploration.
         if not policy.placement_authorize(context, 'placement'):
             raise webob.exc.HTTPForbidden(
                 _('admin required'),
                 json_formatter=util.json_error_formatter)
     # Check that an incoming write-oriented request method has
     # the required content-type header. If not raise a 400. If
     # this doesn't happen here then webob.dec.wsgify (elsewhere
     # in the stack) will raise an uncaught KeyError. Since that
     # is such a generic exception we cannot merely catch it
     # here, we need to avoid it ever happening.
     # TODO(cdent): Move this and the auth checking above into
     # middleware. It shouldn't be here. This is for dispatch not
     # validation or authorization.
     request_method = environ['REQUEST_METHOD'].upper()
     if request_method in ('POST', 'PUT', 'PATCH'):
         if 'CONTENT_TYPE' not in environ:
             raise webob.exc.HTTPBadRequest(
                 _('content-type header required'),
                 json_formatter=util.json_error_formatter)
     try:
         return dispatch(environ, start_response, self._map)
     # Trap the NotFound exceptions raised by the objects used
     # with the API and transform them into webob.exc.HTTPNotFound.
     except exception.NotFound as exc:
         raise webob.exc.HTTPNotFound(
             exc, json_formatter=util.json_error_formatter)
     # Trap the HTTPNotFound that can be raised by dispatch()
     # when no route is found. The exception is passed through to
     # the FaultWrap middleware without causing an alarming log
     # message.
     except webob.exc.HTTPNotFound:
         raise
     except Exception as exc:
         LOG.exception(_LE("Uncaught exception"))
         raise
예제 #5
0
파일: handler.py 프로젝트: sapcc/nova
 def __call__(self, environ, start_response):
     # All requests but '/' require admin.
     if environ['PATH_INFO'] != '/':
         context = environ['placement.context']
         # TODO(cdent): Using is_admin everywhere (except /) is
         # insufficiently flexible for future use case but is
         # convenient for initial exploration.
         if not policy.placement_authorize(context, 'placement'):
             raise webob.exc.HTTPForbidden(
                 _('admin required'),
                 json_formatter=util.json_error_formatter)
     # Check that an incoming request with a content-length header
     # that is an integer > 0 and not empty, also has a content-type
     # header that is not empty. If not raise a 400.
     clen = environ.get('CONTENT_LENGTH')
     try:
         if clen and (int(clen) > 0) and not environ.get('CONTENT_TYPE'):
             raise webob.exc.HTTPBadRequest(
                _('content-type header required when content-length > 0'),
                json_formatter=util.json_error_formatter)
     except ValueError as exc:
         raise webob.exc.HTTPBadRequest(
             _('content-length header must be an integer'),
             json_formatter=util.json_error_formatter)
     try:
         return dispatch(environ, start_response, self._map)
     # Trap the NotFound exceptions raised by the objects used
     # with the API and transform them into webob.exc.HTTPNotFound.
     except exception.NotFound as exc:
         raise webob.exc.HTTPNotFound(
             exc, json_formatter=util.json_error_formatter)
     # Trap the HTTPNotFound that can be raised by dispatch()
     # when no route is found. The exception is passed through to
     # the FaultWrap middleware without causing an alarming log
     # message.
     except webob.exc.HTTPNotFound:
         raise
     except Exception as exc:
         LOG.exception("Uncaught exception")
         raise