Use from_environ to load context

Oslo.context provides a from_environ method that loads all the headers
from the auth_token middleware into the correct parameters and will let
oslo context provide new features in future.

Related-Bug: #1602081
Change-Id: Ie79ee8d5f40032777bf12b8798d64e9dc8141c9e
This commit is contained in:
Jamie Lennox
2016-07-11 11:17:24 +10:00
parent 842d95bb68
commit abf91a8a4e
2 changed files with 23 additions and 41 deletions

View File

@@ -49,11 +49,10 @@ class RequestContext(context.RequestContext):
Represents the user taking a given action within the system.
"""
def __init__(self, user_id, project_id, is_admin=None, read_deleted="no",
roles=None, project_name=None, remote_address=None,
timestamp=None, request_id=None, auth_token=None,
overwrite=True, quota_class=None, service_catalog=None,
domain=None, user_domain=None, project_domain=None):
def __init__(self, user_id=None, project_id=None, is_admin=None,
read_deleted="no", project_name=None, remote_address=None,
timestamp=None, quota_class=None, service_catalog=None,
**kwargs):
"""Initialize RequestContext.
:param read_deleted: 'no' indicates deleted records are hidden, 'yes'
@@ -63,17 +62,14 @@ class RequestContext(context.RequestContext):
:param overwrite: Set to False to ensure that the greenthread local
copy of the index is not overwritten.
"""
# NOTE(jamielennox): oslo.context still uses some old variables names.
# These arguments are maintained instead of passed as kwargs to
# maintain the interface for tests.
kwargs.setdefault('user', user_id)
kwargs.setdefault('tenant', project_id)
super(RequestContext, self).__init__(is_admin=is_admin, **kwargs)
super(RequestContext, self).__init__(auth_token=auth_token,
user=user_id,
tenant=project_id,
domain=domain,
user_domain=user_domain,
project_domain=project_domain,
is_admin=is_admin,
request_id=request_id,
overwrite=overwrite,
roles=roles)
self.project_name = project_name
self.read_deleted = read_deleted
self.remote_address = remote_address