treat empty jobs & empty YAML as valid & ship empty jobs in deb/rpm (#788)

fixes https://github.com/zrepl/zrepl/issues/784
obsoletes https://github.com/zrepl/zrepl/pull/787
This commit is contained in:
Christian Schwarz
2024-05-14 19:18:22 +02:00
committed by GitHub
parent 830536715e
commit 9c63736489
5 changed files with 30 additions and 28 deletions
+10 -15
View File
@@ -5,7 +5,6 @@ import (
"io/ioutil"
"log/syslog"
"os"
"reflect"
"time"
"github.com/pkg/errors"
@@ -24,7 +23,7 @@ const (
)
type Config struct {
Jobs []JobEnum `yaml:"jobs"`
Jobs []JobEnum `yaml:"jobs,optional"`
Global *Global `yaml:"global,optional,fromdefaults"`
}
@@ -299,18 +298,6 @@ type Global struct {
Serve *GlobalServe `yaml:"serve,optional,fromdefaults"`
}
func Default(i interface{}) {
v := reflect.ValueOf(i)
if v.Kind() != reflect.Ptr {
panic(v)
}
y := `{}`
err := yaml.Unmarshal([]byte(y), v.Interface())
if err != nil {
panic(err)
}
}
type ConnectEnum struct {
Ret interface{}
}
@@ -696,8 +683,16 @@ func ParseConfigBytes(bytes []byte) (*Config, error) {
if err := yaml.UnmarshalStrict(bytes, &c); err != nil {
return nil, err
}
if c != nil {
return c, nil
}
// There was no yaml document in the file, deserialize from default.
// => See TestFromdefaultsEmptyDoc in yaml-config package.
if err := yaml.UnmarshalStrict([]byte("{}"), &c); err != nil {
return nil, err
}
if c == nil {
return nil, fmt.Errorf("config is empty or only consists of comments")
panic("the fallback to deserialize from `{}` should work")
}
return c, nil
}