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

Signed-off-by: yanggang <gang.yang@daocloud.io>

update typo

Signed-off-by: yminer <yminer@vmware.com>

Signed-off-by: yminer <yminer@vmware.com>
Co-authored-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
yanggang 2022-11-17 10:02:29 +08:00 committed by GitHub
parent ac338a2531
commit 0f4e2daf4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
87 changed files with 216 additions and 246 deletions

View File

@ -3,7 +3,6 @@ package chartserver
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -69,7 +68,7 @@ func (cc *ChartClient) GetContent(addr string) ([]byte, error) {
return nil, err return nil, err
} }
content, err := ioutil.ReadAll(response.Body) content, err := io.ReadAll(response.Body)
if err != nil { if err != nil {
err = errors.Wrap(err, "Read response body error") err = errors.Wrap(err, "Read response body error")
return nil, err return nil, err
@ -97,7 +96,7 @@ func (cc *ChartClient) DeleteContent(addr string) error {
return err return err
} }
content, err := ioutil.ReadAll(response.Body) content, err := io.ReadAll(response.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,7 +3,7 @@ package chartserver
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -92,7 +92,7 @@ func TestResponseRewrite(t *testing.T) {
t.Fatalf("Expect status code 500 but got %d", response.StatusCode) 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 { if err != nil {
t.Fatalf("Read bytes from http response failed with error: %s", err) t.Fatalf("Read bytes from http response failed with error: %s", err)
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
@ -171,7 +171,7 @@ func modifyResponse(res *http.Response) error {
res.StatusCode = http.StatusInternalServerError res.StatusCode = http.StatusInternalServerError
} else { } else {
// Extract the error and wrap it into the error object // 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 { if err != nil {
errorObj["error"] = fmt.Sprintf("%s: %s", res.Status, err.Error()) errorObj["error"] = fmt.Sprintf("%s: %s", res.Status, err.Error())
} else { } else {
@ -187,7 +187,7 @@ func modifyResponse(res *http.Response) error {
} }
size := len(content) size := len(content)
body := ioutil.NopCloser(bytes.NewReader(content)) body := io.NopCloser(bytes.NewReader(content))
res.Body = body res.Body = body
res.ContentLength = int64(size) res.ContentLength = int64(size)
res.Header.Set(contentLengthHeader, strconv.Itoa(size)) res.Header.Set(contentLengthHeader, strconv.Itoa(size))

View File

@ -19,7 +19,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"reflect" "reflect"
@ -160,7 +159,7 @@ func (c *Client) do(req *http.Request) ([]byte, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -202,7 +201,7 @@ func (c *Client) GetAndIteratePagination(endpoint string, v interface{}) error {
if err != nil { if err != nil {
return err return err
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
resp.Body.Close() resp.Body.Close()
if err != nil { if err != nil {
return err return err

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -119,7 +119,7 @@ func (d *DefaultClient) SubmitJob(jd *models.JobData) (string, error) {
return "", err return "", err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -148,7 +148,7 @@ func (d *DefaultClient) GetJobLog(uuid string) ([]byte, error) {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -173,7 +173,7 @@ func (d *DefaultClient) GetExecutions(periodicJobID string) ([]job.Stats, error)
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -226,7 +226,7 @@ func (d *DefaultClient) GetJobServiceConfig() (*job.Config, error) {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,9 +3,10 @@ package test
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"path" "path"
"runtime" "runtime"
"strings" "strings"
@ -41,7 +42,7 @@ func NewJobServiceServer() *httptest.Server {
rw.Header().Add("Content-Type", "text/plain") rw.Header().Add("Content-Type", "text/plain")
rw.WriteHeader(http.StatusOK) rw.WriteHeader(http.StatusOK)
f := path.Join(currPath(), "test.log") f := path.Join(currPath(), "test.log")
b, _ := ioutil.ReadFile(f) b, _ := os.ReadFile(f)
_, err := rw.Write(b) _, err := rw.Write(b)
if err != nil { if err != nil {
panic(err) panic(err)
@ -75,7 +76,7 @@ func NewJobServiceServer() *httptest.Server {
rw.WriteHeader(http.StatusMethodNotAllowed) rw.WriteHeader(http.StatusMethodNotAllowed)
return return
} }
data, err := ioutil.ReadAll(req.Body) data, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -92,7 +93,7 @@ func NewJobServiceServer() *httptest.Server {
mux.HandleFunc(jobsPrefix, mux.HandleFunc(jobsPrefix,
func(rw http.ResponseWriter, req *http.Request) { func(rw http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodPost { if req.Method == http.MethodPost {
data, err := ioutil.ReadAll(req.Body) data, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -18,7 +18,7 @@ import (
"crypto/aes" "crypto/aes"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io/ioutil" "os"
) )
// GenerateKey generates aes key // GenerateKey generates aes key
@ -32,7 +32,7 @@ func GenerateKey(path string) (string, error) {
return "", fmt.Errorf("the length of random bytes %d != %d", n, aes.BlockSize) 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) return "", fmt.Errorf("failed write secret key to file %s: %v", path, err)
} }

View File

@ -20,7 +20,7 @@ import (
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -124,7 +124,7 @@ func (dc *defaultClient) GetUserInfo(token string) (*UserInfo, error) {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -155,7 +155,7 @@ func (dc *defaultClient) SearchUser(username string) ([]*SearchUserEntry, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
bytes, err := ioutil.ReadAll(resp.Body) bytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -186,7 +186,7 @@ func (dc *defaultClient) UpdateConfig(cfg *ClientConfig) error {
} }
if !cfg.SkipTLSVerify && len(cfg.CARootPath) > 0 { if !cfg.SkipTLSVerify && len(cfg.CARootPath) > 0 {
if _, err := os.Stat(cfg.CARootPath); !os.IsNotExist(err) { if _, err := os.Stat(cfg.CARootPath); !os.IsNotExist(err) {
content, err := ioutil.ReadFile(cfg.CARootPath) content, err := os.ReadFile(cfg.CARootPath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -2,7 +2,6 @@ package uaa
import ( import (
"fmt" "fmt"
"io/ioutil"
"net/http/httptest" "net/http/httptest"
"os" "os"
"path" "path"
@ -55,7 +54,7 @@ func TestUserInfo(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
client, err := NewDefaultClient(getCfg()) client, err := NewDefaultClient(getCfg())
assert.Nil(err) 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 { if err != nil {
panic(err) panic(err)
} }

View File

@ -17,9 +17,9 @@ package test
import ( import (
"fmt" "fmt"
"html" "html"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"path" "path"
"runtime" "runtime"
"strings" "strings"
@ -76,7 +76,7 @@ func serveToken(rw http.ResponseWriter) {
} }
func serveJSONFile(rw http.ResponseWriter, filename string) { 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 { if err != nil {
panic(err) panic(err)
} }
@ -143,7 +143,7 @@ func NewMockServer(cfg *MockServerConfig) *httptest.Server {
cfg.Username, cfg.Username,
cfg.Password, 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 { if err != nil {
panic(err) panic(err)
} }

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -80,7 +79,7 @@ func parseV1alpha1Icon(artifact *artifact.Artifact, manifest *v1.Manifest, reg r
return err return err
} }
// check the size of the size <= 1MB // 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 != nil {
if err == io.EOF { if err == io.EOF {
return errors.New(nil).WithCode(errors.BadRequestCode).WithMessage("the maximum size of the icon is 1MB") return errors.New(nil).WithCode(errors.BadRequestCode).WithMessage("the maximum size of the icon is 1MB")

View File

@ -17,7 +17,7 @@ package annotation
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -191,12 +191,12 @@ func (p *v1alpha1TestSuite) TestParse() {
p.Require().Nil(err) p.Require().Nil(err)
metadata := map[string]interface{}{} metadata := map[string]interface{}{}
configBlob := ioutil.NopCloser(strings.NewReader(ormbConfig)) configBlob := io.NopCloser(strings.NewReader(ormbConfig))
err = json.NewDecoder(configBlob).Decode(&metadata) err = json.NewDecoder(configBlob).Decode(&metadata)
p.Require().Nil(err) p.Require().Nil(err)
art := &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata} 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) p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), blob, nil)
err = p.v1alpha1Parser.Parse(nil, art, content) err = p.v1alpha1Parser.Parse(nil, art, content)
p.Require().Nil(err) p.Require().Nil(err)
@ -214,12 +214,12 @@ func (p *v1alpha1TestSuite) TestParse() {
p.Require().Nil(err) p.Require().Nil(err)
metadata = map[string]interface{}{} metadata = map[string]interface{}{}
configBlob = ioutil.NopCloser(strings.NewReader(ormbConfig)) configBlob = io.NopCloser(strings.NewReader(ormbConfig))
err = json.NewDecoder(configBlob).Decode(&metadata) err = json.NewDecoder(configBlob).Decode(&metadata)
p.Require().Nil(err) p.Require().Nil(err)
art = &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata} 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) p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), blob, nil)
err = p.v1alpha1Parser.Parse(nil, art, content) err = p.v1alpha1Parser.Parse(nil, art, content)
p.Require().Nil(err) p.Require().Nil(err)
@ -237,7 +237,7 @@ func (p *v1alpha1TestSuite) TestParse() {
p.Require().Nil(err) p.Require().Nil(err)
metadata = map[string]interface{}{} metadata = map[string]interface{}{}
configBlob = ioutil.NopCloser(strings.NewReader(ormbConfig)) configBlob = io.NopCloser(strings.NewReader(ormbConfig))
err = json.NewDecoder(configBlob).Decode(&metadata) err = json.NewDecoder(configBlob).Decode(&metadata)
p.Require().Nil(err) p.Require().Nil(err)
art = &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata} art = &artifact.Artifact{ManifestMediaType: manifestMediaType, ExtraAttrs: metadata}

View File

@ -15,7 +15,7 @@
package base package base
import ( import (
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -140,7 +140,7 @@ func (m *manifestTestSuite) TestAbstractMetadata() {
// abstract all properties // abstract all properties
art := &artifact.Artifact{} 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.processor.AbstractMetadata(nil, art, []byte(manifest))
m.Len(art.ExtraAttrs, 9) m.Len(art.ExtraAttrs, 9)
@ -150,14 +150,14 @@ func (m *manifestTestSuite) TestAbstractMetadata() {
// abstract the specified properties // abstract the specified properties
m.processor.properties = []string{"os"} m.processor.properties = []string{"os"}
art = &artifact.Artifact{} 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.processor.AbstractMetadata(nil, art, []byte(manifest))
m.Require().Len(art.ExtraAttrs, 1) m.Require().Len(art.ExtraAttrs, 1)
m.Equal("linux", art.ExtraAttrs["os"]) m.Equal("linux", art.ExtraAttrs["os"])
} }
func (m *manifestTestSuite) TestUnmarshalConfig() { 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{} config := &v1.Image{}
err := m.processor.UnmarshalConfig(nil, "library/hello-world", []byte(manifest), config) err := m.processor.UnmarshalConfig(nil, "library/hello-world", []byte(manifest), config)
m.Require().Nil(err) m.Require().Nil(err)

View File

@ -17,7 +17,7 @@ package chart
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil" "io"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
@ -85,7 +85,7 @@ func (p *processor) AbstractAddition(ctx context.Context, artifact *artifact.Art
if err != nil { if err != nil {
return nil, err return nil, err
} }
content, err := ioutil.ReadAll(blob) content, err := io.ReadAll(blob)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -15,7 +15,7 @@
package chart package chart
import ( import (
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -105,7 +105,7 @@ func (p *processorTestSuite) TestAbstractAddition() {
manifest, _, err := distribution.UnmarshalManifest(v1.MediaTypeImageManifest, []byte(chartManifest)) manifest, _, err := distribution.UnmarshalManifest(v1.MediaTypeImageManifest, []byte(chartManifest))
p.Require().Nil(err) p.Require().Nil(err)
p.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(manifest, "", nil) p.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(manifest, "", nil)
p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(strings.NewReader(chartYaml)), nil) p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(chartYaml)), nil)
p.chartOptr.On("GetDetails").Return(chartDetails, nil) p.chartOptr.On("GetDetails").Return(chartDetails, nil)
// values.yaml // values.yaml

View File

@ -15,7 +15,7 @@
package cnab package cnab
import ( import (
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -95,7 +95,7 @@ func (p *processorTestSuite) TestAbstractMetadata() {
mani, _, err := distribution.UnmarshalManifest(v1.MediaTypeImageManifest, []byte(manifest)) mani, _, err := distribution.UnmarshalManifest(v1.MediaTypeImageManifest, []byte(manifest))
p.Require().Nil(err) p.Require().Nil(err)
p.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(mani, "", nil) p.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(mani, "", nil)
p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(strings.NewReader(config)), nil) p.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(config)), nil)
err = p.processor.AbstractMetadata(nil, art, nil) err = p.processor.AbstractMetadata(nil, art, nil)
p.Require().Nil(err) p.Require().Nil(err)
p.Len(art.ExtraAttrs, 7) p.Len(art.ExtraAttrs, 7)

View File

@ -16,7 +16,7 @@ package processor
import ( import (
"context" "context"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -177,7 +177,7 @@ func (d *defaultProcessorTestSuite) TestAbstractMetadata() {
manifestMediaType, content, err := manifest.Payload() manifestMediaType, content, err := manifest.Payload()
d.Require().Nil(err) d.Require().Nil(err)
configBlob := ioutil.NopCloser(strings.NewReader(ormbConfig)) configBlob := io.NopCloser(strings.NewReader(ormbConfig))
art := &artifact.Artifact{ManifestMediaType: manifestMediaType} art := &artifact.Artifact{ManifestMediaType: manifestMediaType}
d.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), configBlob, nil) d.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), configBlob, nil)
d.parser.On("Parse", context.TODO(), mock.AnythingOfType("*artifact.Artifact"), mock.AnythingOfType("[]byte")).Return(nil) d.parser.On("Parse", context.TODO(), mock.AnythingOfType("*artifact.Artifact"), mock.AnythingOfType("[]byte")).Return(nil)

View File

@ -16,7 +16,7 @@ package image
import ( import (
"bytes" "bytes"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -142,7 +142,7 @@ func (m *manifestV2ProcessorTestSuite) SetupTest() {
func (m *manifestV2ProcessorTestSuite) TestAbstractMetadata() { func (m *manifestV2ProcessorTestSuite) TestAbstractMetadata() {
artifact := &artifact.Artifact{} artifact := &artifact.Artifact{}
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(bytes.NewReader([]byte(config))), nil) m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(bytes.NewReader([]byte(config))), nil)
err := m.processor.AbstractMetadata(nil, artifact, []byte(manifest)) err := m.processor.AbstractMetadata(nil, artifact, []byte(manifest))
m.Require().Nil(err) m.Require().Nil(err)
m.NotNil(artifact.ExtraAttrs["created"]) m.NotNil(artifact.ExtraAttrs["created"])
@ -163,7 +163,7 @@ func (m *manifestV2ProcessorTestSuite) TestAbstractAddition() {
manifest, _, err := distribution.UnmarshalManifest(schema2.MediaTypeManifest, []byte(manifest)) manifest, _, err := distribution.UnmarshalManifest(schema2.MediaTypeManifest, []byte(manifest))
m.Require().Nil(err) m.Require().Nil(err)
m.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(manifest, "", nil) m.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(manifest, "", nil)
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)
addition, err := m.processor.AbstractAddition(nil, artifact, AdditionTypeBuildHistory) addition, err := m.processor.AbstractAddition(nil, artifact, AdditionTypeBuildHistory)
m.Require().Nil(err) m.Require().Nil(err)
m.Equal("application/json; charset=utf-8", addition.ContentType) m.Equal("application/json; charset=utf-8", addition.ContentType)

View File

@ -17,7 +17,7 @@ package wasm
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -124,7 +124,7 @@ func (m *WASMProcessorTestSuite) SetupTest() {
func (m *WASMProcessorTestSuite) TestAbstractMetadataForAnnotationFashion() { func (m *WASMProcessorTestSuite) TestAbstractMetadataForAnnotationFashion() {
artifact := &artifact.Artifact{} artifact := &artifact.Artifact{}
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(bytes.NewReader([]byte(annnotated_config))), nil) m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(bytes.NewReader([]byte(annnotated_config))), nil)
err := m.processor.AbstractMetadata(nil, artifact, []byte(annnotated_manifest)) err := m.processor.AbstractMetadata(nil, artifact, []byte(annnotated_manifest))
m.Require().Nil(err) m.Require().Nil(err)
m.NotNil(artifact.ExtraAttrs["created"]) m.NotNil(artifact.ExtraAttrs["created"])
@ -158,7 +158,7 @@ func (m *WASMProcessorTestSuite) TestAbstractAdditionForAnnotationFashion() {
deserializedManifest, err := schema2.FromStruct(manifest) deserializedManifest, err := schema2.FromStruct(manifest)
m.Require().Nil(err) m.Require().Nil(err)
m.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(deserializedManifest, "", nil) m.regCli.On("PullManifest", mock.Anything, mock.Anything).Return(deserializedManifest, "", nil)
m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), ioutil.NopCloser(strings.NewReader(annnotated_config)), nil) m.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), io.NopCloser(strings.NewReader(annnotated_config)), nil)
addition, err := m.processor.AbstractAddition(nil, artifact, AdditionTypeBuildHistory) addition, err := m.processor.AbstractAddition(nil, artifact, AdditionTypeBuildHistory)
m.Require().Nil(err) m.Require().Nil(err)
m.Equal("application/json; charset=utf-8", addition.ContentType) m.Equal("application/json; charset=utf-8", addition.ContentType)

View File

@ -17,7 +17,7 @@ package health
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
@ -59,7 +59,7 @@ func HTTPStatusCodeHealthChecker(method string, url string, header http.Header,
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != statusCode { if resp.StatusCode != statusCode {
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Debugf("failed to read response body: %v", err) log.Debugf("failed to read response body: %v", err)
} }

View File

@ -16,7 +16,7 @@ package icon
import ( import (
"encoding/base64" "encoding/base64"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -67,7 +67,7 @@ func (c *controllerTestSuite) TestGet() {
RepositoryName: "library/hello-world", RepositoryName: "library/hello-world",
}, },
}, nil) }, nil)
blob := ioutil.NopCloser(base64.NewDecoder(base64.StdEncoding, strings.NewReader(iconStr))) blob := io.NopCloser(base64.NewDecoder(base64.StdEncoding, strings.NewReader(iconStr)))
c.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), blob, nil) c.regCli.On("PullBlob", mock.Anything, mock.Anything).Return(int64(0), blob, nil)
icon, err := c.controller.Get(nil, "sha256:364feec11702f7ee079ba81da723438373afb0921f3646e9e5015406ee150986") icon, err := c.controller.Get(nil, "sha256:364feec11702f7ee079ba81da723438373afb0921f3646e9e5015406ee150986")
c.Require().Nil(err) c.Require().Nil(err)

View File

@ -17,7 +17,6 @@ package chart
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -47,7 +46,7 @@ func (f *fakeRegistry) ChartExist(name, version string) (bool, error) {
return true, nil return true, nil
} }
func (f *fakeRegistry) DownloadChart(name, version, contentURL string) (io.ReadCloser, error) { func (f *fakeRegistry) DownloadChart(name, version, contentURL string) (io.ReadCloser, error) {
r := ioutil.NopCloser(bytes.NewReader([]byte{'a'})) r := io.NopCloser(bytes.NewReader([]byte{'a'}))
return r, nil return r, nil
} }
func (f *fakeRegistry) UploadChart(name, version string, chart io.Reader) error { func (f *fakeRegistry) UploadChart(name, version string, chart io.Reader) error {

View File

@ -17,7 +17,6 @@ package image
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"testing" "testing"
"github.com/docker/distribution" "github.com/docker/distribution"
@ -88,11 +87,11 @@ func (f *fakeRegistry) BlobExist(repository, digest string) (bool, error) {
return false, nil return false, nil
} }
func (f *fakeRegistry) PullBlob(repository, digest string) (size int64, blob io.ReadCloser, err error) { func (f *fakeRegistry) PullBlob(repository, digest string) (size int64, blob io.ReadCloser, err error) {
r := ioutil.NopCloser(bytes.NewReader([]byte{'a'})) r := io.NopCloser(bytes.NewReader([]byte{'a'}))
return 1, r, nil return 1, r, nil
} }
func (f *fakeRegistry) PullBlobChunk(repository, digest string, blobSize, start, end int64) (size int64, blob io.ReadCloser, err error) { func (f *fakeRegistry) PullBlobChunk(repository, digest string, blobSize, start, end int64) (size int64, blob io.ReadCloser, err error) {
r := ioutil.NopCloser(bytes.NewReader([]byte{'a'})) r := io.NopCloser(bytes.NewReader([]byte{'a'}))
return 1, r, nil return 1, r, nil
} }
func (f *fakeRegistry) PushBlob(repository, digest string, size int64, blob io.Reader) error { func (f *fakeRegistry) PushBlob(repository, digest string, size int64, blob io.Reader) error {

View File

@ -16,7 +16,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -147,7 +147,7 @@ func handleAndParse(r *testingRequest, v interface{}) error {
return err return err
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/url" "net/url"
@ -587,7 +586,7 @@ func (cra *ChartRepositoryAPI) rewriteFileContent(files []formFile, request *htt
request.Header.Set(headerContentType, w.FormDataContentType()) request.Header.Set(headerContentType, w.FormDataContentType())
request.ContentLength = -1 request.ContentLength = -1
request.Body = ioutil.NopCloser(&body) request.Body = io.NopCloser(&body)
return nil return nil
} }

View File

@ -16,7 +16,7 @@
package api package api
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"path/filepath" "path/filepath"
@ -135,7 +135,7 @@ func request0(_sling *sling.Sling, acceptHeader string, authInfo ...usrInfo) (in
w := httptest.NewRecorder() w := httptest.NewRecorder()
handler.ServeHTTP(w, req) handler.ServeHTTP(w, req)
body, err := ioutil.ReadAll(w.Body) body, err := io.ReadAll(w.Body)
return w.Code, w.Header(), body, err return w.Code, w.Header(), body, err
} }

View File

@ -21,7 +21,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
@ -83,7 +83,7 @@ func (a *Auth) Authenticate(ctx context.Context, m models.AuthModel) (*models.Us
if err != nil { if err != nil {
return nil, err return nil, err
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Warningf("Failed to read response body, error: %v", err) log.Warningf("Failed to read response body, error: %v", err)
return nil, auth.ErrAuth{} return nil, auth.ErrAuth{}
@ -103,7 +103,7 @@ func (a *Auth) Authenticate(ctx context.Context, m models.AuthModel) (*models.Us
} else if resp.StatusCode == http.StatusUnauthorized { } else if resp.StatusCode == http.StatusUnauthorized {
return nil, auth.NewErrAuth(string(data)) return nil, auth.NewErrAuth(string(data))
} else { } else {
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Warningf("Failed to read response body, error: %v", err) log.Warningf("Failed to read response body, error: %v", err)
} }

View File

@ -18,7 +18,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html" "html"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -75,7 +75,7 @@ func (rth *reviewTokenHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque
if req.Method != http.MethodPost { if req.Method != http.MethodPost {
http.Error(rw, "", http.StatusMethodNotAllowed) http.Error(rw, "", http.StatusMethodNotAllowed)
} }
bodyBytes, err := ioutil.ReadAll(req.Body) bodyBytes, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
http.Error(rw, html.EscapeString(fmt.Sprintf("failed to read request body, error: %v", err)), http.StatusBadRequest) http.Error(rw, html.EscapeString(fmt.Sprintf("failed to read request body, error: %v", err)), http.StatusBadRequest)
} }

View File

@ -19,7 +19,6 @@ import (
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path" "path"
@ -110,7 +109,7 @@ func getKeyAndCertPath() (string, string) {
} }
func getPublicKey(crtPath string) (*rsa.PublicKey, error) { func getPublicKey(crtPath string) (*rsa.PublicKey, error) {
crt, err := ioutil.ReadFile(crtPath) crt, err := os.ReadFile(crtPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -17,7 +17,6 @@ package utils
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"github.com/goharbor/harbor/src/common/api" "github.com/goharbor/harbor/src/common/api"
@ -38,7 +37,7 @@ type StatusRespHandler struct {
func (s StatusRespHandler) Handle(resp *http.Response) error { func (s StatusRespHandler) Handle(resp *http.Response) error {
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != s.status { if resp.StatusCode != s.status {
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -73,7 +72,7 @@ func (h JobLogRespHandler) Handle(resp *http.Response) error {
return nil return nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Errorf("failed to read response body: %v", err) log.Errorf("failed to read response body: %v", err)
return err return err

View File

@ -17,7 +17,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@ -81,7 +81,7 @@ func NewDefaultHandler(ctl core.Interface) *DefaultHandler {
// HandleLaunchJobReq is implementation of method defined in interface 'Handler' // HandleLaunchJobReq is implementation of method defined in interface 'Handler'
func (dh *DefaultHandler) HandleLaunchJobReq(w http.ResponseWriter, req *http.Request) { func (dh *DefaultHandler) HandleLaunchJobReq(w http.ResponseWriter, req *http.Request) {
data, err := ioutil.ReadAll(req.Body) data, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
dh.handleError(w, req, http.StatusInternalServerError, errs.ReadRequestBodyError(err)) dh.handleError(w, req, http.StatusInternalServerError, errs.ReadRequestBodyError(err))
return return
@ -143,7 +143,7 @@ func (dh *DefaultHandler) HandleJobActionReq(w http.ResponseWriter, req *http.Re
vars := mux.Vars(req) vars := mux.Vars(req)
jobID := vars["job_id"] jobID := vars["job_id"]
data, err := ioutil.ReadAll(req.Body) data, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
dh.handleError(w, req, http.StatusInternalServerError, errs.ReadRequestBodyError(err)) dh.handleError(w, req, http.StatusInternalServerError, errs.ReadRequestBodyError(err))
return return

View File

@ -18,7 +18,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
@ -344,7 +344,7 @@ func (suite *APIHandlerTestSuite) postReq(url string, data []byte) ([]byte, int)
_ = res.Body.Close() _ = res.Body.Close()
}() }()
if res.ContentLength > 0 { if res.ContentLength > 0 {
resData, err = ioutil.ReadAll(res.Body) resData, err = io.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, 0 return nil, 0
} }
@ -371,7 +371,7 @@ func (suite *APIHandlerTestSuite) getReq(url string) ([]byte, int) {
_ = res.Body.Close() _ = res.Body.Close()
}() }()
data, err := ioutil.ReadAll(res.Body) data, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, 0 return nil, 0
} }

View File

@ -18,8 +18,8 @@ package config
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os"
"strconv" "strconv"
"strings" "strings"
@ -142,7 +142,7 @@ type LoggerConfig struct {
func (c *Configuration) Load(yamlFilePath string, detectEnv bool) error { func (c *Configuration) Load(yamlFilePath string, detectEnv bool) error {
if !utils.IsEmptyStr(yamlFilePath) { if !utils.IsEmptyStr(yamlFilePath) {
// Try to load from file first // Try to load from file first
data, err := ioutil.ReadFile(yamlFilePath) data, err := os.ReadFile(yamlFilePath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,7 +19,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@ -111,7 +111,7 @@ func (bc *basicClient) SendEvent(evt *Event) error {
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
if res.ContentLength > 0 { if res.ContentLength > 0 {
// read error content and return // read error content and return
dt, err := ioutil.ReadAll(res.Body) dt, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -41,7 +41,7 @@ type HookClientTestSuite struct {
func (suite *HookClientTestSuite) SetupSuite() { func (suite *HookClientTestSuite) SetupSuite() {
suite.client = NewClient(context.Background()) suite.client = NewClient(context.Background())
suite.mockServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { suite.mockServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
bytes, err := ioutil.ReadAll(r.Body) bytes, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return

View File

@ -1,7 +1,7 @@
package notification package notification
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -56,7 +56,7 @@ func TestSlackJobRun(t *testing.T) {
// test slack request // test slack request
ts := httptest.NewServer( ts := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body) body, _ := io.ReadAll(r.Body)
// test request method // test request method
assert.Equal(t, http.MethodPost, r.Method) assert.Equal(t, http.MethodPost, r.Method)

View File

@ -1,7 +1,7 @@
package notification package notification
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -49,7 +49,7 @@ func TestRun(t *testing.T) {
// test webhook request // test webhook request
ts := httptest.NewServer( ts := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body) body, _ := io.ReadAll(r.Body)
// test request method // test request method
assert.Equal(t, http.MethodPost, r.Method) assert.Equal(t, http.MethodPost, r.Method)

View File

@ -3,7 +3,6 @@ package logger
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path" "path"
"testing" "testing"
@ -150,7 +149,7 @@ func TestGetGetter(t *testing.T) {
} }
logFile := path.Join(os.TempDir(), fakeLogFile) logFile := path.Join(os.TempDir(), fakeLogFile)
if err := ioutil.WriteFile(logFile, []byte("hello log getter"), 0644); err != nil { if err := os.WriteFile(logFile, []byte("hello log getter"), 0644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer func() { defer func() {

View File

@ -4,7 +4,7 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"path" "path"
"strings" "strings"
@ -34,7 +34,7 @@ func (fg *FileGetter) Retrieve(logID string) ([]byte, error) {
return nil, errs.NoObjectFoundError(logID) return nil, errs.NoObjectFoundError(logID)
} }
return ioutil.ReadFile(fPath) return os.ReadFile(fPath)
} }
func isValidLogID(id string) error { func isValidLogID(id string) error {

View File

@ -1,7 +1,6 @@
package getter package getter
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
"testing" "testing"
@ -18,7 +17,7 @@ const (
// Test the log data getter // Test the log data getter
func TestLogDataGetter(t *testing.T) { func TestLogDataGetter(t *testing.T) {
fakeLog := path.Join(os.TempDir(), newLogFileName) fakeLog := path.Join(os.TempDir(), newLogFileName)
if err := ioutil.WriteFile(fakeLog, []byte("hello"), 0600); err != nil { if err := os.WriteFile(fakeLog, []byte("hello"), 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer func() { defer func() {

View File

@ -2,7 +2,6 @@ package sweeper
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -31,7 +30,7 @@ func NewFileSweeper(workDir string, duration int) *FileSweeper {
func (fs *FileSweeper) Sweep() (int, error) { func (fs *FileSweeper) Sweep() (int, error) {
cleared := 0 cleared := 0
logFiles, err := ioutil.ReadDir(fs.workDir) logFiles, err := os.ReadDir(fs.workDir)
if err != nil { if err != nil {
return 0, fmt.Errorf("getting outdated log files under '%s' failed with error: %s", fs.workDir, err) return 0, fmt.Errorf("getting outdated log files under '%s' failed with error: %s", fs.workDir, err)
} }
@ -45,13 +44,16 @@ func (fs *FileSweeper) Sweep() (int, error) {
// Record all errors // Record all errors
errs := make([]string, 0) errs := make([]string, 0)
for _, logFile := range logFiles { for _, logFile := range logFiles {
if logFile.ModTime().Add(time.Duration(fs.duration) * oneDay).Before(time.Now()) { logFileInfo, ise := logFile.Info()
if ise != nil {
continue
}
if logFileInfo.ModTime().Add(time.Duration(fs.duration) * oneDay).Before(time.Now()) {
logFilePath := path.Join(fs.workDir, logFile.Name()) logFilePath := path.Join(fs.workDir, logFile.Name())
if err := os.Remove(logFilePath); err != nil { if err := os.Remove(logFilePath); err != nil {
errs = append(errs, fmt.Sprintf("remove log file '%s' error: %s", logFilePath, err)) errs = append(errs, fmt.Sprintf("remove log file '%s' error: %s", logFilePath, err))
continue // go on for next one continue // go on for next one
} }
cleared++ cleared++
} }
} }

View File

@ -1,7 +1,6 @@
package sweeper package sweeper
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
"testing" "testing"
@ -21,7 +20,7 @@ func TestFileSweeper(t *testing.T) {
}() }()
logFile := path.Join(workDir, "TestFileSweeper.log") logFile := path.Join(workDir, "TestFileSweeper.log")
if err := ioutil.WriteFile(logFile, []byte("hello"), os.ModePerm); err != nil { if err := os.WriteFile(logFile, []byte("hello"), os.ModePerm); err != nil {
t.Fatal(err) t.Fatal(err)
} }
oldModTime := time.Unix(time.Now().Unix()-6*24*3600, 0) oldModTime := time.Unix(time.Now().Unix()-6*24*3600, 0)

View File

@ -16,7 +16,6 @@ package encrypt
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -25,8 +24,8 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
secret := []byte("9TXCcHgNAAp1aSHh") secret := []byte("9TXCcHgNAAp1aSHh")
filename, err := ioutil.TempFile(os.TempDir(), "keyfile") filename, err := os.CreateTemp(os.TempDir(), "keyfile")
err = ioutil.WriteFile(filename.Name(), secret, 0644) err = os.WriteFile(filename.Name(), secret, 0644)
if err != nil { if err != nil {
fmt.Printf("failed to create temp key file\n") fmt.Printf("failed to create temp key file\n")
} }

View File

@ -14,9 +14,7 @@
package encrypt package encrypt
import ( import "os"
"io/ioutil"
)
// KeyProvider provides the key used to encrypt and decrypt attrs // KeyProvider provides the key used to encrypt and decrypt attrs
type KeyProvider interface { type KeyProvider interface {
@ -40,7 +38,7 @@ func NewFileKeyProvider(path string) KeyProvider {
// Get returns the key read from file // Get returns the key read from file
func (f *FileKeyProvider) Get(params map[string]interface{}) (string, error) { func (f *FileKeyProvider) Get(params map[string]interface{}) (string, error) {
b, err := ioutil.ReadFile(f.path) b, err := os.ReadFile(f.path)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -15,7 +15,6 @@
package encrypt package encrypt
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
) )
@ -24,7 +23,7 @@ func TestGetOfFileKeyProvider(t *testing.T) {
path := "/tmp/key" path := "/tmp/key"
key := "key_content" key := "key_content"
if err := ioutil.WriteFile(path, []byte(key), 0777); err != nil { if err := os.WriteFile(path, []byte(key), 0777); err != nil {
t.Errorf("failed to write to file %s: %v", path, err) t.Errorf("failed to write to file %s: %v", path, err)
return return
} }

View File

@ -15,7 +15,7 @@
package lib package lib
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"testing" "testing"
@ -30,22 +30,22 @@ type NopCloseRequestTestSuite struct {
func (suite *NopCloseRequestTestSuite) TestReusableBody() { func (suite *NopCloseRequestTestSuite) TestReusableBody() {
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader("body")) r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader("body"))
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
suite.Nil(err) suite.Nil(err)
suite.Equal([]byte("body"), body) suite.Equal([]byte("body"), body)
body, err = ioutil.ReadAll(r.Body) body, err = io.ReadAll(r.Body)
suite.Nil(err) suite.Nil(err)
suite.Equal([]byte(""), body) suite.Equal([]byte(""), body)
r, _ = http.NewRequest(http.MethodPost, "/", strings.NewReader("body")) r, _ = http.NewRequest(http.MethodPost, "/", strings.NewReader("body"))
r = NopCloseRequest(r) r = NopCloseRequest(r)
body, err = ioutil.ReadAll(r.Body) body, err = io.ReadAll(r.Body)
suite.Nil(err) suite.Nil(err)
suite.Equal([]byte("body"), body) suite.Equal([]byte("body"), body)
body, err = ioutil.ReadAll(r.Body) body, err = io.ReadAll(r.Body)
suite.Nil(err) suite.Nil(err)
suite.Equal([]byte("body"), body) suite.Equal([]byte("body"), body)
} }

View File

@ -17,7 +17,7 @@ package rest
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -58,7 +58,7 @@ var configMapForTest = map[string]interface{}{}
func ConfigPutHandler(w http.ResponseWriter, r *http.Request) { func ConfigPutHandler(w http.ResponseWriter, r *http.Request) {
cfgs := map[string]interface{}{} cfgs := map[string]interface{}{}
content, err := ioutil.ReadAll(r.Body) content, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -4,7 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -119,7 +119,7 @@ func (hc *HTTPClient) get(url string, cred *auth.Credential, parmas map[string]s
// If failed, read error message; if succeeded, read content. // If failed, read error message; if succeeded, read content.
defer res.Body.Close() defer res.Body.Close()
bytes, err := ioutil.ReadAll(res.Body) bytes, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -185,7 +185,7 @@ func (hc *HTTPClient) post(url string, cred *auth.Credential, body interface{},
} }
defer res.Body.Close() defer res.Body.Close()
bytes, err := ioutil.ReadAll(res.Body) bytes, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -16,7 +16,7 @@ package provider
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -45,7 +45,7 @@ func MockDragonflyProvider() *httptest.Server {
return return
} }
data, err := ioutil.ReadAll(r.Body) data, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error())) _, _ = w.Write([]byte(err.Error()))
@ -118,7 +118,7 @@ func MockKrakenProvider() *httptest.Server {
return return
} }
data, err := ioutil.ReadAll(r.Body) data, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error())) _, _ = w.Write([]byte(err.Error()))

View File

@ -3,7 +3,6 @@ package aliacr
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -43,7 +42,7 @@ func getMockAdapter(t *testing.T, hasCred, health bool) (*adapter, *httptest.Ser
Pattern: "/", Pattern: "/",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL) fmt.Println(r.Method, r.URL)
if buf, e := ioutil.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil { if buf, e := io.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil {
fmt.Println("\t", string(buf)) fmt.Println("\t", string(buf))
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@ -17,7 +17,6 @@ package artifacthub
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
@ -140,7 +139,7 @@ func (a *adapter) download(contentURL string) (io.ReadCloser, error) {
return nil, err return nil, err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,7 +3,7 @@ package artifacthub
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
common_http "github.com/goharbor/harbor/src/common/http" common_http "github.com/goharbor/harbor/src/common/http"
@ -38,7 +38,7 @@ func (c *Client) getHelmChartVersion(fullName, version string) (*ChartVersion, e
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -77,7 +77,7 @@ func (c *Client) getReplicationInfo() ([]*ChartInfo, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -112,7 +112,7 @@ func (c *Client) checkHealthy() error {
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body) _, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"regexp" "regexp"
@ -140,7 +139,7 @@ func getMockAdapter(t *testing.T, hasCred, health bool) (*adapter, *httptest.Ser
Pattern: "/", Pattern: "/",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL) fmt.Println(r.Method, r.URL)
if buf, e := ioutil.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil { if buf, e := io.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil {
fmt.Println("\t", string(buf)) fmt.Println("\t", string(buf))
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
@ -250,7 +249,7 @@ func TestAwsAuthCredential_Modify(t *testing.T) {
Pattern: "/", Pattern: "/",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL) fmt.Println(r.Method, r.URL)
if buf, e := ioutil.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil { if buf, e := io.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil {
fmt.Println("\t", string(buf)) fmt.Println("\t", string(buf))
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@ -17,7 +17,7 @@ package azurecr
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -92,7 +92,7 @@ func (a *authorizer) Modify(req *http.Request) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
@ -151,7 +151,7 @@ func (a *adapter) listNamespaces() ([]string, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -199,7 +199,7 @@ func (a *adapter) CreateNamespace(namespace *model.Namespace) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -220,7 +220,7 @@ func (a *adapter) getNamespace(namespace string) (*model.Namespace, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -381,7 +381,7 @@ func (a *adapter) DeleteManifest(repository, reference string) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -402,7 +402,7 @@ func (a *adapter) getRepos(namespace, name string, page, pageSize int) (*ReposRe
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -429,7 +429,7 @@ func (a *adapter) getTags(namespace, repo string, page, pageSize int) (*TagsResp
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
commonhttp "github.com/goharbor/harbor/src/common/http" commonhttp "github.com/goharbor/harbor/src/common/http"
@ -68,7 +67,7 @@ func (c *Client) refreshToken() error {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"reflect" "reflect"
@ -66,7 +66,7 @@ func (c *Client) getAndIteratePagination(endpoint string, v interface{}) error {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -117,7 +117,7 @@ func (c *Client) getRepositories() ([]*model.Repository, error) {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -198,7 +198,7 @@ func (c *Client) getNamespaces() ([]Account, error) {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -270,7 +270,7 @@ func (c *Client) createRepository(repository string) error {
return nil return nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -313,7 +313,7 @@ func (c *Client) createNamespace(namespace string) error {
return nil return nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"reflect" "reflect"
@ -121,7 +120,7 @@ func (c *Client) GetAndIteratePagination(endpoint string, v interface{}) error {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,7 @@ package googlegcr
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
@ -170,7 +170,7 @@ func (a adapter) listGcrTagsByRef(repository, reference string) ([]string, strin
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }

View File

@ -3,7 +3,6 @@ package googlegcr
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -69,7 +68,7 @@ func getMockAdapter(t *testing.T, hasCred, health bool) (*adapter, *httptest.Ser
Pattern: "/", Pattern: "/",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL) fmt.Println(r.Method, r.URL)
if buf, e := ioutil.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil { if buf, e := io.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil {
fmt.Println("\t", string(buf)) fmt.Println("\t", string(buf))
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@ -18,7 +18,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/url" "net/url"
@ -176,7 +175,7 @@ func (a *Adapter) DownloadChart(name, version, contentURL string) (io.ReadCloser
return nil, err return nil, err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -215,7 +214,7 @@ func (a *Adapter) UploadChart(name, version string, chart io.Reader) error {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,6 @@ package helmhub
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -134,7 +133,7 @@ func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
return nil, err return nil, err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,7 +3,7 @@ package helmhub
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
commonhttp "github.com/goharbor/harbor/src/common/http" commonhttp "github.com/goharbor/harbor/src/common/http"
@ -41,7 +41,7 @@ func (c *Client) fetchCharts() (*chartList, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -72,7 +72,7 @@ func (c *Client) fetchChartDetail(chartName string) (*chartVersionList, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -104,7 +104,7 @@ func (c *Client) checkHealthy() error {
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body) _, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,7 @@ package huawei
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -114,10 +114,10 @@ func (a *adapter) ListNamespaces(query *model.NamespaceQuery) ([]*model.Namespac
defer resp.Body.Close() defer resp.Body.Close()
code := resp.StatusCode code := resp.StatusCode
if code >= 300 || code < 200 { if code >= 300 || code < 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return namespaces, fmt.Errorf("[%d][%s]", code, string(body)) return namespaces, fmt.Errorf("[%d][%s]", code, string(body))
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return namespaces, err return namespaces, err
} }
@ -199,7 +199,7 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
defer resp.Body.Close() defer resp.Body.Close()
code := resp.StatusCode code := resp.StatusCode
if code >= 300 || code < 200 { if code >= 300 || code < 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("[%d][%s]", code, string(body)) return fmt.Errorf("[%d][%s]", code, string(body))
} }
@ -231,10 +231,10 @@ func (a *adapter) GetNamespace(namespaceStr string) (*model.Namespace, error) {
defer resp.Body.Close() defer resp.Body.Close()
code := resp.StatusCode code := resp.StatusCode
if code >= 300 || code < 200 { if code >= 300 || code < 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return namespace, fmt.Errorf("[%d][%s]", code, string(body)) return namespace, fmt.Errorf("[%d][%s]", code, string(body))
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return namespace, err return namespace, err
} }

View File

@ -17,7 +17,7 @@ package huawei
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -48,10 +48,10 @@ func (a *adapter) FetchArtifacts(filters []*model.Filter) ([]*model.Resource, er
defer resp.Body.Close() defer resp.Body.Close()
code := resp.StatusCode code := resp.StatusCode
if code >= 300 || code < 200 { if code >= 300 || code < 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return resources, fmt.Errorf("[%d][%s]", code, string(body)) return resources, fmt.Errorf("[%d][%s]", code, string(body))
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return resources, err return resources, err
} }
@ -96,10 +96,10 @@ func (a *adapter) ManifestExist(repository, reference string) (exist bool, desc
if code == 404 { if code == 404 {
return false, nil, nil return false, nil, nil
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return exist, nil, fmt.Errorf("[%d][%s]", code, string(body)) return exist, nil, fmt.Errorf("[%d][%s]", code, string(body))
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return exist, nil, err return exist, nil, err
} }
@ -140,7 +140,7 @@ func (a *adapter) DeleteManifest(repository, reference string) error {
defer resp.Body.Close() defer resp.Body.Close()
code := resp.StatusCode code := resp.StatusCode
if code >= 300 || code < 200 { if code >= 300 || code < 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("[%d][%s]", code, string(body)) return fmt.Errorf("[%d][%s]", code, string(body))
} }
@ -219,10 +219,10 @@ func getJwtToken(a *adapter, repository string) (token jwtToken, err error) {
defer resp.Body.Close() defer resp.Body.Close()
code := resp.StatusCode code := resp.StatusCode
if code >= 300 || code < 200 { if code >= 300 || code < 200 {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return token, fmt.Errorf("[%d][%s]", code, string(body)) return token, fmt.Errorf("[%d][%s]", code, string(body))
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return token, err return token, err
} }

View File

@ -18,7 +18,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -300,7 +299,7 @@ func (a *adapter) PushBlob(repository, digest string, size int64, blob io.Reader
return a.ackPushBlob(repository, digest, location, rangeSize) return a.ackPushBlob(repository, digest, location, rangeSize)
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -330,7 +329,7 @@ func (a *adapter) preparePushBlob(repository string) (string, error) {
return resp.Header.Get("Docker-Upload-Uuid"), nil return resp.Header.Get("Docker-Upload-Uuid"), nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -361,7 +360,7 @@ func (a *adapter) ackPushBlob(repository, digest, location, size string) error {
return nil return nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -18,7 +18,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
common_http "github.com/goharbor/harbor/src/common/http" common_http "github.com/goharbor/harbor/src/common/http"
@ -74,7 +74,7 @@ func (c *client) getDockerRepositories() ([]*repository, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return repositories, err return repositories, err
} }
@ -109,7 +109,7 @@ func (c *client) createDockerRepository(name string) error {
return nil return nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -20,7 +20,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -214,7 +213,7 @@ func (a *adapter) createNamespace(namespace *model.Namespace) error {
return nil return nil
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }
@ -235,7 +234,7 @@ func (a *adapter) getNamespace(namespace string) (*model.Namespace, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -274,12 +273,12 @@ func (a *adapter) PullBlob(repository, digest string) (size int64, blob io.ReadC
if size == 0 { if size == 0 {
var data []byte var data []byte
defer blob.Close() defer blob.Close()
data, err = ioutil.ReadAll(blob) data, err = io.ReadAll(blob)
if err != nil { if err != nil {
return return
} }
size = int64(len(data)) size = int64(len(data))
blob = ioutil.NopCloser(bytes.NewReader(data)) blob = io.NopCloser(bytes.NewReader(data))
return size, blob, nil return size, blob, nil
} }
} }

View File

@ -3,7 +3,6 @@ package tencentcr
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
@ -229,7 +228,7 @@ func getMockAdapter(t *testing.T, hasCred, health bool) (*adapter, *httptest.Ser
Pattern: "/", Pattern: "/",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL) fmt.Println(r.Method, r.URL)
if buf, e := ioutil.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil { if buf, e := io.ReadAll(&io.LimitedReader{R: r.Body, N: 80}); e == nil {
fmt.Println("\t", string(buf)) fmt.Println("\t", string(buf))
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"strings" "strings"
@ -183,7 +182,7 @@ func (a *adapter) DownloadChart(name, version, contentURL string) (rc io.ReadClo
return return
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err = ioutil.ReadAll(resp.Body) body, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return return
} }
@ -234,7 +233,7 @@ func (a *adapter) UploadChart(name, version string, reader io.Reader) (err error
// 3. parse response // 3. parse response
var data []byte var data []byte
data, err = ioutil.ReadAll(resp.Body) data, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return return
} }

View File

@ -17,7 +17,7 @@ package bearer
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -120,7 +120,7 @@ func (a *authorizer) fetchToken(scopes []*scope) (*token, error) {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,7 +19,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -201,7 +200,7 @@ func (c *client) catalog(url string) ([]string, string, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
@ -248,7 +247,7 @@ func (c *client) listTags(url string) ([]string, string, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
@ -301,7 +300,7 @@ func (c *client) PullManifest(repository, reference string, acceptedMediaTypes .
return nil, "", err return nil, "", err
} }
defer resp.Body.Close() defer resp.Body.Close()
payload, err := ioutil.ReadAll(resp.Body) payload, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
@ -664,7 +663,7 @@ func (c *client) do(req *http.Request) (*http.Response, error) {
} }
if resp.StatusCode < 200 || resp.StatusCode > 299 { if resp.StatusCode < 200 || resp.StatusCode > 299 {
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -16,7 +16,7 @@ package registry
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"testing" "testing"
@ -319,7 +319,7 @@ func (c *clientTestSuite) TestPullBlob() {
c.Require().Nil(err) c.Require().Nil(err)
c.Equal(int64(len(data)), size) c.Equal(int64(len(data)), size)
b, err := ioutil.ReadAll(blob) b, err := io.ReadAll(blob)
c.Require().Nil(err) c.Require().Nil(err)
c.EqualValues(data, b) c.EqualValues(data, b)
} }

View File

@ -3,7 +3,6 @@ package export
import ( import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -17,7 +16,7 @@ type DigestCalculatorTestSuite struct {
func (suite *DigestCalculatorTestSuite) TestDigestCalculation() { func (suite *DigestCalculatorTestSuite) TestDigestCalculation() {
fileName := "/tmp/testfile.txt" fileName := "/tmp/testfile.txt"
data := []byte("test") data := []byte("test")
ioutil.WriteFile(fileName, data, os.ModePerm) os.WriteFile(fileName, data, os.ModePerm)
digestCalc := SHA256ArtifactDigestCalculator{} digestCalc := SHA256ArtifactDigestCalculator{}
digest, err := digestCalc.Calculate(fileName) digest, err := digestCalc.Calculate(fileName)
suite.NoError(err) suite.NoError(err)

View File

@ -19,7 +19,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"reflect" "reflect"
@ -578,7 +578,7 @@ func makeBearerAuthorization(robotAccount *model.Robot, tokenURL string, reposit
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -19,7 +19,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -254,7 +254,7 @@ func reportResponseHandler() responseHandler {
// generalRespHandlerFunc is a handler to cover the general cases // generalRespHandlerFunc is a handler to cover the general cases
func generalRespHandlerFunc(expectedCode, code int, resp *http.Response) ([]byte, error) { func generalRespHandlerFunc(expectedCode, code int, resp *http.Response) ([]byte, error) {
buf, err := ioutil.ReadAll(resp.Body) buf, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -140,7 +139,7 @@ func (suite *ManagerTestSuite) TestRead() {
dummyRepoFilepath := fmt.Sprintf("/tmp/sys_art_test.dmp_%v", time.Now()) dummyRepoFilepath := fmt.Sprintf("/tmp/sys_art_test.dmp_%v", time.Now())
data := []byte("test data") data := []byte("test data")
err := ioutil.WriteFile(dummyRepoFilepath, data, os.ModePerm) err := os.WriteFile(dummyRepoFilepath, data, os.ModePerm)
suite.NoErrorf(err, "Unexpected error when creating test repo file: %v", dummyRepoFilepath) suite.NoErrorf(err, "Unexpected error when creating test repo file: %v", dummyRepoFilepath)
repoHandle, err := os.Open(dummyRepoFilepath) repoHandle, err := os.Open(dummyRepoFilepath)
@ -162,7 +161,7 @@ func (suite *ManagerTestSuite) TestReadSystemArtifactRecordNotFound() {
dummyRepoFilepath := fmt.Sprintf("/tmp/sys_art_test.dmp_%v", time.Now()) dummyRepoFilepath := fmt.Sprintf("/tmp/sys_art_test.dmp_%v", time.Now())
data := []byte("test data") data := []byte("test data")
err := ioutil.WriteFile(dummyRepoFilepath, data, os.ModePerm) err := os.WriteFile(dummyRepoFilepath, data, os.ModePerm)
suite.NoErrorf(err, "Unexpected error when creating test repo file: %v", dummyRepoFilepath) suite.NoErrorf(err, "Unexpected error when creating test repo file: %v", dummyRepoFilepath)
repoHandle, err := os.Open(dummyRepoFilepath) repoHandle, err := os.Open(dummyRepoFilepath)

View File

@ -3,7 +3,7 @@ package token
import ( import (
"crypto/rsa" "crypto/rsa"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/golang-jwt/jwt/v4" "github.com/golang-jwt/jwt/v4"
@ -67,7 +67,7 @@ func DefaultTokenOptions() *Options {
// NewOptions create Options based on input parms // NewOptions create Options based on input parms
func NewOptions(sm, iss, keyPath string) (*Options, error) { func NewOptions(sm, iss, keyPath string) (*Options, error) {
pk, err := ioutil.ReadFile(keyPath) pk, err := os.ReadFile(keyPath)
if err != nil { if err != nil {
log.Errorf(fmt.Sprintf("failed to read private key %v", err)) log.Errorf(fmt.Sprintf("failed to read private key %v", err))
return nil, err return nil, err

View File

@ -15,7 +15,7 @@
package api package api
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -28,6 +28,6 @@ func TestHealth(t *testing.T) {
req, _ := http.NewRequest("GET", "", nil) req, _ := http.NewRequest("GET", "", nil)
Health(w, req) Health(w, req)
assert.Equal(t, http.StatusOK, w.Code) assert.Equal(t, http.StatusOK, w.Code)
result, _ := ioutil.ReadAll(w.Body) result, _ := io.ReadAll(w.Body)
assert.Equal(t, "\"healthy\"", string(result)) assert.Equal(t, "\"healthy\"", string(result))
} }

View File

@ -16,7 +16,7 @@ package client
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
@ -120,7 +120,7 @@ func (c *client) do(req *http.Request) (*http.Response, error) {
} }
if resp.StatusCode < 200 || resp.StatusCode > 299 { if resp.StatusCode < 200 || resp.StatusCode > 299 {
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -16,7 +16,6 @@ package config
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/docker/distribution/configuration" "github.com/docker/distribution/configuration"
@ -47,7 +46,7 @@ type Configuration struct {
func (c *Configuration) Load(yamlFilePath string, detectEnv bool) error { func (c *Configuration) Load(yamlFilePath string, detectEnv bool) error {
if len(yamlFilePath) != 0 { if len(yamlFilePath) != 0 {
// Try to load from file first // Try to load from file first
data, err := ioutil.ReadFile(yamlFilePath) data, err := os.ReadFile(yamlFilePath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -15,7 +15,7 @@
package blob package blob
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"github.com/goharbor/harbor/src/lib" "github.com/goharbor/harbor/src/lib"
@ -34,7 +34,7 @@ func PutManifestMiddleware() func(http.Handler) http.Handler {
logger := log.G(ctx) logger := log.G(ctx)
lib.NopCloseRequest(r) // make the r.Body re-readable lib.NopCloseRequest(r) // make the r.Body re-readable
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
return err return err
} }
@ -64,7 +64,7 @@ func PutManifestMiddleware() func(http.Handler) http.Handler {
return err return err
} }
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,7 +3,7 @@ package cosign
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"regexp" "regexp"
@ -76,7 +76,7 @@ func SignatureMiddleware() func(http.Handler) http.Handler {
return nil return nil
} }
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,7 +3,7 @@ package nydus
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
@ -84,7 +84,7 @@ func AcceleratorMiddleware() func(http.Handler) http.Handler {
return nil return nil
} }
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -16,7 +16,7 @@ package quota
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -49,7 +49,7 @@ var (
unmarshalManifest = func(r *http.Request) (distribution.Manifest, distribution.Descriptor, error) { unmarshalManifest = func(r *http.Request) (distribution.Manifest, distribution.Descriptor, error) {
lib.NopCloseRequest(r) lib.NopCloseRequest(r)
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
return nil, distribution.Descriptor{}, err return nil, distribution.Descriptor{}, err
} }

View File

@ -17,7 +17,7 @@ package security
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -89,7 +89,7 @@ func newAuthProxyTestServer() (*httptest.Server, error) {
} }
var review v1beta1.TokenReview var review v1beta1.TokenReview
bodyData, _ := ioutil.ReadAll(r.Body) bodyData, _ := io.ReadAll(r.Body)
if err := json.Unmarshal(bodyData, &review); err != nil { if err := json.Unmarshal(bodyData, &review); err != nil {
http.Error(w, fmt.Sprintf("failed to decode body: %v", err), http.StatusBadRequest) http.Error(w, fmt.Sprintf("failed to decode body: %v", err), http.StatusBadRequest)
return return

View File

@ -18,7 +18,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -102,7 +101,7 @@ func (suite *Suite) GetJSON(url string, js interface{}, headers ...map[string]st
} }
if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest { if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest {
data, err := ioutil.ReadAll(res.Body) data, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return res, err return res, err
} }
@ -112,7 +111,7 @@ func (suite *Suite) GetJSON(url string, js interface{}, headers ...map[string]st
return res, err return res, err
} }
res.Body = ioutil.NopCloser(bytes.NewBuffer(data)) res.Body = io.NopCloser(bytes.NewBuffer(data))
} }
return res, nil return res, nil