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

Method ToConfig

cel/env.go:255–416  ·  view source on GitHub ↗

ToConfig produces a YAML-serializable env.Config object from the given environment. The serialized configuration value is intended to represent a baseline set of config options which could be used as input to an EnvOption to configure the majority of the environment from a file. Note: validators,

(name string)

Source from the content-addressed store, hash-verified

253// and the standard expression components (parse, check, evalute), they are also not
254// supported by the serialize method.
255func (e *Env) ToConfig(name string) (*env.Config, error) {
256 conf := env.NewConfig(name)
257 // Container settings
258 if e.Container != containers.DefaultContainer {
259 conf.SetContainer(e.Container.Name())
260 }
261 for _, typeName := range e.Container.AliasSet() {
262 conf.AddImports(env.NewImport(typeName))
263 }
264
265 // Serialize features
266 for featID, enabled := range e.features {
267 featName, found := featureNameByID(featID)
268 if !found {
269 // If the feature isn't named, it isn't intended to be publicly exposed
270 continue
271 }
272 conf.AddFeatures(env.NewFeature(featName, enabled))
273 }
274
275 libOverloads := map[string][]string{}
276 for libName, lib := range e.libraries {
277 // Track the options which have been configured by a library and
278 // then diff the library version against the configured function
279 // to detect incremental overloads or rewrites.
280 libEnv, err := NewCustomEnv()
281 if err != nil {
282 return nil, err
283 }
284 libEnv, err = Lib(lib)(libEnv)
285 if err != nil {
286 return nil, err
287 }
288 for fnName, fnDecl := range libEnv.Functions() {
289 if len(fnDecl.OverloadDecls()) == 0 {
290 continue
291 }
292 overloads, exist := libOverloads[fnName]
293 if !exist {
294 overloads = make([]string, 0, len(fnDecl.OverloadDecls()))
295 }
296 for _, o := range fnDecl.OverloadDecls() {
297 overloads = append(overloads, o.ID())
298 }
299 libOverloads[fnName] = overloads
300 }
301 subsetLib, canSubset := lib.(LibrarySubsetter)
302 alias := ""
303 if aliasLib, canAlias := lib.(LibraryAliaser); canAlias {
304 alias = aliasLib.LibraryAlias()
305 libName = alias
306 }
307 if libName == "stdlib" && canSubset {
308 conf.SetStdLib(subsetLib.LibrarySubset())
309 continue
310 }
311 version := uint32(math.MaxUint32)
312 if versionLib, isVersioned := lib.(LibraryVersioner); isVersioned {

Callers 3

initCheckerMethod · 0.95
TestEnvToConfigFunction · 0.95

Calls 15

SetContainerMethod · 0.95
AddImportsMethod · 0.95
AddFeaturesMethod · 0.95
FunctionsMethod · 0.95
SetStdLibMethod · 0.95
AddExtensionsMethod · 0.95
HasLibraryMethod · 0.95
VariablesMethod · 0.95
SetContextVariableMethod · 0.95
HasFeatureMethod · 0.95
AddVariableDeclsMethod · 0.95
AddFunctionDeclsMethod · 0.95

Tested by 2

TestEnvToConfigFunction · 0.76