mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-24 16:17:11 +08:00
Remove uses of deprecated ioutil package
This commit is contained in:
committed by
Zac Bergquist
parent
77fbed70ce
commit
3f507dfd06
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -35,7 +34,7 @@ func write(t *testing.T, data []byte, path ...string) string {
|
||||
t.Helper()
|
||||
filePath := filepath.Join(path...)
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(filePath), 0777))
|
||||
require.NoError(t, ioutil.WriteFile(filePath, data, 0644))
|
||||
require.NoError(t, os.WriteFile(filePath, data, 0644))
|
||||
return filePath
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -166,7 +165,7 @@ func waitForEtcdToStart(ctx context.Context, certDir string) error {
|
||||
// as started with Start()
|
||||
func newHTTPSTransport(certDir string) (*http.Client, error) {
|
||||
caCertPath := path.Join(certDir, "ca-cert.pem")
|
||||
caCert, err := ioutil.ReadFile(caCertPath)
|
||||
caCert, err := os.ReadFile(caCertPath)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err, "failed reading CA cert from %s", caCertPath)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package client
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/gravitational/teleport/api/constants"
|
||||
"github.com/gravitational/teleport/api/identityfile"
|
||||
@@ -115,7 +115,7 @@ func (c *keypairCreds) TLSConfig() (*tls.Config, error) {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
cas, err := ioutil.ReadFile(c.caFile)
|
||||
cas, err := os.ReadFile(c.caFile)
|
||||
if err != nil {
|
||||
return nil, trace.ConvertSystemError(err)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package client
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -153,11 +152,11 @@ func TestLoadKeyPair(t *testing.T) {
|
||||
// Write key pair and CAs files from bytes.
|
||||
path := t.TempDir() + "username"
|
||||
certPath, keyPath, caPath := path+".crt", path+".key", path+".cas"
|
||||
err := ioutil.WriteFile(certPath, tlsCert, 0600)
|
||||
err := os.WriteFile(certPath, tlsCert, 0600)
|
||||
require.NoError(t, err)
|
||||
err = ioutil.WriteFile(keyPath, keyPEM, 0600)
|
||||
err = os.WriteFile(keyPath, keyPEM, 0600)
|
||||
require.NoError(t, err)
|
||||
err = ioutil.WriteFile(caPath, tlsCACert, 0600)
|
||||
err = os.WriteFile(caPath, tlsCACert, 0600)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Load key pair from disk.
|
||||
@@ -185,20 +184,7 @@ func TestLoadProfile(t *testing.T) {
|
||||
SiteName: "example.com",
|
||||
Username: "testUser",
|
||||
Dir: dir,
|
||||
}, false)
|
||||
testProfileContents(t, dir, profileName)
|
||||
})
|
||||
|
||||
// DELETE IN 8.0.0
|
||||
t.Run("old profile", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
writeProfile(t, &profile.Profile{
|
||||
WebProxyAddr: profileName + ":3080",
|
||||
SiteName: "example.com",
|
||||
Username: "testUser",
|
||||
Dir: dir,
|
||||
}, true)
|
||||
})
|
||||
testProfileContents(t, dir, profileName)
|
||||
})
|
||||
|
||||
@@ -236,24 +222,18 @@ func testProfileContents(t *testing.T, dir, name string) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func writeProfile(t *testing.T, p *profile.Profile, oldSSHPath bool) {
|
||||
func writeProfile(t *testing.T, p *profile.Profile) {
|
||||
// Save profile and keys to disk.
|
||||
require.NoError(t, p.SaveToDir(p.Dir, true))
|
||||
require.NoError(t, os.MkdirAll(p.KeyDir(), 0700))
|
||||
require.NoError(t, os.MkdirAll(p.ProxyKeyDir(), 0700))
|
||||
require.NoError(t, os.MkdirAll(p.TLSClusterCASDir(), 0700))
|
||||
require.NoError(t, ioutil.WriteFile(p.UserKeyPath(), keyPEM, 0600))
|
||||
require.NoError(t, ioutil.WriteFile(p.TLSCertPath(), tlsCert, 0600))
|
||||
require.NoError(t, ioutil.WriteFile(p.TLSCAPathCluster(p.SiteName), tlsCACert, 0600))
|
||||
require.NoError(t, ioutil.WriteFile(p.KnownHostsPath(), sshCACert, 0600))
|
||||
// If oldSSHPath is specified, write the sshCert to the old ssh cert path.
|
||||
// DELETE IN 8.0.0
|
||||
if oldSSHPath {
|
||||
require.NoError(t, ioutil.WriteFile(p.OldSSHCertPath(), sshCert, 0600))
|
||||
return
|
||||
}
|
||||
require.NoError(t, os.WriteFile(p.UserKeyPath(), keyPEM, 0600))
|
||||
require.NoError(t, os.WriteFile(p.TLSCertPath(), tlsCert, 0600))
|
||||
require.NoError(t, os.WriteFile(p.TLSCAPathCluster(p.SiteName), tlsCACert, 0600))
|
||||
require.NoError(t, os.WriteFile(p.KnownHostsPath(), sshCACert, 0600))
|
||||
require.NoError(t, os.MkdirAll(p.SSHDir(), 0700))
|
||||
require.NoError(t, ioutil.WriteFile(p.SSHCertPath(), sshCert, 0600))
|
||||
require.NoError(t, os.WriteFile(p.SSHCertPath(), sshCert, 0600))
|
||||
}
|
||||
|
||||
func getExpectedTLSConfig(t *testing.T) *tls.Config {
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -102,7 +101,7 @@ func Write(idFile *IdentityFile, path string) error {
|
||||
if err := encodeIdentityFile(buf, idFile); err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
if err := ioutil.WriteFile(path, buf.Bytes(), FilePermissions); err != nil {
|
||||
if err := os.WriteFile(path, buf.Bytes(), FilePermissions); err != nil {
|
||||
return trace.ConvertSystemError(err)
|
||||
}
|
||||
return nil
|
||||
@@ -139,7 +138,7 @@ func ReadFile(path string) (*IdentityFile, error) {
|
||||
// separate file with -cert.pub suffix.
|
||||
if len(ident.Certs.SSH) == 0 {
|
||||
certFn := keypaths.IdentitySSHCertPath(path)
|
||||
if ident.Certs.SSH, err = ioutil.ReadFile(certFn); err != nil {
|
||||
if ident.Certs.SSH, err = os.ReadFile(certFn); err != nil {
|
||||
return nil, trace.Wrap(err, "could not find SSH cert in the identity file or %v", certFn)
|
||||
}
|
||||
}
|
||||
|
||||
+15
-27
@@ -21,7 +21,6 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/user"
|
||||
@@ -118,7 +117,7 @@ func (p *Profile) TLSConfig() (*tls.Config, error) {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
cert, err := ioutil.ReadFile(path)
|
||||
cert, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return trace.ConvertSystemError(err)
|
||||
}
|
||||
@@ -139,23 +138,17 @@ func (p *Profile) TLSConfig() (*tls.Config, error) {
|
||||
|
||||
// SSHClientConfig returns the profile's associated SSHClientConfig.
|
||||
func (p *Profile) SSHClientConfig() (*ssh.ClientConfig, error) {
|
||||
cert, err := ioutil.ReadFile(p.SSHCertPath())
|
||||
if err != nil {
|
||||
// Try reading SSHCert from old cert path, return original error otherwise
|
||||
// DELETE IN 8.0.0
|
||||
var err2 error
|
||||
cert, err2 = ioutil.ReadFile(p.OldSSHCertPath())
|
||||
if err2 != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
key, err := ioutil.ReadFile(p.UserKeyPath())
|
||||
cert, err := os.ReadFile(p.SSHCertPath())
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
caCerts, err := ioutil.ReadFile(p.KnownHostsPath())
|
||||
key, err := os.ReadFile(p.UserKeyPath())
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
caCerts, err := os.ReadFile(p.KnownHostsPath())
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -174,7 +167,7 @@ func SetCurrentProfileName(dir string, name string) error {
|
||||
}
|
||||
|
||||
path := filepath.Join(dir, currentProfileFilename)
|
||||
if err := ioutil.WriteFile(path, []byte(strings.TrimSpace(name)+"\n"), 0660); err != nil {
|
||||
if err := os.WriteFile(path, []byte(strings.TrimSpace(name)+"\n"), 0660); err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
return nil
|
||||
@@ -186,7 +179,7 @@ func GetCurrentProfileName(dir string) (name string, err error) {
|
||||
return "", trace.BadParameter("cannot get current profile: missing dir")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(filepath.Join(dir, currentProfileFilename))
|
||||
data, err := os.ReadFile(filepath.Join(dir, currentProfileFilename))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return "", trace.NotFound("current-profile is not set")
|
||||
@@ -205,7 +198,7 @@ func ListProfileNames(dir string) ([]string, error) {
|
||||
if dir == "" {
|
||||
return nil, trace.BadParameter("cannot list profiles: missing dir")
|
||||
}
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -215,7 +208,8 @@ func ListProfileNames(dir string) ([]string, error) {
|
||||
if file.IsDir() {
|
||||
continue
|
||||
}
|
||||
if file.Mode()&os.ModeSymlink != 0 {
|
||||
|
||||
if file.Type()&os.ModeSymlink != 0 {
|
||||
continue
|
||||
}
|
||||
if !strings.HasSuffix(file.Name(), ".yaml") {
|
||||
@@ -266,7 +260,7 @@ func FromDir(dir string, name string) (*Profile, error) {
|
||||
|
||||
// profileFromFile loads the profile from a YAML file.
|
||||
func profileFromFile(filePath string) (*Profile, error) {
|
||||
bytes, err := ioutil.ReadFile(filePath)
|
||||
bytes, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, trace.ConvertSystemError(err)
|
||||
}
|
||||
@@ -306,7 +300,7 @@ func (p *Profile) saveToFile(filepath string) error {
|
||||
if err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
if err = ioutil.WriteFile(filepath, bytes, 0660); err != nil {
|
||||
if err = os.WriteFile(filepath, bytes, 0660); err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
return nil
|
||||
@@ -352,12 +346,6 @@ func (p *Profile) SSHCertPath() string {
|
||||
return keypaths.SSHCertPath(p.Dir, p.Name(), p.Username, p.SiteName)
|
||||
}
|
||||
|
||||
// OldSSHCertPath returns the old (before v6.1) path to the profile's ssh certificate.
|
||||
// DELETE IN 8.0.0
|
||||
func (p *Profile) OldSSHCertPath() string {
|
||||
return keypaths.OldSSHCertPath(p.Dir, p.Name(), p.Username)
|
||||
}
|
||||
|
||||
// KnownHostsPath returns the path to the profile's ssh certificate authorities.
|
||||
func (p *Profile) KnownHostsPath() string {
|
||||
return keypaths.KnownHostsPath(p.Dir)
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -507,7 +506,7 @@ func GenerateUserCreds(req UserCredsRequest) (*UserCreds, error) {
|
||||
// GenerateConfig generates instance config
|
||||
func (i *TeleInstance) GenerateConfig(t *testing.T, trustedSecrets []*InstanceSecrets, tconf *service.Config) (*service.Config, error) {
|
||||
var err error
|
||||
dataDir, err := ioutil.TempDir("", "cluster-"+i.Secrets.SiteName)
|
||||
dataDir, err := os.MkdirTemp("", "cluster-"+i.Secrets.SiteName)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -722,7 +721,7 @@ func (i *TeleInstance) StartReverseTunnelNode(tconf *service.Config) (*service.T
|
||||
|
||||
// startNode starts a node and connects it to the cluster.
|
||||
func (i *TeleInstance) startNode(tconf *service.Config, authPort string) (*service.TeleportProcess, error) {
|
||||
dataDir, err := ioutil.TempDir("", "cluster-"+i.Secrets.SiteName)
|
||||
dataDir, err := os.MkdirTemp("", "cluster-"+i.Secrets.SiteName)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -776,7 +775,7 @@ func (i *TeleInstance) startNode(tconf *service.Config, authPort string) (*servi
|
||||
}
|
||||
|
||||
func (i *TeleInstance) StartApp(conf *service.Config) (*service.TeleportProcess, error) {
|
||||
dataDir, err := ioutil.TempDir("", "cluster-"+i.Secrets.SiteName)
|
||||
dataDir, err := os.MkdirTemp("", "cluster-"+i.Secrets.SiteName)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -821,7 +820,7 @@ func (i *TeleInstance) StartApp(conf *service.Config) (*service.TeleportProcess,
|
||||
|
||||
// StartDatabase starts the database access service with the provided config.
|
||||
func (i *TeleInstance) StartDatabase(conf *service.Config) (*service.TeleportProcess, *auth.Client, error) {
|
||||
dataDir, err := ioutil.TempDir("", "cluster-"+i.Secrets.SiteName)
|
||||
dataDir, err := os.MkdirTemp("", "cluster-"+i.Secrets.SiteName)
|
||||
if err != nil {
|
||||
return nil, nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -886,7 +885,7 @@ func (i *TeleInstance) StartDatabase(conf *service.Config) (*service.TeleportPro
|
||||
// StartNodeAndProxy starts a SSH node and a Proxy Server and connects it to
|
||||
// the cluster.
|
||||
func (i *TeleInstance) StartNodeAndProxy(name string, sshPort, proxyWebPort, proxySSHPort int) error {
|
||||
dataDir, err := ioutil.TempDir("", "cluster-"+i.Secrets.SiteName)
|
||||
dataDir, err := os.MkdirTemp("", "cluster-"+i.Secrets.SiteName)
|
||||
if err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
@@ -973,7 +972,7 @@ type ProxyConfig struct {
|
||||
|
||||
// StartProxy starts another Proxy Server and connects it to the cluster.
|
||||
func (i *TeleInstance) StartProxy(cfg ProxyConfig) (reversetunnel.Server, error) {
|
||||
dataDir, err := ioutil.TempDir("", "cluster-"+i.Secrets.SiteName+"-"+cfg.Name)
|
||||
dataDir, err := os.MkdirTemp("", "cluster-"+i.Secrets.SiteName+"-"+cfg.Name)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -1192,7 +1191,7 @@ func (i *TeleInstance) NewClientWithCreds(cfg ClientConfig, creds UserCreds) (tc
|
||||
// NewUnauthenticatedClient returns a fully configured and pre-authenticated client
|
||||
// (pre-authenticated with server CAs and signed session key)
|
||||
func (i *TeleInstance) NewUnauthenticatedClient(cfg ClientConfig) (tc *client.TeleportClient, err error) {
|
||||
keyDir, err := ioutil.TempDir(i.Config.DataDir, "tsh")
|
||||
keyDir, err := os.MkdirTemp(i.Config.DataDir, "tsh")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1624,7 +1623,7 @@ func externalSSHCommand(o commandOptions) (*exec.Cmd, error) {
|
||||
// clobber your system agent.
|
||||
func createAgent(me *user.User, privateKeyByte []byte, certificateBytes []byte) (*teleagent.AgentServer, string, string, error) {
|
||||
// create a path to the unix socket
|
||||
sockDir, err := ioutil.TempDir("", "int-test")
|
||||
sockDir, err := os.MkdirTemp("", "int-test")
|
||||
if err != nil {
|
||||
return nil, "", "", trace.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -608,7 +607,7 @@ func testInteroperability(t *testing.T, suite *integrationTestSuite) {
|
||||
// if we are looking for the output in a file, look in the file
|
||||
// otherwise check stdout and stderr for the expected output
|
||||
if tt.outFile {
|
||||
bytes, err := ioutil.ReadFile(tempfile)
|
||||
bytes, err := os.ReadFile(tempfile)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(bytes), tt.outContains)
|
||||
} else {
|
||||
@@ -1543,7 +1542,7 @@ func twoClustersTunnel(t *testing.T, suite *integrationTestSuite, now time.Time,
|
||||
|
||||
// The known_hosts file should have two certificates, the way bytes.Split
|
||||
// works that means the output will be 3 (2 certs + 1 empty).
|
||||
buffer, err := ioutil.ReadFile(keypaths.KnownHostsPath(tc.KeysDir))
|
||||
buffer, err := os.ReadFile(keypaths.KnownHostsPath(tc.KeysDir))
|
||||
require.NoError(t, err)
|
||||
parts := bytes.Split(buffer, []byte("\n"))
|
||||
require.Len(t, parts, 3)
|
||||
@@ -1554,7 +1553,7 @@ func twoClustersTunnel(t *testing.T, suite *integrationTestSuite, now time.Time,
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
buffer, err = ioutil.ReadFile(path)
|
||||
buffer, err = os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
ok := roots.AppendCertsFromPEM(buffer)
|
||||
require.True(t, ok)
|
||||
@@ -3253,7 +3252,7 @@ func testControlMaster(t *testing.T, suite *integrationTestSuite) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
controlDir, err := ioutil.TempDir("", "teleport-")
|
||||
controlDir, err := os.MkdirTemp("", "teleport-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(controlDir)
|
||||
controlPath := filepath.Join(controlDir, "control-path")
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -1452,7 +1451,7 @@ func kubeExec(kubeConfig *rest.Config, args kubeExecArgs) error {
|
||||
// stderr channel is only set if there is no tty allocated
|
||||
// otherwise k8s server gets confused
|
||||
if !args.tty && args.stderr == nil {
|
||||
args.stderr = ioutil.Discard
|
||||
args.stderr = io.Discard
|
||||
}
|
||||
if args.stderr != nil && !args.tty {
|
||||
query.Set("stderr", "true")
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -1829,7 +1828,7 @@ func (s *APIServer) emitAuditEvent(auth ClientI, w http.ResponseWriter, r *http.
|
||||
|
||||
// HTTP POST /:version/sessions/:id/slice
|
||||
func (s *APIServer) postSessionSlice(auth ClientI, w http.ResponseWriter, r *http.Request, p httprouter.Params, version string) (interface{}, error) {
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
data, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -1309,7 +1309,7 @@ func (c *Client) PostSessionSlice(slice events.SessionSlice) error {
|
||||
// we **must** consume response by reading all of its body, otherwise the http
|
||||
// client will allocate a new connection for subsequent requests
|
||||
defer re.Body.Close()
|
||||
responseBytes, _ := ioutil.ReadAll(re.Body)
|
||||
responseBytes, _ := io.ReadAll(re.Body)
|
||||
return trace.ReadError(re.StatusCode, responseBytes)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
@@ -600,7 +600,7 @@ func claimsFromUserInfo(oidcClient *oidc.Client, issuerURL string, accessToken s
|
||||
code == http.StatusForbidden || code == http.StatusMethodNotAllowed {
|
||||
return nil, trace.AccessDenied("bad status code: %v", code)
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
@@ -254,7 +254,7 @@ func parseSAMLInResponseTo(response string) (string, error) {
|
||||
err := doc.ReadFromBytes(raw)
|
||||
if err != nil {
|
||||
// Attempt to inflate the response in case it happens to be compressed (as with one case at saml.oktadev.com)
|
||||
buf, err := ioutil.ReadAll(flate.NewReader(bytes.NewReader(raw)))
|
||||
buf, err := io.ReadAll(flate.NewReader(bytes.NewReader(raw)))
|
||||
if err != nil {
|
||||
return "", trace.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -2950,7 +2949,7 @@ func (s *TLSSuite) TestRegisterCAPath(c *check.C) {
|
||||
c.Assert(certs, check.HasLen, 1)
|
||||
certPem := certs[0]
|
||||
caPath := filepath.Join(s.dataDir, defaults.CACertFile)
|
||||
err = ioutil.WriteFile(caPath, certPem, teleport.FileMaskOwnerOnly)
|
||||
err = os.WriteFile(caPath, certPem, teleport.FileMaskOwnerOnly)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
// Attempt to register with valid CA path, should work.
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -277,7 +277,7 @@ func (cfg *Config) Validate() error {
|
||||
cfg.DialTimeout = apidefaults.DefaultDialTimeout
|
||||
}
|
||||
if cfg.PasswordFile != "" {
|
||||
out, err := ioutil.ReadFile(cfg.PasswordFile)
|
||||
out, err := os.ReadFile(cfg.PasswordFile)
|
||||
if err != nil {
|
||||
return trace.ConvertSystemError(err)
|
||||
}
|
||||
@@ -313,11 +313,11 @@ func (b *EtcdBackend) reconnect(ctx context.Context) error {
|
||||
tlsConfig := utils.TLSConfig(nil)
|
||||
|
||||
if b.cfg.TLSCertFile != "" {
|
||||
clientCertPEM, err := ioutil.ReadFile(b.cfg.TLSCertFile)
|
||||
clientCertPEM, err := os.ReadFile(b.cfg.TLSCertFile)
|
||||
if err != nil {
|
||||
return trace.ConvertSystemError(err)
|
||||
}
|
||||
clientKeyPEM, err := ioutil.ReadFile(b.cfg.TLSKeyFile)
|
||||
clientKeyPEM, err := os.ReadFile(b.cfg.TLSKeyFile)
|
||||
if err != nil {
|
||||
return trace.ConvertSystemError(err)
|
||||
}
|
||||
@@ -329,7 +329,7 @@ func (b *EtcdBackend) reconnect(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if b.cfg.TLSCAFile != "" {
|
||||
caCertPEM, err := ioutil.ReadFile(b.cfg.TLSCAFile)
|
||||
caCertPEM, err := os.ReadFile(b.cfg.TLSCAFile)
|
||||
if err != nil {
|
||||
return trace.ConvertSystemError(err)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -157,8 +156,8 @@ func ExportLatencyProfile(path string, h *hdrhistogram.Histogram, ticks int32, v
|
||||
// to benchmark spec. It returns benchmark result when completed.
|
||||
// This is a blocking function that can be cancelled via context argument.
|
||||
func (c *Config) Benchmark(ctx context.Context, tc *client.TeleportClient) (Result, error) {
|
||||
tc.Stdout = ioutil.Discard
|
||||
tc.Stderr = ioutil.Discard
|
||||
tc.Stdout = io.Discard
|
||||
tc.Stderr = io.Discard
|
||||
tc.Stdin = &bytes.Buffer{}
|
||||
var delay time.Duration
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
+3
-4
@@ -23,7 +23,6 @@ import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -69,7 +68,7 @@ func (s *Suite) TestWatch(c *check.C) {
|
||||
}
|
||||
|
||||
// Create temporary directory where cgroup2 hierarchy will be mounted.
|
||||
dir, err := ioutil.TempDir("", "cgroup-test")
|
||||
dir, err := os.MkdirTemp("", "cgroup-test")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
@@ -171,7 +170,7 @@ func (s *Suite) TestObfuscate(c *check.C) {
|
||||
// has been executed.
|
||||
go func() {
|
||||
// Create temporary file.
|
||||
file, err := ioutil.TempFile("", "test-script")
|
||||
file, err := os.CreateTemp("", "test-script")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
@@ -248,7 +247,7 @@ func (s *Suite) TestScript(c *check.C) {
|
||||
// has been executed.
|
||||
go func() {
|
||||
// Create temporary file.
|
||||
file, err := ioutil.TempFile("", "test-script")
|
||||
file, err := os.CreateTemp("", "test-script")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user