diff --git a/karbor/context.py b/karbor/context.py index 5ace9ad3..4857ce59 100644 --- a/karbor/context.py +++ b/karbor/context.py @@ -38,7 +38,7 @@ class RequestContext(context.RequestContext): timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, service_catalog=None, domain=None, user_domain=None, project_domain=None, - **kwargs): + auth_token_info=None): """Initialize RequestContext. :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 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, @@ -70,7 +67,7 @@ class RequestContext(context.RequestContext): timestamp = timeutils.parse_isotime(timestamp) self.timestamp = timestamp self.quota_class = quota_class - self._auth_token_info = kwargs.get('auth_token_info') + self._auth_token_info = auth_token_info if service_catalog: # Only include required parts of service_catalog @@ -125,7 +122,26 @@ class RequestContext(context.RequestContext): @classmethod 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): """Return a version of this context with admin flag set.""" diff --git a/karbor/tests/unit/test_context.py b/karbor/tests/unit/test_context.py index bb722dac..8302b577 100644 --- a/karbor/tests/unit/test_context.py +++ b/karbor/tests/unit/test_context.py @@ -53,7 +53,7 @@ class ContextTestCase(base.TestCase): def test_request_context_elevated(self): user_context = context.RequestContext( - 'fake_user', 'fake_project', admin=False) + 'fake_user', 'fake_project', is_admin=False) self.assertFalse(user_context.is_admin) admin_context = user_context.elevated() self.assertFalse(user_context.is_admin)