-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Middleware to pass user token to API server
Change-Id: Icb81bc1e9ebe57ff07fa2d3c427061b2eef4ed61
- Loading branch information
Deepinder Setia
committed
Apr 17, 2015
1 parent
983d9a2
commit 1b1b33d
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
neutron_plugin_contrail/plugins/opencontrail/neutron_middleware.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
from eventlet import corolocal | ||
from eventlet.greenthread import getcurrent | ||
|
||
""" | ||
This middleware is used to forward user token to Contrail API server. | ||
Middleware is inserted at head of Neutron pipeline via api-paste.ini file | ||
so that user token can be preserved in local storage of Neutron thread. | ||
This is needed because neutron will later remove the user token before control | ||
finally reaches Contrail plugin. Contrail plugin will retreive the user token | ||
from thread's local storage and pass it to API server via X-AUTH-TOKEN header. | ||
""" | ||
|
||
|
||
class UserToken(object): | ||
def __init__(self, app, conf): | ||
self._logger = logging.getLogger(__name__) | ||
self._app = app | ||
self._conf = conf | ||
|
||
def __call__(self, env, start_response): | ||
# preserve user token for later forwarding to contrail API server | ||
cur_greenlet = getcurrent() | ||
cur_greenlet.contrail_vars = corolocal.local() | ||
cur_greenlet.contrail_vars.token = env.get('HTTP_X_AUTH_TOKEN') | ||
return self._app(env, start_response) | ||
|
||
|
||
def token_factory(global_conf, **local_conf): | ||
"""Paste factory.""" | ||
|
||
conf = global_conf.copy() | ||
conf.update(local_conf) | ||
|
||
def _factory(app): | ||
return UserToken(app, conf) | ||
return _factory |