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 (
"fmt"
"io/ioutil"
"net"
"os"
"time"
"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) {
key, err := ioutil.ReadFile(keyFile)
key, err := os.ReadFile(keyFile)
if err != nil {
return nil, err
}

View File

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

View File

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

View File

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

View File

@@ -5,7 +5,6 @@ package e2e
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -39,7 +38,7 @@ func init() {
flag.StringVar(&binDir, "bin", "../bin", "directory with compiled binaries")
_ = os.MkdirAll(tmpDir, 0755)
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")
tidFile = filepath.Join(tmpDir, "win-sshproxy.tid")
}
@@ -59,7 +58,7 @@ func startProxy() error {
}
func readTid() (uint32, uint32, error) {
contents, err := ioutil.ReadFile(tidFile)
contents, err := os.ReadFile(tidFile)
if err != nil {
return 0, 0, err
}

View File

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

View File

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

View File

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