From 516dbc346c50a488505afd1ade682129b96c3836 Mon Sep 17 00:00:00 2001 From: abhishekkekane Date: Tue, 26 Aug 2014 10:51:12 -0700 Subject: [PATCH] Syncing changes from oslo-incubator policy engine In this patch, I have copied required changes from oslo-incubator policy module from commit 0da5de6b548d34300a75f80bf87d6a809c609d2f. This changes are required for implementation of blueprint restrict-downloading-images-protected-properties. blueprint: restrict-downloading-images-protected-properties Change-Id: I00653411cd0a92503a3096c0dde07e1d6a229353 --- glance/openstack/common/policy.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/glance/openstack/common/policy.py b/glance/openstack/common/policy.py index 8bb77be810..0b441f7792 100644 --- a/glance/openstack/common/policy.py +++ b/glance/openstack/common/policy.py @@ -57,6 +57,7 @@ as it allows particular rules to be explicitly disabled. """ import abc +import ast import re import urllib @@ -775,6 +776,13 @@ class GenericCheck(Check): # TODO(termie): do dict inspection via dot syntax match = self.match % target - if self.kind in creds: - return match == six.text_type(creds[self.kind]) - return False + + try: + # Try to interpret self.kind as a literal + leftval = ast.literal_eval(self.kind) + except ValueError: + try: + leftval = creds[self.kind] + except KeyError: + return False + return match == six.text_type(leftval)