From: Steven Dake Date: Fri, 20 Jul 2012 02:51:47 +0000 (-0700) Subject: Optimize filter context X-Git-Tag: 2014.1~1579 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=06705da563935a5097a3a502ede1c349e14656ac;p=openstack-build%2Fheat-build.git Optimize filter context Just use a direct filter factory for ContextMiddleware Change-Id: Ie17bb88c331bdb4354d0abb24346ab80f13cd323 Signed-off-by: Steven Dake --- diff --git a/etc/heat-api-paste.ini b/etc/heat-api-paste.ini index 3a03fbd5..d4ca06aa 100644 --- a/etc/heat-api-paste.ini +++ b/etc/heat-api-paste.ini @@ -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 diff --git a/etc/heat-metadata-paste.ini b/etc/heat-metadata-paste.ini index f35c0d47..e63321eb 100644 --- a/etc/heat-metadata-paste.ini +++ b/etc/heat-metadata-paste.ini @@ -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 diff --git a/heat/common/context.py b/heat/common/context.py index 416a12ed..2da85999 100644 --- a/heat/common/context.py +++ b/heat/common/context.py @@ -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