summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortermie <github@anarkystic.com>2012-01-03 16:00:59 -0800
committertermie <github@anarkystic.com>2012-01-03 16:01:39 -0800
commit23c6f49f874b5cb2dc7e94aa3b47136ee042bd32 (patch)
tree204688b03bdbb877f35703f2f8a2629c09f259b2
parent63c79344445bafb828c1cec3ddfe65e0e482c6f7 (diff)
example crud extension for create_tenant
-rw-r--r--keystonelight/keystone_compat.py13
-rw-r--r--keystonelight/wsgi.py42
-rw-r--r--tests/keystoneclient_compat_master.conf5
3 files changed, 59 insertions, 1 deletions
diff --git a/keystonelight/keystone_compat.py b/keystonelight/keystone_compat.py
index 8e5a15d0..6ff95bd1 100644
--- a/keystonelight/keystone_compat.py
+++ b/keystonelight/keystone_compat.py
@@ -125,6 +125,19 @@ class KeystoneServiceRouter(wsgi.Router):
super(KeystoneServiceRouter, self).__init__(mapper)
+class KeystoneAdminCrudExtension(wsgi.ExtensionRouter):
+ def __init__(self, application, options):
+ self.options = options
+ mapper = routes.Mapper()
+ tenant_controller = KeystoneTenantController(self.options)
+ mapper.connect('/tenants',
+ controller=tenant_controller,
+ action='create_tenant',
+ conditions=dict(method=['POST']))
+ super(KeystoneAdminCrudExtension, self).__init__(
+ application, options, mapper)
+
+
class KeystoneTokenController(service.BaseApplication):
def __init__(self, options):
self.options = options
diff --git a/keystonelight/wsgi.py b/keystonelight/wsgi.py
index 5ba1d5ce..0744fd32 100644
--- a/keystonelight/wsgi.py
+++ b/keystonelight/wsgi.py
@@ -308,3 +308,45 @@ class Router(object):
return webob.exc.HTTPNotFound()
app = match['controller']
return app
+
+
+class ExtensionRouter(Router):
+ """A router that allows extensions to supplement or overwrite routes.
+
+ Expects to be subclassed.
+ """
+ def __init__(self, application, options, mapper):
+ self.options = options
+ self.application = application
+
+ mapper.connect('{path_info:.*}', controller=self.application)
+ super(ExtensionRouter, self).__init__(mapper)
+
+ @classmethod
+ def factory(cls, global_config, **local_config):
+ """Used for paste app factories in paste.deploy config files.
+
+ Any local configuration (that is, values under the [filter:APPNAME]
+ section of the paste config) will be passed into the `__init__` method
+ as kwargs.
+
+ A hypothetical configuration would look like:
+
+ [filter:analytics]
+ redis_host = 127.0.0.1
+ paste.filter_factory = nova.api.analytics:Analytics.factory
+
+ which would result in a call to the `Analytics` class as
+
+ import nova.api.analytics
+ analytics.Analytics(app_from_paste, redis_host='127.0.0.1')
+
+ You could of course re-implement the `factory` method in subclasses,
+ but using the kwarg passing it shouldn't be necessary.
+
+ """
+ def _factory(app):
+ conf = global_config.copy()
+ conf.update(local_config)
+ return cls(app, conf)
+ return _factory
diff --git a/tests/keystoneclient_compat_master.conf b/tests/keystoneclient_compat_master.conf
index c6e4ee06..1930c50c 100644
--- a/tests/keystoneclient_compat_master.conf
+++ b/tests/keystoneclient_compat_master.conf
@@ -34,6 +34,9 @@ paste.filter_factory = keystonelight.middleware:AdminTokenAuthMiddleware.factory
[filter:json_body]
paste.filter_factory = keystonelight.middleware:JsonBodyMiddleware.factory
+[filter:crud_extension]
+paste.filter_factory = keystonelight.keystone_compat:KeystoneAdminCrudExtension.factory
+
[app:keystonelight]
paste.app_factory = keystonelight.service:app_factory
@@ -50,7 +53,7 @@ pipeline = token_auth admin_token_auth json_body debug keystonelight
pipeline = token_auth admin_token_auth json_body debug keystone_service
[pipeline:keystone_admin_api]
-pipeline = token_auth admin_token_auth json_body debug keystone_admin
+pipeline = token_auth admin_token_auth json_body debug crud_extension keystone_admin
[composite:main]
use = egg:Paste#urlmap