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

Fix gosec issue #664

Merged
merged 1 commit into from
Feb 7, 2023
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
6 changes: 5 additions & 1 deletion src/cluster/clusterMgmtHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ func getResponseBytes(method string, url string, data map[string]interface{}) []
return nil
}
dumpHttpClient(nil, resp)
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
log.Warn().Msgf("Error closing http stream %s\n", err)
}
}()

// read response to []byte
resByte, err := ioutil.ReadAll(resp.Body)
Expand Down
6 changes: 5 additions & 1 deletion src/cluster/kvmServiceHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func GetResourcesFromKvmService() ([]string, []types.Pod) {
log.Error().Msgf("http response error: %s", err.Error())
return nil, nil
}
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
log.Warn().Msgf("Error closing http stream %s\n", err)
}
}()

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func configure(config Config) *zerolog.Logger {
}

func newRollingFile(config Config) io.Writer {
if err := os.MkdirAll(config.Directory, 0744); err != nil {
if err := os.MkdirAll(config.Directory, 0700); err != nil {
log.Error().Err(err).Str("path", config.Directory).Msg("can't create log directory")
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion src/recommendpolicy/downloadTemplates.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ func unZip(source, dest string) error {
if err = create.Close(); err != nil {
return err
}
defer open.Close()
defer func() {
if err := open.Close(); err != nil {
log.Warn().Msgf("Error closing file %s\n", err)
}
}()
}
return nil
}
Expand Down