1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/config/defaults.go
Jordi van Liempt 0ba4c2206c
chore(deps): Replace io/ioutil package (#4494)
* update all deprecated ioutil usages

* forgotten changes

* add missing imports

* undo changing comment

* add missing 'os' import

* fix integration test

---------

Co-authored-by: I557621 <jordi.van.liempt@sap.com>
Co-authored-by: Gulom Alimov <gulomjon.alimov@sap.com>
2023-08-16 12:57:04 +02:00

43 lines
837 B
Go

package config
import (
"fmt"
"io"
"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 {
defer func() {
for _, def := range defaultSources {
def.Close()
}
}()
for _, def := range defaultSources {
var c Config
var err error
content, err := io.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
}