woodpecker/pipeline/frontend/yaml/secret.go

35 lines
656 B
Go
Raw Normal View History

2017-04-10 10:39:50 +00:00
package yaml
2019-11-14 19:16:03 +00:00
import "gopkg.in/yaml.v3"
2017-04-10 10:39:50 +00:00
type (
// Secrets defines a collection of secrets.
Secrets struct {
Secrets []*Secret
}
// Secret defines a container secret.
Secret struct {
Source string `yaml:"source"`
Target string `yaml:"target"`
}
)
// UnmarshalYAML implements the Unmarshaler interface.
2019-11-14 19:16:03 +00:00
func (s *Secrets) UnmarshalYAML(value *yaml.Node) error {
y, _ := yaml.Marshal(value)
2017-04-10 10:39:50 +00:00
var strslice []string
2019-11-14 19:16:03 +00:00
err := yaml.Unmarshal(y, &strslice)
2017-04-10 10:39:50 +00:00
if err == nil {
for _, str := range strslice {
s.Secrets = append(s.Secrets, &Secret{
Source: str,
Target: str,
})
}
return nil
}
2019-11-14 19:16:03 +00:00
return yaml.Unmarshal(y, &s.Secrets)
2017-04-10 10:39:50 +00:00
}