(pbEnv *configpb.Environment)
| 359 | } |
| 360 | |
| 361 | func envToStdLib(pbEnv *configpb.Environment) (*env.LibrarySubset, error) { |
| 362 | stdLib := env.NewLibrarySubset() |
| 363 | pbEnvStdLib := pbEnv.GetStdlib() |
| 364 | if pbEnvStdLib == nil { |
| 365 | if pbEnv.GetDisableStandardCelDeclarations() { |
| 366 | stdLib.SetDisabled(true) |
| 367 | return stdLib, nil |
| 368 | } |
| 369 | return nil, nil |
| 370 | } |
| 371 | if !stdLib.Disabled { |
| 372 | stdLib.SetDisabled(pbEnvStdLib.GetDisabled()) |
| 373 | } |
| 374 | stdLib.SetDisableMacros(pbEnvStdLib.GetDisableMacros()) |
| 375 | stdLib.AddIncludedMacros(pbEnvStdLib.GetIncludeMacros()...) |
| 376 | stdLib.AddExcludedMacros(pbEnvStdLib.GetExcludeMacros()...) |
| 377 | if pbEnvStdLib.GetIncludeFunctions() != nil { |
| 378 | for _, includeFn := range pbEnvStdLib.GetIncludeFunctions() { |
| 379 | if includeFn.GetFunction() != nil { |
| 380 | fn, err := protoDeclToFunction(includeFn) |
| 381 | if err != nil { |
| 382 | return nil, err |
| 383 | } |
| 384 | stdLib.AddIncludedFunctions(fn) |
| 385 | } else { |
| 386 | return nil, fmt.Errorf("IncludeFunctions must specify a function decl") |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | if pbEnvStdLib.GetExcludeFunctions() != nil { |
| 391 | for _, excludeFn := range pbEnvStdLib.GetExcludeFunctions() { |
| 392 | if excludeFn.GetFunction() != nil { |
| 393 | fn, err := protoDeclToFunction(excludeFn) |
| 394 | if err != nil { |
| 395 | return nil, err |
| 396 | } |
| 397 | stdLib.AddExcludedFunctions(fn) |
| 398 | } else { |
| 399 | return nil, fmt.Errorf("ExcludeFunctions must specify a function decl") |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | return stdLib, nil |
| 404 | } |
| 405 | |
| 406 | func protoDeclToFunction(decl *celpb.Decl) (*env.Function, error) { |
| 407 | declFn := decl.GetFunction() |
no test coverage detected