mirror of
https://github.com/kairos-io/kairos.git
synced 2025-02-09 05:18:51 +00:00

* Introduce config/collector package to split the collection of config sources out of the config package. Each consumer of the new package will take care of unmarshalling the yaml to a specific Config struct, do validations etc. * Add tests and remove garbage * Follow all config_url chains and test it * Add missing options file and refactor cmdline code * Consolidate the way we merge configs no matter where they come from * Allow and use only files with valid headers Config is specific to Kairos while Collector is generic. This will allow us to do validations which are just related to Kairos at the config level, while including every type of key and querying of the full yaml at the Collector level splitting the responsibilities of each package. --------- Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package collector
|
|
|
|
import "fmt"
|
|
|
|
type Options struct {
|
|
ScanDir []string
|
|
BootCMDLineFile string
|
|
MergeBootCMDLine bool
|
|
NoLogs bool
|
|
StrictValidation bool
|
|
}
|
|
|
|
type Option func(o *Options) error
|
|
|
|
var NoLogs Option = func(o *Options) error {
|
|
o.NoLogs = true
|
|
return nil
|
|
}
|
|
|
|
// SoftErr prints a warning if err is no nil and NoLogs is not true.
|
|
// It's use to wrap the same handling happening in multiple places.
|
|
//
|
|
// TODO: Switch to a standard logging library (e.g. verbose, silent mode etc).
|
|
func (o *Options) SoftErr(message string, err error) {
|
|
if !o.NoLogs && err != nil {
|
|
fmt.Printf("WARNING: %s, %s\n", message, err.Error())
|
|
}
|
|
}
|
|
|
|
func (o *Options) Apply(opts ...Option) error {
|
|
for _, oo := range opts {
|
|
if err := oo(o); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var MergeBootLine = func(o *Options) error {
|
|
o.MergeBootCMDLine = true
|
|
return nil
|
|
}
|
|
|
|
func WithBootCMDLineFile(s string) Option {
|
|
return func(o *Options) error {
|
|
o.BootCMDLineFile = s
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func StrictValidation(v bool) Option {
|
|
return func(o *Options) error {
|
|
o.StrictValidation = v
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func Directories(d ...string) Option {
|
|
return func(o *Options) error {
|
|
o.ScanDir = d
|
|
return nil
|
|
}
|
|
}
|