Add token_auth helper to request

This is the user plugin object that is passed down to the services. Add
helpers for setting and retrieving it from a request.

Change-Id: I39173ad5025b7bafc9d41da42180be5cea9df6b5
This commit is contained in:
Jamie Lennox 2015-06-30 13:31:07 +10:00
parent c2deb9e38e
commit f0ad77c060
3 changed files with 22 additions and 3 deletions

View File

@ -567,15 +567,16 @@ class AuthProtocol(_BaseAuthProtocol):
_LI('Invalid service token - rejecting request'))
self._reject_request()
p = _user_plugin.UserAuthPlugin(user_auth_ref, serv_auth_ref)
request.environ['keystone.token_auth'] = p
request.token_auth = _user_plugin.UserAuthPlugin(user_auth_ref,
serv_auth_ref)
except exc.ServiceError as e:
self.log.critical(_LC('Unable to obtain admin token: %s'), e)
raise webob.exc.HTTPServiceUnavailable()
if self.log.isEnabledFor(logging.DEBUG):
self.log.debug('Received request from %s' % p._log_format)
self.log.debug('Received request from %s' %
request.token_auth._log_format)
def process_response(self, response):
"""Process Response.

View File

@ -77,6 +77,7 @@ class _AuthTokenRequest(webob.Request):
_SERVICE_STATUS_HEADER = 'X-Service-Identity-Status'
_SERVICE_CATALOG_HEADER = 'X-Service-Catalog'
_TOKEN_AUTH = 'keystone.token_auth'
_CONFIRMED = 'Confirmed'
_INVALID = 'Invalid'
@ -203,3 +204,12 @@ class _AuthTokenRequest(webob.Request):
return None
else:
return auth_type.lower()
@property
def token_auth(self):
"""The auth plugin that will be associated with this request"""
return self.environ.get(self._TOKEN_AUTH)
@token_auth.setter
def token_auth(self, v):
self.environ[self._TOKEN_AUTH] = v

View File

@ -181,6 +181,14 @@ class RequestObjectTests(utils.TestCase):
self.request.headers['X-Service-Token'] = token
self.assertEqual(token, self.request.service_token)
def test_token_auth(self):
plugin = object()
self.assertNotIn('keystone.token_auth', self.request.environ)
self.request.token_auth = plugin
self.assertIs(plugin, self.request.environ['keystone.token_auth'])
self.assertIs(plugin, self.request.token_auth)
class CatalogConversionTests(utils.TestCase):