Skip to content

Commit

Permalink
Add request.body in CEL notification filtering
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bigkevmcd committed Oct 13, 2024
1 parent b1c4e7e commit 45bd724
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/server/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func newCELEvaluator(expr string, req *http.Request) (resourcePredicate, error)

out, _, err := prg.Eval(map[string]any{
"resource": data,
"request": body,
"request": map[string]any{
"body": body,
},
})
if err != nil {
return nil, fmt.Errorf("expression %v failed to evaluate: %w", expr, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/server/receiver_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ func Test_handlePayload(t *testing.T) {
},
},
},
ResourceFilter: `has(resource.metadata.annotations) && request.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
ResourceFilter: `has(resource.metadata.annotations) && request.body.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
},
Status: apiv1.ReceiverStatus{
WebhookPath: apiv1.ReceiverWebhookPath,
Expand Down Expand Up @@ -878,7 +878,7 @@ func Test_handlePayload(t *testing.T) {
Name: "test-resource",
},
},
ResourceFilter: `has(resource.metadata.annotations) && request.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
ResourceFilter: `has(resource.metadata.annotations) && request.body.tag.split('/').last().split(":").first() == resource.metadata.annotations['update-image']`,
},
Status: apiv1.ReceiverStatus{
WebhookPath: apiv1.ReceiverWebhookPath,
Expand Down

0 comments on commit 45bd724

Please sign in to comment.