Skip to content

Commit

Permalink
feat(parser): support of YAML alias (#4659)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaela-soares authored Jan 18, 2022
1 parent 8b4b920 commit 795a270
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/model/model_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"strconv"

"github.com/Checkmarx/kics/pkg/utils"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -70,6 +71,10 @@ func unmarshal(val *yaml.Node) interface{} {
contentArray = append(contentArray, unmarshal(contentEntry))
}
tmp[val.Content[i].Value] = contentArray
case yaml.AliasNode:
tt := unmarshal(val.Content[i+1].Alias).(map[string]interface{})
tt["_kics_lines"] = getLines(val.Content[i+1], val.Content[i].Line)
utils.MergeMaps(tmp, tt)
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion pkg/parser/yaml/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,24 @@ downscaler_enabled: "false"
}
},
"perm": [
{}
{
"_kics_lines": {
"_kics__default": {
"_kics_line": 9
}
},
"group": {
"_kics_lines": {
"_kics__default": {
"_kics_line": 4
},
"_kics_name": {
"_kics_line": 6
}
},
"name": "cx"
}
}
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/utils/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ func SortedKeys(mapToSort map[string]string) []string {
sort.Strings(keys)
return keys
}

// MergeMaps merges two maps
func MergeMaps(map1, map2 map[string]interface{}) {
for key, value := range map2 {
map1[key] = value
}
}

0 comments on commit 795a270

Please sign in to comment.