Skip to content
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

Constrain acceptable any values #905

Open
2 tasks done
jacobmikesell opened this issue Mar 13, 2024 · 2 comments
Open
2 tasks done

Constrain acceptable any values #905

jacobmikesell opened this issue Mar 13, 2024 · 2 comments

Comments

@jacobmikesell
Copy link

jacobmikesell commented Mar 13, 2024

Feature request checklist

  • There are no issues that match the desired change
  • The change is large enough it can't be addressed with a simple Pull Request

Change
Summary of the proposed change and some details about what problem
it helps solve.

We make use of "Any" protos for several api's where the list of expected/possible types is known a priori. A key example of this is googles LongRunning service and associated rpcs. Today we are unable to inform the cel env that while the type of the any can vary it should only vary among a subset of possible types (which lets some bad filters execute, for example comparing ints to strings in the underlying message)

Example
This may currently be possible (and I'm just uninformed) but we'd like to be able to tell the cel environment something akin to

cel.Variable("any_var", cel.UnionAnyType(proto_one{}, proto_two{}))

Alternatives considered
None

@TristonianJones
Copy link
Collaborator

This is actually really hard to do within CEL; however, you could have a base environment which you extend M times (once per Any) which declares the variable with a concrete type. Effectively if any of the M environments compiles the expression without a failure, then it's a valid expression. Very hacky and not very fun to implement, but it would work.

@jacobmikesell
Copy link
Author

jacobmikesell commented Mar 13, 2024

That would work for parse/check but for Eval that would end up failing due to the types not matching right?

effectively something like

var possibleEnvs := map[type]cel.Env{}

//parse/check against both `Any` and `Concrete`
ast, issues := possibleEnvs[Any].Compile()
...
_, issues := possibleEnvs[Concrete].Compile()
//if either have issues return

possibleEnvs[Any].Program(ast)
...

would be needed to fully hack around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants