From 6f28c2bccefba207a8422248bf6bcec737b70f4c Mon Sep 17 00:00:00 2001 From: Preslav Date: Thu, 22 Feb 2024 17:38:22 +0100 Subject: [PATCH] Simplify ParseOrUse. --- apps/cnspec/cmd/scan.go | 2 +- apps/cnspec/cmd/serve.go | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/cnspec/cmd/scan.go b/apps/cnspec/cmd/scan.go index 68511867..8ba6f591 100644 --- a/apps/cnspec/cmd/scan.go +++ b/apps/cnspec/cmd/scan.go @@ -228,7 +228,7 @@ func getCobraScanConfig(cmd *cobra.Command, runtime *providers.Runtime, cliRes * cliRes.Asset.Name = assetName } - inv, err := inventoryloader.ParseOrUse(func() *inventory.Asset { return cliRes.Asset }, viper.GetBool("insecure"), optAnnotations) + inv, err := inventoryloader.ParseOrUse(cliRes.Asset, viper.GetBool("insecure"), optAnnotations) if err != nil { log.Fatal().Err(err).Msg("failed to parse inventory") } diff --git a/apps/cnspec/cmd/serve.go b/apps/cnspec/cmd/serve.go index 638e0e86..338424fe 100644 --- a/apps/cnspec/cmd/serve.go +++ b/apps/cnspec/cmd/serve.go @@ -180,17 +180,14 @@ func getServeConfig() (*scanConfig, *cnspec_config.CliConfig, error) { } var err error - assetFn := func() *inventory.Asset { - log.Info().Msg("configure inventory to scan local operating system") - return &inventory.Asset{ - Connections: []*inventory.Config{{ - Type: "local", - }}, - Annotations: optAnnotations, - } + asset := &inventory.Asset{ + Connections: []*inventory.Config{{ + Type: "local", + }}, + Annotations: optAnnotations, } - conf.Inventory, err = inventoryloader.ParseOrUse(assetFn, viper.GetBool("insecure"), optAnnotations) + conf.Inventory, err = inventoryloader.ParseOrUse(asset, viper.GetBool("insecure"), optAnnotations) if err != nil { return nil, nil, errors.Wrap(err, "could not load configuration") }