diff --git a/api/auth/azure/azure.go b/api/auth/azure/azure.go index b682195701..ecca535b43 100644 --- a/api/auth/azure/azure.go +++ b/api/auth/azure/azure.go @@ -7,7 +7,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -175,7 +175,7 @@ func (a *AzureAuth) getJWT() (string, error) { } defer resp.Body.Close() - responseBytes, err := ioutil.ReadAll(resp.Body) + responseBytes, err := io.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("error reading response body from Azure token endpoint: %w", err) } @@ -222,7 +222,7 @@ func getMetadata() (metadataJSON, error) { } defer resp.Body.Close() - responseBytes, err := ioutil.ReadAll(resp.Body) + responseBytes, err := io.ReadAll(resp.Body) if err != nil { return metadataJSON{}, fmt.Errorf("error reading response body from metadata endpoint: %w", err) } diff --git a/api/auth/gcp/gcp.go b/api/auth/gcp/gcp.go index 2d6ef842a4..7f4f222c0c 100644 --- a/api/auth/gcp/gcp.go +++ b/api/auth/gcp/gcp.go @@ -7,7 +7,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -181,7 +181,7 @@ func (a *GCPAuth) getJWTFromMetadataService(vaultAddress string) (string, error) defer resp.Body.Close() // get jwt from response - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) jwt := string(body) if err != nil { return "", fmt.Errorf("error reading response from metadata service: %w", err) diff --git a/api/sys_raft.go b/api/sys_raft.go index 699f6e9fd0..f0e896271b 100644 --- a/api/sys_raft.go +++ b/api/sys_raft.go @@ -264,7 +264,7 @@ func (c *Sys) RaftSnapshotWithContext(ctx context.Context, snapWriter io.Writer) continue } var b []byte - b, err = ioutil.ReadAll(t) + b, err = io.ReadAll(t) if err != nil || len(b) == 0 { return } diff --git a/builtin/credential/aws/backend_test.go b/builtin/credential/aws/backend_test.go index 771dc0e311..5770b2c5ed 100644 --- a/builtin/credential/aws/backend_test.go +++ b/builtin/credential/aws/backend_test.go @@ -8,7 +8,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -1516,7 +1516,7 @@ func buildCallerIdentityLoginData(request *http.Request, roleName string) (map[s if err != nil { return nil, err } - requestBody, err := ioutil.ReadAll(request.Body) + requestBody, err := io.ReadAll(request.Body) if err != nil { return nil, err } diff --git a/builtin/credential/aws/path_login.go b/builtin/credential/aws/path_login.go index a0e5a96505..fdb37da72b 100644 --- a/builtin/credential/aws/path_login.go +++ b/builtin/credential/aws/path_login.go @@ -12,7 +12,7 @@ import ( "encoding/xml" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "regexp" @@ -1803,7 +1803,7 @@ func submitCallerIdentityRequest(ctx context.Context, maxRetries int, method, en } // we check for status code afterwards to also print out response body - responseBody, err := ioutil.ReadAll(response.Body) + responseBody, err := io.ReadAll(response.Body) if err != nil { return nil, err } diff --git a/builtin/credential/cert/test_responder.go b/builtin/credential/cert/test_responder.go index 2052736d33..56fb4727be 100644 --- a/builtin/credential/cert/test_responder.go +++ b/builtin/credential/cert/test_responder.go @@ -19,7 +19,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -168,7 +168,7 @@ func (rs *Responder) ServeHTTP(response http.ResponseWriter, request *http.Reque return } case "POST": - requestBody, err = ioutil.ReadAll(request.Body) + requestBody, err = io.ReadAll(request.Body) if err != nil { rs.log.Log("Problem reading body of POST", err) response.WriteHeader(http.StatusBadRequest) diff --git a/builtin/logical/rabbitmq/path_role_create.go b/builtin/logical/rabbitmq/path_role_create.go index 956a016720..c06e824428 100644 --- a/builtin/logical/rabbitmq/path_role_create.go +++ b/builtin/logical/rabbitmq/path_role_create.go @@ -6,7 +6,7 @@ package rabbitmq import ( "context" "fmt" - "io/ioutil" + "io" "github.com/hashicorp/vault/sdk/framework" "github.com/hashicorp/vault/sdk/helper/template" @@ -113,7 +113,7 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr } }() if !isIn200s(resp.StatusCode) { - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) return nil, fmt.Errorf("error creating user %s - %d: %s", username, resp.StatusCode, body) } @@ -128,7 +128,7 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr b.Logger().Error(fmt.Sprintf("deleting %s due to permissions being in an unknown state, but failed: %s", username, err)) } if !isIn200s(resp.StatusCode) { - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) b.Logger().Error(fmt.Sprintf("deleting %s due to permissions being in an unknown state, but error deleting: %d: %s", username, resp.StatusCode, body)) } }() @@ -151,7 +151,7 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr } }() if !isIn200s(resp.StatusCode) { - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) return fmt.Errorf("error updating vhost permissions for %s - %d: %s", vhost, resp.StatusCode, body) } return nil @@ -180,7 +180,7 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr } }() if !isIn200s(resp.StatusCode) { - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) return fmt.Errorf("error updating vhost permissions for %s - %d: %s", vhost, resp.StatusCode, body) } return nil diff --git a/command/agentproxyshared/auth/gcp/gcp.go b/command/agentproxyshared/auth/gcp/gcp.go index 5d913581bc..aaaf21d16a 100644 --- a/command/agentproxyshared/auth/gcp/gcp.go +++ b/command/agentproxyshared/auth/gcp/gcp.go @@ -8,7 +8,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "time" @@ -151,7 +151,7 @@ func (g *gcpMethod) Authenticate(ctx context.Context, client *api.Client) (retPa return } defer resp.Body.Close() - jwtBytes, err := ioutil.ReadAll(resp.Body) + jwtBytes, err := io.ReadAll(resp.Body) if err != nil { retErr = fmt.Errorf("error reading instance token response body: %w", err) return diff --git a/command/agentproxyshared/auth/kubernetes/kubernetes.go b/command/agentproxyshared/auth/kubernetes/kubernetes.go index 639226505f..6f16a2b9b4 100644 --- a/command/agentproxyshared/auth/kubernetes/kubernetes.go +++ b/command/agentproxyshared/auth/kubernetes/kubernetes.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "os" "strings" @@ -123,7 +122,7 @@ func (k *kubernetesMethod) readJWT() (string, error) { } defer data.Close() - contentBytes, err := ioutil.ReadAll(data) + contentBytes, err := io.ReadAll(data) if err != nil { return "", err } diff --git a/command/agentproxyshared/cache/proxy.go b/command/agentproxyshared/cache/proxy.go index 503d981d60..231c5d9d20 100644 --- a/command/agentproxyshared/cache/proxy.go +++ b/command/agentproxyshared/cache/proxy.go @@ -57,7 +57,7 @@ func NewSendResponse(apiResponse *api.Response, responseBody []byte) (*SendRespo } // If a response body is separately provided we set that as the SendResponse.ResponseBody, - // otherwise we will do an ioutil.ReadAll to extract the response body from apiResponse. + // otherwise we will do an io.ReadAll to extract the response body from apiResponse. switch { case len(responseBody) > 0: resp.ResponseBody = responseBody diff --git a/helper/testhelpers/testhelpers.go b/helper/testhelpers/testhelpers.go index 184f064c86..e7f8ed30a0 100644 --- a/helper/testhelpers/testhelpers.go +++ b/helper/testhelpers/testhelpers.go @@ -9,7 +9,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "math/rand" "os" "strings" @@ -641,7 +641,7 @@ func SysMetricsReq(client *api.Client, cluster *vault.TestCluster, unauth bool) if err != nil { return nil, err } - bodyBytes, err := ioutil.ReadAll(resp.Response.Body) + bodyBytes, err := io.ReadAll(resp.Response.Body) if err != nil { return nil, err } diff --git a/http/plugin_test.go b/http/plugin_test.go index c2e084e43d..8a1b35d98d 100644 --- a/http/plugin_test.go +++ b/http/plugin_test.go @@ -6,7 +6,7 @@ package http import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "reflect" "sync" @@ -147,7 +147,7 @@ func TestPlugin_MockRawResponse(t *testing.T) { t.Fatal(err) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } diff --git a/http/sys_health_test.go b/http/sys_health_test.go index bd64ea8532..dcc3473b06 100644 --- a/http/sys_health_test.go +++ b/http/sys_health_test.go @@ -4,7 +4,7 @@ package http import ( - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -206,7 +206,7 @@ func TestSysHealth_head(t *testing.T) { t.Fatalf("HEAD %v expected code %d, got %d.", queryurl, tt.code, resp.StatusCode) } - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("err on %v: %s", queryurl, err) } diff --git a/physical/azure/azure.go b/physical/azure/azure.go index fc016e7fe9..e941af1611 100644 --- a/physical/azure/azure.go +++ b/physical/azure/azure.go @@ -7,7 +7,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "net/url" "os" "regexp" @@ -271,7 +271,7 @@ func (a *AzureBackend) Get(ctx context.Context, key string) (*physical.Entry, er reader := res.Body(azblob.RetryReaderOptions{}) defer reader.Close() - data, err := ioutil.ReadAll(reader) + data, err := io.ReadAll(reader) ent := &physical.Entry{ Key: key, diff --git a/physical/couchdb/couchdb.go b/physical/couchdb/couchdb.go index 0a1c379c6e..cbb32e5609 100644 --- a/physical/couchdb/couchdb.go +++ b/physical/couchdb/couchdb.go @@ -8,7 +8,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -114,7 +114,7 @@ func (m *couchDBClient) get(key string) (*physical.Entry, error) { } else if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("GET returned %q", resp.Status) } - bs, err := ioutil.ReadAll(resp.Body) + bs, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -143,7 +143,7 @@ func (m *couchDBClient) list(prefix string) ([]couchDBListItem, error) { } defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/physical/couchdb/couchdb_test.go b/physical/couchdb/couchdb_test.go index bc8f6b41df..0428d52d25 100644 --- a/physical/couchdb/couchdb_test.go +++ b/physical/couchdb/couchdb_test.go @@ -6,7 +6,7 @@ package couchdb import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -145,7 +145,7 @@ func setupCouchDB(ctx context.Context, host string, port int) (docker.ServiceCon } defer resp.Body.Close() if resp.StatusCode != http.StatusCreated { - bs, _ := ioutil.ReadAll(resp.Body) + bs, _ := io.ReadAll(resp.Body) return nil, fmt.Errorf("failed to create database: %s %s\n", resp.Status, string(bs)) } } @@ -164,7 +164,7 @@ func setupCouchDB(ctx context.Context, host string, port int) (docker.ServiceCon } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - bs, _ := ioutil.ReadAll(resp.Body) + bs, _ := io.ReadAll(resp.Body) return nil, fmt.Errorf("Failed to create admin user: %s %s\n", resp.Status, string(bs)) } } diff --git a/physical/gcs/gcs.go b/physical/gcs/gcs.go index eea7a515ac..51b1f926ff 100644 --- a/physical/gcs/gcs.go +++ b/physical/gcs/gcs.go @@ -8,7 +8,7 @@ import ( "crypto/md5" "errors" "fmt" - "io/ioutil" + "io" "os" "sort" "strconv" @@ -230,7 +230,7 @@ func (b *Backend) Get(ctx context.Context, key string) (retEntry *physical.Entry } }() - value, err := ioutil.ReadAll(r) + value, err := io.ReadAll(r) if err != nil { return nil, fmt.Errorf("failed to read value into a string: %w", err) } diff --git a/physical/oci/oci.go b/physical/oci/oci.go index c27e7e237c..628f310491 100644 --- a/physical/oci/oci.go +++ b/physical/oci/oci.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "sort" "strconv" @@ -231,7 +230,7 @@ func (o *Backend) Get(ctx context.Context, key string) (*physical.Entry, error) return nil, fmt.Errorf("failed to read Value: %w", err) } - body, err := ioutil.ReadAll(resp.Content) + body, err := io.ReadAll(resp.Content) if err != nil { metrics.IncrCounter(metricGetFailed, 1) return nil, fmt.Errorf("failed to decode Value into bytes: %w", err) diff --git a/physical/oci/oci_ha.go b/physical/oci/oci_ha.go index cf6b22e676..cc0e0edc62 100644 --- a/physical/oci/oci_ha.go +++ b/physical/oci/oci_ha.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "sync" "sync/atomic" @@ -399,7 +398,7 @@ func (l *Lock) get(ctx context.Context) (*LockRecord, string, error) { defer response.RawResponse.Body.Close() - body, err := ioutil.ReadAll(response.Content) + body, err := io.ReadAll(response.Content) if err != nil { metrics.IncrCounter(metricGetFailed, 1) l.backend.logger.Error("Error reading content", "err", err) diff --git a/sdk/helper/certutil/helpers.go b/sdk/helper/certutil/helpers.go index b7fc22db02..61bf7560f3 100644 --- a/sdk/helper/certutil/helpers.go +++ b/sdk/helper/certutil/helpers.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "net" "net/url" @@ -1315,7 +1314,7 @@ func signCertificate(data *CreationBundle, randReader io.Reader) (*ParsedCertBun } func NewCertPool(reader io.Reader) (*x509.CertPool, error) { - pemBlock, err := ioutil.ReadAll(reader) + pemBlock, err := io.ReadAll(reader) if err != nil { return nil, err } diff --git a/sdk/helper/docker/testhelpers.go b/sdk/helper/docker/testhelpers.go index f1fefd65cd..af1f3f72a6 100644 --- a/sdk/helper/docker/testhelpers.go +++ b/sdk/helper/docker/testhelpers.go @@ -12,7 +12,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/url" "os" "strconv" @@ -415,7 +414,7 @@ func (d *Runner) Start(ctx context.Context, addSuffix, forceLocalAddr bool) (*St } resp, _ := d.DockerAPI.ImageCreate(ctx, cfg.Image, opts) if resp != nil { - _, _ = ioutil.ReadAll(resp) + _, _ = io.ReadAll(resp) } for vol, mtpt := range d.RunOptions.VolumeNameToMountPoint { diff --git a/sdk/helper/ocsp/ocsp_test.go b/sdk/helper/ocsp/ocsp_test.go index 326a5b2336..1115766534 100644 --- a/sdk/helper/ocsp/ocsp_test.go +++ b/sdk/helper/ocsp/ocsp_test.go @@ -15,7 +15,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "net" "net/http" @@ -64,7 +63,7 @@ func TestOCSP(t *testing.T) { t.Fatalf("failed to GET contents. err: %v", err) } defer res.Body.Close() - _, err = ioutil.ReadAll(res.Body) + _, err = io.ReadAll(res.Body) if err != nil { t.Fatalf("failed to read content body for %v", tgt) } @@ -113,7 +112,7 @@ func TestMultiOCSP(t *testing.T) { t.Fatalf("failed to GET contents. err: %v", err) } defer res.Body.Close() - _, err = ioutil.ReadAll(res.Body) + _, err = io.ReadAll(res.Body) if err != nil { t.Fatalf("failed to read content body for %v", tgt) } diff --git a/vault/external_tests/api/feature_flag_ext_test.go b/vault/external_tests/api/feature_flag_ext_test.go index 4f8cc8138e..d5d45123ea 100644 --- a/vault/external_tests/api/feature_flag_ext_test.go +++ b/vault/external_tests/api/feature_flag_ext_test.go @@ -5,7 +5,7 @@ package api import ( "encoding/json" - "io/ioutil" + "io" "net/http" "os" "testing" @@ -54,7 +54,7 @@ func TestFeatureFlags(t *testing.T) { } defer resp.Body.Close() - httpRespBody, err := ioutil.ReadAll(resp.Body) + httpRespBody, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } diff --git a/vault/external_tests/metrics/core_metrics_int_test.go b/vault/external_tests/metrics/core_metrics_int_test.go index 7a9005ed9b..fe8323299c 100644 --- a/vault/external_tests/metrics/core_metrics_int_test.go +++ b/vault/external_tests/metrics/core_metrics_int_test.go @@ -7,7 +7,7 @@ import ( "context" "encoding/json" "errors" - "io/ioutil" + "io" "testing" "time" @@ -139,7 +139,7 @@ func TestLeaderReElectionMetrics(t *testing.T) { if err != nil { t.Fatal(err) } - bodyBytes, err := ioutil.ReadAll(respo.Response.Body) + bodyBytes, err := io.ReadAll(respo.Response.Body) if err != nil { t.Fatal(err) } @@ -183,7 +183,7 @@ func TestLeaderReElectionMetrics(t *testing.T) { if err != nil { t.Fatal(err) } - bodyBytes, err = ioutil.ReadAll(respo.Response.Body) + bodyBytes, err = io.ReadAll(respo.Response.Body) if err != nil { t.Fatal(err) } diff --git a/vault/external_tests/pprof/pprof_test.go b/vault/external_tests/pprof/pprof_test.go index 633d853210..dff9203012 100644 --- a/vault/external_tests/pprof/pprof_test.go +++ b/vault/external_tests/pprof/pprof_test.go @@ -5,7 +5,7 @@ package pprof import ( "encoding/json" - "io/ioutil" + "io" "net/http" "strconv" "strings" @@ -64,7 +64,7 @@ func TestSysPprof_MaxRequestDuration(t *testing.T) { } defer resp.Body.Close() - httpRespBody, err := ioutil.ReadAll(resp.Body) + httpRespBody, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } diff --git a/vault/external_tests/raft/raft_test.go b/vault/external_tests/raft/raft_test.go index 15c6e28072..2129bb4df2 100644 --- a/vault/external_tests/raft/raft_test.go +++ b/vault/external_tests/raft/raft_test.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strings" "sync" @@ -517,7 +516,7 @@ func TestRaft_SnapshotAPI_MidstreamFailure(t *testing.T) { var readErr error go func() { - snap, readErr = ioutil.ReadAll(r) + snap, readErr = io.ReadAll(r) wg.Done() }() @@ -634,7 +633,7 @@ func TestRaft_SnapshotAPI_RekeyRotate_Backward(t *testing.T) { } defer resp.Body.Close() - snap, err := ioutil.ReadAll(resp.Body) + snap, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } @@ -837,7 +836,7 @@ func TestRaft_SnapshotAPI_RekeyRotate_Forward(t *testing.T) { t.Fatal(err) } - snap, err := ioutil.ReadAll(resp.Body) + snap, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { t.Fatal(err) @@ -894,7 +893,7 @@ func TestRaft_SnapshotAPI_RekeyRotate_Forward(t *testing.T) { t.Fatal(err) } - snap2, err := ioutil.ReadAll(resp.Body) + snap2, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { t.Fatal(err) @@ -1024,7 +1023,7 @@ func TestRaft_SnapshotAPI_DifferentCluster(t *testing.T) { t.Fatal(err) } - snap, err := ioutil.ReadAll(resp.Body) + snap, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { t.Fatal(err)