Skip to content

Commit

Permalink
🐛 Set asset annotations during cnspec serve. (#1133)
Browse files Browse the repository at this point in the history
* 🐛 Set asset annotations during cnspec serve.

Signed-off-by: Preslav <preslav@mondoo.com>

* Simplify ParseOrUse.

---------

Signed-off-by: Preslav <preslav@mondoo.com>
  • Loading branch information
preslavgerchev authored Feb 22, 2024
1 parent 0d76b70 commit 7eefe1c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions apps/cnspec/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,17 @@ func getServeConfig() (*scanConfig, *cnspec_config.CliConfig, error) {
optAnnotations = map[string]string{}
}
var err error
conf.Inventory, err = inventoryloader.ParseOrUse(nil, viper.GetBool("insecure"), optAnnotations)
if err != nil {
return nil, nil, errors.Wrap(err, "could not load configuration")

asset := &inventory.Asset{
Connections: []*inventory.Config{{
Type: "local",
}},
Annotations: optAnnotations,
}

// fall back to local machine if no inventory was localed
if conf.Inventory == nil || conf.Inventory.Spec == nil || len(conf.Inventory.Spec.Assets) == 0 {
log.Info().Msg("configure inventory to scan local operating system")
conf.Inventory = inventory.New(inventory.WithAssets(&inventory.Asset{
Connections: []*inventory.Config{{
Type: "local",
}},
}))
conf.Inventory, err = inventoryloader.ParseOrUse(asset, viper.GetBool("insecure"), optAnnotations)
if err != nil {
return nil, nil, errors.Wrap(err, "could not load configuration")
}

// set the default scan interval if not set
Expand Down

0 comments on commit 7eefe1c

Please sign in to comment.