diff --git a/agent-inject/handler.go b/agent-inject/handler.go index 12dde6b3..d3588504 100644 --- a/agent-inject/handler.go +++ b/agent-inject/handler.go @@ -6,7 +6,7 @@ package agent_inject import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -94,7 +94,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) diff --git a/helper/cert/source_disk.go b/helper/cert/source_disk.go index 4b7d2e4b..41eea493 100644 --- a/helper/cert/source_disk.go +++ b/helper/cert/source_disk.go @@ -7,7 +7,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "os" "time" "github.com/radovskyb/watcher" @@ -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 } diff --git a/helper/cert/source_disk_test.go b/helper/cert/source_disk_test.go index a2de05a4..05ca52dd 100644 --- a/helper/cert/source_disk_test.go +++ b/helper/cert/source_disk_test.go @@ -5,7 +5,6 @@ package cert import ( "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -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) diff --git a/helper/cert/source_gen_test.go b/helper/cert/source_gen_test.go index bb37ba91..c8a3d7cd 100644 --- a/helper/cert/source_gen_test.go +++ b/helper/cert/source_gen_test.go @@ -5,7 +5,6 @@ package cert import ( "context" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -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 }