Skip to content

Commit

Permalink
skip discovery only for new clients
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Mar 6, 2024
1 parent 034c94c commit a70a04f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions providers-sdk/v1/plugin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
inventory "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
)

const DISABLE_DELAYED_DISCOVERY_OPTION = "disable-delayed-discovery"

type Service struct {
runtimes map[uint32]*Runtime
lastConnectionID uint32
Expand All @@ -39,6 +41,12 @@ func (s *Service) AddRuntime(conf *inventory.Config, createRuntime func(connId u
// FIXME: DEPRECATED, remove in v12.0 vv
// This approach is used only when old clients use new providers. We will throw it away in v12
if conf.Id == 0 {
if conf.Options == nil {
conf.Options = make(map[string]string)
}

// Disable delayed discovery for old clients since they don't know how to handle it
conf.Options[DISABLE_DELAYED_DISCOVERY_OPTION] = "true"
return s.deprecatedAddRuntime(createRuntime)
}
// ^^
Expand Down
8 changes: 7 additions & 1 deletion providers/os/connection/container/image_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers/os/connection/container/auth"
"go.mondoo.com/cnquery/v10/providers/os/connection/container/image"
"go.mondoo.com/cnquery/v10/providers/os/connection/tar"
Expand All @@ -21,7 +22,12 @@ import (

// NewImageConnection uses a container image reference as input and creates a tar connection
func NewImageConnection(id uint32, conf *inventory.Config, asset *inventory.Asset, img v1.Image) (*tar.Connection, error) {
conf.SkipDiscovery = true
// FIXME: DEPRECATED, remove in v12.0 vv
// The SkipDiscovery flag should always be set from v12
if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" {
conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image
}
// ^^
f, err := tar.RandomFile()
if err != nil {
return nil, err
Expand Down
14 changes: 12 additions & 2 deletions providers/os/connection/docker/container_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ func NewDockerEngineContainer(id uint32, conf *inventory.Config, asset *inventor
conn.PlatformIdentifier = containerid.MondooContainerID(ci.ID)
conn.Metadata.Name = containerid.ShortContainerImageID(ci.ID)
conn.Metadata.Labels = ci.Labels
conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image
// FIXME: DEPRECATED, remove in v12.0 vv
// The SkipDiscovery flag should always be set from v12
if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" {
conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image
}
// ^^
asset.Name = ci.Name
asset.PlatformIds = []string{containerid.MondooContainerID(ci.ID)}
return conn, nil
Expand Down Expand Up @@ -296,7 +301,12 @@ func NewContainerImageConnection(id uint32, conf *inventory.Config, asset *inven
conf.Options = map[string]string{}
}
conf.Options[tar.OPTION_FILE] = filename
conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image
// FIXME: DEPRECATED, remove in v12.0 vv
// The SkipDiscovery flag should always be set from v12
if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" {
conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image
}
// ^^

tarConn, err := tar.NewConnection(
id,
Expand Down

0 comments on commit a70a04f

Please sign in to comment.