refactor: move from io/ioutil to io and os package

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2021-09-17 14:12:39 +08:00
parent 40b426b276
commit f0186ff265
No known key found for this signature in database
GPG key ID: DAEBBD2E34C111E6
25 changed files with 69 additions and 72 deletions

View file

@ -6,7 +6,6 @@ import (
"crypto/x509" "crypto/x509"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -76,7 +75,7 @@ func commandServe() *cobra.Command {
func runServe(options serveOptions) error { func runServe(options serveOptions) error {
configFile := options.config configFile := options.config
configData, err := ioutil.ReadFile(configFile) configData, err := os.ReadFile(configFile)
if err != nil { if err != nil {
return fmt.Errorf("failed to read config file %s: %v", configFile, err) return fmt.Errorf("failed to read config file %s: %v", configFile, err)
} }
@ -148,7 +147,7 @@ func runServe(options serveOptions) error {
if c.GRPC.TLSClientCA != "" { if c.GRPC.TLSClientCA != "" {
// Parse certificates from client CA file to a new CertPool. // Parse certificates from client CA file to a new CertPool.
cPool := x509.NewCertPool() cPool := x509.NewCertPool()
clientCert, err := ioutil.ReadFile(c.GRPC.TLSClientCA) clientCert, err := os.ReadFile(c.GRPC.TLSClientCA)
if err != nil { if err != nil {
return fmt.Errorf("invalid config: reading from client CA file: %v", err) return fmt.Errorf("invalid config: reading from client CA file: %v", err)
} }

View file

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@ -432,7 +431,7 @@ func (c *crowdConnector) crowdUserManagementRequest(ctx context.Context, method
// validateCrowdResponse validates unique not JSON responses from API // validateCrowdResponse validates unique not JSON responses from API
func (c *crowdConnector) validateCrowdResponse(resp *http.Response) ([]byte, error) { func (c *crowdConnector) validateCrowdResponse(resp *http.Response) ([]byte, error) {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("crowd: read user body: %v", err) return nil, fmt.Errorf("crowd: read user body: %v", err)
} }

View file

@ -6,7 +6,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"reflect" "reflect"
@ -152,7 +152,7 @@ func newTestCrowdConnector(baseURL string) crowdConnector {
connector := crowdConnector{} connector := crowdConnector{}
connector.BaseURL = baseURL connector.BaseURL = baseURL
connector.logger = &logrus.Logger{ connector.logger = &logrus.Logger{
Out: ioutil.Discard, Out: io.Discard,
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
} }

View file

@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"sync" "sync"
"time" "time"
@ -453,7 +453,7 @@ func get(ctx context.Context, client *http.Client, apiURL string, v interface{})
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return fmt.Errorf("bitbucket: read body: %s: %v", resp.Status, err) return fmt.Errorf("bitbucket: read body: %s: %v", resp.Status, err)
} }

View file

@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"sync" "sync"
@ -252,7 +252,7 @@ func (c *giteaConnector) user(ctx context.Context, client *http.Client) (giteaUs
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return u, fmt.Errorf("gitea: read body: %v", err) return u, fmt.Errorf("gitea: read body: %v", err)
} }

View file

@ -8,9 +8,10 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"os"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -210,7 +211,7 @@ func (e *oauth2Error) Error() string {
// newHTTPClient returns a new HTTP client that trusts the custom declared rootCA cert. // newHTTPClient returns a new HTTP client that trusts the custom declared rootCA cert.
func newHTTPClient(rootCA string) (*http.Client, error) { func newHTTPClient(rootCA string) (*http.Client, error) {
tlsConfig := tls.Config{RootCAs: x509.NewCertPool()} tlsConfig := tls.Config{RootCAs: x509.NewCertPool()}
rootCABytes, err := ioutil.ReadFile(rootCA) rootCABytes, err := os.ReadFile(rootCA)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read root-ca: %v", err) return nil, fmt.Errorf("failed to read root-ca: %v", err)
} }
@ -488,7 +489,7 @@ func get(ctx context.Context, client *http.Client, apiURL string, v interface{})
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return "", fmt.Errorf("github: read body: %v", err) return "", fmt.Errorf("github: read body: %v", err)
} }

View file

@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
@ -232,7 +232,7 @@ func (c *gitlabConnector) user(ctx context.Context, client *http.Client) (gitlab
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return u, fmt.Errorf("gitlab: read body: %v", err) return u, fmt.Errorf("gitlab: read body: %v", err)
} }
@ -266,7 +266,7 @@ func (c *gitlabConnector) userGroups(ctx context.Context, client *http.Client) (
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("gitlab: read body: %v", err) return nil, fmt.Errorf("gitlab: read body: %v", err)
} }

View file

@ -5,8 +5,8 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os"
"time" "time"
"github.com/coreos/go-oidc/v3/oidc" "github.com/coreos/go-oidc/v3/oidc"
@ -274,7 +274,7 @@ func createDirectoryService(serviceAccountFilePath string, email string) (*admin
if serviceAccountFilePath == "" || email == "" { if serviceAccountFilePath == "" || email == "" {
return nil, fmt.Errorf("directory service requires both serviceAccountFilePath and adminEmail") return nil, fmt.Errorf("directory service requires both serviceAccountFilePath and adminEmail")
} }
jsonCredentials, err := ioutil.ReadFile(serviceAccountFilePath) jsonCredentials, err := os.ReadFile(serviceAccountFilePath)
if err != nil { if err != nil {
return nil, fmt.Errorf("error reading credentials from file: %v", err) return nil, fmt.Errorf("error reading credentials from file: %v", err)
} }

View file

@ -6,7 +6,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
@ -133,7 +133,7 @@ func (p *conn) Login(ctx context.Context, scopes connector.Scopes, username, pas
return identity, false, nil return identity, false, nil
} }
token := resp.Header.Get("X-Subject-Token") token := resp.Header.Get("X-Subject-Token")
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return identity, false, err return identity, false, err
} }
@ -260,7 +260,7 @@ func (p *conn) getUser(ctx context.Context, userID string, token string) (*userR
return nil, err return nil, err
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -290,7 +290,7 @@ func (p *conn) getUserGroups(ctx context.Context, userID string, token string) (
return nil, err return nil, err
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -5,7 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"reflect" "reflect"
@ -78,7 +78,7 @@ func getAdminToken(t *testing.T, adminName, adminPass string) (token, id string)
token = resp.Header.Get("X-Subject-Token") token = resp.Header.Get("X-Subject-Token")
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -122,7 +122,7 @@ func createUser(t *testing.T, token, userName, userEmail, userPass string) strin
t.Fatal(err) t.Fatal(err)
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -183,7 +183,7 @@ func createGroup(t *testing.T, token, description, name string) string {
t.Fatal(err) t.Fatal(err)
} }
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -7,8 +7,8 @@ import (
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os"
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
@ -257,7 +257,7 @@ func (c *Config) openConnector(logger log.Logger) (*ldapConnector, error) {
data := c.RootCAData data := c.RootCAData
if len(data) == 0 { if len(data) == 0 {
var err error var err error
if data, err = ioutil.ReadFile(c.RootCA); err != nil { if data, err = os.ReadFile(c.RootCA); err != nil {
return nil, fmt.Errorf("ldap: read ca file: %v", err) return nil, fmt.Errorf("ldap: read ca file: %v", err)
} }
} }

View file

@ -3,7 +3,7 @@ package ldap
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"testing" "testing"
@ -555,7 +555,7 @@ func runTests(t *testing.T, connMethod connectionMethod, config *Config, tests [
c.BindDN = "cn=admin,dc=example,dc=org" c.BindDN = "cn=admin,dc=example,dc=org"
c.BindPW = "admin" c.BindPW = "admin"
l := &logrus.Logger{Out: ioutil.Discard, Formatter: &logrus.TextFormatter{}} l := &logrus.Logger{Out: io.Discard, Formatter: &logrus.TextFormatter{}}
conn, err := c.openConnector(l) conn, err := c.openConnector(l)
if err != nil { if err != nil {

View file

@ -5,7 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
@ -169,7 +169,7 @@ func (c *linkedInConnector) primaryEmail(ctx context.Context, client *http.Clien
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return email, fmt.Errorf("read body: %v", err) return email, fmt.Errorf("read body: %v", err)
} }
@ -209,7 +209,7 @@ func (c *linkedInConnector) profile(ctx context.Context, client *http.Client) (p
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return p, fmt.Errorf("read body: %v", err) return p, fmt.Errorf("read body: %v", err)
} }

View file

@ -6,9 +6,10 @@ import (
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
@ -195,7 +196,7 @@ func (c *openshiftConnector) user(ctx context.Context, client *http.Client) (u u
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return u, fmt.Errorf("read body: %v", err) return u, fmt.Errorf("read body: %v", err)
} }
@ -223,7 +224,7 @@ func newHTTPClient(insecureCA bool, rootCA string) (*http.Client, error) {
tlsConfig = tls.Config{InsecureSkipVerify: true} tlsConfig = tls.Config{InsecureSkipVerify: true}
} else if rootCA != "" { } else if rootCA != "" {
tlsConfig = tls.Config{RootCAs: x509.NewCertPool()} tlsConfig = tls.Config{RootCAs: x509.NewCertPool()}
rootCABytes, err := ioutil.ReadFile(rootCA) rootCABytes, err := os.ReadFile(rootCA)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read root-ca: %v", err) return nil, fmt.Errorf("failed to read root-ca: %v", err)
} }

View file

@ -8,7 +8,7 @@ import (
"encoding/pem" "encoding/pem"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -194,7 +194,7 @@ func (c *Config) openConnector(logger log.Logger) (*provider, error) {
var caData []byte var caData []byte
if c.CA != "" { if c.CA != "" {
data, err := ioutil.ReadFile(c.CA) data, err := os.ReadFile(c.CA)
if err != nil { if err != nil {
return nil, fmt.Errorf("read ca file: %v", err) return nil, fmt.Errorf("read ca file: %v", err)
} }

View file

@ -5,7 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/pem" "encoding/pem"
"errors" "errors"
"io/ioutil" "os"
"sort" "sort"
"testing" "testing"
"time" "time"
@ -392,7 +392,7 @@ func TestTamperedResponseNameID(t *testing.T) {
} }
func loadCert(ca string) (*x509.Certificate, error) { func loadCert(ca string) (*x509.Certificate, error) {
data, err := ioutil.ReadFile(ca) data, err := os.ReadFile(ca)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -426,7 +426,7 @@ func (r responseTest) run(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
conn.now = func() time.Time { return now } conn.now = func() time.Time { return now }
resp, err := ioutil.ReadFile(r.respFile) resp, err := os.ReadFile(r.respFile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -456,11 +456,11 @@ func (r responseTest) run(t *testing.T) {
func TestConfigCAData(t *testing.T) { func TestConfigCAData(t *testing.T) {
logger := logrus.New() logger := logrus.New()
validPEM, err := ioutil.ReadFile("testdata/ca.crt") validPEM, err := os.ReadFile("testdata/ca.crt")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
valid2ndPEM, err := ioutil.ReadFile("testdata/okta-ca.pem") valid2ndPEM, err := os.ReadFile("testdata/okta-ca.pem")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -551,7 +551,7 @@ func runVerify(t *testing.T, ca string, resp string, shouldSucceed bool) {
validator := dsig.NewDefaultValidationContext(s) validator := dsig.NewDefaultValidationContext(s)
data, err := ioutil.ReadFile(resp) data, err := os.ReadFile(resp)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
@ -43,7 +42,7 @@ type app struct {
// return an HTTP client which trusts the provided root CAs. // return an HTTP client which trusts the provided root CAs.
func httpClientForRootCAs(rootCAs string) (*http.Client, error) { func httpClientForRootCAs(rootCAs string) (*http.Client, error) {
tlsConfig := tls.Config{RootCAs: x509.NewCertPool()} tlsConfig := tls.Config{RootCAs: x509.NewCertPool()}
rootCABytes, err := ioutil.ReadFile(rootCAs) rootCABytes, err := os.ReadFile(rootCAs)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read root-ca: %v", err) return nil, fmt.Errorf("failed to read root-ca: %v", err)
} }

View file

@ -6,8 +6,8 @@ import (
"crypto/x509" "crypto/x509"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
@ -17,7 +17,7 @@ import (
func newDexClient(hostAndPort, caPath, clientCrt, clientKey string) (api.DexClient, error) { func newDexClient(hostAndPort, caPath, clientCrt, clientKey string) (api.DexClient, error) {
cPool := x509.NewCertPool() cPool := x509.NewCertPool()
caCert, err := ioutil.ReadFile(caPath) caCert, err := os.ReadFile(caPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid CA crt file: %s", caPath) return nil, fmt.Errorf("invalid CA crt file: %s", caPath)
} }

View file

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -101,7 +101,7 @@ func TestHandleDeviceCode(t *testing.T) {
t.Errorf("Unexpected Response Type. Expected %v got %v", tc.expectedResponseCode, rr.Code) t.Errorf("Unexpected Response Type. Expected %v got %v", tc.expectedResponseCode, rr.Code)
} }
body, err := ioutil.ReadAll(rr.Body) body, err := io.ReadAll(rr.Body)
if err != nil { if err != nil {
t.Errorf("Could read token response %v", err) t.Errorf("Could read token response %v", err)
} }
@ -541,7 +541,7 @@ func TestDeviceTokenResponse(t *testing.T) {
t.Errorf("Unexpected Response Type. Expected %v got %v", tc.expectedResponseCode, rr.Code) t.Errorf("Unexpected Response Type. Expected %v got %v", tc.expectedResponseCode, rr.Code)
} }
body, err := ioutil.ReadAll(rr.Body) body, err := io.ReadAll(rr.Body)
if err != nil { if err != nil {
t.Errorf("Could read token response %v", err) t.Errorf("Could read token response %v", err)
} }

View file

@ -8,7 +8,7 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/http/httputil" "net/http/httputil"
@ -1588,7 +1588,7 @@ func TestOAuth2DeviceFlow(t *testing.T) {
t.Errorf("Could not request device code: %v", err) t.Errorf("Could not request device code: %v", err)
} }
defer resp.Body.Close() defer resp.Body.Close()
responseBody, err := ioutil.ReadAll(resp.Body) responseBody, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Errorf("Could read device code response %v", err) t.Errorf("Could read device code response %v", err)
} }
@ -1615,7 +1615,7 @@ func TestOAuth2DeviceFlow(t *testing.T) {
t.Errorf("Error Posting Form: %v", err) t.Errorf("Error Posting Form: %v", err)
} }
defer resp.Body.Close() defer resp.Body.Close()
responseBody, err = ioutil.ReadAll(resp.Body) responseBody, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Errorf("Could read verification response %v", err) t.Errorf("Could read verification response %v", err)
} }
@ -1634,7 +1634,7 @@ func TestOAuth2DeviceFlow(t *testing.T) {
t.Errorf("Could not request device token: %v", err) t.Errorf("Could not request device token: %v", err)
} }
defer resp.Body.Close() defer resp.Body.Close()
responseBody, err = ioutil.ReadAll(resp.Body) responseBody, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Errorf("Could read device token response %v", err) t.Errorf("Could read device token response %v", err)
} }

View file

@ -12,8 +12,8 @@ import (
"encoding/json" "encoding/json"
"go/format" "go/format"
"io" "io"
"io/ioutil"
"log" "log"
"os"
"text/template" "text/template"
jose "gopkg.in/square/go-jose.v2" jose "gopkg.in/square/go-jose.v2"
@ -104,7 +104,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("gofmt failed: %v", err) log.Fatalf("gofmt failed: %v", err)
} }
if err := ioutil.WriteFile("jwks.go", out, 0644); err != nil { if err := os.WriteFile("jwks.go", out, 0644); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View file

@ -13,7 +13,6 @@ import (
"hash" "hash"
"hash/fnv" "hash/fnv"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -132,7 +131,7 @@ func checkHTTPErr(r *http.Response, validStatusCodes ...int) error {
} }
} }
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 2<<15)) // 64 KiB body, err := io.ReadAll(io.LimitReader(r.Body, 2<<15)) // 64 KiB
if err != nil { if err != nil {
return fmt.Errorf("read response body: %v", err) return fmt.Errorf("read response body: %v", err)
} }
@ -156,7 +155,7 @@ func checkHTTPErr(r *http.Response, validStatusCodes ...int) error {
// Close the response body. The initial request is drained so the connection can // Close the response body. The initial request is drained so the connection can
// be reused. // be reused.
func closeResp(r *http.Response) { func closeResp(r *http.Response) {
io.Copy(ioutil.Discard, r.Body) io.Copy(io.Discard, r.Body)
r.Body.Close() r.Body.Close()
} }
@ -312,7 +311,7 @@ func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, l
if file == "" { if file == "" {
return nil, nil return nil, nil
} }
return ioutil.ReadFile(file) return os.ReadFile(file)
} }
if caData, err := data(cluster.CertificateAuthorityData, cluster.CertificateAuthority); err != nil { if caData, err := data(cluster.CertificateAuthorityData, cluster.CertificateAuthority); err != nil {
@ -379,7 +378,7 @@ func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, l
} }
func loadKubeConfig(kubeConfigPath string) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, err error) { func loadKubeConfig(kubeConfigPath string) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, err error) {
data, err := ioutil.ReadFile(kubeConfigPath) data, err := os.ReadFile(kubeConfigPath)
if err != nil { if err != nil {
err = fmt.Errorf("read %s: %v", kubeConfigPath, err) err = fmt.Errorf("read %s: %v", kubeConfigPath, err)
return return
@ -425,7 +424,7 @@ func namespaceFromServiceAccountJWT(s string) (string, error) {
} }
func namespaceFromFile(path string) (string, error) { func namespaceFromFile(path string) (string, error) {
data, err := ioutil.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -481,7 +480,7 @@ func inClusterConfig() (k8sapi.Cluster, k8sapi.AuthInfo, string, error) {
CertificateAuthority: serviceAccountCAPath, CertificateAuthority: serviceAccountCAPath,
} }
token, err := ioutil.ReadFile(serviceAccountTokenPath) token, err := os.ReadFile(serviceAccountTokenPath)
if err != nil { if err != nil {
return cluster, k8sapi.AuthInfo{}, "", err return cluster, k8sapi.AuthInfo{}, "", err
} }

View file

@ -3,7 +3,6 @@ package kubernetes
import ( import (
"hash" "hash"
"hash/fnv" "hash/fnv"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -72,7 +71,7 @@ func TestInClusterTransport(t *testing.T) {
fpath := filepath.Join(os.TempDir(), "test.in_cluster") fpath := filepath.Join(os.TempDir(), "test.in_cluster")
defer os.RemoveAll(fpath) defer os.RemoveAll(fpath)
err = ioutil.WriteFile(fpath, []byte("def"), 0o644) err = os.WriteFile(fpath, []byte("def"), 0o644)
require.NoError(t, err) require.NoError(t, err)
tests := []struct { tests := []struct {
@ -136,7 +135,7 @@ func TestGetClusterConfigNamespace(t *testing.T) {
var namespaceFile string var namespaceFile string
{ {
tmpfile, err := ioutil.TempFile(os.TempDir(), "test-get-cluster-config-namespace") tmpfile, err := os.CreateTemp(os.TempDir(), "test-get-cluster-config-namespace")
require.NoError(t, err) require.NoError(t, err)
_, err = tmpfile.Write([]byte("namespace-from-file")) _, err = tmpfile.Write([]byte("namespace-from-file"))

View file

@ -1,8 +1,8 @@
package kubernetes package kubernetes
import ( import (
"io/ioutil"
"net/http" "net/http"
"os"
"sync" "sync"
"time" "time"
@ -103,7 +103,7 @@ func (c *inClusterTransportHelper) UpdateToken() {
return return
} }
token, err := ioutil.ReadFile(c.tokenLocation) token, err := os.ReadFile(c.tokenLocation)
if err != nil { if err != nil {
return return
} }

View file

@ -5,8 +5,8 @@ import (
"crypto/x509" "crypto/x509"
"database/sql" "database/sql"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -320,7 +320,7 @@ func (s *MySQL) makeTLSConfig() error {
cfg := &tls.Config{} cfg := &tls.Config{}
if s.SSL.CAFile != "" { if s.SSL.CAFile != "" {
rootCertPool := x509.NewCertPool() rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile(s.SSL.CAFile) pem, err := os.ReadFile(s.SSL.CAFile)
if err != nil { if err != nil {
return err return err
} }