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

Function configToEnvOptions

cel/options.go:566–684  ·  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

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