diff --git a/internal/app/wwclient/root.go b/internal/app/wwclient/root.go index efe4271f..be8c2fd5 100644 --- a/internal/app/wwclient/root.go +++ b/internal/app/wwclient/root.go @@ -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) diff --git a/internal/app/wwctl/configure/tls/main.go b/internal/app/wwctl/configure/tls/main.go index d422515b..098b9ce3 100644 --- a/internal/app/wwctl/configure/tls/main.go +++ b/internal/app/wwctl/configure/tls/main.go @@ -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 } diff --git a/internal/pkg/configure/tls.go b/internal/pkg/configure/tls.go index fb55cc14..8e5b355a 100644 --- a/internal/pkg/configure/tls.go +++ b/internal/pkg/configure/tls.go @@ -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) } diff --git a/internal/pkg/warewulfd/efi_test.go b/internal/pkg/warewulfd/efi_test.go index cc423fb5..aedaf067 100644 --- a/internal/pkg/warewulfd/efi_test.go +++ b/internal/pkg/warewulfd/efi_test.go @@ -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) diff --git a/internal/pkg/warewulfd/grub_test.go b/internal/pkg/warewulfd/grub_test.go index df57af44..38eccf53 100644 --- a/internal/pkg/warewulfd/grub_test.go +++ b/internal/pkg/warewulfd/grub_test.go @@ -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) diff --git a/internal/pkg/warewulfd/initramfs_test.go b/internal/pkg/warewulfd/initramfs_test.go index febbedde..d2fe35d5 100644 --- a/internal/pkg/warewulfd/initramfs_test.go +++ b/internal/pkg/warewulfd/initramfs_test.go @@ -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) }) diff --git a/internal/pkg/warewulfd/ipxe_test.go b/internal/pkg/warewulfd/ipxe_test.go index 9aaacc51..50954783 100644 --- a/internal/pkg/warewulfd/ipxe_test.go +++ b/internal/pkg/warewulfd/ipxe_test.go @@ -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) diff --git a/internal/pkg/warewulfd/overlay_test.go b/internal/pkg/warewulfd/overlay_test.go index 5bd76d1d..dcc9ea03 100644 --- a/internal/pkg/warewulfd/overlay_test.go +++ b/internal/pkg/warewulfd/overlay_test.go @@ -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)