diff --git a/cautils/apis/backendconnector.go b/cautils/apis/backendconnector.go index 0c466366..58a7a506 100644 --- a/cautils/apis/backendconnector.go +++ b/cautils/apis/backendconnector.go @@ -3,7 +3,7 @@ package apis import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" ) @@ -66,7 +66,7 @@ func BEHttpRequest(loginobj *LoginObject, beURL, return nil, fmt.Errorf("Error #%v Due to: %v", resp.StatusCode, resp.Status) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/cautils/apis/backendconnectormethods.go b/cautils/apis/backendconnectormethods.go index cfb3bc99..26c195c6 100644 --- a/cautils/apis/backendconnectormethods.go +++ b/cautils/apis/backendconnectormethods.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" ) @@ -57,7 +57,7 @@ func (r *BackendConnector) Login() error { return err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("unable to read login response") } @@ -120,7 +120,7 @@ func (r *BackendConnector) HTTPSend(httpverb string, return nil, fmt.Errorf("Error #%v Due to: %v", resp.StatusCode, resp.Status) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/cautils/apis/login.go b/cautils/apis/login.go index 9bc7e535..458f7068 100644 --- a/cautils/apis/login.go +++ b/cautils/apis/login.go @@ -2,11 +2,10 @@ package apis import ( "bytes" + "io" "net/http" "time" - "io/ioutil" - oidc "github.com/coreos/go-oidc" uuid "github.com/satori/go.uuid" @@ -231,7 +230,7 @@ func BELogin(loginDetails *CustomerLoginDetails, login string, cfg string) (*BEL return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/cautils/cautils/armometadata.go b/cautils/cautils/armometadata.go index b5e77ee1..13f91e4f 100644 --- a/cautils/cautils/armometadata.go +++ b/cautils/cautils/armometadata.go @@ -3,7 +3,6 @@ package cautils import ( "encoding/json" "fmt" - "io/ioutil" "os" "strings" @@ -154,7 +153,7 @@ func LoadConfig(configPath string, loadToEnv bool) (*ClusterConfig, error) { configPath = "/etc/config/clusterData.json" } - dat, err := ioutil.ReadFile(configPath) + dat, err := os.ReadFile(configPath) if err != nil || len(dat) == 0 { return nil, fmt.Errorf("Config empty or not found. path: %s", configPath) } diff --git a/cautils/customerloader.go b/cautils/customerloader.go index 7e4bae6c..a810d1db 100644 --- a/cautils/customerloader.go +++ b/cautils/customerloader.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net/url" "os" "strings" @@ -73,12 +72,12 @@ func NewClusterConfig(k8s *k8sinterface.KubernetesApi, armoAPI *getter.ArmoAPI) } } func createConfigJson() { - ioutil.WriteFile(getter.GetDefaultPath(ConfigFileName+".json"), nil, 0664) + os.WriteFile(getter.GetDefaultPath(ConfigFileName+".json"), nil, 0664) } func update(configObj *ConfigObj) { - ioutil.WriteFile(getter.GetDefaultPath(ConfigFileName+".json"), configObj.Json(), 0664) + os.WriteFile(getter.GetDefaultPath(ConfigFileName+".json"), configObj.Json(), 0664) } func (c *ClusterConfig) GenerateURL() { u := url.URL{} @@ -126,7 +125,7 @@ func (c *ClusterConfig) GetValueByKeyFromConfigMap(key string) (string, error) { } func GetValueFromConfigJson(key string) (string, error) { - data, err := ioutil.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) + data, err := os.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) if err != nil { return "", err } @@ -141,7 +140,7 @@ func GetValueFromConfigJson(key string) (string, error) { } func SetKeyValueInConfigJson(key string, value string) error { - data, err := ioutil.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) + data, err := os.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) if err != nil { return err } @@ -157,7 +156,7 @@ func SetKeyValueInConfigJson(key string, value string) error { return err } - return ioutil.WriteFile(getter.GetDefaultPath(ConfigFileName+".json"), newData, 0664) + return os.WriteFile(getter.GetDefaultPath(ConfigFileName+".json"), newData, 0664) } @@ -251,7 +250,7 @@ func (c *ClusterConfig) existsConfigMap() bool { } func existsConfigJson() bool { - _, err := ioutil.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) + _, err := os.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) return err == nil @@ -300,7 +299,7 @@ func (c *ClusterConfig) updateConfigData(configMap *corev1.ConfigMap) { } } func loadConfigFromFile() (*ConfigObj, error) { - dat, err := ioutil.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) + dat, err := os.ReadFile(getter.GetDefaultPath(ConfigFileName + ".json")) if err != nil { return nil, err } diff --git a/cautils/getter/downloadreleasedpolicy.go b/cautils/getter/downloadreleasedpolicy.go index 6853e77a..1740888a 100644 --- a/cautils/getter/downloadreleasedpolicy.go +++ b/cautils/getter/downloadreleasedpolicy.go @@ -3,7 +3,7 @@ package getter import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/armosec/kubescape/cautils/opapolicy" @@ -56,7 +56,7 @@ func (drp *DownloadReleasedPolicy) setURL(frameworkName string) error { return fmt.Errorf("failed to download file, status code: %s", resp.Status) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("failed to read response body from '%s', reason: %s", latestReleases, err.Error()) } diff --git a/cautils/getter/loadpolicy.go b/cautils/getter/loadpolicy.go index 9fb72027..127073cd 100644 --- a/cautils/getter/loadpolicy.go +++ b/cautils/getter/loadpolicy.go @@ -3,7 +3,7 @@ package getter import ( "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "github.com/armosec/kubescape/cautils/armotypes" @@ -29,7 +29,7 @@ func NewLoadPolicy(filePath string) *LoadPolicy { func (lp *LoadPolicy) GetFramework(frameworkName string) (*opapolicy.Framework, error) { framework := &opapolicy.Framework{} - f, err := ioutil.ReadFile(lp.filePath) + f, err := os.ReadFile(lp.filePath) if err != nil { return nil, err } @@ -44,7 +44,7 @@ func (lp *LoadPolicy) GetFramework(frameworkName string) (*opapolicy.Framework, func (lp *LoadPolicy) GetExceptions(customerGUID, clusterName string) ([]armotypes.PostureExceptionPolicy, error) { exception := []armotypes.PostureExceptionPolicy{} - f, err := ioutil.ReadFile(lp.filePath) + f, err := os.ReadFile(lp.filePath) if err != nil { return nil, err } diff --git a/cautils/k8sinterface/cloudvendorregistrycreds.go b/cautils/k8sinterface/cloudvendorregistrycreds.go index 690680b7..06996ade 100644 --- a/cautils/k8sinterface/cloudvendorregistrycreds.go +++ b/cautils/k8sinterface/cloudvendorregistrycreds.go @@ -5,7 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -105,7 +105,7 @@ func getAzureAADAccessToken() (string, error) { } // Pull out response body - responseBytes, err := ioutil.ReadAll(resp.Body) + responseBytes, err := io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { return "", fmt.Errorf("reading response body : %v", err) @@ -173,7 +173,7 @@ func excahngeAzureAADAccessTokenForACRRefreshToken(registry, tenantID, azureAADA } // Pull out response body - responseBytes, err := ioutil.ReadAll(resp.Body) + responseBytes, err := io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { return "", fmt.Errorf("reading response body : %v", err) diff --git a/cautils/k8sinterface/k8sdynamic_test.go b/cautils/k8sinterface/k8sdynamic_test.go index 6be23ad5..38276444 100644 --- a/cautils/k8sinterface/k8sdynamic_test.go +++ b/cautils/k8sinterface/k8sdynamic_test.go @@ -37,7 +37,7 @@ func NewKubernetesApiMock() *KubernetesApi { // } else { // bla, _ := json.Marshal(clientResource) // // t.Errorf("BearerToken: %v", *K8SConfig) -// // ioutil.WriteFile("bla.json", bla, 777) +// // os.WriteFile("bla.json", bla, 777) // t.Errorf("clientResource: %s", string(bla)) // } // } diff --git a/cautils/opapolicy/resources/resourcesutils.go b/cautils/opapolicy/resources/resourcesutils.go index 3b43ec9f..befd25b7 100644 --- a/cautils/opapolicy/resources/resourcesutils.go +++ b/cautils/opapolicy/resources/resourcesutils.go @@ -3,7 +3,6 @@ package resources import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -94,7 +93,7 @@ func LoadRegoFiles(dir string) map[string]string { // Compile the module. The keys are used as identifiers in error messages. filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err == nil && strings.HasSuffix(path, ".rego") && !info.IsDir() { - content, err := ioutil.ReadFile(path) + content, err := os.ReadFile(path) if err != nil { glog.Errorf("LoadRegoFiles, Failed to load: %s: %v", path, err) } else { diff --git a/cmd/framework.go b/cmd/framework.go index e247e183..34d24549 100644 --- a/cmd/framework.go +++ b/cmd/framework.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "strings" @@ -56,7 +55,7 @@ var frameworkCmd = &cobra.Command{ if len(args[1:]) == 0 || args[1] != "-" { scanInfo.InputPatterns = args[1:] } else { // store stout to file - tempFile, err := ioutil.TempFile(".", "tmp-kubescape*.yaml") + tempFile, err := os.CreateTemp(".", "tmp-kubescape*.yaml") if err != nil { return err } diff --git a/cmd/version.go b/cmd/version.go index e78a338f..ebcc7d68 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -3,7 +3,7 @@ package cmd import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/spf13/cobra" @@ -32,7 +32,7 @@ func GetLatestVersion() (string, error) { return "", fmt.Errorf("failed to download file, status code: %s", resp.Status) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("failed to read response body from '%s', reason: %s", latestVersion, err.Error()) } diff --git a/policyhandler/filesloader.go b/policyhandler/filesloader.go index e3272f65..c95d6400 100644 --- a/policyhandler/filesloader.go +++ b/policyhandler/filesloader.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -131,7 +130,7 @@ func loadFiles(filePaths []string) ([]k8sinterface.IWorkload, []error) { } func loadFile(filePath string) ([]byte, error) { - return ioutil.ReadFile(filePath) + return os.ReadFile(filePath) } func readFile(fileContent []byte, fileFromat FileFormat) ([]k8sinterface.IWorkload, []error) { diff --git a/scapepkg/score/score.go b/scapepkg/score/score.go index 6bdf687a..36e0f7f6 100644 --- a/scapepkg/score/score.go +++ b/scapepkg/score/score.go @@ -3,7 +3,7 @@ package score import ( "encoding/json" "fmt" - "io/ioutil" + "os" "strings" appsv1 "k8s.io/api/apps/v1" @@ -157,7 +157,7 @@ func getPostureFrameworksScores(weightPath string) map[string]map[string]Control weightPath = weightPath + "/" } frameworksScoreMap := make(map[string]map[string]ControlScoreWeights) - dat, err := ioutil.ReadFile(weightPath + "frameworkdict.json") + dat, err := os.ReadFile(weightPath + "frameworkdict.json") if err != nil { return nil } @@ -174,7 +174,7 @@ func getPostureResourceScores(weightPath string) map[string]float32 { weightPath = weightPath + "/" } resourceScoreMap := make(map[string]float32) - dat, err := ioutil.ReadFile(weightPath + "resourcesdict.json") + dat, err := os.ReadFile(weightPath + "resourcesdict.json") if err != nil { return nil } diff --git a/scapepkg/score/score_mocks.go b/scapepkg/score/score_mocks.go index fdf2ea32..17c6fc6e 100644 --- a/scapepkg/score/score_mocks.go +++ b/scapepkg/score/score_mocks.go @@ -2,7 +2,7 @@ package score import ( "encoding/json" - "io/ioutil" + "os" "strings" k8sinterface "github.com/armosec/kubescape/cautils/k8sinterface" @@ -12,7 +12,7 @@ import ( func loadResourcesMock() []map[string]interface{} { resources := make([]map[string]interface{}, 0) - dat, err := ioutil.ReadFile("resourcemocks.json") + dat, err := os.ReadFile("resourcemocks.json") if err != nil { return resources @@ -51,7 +51,7 @@ func getResouceByType(desiredType string) map[string]interface{} { func loadFrameworkMock() *opapolicy.FrameworkReport { report := &opapolicy.FrameworkReport{} - dat, err := ioutil.ReadFile("frameworkmock.json") + dat, err := os.ReadFile("frameworkmock.json") if err != nil { return report