mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
chore: fix deprecated ioutil readall (#27823)
Signed-off-by: idnandre <andre@idntimes.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
2
command/agentproxyshared/cache/proxy.go
vendored
2
command/agentproxyshared/cache/proxy.go
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user