Skip to content

Instantly share code, notes, and snippets.

@mkaranasou
Created October 5, 2019 12:26
Show Gist options
  • Select an option

  • Save mkaranasou/17d57d7afe0509aa323b215beb5a7fd0 to your computer and use it in GitHub Desktop.

Select an option

Save mkaranasou/17d57d7afe0509aa323b215beb5a7fd0 to your computer and use it in GitHub Desktop.
The function to be provided as an environment variable resolver
def constructor_env_variables(loader, node):
"""
Extracts the environment variable from the node's value
:param yaml.Loader loader: the yaml loader
:param node: the current node in the yaml
:return: the parsed string that contains the value of the environment
variable
"""
value = loader.construct_scalar(node)
match = pattern.findall(value)
if match:
full_value = value
for g in match:
full_value = full_value.replace(
f'${{{g}}}', os.environ.get(g, g)
)
return full_value
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment