Skip to content

Commit

Permalink
🐛 properly discover scannable root assets (#3213)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Feb 6, 2024
1 parent 3391deb commit ac46c79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions explorer/scan/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions explorer/scan/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit ac46c79

Please sign in to comment.