From 55e1af6a1c0b34acc9dfdc73cbdd58efc09d3b3f Mon Sep 17 00:00:00 2001 From: Dolph Mathews Date: Thu, 7 Jul 2011 14:53:34 -0500 Subject: Moved exthandler to keystone.middleware --- etc/keystone.conf | 2 +- keystone/middleware/exthandler.py | 58 +++++++++++++++++++++++++++++++++++ keystone/queryext/__init__.py | 0 keystone/queryext/exthandler.py | 58 ----------------------------------- keystone/test/unit/test_exthandler.py | 2 +- setup.py | 2 +- 6 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 keystone/middleware/exthandler.py delete mode 100644 keystone/queryext/__init__.py delete mode 100644 keystone/queryext/exthandler.py diff --git a/etc/keystone.conf b/etc/keystone.conf index f93e3b58..425b41ee 100755 --- a/etc/keystone.conf +++ b/etc/keystone.conf @@ -80,7 +80,7 @@ paste.app_factory = keystone.server:app_factory paste.app_factory = keystone.server:admin_app_factory [filter:exthandler] -paste.filter_factory = keystone.queryext.exthandler:filter_factory +paste.filter_factory = keystone.middleware.exthandler:filter_factory [filter:legacy_auth] paste.filter_factory = keystone.frontends.legacy_token_auth:filter_factory diff --git a/keystone/middleware/exthandler.py b/keystone/middleware/exthandler.py new file mode 100644 index 00000000..e0fae135 --- /dev/null +++ b/keystone/middleware/exthandler.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright (c) 2010 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +""" +Auth Middleware that accepts URL query extension. + +This module can be installed as a filter in front of your service to +detect extension in the resource URI (e.g., foo/resource.xml) to +specify HTTP response body type. If an extension is specified, it +overwrites the Accept header in the request, if present. + +""" + +CONTENT_TYPES = {'json': 'application/json', 'xml': 'application/xml'} +DEFAULT_CONTENT_TYPE = CONTENT_TYPES['json'] + +class UrlExtensionFilter(object): + + def __init__(self, app, conf): + # app is the next app in WSGI chain - eventually the OpenStack service + self.app = app + self.conf = conf + + def __call__(self, env, start_response): + uri = env['PATH_INFO'] + (path, ext) = uri.rsplit('.', 1) + if ext in CONTENT_TYPES: + env['HTTP_ACCEPT'] = CONTENT_TYPES[ext] + env['PATH_INFO'] = path + elif 'HTTP_ACCEPT' not in env: + env['HTTP_ACCEPT'] = DEFAULT_CONTENT_TYPE + + return self.app(env, start_response) + +def filter_factory(global_conf, **local_conf): + """Returns a WSGI filter app for use with paste.deploy.""" + conf = global_conf.copy() + conf.update(local_conf) + + def ext_filter(app): + return UrlExtensionFilter(app, conf) + return ext_filter diff --git a/keystone/queryext/__init__.py b/keystone/queryext/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/keystone/queryext/exthandler.py b/keystone/queryext/exthandler.py deleted file mode 100644 index e0fae135..00000000 --- a/keystone/queryext/exthandler.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# vim: tabstop=4 shiftwidth=4 softtabstop=4 -# -# Copyright (c) 2010 OpenStack, LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -""" -Auth Middleware that accepts URL query extension. - -This module can be installed as a filter in front of your service to -detect extension in the resource URI (e.g., foo/resource.xml) to -specify HTTP response body type. If an extension is specified, it -overwrites the Accept header in the request, if present. - -""" - -CONTENT_TYPES = {'json': 'application/json', 'xml': 'application/xml'} -DEFAULT_CONTENT_TYPE = CONTENT_TYPES['json'] - -class UrlExtensionFilter(object): - - def __init__(self, app, conf): - # app is the next app in WSGI chain - eventually the OpenStack service - self.app = app - self.conf = conf - - def __call__(self, env, start_response): - uri = env['PATH_INFO'] - (path, ext) = uri.rsplit('.', 1) - if ext in CONTENT_TYPES: - env['HTTP_ACCEPT'] = CONTENT_TYPES[ext] - env['PATH_INFO'] = path - elif 'HTTP_ACCEPT' not in env: - env['HTTP_ACCEPT'] = DEFAULT_CONTENT_TYPE - - return self.app(env, start_response) - -def filter_factory(global_conf, **local_conf): - """Returns a WSGI filter app for use with paste.deploy.""" - conf = global_conf.copy() - conf.update(local_conf) - - def ext_filter(app): - return UrlExtensionFilter(app, conf) - return ext_filter diff --git a/keystone/test/unit/test_exthandler.py b/keystone/test/unit/test_exthandler.py index 1e881a54..76614ab6 100644 --- a/keystone/test/unit/test_exthandler.py +++ b/keystone/test/unit/test_exthandler.py @@ -19,7 +19,7 @@ import sys # Need to access identity module sys.path.append(os.path.abspath(os.path.join( os.getcwd(), '..', '..', 'keystone'))) -from keystone.queryext.exthandler import UrlExtensionFilter +from keystone.middleware.exthandler import UrlExtensionFilter import unittest diff --git a/setup.py b/setup.py index 6ed7a418..6e7276a4 100755 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ setup( entry_points={ 'paste.app_factory': ['main=identity:app_factory'], 'paste.filter_factory': [ - 'extfilter=keystone.queryext.exthandler:filter_factory', + 'extfilter=keystone.middleware.exthandler:filter_factory', 'remoteauth=keystone.middleware.remoteauth:remoteauth_factory', 'tokenauth=keystone.auth_protocols.auth_token:filter_factory', 'swiftauth=keystone.middleware.swift_auth:filter_factory', -- cgit