summaryrefslogtreecommitdiff
path: root/keystone/common/wsgi.py
diff options
context:
space:
mode:
authorJamie Lennox <jamielennox@gmail.com>2015-12-10 17:04:33 +1100
committerJamie Lennox <jamielennox@gmail.com>2016-04-06 15:49:22 +1000
commitbe558717ed29dfe01664f68d6de42f73d3afe8ab (patch)
tree415639b61684cc82392124f1b62a4b4832764ec6 /keystone/common/wsgi.py
parentdabf76f2cffc4c361f17d904cf0235dc68376d20 (diff)
downloadkeystone-be558717ed29dfe01664f68d6de42f73d3afe8ab.tar.gz
Make AuthContext depend on auth_token middleware
Reuse the validation logic that is already present in auth_token middleware. Once this is present keystone can start to reuse the same helpers that are created from auth_token middleware that the other services rely on. For now there is still some redundancy, like for example bind checking is now enforced in auth_token middleware and in keystone. These can be removed in later commits because they will require test changes. My intention after this is to start to more directly integrate this with oslo.policy and start to standardize the way auth is handled from auth_token middleware to enforcement. Doing this work here means that we get keystone to try out policy changes first. Change-Id: I6592ea2865863c9ace1304b06d73a917c3a1b114
Diffstat (limited to 'keystone/common/wsgi.py')
-rw-r--r--keystone/common/wsgi.py51
1 files changed, 31 insertions, 20 deletions
diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py
index 04528a0c0..53cb5631e 100644
--- a/keystone/common/wsgi.py
+++ b/keystone/common/wsgi.py
@@ -19,6 +19,7 @@
"""Utility methods for working with WSGI servers."""
import copy
+import functools
import itertools
import re
import wsgiref.util
@@ -393,6 +394,30 @@ class Application(BaseApplication):
return url.rstrip('/')
+def middleware_exceptions(method):
+
+ @functools.wraps(method)
+ def _inner(self, request):
+ try:
+ return method(self, request)
+ except exception.Error as e:
+ LOG.warning(six.text_type(e))
+ return render_exception(e, request=request,
+ user_locale=best_match_language(request))
+ except TypeError as e:
+ LOG.exception(six.text_type(e))
+ return render_exception(exception.ValidationError(e),
+ request=request,
+ user_locale=best_match_language(request))
+ except Exception as e:
+ LOG.exception(six.text_type(e))
+ return render_exception(exception.UnexpectedError(exception=e),
+ request=request,
+ user_locale=best_match_language(request))
+
+ return _inner
+
+
class Middleware(Application):
"""Base WSGI middleware.
@@ -429,27 +454,13 @@ class Middleware(Application):
return response
@webob.dec.wsgify()
+ @middleware_exceptions
def __call__(self, request):
- try:
- response = self.process_request(request)
- if response:
- return response
- response = request.get_response(self.application)
- return self.process_response(request, response)
- except exception.Error as e:
- LOG.warning(six.text_type(e))
- return render_exception(e, request=request,
- user_locale=best_match_language(request))
- except TypeError as e:
- LOG.exception(six.text_type(e))
- return render_exception(exception.ValidationError(e),
- request=request,
- user_locale=best_match_language(request))
- except Exception as e:
- LOG.exception(six.text_type(e))
- return render_exception(exception.UnexpectedError(exception=e),
- request=request,
- user_locale=best_match_language(request))
+ response = self.process_request(request)
+ if response:
+ return response
+ response = request.get_response(self.application)
+ return self.process_response(request, response)
class Debug(Middleware):