Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using httputil for NVD #610

Merged
merged 5 commits into from
Sep 19, 2018
Merged

Conversation

MackJM
Copy link
Contributor

@MackJM MackJM commented Sep 6, 2018

nvd was missed when moving to httputil, this fixes it

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not if an error occurs

if err != nil {
return "", err
}
defer r.Body.Close()

if !httputil.Status2xx(r) {
return "", errors.New("Unsuccesuful status code: " + string(r.StatusCode))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsuccessful

Also having some more context in this message would be nice. I have no idea what request was being tried that returned a non-200 status code.

@MackJM
Copy link
Contributor Author

MackJM commented Sep 7, 2018

I was wrong at first with that comment, because that's where it crashed when I had defer there.

@@ -171,7 +171,7 @@ func getDataFeeds(dataFeedHashes map[string]string, localPath string) (map[strin
log.WithError(err).WithField(logDataFeedName, dataFeedName).Error("could not download NVD data feed")
return dataFeedReaders, dataFeedHashes, commonerr.ErrCouldNotDownload
}
// r is closed in BuildCache()
defer r.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't close anything until the whole function getDataFeeds() exits. This is not what we want to do.

It could end up being more trouble than it's worth, but wrapping everything inside the loop iteration into a it's own function might be the best way to get defer to execute at the right time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was a little outside of what I set out with my initial PR, but I agree with you. I think I wrapped it up nicely now. Without spending too much effort.

log.WithError(err).WithField(logDataFeedName, dataFeedName).Error("could not download NVD data feed")
return dataFeedReaders, dataFeedHashes, commonerr.ErrCouldNotDownload
}
downloadAndSave := func() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should pull this out into a top-level function called downloadFeed, rather than an inline function. After that LGTM.

// Store it to a file at the same time if possible.
f, err := os.Create(fileName)
if err != nil {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the OCD, but drop this newline and we're good to go.

@jzelinskie jzelinskie added kind/cleanup no functional changes, only reorganization component/ext/vulnmdsrc labels Sep 14, 2018
@jzelinskie jzelinskie merged commit 44ae4bc into quay:master Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup no functional changes, only reorganization
Development

Successfully merging this pull request may close these issues.

None yet

3 participants