woodpecker/pipeline/frontend/yaml/network.go

39 lines
774 B
Go
Raw Normal View History

2017-03-05 07:56:08 +00:00
package yaml
import (
"fmt"
2019-11-14 19:16:03 +00:00
"gopkg.in/yaml.v3"
2017-03-05 07:56:08 +00:00
)
type (
// Networks defines a collection of networks.
Networks struct {
Networks []*Network
}
// Network defines a container network.
Network struct {
Name string `yaml:"name,omitempty"`
Driver string `yaml:"driver,omitempty"`
DriverOpts map[string]string `yaml:"driver_opts,omitempty"`
}
)
// UnmarshalYAML implements the Unmarshaler interface.
2019-11-14 19:16:03 +00:00
func (n *Networks) UnmarshalYAML(value *yaml.Node) error {
networks := map[string]Network{}
err := value.Decode(&networks)
2017-03-05 07:56:08 +00:00
2019-11-14 19:16:03 +00:00
for key, nn := range networks {
2017-03-05 07:56:08 +00:00
if nn.Name == "" {
2019-11-14 19:16:03 +00:00
nn.Name = fmt.Sprintf("%v", key)
2017-03-05 07:56:08 +00:00
}
if nn.Driver == "" {
nn.Driver = "bridge"
}
n.Networks = append(n.Networks, &nn)
}
return err
}