fn find_dependencies(
    root_condition_name: &str,
    condition_val: &ConditionValue,
    condition_dependency_tracker: &mut HashMap<String, ConditionNode>,
) {
    match condition_val {
        ConditionValue::And(x) | ConditionValue::Or(x) => x.iter().for_each(|cond| {
            find_dependencies(root_condition_name, cond, condition_dependency_tracker)
        }),
        ConditionValue::Equals(a, b) => {
            find_dependencies(root_condition_name, a, condition_dependency_tracker);
            find_dependencies(root_condition_name, b, condition_dependency_tracker);
        }
        ConditionValue::Not(a) => {
            find_dependencies(root_condition_name, a, condition_dependency_tracker);
        }
        ConditionValue::Ref(_x) | ConditionValue::Str(_x) => {}
        ConditionValue::Condition(x) => {
            let mut root_condition_node = condition_dependency_tracker
                .remove(root_condition_name)
                .unwrap();
            let mut used_by_condition_node = condition_dependency_tracker.remove(x).unwrap();
            // Associate root condition with its dependency and vice-versa
            root_condition_node.uses.push(x.clone());
            used_by_condition_node
                .used_by
                .push(root_condition_node.name.clone());

            condition_dependency_tracker
                .insert(root_condition_name.to_string(), root_condition_node);
            condition_dependency_tracker.insert(x.clone(), used_by_condition_node);
        }
        ConditionValue::FindInMap(name, l1, l2) => {
            find_dependencies(root_condition_name, name, condition_dependency_tracker);
            find_dependencies(root_condition_name, l1, condition_dependency_tracker);
            find_dependencies(root_condition_name, l2, condition_dependency_tracker);
        }
    };
}
/**
 * Recursively identify the dependency conditions of a CloudFormation condition.
 */
Recursively identify the dependency conditions of a CloudFormation condition.
Recursively identify the dependency conditions of a CloudFormation condition .
fn find_dependencies(
    root_condition_name: &str,
    condition_val: &ConditionValue,
    condition_dependency_tracker: &mut HashMap<String, ConditionNode>,
) {
    match condition_val {
        ConditionValue::And(x) | ConditionValue::Or(x) => x.iter().for_each(|cond| {
            find_dependencies(root_condition_name, cond, condition_dependency_tracker)
        }),
        ConditionValue::Equals(a, b) => {
            find_dependencies(root_condition_name, a, condition_dependency_tracker);
            find_dependencies(root_condition_name, b, condition_dependency_tracker);
        }
        ConditionValue::Not(a) => {
            find_dependencies(root_condition_name, a, condition_dependency_tracker);
        }
        ConditionValue::Ref(_x) | ConditionValue::Str(_x) => {}
        ConditionValue::Condition(x) => {
            let mut root_condition_node = condition_dependency_tracker
                .remove(root_condition_name)
                .unwrap();
            let mut used_by_condition_node = condition_dependency_tracker.remove(x).unwrap();
            // Associate root condition with its dependency and vice-versa
            root_condition_node.uses.push(x.clone());
            used_by_condition_node
                .used_by
                .push(root_condition_node.name.clone());
            condition_dependency_tracker
                .insert(root_condition_name.to_string(), root_condition_node);
            condition_dependency_tracker.insert(x.clone(), used_by_condition_node);
        }
        ConditionValue::FindInMap(name, l1, l2) => {
            find_dependencies(root_condition_name, name, condition_dependency_tracker);
            find_dependencies(root_condition_name, l1, condition_dependency_tracker);
            find_dependencies(root_condition_name, l2, condition_dependency_tracker);
        }
    };
}
fn find_dependencies ( root_condition_name : & str , condition_val : & ConditionValue , condition_dependency_tracker : & mut HashMap < String , ConditionNode > , ) { match condition_val { ConditionValue :: And ( x ) | ConditionValue :: Or ( x ) => x . iter ( ) . for_each ( | cond | { find_dependencies ( root_condition_name , cond , condition_dependency_tracker ) } ) , ConditionValue :: Equals ( a , b ) => { find_dependencies ( root_condition_name , a , condition_dependency_tracker ) ; find_dependencies ( root_condition_name , b , condition_dependency_tracker ) ; } ConditionValue :: Not ( a ) => { find_dependencies ( root_condition_name , a , condition_dependency_tracker ) ; } ConditionValue :: Ref ( _x ) | ConditionValue :: Str ( _x ) => { } ConditionValue :: Condition ( x ) => { let mut root_condition_node = condition_dependency_tracker . remove ( root_condition_name ) . unwrap ( ) ; let mut used_by_condition_node = condition_dependency_tracker . remove ( x ) . unwrap ( ) ; // Associate root condition with its dependency and vice-versa root_condition_node . uses . push ( x . clone ( ) ) ; used_by_condition_node . used_by . push ( root_condition_node . name . clone ( ) ) ; condition_dependency_tracker . insert ( root_condition_name . to_string ( ) , root_condition_node ) ; condition_dependency_tracker . insert ( x . clone ( ) , used_by_condition_node ) ; } ConditionValue :: FindInMap ( name , l1 , l2 ) => { find_dependencies ( root_condition_name , name , condition_dependency_tracker ) ; find_dependencies ( root_condition_name , l1 , condition_dependency_tracker ) ; find_dependencies ( root_condition_name , l2 , condition_dependency_tracker ) ; } } ; }
Recursively identify the dependency conditions of a CloudFormation condition.
Recursively identify the dependency conditions of a CloudFormation condition .
root_condition_name
&str
condition_val
&ConditionValue
condition_dependency_tracker
&mut HashMap<String, ConditionNode>
root_condition_name
&str
condition_val
&ConditionValue
condition_dependency_tracker
&mut HashMap<String, ConditionNode>