/
volume_list.go
75 lines (57 loc) · 1.33 KB
/
volume_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package config
import (
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/invopop/jsonschema"
"golang.org/x/exp/maps"
)
type VolumeList map[string]Volume
func (list VolumeList) Validate() error {
for _, vol := range list {
if err := vol.Validate(); err != nil {
return err
}
}
return nil
}
func (vlist VolumeList) ToAws() []ecsTypes.Volume {
out := make([]ecsTypes.Volume, 0)
for _, val := range vlist {
out = append(out, val.ToAws())
}
return out
}
func (obj *VolumeList) UnmarshalYAML(unmarshal func(interface{}) error) error {
type tVolumeList []Volume
var defo = tVolumeList{}
if err := unmarshal(&defo); err != nil {
return err
}
newMap := make(VolumeList)
for _, val := range defo {
if _, ok := newMap[val.Name]; ok {
return NewValidationError("Duplicate volume name: %s", val.Name)
}
newMap[val.Name] = val
}
*obj = newMap
return obj.Validate()
}
func (VolumeList) JSONSchemaExtend(base *jsonschema.Schema) {
// get the original mapping
volRef := base.PatternProperties[".*"]
*base = jsonschema.Schema{
Type: "array",
Items: volRef,
}
}
func MergeVolumeLists(volumeLists ...VolumeList) VolumeList {
newMap := make(VolumeList)
for _, value := range volumeLists {
if value == nil {
continue
}
value := value
maps.Copy(newMap, value)
}
return newMap
}