Skip to content

Commit

Permalink
Bump to using latest cel-go version, this brings in a new Strings lib…
Browse files Browse the repository at this point in the history
…rary.

Migrate the Triggers extensions to a CEL library.

This is a breaking change, CEL expressions will need to be updated to reflect this change.
  • Loading branch information
bigkevmcd authored and tekton-robot committed May 5, 2020
1 parent 9ab5a12 commit 4f63b78
Show file tree
Hide file tree
Showing 188 changed files with 24,885 additions and 93,746 deletions.
61 changes: 41 additions & 20 deletions docs/cel_expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ In addition to the custom function extension listed below, you can craft any
valid CEL expression as defined by the
[cel-spec language definition](https://github.com/google/cel-spec/blob/master/doc/langdef.md)

## String functions

The [upstream CEL implementation](https://github.com/google/cel-go/) provides
extensions to the CEL specification for manipulating strings.

For example:

```javascript
'refs/heads/master'.split('/') // result = list ['refs', 'heads', 'master']
'my place'.replace('my ',' ') // result = string 'place'
'this that another'.replace('th ',' ', 2) // result = 'is at another'
```

The `replace` overload allows an optional limit on replacements.

## Notes on numbers in CEL expressions

One thing to be aware of is how numeric values are treated in CEL expressions,
Expand All @@ -29,7 +44,7 @@ For example:
}
```

In the JSON above, both numbers are parsed as floating point values.
In the JSON above, both numbers are parsed as CEL double (Go float64) values.

This means that if you want to do integer arithmetic, you'll need to
[use explicit conversion functions](https://github.com/google/cel-spec/blob/master/doc/langdef.md#numeric-values).
Expand Down Expand Up @@ -79,6 +94,11 @@ interceptors:
`failed to evaluate overlay expression 'body.measure * 3': no such overload`
because there's no automatic conversion.

## cel-go extensions

All the functionality from the cel-go project's [String extension](https://github.com/google/cel-go/tree/master/ext) is available in
your CEL expressions.

## List of extensions

The body from the `http.Request` value is decoded to JSON and exposed, and the
Expand Down Expand Up @@ -157,67 +177,68 @@ interceptor.
<pre>header.match('x-test', 'test-value')</pre>
</td>
</tr>
<tr>
</tr>
<th>
truncate
canonical
</th>
<td>
truncate(string, uint) -> string
header.canonical(string) -> string
</td>
<td>
Truncates a string to no more than the specified length.
Uses the canonical header matching from Go's http.Request to get the provided header name.
</td>
<td>
<pre>truncate(body.commit.sha, 5)</pre>
<pre>header.canonical('x-test')</pre>
</td>
</tr>
<tr>
<th>
split
truncate
</th>
<td>
split(string, string) -> string(dyn)
<string>.truncate(uint) -> string
</td>
<td>
Splits a string on the provided separator value.
Truncates a string to no more than the specified length.
</td>
<td>
<pre>split(body.ref, '/')</pre>
<pre>body.commit.sha.truncate(5)</pre>
</td>
</tr>
<tr>
<th>
canonical
split
</th>
<td>
header.canonical(string) -> string
<string>.split(string) -> string(dyn)
</td>
<td>
Uses the canonical header matching from Go's http.Request to get the provided header name.
Splits a string on the provided separator value.
</td>
<td>
<pre>header.canonical('x-test')</pre>
<pre>body.ref.split('/')</pre>
</td>
</tr>
<tr>
<th>
decodeb64
</th>
<td>
(string) -> string
<string>.decodeb64() -> string
</td>
<td>
Decodes a base64 encoded string.
</td>
<td>
<pre>decodeb64(body.message.data)</pre>
<pre>body.message.data.decodeb64()</pre>
</td>
</tr>
<tr>
<th>
compareSecret
</th>
<td>
string.compareSecret(string, string, string) -> bool
<string>.compareSecret(string, string, string) -> bool
</td>
<td>
Constant-time comparison of strings against secrets, this will fetch the secret using the combination of namespace/name and compare the token key to the string using a cryptographic constant-time comparison..<p>
Expand All @@ -232,7 +253,7 @@ interceptor.
compareSecret
</th>
<td>
string.compareSecret(string, string) -> bool
<string>.compareSecret(string, string) -> bool
</td>
<td>
This is almost identical to the version above, but only requires two arguments, the namespace is assumed to be the namespace for the event-listener.
Expand All @@ -243,10 +264,10 @@ interceptor.
</tr>
<tr>
<th>
parseJSON
parseJSON()
</th>
<td>
parseJSON(string) -> map
<string>.parseJSON() -> map
</td>
<td>
This parses a string that contains a JSON body into a map which which can be subsequently used in other expressions.
Expand Down
10 changes: 5 additions & 5 deletions docs/eventlisteners.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ spec:
filter: "header.match('X-GitHub-Event', 'pull_request')"
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
bindings:
- name: pipeline-binding
template:
Expand Down Expand Up @@ -477,7 +477,7 @@ spec:
filter: "header.match('X-GitHub-Event', 'pull_request')"
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
bindings:
- name: pipeline-binding
template:
Expand Down Expand Up @@ -512,7 +512,7 @@ spec:
- cel:
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
bindings:
- name: pipeline-binding
template:
Expand All @@ -539,9 +539,9 @@ spec:
- cel:
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
- key: extensions.branch_name
expression: "split(body.ref, '/')[2]"
expression: "body.ref.split('/')[2]"
bindings:
- name: pipeline-binding
template:
Expand Down
2 changes: 1 addition & 1 deletion examples/eventlisteners/cel-eventlistener-interceptor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
filter: "header.match('X-GitHub-Event', 'pull_request')"
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
bindings:
- name: pipeline-binding
template:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ spec:
- cel:
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
- key: extensions.branch_name
expression: "split(body.ref, '/')[2]"
expression: "body.ref.split('/')[2]"
bindings:
- name: pipeline-binding
template:
Expand Down
2 changes: 1 addition & 1 deletion examples/eventlisteners/cel-eventlistener-no-filter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
- cel:
overlays:
- key: extensions.truncated_sha
expression: "truncate(body.pull_request.head.sha, 7)"
expression: "body.pull_request.head.sha.truncate(7)"
bindings:
- name: pipeline-binding
template:
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
contrib.go.opencensus.io/exporter/stackdriver v0.12.9 // indirect
github.com/GoogleCloudPlatform/cloud-builders/gcs-fetcher v0.0.0-20191203181535-308b93ad1f39
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/golang/protobuf v1.3.3
github.com/google/cel-go v0.3.2
github.com/golang/protobuf v1.3.4
github.com/google/cel-go v0.4.2
github.com/google/go-cmp v0.4.0
github.com/google/go-github/v31 v31.0.0
github.com/gorilla/mux v1.7.3
Expand All @@ -22,7 +22,7 @@ require (
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03
google.golang.org/genproto v0.0.0-20200305110556-506484158171
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.18.2
k8s.io/apimachinery v0.18.2
Expand Down
17 changes: 14 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,15 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/cel-go v0.3.2 h1:72Lj/nrfpWSJkuXdeEGB/7jfdwVFtV8kPJSL2Mt9rog=
github.com/google/cel-go v0.3.2/go.mod h1:DoRSdzaJzNiP1lVuWhp/RjSnHLDQr/aNPlyqSBasBqA=
github.com/google/cel-spec v0.3.0/go.mod h1:MjQm800JAGhOZXI7vatnVpmIaFTR6L8FHcKk+piiKpI=
github.com/google/cel-go v0.4.2 h1:Fx1DQPo05qFcDst4TwiGgFfmTjjHsLLbLYQGX67QYUk=
github.com/google/cel-go v0.4.2/go.mod h1:0pIisECLUDurNyQcYRcNjhGp0j/yM6v617EmXsBJE3A=
github.com/google/cel-spec v0.4.0/go.mod h1:2pBM5cU4UKjbPDXBgwWkiwBsVgnxknuEJ7C5TDWwORQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -572,6 +574,8 @@ golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -616,6 +620,8 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191119060738-e882bf8e40c2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -701,6 +707,8 @@ google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBr
google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 h1:4HYDjxeNXAOTv3o1N2tjo8UUSlhQgAD52FVkwxnWgM8=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20200305110556-506484158171 h1:xes2Q2k+d/+YNXVw0FpZkIDJiaux4OVrRKXRAzH6A0U=
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand All @@ -714,6 +722,9 @@ google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading

0 comments on commit 4f63b78

Please sign in to comment.