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
This commit is contained in:
parent
4d5af37811
commit
83e7caa02c
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import inspect
|
||||||
import oslo_context
|
import oslo_context
|
||||||
from oslo_policy import policy
|
from oslo_policy import policy
|
||||||
|
|
||||||
@ -34,8 +35,17 @@ class RequestContext(oslo_context.context.RequestContext):
|
|||||||
if project:
|
if project:
|
||||||
kwargs['tenant'] = project
|
kwargs['tenant'] = project
|
||||||
self.project = project
|
self.project = project
|
||||||
self.roles = roles or []
|
|
||||||
self.policy_enforcer = policy_enforcer or policy.Enforcer(CONF)
|
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)
|
super(RequestContext, self).__init__(**kwargs)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user