Skip to content

Commit

Permalink
šŸ› Ensure we use the proper runtime for shell connections, do not storā€¦
Browse files Browse the repository at this point in the history
ā€¦e assets with no platform. (#3887)

Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored May 2, 2024
1 parent 199aacf commit 401d525
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions apps/cnquery/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.mondoo.com/cnquery/v11/providers"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/recording"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream"
)

Expand Down Expand Up @@ -107,7 +106,7 @@ func StartShell(runtime *providers.Runtime, conf *ShellConfig) error {
discoveredAssets, err := scan.DiscoverAssets(ctx,
inventory.New(inventory.WithAssets(conf.Asset)),
conf.UpstreamConfig,
recording.Null{})
runtime.Recording())
if err != nil {
log.Fatal().Err(err).Msg("could not process assets")
}
Expand Down Expand Up @@ -155,7 +154,6 @@ func StartShell(runtime *providers.Runtime, conf *ShellConfig) error {

// when we close the shell, we need to close the backend and store the recording
onCloseHandler := func() {
runtime.Close()
connectAsset.Runtime.Close()
providers.Coordinator.Shutdown()
}
Expand Down
6 changes: 6 additions & 0 deletions providers-sdk/v1/recording/recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func NewWithFile(path string, opts RecordingOptions) (llx.Recording, error) {
Path: path,
prettyPrintJSON: opts.PrettyPrintJSON,
doNotSave: opts.DoNotSave,
assets: map[uint32]*Asset{},
}
res.refreshCache() // only for initialization
return res, nil
Expand Down Expand Up @@ -355,6 +356,10 @@ func (r *recording) findAssetConnID(asset *inventory.Asset) (int, string) {
func (r *recording) EnsureAsset(asset *inventory.Asset, providerID string, connectionID uint32, conf *inventory.Config) {
found, _ := r.findAssetConnID(asset)

if asset.Platform == nil {
log.Warn().Msg("cannot store asset in recording, asset has no platform")
return
}
if found == -1 {
id := asset.Mrn
if id == "" {
Expand All @@ -363,6 +368,7 @@ func (r *recording) EnsureAsset(asset *inventory.Asset, providerID string, conne
if id == "" {
id = asset.Platform.Title
}

r.Assets = append(r.Assets, &Asset{
Asset: assetInfo{
ID: id,
Expand Down

0 comments on commit 401d525

Please sign in to comment.