Use context.from_dict to determine available arguments
RequestContext.__init__ takes and ignores arbitrary keyword arguments. The ignored arguments are generally made up of things that oslo_context added to the to_dict that karbor doesn't handle. Instead of accepting and ignoring those arguments make from_dict smart enough to construct the correct arguments to the class. Related-Bug: #1602081 Change-Id: I6782e63e6a530f53e7bf430d28cc3309903e7fb4
This commit is contained in:
parent
3c006f887a
commit
c2dd9e0f65
|
@ -38,7 +38,7 @@ class RequestContext(context.RequestContext):
|
||||||
timestamp=None, request_id=None, auth_token=None,
|
timestamp=None, request_id=None, auth_token=None,
|
||||||
overwrite=True, quota_class=None, service_catalog=None,
|
overwrite=True, quota_class=None, service_catalog=None,
|
||||||
domain=None, user_domain=None, project_domain=None,
|
domain=None, user_domain=None, project_domain=None,
|
||||||
**kwargs):
|
auth_token_info=None):
|
||||||
"""Initialize RequestContext.
|
"""Initialize RequestContext.
|
||||||
|
|
||||||
:param read_deleted: 'no' indicates deleted records are hidden, 'yes'
|
:param read_deleted: 'no' indicates deleted records are hidden, 'yes'
|
||||||
|
@ -47,9 +47,6 @@ class RequestContext(context.RequestContext):
|
||||||
|
|
||||||
:param overwrite: Set to False to ensure that the greenthread local
|
:param overwrite: Set to False to ensure that the greenthread local
|
||||||
copy of the index is not overwritten.
|
copy of the index is not overwritten.
|
||||||
|
|
||||||
:param kwargs: Extra arguments that might be present, but we ignore
|
|
||||||
because they possibly came in from older rpc messages.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
super(RequestContext, self).__init__(auth_token=auth_token,
|
super(RequestContext, self).__init__(auth_token=auth_token,
|
||||||
|
@ -70,7 +67,7 @@ class RequestContext(context.RequestContext):
|
||||||
timestamp = timeutils.parse_isotime(timestamp)
|
timestamp = timeutils.parse_isotime(timestamp)
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.quota_class = quota_class
|
self.quota_class = quota_class
|
||||||
self._auth_token_info = kwargs.get('auth_token_info')
|
self._auth_token_info = auth_token_info
|
||||||
|
|
||||||
if service_catalog:
|
if service_catalog:
|
||||||
# Only include required parts of service_catalog
|
# Only include required parts of service_catalog
|
||||||
|
@ -125,7 +122,26 @@ class RequestContext(context.RequestContext):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, values):
|
def from_dict(cls, values):
|
||||||
return cls(**values)
|
allowed_keys = [
|
||||||
|
'user_id',
|
||||||
|
'project_id',
|
||||||
|
'project_name',
|
||||||
|
'domain',
|
||||||
|
'read_deleted',
|
||||||
|
'remote_address',
|
||||||
|
'timestamp',
|
||||||
|
'quota_class',
|
||||||
|
'service_catalog',
|
||||||
|
'request_id',
|
||||||
|
'is_admin',
|
||||||
|
'roles',
|
||||||
|
'auth_token',
|
||||||
|
'user_domain',
|
||||||
|
'project_domain',
|
||||||
|
'auth_token_info'
|
||||||
|
]
|
||||||
|
kwargs = {k: values[k] for k in values if k in allowed_keys}
|
||||||
|
return cls(**kwargs)
|
||||||
|
|
||||||
def elevated(self, read_deleted=None, overwrite=False):
|
def elevated(self, read_deleted=None, overwrite=False):
|
||||||
"""Return a version of this context with admin flag set."""
|
"""Return a version of this context with admin flag set."""
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ContextTestCase(base.TestCase):
|
||||||
|
|
||||||
def test_request_context_elevated(self):
|
def test_request_context_elevated(self):
|
||||||
user_context = context.RequestContext(
|
user_context = context.RequestContext(
|
||||||
'fake_user', 'fake_project', admin=False)
|
'fake_user', 'fake_project', is_admin=False)
|
||||||
self.assertFalse(user_context.is_admin)
|
self.assertFalse(user_context.is_admin)
|
||||||
admin_context = user_context.elevated()
|
admin_context = user_context.elevated()
|
||||||
self.assertFalse(user_context.is_admin)
|
self.assertFalse(user_context.is_admin)
|
||||||
|
|
Loading…
Reference in New Issue