CELLibrary produces options that expose this matcher for use in CEL expression matchers. Example: expression vars_regexp('foo', '{magic_number}', '[0-9]+') expression vars_regexp('{magic_number}', '[0-9]+')
(ctx caddy.Context)
| 362 | // expression vars_regexp('foo', '{magic_number}', '[0-9]+') |
| 363 | // expression vars_regexp('{magic_number}', '[0-9]+') |
| 364 | func (MatchVarsRE) CELLibrary(ctx caddy.Context) (cel.Library, error) { |
| 365 | unnamedPattern, err := CELMatcherImpl( |
| 366 | "vars_regexp", |
| 367 | "vars_regexp_request_string_string", |
| 368 | []*cel.Type{cel.StringType, cel.StringType}, |
| 369 | func(data ref.Val) (RequestMatcherWithError, error) { |
| 370 | refStringList := stringSliceType |
| 371 | params, err := data.ConvertToNative(refStringList) |
| 372 | if err != nil { |
| 373 | return nil, err |
| 374 | } |
| 375 | strParams := params.([]string) |
| 376 | matcher := MatchVarsRE{} |
| 377 | matcher[strParams[0]] = &MatchRegexp{ |
| 378 | Pattern: strParams[1], |
| 379 | Name: ctx.Value(MatcherNameCtxKey).(string), |
| 380 | } |
| 381 | err = matcher.Provision(ctx) |
| 382 | return matcher, err |
| 383 | }, |
| 384 | ) |
| 385 | if err != nil { |
| 386 | return nil, err |
| 387 | } |
| 388 | namedPattern, err := CELMatcherImpl( |
| 389 | "vars_regexp", |
| 390 | "vars_regexp_request_string_string_string", |
| 391 | []*cel.Type{cel.StringType, cel.StringType, cel.StringType}, |
| 392 | func(data ref.Val) (RequestMatcherWithError, error) { |
| 393 | refStringList := stringSliceType |
| 394 | params, err := data.ConvertToNative(refStringList) |
| 395 | if err != nil { |
| 396 | return nil, err |
| 397 | } |
| 398 | strParams := params.([]string) |
| 399 | name := strParams[0] |
| 400 | if name == "" { |
| 401 | name = ctx.Value(MatcherNameCtxKey).(string) |
| 402 | } |
| 403 | matcher := MatchVarsRE{} |
| 404 | matcher[strParams[1]] = &MatchRegexp{ |
| 405 | Pattern: strParams[2], |
| 406 | Name: name, |
| 407 | } |
| 408 | err = matcher.Provision(ctx) |
| 409 | return matcher, err |
| 410 | }, |
| 411 | ) |
| 412 | if err != nil { |
| 413 | return nil, err |
| 414 | } |
| 415 | envOpts := append(unnamedPattern.CompileOptions(), namedPattern.CompileOptions()...) |
| 416 | prgOpts := append(unnamedPattern.ProgramOptions(), namedPattern.ProgramOptions()...) |
| 417 | return NewMatcherCELLibrary(envOpts, prgOpts), nil |
| 418 | } |
| 419 | |
| 420 | // Validate validates m's regular expressions. |
| 421 | func (m MatchVarsRE) Validate() error { |
nothing calls this directly
no test coverage detected