Skip to content

Commit

Permalink
epss: removed logs
Browse files Browse the repository at this point in the history
Signed-off-by: daynewlee <[email protected]>
  • Loading branch information
daynewlee committed Dec 1, 2024
1 parent 24e8e6f commit 1f2f56a
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions enricher/epss/epss.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ var (
defaultFeed *url.URL
)

type EPSSItem struct {
ModelVersion string `json:"modelVersion"`
Date string `json:"date"`
CVE string `json:"cve"`
EPSS float64 `json:"epss"`
Percentile float64 `json:"percentile"`
}

// This is a slightly more relaxed version of the validation pattern in the NVD
// JSON schema: https://csrc.nist.gov/schema/nvd/feed/1.1/CVE_JSON_4.0_min_1.1.schema
//
Expand Down Expand Up @@ -295,7 +303,6 @@ func (e *Enricher) Enrich(ctx context.Context, g driver.EnrichmentGetter, r *cla
sort.Strings(ts)

cveKey := strings.Join(ts, "_")
zlog.Debug(ctx).Str("cve_key", cveKey).Strs("cve", ts).Msg("generated CVE cache key")

rec, ok := erCache[cveKey]
if !ok {
Expand Down Expand Up @@ -335,30 +342,40 @@ func (e *Enricher) Enrich(ctx context.Context, g driver.EnrichmentGetter, r *cla
}

func newItemFeed(record []string, headers []string, modelVersion string, scoreDate string) (driver.EnrichmentRecord, error) {
item := make(map[string]interface{}) // Use interface{} to allow mixed types
if len(record) != len(headers) {
return driver.EnrichmentRecord{}, fmt.Errorf("record and headers length mismatch")
}

var item EPSSItem
for i, value := range record {
// epss details are numeric values
if f, err := strconv.ParseFloat(value, 64); err == nil {
item[headers[i]] = f
} else {
item[headers[i]] = value
switch headers[i] {
case "cve":
item.CVE = value
case "epss":
if f, err := strconv.ParseFloat(value, 64); err == nil {
item.EPSS = f
} else {
return driver.EnrichmentRecord{}, fmt.Errorf("invalid float for epss: %w", err)
}
case "percentile":
if f, err := strconv.ParseFloat(value, 64); err == nil {
item.Percentile = f
} else {
return driver.EnrichmentRecord{}, fmt.Errorf("invalid float for percentile: %w", err)
}
}
}

if modelVersion != "" {
item["modelVersion"] = modelVersion
}
if scoreDate != "" {
item["date"] = scoreDate
}
item.ModelVersion = modelVersion
item.Date = scoreDate

enrichment, err := json.Marshal(item)
if err != nil {
return driver.EnrichmentRecord{}, fmt.Errorf("unable to encode enrichment: %w", err)
}

r := driver.EnrichmentRecord{
Tags: []string{item["cve"].(string)}, // Ensure the "cve" field is a string
Tags: []string{item.CVE}, // CVE field should be set
Enrichment: enrichment,
}

Expand Down

0 comments on commit 1f2f56a

Please sign in to comment.