فهرست منبع

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

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 8 سال پیش
والد
کامیت
23b873c2ce
3فایلهای تغییر یافته به همراه17 افزوده شده و 17 حذف شده
  1. 1 1
      compose/config/errors.py
  2. 9 15
      compose/config/serialize.py
  3. 7 1
      tests/unit/config/config_test.py

+ 1 - 1
compose/config/errors.py

@@ -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 '

+ 9 - 15
compose/config/serialize.py

@@ -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):

+ 7 - 1
tests/unit/config/config_test.py

@@ -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