MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ParseVariableConfigs

Function ParseVariableConfigs

env/env_yaml.cc:504–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

502}
503
504absl::Status ParseVariableConfigs(Config& config, absl::string_view yaml,
505 const YAML::Node& root) {
506 const YAML::Node variables = root["variables"];
507 if (!variables.IsDefined()) {
508 return absl::OkStatus();
509 }
510 if (!variables.IsSequence()) {
511 return YamlError(yaml, variables, "Node 'variables' is not a sequence");
512 }
513
514 for (const YAML::Node& variable : variables) {
515 Config::VariableConfig variable_config;
516 if (!variable || !variable.IsMap()) {
517 return YamlError(yaml, variable, "Variable is not a map");
518 }
519 const YAML::Node name = variable["name"];
520 if (!name || !name.IsScalar()) {
521 return YamlError(yaml, name, "Variable name is not a string");
522 }
523 variable_config.name = GetString(yaml, name);
524 const YAML::Node description = variable["description"];
525 if (description.IsDefined()) {
526 if (!description.IsScalar()) {
527 return YamlError(yaml, description,
528 "Variable description is not a string");
529 }
530 variable_config.description = GetString(yaml, description);
531 }
532
533 CEL_ASSIGN_OR_RETURN(auto type_info, ParseTypeInfo(variable, yaml));
534 ConstantKindCase constant_kind_case = GetConstantKindCase(type_info.name);
535 std::string value_str;
536 YAML::Node value = variable["value"];
537 if (value.IsDefined()) {
538 if (constant_kind_case == ConstantKindCase::kUnspecified) {
539 return YamlError(yaml, value,
540 absl::StrCat("Constant type '", type_info.name,
541 "' is not supported"));
542 }
543 if (!value.IsScalar()) {
544 return YamlError(yaml, value, "Variable value is not a scalar");
545 }
546 if (IsBinary(value)) {
547 CEL_ASSIGN_OR_RETURN(value_str, GetBinary(yaml, value));
548 } else {
549 value_str = GetString(yaml, value);
550 }
551 }
552
553 variable_config.type_info = type_info;
554
555 if (constant_kind_case != ConstantKindCase::kUnspecified &&
556 !value_str.empty()) {
557 CEL_ASSIGN_OR_RETURN(
558 variable_config.value,
559 ParseConstantValue(yaml, value, constant_kind_case, value_str));
560 } else if (constant_kind_case == ConstantKindCase::kNull) {
561 variable_config.value = Constant(nullptr);

Callers 1

EnvConfigFromYamlFunction · 0.85

Calls 11

YamlErrorFunction · 0.85
GetStringFunction · 0.85
GetConstantKindCaseFunction · 0.85
IsBinaryFunction · 0.85
GetBinaryFunction · 0.85
ParseConstantValueFunction · 0.85
ConstantClass · 0.85
AddVariableConfigMethod · 0.80
CEL_ASSIGN_OR_RETURNFunction · 0.50
IsMapMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected