Browse code

exported cli compose loader parsing methods

Signed-off-by: James Nesbitt <james.nesbitt@wunderkraut.com>

James Nesbitt authored on 2017/03/01 17:52:00
Showing 1 changed files
... ...
@@ -75,7 +75,7 @@ func Load(configDetails types.ConfigDetails) (*types.Config, error) {
75 75
 			return nil, err
76 76
 		}
77 77
 
78
-		servicesList, err := loadServices(servicesConfig, configDetails.WorkingDir)
78
+		servicesList, err := LoadServices(servicesConfig, configDetails.WorkingDir)
79 79
 		if err != nil {
80 80
 			return nil, err
81 81
 		}
... ...
@@ -89,7 +89,7 @@ func Load(configDetails types.ConfigDetails) (*types.Config, error) {
89 89
 			return nil, err
90 90
 		}
91 91
 
92
-		networksMapping, err := loadNetworks(networksConfig)
92
+		networksMapping, err := LoadNetworks(networksConfig)
93 93
 		if err != nil {
94 94
 			return nil, err
95 95
 		}
... ...
@@ -103,7 +103,7 @@ func Load(configDetails types.ConfigDetails) (*types.Config, error) {
103 103
 			return nil, err
104 104
 		}
105 105
 
106
-		volumesMapping, err := loadVolumes(volumesConfig)
106
+		volumesMapping, err := LoadVolumes(volumesConfig)
107 107
 		if err != nil {
108 108
 			return nil, err
109 109
 		}
... ...
@@ -117,7 +117,7 @@ func Load(configDetails types.ConfigDetails) (*types.Config, error) {
117 117
 			return nil, err
118 118
 		}
119 119
 
120
-		secretsMapping, err := loadSecrets(secretsConfig, configDetails.WorkingDir)
120
+		secretsMapping, err := LoadSecrets(secretsConfig, configDetails.WorkingDir)
121 121
 		if err != nil {
122 122
 			return nil, err
123 123
 		}
... ...
@@ -304,11 +304,13 @@ func formatInvalidKeyError(keyPrefix string, key interface{}) error {
304 304
 	return fmt.Errorf("Non-string key %s: %#v", location, key)
305 305
 }
306 306
 
307
-func loadServices(servicesDict types.Dict, workingDir string) ([]types.ServiceConfig, error) {
307
+// LoadServices produces a ServiceConfig map from a compose file Dict
308
+// the servicesDict is not validated if directly used. Use Load() to enable validation
309
+func LoadServices(servicesDict types.Dict, workingDir string) ([]types.ServiceConfig, error) {
308 310
 	var services []types.ServiceConfig
309 311
 
310 312
 	for name, serviceDef := range servicesDict {
311
-		serviceConfig, err := loadService(name, serviceDef.(types.Dict), workingDir)
313
+		serviceConfig, err := LoadService(name, serviceDef.(types.Dict), workingDir)
312 314
 		if err != nil {
313 315
 			return nil, err
314 316
 		}
... ...
@@ -318,7 +320,9 @@ func loadServices(servicesDict types.Dict, workingDir string) ([]types.ServiceCo
318 318
 	return services, nil
319 319
 }
320 320
 
321
-func loadService(name string, serviceDict types.Dict, workingDir string) (*types.ServiceConfig, error) {
321
+// LoadService produces a single ServiceConfig from a compose file Dict
322
+// the serviceDict is not validated if directly used. Use Load() to enable validation
323
+func LoadService(name string, serviceDict types.Dict, workingDir string) (*types.ServiceConfig, error) {
322 324
 	serviceConfig := &types.ServiceConfig{}
323 325
 	if err := transform(serviceDict, serviceConfig); err != nil {
324 326
 		return nil, err
... ...
@@ -405,7 +409,9 @@ func transformUlimits(data interface{}) (interface{}, error) {
405 405
 	}
406 406
 }
407 407
 
408
-func loadNetworks(source types.Dict) (map[string]types.NetworkConfig, error) {
408
+// LoadNetworks produces a NetworkConfig map from a compose file Dict
409
+// the source Dict is not validated if directly used. Use Load() to enable validation
410
+func LoadNetworks(source types.Dict) (map[string]types.NetworkConfig, error) {
409 411
 	networks := make(map[string]types.NetworkConfig)
410 412
 	err := transform(source, &networks)
411 413
 	if err != nil {
... ...
@@ -420,7 +426,9 @@ func loadNetworks(source types.Dict) (map[string]types.NetworkConfig, error) {
420 420
 	return networks, nil
421 421
 }
422 422
 
423
-func loadVolumes(source types.Dict) (map[string]types.VolumeConfig, error) {
423
+// LoadVolumes produces a VolumeConfig map from a compose file Dict
424
+// the source Dict is not validated if directly used. Use Load() to enable validation
425
+func LoadVolumes(source types.Dict) (map[string]types.VolumeConfig, error) {
424 426
 	volumes := make(map[string]types.VolumeConfig)
425 427
 	err := transform(source, &volumes)
426 428
 	if err != nil {
... ...
@@ -435,7 +443,9 @@ func loadVolumes(source types.Dict) (map[string]types.VolumeConfig, error) {
435 435
 	return volumes, nil
436 436
 }
437 437
 
438
-func loadSecrets(source types.Dict, workingDir string) (map[string]types.SecretConfig, error) {
438
+// LoadSecrets produces a SecretConfig map from a compose file Dict
439
+// the source Dict is not validated if directly used. Use Load() to enable validation
440
+func LoadSecrets(source types.Dict, workingDir string) (map[string]types.SecretConfig, error) {
439 441
 	secrets := make(map[string]types.SecretConfig)
440 442
 	if err := transform(source, &secrets); err != nil {
441 443
 		return secrets, err