Skip to content

Commit

Permalink
enricher: replace io.ReadCloser with io.Reader
Browse files Browse the repository at this point in the history
Signed-off-by: RTann <rtannenb@redhat.com>
  • Loading branch information
RTann committed Feb 24, 2025
1 parent 6710a18 commit e9c6e41
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions enricher/cvss/cvss.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ func (e *Enricher) FetchEnrichment(ctx context.Context, hint driver.Fingerprint)
}

// ParseEnrichment implements driver.EnrichmentUpdater.
func (e *Enricher) ParseEnrichment(ctx context.Context, rc io.ReadCloser) ([]driver.EnrichmentRecord, error) {
func (e *Enricher) ParseEnrichment(ctx context.Context, rc io.Reader) ([]driver.EnrichmentRecord, error) {
ctx = zlog.ContextWithValues(ctx, "component", "enricher/cvss/Enricher/ParseEnrichment")
// Our Fetch method actually has all the smarts w/r/t to constructing the
// records, so this is just decoding in a loop.
defer rc.Close()
var err error
dec := json.NewDecoder(rc)
ret := make([]driver.EnrichmentRecord, 0, 1024) // Wild guess at initial capacity.
Expand Down
4 changes: 1 addition & 3 deletions enricher/epss/epss.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,9 @@ func (e *Enricher) FetchEnrichment(ctx context.Context, prevFingerprint driver.F
}

// ParseEnrichment implements driver.EnrichmentUpdater.
func (e *Enricher) ParseEnrichment(ctx context.Context, rc io.ReadCloser) ([]driver.EnrichmentRecord, error) {
func (e *Enricher) ParseEnrichment(ctx context.Context, rc io.Reader) ([]driver.EnrichmentRecord, error) {
ctx = zlog.ContextWithValues(ctx, "component", "enricher/epss/Enricher/ParseEnrichment")

defer rc.Close()

dec := json.NewDecoder(rc)
ret := make([]driver.EnrichmentRecord, 0, 250_000)
var err error
Expand Down
4 changes: 2 additions & 2 deletions libvuln/driver/enrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ type EnrichmentUpdater interface {
//
// If there's no new data, the method should report Unchanged.
FetchEnrichment(context.Context, Fingerprint) (io.ReadCloser, Fingerprint, error)
// ParseEnrichment reads from the provided io.ReadCloser, parses its contents,
// ParseEnrichment reads from the provided io.Reader, parses its contents,
// and returns a slice of EnrichmentRecords or an error.
ParseEnrichment(context.Context, io.ReadCloser) ([]EnrichmentRecord, error)
ParseEnrichment(context.Context, io.Reader) ([]EnrichmentRecord, error)
}

// NoopUpdater is designed to be embedded into other Updater types so they can
Expand Down

0 comments on commit e9c6e41

Please sign in to comment.