Skip to content

Commit

Permalink
Merge pull request #193 from coveooss/feature/DT-5227-ioutil-deprecated
Browse files Browse the repository at this point in the history
DT-5227 // remove ioutils
  • Loading branch information
jonapich committed Oct 24, 2022
2 parents 06b9c42 + d72f9b1 commit ebb17d4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
7 changes: 4 additions & 3 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package cli

import (
"fmt"
"io/ioutil"
"io"
"net/url"
"os"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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
}
}
Expand Down
3 changes: 1 addition & 2 deletions credentials/source_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package credentials

import (
"fmt"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions credentials/source_local_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package credentials

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -10,7 +9,7 @@ import (
)

func TestGetCredentialsFromLocalSource(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
panic(err)
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions credentials/source_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions credentials/source_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package credentials

import (
"fmt"
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions credentials/sources_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package credentials

import (
"io/ioutil"
"os"
"path"
"sort"
Expand All @@ -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,
}
Expand Down

0 comments on commit ebb17d4

Please sign in to comment.