forked from rancher/rancher-compose-executor
/
secret.go
40 lines (33 loc) · 1006 Bytes
/
secret.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
package config
import "github.com/docker/libcompose/utils"
type SecretReferences []SecretReference
type SecretReference struct {
Source string `yaml:"source,omitempty"`
Target string `yaml:"target,omitempty"`
Uid string `yaml:"uid,omitempty"`
Gid string `yaml:"gid,omitempty"`
Mode string `yaml:"mode,omitempty"`
}
func (s *SecretReferences) UnmarshalYAML(unmarshal func(interface{}) error) error {
var secretReferences []SecretReference
var sliceType []interface{}
if err := unmarshal(&sliceType); err == nil {
for _, elem := range sliceType {
switch elem := elem.(type) {
case string:
secretReferences = append(secretReferences, SecretReference{
Source: elem,
Target: elem,
})
case map[interface{}]interface{}:
var secretReference SecretReference
if err = utils.Convert(elem, &secretReference); err != nil {
return err
}
secretReferences = append(secretReferences, secretReference)
}
}
}
*s = secretReferences
return nil
}