Don't use dot as a path separator as it is a valid character in resource identifiers

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-10-16 17:21:57 -07:00
parent 5e4098d228
commit 0fa1462b0f
2 changed files with 36 additions and 5 deletions

View File

@ -48,7 +48,7 @@ def interpolate_environment_variables(version, config, section, environment):
def get_config_path(config_key, section, name):
return '{}.{}.{}'.format(section, name, config_key)
return '{}/{}/{}'.format(section, name, config_key)
def interpolate_value(name, config_key, value, section, interpolator):
@ -75,7 +75,7 @@ def interpolate_value(name, config_key, value, section, interpolator):
def recursive_interpolate(obj, interpolator, config_path):
def append(config_path, key):
return '{}.{}'.format(config_path, key)
return '{}/{}'.format(config_path, key)
if isinstance(obj, six.string_types):
return converter.convert(config_path, interpolator.interpolate(obj))
@ -160,12 +160,12 @@ class UnsetRequiredSubstitution(Exception):
self.err = custom_err_msg
PATH_JOKER = '[^.]+'
PATH_JOKER = '[^/]+'
FULL_JOKER = '.+'
def re_path(*args):
return re.compile('^{}$'.format('\.'.join(args)))
return re.compile('^{}$'.format('/'.join(args)))
def re_path_basic(section, name):
@ -288,7 +288,7 @@ class ConversionMap(object):
except ValueError as e:
raise ConfigurationError(
'Error while attempting to convert {} to appropriate type: {}'.format(
path, e
path.replace('/', '.'), e
)
)
return value

View File

@ -332,6 +332,37 @@ def test_interpolate_environment_external_resource_convert_types(mock_env):
assert value == expected
def test_interpolate_service_name_uses_dot(mock_env):
entry = {
'service.1': {
'image': 'busybox',
'ulimits': {
'nproc': '${POSINT}',
'nofile': {
'soft': '${POSINT}',
'hard': '${DEFAULT:-40000}'
},
},
}
}
expected = {
'service.1': {
'image': 'busybox',
'ulimits': {
'nproc': 50,
'nofile': {
'soft': 50,
'hard': 40000
},
},
}
}
value = interpolate_environment_variables(V3_4, entry, 'service', mock_env)
assert value == expected
def test_escaped_interpolation(defaults_interpolator):
assert defaults_interpolator('$${foo}') == '${foo}'