Created
October 5, 2019 12:26
-
-
Save mkaranasou/17d57d7afe0509aa323b215beb5a7fd0 to your computer and use it in GitHub Desktop.
The function to be provided as an environment variable resolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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