2019-10-22 15:41:27 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PipelineDefaults defines the structure of the pipeline defaults
|
|
|
|
type PipelineDefaults struct {
|
|
|
|
Defaults []Config `json:"defaults"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadPipelineDefaults loads defaults and returns its content
|
|
|
|
func (d *PipelineDefaults) ReadPipelineDefaults(defaultSources []io.ReadCloser) error {
|
|
|
|
|
2020-05-12 15:46:47 +02:00
|
|
|
defer func() {
|
|
|
|
for _, def := range defaultSources {
|
|
|
|
def.Close()
|
|
|
|
}
|
|
|
|
}()
|
2019-10-22 15:41:27 +02:00
|
|
|
|
2020-05-12 15:46:47 +02:00
|
|
|
for _, def := range defaultSources {
|
2019-10-22 15:41:27 +02:00
|
|
|
var c Config
|
|
|
|
var err error
|
|
|
|
|
|
|
|
content, err := ioutil.ReadAll(def)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error reading %v", def)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(content, &c)
|
|
|
|
if err != nil {
|
|
|
|
return NewParseError(fmt.Sprintf("error unmarshalling %q: %v", content, err))
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Defaults = append(d.Defaults, c)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|