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 f69a9e2
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,11 @@ 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")
if err := handleDelayedDiscovery(ctx, asset, runtime, services, spaceMrn); 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
}
}

p := &progress.MultiProgressAdapter{Key: asset.PlatformIds[0], Multi: multiprogress}
Expand All @@ -392,6 +373,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) error {
asset.Connections[0].DelayDiscovery = false
if err := runtime.Connect(&plugin.ConnectReq{Asset: asset}); err != nil {
return err
}
if services != nil {
resp, err := services.SynchronizeAssets(ctx, &explorer.SynchronizeAssetsReq{
SpaceMrn: spaceMrn,
List: []*inventory.Asset{asset},
})
if err != nil {
return 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 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 f69a9e2

Please sign in to comment.