From ac46c7903f1a7388ae37c339d0cfb219ffca597d Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Tue, 6 Feb 2024 15:28:57 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20properly=20discover=20scannable?= =?UTF-8?q?=20root=20assets=20(#3213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ivan Milchev --- explorer/scan/discovery.go | 12 ++++++++++++ explorer/scan/discovery_test.go | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/explorer/scan/discovery.go b/explorer/scan/discovery.go index 19eaf52573..7f8dd6fac9 100644 --- a/explorer/scan/discovery.go +++ b/explorer/scan/discovery.go @@ -110,6 +110,18 @@ func DiscoverAssets(ctx context.Context, inv *inventory.Inventory, upstream *ups resolvedRootAsset = rootAssetWithRuntime.Asset // to ensure we get all the information the connect call gave us + // If the root asset has platform IDs, then it is a scannable asset, so we need to add it + if len(resolvedRootAsset.PlatformIds) > 0 { + if !discoveredAssets.Add(rootAssetWithRuntime.Asset, rootAssetWithRuntime.Runtime) { + rootAssetWithRuntime.Runtime.Close() + } + } + + // If there is no inventory, no assets have been discovered under the root asset + if rootAssetWithRuntime.Runtime.Provider.Connection.Inventory == nil { + continue + } + // for all discovered assets, we apply mondoo-specific labels and annotations that come from the root asset for _, a := range rootAssetWithRuntime.Runtime.Provider.Connection.Inventory.Spec.Assets { // create runtime for root asset diff --git a/explorer/scan/discovery_test.go b/explorer/scan/discovery_test.go index 3c0ecb5128..b7a280a9c9 100644 --- a/explorer/scan/discovery_test.go +++ b/explorer/scan/discovery_test.go @@ -221,4 +221,13 @@ func TestDiscoverAssets(t *testing.T) { assert.Equal(t, "actions.github.com", asset.Asset.Labels["mondoo.com/exec-environment"]) } }) + + t.Run("scannable root asset", func(t *testing.T) { + inv := getInventory() + inv.Spec.Assets[0].Connections[0].Type = "local" + + discoveredAssets, err := DiscoverAssets(context.Background(), inv, nil, providers.NullRecording{}) + require.NoError(t, err) + assert.Len(t, discoveredAssets.Assets, 1) + }) }