Add "secrets" section to docker-compose config output when applicable

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-03-10 14:32:55 -08:00
parent dd294ce9cc
commit 23b873c2ce
3 changed files with 17 additions and 17 deletions

View File

@ -4,7 +4,7 @@ from __future__ import unicode_literals
VERSION_EXPLANATION = (
'You might be seeing this error because you\'re using the wrong Compose file version. '
'Either specify a supported version ("2.0", "2.1", "3.0") and place your '
'Either specify a supported version ("2.0", "2.1", "3.0", "3.1") and place your '
'service definitions under the `services` key, or omit the `version` key '
'and place your service definitions at the root of the file to use '
'version 1.\nFor more on the Compose file format versions, see '

View File

@ -26,34 +26,28 @@ yaml.SafeDumper.add_representer(types.ServicePort, serialize_dict_type)
def denormalize_config(config):
result = {'version': V2_1 if config.version == V1 else config.version}
denormalized_services = [
denormalize_service_dict(service_dict, config.version)
for service_dict in config.services
]
services = {
result['services'] = {
service_dict.pop('name'): service_dict
for service_dict in denormalized_services
}
networks = config.networks.copy()
for net_name, net_conf in networks.items():
result['networks'] = config.networks.copy()
for net_name, net_conf in result['networks'].items():
if 'external_name' in net_conf:
del net_conf['external_name']
volumes = config.volumes.copy()
for vol_name, vol_conf in volumes.items():
result['volumes'] = config.volumes.copy()
for vol_name, vol_conf in result['volumes'].items():
if 'external_name' in vol_conf:
del vol_conf['external_name']
version = config.version
if version == V1:
version = V2_1
return {
'version': version,
'services': services,
'networks': networks,
'volumes': volumes,
}
if config.version in (V3_1,):
result['secrets'] = config.secrets
return result
def serialize_config(config):

View File

@ -3650,11 +3650,17 @@ class SerializeTest(unittest.TestCase):
}
]
}
secrets_dict = {
'one': {'file': '/one.txt'},
'source': {'file': '/source.pem'}
}
config_dict = config.load(build_config_details({
'version': '3.1',
'services': {'web': service_dict}
'services': {'web': service_dict},
'secrets': secrets_dict
}))
serialized_config = yaml.load(serialize_config(config_dict))
serialized_service = serialized_config['services']['web']
assert secret_sort(serialized_service['secrets']) == secret_sort(service_dict['secrets'])
assert serialized_config['secrets'] == secrets_dict