github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/github/yaml/secrets.go (about) 1 package yaml 2 3 import ( 4 "errors" 5 ) 6 7 type Secrets struct { 8 Inherit bool 9 Values map[string]string 10 } 11 12 // UnmarshalYAML implements the unmarshal interface. 13 func (v *Secrets) UnmarshalYAML(unmarshal func(interface{}) error) error { 14 var out1 string 15 var out2 map[string]string 16 17 if err := unmarshal(&out1); err == nil { 18 if out1 == "inherit" { 19 v.Inherit = true 20 return nil 21 } else { 22 return errors.New("invalid string value for secrets") 23 } 24 } 25 if err := unmarshal(&out2); err == nil { 26 v.Values = out2 27 return nil 28 } 29 return errors.New("failed to unmarshal secrets") 30 } 31 32 // MarshalYAML implements the marshal interface. 33 func (v *Secrets) MarshalYAML() (interface{}, error) { 34 if v.Inherit { 35 return map[string]bool{"inherit": true}, nil 36 } 37 return v.Values, nil 38 }