Skip to content

Commit

Permalink
epss: generate single item
Browse files Browse the repository at this point in the history
Signed-off-by: daynewlee <[email protected]>
  • Loading branch information
daynewlee committed Nov 14, 2024
1 parent 39a9a2e commit f5058ef
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions enricher/epss/epss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit f5058ef

Please sign in to comment.