def __call__(self, req): arg_dict = req.environ['wsgiorg.routing_args'][1] action = arg_dict.pop('action') del arg_dict['controller'] LOG.debug(_('arg_dict: %s'), arg_dict) # allow middleware up the stack to provide context & params context = req.environ.get(CONTEXT_ENV, {}) context['query_string'] = dict(req.params.iteritems()) context['path'] = req.environ['PATH_INFO'] params = req.environ.get(PARAMS_ENV, {}) if 'REMOTE_USER' in req.environ: context['REMOTE_USER'] = req.environ['REMOTE_USER'] elif context.get('REMOTE_USER', None) is not None: del context['REMOTE_USER'] params.update(arg_dict) # TODO(termie): do some basic normalization on methods method = getattr(self, action) # NOTE(vish): make sure we have no unicode keys for py2.6. params = self._normalize_dict(params) try: result = method(context, **params) except exception.Unauthorized as e: LOG.warning(_("Authorization failed. %s from %s") % (e, req.environ['REMOTE_ADDR'])) return render_exception(e) except exception.Error as e: LOG.warning(e) return render_exception(e) except TypeError as e: logging.exception(e) return render_exception(exception.ValidationError(e)) except Exception as e: logging.exception(e) return render_exception(exception.UnexpectedError(exception=e)) if result is None: return render_response(status=(204, 'No Content')) elif isinstance(result, basestring): return result elif isinstance(result, webob.Response): return result elif isinstance(result, webob.exc.WSGIHTTPException): return result response_code = self._get_response_code(req) return render_response(body=result, status=response_code)
def __call__(self, req): arg_dict = req.environ["wsgiorg.routing_args"][1] action = arg_dict.pop("action") del arg_dict["controller"] LOG.debug("arg_dict: %s", arg_dict) # allow middleware up the stack to provide context & params context = req.environ.get(CONTEXT_ENV, {}) context["query_string"] = dict(req.params.iteritems()) params = req.environ.get(PARAMS_ENV, {}) if "REMOTE_USER" in req.environ: context["REMOTE_USER"] = req.environ["REMOTE_USER"] elif context.get("REMOTE_USER", None) is not None: del context["REMOTE_USER"] params.update(arg_dict) # TODO(termie): do some basic normalization on methods method = getattr(self, action) # NOTE(vish): make sure we have no unicode keys for py2.6. params = self._normalize_dict(params) try: result = method(context, **params) except exception.Unauthorized as e: LOG.warning("Authorization failed. %s from %s" % (e, req.environ["REMOTE_ADDR"])) return render_exception(e) except exception.Error as e: LOG.warning(e) return render_exception(e) except Exception as e: logging.exception(e) return render_exception(exception.UnexpectedError(exception=e)) if result is None: return render_response(status=(204, "No Content")) elif isinstance(result, basestring): return result elif isinstance(result, webob.Response): return result elif isinstance(result, webob.exc.WSGIHTTPException): return result return render_response(body=result)
def __call__(self, req): arg_dict = req.environ['wsgiorg.routing_args'][1] action = arg_dict.pop('action') del arg_dict['controller'] LOG.debug('arg_dict: %s', arg_dict) # allow middleware up the stack to provide context & params context = req.environ.get('openstack.context', {}) context['query_string'] = dict(req.params.iteritems()) params = req.environ.get('openstack.params', {}) params.update(arg_dict) # TODO(termie): do some basic normalization on methods method = getattr(self, action) # NOTE(vish): make sure we have no unicode keys for py2.6. params = self._normalize_dict(params) try: result = method(context, **params) except exception.Error as e: LOG.warning(e) return render_exception(e) except Exception as e: logging.exception(e) return render_exception(exception.UnexpectedError(exception=e)) if result is None: return render_response(status=(204, 'No Content')) elif isinstance(result, basestring): return result elif isinstance(result, webob.Response): return result elif isinstance(result, webob.exc.WSGIHTTPException): return result return render_response(body=result)