Skip to content

Commit

Permalink
fix(flags): use scope flag parser for policy
Browse files Browse the repository at this point in the history
Make PrepareFilterMapsFromPolicies() use parseScopeFlag() instead of
parsing the scope flag manually.
  • Loading branch information
geyslan committed Sep 1, 2023
1 parent 52065e1 commit b401e2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
19 changes: 4 additions & 15 deletions pkg/cmd/flags/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,12 @@ func PrepareFilterMapsFromPolicies(policies []v1beta1.PolicyFile) (PolicyScopeMa
break
}

var scopeName, operatorAndValues string

switch s {
case "follow", "!container", "container":
scopeName = s
operatorAndValues = ""
default:
operatorIdx := strings.IndexAny(s, "=!<>")
scopeName = s[:operatorIdx]
operatorAndValues = s[operatorIdx:]
parsed, err := parseScopeFlag(s)
if err != nil {
return nil, nil, errfmt.WrapError(err)
}

scopeFlags = append(scopeFlags, scopeFlag{
full: s,
scopeName: scopeName,
operatorAndValues: operatorAndValues,
})
scopeFlags = append(scopeFlags, parsed)
}

policyScopeMap[pIdx] = policyScopes{
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/flags/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ func TestPrepareFilterMapsFromPolicies(t *testing.T) {
policyName: "!container-scope",
scopeFlags: []scopeFlag{
{
full: "!container",
scopeName: "!container",
operatorAndValues: "",
full: "!container",
scopeName: "container",
operator: "!",
},
},
},
Expand Down Expand Up @@ -617,9 +617,9 @@ func TestPrepareFilterMapsFromPolicies(t *testing.T) {
operatorAndValues: "",
},
{
full: "!container",
scopeName: "!container",
operatorAndValues: "",
full: "!container",
scopeName: "container",
operator: "!",
},
{
full: "uid=1000",
Expand Down

0 comments on commit b401e2e

Please sign in to comment.