Use the from_environ features of oslo_context

Oslo context provides a from_environ features that loads up a context
with all the standard auth_token middleware and oslo middleware. Use
that instead of checking those ourselves.

Change-Id: Id19aa796bf284348667b8e02f91bec4dba9d7b4a
This commit is contained in:
Jamie Lennox 2016-07-27 15:24:01 -05:00
parent 53834349fb
commit 636165b852
2 changed files with 8 additions and 14 deletions

View File

@ -20,12 +20,5 @@ from octavia.common import context
class ContextHook(hooks.PecanHook):
def on_route(self, state):
user_id = state.request.headers.get('X-User-Id')
user_id = state.request.headers.get('X-User', user_id)
project = state.request.headers.get('X-Tenant-Id')
project = state.request.headers.get('X-Tenant', project)
project = state.request.headers.get('X-Project-Id', project)
project = state.request.headers.get('X-Project', project)
auth_token = state.request.headers.get('X-Auth-Token')
state.request.context['octavia_context'] = context.Context(
user_id=user_id, project_id=project, auth_token=auth_token)
context_obj = context.Context.from_environ(state.request.environ)
state.request.context['octavia_context'] = context_obj

View File

@ -18,14 +18,15 @@ from octavia.db import api as db_api
class Context(common_context.RequestContext):
def __init__(self, user_id, project_id, is_admin=False, auth_token=None):
super(Context, self).__init__(tenant=project_id, auth_token=auth_token,
is_admin=is_admin, user=user_id)
self._session = None
self.project_id = project_id
_session = None
@property
def session(self):
if self._session is None:
self._session = db_api.get_session()
return self._session
@property
def project_id(self):
return self.tenant