Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <ivan@mondoo.com>
  • Loading branch information
imilchev committed Nov 20, 2024
1 parent 2548204 commit 986235f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
21 changes: 17 additions & 4 deletions providers/os/id/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers/os/connection/mock"
"go.mondoo.com/cnquery/v11/providers/os/detector"
"go.mondoo.com/cnquery/v11/providers/os/resources/smbios"
)

func TestDetectInstance(t *testing.T) {
Expand All @@ -19,7 +20,10 @@ func TestDetectInstance(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, related := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, related := Detect(conn, platform, mgr)

assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/ec2/v1/accounts/123456789012/regions/us-west-2/instances/i-1234567890abcdef0", identifier)
assert.Equal(t, "ec2-name", name)
Expand All @@ -33,7 +37,10 @@ func TestDetectInstanceArm(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, related := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, related := Detect(conn, platform, mgr)

assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/ec2/v1/accounts/123456789012/regions/us-west-2/instances/i-1234567890abcdef0", identifier)
assert.Equal(t, "ec2-name", name)
Expand All @@ -47,7 +54,10 @@ func TestDetectNotInstance(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, related := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, related := Detect(conn, platform, mgr)

assert.Equal(t, "", identifier)
assert.Equal(t, "", name)
Expand All @@ -61,7 +71,10 @@ func TestDetectContainer(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, related := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, related := Detect(conn, platform, mgr)

assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/ecs/v1/accounts/172746783610/regions/us-east-1/container/vjtest/f088b38d61ac45d6a946b5aebbe7197a/314e35e0-2d0a-4408-b37e-16063461d73a", identifier)
assert.Equal(t, "fargate-app", name)
Expand Down
16 changes: 13 additions & 3 deletions providers/os/id/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers/os/connection/mock"
"go.mondoo.com/cnquery/v11/providers/os/detector"
"go.mondoo.com/cnquery/v11/providers/os/resources/smbios"
)

func TestDetectLinuxInstance(t *testing.T) {
Expand All @@ -19,7 +20,10 @@ func TestDetectLinuxInstance(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, relatedIdentifiers := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, relatedIdentifiers := Detect(conn, platform, mgr)

assert.Equal(t, "//platformid.api.mondoo.app/runtime/gcp/compute/v1/projects/mondoo-dev-262313/zones/us-central1-a/instances/6001244637815193808", identifier)
assert.Equal(t, "", name)
Expand All @@ -33,7 +37,10 @@ func TestDetectWindowsInstance(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, relatedIdentifiers := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, relatedIdentifiers := Detect(conn, platform, mgr)

assert.Equal(t, "//platformid.api.mondoo.app/runtime/gcp/compute/v1/projects/mondoo-dev-262313/zones/us-central1-a/instances/5275377306317132843", identifier)
assert.Equal(t, "", name)
Expand All @@ -47,7 +54,10 @@ func TestNoMatch(t *testing.T) {
platform, ok := detector.DetectOS(conn)
require.True(t, ok)

identifier, name, relatedIdentifiers := Detect(conn, platform)
mgr, err := smbios.ResolveManager(conn, platform)
require.NoError(t, err)

identifier, name, relatedIdentifiers := Detect(conn, platform, mgr)

assert.Empty(t, identifier)
assert.Empty(t, name)
Expand Down
12 changes: 9 additions & 3 deletions providers/os/provider/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.mondoo.com/cnquery/v11/providers/os/id/ids"
"go.mondoo.com/cnquery/v11/providers/os/id/machineid"
"go.mondoo.com/cnquery/v11/providers/os/id/sshhostkey"
"go.mondoo.com/cnquery/v11/providers/os/resources/smbios"
)

// default id detectors
Expand Down Expand Up @@ -75,8 +76,13 @@ func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error {
}

if hasDetector(detectors, ids.IdDetector_CloudDetect) {
mgr, err := smbios.ResolveManager(conn, asset.Platform)
if err != nil {
return err
}

log.Debug().Msg("run cloud platform detector")
if id, name, related := aws.Detect(conn, asset.Platform); id != "" {
if id, name, related := aws.Detect(conn, asset.Platform, mgr); id != "" {
asset.PlatformIds = append(asset.PlatformIds, id)
if name != "" {
// if we weren't able to detect a name for this asset, don't update to an empty value
Expand All @@ -85,12 +91,12 @@ func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error {
asset.RelatedAssets = append(asset.RelatedAssets, relatedIds2assets(related)...)
}

if id, _, related := azure.Detect(conn, asset.Platform); id != "" {
if id, _, related := azure.Detect(conn, asset.Platform, mgr); id != "" {
asset.PlatformIds = append(asset.PlatformIds, id)
asset.RelatedAssets = append(asset.RelatedAssets, relatedIds2assets(related)...)
}

if id, _, related := gcp.Detect(conn, asset.Platform); id != "" {
if id, _, related := gcp.Detect(conn, asset.Platform, mgr); id != "" {
asset.PlatformIds = append(asset.PlatformIds, id)
asset.RelatedAssets = append(asset.RelatedAssets, relatedIds2assets(related)...)
}
Expand Down
1 change: 1 addition & 0 deletions providers/os/resources/smbios/win.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (s *WindowsSmbiosManager) Info() (*SmBiosInfo, error) {
Type: winBios.Chassis[0].GetChassisTypes().Value()[0],
},
}
s.smInfo = &smInfo

return &smInfo, nil
}
Expand Down

0 comments on commit 986235f

Please sign in to comment.