diff --git a/explorer/scan/local_scanner.go b/explorer/scan/local_scanner.go index 9e708e0234..1961124618 100644 --- a/explorer/scan/local_scanner.go +++ b/explorer/scan/local_scanner.go @@ -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} @@ -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)