bump compose-go to v2.2.0

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours
2024-09-12 18:14:18 +02:00
parent 3f81293fd4
commit 4da753da79
16 changed files with 197 additions and 31 deletions

View File

@ -79,7 +79,7 @@ func resolveSecretsEnvironment(dict map[string]any, environment types.Mapping) {
continue
}
if found, ok := environment[env]; ok {
secret["content"] = found
secret[types.SecretConfigXValue] = found
}
secrets[name] = secret
}

View File

@ -163,8 +163,15 @@ func getExtendsBaseFromFile(
if err != nil {
return nil, nil, err
}
services := source["services"].(map[string]any)
_, ok := services[ref]
m, ok := source["services"]
if !ok {
return nil, nil, fmt.Errorf("cannot extend service %q in %s: no services section", name, local)
}
services, ok := m.(map[string]any)
if !ok {
return nil, nil, fmt.Errorf("cannot extend service %q in %s: services must be a mapping", name, local)
}
_, ok = services[ref]
if !ok {
return nil, nil, fmt.Errorf(
"cannot extend service %q in %s: service %q not found in %s",

View File

@ -118,7 +118,9 @@ services:
- "a 7:* rmw"
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
- source: /dev/ttyUSB0
target: /dev/ttyUSB0
permissions: rwm
# String or list
# dns: 8.8.8.8

View File

@ -738,7 +738,9 @@ func Transform(source interface{}, target interface{}) error {
DecodeHook: mapstructure.ComposeDecodeHookFunc(
nameServices,
decoderHook,
cast),
cast,
secretConfigDecoderHook,
),
Result: target,
TagName: "yaml",
Metadata: &data,
@ -764,6 +766,28 @@ func nameServices(from reflect.Value, to reflect.Value) (interface{}, error) {
return from.Interface(), nil
}
func secretConfigDecoderHook(from, to reflect.Type, data interface{}) (interface{}, error) {
// Check if the input is a map and we're decoding into a SecretConfig
if from.Kind() == reflect.Map && to == reflect.TypeOf(types.SecretConfig{}) {
if v, ok := data.(map[string]interface{}); ok {
if ext, ok := v["#extensions"].(map[string]interface{}); ok {
if val, ok := ext[types.SecretConfigXValue].(string); ok {
// Return a map with the Content field populated
v["Content"] = val
delete(ext, types.SecretConfigXValue)
if len(ext) == 0 {
delete(v, "#extensions")
}
}
}
}
}
// Return the original data so the rest is handled by default mapstructure logic
return data, nil
}
// keys need to be converted to strings for jsonschema
func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) {
if mapping, ok := value.(map[string]interface{}); ok {