github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/parser/fn_select.go (about) 1 package parser 2 3 import ( 4 "github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/cftypes" 5 ) 6 7 func ResolveSelect(property *Property) (resolved *Property, success bool) { 8 if !property.isFunction() { 9 return property, true 10 } 11 12 refValue := property.AsMap()["Fn::Select"].AsList() 13 14 if len(refValue) != 2 { 15 return abortIntrinsic(property, "Fn::Select should have exactly 2 values, returning original Property") 16 } 17 18 index := refValue[0] 19 list := refValue[1] 20 21 if index.IsNotInt() { 22 if index.IsConvertableTo(cftypes.Int) { 23 // 24 index = index.ConvertTo(cftypes.Int) 25 } else { 26 return abortIntrinsic(property, "index on property [%s] should be an int, returning original Property", property.name) 27 } 28 } 29 30 if list.IsNotList() { 31 return abortIntrinsic(property, "list on property [%s] should be a list, returning original Property", property.name) 32 } 33 34 listItems := list.AsList() 35 36 if len(listItems) <= index.AsInt() { 37 return nil, false 38 } 39 40 return listItems[index.AsInt()], true 41 }