validator.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:terraform-validator 作者: ApplauseOSS 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号