diff --git a/pkg/config/cfgReader.go b/pkg/config/cfgReader.go index 1158727..474240e 100755 --- a/pkg/config/cfgReader.go +++ b/pkg/config/cfgReader.go @@ -19,7 +19,7 @@ package cfgreader import ( "bytes" "encoding/json" - "io/ioutil" + "io" "os" "unicode" @@ -40,7 +40,7 @@ func LoadConfig(cfg interface{}, path string) (err error) { defer file.Close() // read our opened json file as a byte array. - data, readErr := ioutil.ReadAll(file) + data, readErr := io.ReadAll(file) if readErr != nil { return readErr } diff --git a/pkg/file/fileUtil.go b/pkg/file/fileUtil.go index 84695d6..ae7ec0b 100755 --- a/pkg/file/fileUtil.go +++ b/pkg/file/fileUtil.go @@ -24,7 +24,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "log" "mime/multipart" "os" @@ -429,7 +428,7 @@ func GetCompressedFiles(files []scan.File, rootPath string) (newfiles []scan.Fil //check if file list contains compressed files, if so, scan their contents for _, file := range files { //Unpack and append to file list - tmppath, err := ioutil.TempDir("", "ebzip") + tmppath, err := os.MkdirTemp("", "ebzip") if err != nil { return newfiles, compresspaths, err } @@ -488,11 +487,11 @@ func Uncompress(src string, dest string) (filenames []string, err error) { if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil { return filenames, err } - body, err := ioutil.ReadAll(rc) + body, err := io.ReadAll(rc) if err != nil { return filenames, err } - err = ioutil.WriteFile(fpath, body, 0644) + err = os.WriteFile(fpath, body, 0644) if err != nil { return filenames, err } @@ -518,7 +517,7 @@ func GetConvertedFiles(files []scan.File) (convertedFiles []scan.File, converted } for _, file := range toBeConverted { - tmppath, err := ioutil.TempDir("", "ebconv") + tmppath, err := os.MkdirTemp("", "ebconv") fpath := filepath.Join(tmppath, file.Name) // Get content from the file as a string @@ -529,7 +528,7 @@ func GetConvertedFiles(files []scan.File) (convertedFiles []scan.File, converted } // Write content to new temp file - err = ioutil.WriteFile(fpath, []byte(content.Body), 0644) + err = os.WriteFile(fpath, []byte(content.Body), 0644) if err != nil { log.Printf("Error writing converted file %s, file not scanned\n", file.Path) continue diff --git a/pkg/git/cloner.go b/pkg/git/cloner.go index d8539a2..ea6a4f2 100755 --- a/pkg/git/cloner.go +++ b/pkg/git/cloner.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "gopkg.in/src-d/go-git.v4/plumbing" - "io/ioutil" "log" "os" "strings" @@ -79,7 +78,7 @@ func ReposPerProject(projectURL, username, password string) (scanRepos []string) //CloneGitRepos Clones a Git repo into a random temporary folder func CloneGitRepos(repoURLs []string, username, password string, branch string, json bool) (tmpDir string, err error) { - tmpDir, err = ioutil.TempDir("", "ebgit") + tmpDir, err = os.MkdirTemp("", "ebgit") if err != nil { return "", err } diff --git a/pkg/update/update.go b/pkg/update/update.go index e23d42a..e065fb3 100755 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -18,10 +18,11 @@ package configupdate import ( "fmt" - "io/ioutil" + "io" "log" "net/http" "net/url" + "os" "path" cfgreader "github.com/americanexpress/earlybird/v4/pkg/config" @@ -70,16 +71,16 @@ func downloadFile(path string, url string) error { defer resp.Body.Close() if resp.StatusCode != 200 { - b, _ := ioutil.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) return fmt.Errorf("received non 200 status code: status=%d, response=%v", resp.StatusCode, string(b)) } - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("reading response body: %v", err) } - err = ioutil.WriteFile(path, b, 0666) + err = os.WriteFile(path, b, 0666) if err != nil { return fmt.Errorf("writing file at %s: %v", path, err) } diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 0918380..a4f8914 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -17,7 +17,6 @@ package utils import ( - "io/ioutil" "os" "testing" ) @@ -128,7 +127,7 @@ func TestDeleteGit(t *testing.T) { } testRepo := "test-repo" - tmpDir, err := ioutil.TempDir("", "ebgit") + tmpDir, err := os.MkdirTemp("", "ebgit") if err != nil { t.Errorf("Failed to create temporoary directory: %v", err) } diff --git a/pkg/writers/jsonout.go b/pkg/writers/jsonout.go index a0ba80e..d1e89f8 100755 --- a/pkg/writers/jsonout.go +++ b/pkg/writers/jsonout.go @@ -22,7 +22,6 @@ import ( cfgReader "github.com/americanexpress/earlybird/v4/pkg/config" "github.com/americanexpress/earlybird/v4/pkg/file" "github.com/americanexpress/earlybird/v4/pkg/scan" - "io/ioutil" "os" "time" ) @@ -62,7 +61,7 @@ func reportToJSONWriter(v interface{}, fileName string) (s string, err error) { if fileName == "" { _, err = os.Stdout.Write(b) } else { - err = ioutil.WriteFile(fileName, b, 0666) + err = os.WriteFile(fileName, b, 0666) } return string(b), err