Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced io/ioutil with "os / io" package. #17792

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ updates:
- "OrlinVasilev"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
labels:
- "release-note/update"

- package-ecosystem: "gomod"
directory: "tests/"
directory: "/src"
schedule:
interval: "weekly"
labels:
Expand Down
5 changes: 2 additions & 3 deletions src/chartserver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chartserver
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (cc *ChartClient) GetContent(addr string) ([]byte, error) {
return nil, err
}

content, err := ioutil.ReadAll(response.Body)
content, err := io.ReadAll(response.Body)
if err != nil {
err = errors.Wrap(err, "Read response body error")
return nil, err
Expand Down Expand Up @@ -97,7 +96,7 @@ func (cc *ChartClient) DeleteContent(addr string) error {
return err
}

content, err := ioutil.ReadAll(response.Body)
content, err := io.ReadAll(response.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions src/chartserver/handler_proxy_traffic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chartserver
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestResponseRewrite(t *testing.T) {
t.Fatalf("Expect status code 500 but got %d", response.StatusCode)
}

bytes, err := ioutil.ReadAll(response.Body)
bytes, err := io.ReadAll(response.Body)
if err != nil {
t.Fatalf("Read bytes from http response failed with error: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions src/chartserver/reverse_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -171,7 +171,7 @@ func modifyResponse(res *http.Response) error {
res.StatusCode = http.StatusInternalServerError
} else {
// Extract the error and wrap it into the error object
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
errorObj["error"] = fmt.Sprintf("%s: %s", res.Status, err.Error())
} else {
Expand All @@ -187,7 +187,7 @@ func modifyResponse(res *http.Response) error {
}

size := len(content)
body := ioutil.NopCloser(bytes.NewReader(content))
body := io.NopCloser(bytes.NewReader(content))
res.Body = body
res.ContentLength = int64(size)
res.Header.Set(contentLengthHeader, strconv.Itoa(size))
Expand Down
5 changes: 2 additions & 3 deletions src/common/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
Expand Down Expand Up @@ -160,7 +159,7 @@ func (c *Client) do(req *http.Request) ([]byte, error) {
}
defer resp.Body.Close()

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -202,7 +201,7 @@ func (c *Client) GetAndIteratePagination(endpoint string, v interface{}) error {
if err != nil {
return err
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions src/common/job/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -119,7 +119,7 @@ func (d *DefaultClient) SubmitJob(jd *models.JobData) (string, error) {
return "", err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (d *DefaultClient) GetJobLog(uuid string) ([]byte, error) {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand All @@ -173,7 +173,7 @@ func (d *DefaultClient) GetExecutions(periodicJobID string) ([]job.Stats, error)
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func (d *DefaultClient) GetJobServiceConfig() (*job.Config, error) {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions src/common/job/test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package test
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
"path"
"runtime"
"strings"
Expand Down Expand Up @@ -41,7 +42,7 @@ func NewJobServiceServer() *httptest.Server {
rw.Header().Add("Content-Type", "text/plain")
rw.WriteHeader(http.StatusOK)
f := path.Join(currPath(), "test.log")
b, _ := ioutil.ReadFile(f)
b, _ := os.ReadFile(f)
_, err := rw.Write(b)
if err != nil {
panic(err)
Expand Down Expand Up @@ -75,7 +76,7 @@ func NewJobServiceServer() *httptest.Server {
rw.WriteHeader(http.StatusMethodNotAllowed)
return
}
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
panic(err)
}
Expand All @@ -92,7 +93,7 @@ func NewJobServiceServer() *httptest.Server {
mux.HandleFunc(jobsPrefix,
func(rw http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodPost {
data, err := ioutil.ReadAll(req.Body)
data, err := io.ReadAll(req.Body)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/test/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"crypto/aes"
"crypto/rand"
"fmt"
"io/ioutil"
"os"
)

// GenerateKey generates aes key
Expand All @@ -32,7 +32,7 @@ func GenerateKey(path string) (string, error) {
return "", fmt.Errorf("the length of random bytes %d != %d", n, aes.BlockSize)
}

if err = ioutil.WriteFile(path, data, 0777); err != nil {
if err = os.WriteFile(path, data, 0777); err != nil {
return "", fmt.Errorf("failed write secret key to file %s: %v", path, err)
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/utils/uaa/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -124,7 +124,7 @@ func (dc *defaultClient) GetUserInfo(token string) (*UserInfo, error) {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (dc *defaultClient) SearchUser(username string) ([]*SearchUserEntry, error)
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func (dc *defaultClient) UpdateConfig(cfg *ClientConfig) error {
}
if !cfg.SkipTLSVerify && len(cfg.CARootPath) > 0 {
if _, err := os.Stat(cfg.CARootPath); !os.IsNotExist(err) {
content, err := ioutil.ReadFile(cfg.CARootPath)
content, err := os.ReadFile(cfg.CARootPath)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions src/common/utils/uaa/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uaa

import (
"fmt"
"io/ioutil"
"net/http/httptest"
"os"
"path"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestUserInfo(t *testing.T) {
assert := assert.New(t)
client, err := NewDefaultClient(getCfg())
assert.Nil(err)
token, err := ioutil.ReadFile(path.Join(currPath(), "test", "./good-access-token.txt"))
token, err := os.ReadFile(path.Join(currPath(), "test", "./good-access-token.txt"))
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils/uaa/test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package test
import (
"fmt"
"html"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path"
"runtime"
"strings"
Expand Down Expand Up @@ -76,7 +76,7 @@ func serveToken(rw http.ResponseWriter) {
}

func serveJSONFile(rw http.ResponseWriter, filename string) {
data, err := ioutil.ReadFile(path.Join(currPath(), filename))
data, err := os.ReadFile(path.Join(currPath(), filename))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func NewMockServer(cfg *MockServerConfig) *httptest.Server {
cfg.Username,
cfg.Password,
})
token, err := ioutil.ReadFile(path.Join(currPath(), "./good-access-token.txt"))
token, err := os.ReadFile(path.Join(currPath(), "./good-access-token.txt"))
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions src/controller/artifact/annotation/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"

Expand Down Expand Up @@ -80,7 +79,7 @@ func parseV1alpha1Icon(artifact *artifact.Artifact, manifest *v1.Manifest, reg r
return err
}
// check the size of the size <= 1MB
data, err := ioutil.ReadAll(io.LimitReader(icon, 1<<20))
data, err := io.ReadAll(io.LimitReader(icon, 1<<20))
if err != nil {
if err == io.EOF {
return errors.New(nil).WithCode(errors.BadRequestCode).WithMessage("the maximum size of the icon is 1MB")
Expand Down
12 changes: 6 additions & 6 deletions src/controller/artifact/annotation/v1alpha1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package annotation
import (
"encoding/base64"
"encoding/json"
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -191,12 +191,12 @@ func (p *v1alpha1TestSuite) TestParse() {
p.Require().Nil(err)

metadata := map[string]interface{}{}
configBlob := ioutil.NopCloser(strings.NewReader(ormbConfig))
configBlob := io.NopCloser(strings.NewReader(ormbConfig))
err = json.NewDecoder(configBlob).Decode(&metadata)
p.Require().Nil(err)
art := &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata}

blob := ioutil.NopCloser(base64.NewDecoder(base64.StdEncoding, strings.NewReader(ormbIcon)))
blob := io.NopCloser(base64.NewDecoder(base64.StdEncoding, strings.NewReader(ormbIcon)))
p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), blob, nil)
err = p.v1alpha1Parser.Parse(nil, art, content)
p.Require().Nil(err)
Expand All @@ -214,12 +214,12 @@ func (p *v1alpha1TestSuite) TestParse() {
p.Require().Nil(err)

metadata = map[string]interface{}{}
configBlob = ioutil.NopCloser(strings.NewReader(ormbConfig))
configBlob = io.NopCloser(strings.NewReader(ormbConfig))
err = json.NewDecoder(configBlob).Decode(&metadata)
p.Require().Nil(err)
art = &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata}

blob = ioutil.NopCloser(base64.NewDecoder(base64.StdEncoding, strings.NewReader(ormbIcon)))
blob = io.NopCloser(base64.NewDecoder(base64.StdEncoding, strings.NewReader(ormbIcon)))
p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), blob, nil)
err = p.v1alpha1Parser.Parse(nil, art, content)
p.Require().Nil(err)
Expand All @@ -237,7 +237,7 @@ func (p *v1alpha1TestSuite) TestParse() {
p.Require().Nil(err)

metadata = map[string]interface{}{}
configBlob = ioutil.NopCloser(strings.NewReader(ormbConfig))
configBlob = io.NopCloser(strings.NewReader(ormbConfig))
err = json.NewDecoder(configBlob).Decode(&metadata)
p.Require().Nil(err)
art = &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata}
Expand Down
8 changes: 4 additions & 4 deletions src/controller/artifact/processor/base/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package base

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

Expand Down Expand Up @@ -140,7 +140,7 @@ func (m *manifestTestSuite) TestAbstractMetadata() {
// abstract all properties
art := &artifact.Artifact{}

m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(strings.NewReader(config)), nil)
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(config)), nil)
m.processor.AbstractMetadata(nil, art, []byte(manifest))
m.Len(art.ExtraAttrs, 9)

Expand All @@ -150,14 +150,14 @@ func (m *manifestTestSuite) TestAbstractMetadata() {
// abstract the specified properties
m.processor.properties = []string{"os"}
art = &artifact.Artifact{}
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(strings.NewReader(config)), nil)
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(config)), nil)
m.processor.AbstractMetadata(nil, art, []byte(manifest))
m.Require().Len(art.ExtraAttrs, 1)
m.Equal("linux", art.ExtraAttrs["os"])
}

func (m *manifestTestSuite) TestUnmarshalConfig() {
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(strings.NewReader(config)), nil)
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(config)), nil)
config := &v1.Image{}
err := m.processor.UnmarshalConfig(nil, "library/hello-world", []byte(manifest), config)
m.Require().Nil(err)
Expand Down
Loading