forked from tektoncd/triggers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an interceptor to that can filter based on CEL expressions.
This adds a cel interceptor, that uses a a CEL expression to filter request bodies. This implements issue tektoncd#49.
- Loading branch information
1 parent
2e8809d
commit 9ace5c1
Showing
168 changed files
with
45,793 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# CEL expression extensions | ||
|
||
The CEL expression is configured to expose parts of the request, and some custom | ||
functions to make matching easier. | ||
|
||
### List of extensions | ||
|
||
The body from the `http.Request` value is decoded to JSON and exposed, and the | ||
headers are also available. | ||
|
||
<table style="width=100%" border="1"> | ||
<tr> | ||
<th>Symbol</th> | ||
<th>Type</th> | ||
<th>Description</th> | ||
<th>Example</th> | ||
</tr> | ||
<tr> | ||
<th> | ||
body | ||
</th> | ||
<td> | ||
map(string, dynamic) | ||
</td> | ||
<td> | ||
This is the decoded JSON body from the incoming http.Request exposed as a map of string keys to any value types. | ||
</td> | ||
<td> | ||
<pre>body.value == 'test'</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
header | ||
</th> | ||
<td> | ||
map(string, list(string)) | ||
</td> | ||
<td> | ||
This is the request Header. | ||
</td> | ||
<td> | ||
<pre>header['X-Test'][0] == 'test-value'</pre> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
NOTE: The header value is a Go `http.Header`, which is [defined](https://golang.org/pkg/net/http/#Header) as: | ||
|
||
```go | ||
type Header map[string][]string | ||
``` | ||
|
||
i.e. the header is a mapping of strings, to arrays of strings, see the `match` | ||
function on headers below for an extension that makes looking up headers easier. | ||
|
||
|
||
### List of extension functions | ||
|
||
This lists custom functions that can be used from CEL expressions in the | ||
CEL interceptor. | ||
|
||
<table style="width=100%" border="1"> | ||
<tr> | ||
<th>Symbol</th> | ||
<th>Type</th> | ||
<th>Description</th> | ||
<th>Example</th> | ||
</tr> | ||
<tr> | ||
<th> | ||
match | ||
</th> | ||
<td> | ||
header.(string, string) -> bool | ||
</td> | ||
<td> | ||
Uses the canonical header matching from Go's http.Request to match the header against the value. | ||
</td> | ||
<td> | ||
<pre>header.match('x-test', 'test-value')</pre> | ||
</td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
examples/eventlisteners/cel-eventlistener-interceptor.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: cel-listener-interceptor | ||
spec: | ||
serviceAccountName: tekton-triggers-example-sa | ||
triggers: | ||
- name: cel-trig | ||
interceptor: | ||
cel: | ||
filter: "headers.match('X-GitHub-Event', 'push')" | ||
bindings: | ||
- name: pipeline-binding | ||
template: | ||
name: pipeline-template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.