Skip to content

Commit

Permalink
Merge pull request #15 from armosec/fix_parser
Browse files Browse the repository at this point in the history
fix parser
  • Loading branch information
kooomix authored Jan 3, 2024
2 parents 39360f0 + d4f1d85 commit aabe68e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions armometadata/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func ExtractMetadataFromJsonBytes(input []byte) (Metadata, error) {
PodSelectorMatchLabels: map[string]string{},
}
// ujson parsing
var parent, subParent, subParent2 string
var parent, subParent string
err := ujson.Walk(input, func(level int, key, value []byte) bool {
switch level {
case 1:
Expand Down Expand Up @@ -170,19 +170,18 @@ func ExtractMetadataFromJsonBytes(input []byte) (Metadata, error) {
m.Labels[unquote(key)] = unquote(value)
}

subParent2 = unquote(key)

case 4:
// read ownerReferences
if subParent == "ownerReferences" {
m.OwnerReferences[unquote(key)] = unquote(value)
}

if subParent2 == "matchLabels" {
if subParent == "podSelector" {
m.PodSelectorMatchLabels[unquote(key)] = unquote(value)
}

}

return true
})
return m, err
Expand Down
1 change: 1 addition & 0 deletions armometadata/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func TestExtractMetadataFromJsonBytes(t *testing.T) {
apiVersion: "networking.k8s.io/v1",
podSelectorMatchLabels: map[string]string{
"role": "frontend",
"tier": "tier1",
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion armometadata/testdata/networkpolicy_withmatching_labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"spec": {
"podSelector": {
"matchLabels": {
"role": "frontend"
"role": "frontend",
"tier": "tier1"
}
},
"policyTypes": ["Ingress"],
Expand Down

0 comments on commit aabe68e

Please sign in to comment.