Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 simplify shell command #3221

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions apps/cnquery/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"

Expand All @@ -21,7 +20,6 @@ import (
"go.mondoo.com/cnquery/v10/explorer/scan"
"go.mondoo.com/cnquery/v10/providers"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory/manager"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/upstream"
)
Expand Down Expand Up @@ -98,25 +96,8 @@ func ParseShellConfig(cmd *cobra.Command, cliRes *plugin.ParseCLIRes) *ShellConf
// StartShell will start an interactive CLI shell
func StartShell(runtime *providers.Runtime, conf *ShellConfig) error {
// we go through inventory resolution to resolve credentials properly for the passed-in asset
im, err := manager.NewManager(manager.WithInventory(inventory.New(inventory.WithAssets(conf.Asset)), runtime))
if err != nil {
return errors.New("failed to resolve inventory for connection")
}
resolvedAsset, err := im.ResolveAsset(conf.Asset)
if err != nil {
return err
}
res, err := runtime.Provider.Instance.Plugin.Connect(&plugin.ConnectReq{
Features: conf.Features,
Asset: resolvedAsset,
Upstream: conf.UpstreamConfig,
}, nil)
if err != nil {
log.Fatal().Err(err).Msg("could not load asset information")
}

ctx := context.Background()
discoveredAssets, err := scan.DiscoverAssets(ctx, res.Inventory, conf.UpstreamConfig, providers.NullRecording{})
discoveredAssets, err := scan.DiscoverAssets(ctx, inventory.New(inventory.WithAssets(conf.Asset)), conf.UpstreamConfig, providers.NullRecording{})
if err != nil {
log.Fatal().Err(err).Msg("could not process assets")
}
Expand Down
Loading