-
Notifications
You must be signed in to change notification settings - Fork 1
/
fn_ref.go
54 lines (45 loc) · 1.15 KB
/
fn_ref.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
47
48
49
50
51
52
53
54
package parser
import (
"github.com/khulnasoft-lab/vul-iac/pkg/scanners/cloudformation/cftypes"
)
func ResolveReference(property *Property) (resolved *Property, success bool) {
if !property.isFunction() {
return property, true
}
refProp := property.AsMap()["Ref"]
if refProp.IsNotString() {
return property, false
}
refValue := refProp.AsString()
if pseudo, ok := pseudoParameters[refValue]; ok {
return property.deriveResolved(pseudo.t, pseudo.val), true
}
if property.ctx == nil {
return property, false
}
var param *Parameter
for k := range property.ctx.Parameters {
if k == refValue {
param = property.ctx.Parameters[k]
resolvedType := param.Type()
switch param.Default().(type) {
case bool:
resolvedType = cftypes.Bool
case string:
resolvedType = cftypes.String
case int:
resolvedType = cftypes.Int
}
resolved = property.deriveResolved(resolvedType, param.Default())
return resolved, true
}
}
for k := range property.ctx.Resources {
if k == refValue {
res := property.ctx.Resources[k]
resolved = property.deriveResolved(cftypes.String, res.ID())
break
}
}
return resolved, true
}