def validate_rule(self, rule, resource):
"""
Validate a single rule on the values of a resource by eval the boolean value of rule's expression.
:param rule: rule dictionary
:param resource: resource values dictionary
:return: True if valid, otherwise False
"""
try:
if 'destroy' in resource and resource['destroy']:
return True # skip validation if resource is being destroyed
R = ResourceContainer(resource) # R is the identifier used in the rule expression
return eval(rule["expr"])
except Exception as e:
'''exceptions are suppressed here to let the validation continue. So that the user will
receive al complete report and be able to fix all errors at once.'''
logging.exception('[EXCEPTION] Exception occurred during rule expression evaluation')
return False
评论列表
文章目录