Enforce usage of oslo.context's project_id

Instead of using "project" which came from our legacy custom context
class, we enforce the usage of oslo.context's project_id. Thus cleaning
up that class a little bit.

Change-Id: Ic030f426de744c585ca6b4a02f0a9e6b6df15cc5
This commit is contained in:
Juan Antonio Osorio Robles 2018-04-23 17:37:52 +03:00
parent e708ff3413
commit aafeb7aa91
4 changed files with 7 additions and 16 deletions

View File

@ -25,11 +25,8 @@ class RequestContext(oslo_context.context.RequestContext):
accesses the system, as well as additional request information. accesses the system, as well as additional request information.
""" """
def __init__(self, policy_enforcer=None, project=None, **kwargs): def __init__(self, policy_enforcer=None, **kwargs):
# prefer usage of 'project' instead of 'tenant' # prefer usage of 'project' instead of 'tenant'
if project:
kwargs['tenant'] = project
self.project = project
if policy_enforcer: if policy_enforcer:
self.policy_enforcer = policy_enforcer self.policy_enforcer = policy_enforcer
else: else:
@ -41,12 +38,6 @@ class RequestContext(oslo_context.context.RequestContext):
out_dict = super(RequestContext, self).to_dict() out_dict = super(RequestContext, self).to_dict()
out_dict['roles'] = self.roles out_dict['roles'] = self.roles
# NOTE(jaosorior): For now, the oslo_context library uses 'tenant'
# instead of project. But in case this changes, this will still issue
# the dict we expect, which would contain 'project'.
if out_dict.get('tenant'):
out_dict['project'] = out_dict['tenant']
out_dict.pop('tenant')
return out_dict return out_dict
@classmethod @classmethod

View File

@ -42,8 +42,8 @@ def get_barbican_env(external_project_id):
Injects the provided external_project_id. Injects the provided external_project_id.
""" """
kwargs = {'roles': None, kwargs = {'roles': None,
'user': None, 'user_id': None,
'project': external_project_id, 'project_id': external_project_id,
'is_admin': True} 'is_admin': True}
ctx = barbican.context.RequestContext(**kwargs) ctx = barbican.context.RequestContext(**kwargs)
ctx.policy_enforcer = None ctx.policy_enforcer = None

View File

@ -131,8 +131,8 @@ class BaseTestCase(utils.BaseTestCase, utils.MockModelRepositoryMixin):
req.get_param.return_value = None req.get_param.return_value = None
kwargs = { kwargs = {
'user': user_id, 'user_id': user_id,
'project': project_id, 'project_id': project_id,
'roles': roles or [], 'roles': roles or [],
'policy_enforcer': self.policy_enforcer, 'policy_enforcer': self.policy_enforcer,
} }

View File

@ -37,8 +37,8 @@ def get_barbican_env(external_project_id):
return return
kwargs = {'roles': None, kwargs = {'roles': None,
'user': None, 'user_id': None,
'project': external_project_id, 'project_id': external_project_id,
'is_admin': True, 'is_admin': True,
'policy_enforcer': NoopPolicyEnforcer()} 'policy_enforcer': NoopPolicyEnforcer()}
barbican_env = {'barbican.context': barbican_env = {'barbican.context':