From 1304182959775405fa023a91658b665f14a63e26 Mon Sep 17 00:00:00 2001 From: Joakim Bygdell Date: Wed, 2 Nov 2022 13:02:25 +0100 Subject: [PATCH] io/ioutil is deprecated --- bucket.go | 4 ++-- config.go | 10 +++++----- healthchecks_test.go | 4 ++-- helper/helper.go | 5 ++--- proxy.go | 6 +++--- userauth.go | 5 ++--- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/bucket.go b/bucket.go index 13cf1b5..e973232 100644 --- a/bucket.go +++ b/bucket.go @@ -3,8 +3,8 @@ package main import ( "crypto/tls" "crypto/x509" - "io/ioutil" "net/http" + "os" "reflect" "strings" @@ -66,7 +66,7 @@ func transportConfigS3(config S3Config) http.RoundTripper { cfg.RootCAs = systemCAs if config.cacert != "" { - cacert, e := ioutil.ReadFile(config.cacert) // #nosec this file comes from our config + cacert, e := os.ReadFile(config.cacert) // #nosec this file comes from our config if e != nil { log.Fatalf("failed to append %q to RootCAs: %v", cacert, e) } diff --git a/config.go b/config.go index 020703a..7ae40f7 100644 --- a/config.go +++ b/config.go @@ -4,7 +4,7 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" + "os" "path" "reflect" "strings" @@ -253,7 +253,7 @@ func TLSConfigBroker(c *Config) (*tls.Config, error) { continue } - cacert, e := ioutil.ReadFile(cacert) // #nosec this file comes from our configuration + cacert, e := os.ReadFile(cacert) // #nosec this file comes from our configuration if e != nil { return nil, fmt.Errorf("failed to append %q to RootCAs: %v", cacert, e) } @@ -268,11 +268,11 @@ func TLSConfigBroker(c *Config) (*tls.Config, error) { } if c.Broker.verifyPeer { - cert, e := ioutil.ReadFile(c.Broker.clientCert) + cert, e := os.ReadFile(c.Broker.clientCert) if e != nil { return nil, fmt.Errorf("failed to read client cert %q, reason: %v", c.Broker.clientKey, e) } - key, e := ioutil.ReadFile(c.Broker.clientKey) + key, e := os.ReadFile(c.Broker.clientKey) if e != nil { return nil, fmt.Errorf("failed to read client key %q, reason: %v", c.Broker.clientKey, e) } @@ -302,7 +302,7 @@ func TLSConfigProxy(c *Config) (*tls.Config, error) { cfg.RootCAs = systemCAs if c.S3.cacert != "" { - cacert, e := ioutil.ReadFile(c.S3.cacert) // #nosec this file comes from our configuration + cacert, e := os.ReadFile(c.S3.cacert) // #nosec this file comes from our configuration if e != nil { return nil, fmt.Errorf("failed to append %q to RootCAs: %v", cacert, e) } diff --git a/healthchecks_test.go b/healthchecks_test.go index 4c028cd..554ada2 100644 --- a/healthchecks_test.go +++ b/healthchecks_test.go @@ -2,7 +2,7 @@ package main import ( "crypto/tls" - "io/ioutil" + "io" "log" "net" "net/http" @@ -47,7 +47,7 @@ func TestHealthchecks(t *testing.T) { if err != nil { log.Fatal(err) } - _, err = ioutil.ReadAll(res.Body) + _, err = io.ReadAll(res.Body) res.Body.Close() if err != nil { log.Fatal(err) diff --git a/helper/helper.go b/helper/helper.go index e202eed..cef2c5e 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -7,7 +7,6 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" - "io/ioutil" "os" "path/filepath" "time" @@ -101,7 +100,7 @@ func MakeFolder(path string) (string, string, error) { // ParsePrivateRSAKey reads and parses the RSA private key func ParsePrivateRSAKey(path, keyName string) (*rsa.PrivateKey, error) { keyPath := path + keyName - prKey, err := ioutil.ReadFile(filepath.Clean(keyPath)) + prKey, err := os.ReadFile(filepath.Clean(keyPath)) if err != nil { return nil, err } @@ -215,7 +214,7 @@ func CreateHSToken(key []byte, headerAlg, headerType string, tokenClaims map[str // ParsePrivateECKey reads and parses the EC private key func ParsePrivateECKey(path, keyName string) (*ecdsa.PrivateKey, error) { keyPath := path + keyName - prKey, err := ioutil.ReadFile(filepath.Clean(keyPath)) + prKey, err := os.ReadFile(filepath.Clean(keyPath)) if err != nil { return nil, err } diff --git a/proxy.go b/proxy.go index ef72e8b..e82ad74 100644 --- a/proxy.go +++ b/proxy.go @@ -6,8 +6,8 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "net/http" + "os" "regexp" "strconv" "strings" @@ -141,7 +141,7 @@ func (p *Proxy) allowedResponse(w http.ResponseWriter, r *http.Request) { // Read any remaining data in the connection and // Close so connection can be reused. - _, _ = ioutil.ReadAll(s3response.Body) + _, _ = io.ReadAll(s3response.Body) _ = s3response.Body.Close() } @@ -338,7 +338,7 @@ func (p *Proxy) newSession() (*session.Session, error) { var mySession *session.Session var err error if p.s3.cacert != "" { - cert, _ := ioutil.ReadFile(p.s3.cacert) + cert, _ := os.ReadFile(p.s3.cacert) cacert := bytes.NewReader(cert) mySession, err = session.NewSessionWithOptions(session.Options{ CustomCABundle: cacert, diff --git a/userauth.go b/userauth.go index 149c53b..3bc4bc6 100644 --- a/userauth.go +++ b/userauth.go @@ -8,7 +8,6 @@ import ( "encoding/pem" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -242,7 +241,7 @@ func (u *ValidateFromToken) getjwtkey(jwtpubkeypath string) error { } if info.Mode().IsRegular() { log.Debug("Reading file: ", filepath.Join(filepath.Clean(jwtpubkeypath), info.Name())) - keyData, err := ioutil.ReadFile(filepath.Join(filepath.Clean(jwtpubkeypath), info.Name())) + keyData, err := os.ReadFile(filepath.Join(filepath.Clean(jwtpubkeypath), info.Name())) if err != nil { return fmt.Errorf("token file error: %v", err) } @@ -293,7 +292,7 @@ func (u *ValidateFromToken) getjwtpubkey(jwtpubkeyurl string) error { if err != nil { return fmt.Errorf("failed to get JWK (%v)", err) } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { return fmt.Errorf("failed to read key response (%v)", err) }