github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/parser/fn_find_in_map.go (about) 1 package parser 2 3 import ( 4 "github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/cftypes" 5 ) 6 7 func ResolveFindInMap(property *Property) (resolved *Property, success bool) { 8 if !property.isFunction() { 9 return property, true 10 } 11 12 refValue := property.AsMap()["Fn::FindInMap"].AsList() 13 14 if len(refValue) != 3 { 15 return abortIntrinsic(property, "Fn::FindInMap should have exactly 3 values, returning original Property") 16 } 17 18 mapName := refValue[0].AsString() 19 topLevelKey := refValue[1].AsString() 20 secondaryLevelKey := refValue[2].AsString() 21 22 if property.ctx == nil { 23 return abortIntrinsic(property, "the property does not have an attached context, returning original Property") 24 } 25 26 m, ok := property.ctx.Mappings[mapName] 27 if !ok { 28 return abortIntrinsic(property, "could not find map %s, returning original Property") 29 } 30 31 mapContents := m.(map[string]interface{}) 32 33 k, ok := mapContents[topLevelKey] 34 if !ok { 35 return abortIntrinsic(property, "could not find %s in the %s map, returning original Property", topLevelKey, mapName) 36 } 37 38 mapValues := k.(map[string]interface{}) 39 40 if prop, ok := mapValues[secondaryLevelKey]; !ok { 41 return abortIntrinsic(property, "could not find a value for %s in %s, returning original Property", secondaryLevelKey, topLevelKey) 42 } else { 43 return property.deriveResolved(cftypes.String, prop), true 44 } 45 }