Using httputil for NVD
nvd was missed when moving to httputil, this fixes it
This commit is contained in:
parent
089a4e0f0a
commit
49cbdd7a7c
@ -24,7 +24,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@ -36,6 +35,7 @@ import (
|
||||
"github.com/coreos/clair/database"
|
||||
"github.com/coreos/clair/ext/vulnmdsrc"
|
||||
"github.com/coreos/clair/pkg/commonerr"
|
||||
"github.com/coreos/clair/pkg/httputil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -166,11 +166,17 @@ func getDataFeeds(dataFeedHashes map[string]string, localPath string) (map[strin
|
||||
}
|
||||
|
||||
// Download data feed.
|
||||
r, err := http.Get(fmt.Sprintf(dataFeedURL, dataFeedName))
|
||||
r, err := httputil.GetWithUserAgent(fmt.Sprintf(dataFeedURL, dataFeedName))
|
||||
if err != nil {
|
||||
log.WithError(err).WithField(logDataFeedName, dataFeedName).Error("could not download NVD data feed")
|
||||
return dataFeedReaders, dataFeedHashes, commonerr.ErrCouldNotDownload
|
||||
}
|
||||
// r is closed in BuildCache()
|
||||
|
||||
if !httputil.Status2xx(r) {
|
||||
log.WithField("StatusCode", r.StatusCode).Error("Failed to download NVD data feed")
|
||||
return dataFeedReaders, dataFeedHashes, commonerr.ErrCouldNotDownload
|
||||
}
|
||||
|
||||
// Un-gzip it.
|
||||
gr, err := gzip.NewReader(r.Body)
|
||||
@ -199,12 +205,16 @@ func getDataFeeds(dataFeedHashes map[string]string, localPath string) (map[strin
|
||||
}
|
||||
|
||||
func getHashFromMetaURL(metaURL string) (string, error) {
|
||||
r, err := http.Get(metaURL)
|
||||
r, err := httputil.GetWithUserAgent(metaURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
if !httputil.Status2xx(r) {
|
||||
return "", errors.New("Unsuccesuful status code: " + string(r.StatusCode))
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(r.Body)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
Loading…
Reference in New Issue
Block a user