-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for splitting strings to CEL expressions. #411
Conversation
This could easily be flipped to become |
Yeah, I think I like |
This adds an additional CEL function for splitting strings on a separator. e.g. split(body.ref, '/') would split the ref on '/' and return a list of strings.
3ffab04
to
ab31468
Compare
really, really need this function to be able to mutate values and capture them as new fields (overlay) in the body. Please merge at least into the master so I can start playing with it. thanks! |
Thanks for adding this, complete with tests cases and docs @bigkevmcd !! This seems fine but I think it would be worth a larger conversation about how many of these custom functions we want to support. Shameless plug for Rego, looks like it comes with a number of string manipulation functions built in: https://www.openpolicyagent.org/docs/latest/policy-reference/#strings Related: @wlynch feature request for string splitting google/cel-go#306 /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bobcatfish The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@bobcatfish I agree, would be great if some bridge could be developed to just expose functions available in other libraries that would not have to be directly maintained by tekton. i.e. like how helm exposes all the go template functions provided by sprig (http://masterminds.github.io/sprig/) greatly enhancing the capabilities. if another lib like you suggested could be added to expose much more CEL string manipulation functions that would be awesome! |
@bobcatfish yes, I'd like to deprecate Other than that, I can't see many more items being added, splitting strings, decoding base64 and trimming strings are the things that I wanna do in my pipelines, but clearly, there might be other useful things, we're dealing with broadly the same data across different environments. I currently have no plans for further functions, but it's fairly easy to add them... :-) |
Agreed. I think we need base64 (for things like pub/sub events that are base64 encoded); trimming strings (tags, commits, refs). The header one is interesting...mainly due to how go represents header values as a array of strings. Other than these 3, I don't see any new ones in the short term! |
is there a nightly release I can point to that has this? or i'll have to build it all and deploy locally? |
Hey everyone, awesome to see CEL being embraced in the wild. I am totally open to reviewing PRs for google/cel-go#306 if that would help accelerate your project. |
is this not possible?
|
No, see #367 But, you can use the CEL interceptor, without actually intercepting, and use the overlay function there. Something like this should work: apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: listener-interceptor
spec:
triggers:
- name: demo-trigger
interceptors:
- cel:
overlays:
- key: intercepted.appName
expression: "split(body.action_values[0],'_')[1]"
bindings:
- name: deploy
template:
name: deploy-template Then you could use the value like this: apiVersion: tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: deploy
spec:
params:
- name: appName
value: $(body.intercepted.appName) |
BTW, I created google/cel-go#316, so if your favorite string function isn't there, just let me know and I'll see if I can get it in. |
@bigkevmcd yep thats what i ended up doing, thanks! |
@TristonianJones would be great to have a i need to take a value and replace looks like it will be in go-cel eventually w/ google/cel-go#316 |
Remove patch changes related to disabling EL to run as https
Changes
This adds an additional CEL function for splitting strings on a separator.
e.g. body.ref.split('/') would split the ref on '/' and return a list of strings.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Release Notes