From 8724c5fcf10bdd8546a5815aaa14b54c91111220 Mon Sep 17 00:00:00 2001 From: John Wood Date: Tue, 9 Aug 2022 12:46:30 -0700 Subject: [PATCH] Remove ioutil --- cmd/init.go | 3 +-- cmd/request_cert.go | 3 +-- cmd/revoke_test.go | 3 +-- cmd/util.go | 11 +++++------ depot/depot.go | 5 ++--- tests/workflow_test.go | 3 +-- 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 3343884..1fec385 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -19,7 +19,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "strings" @@ -153,7 +152,7 @@ func initAction(c *cli.Context) { var key *pkix.Key switch { case c.IsSet("key"): - keyBytes, err := ioutil.ReadFile(c.String("key")) + keyBytes, err := os.ReadFile(c.String("key")) if err != nil { fmt.Fprintln(os.Stderr, "Read Key error:", err) os.Exit(1) diff --git a/cmd/request_cert.go b/cmd/request_cert.go index 5946012..5534cfc 100644 --- a/cmd/request_cert.go +++ b/cmd/request_cert.go @@ -19,7 +19,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "regexp" "strings" @@ -163,7 +162,7 @@ func newCertAction(c *cli.Context) { keyFilepath := fileName(c, "key", depotDir, formattedName, "key") switch { case c.IsSet("key") && fileExists(c.String("key")): - keyBytes, err := ioutil.ReadFile(c.String("key")) + keyBytes, err := os.ReadFile(c.String("key")) if err != nil { fmt.Fprintln(os.Stderr, "Read Key error:", err) os.Exit(1) diff --git a/cmd/revoke_test.go b/cmd/revoke_test.go index e9612c0..983dbd5 100644 --- a/cmd/revoke_test.go +++ b/cmd/revoke_test.go @@ -3,7 +3,6 @@ package cmd import ( "crypto/x509" "flag" - "io/ioutil" "os" "testing" "time" @@ -19,7 +18,7 @@ const ( ) func TestRevokeCmd(t *testing.T) { - tmp, err := ioutil.TempDir("", "certstrap-revoke") + tmp, err := os.MkdirTemp("", "certstrap-revoke") if err != nil { t.Fatalf("could not create tmp dir: %v", err) } diff --git a/cmd/util.go b/cmd/util.go index 0c91c45..8679bd1 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -21,7 +21,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "os" "github.com/howeyc/gopass" @@ -84,7 +83,7 @@ func putCertificate(c *cli.Context, d *depot.FileDepot, name string, crt *pkix.C if err != nil { return err } - return ioutil.WriteFile(c.String("cert"), bytes, depot.LeafPerm) + return os.WriteFile(c.String("cert"), bytes, depot.LeafPerm) } return depot.PutCertificate(d, name, crt) } @@ -95,14 +94,14 @@ func putCertificateSigningRequest(c *cli.Context, d *depot.FileDepot, name strin if err != nil { return err } - return ioutil.WriteFile(c.String("csr"), bytes, depot.LeafPerm) + return os.WriteFile(c.String("csr"), bytes, depot.LeafPerm) } return depot.PutCertificateSigningRequest(d, name, csr) } func getCertificateSigningRequest(c *cli.Context, d *depot.FileDepot, name string) (*pkix.CertificateSigningRequest, error) { if c.IsSet("csr") { - bytes, err := ioutil.ReadFile(c.String("csr")) + bytes, err := os.ReadFile(c.String("csr")) if err != nil { return nil, err } @@ -121,7 +120,7 @@ func putEncryptedPrivateKey(c *cli.Context, d *depot.FileDepot, name string, key if err != nil { return err } - return ioutil.WriteFile(c.String("key"), bytes, depot.BranchPerm) + return os.WriteFile(c.String("key"), bytes, depot.BranchPerm) } return depot.PutEncryptedPrivateKey(d, name, key, passphrase) } @@ -136,7 +135,7 @@ func putPrivateKey(c *cli.Context, d *depot.FileDepot, name string, key *pkix.Ke if err != nil { return err } - return ioutil.WriteFile(c.String("key"), bytes, depot.BranchPerm) + return os.WriteFile(c.String("key"), bytes, depot.BranchPerm) } return depot.PutPrivateKey(d, name, key) } diff --git a/depot/depot.go b/depot/depot.go index 0b0099a..b8c2ced 100644 --- a/depot/depot.go +++ b/depot/depot.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io/fs" - "io/ioutil" "os" "path/filepath" ) @@ -132,7 +131,7 @@ func (d *FileDepot) Get(tag *Tag) ([]byte, error) { if err := d.check(tag); err != nil { return nil, err } - return ioutil.ReadFile(d.path(tag.name)) + return os.ReadFile(d.path(tag.name)) } // Delete removes the file specified by the tag @@ -181,6 +180,6 @@ func (d *FileDepot) GetFile(tag *Tag) (*File, error) { if err != nil { return nil, err } - b, err := ioutil.ReadFile(d.path(tag.name)) + b, err := os.ReadFile(d.path(tag.name)) return &File{fi, b}, err } diff --git a/tests/workflow_test.go b/tests/workflow_test.go index 3b7e081..1e64be3 100644 --- a/tests/workflow_test.go +++ b/tests/workflow_test.go @@ -22,7 +22,6 @@ package tests import ( "crypto/x509" "encoding/pem" - "io/ioutil" "os" "path" "strings" @@ -100,7 +99,7 @@ func TestWorkflow(t *testing.T) { t.Fatalf("Received incorrect create: %v", stdout) } - fcontents, err := ioutil.ReadFile(path.Join(depotDir, strings.Join([]string{hostname, ".crt"}, ""))) + fcontents, err := os.ReadFile(path.Join(depotDir, strings.Join([]string{hostname, ".crt"}, ""))) if err != nil { t.Fatalf("Reading cert failed: %v", err) }