NewCustomEnv creates a custom program environment which is not automatically configured with the standard library of functions and macros documented in the CEL spec. The purpose for using a custom environment might be for subsetting the standard library produced by the cel.StdLib() function. Subset
(opts ...EnvOption)
| 445 | // See the EnvOption helper functions for the options that can be used to configure the |
| 446 | // environment. |
| 447 | func NewCustomEnv(opts ...EnvOption) (*Env, error) { |
| 448 | registry, err := types.NewRegistry() |
| 449 | if err != nil { |
| 450 | return nil, err |
| 451 | } |
| 452 | return (&Env{ |
| 453 | variables: []*decls.VariableDecl{}, |
| 454 | functions: map[string]*decls.FunctionDecl{}, |
| 455 | macros: []parser.Macro{}, |
| 456 | Container: containers.DefaultContainer, |
| 457 | adapter: registry, |
| 458 | provider: registry, |
| 459 | features: map[int]bool{}, |
| 460 | appliedFeatures: map[int]bool{}, |
| 461 | limits: map[limitID]int{}, |
| 462 | libraries: map[string]SingletonLibrary{}, |
| 463 | validators: []ASTValidator{}, |
| 464 | progOpts: []ProgramOption{}, |
| 465 | costOptions: []cost.Option{}, |
| 466 | costConfig: &costConfig{}, |
| 467 | }).configure(opts) |
| 468 | } |
| 469 | |
| 470 | // Check performs type-checking on the input Ast and yields a checked Ast and/or set of Issues. |
| 471 | // If any `ASTValidators` are configured on the environment, they will be applied after a valid |