def handle_fn_and(self, intrinsic_value): """ {"Fn::And": [{condition}, {...}]} This intrinsic checks that every item in the list evaluates to a boolean. The items in the list can either be of the format {Condition: condition_name} which finds and evaluates the Conditions dictionary of another intrinsic function. The Conditions dictionary will have the following format: { "Conditions": { "condition_name": True/False or "{Intrinsic Function}" } } This intrinsic function will resolve all the objects within the function's value and check their type. Parameter ---------- intrinsic_value: list, dict This is the value of the object inside the Fn::Join intrinsic function property Return ------- A boolean depending on if all of the properties in Fn::And evaluate to True """ arguments = self.intrinsic_property_resolver( intrinsic_value, parent_function=IntrinsicResolver.FN_AND ) verify_intrinsic_type_list(arguments, IntrinsicResolver.FN_AND) for i, argument in enumerate(arguments): if isinstance(argument, dict) and "Condition" in argument: condition_name = argument.get("Condition") verify_intrinsic_type_str(condition_name, IntrinsicResolver.FN_AND) condition = self._conditions.get(condition_name) verify_non_null( condition, IntrinsicResolver.FN_AND, position_in_list=self.get_prefix_position_in_list(i), ) condition_evaluated = self.intrinsic_property_resolver( condition, parent_function=IntrinsicResolver.FN_AND ) verify_intrinsic_type_bool( condition_evaluated, IntrinsicResolver.FN_AND ) if not condition_evaluated: return False else: condition = self.intrinsic_property_resolver( argument, parent_function=IntrinsicResolver.FN_AND ) verify_intrinsic_type_bool(condition, IntrinsicResolver.FN_AND) if not condition: return False return True
def handle_fn_not(self, intrinsic_value, ignore_errors): """ {"Fn::Not": [{condition}]} This intrinsic function will negate the evaluation of the condition specified. This intrinsic function will resolve all the objects within the function's value and check their type. Parameter ---------- intrinsic_value: list, dict This is the value of the object inside the Fn::Join intrinsic function property Return ------- A boolean that is the opposite of the condition evaluated """ arguments = self.intrinsic_property_resolver( intrinsic_value, ignore_errors, parent_function=IntrinsicResolver.FN_NOT) verify_intrinsic_type_list(arguments, IntrinsicResolver.FN_NOT) verify_number_arguments(arguments, IntrinsicResolver.FN_NOT, num=1) argument_sanitised = self.intrinsic_property_resolver( arguments[0], ignore_errors, parent_function=IntrinsicResolver.FN_NOT) if isinstance(argument_sanitised, dict) and "Condition" in arguments[0]: condition_name = argument_sanitised.get("Condition") verify_intrinsic_type_str(condition_name, IntrinsicResolver.FN_NOT) condition = self._conditions.get(condition_name) verify_non_null(condition, IntrinsicResolver.FN_NOT, position_in_list="first") argument_sanitised = self.intrinsic_property_resolver( condition, ignore_errors, parent_function=IntrinsicResolver.FN_NOT) verify_intrinsic_type_bool( argument_sanitised, IntrinsicResolver.FN_NOT, message="The result of {} must evaluate to bool".format( IntrinsicResolver.FN_NOT), ) return not argument_sanitised