Skip to content

Commit 8a6ac95

Browse files
ndeloofglours
authored andcommitted
provider.options can be an array
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 70d014d commit 8a6ac95

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

loader/loader_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,11 +3771,25 @@ services:
37713771
type: foo
37723772
options:
37733773
bar: zot
3774+
strings:
3775+
- foo
3776+
- bar
3777+
numbers:
3778+
- 12
3779+
- 34
3780+
booleans:
3781+
- true
3782+
- false
37743783
`)
37753784
assert.NilError(t, err)
37763785
assert.DeepEqual(t, p.Services["test"].Provider, &types.ServiceProviderConfig{
3777-
Type: "foo",
3778-
Options: map[string]string{"bar": "zot"},
3786+
Type: "foo",
3787+
Options: types.MultiOptions{
3788+
"bar": []string{"zot"},
3789+
"strings": []string{"foo", "bar"},
3790+
"numbers": []string{"12", "34"},
3791+
"booleans": []string{"true", "false"},
3792+
},
37793793
})
37803794
}
37813795

schema/compose-spec.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,17 @@
401401
"type": "object",
402402
"description": "Provider-specific options.",
403403
"patternProperties": {
404-
"^.+$": {"type": ["string", "number", "null"]}
404+
"^.+$": {"oneOf": [
405+
{ "type": ["string", "number", "boolean"] },
406+
{ "type": "array", "items": {"type": ["string", "number", "boolean"]}}
407+
]}
408+
}
409+
},
410+
"configs": {
411+
"type": "object",
412+
"description": "Config files to pass to the provider.",
413+
"patternProperties": {
414+
"^.+$": {"type": ["string"]}
405415
}
406416
}
407417
},

types/derived.gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/options.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,27 @@ func (d *Options) DecodeMapstructure(value interface{}) error {
4040
}
4141
return nil
4242
}
43+
44+
// MultiOptions allow option to be repeated
45+
type MultiOptions map[string][]string
46+
47+
func (d *MultiOptions) DecodeMapstructure(value interface{}) error {
48+
switch v := value.(type) {
49+
case map[string]interface{}:
50+
m := make(map[string][]string)
51+
for key, e := range v {
52+
switch e := e.(type) {
53+
case []interface{}:
54+
for _, v := range e {
55+
m[key] = append(m[key], fmt.Sprint(v))
56+
}
57+
default:
58+
m[key] = append(m[key], fmt.Sprint(e))
59+
}
60+
}
61+
*d = m
62+
default:
63+
return fmt.Errorf("invalid type %T for options", value)
64+
}
65+
return nil
66+
}

types/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ type ServiceConfig struct {
143143
}
144144

145145
type ServiceProviderConfig struct {
146-
Type string `yaml:"type,omitempty" json:"driver,omitempty"`
147-
Options Options `yaml:"options,omitempty" json:"options,omitempty"`
148-
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
146+
Type string `yaml:"type,omitempty" json:"driver,omitempty"`
147+
Options MultiOptions `yaml:"options,omitempty" json:"options,omitempty"`
148+
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
149149
}
150150

151151
// MarshalYAML makes ServiceConfig implement yaml.Marshaller

0 commit comments

Comments
 (0)