Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func NewReportCmd(config *viper.Viper) *cobra.Command {
if openErr != nil {
return fmt.Errorf("report path %s: error opening file %v", reportArg, openErr)
}
defer reportFile.Close()

reportBytes, readErr := io.ReadAll(reportFile)
if readErr != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/chartverifier/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func SignatureIsValid(opts *CheckOptions) (Result, error) {
if err != nil {
return NewResult(false, fmt.Sprintf("%s : get error was %v", SignatureFailure, err)), nil
}
defer resp.Body.Close()

if resp.StatusCode == 404 {
return NewSkippedResult(fmt.Sprintf("%s : %s", ChartNotSigned, SignatureIsNotPresentSuccess)), nil
Expand Down Expand Up @@ -458,6 +459,8 @@ func downloadFile(fileURL *url.URL, directory string) (string, error) {
if err != nil {
return "", err
}
defer file.Close()

client := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
Expand All @@ -476,8 +479,6 @@ func downloadFile(fileURL *url.URL, directory string) (string, error) {
if err != nil {
return "", err
}
// #nosec G307
defer file.Close()

return filePath, nil
}
Expand Down
1 change: 1 addition & 0 deletions internal/chartverifier/checks/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func loadChartFromRemote(url *url.URL) (*chart.Chart, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusNotFound {
return nil, ChartNotFoundErr(url.String())
Expand Down
8 changes: 4 additions & 4 deletions internal/chartverifier/pyxis/pyxis.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func GetImageRegistries(repository string) ([]string, error) {
if reqErr != nil {
err = fmt.Errorf("error getting repository %s : %v", repository, err)
} else {
// #nosec G307
defer resp.Body.Close()
if resp.StatusCode == 200 {
// #nosec G307
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var repositoriesBody RepositoriesBody
//nolint:errcheck // TODO(komish): this should be checked, but we really need
Expand Down Expand Up @@ -162,9 +162,9 @@ Loops:
resp, reqErr := client.Do(req)

if reqErr == nil {
// #nosec G307
defer resp.Body.Close()
if resp.StatusCode == 200 {
// #nosec G307
defer resp.Body.Close()
// TODO(komish): this should be checked, but we really need
// to look at refactoring this block in its entirety. Delay fixing this until then
//
Expand Down
1 change: 1 addition & 0 deletions pkg/chartverifier/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func loadReportFromRemote(url *url.URL) (string, error) {
if getErr != nil {
return "", fmt.Errorf("report uri %s: error reading from url %v", url, getErr)
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusNotFound {
return "", fmt.Errorf("report uri %s: bad response reading from url %d", url, resp.StatusCode)
Expand Down
1 change: 1 addition & 0 deletions pkg/chartverifier/reportsummary/reportsummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func loadChartFromAbsPath(path string) ([]byte, error) {
if openErr != nil {
return nil, fmt.Errorf("report path %s: error opening file %v", path, openErr)
}
defer reportFile.Close()

reportBytes, readErr := io.ReadAll(reportFile)
if readErr != nil {
Expand Down