cleanup: use os.ReadFile to read file

as ioutil.ReadFile is deprecated and
suggestion is to use os.ReadFile as
per https://pkg.go.dev/io/ioutil updating
the same.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2022-01-21 15:02:34 +05:30
committed by mergify[bot]
parent 562dff0d19
commit aba6979d29
10 changed files with 17 additions and 23 deletions

View File

@ -20,7 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/ceph/ceph-csi/internal/util/k8s"
@ -94,7 +93,7 @@ func GetKMS(tenant, kmsID string, secrets map[string]string) (EncryptionKMS, err
func getKMSConfiguration() (map[string]interface{}, error) {
var config map[string]interface{}
// #nosec
content, err := ioutil.ReadFile(kmsConfigPath)
content, err := os.ReadFile(kmsConfigPath)
if err == nil {
// kmsConfigPath exists and was successfully read
err = json.Unmarshal(content, &config)

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
@ -244,7 +243,7 @@ func GetKrbdSupportedFeatures() (string, error) {
return "", err
}
}
val, err := ioutil.ReadFile(krbdSupportedFeaturesFile)
val, err := os.ReadFile(krbdSupportedFeaturesFile)
if err != nil {
log.ErrorLogMsg("reading file %q failed: %v", krbdSupportedFeaturesFile, err)
@ -1638,7 +1637,7 @@ func lookupRBDImageMetadataStash(metaDataPath string) (rbdImageMetadataStash, er
var imgMeta rbdImageMetadataStash
fPath := filepath.Join(metaDataPath, stashFileName)
encodedBytes, err := ioutil.ReadFile(fPath) // #nosec - intended reading from fPath
encodedBytes, err := os.ReadFile(fPath) // #nosec - intended reading from fPath
if err != nil {
if !os.IsNotExist(err) {
return imgMeta, fmt.Errorf("failed to read stashed JSON image metadata from path (%s): %w", fPath, err)

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/ceph/ceph-csi/internal/util/log"
@ -70,7 +69,7 @@ type ClusterMappingInfo struct {
func readClusterMappingInfo(filename string) (*[]ClusterMappingInfo, error) {
var info []ClusterMappingInfo
content, err := ioutil.ReadFile(filename) // #nosec:G304, file inclusion via variable.
content, err := os.ReadFile(filename) // #nosec:G304, file inclusion via variable.
if err != nil {
err = fmt.Errorf("error fetching clusterID mapping %w", err)

View File

@ -18,7 +18,7 @@ package util
import (
"fmt"
"io/ioutil"
"os"
"sync"
"time"
@ -96,7 +96,7 @@ func (cp *ConnPool) Destroy() {
func (cp *ConnPool) generateUniqueKey(monitors, user, keyfile string) (string, error) {
// the keyfile can be unique for operations, contents will be the same
key, err := ioutil.ReadFile(keyfile) // #nosec:G304, file inclusion via variable.
key, err := os.ReadFile(keyfile) // #nosec:G304, file inclusion via variable.
if err != nil {
return "", fmt.Errorf("could not open keyfile %s: %w", keyfile, err)
}

View File

@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
)
@ -72,7 +72,7 @@ func readClusterInfo(pathToConfig, clusterID string) (*ClusterInfo, error) {
var config []ClusterInfo
// #nosec
content, err := ioutil.ReadFile(pathToConfig)
content, err := os.ReadFile(pathToConfig)
if err != nil {
err = fmt.Errorf("error fetching configuration for cluster ID %q: %w", clusterID, err)

View File

@ -15,7 +15,6 @@ package log
import (
"compress/gzip"
"io/ioutil"
"os"
"strings"
)
@ -24,7 +23,7 @@ import (
// compressed format.
func GzipLogFile(pathToFile string) error {
// Get all the bytes from the file.
content, err := ioutil.ReadFile(pathToFile) // #nosec:G304, file inclusion via variable.
content, err := os.ReadFile(pathToFile) // #nosec:G304, file inclusion via variable.
if err != nil {
return err
}