github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/cloudformation/parser/fn_if.go (about) 1 package parser 2 3 func ResolveIf(property *Property) (resolved *Property, success bool) { 4 if !property.isFunction() { 5 return property, true 6 } 7 8 refValue := property.AsMap()["Fn::If"].AsList() 9 10 if len(refValue) != 3 { 11 return abortIntrinsic(property, "Fn::If should have exactly 3 values, returning original Property") 12 } 13 14 condition, _ := refValue[0].resolveValue() 15 trueState, _ := refValue[1].resolveValue() 16 falseState, _ := refValue[2].resolveValue() 17 18 conditionMet := false 19 20 con, _ := condition.resolveValue() 21 if con.IsBool() { 22 conditionMet = con.AsBool() 23 } else if property.ctx.Conditions != nil && 24 condition.IsString() { 25 26 condition := property.ctx.Conditions[condition.AsString()] 27 if condition.isFunction() { 28 con, _ := condition.resolveValue() 29 if con.IsBool() { 30 conditionMet = con.AsBool() 31 } 32 } 33 } 34 35 if conditionMet { 36 return trueState, true 37 } else { 38 return falseState, true 39 } 40 }