Skip to content

Commit

Permalink
cleanup: fix static checks
Browse files Browse the repository at this point in the history
fix SA1019 static check to replace
io/utils with os package and sets
with generic sets

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
  • Loading branch information
Madhu-1 committed Feb 2, 2023
1 parent bc0e19c commit 1f57621
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
6 changes: 2 additions & 4 deletions internal/kms/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package kms
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -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{})

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/kms/vault_sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/libopenstorage/secrets/vault"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/rbd/rbd_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package rbd
import (
"context"
"errors"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/util/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package util
import (
"errors"
"fmt"
"io/ioutil"
"os"
)

Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/util/idlocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const (
// VolumeLocks implements a map with atomic operations. It stores a set of all volume IDs
// with an ongoing operation.
type VolumeLocks struct {
locks sets.String
locks sets.Set[string]
mux sync.Mutex
}

// NewVolumeLocks returns new VolumeLocks.
func NewVolumeLocks() *VolumeLocks {
return &VolumeLocks{
locks: sets.NewString(),
locks: sets.New[string](),
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/util/log/log_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package log
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -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)
}
Expand Down

0 comments on commit 1f57621

Please sign in to comment.