internal/communicator: deprecate io/ioutil (#332)

Signed-off-by: Lars Lehtonen <lars.lehtonen@gmail.com>
This commit is contained in:
Lars Lehtonen 2023-09-07 07:50:30 -07:00 committed by GitHub
parent 3d7fda123a
commit 9d595db5af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 12 deletions

View File

@ -10,7 +10,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"math/rand" "math/rand"
"net" "net"
@ -654,7 +653,7 @@ func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader, size
if size == 0 { if size == 0 {
// Create a temporary file where we can copy the contents of the src // Create a temporary file where we can copy the contents of the src
// so that we can determine the length, since SCP is length-prefixed. // so that we can determine the length, since SCP is length-prefixed.
tf, err := ioutil.TempFile("", "terraform-upload") tf, err := os.CreateTemp("", "terraform-upload")
if err != nil { if err != nil {
return fmt.Errorf("Error creating temporary file for upload: %s", err) return fmt.Errorf("Error creating temporary file for upload: %s", err)
} }

View File

@ -12,7 +12,6 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net" "net"
"os" "os"
@ -607,7 +606,7 @@ func TestAccUploadFile(t *testing.T) {
t.Fatalf("error uploading file: %s", err) t.Fatalf("error uploading file: %s", err)
} }
data, err := ioutil.ReadFile(tmpFile) data, err := os.ReadFile(tmpFile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -641,7 +640,7 @@ func TestAccHugeUploadFile(t *testing.T) {
size := int64(1 << 32) size := int64(1 << 32)
source := io.LimitReader(rand.New(rand.NewSource(0)), size) source := io.LimitReader(rand.New(rand.NewSource(0)), size)
dest, err := ioutil.TempFile("", "communicator") dest, err := os.CreateTemp("", "communicator")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -8,7 +8,6 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"os" "os"
@ -334,7 +333,7 @@ func buildSSHClientConfig(opts sshClientConfigOpts) (*ssh.ClientConfig, error) {
// generally wants to handle config data in-memory. Rather than making // generally wants to handle config data in-memory. Rather than making
// the known_hosts file an exception, write out the data to a temporary // the known_hosts file an exception, write out the data to a temporary
// file to create the HostKeyCallback. // file to create the HostKeyCallback.
tf, err := ioutil.TempFile("", "tf-known_hosts") tf, err := os.CreateTemp("", "tf-known_hosts")
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create temp known_hosts file: %s", err) return nil, fmt.Errorf("failed to create temp known_hosts file: %s", err)
} }
@ -525,7 +524,7 @@ func idKeyData(id string) [][]byte {
} }
for _, p := range paths { for _, p := range paths {
d, err := ioutil.ReadFile(p) d, err := os.ReadFile(p)
if err != nil { if err != nil {
log.Printf("[DEBUG] error reading %q: %s", p, err) log.Printf("[DEBUG] error reading %q: %s", p, err)
continue continue

View File

@ -9,7 +9,6 @@ import (
"crypto/rsa" "crypto/rsa"
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -40,7 +39,7 @@ func TestFindKeyData(t *testing.T) {
if err := os.Rename(id+".pub", "saved.pub"); err != nil { if err := os.Rename(id+".pub", "saved.pub"); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := ioutil.WriteFile(id+".pub", []byte("not a public key"), 0600); err != nil { if err := os.WriteFile(id+".pub", []byte("not a public key"), 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -55,7 +54,7 @@ func TestFindKeyData(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err := ioutil.WriteFile(id, []byte("encrypted private key"), 0600); err != nil { if err := os.WriteFile(id, []byte("encrypted private key"), 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -95,7 +94,7 @@ func generateSSHKey(t *testing.T, idFile string) ssh.PublicKey {
t.Fatal(err) t.Fatal(err)
} }
err = ioutil.WriteFile(idFile+".pub", ssh.MarshalAuthorizedKey(pub), 0600) err = os.WriteFile(idFile+".pub", ssh.MarshalAuthorizedKey(pub), 0600)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }