Skip to content

Commit

Permalink
revert: use embedded fs connection and expose MountedDirs
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp committed Oct 8, 2024
1 parent c188b0b commit 3f5fa33
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions providers/os/connection/device/device_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
const PlatformIdInject = "inject-platform-ids"

type DeviceConnection struct {
FsConnections []*fs.FileSystemConnection
*fs.FileSystemConnection
plugin.Connection
asset *inventory.Asset
deviceManager DeviceManager

MountedDirs []string
}

func getDeviceManager(conf *inventory.Config) (DeviceManager, error) {
Expand Down Expand Up @@ -79,6 +81,8 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory
}

conf.Options["path"] = scanDir
res.MountedDirs = append(res.MountedDirs, scanDir)

// create and initialize fs provider
fsConn, err := fs.NewConnection(connId, &inventory.Config{
Path: scanDir,
Expand All @@ -92,8 +96,6 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory
return nil, err
}

res.FsConnections = append(res.FsConnections, fsConn)

// allow injecting platform ids into the device connection. we cannot always know the asset that's being scanned, e.g.
// if we can scan an azure VM's disk we should be able to inject the platform ids of the VM
if platformIDs, ok := conf.Options[PlatformIdInject]; ok {
Expand All @@ -119,7 +121,7 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory
}
asset.Platform = p
asset.IdDetector = []string{ids.IdDetector_Hostname}
fingerprint, p, err := id.IdentifyPlatform(fsConn, &plugin.ConnectReq{}, asset.Platform, asset.IdDetector)
fingerprint, p, err := id.IdentifyPlatform(res, &plugin.ConnectReq{}, asset.Platform, asset.IdDetector)
if err == nil {
if asset.Name == "" {
asset.Name = fingerprint.Name
Expand All @@ -128,6 +130,8 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory
asset.IdDetector = fingerprint.ActiveIdDetectors
asset.Platform = p
asset.Id = conf.Type

res.FileSystemConnection = fsConn
}
}

Expand All @@ -136,6 +140,11 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory
return nil, errors.New("failed to detect OS")
}

if res.FileSystemConnection == nil {
res.Close()
return nil, errors.New("failed to create fs connection")
}

return res, nil
}

Expand Down Expand Up @@ -167,21 +176,21 @@ func (p *DeviceConnection) UpdateAsset(asset *inventory.Asset) {
}

func (p *DeviceConnection) Capabilities() shared.Capabilities {
return p.FsConnections[0].Capabilities()
return p.FileSystemConnection.Capabilities()
}

func (p *DeviceConnection) RunCommand(command string) (*shared.Command, error) {
return nil, plugin.ErrRunCommandNotImplemented
}

func (p *DeviceConnection) FileSystem() afero.Fs {
return p.FsConnections[0].FileSystem()
return p.FileSystemConnection.FileSystem()
}

func (p *DeviceConnection) FileInfo(path string) (shared.FileInfoDetails, error) {
return p.FsConnections[0].FileInfo(path)
return p.FileSystemConnection.FileInfo(path)
}

func (p *DeviceConnection) Conf() *inventory.Config {
return p.FsConnections[0].Conf
return p.FileSystemConnection.Conf
}

1 comment on commit 3f5fa33

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 3f5fa33 Previous: afec124 Ratio
BenchmarkScan_SingleAsset - B/op 238929264 B/op 141334920 B/op 1.69

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.