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):