github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/parser/fn_or.go (about)

     1  package parser
     2  
     3  import "github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/cftypes"
     4  
     5  func ResolveOr(property *Property) (resolved *Property, success bool) {
     6  	if !property.isFunction() {
     7  		return property, true
     8  	}
     9  
    10  	refValue := property.AsMap()["Fn::Or"].AsList()
    11  
    12  	if len(refValue) < 2 {
    13  		return abortIntrinsic(property, "Fn::Or should have at least 2 values, returning original Property")
    14  	}
    15  
    16  	results := make([]bool, len(refValue))
    17  	for i := 0; i < len(refValue); i++ {
    18  
    19  		r := false
    20  		if refValue[i].IsBool() {
    21  			r = refValue[i].AsBool()
    22  		}
    23  
    24  		results[i] = r
    25  	}
    26  
    27  	atleastOne := atleastOne(results)
    28  	return property.deriveResolved(cftypes.Bool, atleastOne), true
    29  }
    30  
    31  func atleastOne(a []bool) bool {
    32  	for _, b := range a {
    33  		if b {
    34  			return true
    35  		}
    36  	}
    37  
    38  	return false
    39  }