all: replace deprecated ioutil references

This PR removes calls to ioutil library and replaces them
with their new locations in the io and os packages.

Fixes #9034
Updates #5210

Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
This commit is contained in:
Marwan Sulaiman 2023-08-23 16:42:44 +01:00 committed by Marwan Sulaiman
parent 1b8a538953
commit 9c07f4f512
5 changed files with 7 additions and 12 deletions

View File

@ -19,7 +19,6 @@
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -149,7 +148,7 @@ func getHostKeys(dir string) (ret []ssh.Signer, err error) {
func hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) { func hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) {
path := filepath.Join(keyDir, "ssh_host_"+typ+"_key") path := filepath.Join(keyDir, "ssh_host_"+typ+"_key")
v, err := ioutil.ReadFile(path) v, err := os.ReadFile(path)
if err == nil { if err == nil {
return v, nil return v, nil
} }

View File

@ -13,7 +13,6 @@
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
@ -1708,7 +1707,7 @@ func (h *Handler) serveTKADisable(w http.ResponseWriter, r *http.Request) {
} }
body := io.LimitReader(r.Body, 1024*1024) body := io.LimitReader(r.Body, 1024*1024)
secret, err := ioutil.ReadAll(body) secret, err := io.ReadAll(body)
if err != nil { if err != nil {
http.Error(w, "reading secret", 400) http.Error(w, "reading secret", 400)
return return
@ -1781,7 +1780,7 @@ func (h *Handler) serveTKAAffectedSigs(w http.ResponseWriter, r *http.Request) {
http.Error(w, "use POST", http.StatusMethodNotAllowed) http.Error(w, "use POST", http.StatusMethodNotAllowed)
return return
} }
keyID, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, 2048)) keyID, err := io.ReadAll(http.MaxBytesReader(w, r.Body, 2048))
if err != nil { if err != nil {
http.Error(w, "reading body", http.StatusBadRequest) http.Error(w, "reading body", http.StatusBadRequest)
return return
@ -1850,7 +1849,7 @@ func (h *Handler) serveTKACosignRecoveryAUM(w http.ResponseWriter, r *http.Reque
} }
body := io.LimitReader(r.Body, 1024*1024) body := io.LimitReader(r.Body, 1024*1024)
aumBytes, err := ioutil.ReadAll(body) aumBytes, err := io.ReadAll(body)
if err != nil { if err != nil {
http.Error(w, "reading AUM", http.StatusBadRequest) http.Error(w, "reading AUM", http.StatusBadRequest)
return return
@ -1881,7 +1880,7 @@ func (h *Handler) serveTKASubmitRecoveryAUM(w http.ResponseWriter, r *http.Reque
} }
body := io.LimitReader(r.Body, 1024*1024) body := io.LimitReader(r.Body, 1024*1024)
aumBytes, err := ioutil.ReadAll(body) aumBytes, err := io.ReadAll(body)
if err != nil { if err != nil {
http.Error(w, "reading AUM", http.StatusBadRequest) http.Error(w, "reading AUM", http.StatusBadRequest)
return return

View File

@ -15,7 +15,6 @@
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -562,7 +561,7 @@ func TestSSHRecordingNonInteractive(t *testing.T) {
recordingServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { recordingServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer cancel() defer cancel()
var err error var err error
recording, err = ioutil.ReadAll(r.Body) recording, err = io.ReadAll(r.Body)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return

View File

@ -16,7 +16,6 @@
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"net" "net"
"net/http" "net/http"
@ -523,7 +522,7 @@ func TestFunnel(t *testing.T) {
t.Errorf("unexpected status code: %v", resp.StatusCode) t.Errorf("unexpected status code: %v", resp.StatusCode)
return return
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -17,7 +17,6 @@
_ "fmt" _ "fmt"
_ "io" _ "io"
_ "io/fs" _ "io/fs"
_ "io/ioutil"
_ "log" _ "log"
_ "math" _ "math"
_ "net" _ "net"