From e9e33fb851c415124c5c2752453b6b8b04459467 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 1 Feb 2023 18:10:01 +0100 Subject: [PATCH] cleanup: fix static checks fix SA1019 static check to replace io/utils with os package Signed-off-by: Madhu Rajanna --- internal/kms/vault.go | 6 ++---- internal/kms/vault_sa.go | 3 +-- internal/rbd/rbd_util_test.go | 3 +-- internal/util/credentials.go | 3 +-- internal/util/log/log_utils_test.go | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/internal/kms/vault.go b/internal/kms/vault.go index 0633998c6..f1b42a396 100644 --- a/internal/kms/vault.go +++ b/internal/kms/vault.go @@ -19,7 +19,6 @@ package kms import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strconv" @@ -254,7 +253,6 @@ func (vc *vaultConnection) initConnection(config map[string]interface{}) error { // initCertificates sets VAULT_* environment variables in the vc.vaultConfig map, // these settings will be used when connecting to the Vault service with // vc.connectVault(). -// func (vc *vaultConnection) initCertificates(config map[string]interface{}, secrets map[string]string) error { vaultConfig := make(map[string]interface{}) @@ -481,9 +479,9 @@ func detectAuthMountPath(path string) (string, error) { } // createTempFile writes data to a temporary file that contains the pattern in -// the filename (see ioutil.TempFile for details). +// the filename (see os.CreateTemp for details). func createTempFile(pattern string, data []byte) (string, error) { - t, err := ioutil.TempFile("", pattern) + t, err := os.CreateTemp("", pattern) if err != nil { return "", fmt.Errorf("failed to create temporary file: %w", err) } diff --git a/internal/kms/vault_sa.go b/internal/kms/vault_sa.go index e06b93e5e..6154877cb 100644 --- a/internal/kms/vault_sa.go +++ b/internal/kms/vault_sa.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "github.com/libopenstorage/secrets/vault" @@ -321,7 +320,7 @@ func (kms *vaultTenantSA) getToken() (string, error) { // linked from the ServiceAccount. This path can then be used in place of the // standard `/var/run/secrets/kubernetes.io/serviceaccount/token` location. func (kms *vaultTenantSA) getTokenPath() (string, error) { - dir, err := ioutil.TempDir("", kms.tenantSAName) + dir, err := os.MkdirTemp("", kms.tenantSAName) if err != nil { return "", fmt.Errorf("failed to create directory for ServiceAccount %s/%s: %w", kms.tenantSAName, kms.Tenant, err) } diff --git a/internal/rbd/rbd_util_test.go b/internal/rbd/rbd_util_test.go index e373a9e61..bd9dbcd53 100644 --- a/internal/rbd/rbd_util_test.go +++ b/internal/rbd/rbd_util_test.go @@ -19,7 +19,6 @@ package rbd import ( "context" "errors" - "io/ioutil" "os" "strings" "testing" @@ -252,7 +251,7 @@ func TestStrategicActionOnLogFile(t *testing.T) { var logFile [3]string for i := 0; i < 3; i++ { - f, err := ioutil.TempFile(tmpDir, "rbd-*.log") + f, err := os.CreateTemp(tmpDir, "rbd-*.log") if err != nil { t.Errorf("creating tempfile failed: %v", err) } diff --git a/internal/util/credentials.go b/internal/util/credentials.go index b189c6c9d..fae403c23 100644 --- a/internal/util/credentials.go +++ b/internal/util/credentials.go @@ -19,7 +19,6 @@ package util import ( "errors" "fmt" - "io/ioutil" "os" ) @@ -43,7 +42,7 @@ type Credentials struct { } func storeKey(key string) (string, error) { - tmpfile, err := ioutil.TempFile(tmpKeyFileLocation, tmpKeyFileNamePrefix) + tmpfile, err := os.CreateTemp(tmpKeyFileLocation, tmpKeyFileNamePrefix) if err != nil { return "", fmt.Errorf("error creating a temporary keyfile: %w", err) } diff --git a/internal/util/log/log_utils_test.go b/internal/util/log/log_utils_test.go index bd05fdfc1..c7a3d0166 100644 --- a/internal/util/log/log_utils_test.go +++ b/internal/util/log/log_utils_test.go @@ -19,7 +19,6 @@ package log import ( "errors" "fmt" - "io/ioutil" "os" "strings" "testing" @@ -28,7 +27,7 @@ import ( func TestGzipLogFile(t *testing.T) { t.Parallel() tmpDir := t.TempDir() - logFile, err := ioutil.TempFile(tmpDir, "rbd-*.log") + logFile, err := os.CreateTemp(tmpDir, "rbd-*.log") if err != nil { fmt.Println(err) }