-
Notifications
You must be signed in to change notification settings - Fork 1
/
fn_split.go
44 lines (31 loc) · 1.14 KB
/
fn_split.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
package parser
import (
"strings"
"github.com/khulnasoft-lab/vul-iac/pkg/scanners/cloudformation/cftypes"
)
func ResolveSplit(property *Property) (resolved *Property, success bool) {
if !property.isFunction() {
return property, true
}
refValue := property.AsMap()["Fn::Split"].AsList()
if len(refValue) != 2 {
return abortIntrinsic(property, "Fn::Split should have exactly 2 values, returning original Property")
}
delimiterProp := refValue[0]
splitProp := refValue[1]
if !splitProp.IsString() || !delimiterProp.IsString() {
abortIntrinsic(property, "Fn::Split requires two strings as input, returning original Property")
}
propertyList := createPropertyList(splitProp, delimiterProp, property)
return property.deriveResolved(cftypes.List, propertyList), true
}
func createPropertyList(splitProp *Property, delimiterProp *Property, parent *Property) []*Property {
splitString := splitProp.AsString()
delimiter := delimiterProp.AsString()
splits := strings.Split(splitString, delimiter)
var props []*Property
for _, split := range splits {
props = append(props, parent.deriveResolved(cftypes.String, split))
}
return props
}