cloud-custodian / cel-python

Pure Python implementation of the Common Expression Language
Apache License 2.0
99 stars 20 forks source link

Support for extension functions #56

Open NoamSherr opened 3 months ago

NoamSherr commented 3 months ago

cel-go has support for the strings and math function extensions - is the extension supported? And if so how can it be set up in the environment ext/strings.go

slott56 commented 1 month ago

Yes.

Seen https://github.com/cloud-custodian/cel-python/blob/main/src/celpy/__init__.py which has a functions = {}. This is the mapping from a CEL-visible name to a Python function.

NoamSherr commented 1 month ago

Cool yeah I used it like that but it meant implementing the lambdas for the functions on my own - is there any intention of supporting the extensions that Go/Java have (String, Math and Optional) without the need for custom implementation? So expressions like the following could run as well - woops.title == "something" ? optional.none() : optional.of(woops.description) or my_string.upper() without the need to pass the functions dict to the celpy.Environment().program.

Additionally if I want the optional to be recognized as a namespace without declaring it as a var in the context (a bit "hack-ish") how can I do so? (with the existing functionality)