Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #516

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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