From f5058efc5c9c041830308831b031ff727854bbba Mon Sep 17 00:00:00 2001 From: daynewlee Date: Thu, 14 Nov 2024 15:59:41 -0600 Subject: [PATCH] epss: generate single item Signed-off-by: daynewlee --- enricher/epss/epss.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/enricher/epss/epss.go b/enricher/epss/epss.go index 97e96db32..d931633e3 100644 --- a/enricher/epss/epss.go +++ b/enricher/epss/epss.go @@ -165,20 +165,7 @@ func (e *Enricher) FetchEnrichment(ctx context.Context, _ driver.Fingerprint) (i continue // Skip lines with mismatched number of fields } - item := make(map[string]string) - for i, value := range record { - item[headers[i]] = value - } - - enrichment, err := json.Marshal(item) - if err != nil { - return nil, "", fmt.Errorf("failed to encode enrichment: %w", err) - } - - r := driver.EnrichmentRecord{ - Tags: []string{item["cve"]}, - Enrichment: enrichment, - } + r, err := newItemFeed(ctx, record, headers) if err = enc.Encode(&r); err != nil { return nil, "", fmt.Errorf("failed to write JSON line to file: %w", err) @@ -294,3 +281,22 @@ func (e *Enricher) Enrich(ctx context.Context, g driver.EnrichmentGetter, r *cla } return Type, []json.RawMessage{b}, nil } + +func newItemFeed(ctx context.Context, record []string, headers []string) (driver.EnrichmentRecord, error) { + item := make(map[string]string) + for i, value := range record { + item[headers[i]] = value + } + + enrichment, err := json.Marshal(item) + if err != nil { + return driver.EnrichmentRecord{}, fmt.Errorf("failed to encode enrichment: %w", err) + } + + r := driver.EnrichmentRecord{ + Tags: []string{item["cve"]}, + Enrichment: enrichment, + } + + return r, nil +}