From 4e264a13b711558a8532eaace4fef20601e6de79 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 20 Mar 2024 09:18:08 +0100 Subject: [PATCH] Add a scanner for config with nulllogger (#262) To create a new config but discards the logs Signed-off-by: Itxaka --- main.go | 2 +- pkg/config/config.go | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 220bcca..38900b0 100644 --- a/main.go +++ b/main.go @@ -351,7 +351,7 @@ enabled: true`, Description: "It allows to navigate the YAML config file by searching with 'yq' style keywords as `config get k3s` to retrieve the k3s config block", Aliases: []string{"g"}, Action: func(c *cli.Context) error { - config, err := agentConfig.Scan(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation"))) + config, err := agentConfig.ScanNoLogs(collector.Directories(constants.GetConfigScanDirs()...), collector.NoLogs, collector.StrictValidation(c.Bool("strict-validation"))) if err != nil { return err } diff --git a/pkg/config/config.go b/pkg/config/config.go index aa37ca9..7c7ee5a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -329,10 +329,22 @@ func FilterKeys(d []byte) ([]byte, error) { return out, nil } -func Scan(opts ...collector.Option) (c *Config, err error) { - // Init new config with some default options - result := NewConfig() +// ScanNoLogs is a wrapper around Scan that sets the logger to null +func ScanNoLogs(opts ...collector.Option) (c *Config, err error) { + log := sdkTypes.NewNullLogger() + result := NewConfig(WithLogger(log)) + return scan(result, opts...) +} +// Scan is a wrapper around collector.Scan that sets the logger to the default Kairos logger +func Scan(opts ...collector.Option) (c *Config, err error) { + result := NewConfig() + return scan(result, opts...) +} + +// scan is the internal function that does the actual scanning of the configs +func scan(result *Config, opts ...collector.Option) (c *Config, err error) { + // Init new config with some default options o := &collector.Options{} if err := o.Apply(opts...); err != nil { return result, err