From 09a096bbea94131d68e6e2a3e66df1fa09f1b761 Mon Sep 17 00:00:00 2001 From: Adrien Candiotti Date: Tue, 4 Feb 2014 03:59:28 -0800 Subject: [PATCH 1/2] add - env variable expand --- fig/cli/command.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fig/cli/command.py b/fig/cli/command.py index c60020d7503..3a7ea03c237 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -33,11 +33,18 @@ def dispatch(self, *args, **kwargs): def client(self): return Client(docker_url()) + def __expand_env_variables(self, yaml_path): + file_content = open(yaml_path).read() + for k, v in os.environ.iteritems(): + if file_content.find('$' + k) != -1: + file_content = file_content.replace('$' + k, v) + return file_content + @cached_property def project(self): try: yaml_path = self.check_yaml_filename() - config = yaml.load(open(yaml_path)) + config = yaml.load(self.__expand_env_variables(yaml_path)) except IOError as e: if e.errno == errno.ENOENT: From f81b3756989b4bf84b8566268f03dfd11a0fc2c7 Mon Sep 17 00:00:00 2001 From: Adrien Candiotti Date: Tue, 4 Feb 2014 04:05:49 -0800 Subject: [PATCH 2/2] mod - cleaner standard way to expand env variables --- fig/cli/command.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fig/cli/command.py b/fig/cli/command.py index 3a7ea03c237..48430bd9995 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -33,18 +33,11 @@ def dispatch(self, *args, **kwargs): def client(self): return Client(docker_url()) - def __expand_env_variables(self, yaml_path): - file_content = open(yaml_path).read() - for k, v in os.environ.iteritems(): - if file_content.find('$' + k) != -1: - file_content = file_content.replace('$' + k, v) - return file_content - @cached_property def project(self): try: yaml_path = self.check_yaml_filename() - config = yaml.load(self.__expand_env_variables(yaml_path)) + config = yaml.load(os.path.expandvars(open(yaml_path).read())) except IOError as e: if e.errno == errno.ENOENT: