CELMatcherRuntimeFunction creates a function binding for when the input to the matcher is dynamically resolved rather than a set of static constant values.
(funcName string, fac any)
| 552 | // CELMatcherRuntimeFunction creates a function binding for when the input to the matcher |
| 553 | // is dynamically resolved rather than a set of static constant values. |
| 554 | func CELMatcherRuntimeFunction(funcName string, fac any) functions.BinaryOp { |
| 555 | return func(celReq, matcherData ref.Val) ref.Val { |
| 556 | if factory, ok := fac.(CELMatcherWithErrorFactory); ok { |
| 557 | matcher, err := factory(matcherData) |
| 558 | if err != nil { |
| 559 | return types.WrapErr(err) |
| 560 | } |
| 561 | httpReq := celReq.Value().(celHTTPRequest) |
| 562 | match, err := matcher.MatchWithError(httpReq.Request) |
| 563 | if err != nil { |
| 564 | return types.WrapErr(err) |
| 565 | } |
| 566 | return types.Bool(match) |
| 567 | } |
| 568 | if factory, ok := fac.(CELMatcherFactory); ok { |
| 569 | matcher, err := factory(matcherData) |
| 570 | if err != nil { |
| 571 | return types.WrapErr(err) |
| 572 | } |
| 573 | httpReq := celReq.Value().(celHTTPRequest) |
| 574 | if m, ok := matcher.(RequestMatcherWithError); ok { |
| 575 | match, err := m.MatchWithError(httpReq.Request) |
| 576 | if err != nil { |
| 577 | return types.WrapErr(err) |
| 578 | } |
| 579 | return types.Bool(match) |
| 580 | } |
| 581 | return types.Bool(matcher.Match(httpReq.Request)) |
| 582 | } |
| 583 | return types.NewErr("CELMatcherRuntimeFunction invalid matcher factory: %T", fac) |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | // celMatcherStringListMacroExpander validates that the macro is called |
| 588 | // with a variable number of string arguments (at least one). |
no test coverage detected