Skip to content

Commit 45bd724

Browse files
committed
Add request.body in CEL notification filtering
This moves the JSON body to request.body from request to allow for future expansion with the headers. Signed-off-by: Kevin McDermott <[email protected]>
1 parent b1c4e7e commit 45bd724

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

internal/server/cel.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ func newCELEvaluator(expr string, req *http.Request) (resourcePredicate, error)
5353

5454
out, _, err := prg.Eval(map[string]any{
5555
"resource": data,
56-
"request": body,
56+
"request": map[string]any{
57+
"body": body,
58+
},
5759
})
5860
if err != nil {
5961
return nil, fmt.Errorf("expression %v failed to evaluate: %w", expr, err)

internal/server/receiver_handler_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ func Test_handlePayload(t *testing.T) {
789789
},
790790
},
791791
},
792-
ResourceFilter: `has(resource.metadata.annotations) && request.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
792+
ResourceFilter: `has(resource.metadata.annotations) && request.body.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
793793
},
794794
Status: apiv1.ReceiverStatus{
795795
WebhookPath: apiv1.ReceiverWebhookPath,
@@ -878,7 +878,7 @@ func Test_handlePayload(t *testing.T) {
878878
Name: "test-resource",
879879
},
880880
},
881-
ResourceFilter: `has(resource.metadata.annotations) && request.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
881+
ResourceFilter: `has(resource.metadata.annotations) && request.body.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
882882
},
883883
Status: apiv1.ReceiverStatus{
884884
WebhookPath: apiv1.ReceiverWebhookPath,

0 commit comments

Comments
 (0)