Add roles to RequestContext.to_dict if they're not there

Old versions of oslo_context do not include rules in to_dict()
However roles are required for newer versions of oslo_policy to operate
and resolve 'role:xxx' rules.

Since minimal version for oslo_context is 0.2.0 and commit, that adds
roles has been added only in 2.2.0 we should support old versions of
oslo_context with newer version.

Change-Id: If35726613bec5d342bad72b542215ec8e5c096a2
Closes-Bug: #1552291
This commit is contained in:
Kirill Zaitsev 2016-03-03 01:15:33 +03:00
parent 503d245269
commit 53845d84e7
2 changed files with 10 additions and 0 deletions

View File

@ -34,3 +34,8 @@ class RequestContext(context.RequestContext):
self.is_admin = is_admin
if self.is_admin is None:
self.is_admin = policy.check_is_admin(self)
def to_dict(self):
d = super(RequestContext, self).to_dict()
d.setdefault('roles', self.roles)
return d

View File

@ -0,0 +1,5 @@
---
fixes:
- RequestContext now serialises it's roles. This should allow murano to
work correctly (and allow rules like "role:xxx" in policy.json)
when using oslo.context prior to 2.2.0 and oslo.policy