summaryrefslogtreecommitdiff
path: root/compose/config
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2019-10-03 15:46:49 +0200
committerFlorian Apolloner <florian@apolloner.eu>2020-01-28 16:33:28 +0100
commitf17e7268b0a7fd287bd8be3af61f9363222d2e07 (patch)
treec935af1fbcaa92975f92d5010dd734f6e3e39bf8 /compose/config
parent73551d5a92c93006ac3405ee60bb90a60da2900c (diff)
Properly escape values coming from env_files, fixes #6871
Signed-off-by: Florian Apolloner <florian@apolloner.eu>
Diffstat (limited to 'compose/config')
-rw-r--r--compose/config/config.py16
-rw-r--r--compose/config/environment.py3
2 files changed, 11 insertions, 8 deletions
diff --git a/compose/config/config.py b/compose/config/config.py
index 84933e9c..3bd49a0f 100644
--- a/compose/config/config.py
+++ b/compose/config/config.py
@@ -408,7 +408,7 @@ def load(config_details, compatibility=False, interpolate=True):
configs = load_mapping(
config_details.config_files, 'get_configs', 'Config', config_details.working_dir
)
- service_dicts = load_services(config_details, main_file, compatibility)
+ service_dicts = load_services(config_details, main_file, compatibility, interpolate=interpolate)
if main_file.version != V1:
for service_dict in service_dicts:
@@ -460,7 +460,7 @@ def validate_external(entity_type, name, config, version):
entity_type, name, ', '.join(k for k in config if k != 'external')))
-def load_services(config_details, config_file, compatibility=False):
+def load_services(config_details, config_file, compatibility=False, interpolate=True):
def build_service(service_name, service_dict, service_names):
service_config = ServiceConfig.with_abs_paths(
config_details.working_dir,
@@ -479,7 +479,8 @@ def load_services(config_details, config_file, compatibility=False):
service_names,
config_file.version,
config_details.environment,
- compatibility
+ compatibility,
+ interpolate
)
return service_dict
@@ -679,13 +680,13 @@ class ServiceExtendsResolver(object):
return filename
-def resolve_environment(service_dict, environment=None):
+def resolve_environment(service_dict, environment=None, interpolate=True):
"""Unpack any environment variables from an env_file, if set.
Interpolate environment values if set.
"""
env = {}
for env_file in service_dict.get('env_file', []):
- env.update(env_vars_from_file(env_file))
+ env.update(env_vars_from_file(env_file, interpolate))
env.update(parse_environment(service_dict.get('environment')))
return dict(resolve_env_var(k, v, environment) for k, v in six.iteritems(env))
@@ -881,11 +882,12 @@ def finalize_service_volumes(service_dict, environment):
return service_dict
-def finalize_service(service_config, service_names, version, environment, compatibility):
+def finalize_service(service_config, service_names, version, environment, compatibility,
+ interpolate=True):
service_dict = dict(service_config.config)
if 'environment' in service_dict or 'env_file' in service_dict:
- service_dict['environment'] = resolve_environment(service_dict, environment)
+ service_dict['environment'] = resolve_environment(service_dict, environment, interpolate)
service_dict.pop('env_file', None)
if 'volumes_from' in service_dict:
diff --git a/compose/config/environment.py b/compose/config/environment.py
index 6afbfc97..292029eb 100644
--- a/compose/config/environment.py
+++ b/compose/config/environment.py
@@ -30,7 +30,7 @@ def split_env(env):
return key, value
-def env_vars_from_file(filename):
+def env_vars_from_file(filename, interpolate=True):
"""
Read in a line delimited file of environment variables.
"""
@@ -39,6 +39,7 @@ def env_vars_from_file(filename):
elif not os.path.isfile(filename):
raise EnvFileNotFound("{} is not a file.".format(filename))
+ # TODO: now we should do something with interpolate here, but what?
return dotenv.dotenv_values(dotenv_path=filename, encoding='utf-8-sig')