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
This commit is contained in:
abhishekkekane 2014-08-26 10:51:12 -07:00
parent 0aca880658
commit 516dbc346c

View File

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