Skip to content

Commit

Permalink
cleanup delayed discovery handling
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Mar 6, 2024
1 parent d3be245 commit b4cd275
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,13 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
}

if asset.Connections[0].DelayDiscovery {
asset.Connections[0].DelayDiscovery = false
if err := runtime.Connect(&plugin.ConnectReq{Asset: asset}); err != nil {
log.Error().Err(err).Str("asset", asset.Name).Msg("failed to connect to asset")
discoveredAsset, err := handleDelayedDiscovery(ctx, asset, runtime, services, spaceMrn)
if err != nil {
reporter.AddScanError(asset, err)
multiprogress.Errored(asset.PlatformIds[0])
continue
}
if services != nil {
resp, err := services.SynchronizeAssets(ctx, &explorer.SynchronizeAssetsReq{
SpaceMrn: spaceMrn,
List: []*inventory.Asset{asset},
})
if err != nil {
reporter.AddScanError(asset, err)
multiprogress.Errored(asset.PlatformIds[0])
continue
}

asset = runtime.Provider.Connection.Asset
slices.Sort(asset.PlatformIds)
details := resp.Details[asset.PlatformIds[0]]
asset.Mrn = details.AssetMrn
asset.Url = details.Url
}
asset = discoveredAsset
}

p := &progress.MultiProgressAdapter{Key: asset.PlatformIds[0], Multi: multiprogress}
Expand All @@ -392,6 +375,30 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return reporter.Reports(), nil
}

func handleDelayedDiscovery(ctx context.Context, asset *inventory.Asset, runtime *providers.Runtime, services *explorer.Services, spaceMrn string) (*inventory.Asset, error) {
asset.Connections[0].DelayDiscovery = false
if err := runtime.Connect(&plugin.ConnectReq{Asset: asset}); err != nil {
return nil, err
}
if services != nil {
resp, err := services.SynchronizeAssets(ctx, &explorer.SynchronizeAssetsReq{
SpaceMrn: spaceMrn,
List: []*inventory.Asset{asset},
})
if err != nil {
return nil, err
}

asset = runtime.Provider.Connection.Asset
slices.Sort(asset.PlatformIds)
details := resp.Details[asset.PlatformIds[0]]
asset.Mrn = details.AssetMrn
asset.Url = details.Url
asset.KindString = asset.GetPlatform().Kind
}
return asset, nil
}

func (s *LocalScanner) RunAssetJob(job *AssetJob) {
log.Debug().Msgf("connecting to asset %s", job.Asset.HumanName())
results, err := s.runMotorizedAsset(job)
Expand Down

0 comments on commit b4cd275

Please sign in to comment.