Skip to content

Commit

Permalink
Remove ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
jdtw committed Aug 9, 2022
1 parent 057e87d commit 8724c5f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
3 changes: 1 addition & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cmd/request_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cmd/revoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"crypto/x509"
"flag"
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -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)
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/howeyc/gopass"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions depot/depot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions tests/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package tests
import (
"crypto/x509"
"encoding/pem"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8724c5f

Please sign in to comment.