diff --git a/CHANGELOG.md b/CHANGELOG.md index d185a47..762e8be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - EPSS Score URL default date go's std lib date parsing uses '02' for day - Viper flag collision between list and validate commands +- EPSS URL env var use ## [0.4.0] - 2024-03-19 diff --git a/cmd/v1/list.go b/cmd/v1/list.go index 649fce6..18e911e 100644 --- a/cmd/v1/list.go +++ b/cmd/v1/list.go @@ -66,10 +66,10 @@ func runList(cmd *cobra.Command, args []string) error { } } - // TODO: use options instead of parameters if listAll { slog.Debug("listing with epss scores") return gatecheck.ListAll(cmd.OutOrStdout(), src, filename, http.DefaultClient, epssURL, epssFile) } + return gatecheck.List(cmd.OutOrStdout(), src, filename) } diff --git a/pkg/epss/v1/epss.go b/pkg/epss/v1/epss.go index cf34566..39b636c 100644 --- a/pkg/epss/v1/epss.go +++ b/pkg/epss/v1/epss.go @@ -58,12 +58,18 @@ func (c CVE) PercentileValue() float64 { type fetchOptionFunc func(*FetchOptions) func WithURL(url string) fetchOptionFunc { + if url == "" { + return func(_ *FetchOptions) {} + } return func(o *FetchOptions) { o.URL = url } } func WithClient(client *http.Client) fetchOptionFunc { + if client == nil { + return func(_ *FetchOptions) {} + } return func(o *FetchOptions) { o.Client = client } @@ -129,13 +135,13 @@ func DownloadData(w io.Writer, optionFuncs ...fetchOptionFunc) error { } // FetchData do a GET request and gunzip on the CSV -func FetchData(data *Data, optionFuncs ...fetchOptionFunc) error { +func FetchData(destData *Data, optionFuncs ...fetchOptionFunc) error { buf := new(bytes.Buffer) if err := DownloadData(buf, optionFuncs...); err != nil { return err } - return ParseEPSSDataCSV(buf, data) + return ParseEPSSDataCSV(buf, destData) } // ParseEPSSDataCSV custom CSV parsing function diff --git a/pkg/gatecheck/list.go b/pkg/gatecheck/list.go index 0151b00..324af82 100644 --- a/pkg/gatecheck/list.go +++ b/pkg/gatecheck/list.go @@ -67,12 +67,7 @@ func ListAll(dst io.Writer, src io.Reader, inputFilename string, client *http.Cl return errors.New("Failed to decode EPSS data file. See log for details.") } default: - fetchOptions := epss.DefaultFetchOptions() - fetchOptions.Client = client - if epssURL != "" { - fetchOptions.URL = epssURL - } - if err := epss.FetchData(epssData); err != nil { + if err := epss.FetchData(epssData, epss.WithClient(client), epss.WithURL(epssURL)); err != nil { return err } }