ioutil: Switch away from deprecated package

ioutil has been deprecated since golang 1.16.
This commit uses the replacement methods from the os or io packages.
This should fix some golangci-lint CI failures.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Christophe Fergeau
2022-09-01 14:36:34 +02:00
committed by Anjan Nath
parent 89efd2bdb9
commit 8c72b59df3
8 changed files with 15 additions and 19 deletions

View File

@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os"
"time" "time"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
@@ -27,7 +27,7 @@ func newClient(conn net.Conn, user string, key string) (*client, error) {
} }
func newConfig(user string, keyFile string) (*ssh.ClientConfig, error) { func newConfig(user string, keyFile string) (*ssh.ClientConfig, error) {
key, err := ioutil.ReadFile(keyFile) key, err := os.ReadFile(keyFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
@@ -52,7 +52,7 @@ func (c *Client) Expose(req *types.ExposeRequest) error {
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
err, readErr := ioutil.ReadAll(res.Body) err, readErr := io.ReadAll(res.Body)
if readErr != nil { if readErr != nil {
return fmt.Errorf("error while reading error message: %v", readErr) return fmt.Errorf("error while reading error message: %v", readErr)
} }
@@ -72,7 +72,7 @@ func (c *Client) Unexpose(req *types.UnexposeRequest) error {
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
err, readErr := ioutil.ReadAll(res.Body) err, readErr := io.ReadAll(res.Body)
if readErr != nil { if readErr != nil {
return fmt.Errorf("error while reading error message: %v", readErr) return fmt.Errorf("error while reading error message: %v", readErr)
} }

View File

@@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"context" "context"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"net/url" "net/url"
"os" "os"
@@ -39,7 +38,7 @@ type Bastion struct {
type ConnectCallback func(ctx context.Context, bastion *Bastion) (net.Conn, error) type ConnectCallback func(ctx context.Context, bastion *Bastion) (net.Conn, error)
func PublicKey(path string, passphrase []byte) (ssh.Signer, error) { func PublicKey(path string, passphrase []byte) (ssh.Signer, error) {
key, err := ioutil.ReadFile(path) key, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -5,7 +5,6 @@ package e2e
import ( import (
"context" "context"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@@ -80,10 +79,10 @@ var _ = Describe("connectivity", func() {
reader, err := cmd.StdoutPipe() reader, err := cmd.StdoutPipe()
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
cmd.Start() cmd.Start()
output, err := ioutil.ReadAll(reader) output, err := io.ReadAll(reader)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
cmd.Wait() cmd.Wait()
Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue()) Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
Expect(strings.Contains(string(output),`[debug] test: Socket forward established`)).Should(BeTrue()) Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
}) })
}) })

View File

@@ -5,7 +5,6 @@ package e2e
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -39,7 +38,7 @@ func init() {
flag.StringVar(&binDir, "bin", "../bin", "directory with compiled binaries") flag.StringVar(&binDir, "bin", "../bin", "directory with compiled binaries")
_ = os.MkdirAll(tmpDir, 0755) _ = os.MkdirAll(tmpDir, 0755)
keyFile = filepath.Join(tmpDir, "id.key") keyFile = filepath.Join(tmpDir, "id.key")
_ = ioutil.WriteFile(keyFile, []byte(fakeHostKey), 0600) _ = os.WriteFile(keyFile, []byte(fakeHostKey), 0600)
winSshProxy = filepath.Join(binDir, "win-sshproxy.exe") winSshProxy = filepath.Join(binDir, "win-sshproxy.exe")
tidFile = filepath.Join(tmpDir, "win-sshproxy.tid") tidFile = filepath.Join(tmpDir, "win-sshproxy.tid")
} }
@@ -59,7 +58,7 @@ func startProxy() error {
} }
func readTid() (uint32, uint32, error) { func readTid() (uint32, uint32, error) {
contents, err := ioutil.ReadFile(tidFile) contents, err := os.ReadFile(tidFile)
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err
} }

View File

@@ -3,7 +3,7 @@ package e2e
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"github.com/coreos/stream-metadata-go/fedoracoreos" "github.com/coreos/stream-metadata-go/fedoracoreos"
@@ -19,7 +19,7 @@ func getFCOSDownload() (*fcosDownloadInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -2,8 +2,8 @@ package e2e
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"net/url" "net/url"
"os"
) )
var ( var (
@@ -142,7 +142,7 @@ ExecStart=/usr/bin/sleep infinity
} }
// #nosec // #nosec
return ioutil.WriteFile(ignitionFile, contents, 0644) return os.WriteFile(ignitionFile, contents, 0644)
} }
func dir(path string) Directory { func dir(path string) Directory {

View File

@@ -4,7 +4,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -176,7 +175,7 @@ func createSSHKeys() (string, error) {
} }
func readPublicKey() (string, error) { func readPublicKey() (string, error) {
publicKey, err := ioutil.ReadFile(publicKeyFile) publicKey, err := os.ReadFile(publicKeyFile)
if err != nil { if err != nil {
return "", nil return "", nil
} }