Adress linter issues from TLS update

This commit is contained in:
Christian Goll
2026-03-11 10:15:06 +01:00
parent 1c9757b683
commit 82b7cf9095
8 changed files with 24 additions and 24 deletions

View File

@@ -346,7 +346,7 @@ func updateSystem(target string, ipaddr string, port int, wwid string, tag strin
}
time.Sleep(1000 * time.Millisecond)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != 200 {
wwlog.Warn("not applying runtime overlay: got status code: %d", resp.StatusCode)
time.Sleep(60000 * time.Millisecond)

View File

@@ -48,7 +48,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if err := os.Chmod(certFile, 0644); err != nil {
return fmt.Errorf("failed to set cert file permissions: %w", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "Imported keys from %s\n", importPath)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Imported keys from %s\n", importPath)
if err := configure.WAREWULFD(); err != nil {
return fmt.Errorf("failed to restart warewulfd: %w", err)
@@ -67,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if err := util.CopyFile(certFile, path.Join(exportPath, "warewulf.crt")); err != nil {
return fmt.Errorf("failed to export cert: %w", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "Exported keys to %s\n", exportPath)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Exported keys to %s\n", exportPath)
return nil
}
if !conf.Warewulf.TLSEnabled() {
fmt.Fprintf(cmd.OutOrStdout(), "TLS is not enabled in warewulf.conf\n")
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "TLS is not enabled in warewulf.conf\n")
return nil
}
@@ -85,20 +85,20 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to restart warewulfd: %w", err)
}
} else {
fmt.Fprintf(cmd.OutOrStdout(), "Keys already exist in %s\n", keystore)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Keys already exist in %s\n", keystore)
}
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
fmt.Fprintf(w, "Private Key:\t%s\n", keyFile)
fmt.Fprintf(w, "Certificate:\t%s\n", certFile)
_, _ = fmt.Fprintf(w, "Private Key:\t%s\n", keyFile)
_, _ = fmt.Fprintf(w, "Certificate:\t%s\n", certFile)
keyBytes, err := os.ReadFile(keyFile)
if err == nil {
block, _ := pem.Decode(keyBytes)
if block != nil {
if key, err := x509.ParsePKCS1PrivateKey(block.Bytes); err == nil {
fmt.Fprintf(w, "Key Size:\t%d bits\n", key.N.BitLen())
_, _ = fmt.Fprintf(w, "Key Size:\t%d bits\n", key.N.BitLen())
}
}
}
@@ -108,22 +108,22 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
block, _ := pem.Decode(certBytes)
if block != nil {
if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
fmt.Fprintf(w, "Issuer:\t%s\n", cert.Issuer)
fmt.Fprintf(w, "Subject:\t%s\n", cert.Subject)
fmt.Fprintf(w, "Valid From:\t%s\n", cert.NotBefore)
fmt.Fprintf(w, "Valid Until:\t%s\n", cert.NotAfter)
fmt.Fprintf(w, "Serial Nr:\t%s\n", cert.SerialNumber)
_, _ = fmt.Fprintf(w, "Issuer:\t%s\n", cert.Issuer)
_, _ = fmt.Fprintf(w, "Subject:\t%s\n", cert.Subject)
_, _ = fmt.Fprintf(w, "Valid From:\t%s\n", cert.NotBefore)
_, _ = fmt.Fprintf(w, "Valid Until:\t%s\n", cert.NotAfter)
_, _ = fmt.Fprintf(w, "Serial Nr:\t%s\n", cert.SerialNumber)
var ipStrings []string
for _, ip := range cert.IPAddresses {
ipStrings = append(ipStrings, ip.String())
}
fmt.Fprintf(w, "IP Addresses:\t%s\n", strings.Join(ipStrings, ", "))
fmt.Fprintf(w, "DNS Names:\t%s\n", strings.Join(cert.DNSNames, ", "))
_, _ = fmt.Fprintf(w, "IP Addresses:\t%s\n", strings.Join(ipStrings, ", "))
_, _ = fmt.Fprintf(w, "DNS Names:\t%s\n", strings.Join(cert.DNSNames, ", "))
}
}
}
w.Flush()
_ = w.Flush()
return nil
}

View File

@@ -100,7 +100,7 @@ func GenTLSKeys() error {
if err != nil {
return fmt.Errorf("failed to open key file for writing: %w", err)
}
defer keyOut.Close()
defer func() { _ = keyOut.Close() }()
if err := pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}); err != nil {
return fmt.Errorf("failed to write data to key file: %w", err)
}
@@ -109,7 +109,7 @@ func GenTLSKeys() error {
if err != nil {
return fmt.Errorf("failed to open cert file for writing: %w", err)
}
defer certOut.Close()
defer func() { _ = certOut.Close() }()
if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
return fmt.Errorf("failed to write data to cert file: %w", err)
}

View File

@@ -77,7 +77,7 @@ nodes:
w := httptest.NewRecorder()
HandleEfiBoot(w, req)
res := w.Result()
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()
data, readErr := io.ReadAll(res.Body)
assert.NoError(t, readErr)

View File

@@ -63,7 +63,7 @@ nodes:
w := httptest.NewRecorder()
HandleGrub(w, req)
res := w.Result()
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()
data, readErr := io.ReadAll(res.Body)
assert.NoError(t, readErr)

View File

@@ -52,7 +52,7 @@ nodes:
w := httptest.NewRecorder()
HandleInitramfs(w, req)
res := w.Result()
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()
assert.Equal(t, tt.status, res.StatusCode)
})

View File

@@ -67,7 +67,7 @@ func Test_HandleIpxe(t *testing.T) {
w := httptest.NewRecorder()
HandleIpxe(w, req)
res := w.Result()
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()
data, readErr := io.ReadAll(res.Body)
assert.NoError(t, readErr)

View File

@@ -100,7 +100,7 @@ nodes:
w := httptest.NewRecorder()
HandleOverlayFile(w, req)
res := w.Result()
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()
data, readErr := io.ReadAll(res.Body)
assert.NoError(t, readErr)
@@ -168,7 +168,7 @@ nodes:
w := httptest.NewRecorder()
HandleSystemOverlay(w, req)
res := w.Result()
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()
data, readErr := io.ReadAll(res.Body)
assert.NoError(t, readErr)