MCPcopy Create free account
hub / github.com/cel-expr/cel-go / configToEnvOptions

Function configToEnvOptions

cel/options.go:554–672  ·  view source on GitHub ↗

configToEnvOptions generates a set of EnvOption values (or error) based on a config, a type provider, and an optional set of environment options.

(config *env.Config, provider types.Provider, optFactories []ConfigOptionFactory)

Source from the content-addressed store, hash-verified

552// configToEnvOptions generates a set of EnvOption values (or error) based on a config, a type provider,
553// and an optional set of environment options.
554func configToEnvOptions(config *env.Config, provider types.Provider, optFactories []ConfigOptionFactory) ([]EnvOption, error) {
555 envOpts := []EnvOption{}
556 // Configure the standard lib subset.
557 if config.StdLib != nil {
558 envOpts = append(envOpts, func(e *Env) (*Env, error) {
559 if e.HasLibrary("cel.lib.std") {
560 return nil, errors.New("invalid subset of stdlib: create a custom env")
561 }
562 return e, nil
563 })
564 if !config.StdLib.Disabled {
565 envOpts = append(envOpts, StdLib(StdLibSubset(config.StdLib)))
566 }
567 } else {
568 envOpts = append(envOpts, StdLib())
569 }
570
571 // Configure the container
572 if config.Container != "" {
573 envOpts = append(envOpts, Container(config.Container))
574 }
575
576 // Configure abbreviations
577 for _, imp := range config.Imports {
578 envOpts = append(envOpts, Abbrevs(imp.Name))
579 }
580
581 // Configure features and common limits.
582 for _, feat := range config.Features {
583 // Note, if a feature is not found, it is skipped as it is possible the feature
584 // is not intended to be supported publicly. In the future, a refinement of
585 // to this strategy to report unrecognized features and validators should probably
586 // be covered as a standard ConfigOptionFactory
587 if id, found := featureIDByName(feat.Name); found {
588 envOpts = append(envOpts, features(id, feat.Enabled))
589 }
590 }
591
592 // Configure the context variable declaration
593 if config.ContextVariable != nil {
594 typeName := config.ContextVariable.TypeName
595 if _, found := provider.FindStructType(typeName); !found {
596 return nil, fmt.Errorf("invalid context proto type: %q", typeName)
597 }
598 // Attempt to instantiate the proto in order to reflect to its descriptor
599 msg := provider.NewValue(typeName, map[string]ref.Val{})
600 pbMsg, ok := msg.Value().(proto.Message)
601 if !ok {
602 return nil, fmt.Errorf("unsupported context type: %T", msg.Value())
603 }
604 envOpts = append(envOpts, DeclareContextProto(pbMsg.ProtoReflect().Descriptor()))
605 }
606
607 // Configure variables
608 if len(config.Variables) != 0 {
609 vars := make([]*decls.VariableDecl, 0, len(config.Variables))
610 for _, v := range config.Variables {
611 vDef, err := v.AsCELVariable(provider)

Callers 1

FromConfigFunction · 0.85

Calls 15

StdLibFunction · 0.85
StdLibSubsetFunction · 0.85
featureIDByNameFunction · 0.85
featuresFunction · 0.85
DeclareContextProtoFunction · 0.85
VariableDeclsFunction · 0.85
FunctionDeclsFunction · 0.85
limitIDByNameFunction · 0.85
setLimitFunction · 0.85
ASTValidatorsFunction · 0.85
OptionalTypesFunction · 0.85

Tested by

no test coverage detected