Skip to content

Commit

Permalink
set bundle in reporter
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Mar 7, 2024
1 parent 1f4eb6d commit b66b9b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
}
}()

// plan scan jobs
reporter := NewAggregateReporter()
if job.Bundle == nil && upstream != nil && upstream.Creds != nil {
client, err := upstream.InitClient()
if err != nil {
Expand All @@ -237,10 +239,9 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return nil, err
}
job.Bundle = bundle
reporter.AddBundle(bundle)
}

// plan scan jobs
reporter := NewAggregateReporter()
// if we had asset errors we want to place them into the reporter
for i := range discoveredAssets.Errors {
reporter.AddScanError(discoveredAssets.Errors[i].Asset, discoveredAssets.Errors[i].Err)
Expand Down Expand Up @@ -461,6 +462,11 @@ func (s *localAssetScanner) prepareAsset() error {
if err := s.ensureBundle(); err != nil {
return err
}

// add asset bundle to the reporter
if s.job.Reporter != nil && s.job.Bundle != nil {
s.job.Reporter.AddBundle(s.job.Bundle)
}
}

if s.job.Bundle == nil {
Expand Down Expand Up @@ -653,8 +659,7 @@ func (s *localAssetScanner) runQueryPack() (*AssetReport, error) {
}

ar := &AssetReport{
Mrn: s.job.Asset.Mrn,
// Bundle: assetBundle,
Mrn: s.job.Asset.Mrn,
Resolved: resolvedPack,
}

Expand Down
7 changes: 5 additions & 2 deletions explorer/scan/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

type Reporter interface {
AddReport(asset *inventory.Asset, results *AssetReport)
AddBundle(bundle *explorer.Bundle)
AddScanError(asset *inventory.Asset, err error)
}

type AssetReport struct {
Mrn string
Bundle *explorer.Bundle
Report *explorer.Report
Resolved *explorer.ResolvedPack
}
Expand All @@ -42,7 +42,10 @@ func (r *AggregateReporter) AddReport(asset *inventory.Asset, results *AssetRepo
r.assets[asset.Mrn] = &explorer.Asset{Name: asset.Name, Mrn: asset.Mrn}
r.assetReports[asset.Mrn] = results.Report
r.resolved[asset.Mrn] = results.Resolved
r.bundle = results.Bundle
}

func (r *AggregateReporter) AddBundle(bundle *explorer.Bundle) {
r.bundle = bundle
}

func (r *AggregateReporter) AddScanError(asset *inventory.Asset, err error) {
Expand Down

0 comments on commit b66b9b7

Please sign in to comment.