From 83e7caa02c571df1d7a4c86f45493eb7afaf0c4e Mon Sep 17 00:00:00 2001 From: Elvin Tubillara Date: Thu, 25 Feb 2016 19:11:41 -0600 Subject: [PATCH] Fix roles attribute for barbican request context The oslo_context.context.RequestContext was updated in oslo_context 2.2.0 to have a roles attribute. This caused the barbican request context to have an empty roles attribute. The 'inspect' library is used to make sure backwards compatibility since the current requirements for oslo_context is >= 0.2.0. Change-Id: Iafc67a6f42e46da998eaf2f5199c47f6beaf345e --- barbican/context.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/barbican/context.py b/barbican/context.py index 3caddee12..264d7f955 100644 --- a/barbican/context.py +++ b/barbican/context.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import inspect import oslo_context from oslo_policy import policy @@ -34,8 +35,17 @@ class RequestContext(oslo_context.context.RequestContext): if project: kwargs['tenant'] = project self.project = project - self.roles = roles or [] self.policy_enforcer = policy_enforcer or policy.Enforcer(CONF) + + # NOTE(edtubill): oslo_context 2.2.0 now has a roles attribute in + # the RequestContext. This will make sure of backwards compatibility + # with past oslo_context versions. + argspec = inspect.getargspec(super(RequestContext, self).__init__) + if 'roles' in argspec.args: + kwargs['roles'] = roles + else: + self.roles = roles or [] + super(RequestContext, self).__init__(**kwargs) def to_dict(self):