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

     1  package parser
     2  
     3  import (
     4  	"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/cftypes"
     5  )
     6  
     7  func ResolveReference(property *Property) (resolved *Property, success bool) {
     8  	if !property.isFunction() {
     9  		return property, true
    10  	}
    11  
    12  	refProp := property.AsMap()["Ref"]
    13  	if refProp.IsNotString() {
    14  		return property, false
    15  	}
    16  	refValue := refProp.AsString()
    17  
    18  	if pseudo, ok := pseudoParameters[refValue]; ok {
    19  		return property.deriveResolved(pseudo.t, pseudo.val), true
    20  	}
    21  
    22  	if property.ctx == nil {
    23  		return property, false
    24  	}
    25  
    26  	var param *Parameter
    27  	for k := range property.ctx.Parameters {
    28  		if k == refValue {
    29  			param = property.ctx.Parameters[k]
    30  			resolvedType := param.Type()
    31  
    32  			switch param.Default().(type) {
    33  			case bool:
    34  				resolvedType = cftypes.Bool
    35  			case string:
    36  				resolvedType = cftypes.String
    37  			case int:
    38  				resolvedType = cftypes.Int
    39  			}
    40  
    41  			resolved = property.deriveResolved(resolvedType, param.Default())
    42  			return resolved, true
    43  		}
    44  	}
    45  
    46  	for k := range property.ctx.Resources {
    47  		if k == refValue {
    48  			res := property.ctx.Resources[k]
    49  			resolved = property.deriveResolved(cftypes.String, res.ID())
    50  			break
    51  		}
    52  	}
    53  	return resolved, true
    54  }