Update yaml parser for handling environment variables (#1967)

This commit is contained in:
Brent 2016-05-03 20:41:14 -05:00 committed by Paulus Schoutsen
parent 298b9d1f12
commit 34193de158

View file

@ -64,6 +64,17 @@ def _ordered_dict(loader, node):
return OrderedDict(nodes)
def _env_var_yaml(loader, node):
"""Load environment variables and embed it into the configuration YAML."""
if node.value in os.environ:
return os.environ[node.value]
else:
_LOGGER.error("Environment variable %s not defined.", node.value)
raise HomeAssistantError(node.value)
yaml.SafeLoader.add_constructor('!include', _include_yaml)
yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
_ordered_dict)
yaml.SafeLoader.add_constructor('!env_var', _env_var_yaml)