Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <[email protected]>
  • Loading branch information
testwill committed Sep 4, 2023
1 parent 1b1d69e commit e29a178
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions agent-inject/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package agent_inject
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -93,7 +93,7 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) {
var body []byte
if r.Body != nil {
var err error
if body, err = ioutil.ReadAll(r.Body); err != nil {
if body, err = io.ReadAll(r.Body); err != nil {
msg := fmt.Sprintf("error reading request body: %s", err)
http.Error(w, msg, http.StatusBadRequest)
h.Log.Error("error on request", "Error", msg, "Code", http.StatusBadRequest)
Expand Down
8 changes: 4 additions & 4 deletions helper/cert/source_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"time"

"github.com/radovskyb/watcher"
Expand Down Expand Up @@ -92,19 +92,19 @@ func (s *DiskSource) Certificate(ctx context.Context, last *Bundle) (Bundle, err
}

func (s *DiskSource) loadCerts() (Bundle, error) {
certPEMBlock, err := ioutil.ReadFile(s.CertPath)
certPEMBlock, err := os.ReadFile(s.CertPath)
if err != nil {
return Bundle{}, err
}

keyPEMBlock, err := ioutil.ReadFile(s.KeyPath)
keyPEMBlock, err := os.ReadFile(s.KeyPath)
if err != nil {
return Bundle{}, err
}

var caPEMBlock []byte
if s.CAPath != "" {
caPEMBlock, err = ioutil.ReadFile(s.CAPath)
caPEMBlock, err = os.ReadFile(s.CAPath)
if err != nil {
return Bundle{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions helper/cert/source_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cert

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -19,7 +18,7 @@ func TestGenDisk_noExist(t *testing.T) {
t.Parallel()
require := require.New(t)

td, err := ioutil.TempDir("", "consul")
td, err := os.MkdirTemp("", "consul")
require.NoError(err)
defer os.RemoveAll(td)

Expand Down
9 changes: 4 additions & 5 deletions helper/cert/source_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cert

import (
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -99,15 +98,15 @@ func testBundle(t *testing.T) *Bundle {
func testBundleDir(t *testing.T, bundle *Bundle, dir string) string {
if dir == "" {
// Create a temporary directory for storing the certs
td, err := ioutil.TempDir("", "consul")
td, err := os.MkdirTemp("", "consul")
require.NoError(t, err)
dir = td
}

// Write the cert
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "ca.pem"), bundle.CACert, 0644))
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "leaf.pem"), bundle.Cert, 0644))
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "leaf.key.pem"), bundle.Key, 0644))
require.NoError(t, os.WriteFile(filepath.Join(dir, "ca.pem"), bundle.CACert, 0644))
require.NoError(t, os.WriteFile(filepath.Join(dir, "leaf.pem"), bundle.Cert, 0644))
require.NoError(t, os.WriteFile(filepath.Join(dir, "leaf.key.pem"), bundle.Key, 0644))

return dir
}
Expand Down

0 comments on commit e29a178

Please sign in to comment.