mirror of https://github.com/docker/compose.git
Fix `config` command output with service.secrets section
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
1d88989ff5
commit
b9e9177ba9
|
@ -102,4 +102,7 @@ def denormalize_service_dict(service_dict, version):
|
||||||
service_dict['healthcheck']['timeout']
|
service_dict['healthcheck']['timeout']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if 'secrets' in service_dict:
|
||||||
|
service_dict['secrets'] = map(lambda s: s.repr(), service_dict['secrets'])
|
||||||
|
|
||||||
return service_dict
|
return service_dict
|
||||||
|
|
|
@ -256,8 +256,5 @@ class ServiceSecret(namedtuple('_ServiceSecret', 'source target uid gid mode')):
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return dict(
|
return dict(
|
||||||
source=self.source,
|
[(k, v) for k, v in self._asdict().items() if v is not None]
|
||||||
target=self.target,
|
)
|
||||||
uid=self.uid,
|
|
||||||
gid=self.gid,
|
|
||||||
mode=self.mode)
|
|
||||||
|
|
|
@ -54,6 +54,10 @@ def service_sort(services):
|
||||||
return sorted(services, key=itemgetter('name'))
|
return sorted(services, key=itemgetter('name'))
|
||||||
|
|
||||||
|
|
||||||
|
def secret_sort(secrets):
|
||||||
|
return sorted(secrets, key=itemgetter('source'))
|
||||||
|
|
||||||
|
|
||||||
class ConfigTest(unittest.TestCase):
|
class ConfigTest(unittest.TestCase):
|
||||||
def test_load(self):
|
def test_load(self):
|
||||||
service_dicts = config.load(
|
service_dicts = config.load(
|
||||||
|
@ -1771,6 +1775,38 @@ class ConfigTest(unittest.TestCase):
|
||||||
'labels': {'com.docker.compose.test': 'yes'}
|
'labels': {'com.docker.compose.test': 'yes'}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def test_merge_different_secrets(self):
|
||||||
|
base = {
|
||||||
|
'image': 'busybox',
|
||||||
|
'secrets': [
|
||||||
|
{'source': 'src.txt'}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
override = {'secrets': ['other-src.txt']}
|
||||||
|
|
||||||
|
actual = config.merge_service_dicts(base, override, V3_1)
|
||||||
|
assert secret_sort(actual['secrets']) == secret_sort([
|
||||||
|
{'source': 'src.txt'},
|
||||||
|
{'source': 'other-src.txt'}
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_merge_secrets_override(self):
|
||||||
|
base = {
|
||||||
|
'image': 'busybox',
|
||||||
|
'secrets': ['src.txt'],
|
||||||
|
}
|
||||||
|
override = {
|
||||||
|
'secrets': [
|
||||||
|
{
|
||||||
|
'source': 'src.txt',
|
||||||
|
'target': 'data.txt',
|
||||||
|
'mode': 0o400
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
actual = config.merge_service_dicts(base, override, V3_1)
|
||||||
|
assert actual['secrets'] == override['secrets']
|
||||||
|
|
||||||
def test_external_volume_config(self):
|
def test_external_volume_config(self):
|
||||||
config_details = build_config_details({
|
config_details = build_config_details({
|
||||||
'version': '2',
|
'version': '2',
|
||||||
|
@ -3491,3 +3527,24 @@ class SerializeTest(unittest.TestCase):
|
||||||
denormalized_service = denormalize_service_dict(processed_service, V2_1)
|
denormalized_service = denormalize_service_dict(processed_service, V2_1)
|
||||||
assert denormalized_service['healthcheck']['interval'] == '100s'
|
assert denormalized_service['healthcheck']['interval'] == '100s'
|
||||||
assert denormalized_service['healthcheck']['timeout'] == '30s'
|
assert denormalized_service['healthcheck']['timeout'] == '30s'
|
||||||
|
|
||||||
|
def test_denormalize_secrets(self):
|
||||||
|
service_dict = {
|
||||||
|
'name': 'web',
|
||||||
|
'image': 'example/web',
|
||||||
|
'secrets': [
|
||||||
|
types.ServiceSecret('one', None, None, None, None),
|
||||||
|
types.ServiceSecret('source', 'target', '100', '200', 0o777),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
denormalized_service = denormalize_service_dict(service_dict, V3_1)
|
||||||
|
assert secret_sort(denormalized_service['secrets']) == secret_sort([
|
||||||
|
{'source': 'one'},
|
||||||
|
{
|
||||||
|
'source': 'source',
|
||||||
|
'target': 'target',
|
||||||
|
'uid': '100',
|
||||||
|
'gid': '200',
|
||||||
|
'mode': 0o777,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
Loading…
Reference in New Issue