Datatype that represents YAML with substituted variables.
If YAML has value that starts with an $
, then such value is treated as a variable from config_vars
. For example if config_vars
contains variable: 42
and the YAML is following:
Then the result of yaml["some_element"]["some"].As<int>()
is 42
.
If YAML key ends on '#env' and the mode is YamlConfig::Mode::kEnvAllowed, then the value of the key is searched in environment variables of the process and returned as a value. For example:
If YAML key ends on '#fallback', then the value of the key is used as a fallback for environment and $
variables. For example for the following YAML with YamlConfig::Mode::kEnvAllowed:
The result of yaml["some_element"]["some"].As<int>()
is the value of variable
from config_vars
if it exists; otherwise the value is the contents of the environment variable SOME_ENV_VARIABLE
if it exists; otherwise the value if 100500
, from the fallback.
Another example:
With YamlConfig::Mode::kEnvAllowed the result of yaml["some_element"]["value"].As<int>()
is the value of ENV_NAME
environment variable if it exists; otherwise it is 5
.
- Warning
- YamlConfig::Mode::kEnvAllowed should be used only on configs that come from trusted environments. Otherwise, an attacker could create a config with
#env
and read any of your environment variables, including variables that contain passwords and other sensitive data.
Definition at line 60 of file yaml_config.hpp.