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

Fix cast process for cel plugin's list type argument #274

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions _examples/15_cel_plugin/federation/federation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 46 additions & 19 deletions _examples/15_cel_plugin/federation/federation_grpc_federation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion _examples/15_cel_plugin/proto/federation/federation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ message ExampleRequest{}

message ExampleResponse {
option (grpc.federation.message) = {
def { name: "v" by: "example.regexp.filterExamples(example.regexp.newExamples())" }
def { name: "exps" by: "example.regexp.newExamples()" }
def { name: "v" by: "example.regexp.filterExamples(exps)" }
def { name: "exp" by: "example.regexp.newExample()"}
def { name: "str" by: "exp.concat(exp.mySplit('/a/b/c', '/'))"}
};
Expand Down
9 changes: 7 additions & 2 deletions grpc/federation/cel/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ func (i *CELPluginInstance) refToCELPluginValue(typ *cel.Type, v ref.Val) (*plug
slice := reflect.ValueOf(v.Value())
list := &plugin.CELPluginListValue{}
for idx := 0; idx < slice.Len(); idx++ {
value, err := i.refToCELPluginValue(elemType, slice.Index(idx).Interface().(ref.Val))
src := slice.Index(idx).Interface()
val := i.celRegistry.NativeToValue(src)
if types.IsError(val) {
return nil, fmt.Errorf("failed to convert %T to CEL value: %v", src, val.Value())
}
value, err := i.refToCELPluginValue(elemType, val)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -442,7 +447,7 @@ func (i *CELPluginInstance) celPluginValueToRef(fn *CELFunction, typ *cel.Type,
values := make([]ref.Val, 0, len(v.GetList().GetValues()))
for _, vv := range v.GetList().GetValues() {
value := i.celPluginValueToRef(fn, elemType, vv)
if value.Type().TypeName() == types.ErrType.TypeName() {
if types.IsError(value) {
// return error value
return value
}
Expand Down
Loading