Skip to content

Commit

Permalink
fix: resolve all gosec issues (#158)
Browse files Browse the repository at this point in the history
* fix: resolve all gosec issues

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>

* fix: nosec for G402 issue

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>

---------

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson authored Dec 19, 2023
1 parent 1c960f8 commit dbca19b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/sinks/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *AlertmanagerSink) Configure(c Client, config map[string][]byte) error {
}
caCertPool.AppendCertsFromPEM(caCert)
}

// #nosec G402
c.hclient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecureSkipVerify,
Expand Down
23 changes: 16 additions & 7 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *helmClient) exec(args []string) error {
sanitizedArgs := sb.String()

fmt.Println("helm " + sanitizedArgs)
cmd := exec.Command(c.helmPath, args...)
cmd := exec.Command(c.helmPath, args...) // #nosec G204
if c.stdout != nil {
cmd.Stdout = c.stdout
cmd.Stderr = c.stderr
Expand Down Expand Up @@ -142,12 +142,16 @@ func (c *helmClient) run(name, namespace string, options UpgradeOptions, command
// Write to temp file
_, err = tempFile.Write([]byte(options.Values))
if err != nil {
os.Remove(tempFile.Name())
if removeErr := os.Remove(tempFile.Name()); removeErr != nil {
klog.Errorf("failed to remove temp file %s: %v", tempFile.Name(), err)
}
return errors.Wrap(err, "write temp file")
}

// Close temp file
tempFile.Close()
if err := tempFile.Close(); err != nil {
return errors.Wrap(err, "close temp file")
}
defer os.Remove(tempFile.Name())

// Wait quickly so helm will find the file
Expand Down Expand Up @@ -215,12 +219,16 @@ func writeKubeConfig(configRaw *clientcmdapi.Config) (string, error) {
// Write to temp file
_, err = tempFile.Write(data)
if err != nil {
os.Remove(tempFile.Name())
if removeErr := os.Remove(tempFile.Name()); removeErr != nil {
klog.Errorf("failed to remove temp file %s: %v", tempFile.Name(), err)
}
return "", errors.Wrap(err, "write temp file")
}

// Close temp file
tempFile.Close()
if err := tempFile.Close(); err != nil {
return "", errors.Wrap(err, "close temp file")
}

// Okay sometimes the file is written so quickly that helm somehow
// cannot read it immediately which causes errors
Expand All @@ -233,8 +241,9 @@ func writeKubeConfig(configRaw *clientcmdapi.Config) (string, error) {
time.Sleep(time.Millisecond * 50)
continue
}

os.Remove(tempFile.Name())
if removeErr := os.Remove(tempFile.Name()); removeErr != nil {
klog.Errorf("failed to remove temp file %s: %v", tempFile.Name(), err)
}
return "", err
}
break
Expand Down

0 comments on commit dbca19b

Please sign in to comment.