Skip to content

Commit ef4111c

Browse files
committed
feat: change allow key to match
1 parent de50bd9 commit ef4111c

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

eval/cmdeval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (cv commandEvaluate) evalPolicy(commands []string, cmdExec cmd, evalExpr st
7575
if len(res) > 0 {
7676
policyResult = utils.MatchPolicy(res[0].ExpressionValue[0].Value, ReturnFields)
7777
} else {
78-
policyResult = utils.PolicyResult{ReturnValues: map[string]string{"allow": "false"}}
78+
policyResult = utils.PolicyResult{ReturnValues: map[string]string{"match": "false"}}
7979
}
8080
policyEvalResults = append(policyEvalResults, policyResult)
8181
}

eval/cmdeval_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestEvalCommand(t *testing.T) {
3333
}
3434

3535
const NotAllowPolicy = `package itsio
36-
policy_eval :={"name":namespace_name,"allow":allow_policy} {
36+
policy_eval :={"name":namespace_name,"match":allow_policy} {
3737
namespace_name:= input.metadata.namespace
3838
input.kind == "Pod"
3939
some i
@@ -42,7 +42,7 @@ policy_eval :={"name":namespace_name,"allow":allow_policy} {
4242
`
4343

4444
const AllowPolicy = `package itsio
45-
policy_eval :={"name":namespace_name,"allow":allow_policy} {
45+
policy_eval :={"name":namespace_name,"match":allow_policy} {
4646
namespace_name:= input.metadata.namespace
4747
allow_policy := namespace_name == "default"
4848
}

utils/stringutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ func MatchPolicy(evalResult interface{}, returnKeys []string) PolicyResult {
220220
switch t := evalResult.(type) {
221221
case bool:
222222
boolValue := strconv.FormatBool(t)
223-
return PolicyResult{ReturnValues: map[string]string{"allow": boolValue}}
223+
return PolicyResult{ReturnValues: map[string]string{"match": boolValue}}
224224
case map[string]interface{}:
225225
pr := PolicyResult{ReturnValues: make(map[string]string)}
226226
for _, rv := range returnKeys {
227227
key := strings.TrimSpace(rv)
228-
if key == "allow" {
228+
if key == "match" {
229229
b, ok := t[key].(bool)
230230
if ok {
231231
boolValue := strconv.FormatBool(b)
@@ -240,7 +240,7 @@ func MatchPolicy(evalResult interface{}, returnKeys []string) PolicyResult {
240240
}
241241
return pr
242242
default:
243-
return PolicyResult{ReturnValues: map[string]string{"allow": "false"}}
243+
return PolicyResult{ReturnValues: map[string]string{"match": "false"}}
244244
}
245245
}
246246

utils/stringutil_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ func Test_GetPolicyExpr(t *testing.T) {
152152

153153
func Test_MatchPolicySingleReturn(t *testing.T) {
154154
policyValues := true
155-
returnData := []string{"allow"}
155+
returnData := []string{"match"}
156156
mpr := MatchPolicy(policyValues, returnData)
157-
assert.Equal(t, mpr.ReturnValues["allow"], "true")
157+
assert.Equal(t, mpr.ReturnValues["match"], "true")
158158
}
159159

160160
func Test_MatchPolicySingleMulti(t *testing.T) {
161-
policyValues := map[string]interface{}{"allow": true}
162-
returnData := []string{"allow"}
161+
policyValues := map[string]interface{}{"match": true}
162+
returnData := []string{"match"}
163163
mpr := MatchPolicy(policyValues, returnData)
164-
assert.Equal(t, mpr.ReturnValues["allow"], "true")
164+
assert.Equal(t, mpr.ReturnValues["match"], "true")
165165
}

0 commit comments

Comments
 (0)