Skip to content

Commit

Permalink
Merge pull request #63 from gatecheckdev/61-the-gatecheck_epss_url-en…
Browse files Browse the repository at this point in the history
…vironment-variable-has-no-effect-on-the-list-command

fix: epss url env variable use
  • Loading branch information
BacchusJackson authored Apr 2, 2024
2 parents f0934dc + 2b90d41 commit 6195381
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cmd/v1/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 8 additions & 2 deletions pkg/epss/v1/epss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions pkg/gatecheck/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 6195381

Please sign in to comment.