-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
fn_get_attr.go
46 lines (34 loc) · 1.17 KB
/
fn_get_attr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package parser
import (
"strings"
"github.com/aquasecurity/trivy/pkg/iac/scanners/cloudformation/cftypes"
)
func ResolveGetAtt(property *Property) (resolved *Property, success bool) {
if !property.isFunction() {
return property, true
}
refValueProp := property.AsMap()["Fn::GetAtt"]
var refValue []string
if refValueProp.IsString() {
refValue = strings.Split(refValueProp.AsString(), ".")
}
if refValueProp.IsList() {
for _, p := range refValueProp.AsList() {
refValue = append(refValue, p.AsString())
}
}
if len(refValue) != 2 {
return abortIntrinsic(property, "Fn::GetAtt should have exactly 2 values, returning original Property")
}
logicalId := refValue[0]
attribute := refValue[1]
referencedResource := property.ctx.GetResourceByLogicalID(logicalId)
if referencedResource == nil || referencedResource.IsNil() {
return property.deriveResolved(cftypes.String, ""), true
}
referencedProperty := referencedResource.GetProperty(attribute)
if referencedProperty.IsNil() {
return property.deriveResolved(cftypes.String, referencedResource.ID()), true
}
return property.deriveResolved(referencedProperty.Type(), referencedProperty.RawValue()), true
}