woodpecker/pipeline/frontend/yaml/types/workflow_volume.go
6543 971cb52032
Rename pipeline frontend types (#1829)
this adjust the packages that parse the yaml-config-file to match
[Terminology](https://woodpecker-ci.org/docs/next/usage/terminology)
2023-06-06 09:14:21 +02:00

44 lines
907 B
Go

package types
import (
"fmt"
"gopkg.in/yaml.v3"
)
type (
// WorkflowVolumes defines a collection of volumes.
WorkflowVolumes struct {
WorkflowVolumes []*WorkflowVolume
}
// WorkflowVolume defines a container volume.
WorkflowVolume struct {
Name string `yaml:"name,omitempty"`
Driver string `yaml:"driver,omitempty"`
DriverOpts map[string]string `yaml:"driver_opts,omitempty"`
}
)
// UnmarshalYAML implements the Unmarshaler interface.
func (v *WorkflowVolumes) UnmarshalYAML(value *yaml.Node) error {
y, _ := yaml.Marshal(value)
volumes := map[string]WorkflowVolume{}
err := yaml.Unmarshal(y, &volumes)
if err != nil {
return err
}
for key, vv := range volumes {
if vv.Name == "" {
vv.Name = fmt.Sprintf("%v", key)
}
if vv.Driver == "" {
vv.Driver = "local"
}
v.WorkflowVolumes = append(v.WorkflowVolumes, &vv)
}
return err
}