]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Optimize filter context
authorSteven Dake <sdake@redhat.com>
Fri, 20 Jul 2012 02:51:47 +0000 (19:51 -0700)
committerSteven Dake <sdake@redhat.com>
Fri, 20 Jul 2012 02:52:24 +0000 (19:52 -0700)
Just use a direct filter factory for ContextMiddleware

Change-Id: Ie17bb88c331bdb4354d0abb24346ab80f13cd323
Signed-off-by: Steven Dake <sdake@redhat.com>
etc/heat-api-paste.ini
etc/heat-metadata-paste.ini
heat/common/context.py

index 3a03fbd523a71827dc3a86a5a2f41c186bd53478..d4ca06aa003d9620901e35c47da6b9859d1cdc0a 100644 (file)
@@ -60,8 +60,7 @@ paste.filter_factory = heat.common.wsgi:filter_factory
 heat.filter_factory = heat.api.middleware.cache_manage:CacheManageFilter
 
 [filter:context]
-paste.filter_factory = heat.common.wsgi:filter_factory
-heat.filter_factory = heat.common.context:ContextMiddleware
+paste.filter_factory = heat.common.context:ContextMiddleware_filter_factory
 
 [filter:ec2authtoken]
 paste.filter_factory = heat.common.wsgi:filter_factory
index f35c0d47134ad2cc1c25da04f1c7dc8035874c43..e63321eb5d8241312fe722e020e301451ad520d8 100644 (file)
@@ -12,5 +12,4 @@ paste.app_factory = heat.common.wsgi:app_factory
 heat.app_factory = heat.metadata.api.v1:API
 
 [filter:context]
-paste.filter_factory = heat.common.wsgi:filter_factory
-heat.filter_factory = heat.common.context:ContextMiddleware
+paste.filter_factory = heat.common.context:ContextMiddleware_filter_factory
index 416a12edbc0007b5d5a9bcda7c2a5595a723915d..2da8599935d6d2d4b854707c0e56f27c0e9c8870 100644 (file)
@@ -110,8 +110,7 @@ class ContextMiddleware(wsgi.Middleware):
         ]
 
     def __init__(self, app, conf, **local_conf):
-        self.conf = conf
-        self.conf.register_opts(self.opts)
+        cfg.CONF.register_opts(self.opts)
 
         # Determine the context class to use
         self.ctxcls = RequestContext
@@ -124,7 +123,7 @@ class ContextMiddleware(wsgi.Middleware):
         """
         Create a context with the given arguments.
         """
-        kwargs.setdefault('owner_is_tenant', self.conf.owner_is_tenant)
+        kwargs.setdefault('owner_is_tenant', cfg.CONF.owner_is_tenant)
 
         return self.ctxcls(*args, **kwargs)
 
@@ -193,3 +192,16 @@ class ContextMiddleware(wsgi.Middleware):
                                         service_password=service_password,
                                         auth_url=auth_url, roles=roles,
                                         is_admin=True)
+
+
+def ContextMiddleware_filter_factory(global_conf, **local_conf):
+    """
+    Factory method for paste.deploy
+    """
+    conf = global_conf.copy()
+    conf.update(local_conf)
+
+    def filter(app):
+        return ContextMiddleware(app, conf)
+
+    return filter