setup_yaml_for_env_vars()

Configures the YAML Loader to do replacement of environment variables. It will replace YAML value strings such as '${HOST}' and '${PORT:80}' with environment variable lookups. In the first example, '${HOST}', it will replace the string with the value from doing os.getenv("HOST"). If the environment variable 'HOST" is not set, an exception will be thrown. In the second example, '${PORT:80}', we are doing the same but looking up `os.getenv("PORT"). In this case, if the 'PORT' environment variable is not set, it will use the default value shows, which in this case is '80'.

Source code in wiseagents/yaml/wise_yaml_loader.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def setup_yaml_for_env_vars():
    """
    Configures the YAML Loader to do replacement of environment variables.
    It will replace YAML value strings such as '${HOST}' and '${PORT:80}' with environment
    variable lookups.
    In the first example, '${HOST}', it will replace the string with the value from doing
    `os.getenv("HOST")`. If the environment variable 'HOST" is not set, an exception will be thrown.
    In the second example, '${PORT:80}', we are doing the same but looking up `os.getenv("PORT"). In this case,
    if the 'PORT' environment variable is not set, it will use the default value shows, which in this case is '80'.
    """
    yaml.add_implicit_resolver(f"!{_env_var_token}", _env_pattern)
    yaml.add_constructor(f"!{_env_var_token}", _env_constructor)

    yaml.add_implicit_resolver(f"!{_env_var_token}", _env_pattern, Loader=WiseAgentsLoader)
    yaml.add_constructor(f"!{_env_var_token}", _env_constructor, Loader=WiseAgentsLoader)