util: log error when closing temp fail fails in GetOMapValue()

gosec-2.3.0 complains about the following:

    [/go/src/github.com/ceph/ceph-csi/internal/util/cephcmds.go:146] - G307 (CWE-): Deferring unsafe method "*os.File" on type "Close" (Confidence: HIGH, Severity: MEDIUM)
      > defer tmpFile.Close()

By logging the error from Close(), the warning is gone.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-30 11:31:47 +02:00 committed by mergify[bot]
parent 21bd26ebc4
commit 16c4e33b09

View File

@ -142,7 +142,12 @@ func GetOMapValue(ctx context.Context, monitors string, cr *Credentials, poolNam
klog.Errorf(Log(ctx, "failed creating a temporary file for key contents"))
return "", err
}
defer tmpFile.Close()
defer func() {
ce := tmpFile.Close()
if ce != nil {
klog.Warningf(Log(ctx, "failed closing temporary file: %s"), ce)
}
}()
defer os.Remove(tmpFile.Name())
args := []string{