Skip to content

Commit

Permalink
fix delayed discovery scans
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Mar 5, 2024
1 parent 1e7e7a0 commit 034c94c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"os"
"slices"
"strings"
sync "sync"
"time"
Expand Down Expand Up @@ -181,6 +182,7 @@ func CreateProgressBar(discoveredAssets *DiscoveredAssets, disableProgressBar bo
asset := discoveredAssets.Assets[i].Asset
// this shouldn't happen, but might
// it normally indicates a bug in the provider
slices.Sort(asset.PlatformIds)
if presentAsset, present := progressBarElements[asset.PlatformIds[0]]; present {
return nil, fmt.Errorf("asset %s and %s have the same platform id %s", presentAsset, asset.Name, asset.PlatformIds[0])
}
Expand Down Expand Up @@ -358,7 +360,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
continue
}

// platformMrn := asset.PlatformIds[0]
asset = runtime.Provider.Connection.Asset
slices.Sort(asset.PlatformIds)
details := resp.Details[asset.PlatformIds[0]]
asset.Mrn = details.AssetMrn
asset.Url = details.Url
Expand Down
4 changes: 4 additions & 0 deletions providers/os/connection/docker/container_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (c *ContainerConnection) Asset() *inventory.Asset {
return c.asset
}

func (p *ContainerConnection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}

func (c *ContainerConnection) ContainerId() string {
return c.container
}
Expand Down
4 changes: 4 additions & 0 deletions providers/os/connection/fs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ func (c *FileSystemConnection) Type() shared.ConnectionType {
func (c *FileSystemConnection) Asset() *inventory.Asset {
return c.asset
}

func (p *FileSystemConnection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}
4 changes: 4 additions & 0 deletions providers/os/connection/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (p *LocalConnection) Asset() *inventory.Asset {
return p.asset
}

func (p *LocalConnection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}

func (p *LocalConnection) Capabilities() shared.Capabilities {
return shared.Capability_File | shared.Capability_RunCommand
}
Expand Down
4 changes: 4 additions & 0 deletions providers/os/connection/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (c *Connection) Asset() *inventory.Asset {
return c.asset
}

func (p *Connection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}

func (c *Connection) Capabilities() shared.Capabilities {
return shared.Capability_File | shared.Capability_RunCommand
}
Expand Down
1 change: 1 addition & 0 deletions providers/os/connection/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Connection interface {
Name() string
Type() ConnectionType
Asset() *inventory.Asset
UpdateAsset(asset *inventory.Asset)
Capabilities() Capabilities
}

Expand Down
4 changes: 4 additions & 0 deletions providers/os/connection/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (p *Connection) Asset() *inventory.Asset {
return p.asset
}

func (p *Connection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}

func (p *Connection) Capabilities() shared.Capabilities {
return shared.Capability_File | shared.Capability_RunCommand
}
Expand Down
4 changes: 4 additions & 0 deletions providers/os/connection/tar/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (p *Connection) Asset() *inventory.Asset {
return p.asset
}

func (p *Connection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}

func (p *Connection) Conf() *inventory.Config {
return p.conf
}
Expand Down
4 changes: 4 additions & 0 deletions providers/os/connection/winrm/winrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (p *Connection) Asset() *inventory.Asset {
return p.asset
}

func (p *Connection) UpdateAsset(asset *inventory.Asset) {
p.asset = asset
}

func (p *Connection) Capabilities() shared.Capabilities {
return shared.Capability_File | shared.Capability_RunCommand
}
Expand Down
6 changes: 6 additions & 0 deletions providers/os/provider/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error {
// First sort the platform IDs and then call Compact, because Compact removes only consecutive duplicates
slices.Sort(asset.PlatformIds)
asset.PlatformIds = slices.Compact(asset.PlatformIds)

// If the asset connection had the SkipDiscovery flag and the current asset doesn't, we just performed
// discovery for the asset and we need to update it.
if conn.Asset().Connections[0].SkipDiscovery && !asset.Connections[0].SkipDiscovery {
conn.UpdateAsset(asset)
}
return nil
}

Expand Down

0 comments on commit 034c94c

Please sign in to comment.