From d72f9b128821970dd7f59860ae5a27e432d1ed16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Pich=C3=A9?= Date: Mon, 24 Oct 2022 07:01:12 -0400 Subject: [PATCH] remove ioutils --- cli/root.go | 7 ++++--- credentials/source_local.go | 3 +-- credentials/source_local_test.go | 5 ++--- credentials/source_s3.go | 4 ++-- credentials/source_s3_test.go | 4 ++-- credentials/sources_test.go | 5 ++--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cli/root.go b/cli/root.go index 52b2385..f80470b 100644 --- a/cli/root.go +++ b/cli/root.go @@ -2,8 +2,9 @@ package cli import ( "fmt" - "io/ioutil" + "io" "net/url" + "os" "strings" "github.com/aws/aws-sdk-go/aws" @@ -76,11 +77,11 @@ var rootCmd = &cobra.Command{ return fmt.Errorf("Failed to download the config file from S3, %v", err) } - if fileContent, err = ioutil.ReadAll(resp.Body); err != nil { + if fileContent, err = io.ReadAll(resp.Body); err != nil { return fmt.Errorf("Failed to read the config file from S3, %v", err) } } else { - if fileContent, err = ioutil.ReadFile(configurationFile); err != nil { + if fileContent, err = os.ReadFile(configurationFile); err != nil { return err } } diff --git a/credentials/source_local.go b/credentials/source_local.go index 6eff3d7..07b3fc4 100644 --- a/credentials/source_local.go +++ b/credentials/source_local.go @@ -2,7 +2,6 @@ package credentials import ( "fmt" - "io/ioutil" "os" ) @@ -34,7 +33,7 @@ func getCredentialsFromFile(fileName string) ([]Credentials, error) { err error fileContent []byte ) - if fileContent, err = ioutil.ReadFile(fileName); err != nil { + if fileContent, err = os.ReadFile(fileName); err != nil { return nil, err } return getCredentialsFromBytes(fileContent) diff --git a/credentials/source_local_test.go b/credentials/source_local_test.go index e6914b9..075b51a 100644 --- a/credentials/source_local_test.go +++ b/credentials/source_local_test.go @@ -1,7 +1,6 @@ package credentials import ( - "io/ioutil" "os" "path" "testing" @@ -10,7 +9,7 @@ import ( ) func TestGetCredentialsFromLocalSource(t *testing.T) { - tempDir, err := ioutil.TempDir("", "") + tempDir, err := os.MkdirTemp("", "") if err != nil { panic(err) } @@ -23,7 +22,7 @@ func TestGetCredentialsFromLocalSource(t *testing.T) { assert.Equal(t, "Local file", localSource.Type()) assert.Error(t, localSource.ValidateConfiguration()) - ioutil.WriteFile(filePath, []byte(`test_cred: + os.WriteFile(filePath, []byte(`test_cred: type: usernamepassword description: a credential username: user diff --git a/credentials/source_s3.go b/credentials/source_s3.go index b8a997e..cb7ec25 100644 --- a/credentials/source_s3.go +++ b/credentials/source_s3.go @@ -2,7 +2,7 @@ package credentials import ( "fmt" - "io/ioutil" + "io" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials/stscreds" @@ -41,7 +41,7 @@ func (source *AWSS3Source) Credentials() ([]Credentials, error) { if err != nil { return nil, err } - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { return nil, err } diff --git a/credentials/source_s3_test.go b/credentials/source_s3_test.go index 9ab17ee..cbbc064 100644 --- a/credentials/source_s3_test.go +++ b/credentials/source_s3_test.go @@ -2,7 +2,7 @@ package credentials import ( "fmt" - "io/ioutil" + "io" "strings" "testing" @@ -66,7 +66,7 @@ func (m *mockS3Client) GetObject(input *s3.GetObjectInput) (*s3.GetObjectOutput, assert.Equal(m.t, s3Bucket, *input.Bucket) assert.Equal(m.t, s3Key, *input.Key) - return &s3.GetObjectOutput{Body: ioutil.NopCloser(strings.NewReader(`test_cred: + return &s3.GetObjectOutput{Body: io.NopCloser(strings.NewReader(`test_cred: type: usernamepassword description: a credential username: user diff --git a/credentials/sources_test.go b/credentials/sources_test.go index 8b50ad4..f302315 100644 --- a/credentials/sources_test.go +++ b/credentials/sources_test.go @@ -1,7 +1,6 @@ package credentials import ( - "io/ioutil" "os" "path" "sort" @@ -13,13 +12,13 @@ import ( ) func TestSourcesConfigWithLocalSource(t *testing.T) { - tempDir, err := ioutil.TempDir("", "") + tempDir, err := os.MkdirTemp("", "") if err != nil { panic(err) } defer os.RemoveAll(tempDir) filePath := path.Join(tempDir, "local_file.json") - ioutil.WriteFile(filePath, []byte(`[{"id": "test", "type": "secret", "description": "test-desc", "secret": "my secret"}]`), 0777) + os.WriteFile(filePath, []byte(`[{"id": "test", "type": "secret", "description": "test-desc", "secret": "my secret"}]`), 0777) localSource := &LocalSource{ File: filePath, }