2626#include " absl/base/no_destructor.h"
2727#include " absl/container/flat_hash_map.h"
2828#include " absl/container/flat_hash_set.h"
29+ #include " absl/log/absl_check.h"
2930#include " absl/status/status.h"
3031#include " absl/status/statusor.h"
3132#include " absl/strings/escaping.h"
@@ -1245,6 +1246,34 @@ void EmitFunctionConfigs(const Config& env_config, YAML::Emitter& out,
12451246 }
12461247 out << YAML ::EndSeq;
12471248}
1249+
1250+ absl::Status ParseContextVariableConfig (Config& config, absl::string_view yaml,
1251+ const YAML ::Node& root) {
1252+ const YAML ::Node context_variable = root[" context_variable" ];
1253+ if (!context_variable.IsDefined ()) {
1254+ return absl::OkStatus ();
1255+ }
1256+ if (!context_variable.IsMap ()) {
1257+ return YamlError (yaml, context_variable,
1258+ " Node 'context_variable' is not a map" );
1259+ }
1260+
1261+ const YAML ::Node type_name = context_variable[" type_name" ];
1262+ const YAML ::Node type = context_variable[" type" ];
1263+ const YAML ::Node* type_node = nullptr ;
1264+ if (type.IsDefined () && type.IsScalar ()) {
1265+ type_node = &type;
1266+ } else if (type_name.IsDefined () && type_name.IsScalar ()) {
1267+ type_node = &type_name;
1268+ } else {
1269+ return YamlError (yaml, context_variable,
1270+ " Node 'context_variable' does not have a valid type" );
1271+ }
1272+ ABSL_DCHECK (type_node != nullptr );
1273+ config.SetContextType (GetString (yaml, *type_node));
1274+ return absl::OkStatus ();
1275+ }
1276+
12481277} // namespace
12491278
12501279absl::StatusOr<Config> EnvConfigFromYaml (const std::string& yaml) {
@@ -1263,6 +1292,7 @@ absl::StatusOr<Config> EnvConfigFromYaml(const std::string& yaml) {
12631292 CEL_RETURN_IF_ERROR (ParseContainerConfig (config, yaml, root));
12641293 CEL_RETURN_IF_ERROR (ParseExtensionConfigs (config, yaml, root));
12651294 CEL_RETURN_IF_ERROR (ParseStandardLibraryConfig (config, yaml, root));
1295+ CEL_RETURN_IF_ERROR (ParseContextVariableConfig (config, yaml, root));
12661296 CEL_RETURN_IF_ERROR (ParseVariableConfigs (config, yaml, root));
12671297 CEL_RETURN_IF_ERROR (ParseFunctionConfigs (config, yaml, root));
12681298 return config;
0 commit comments