Browse Source

removes ioutil usage everywhere which was deprecated in go1.16 (#15297)

* update go version to 1.18 for api and sdk, go mod tidy
* removes ioutil usage everywhere which was deprecated in go1.16 in favour of io and os packages. Also introduces a lint rule which forbids use of ioutil going forward.
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
pull/15328/head
Kyle Schochenmaier 2 years ago committed by GitHub
parent
commit
bf0f61a878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .changelog/15297.txt
  2. 1
      .golangci.yml
  3. 19
      agent/agent.go
  4. 5
      agent/agent_endpoint_test.go
  5. 99
      agent/agent_test.go
  6. 4
      agent/auto-config/auto_config.go
  7. 5
      agent/auto-config/auto_config_test.go
  8. 5
      agent/auto-config/persist.go
  9. 3
      agent/checks/check.go
  10. 3
      agent/checks/docker.go
  11. 6
      agent/checks/grpc_test.go
  12. 3
      agent/config/builder.go
  13. 9
      agent/config/builder_test.go
  14. 5
      agent/config/golden_test.go
  15. 3
      agent/config/runtime_test.go
  16. 6
      agent/connect/ca/provider_vault.go
  17. 4
      agent/connect/ca/provider_vault_test.go
  18. 8
      agent/connect/ca/testing.go
  19. 15
      agent/connect/testing_ca_test.go
  20. 4
      agent/connect_ca_endpoint_test.go
  21. 3
      agent/consul/acl_endpoint.go
  22. 5
      agent/consul/acl_endpoint_test.go
  23. 6
      agent/consul/authmethod/kubeauth/testing.go
  24. 12
      agent/consul/auto_config_endpoint_test.go
  25. 3
      agent/consul/leader_connect_test.go
  26. 4
      agent/consul/leader_peering_test.go
  27. 9
      agent/consul/rpc_test.go
  28. 3
      agent/consul/server.go
  29. 3
      agent/consul/snapshot_endpoint.go
  30. 9
      agent/hcp/bootstrap/bootstrap.go
  31. 8
      agent/hcp/manager_test.go
  32. 9
      agent/http_test.go
  33. 3
      agent/keyring.go
  34. 6
      agent/keyring_test.go
  35. 8
      agent/metrics_test.go
  36. 5
      agent/nodeid.go
  37. 6
      agent/nodeid_test.go
  38. 6
      agent/pool/peek_test.go
  39. 4
      agent/proxycfg/testing.go
  40. 3
      agent/remote_exec.go
  41. 8
      agent/routine-leak-checker/leak_test.go
  42. 6
      agent/rpc/peering/service_test.go
  43. 3
      agent/service_manager_test.go
  44. 3
      agent/token/persistence.go
  45. 14
      agent/token/persistence_test.go
  46. 4
      agent/ui_endpoint_test.go
  47. 5
      agent/uiserver/uiserver_test.go
  48. 8
      agent/watch_handler_test.go
  49. 9
      agent/xds/golden_test.go
  50. 5
      api/acl.go
  51. 3
      api/agent_test.go
  52. 9
      api/api_test.go
  53. 31
      api/go.mod
  54. 6
      api/go.sum
  55. 3
      api/mock_api_test.go
  56. 4
      api/operator_license.go
  57. 6
      command/acl/authmethod/create/authmethod_create_test.go
  58. 8
      command/acl/authmethod/update/authmethod_update_test.go
  59. 6
      command/acl/policy/create/policy_create_test.go
  60. 6
      command/acl/policy/update/policy_update_test.go
  61. 6
      command/acl/role/formatter_test.go
  62. 4
      command/acl/rules/translate_test.go
  63. 6
      command/acl/token/formatter_test.go
  64. 4
      command/agent/agent.go
  65. 4
      command/connect/ca/set/connect_ca_set.go
  66. 7
      command/connect/envoy/envoy_test.go
  67. 3
      command/connect/envoy/exec_test.go
  68. 4
      command/flags/http.go
  69. 3
      command/helpers/helpers.go
  70. 3
      command/kv/imp/kv_import.go
  71. 18
      command/lock/lock_test.go
  72. 4
      command/login/login.go
  73. 17
      command/login/login_test.go
  74. 3
      command/logout/logout_test.go
  75. 8
      command/operator/autopilot/state/operator_autopilot_state_test.go
  76. 3
      command/snapshot/inspect/snapshot_inspect.go
  77. 6
      command/snapshot/inspect/snapshot_inspect_test.go
  78. 5
      command/snapshot/restore/snapshot_restore_test.go
  79. 4
      command/snapshot/save/snapshot_save_test.go
  80. 5
      command/tls/ca/create/tls_ca_create_test.go
  81. 6
      command/tls/cert/create/tls_cert_create.go
  82. 5
      command/tls/cert/create/tls_cert_create_test.go
  83. 16
      command/validate/validate_test.go
  84. 6
      command/version/formatter_test.go
  85. 3
      command/watch/watch_test.go
  86. 3
      connect/certgen/certgen.go
  87. 3
      connect/service_test.go
  88. 4
      connect/tls.go
  89. 3
      go.sum
  90. 4
      internal/go-sso/oidcauth/oidcauthtest/testing.go
  91. 5
      internal/testing/golden/golden.go
  92. 4
      internal/tools/proto-gen-rpc-glue/main_test.go
  93. 5
      lib/file/atomic_test.go
  94. 7
      logging/logfile_test.go
  95. 4
      main.go
  96. 4
      sdk/freeport/ephemeral_linux.go
  97. 14
      sdk/go.mod
  98. 5
      sdk/testutil/io.go
  99. 5
      sdk/testutil/server.go
  100. 5
      sdk/testutil/server_methods.go
  101. Some files were not shown because too many files have changed in this diff Show More

7
.changelog/15297.txt

@ -0,0 +1,7 @@
```release-note:improvement
api: updated the go module directive to 1.18.
```
```release-note:improvement
sdk: updated the go module directive to 1.18.
```

1
.golangci.yml

@ -83,6 +83,7 @@ linters-settings:
forbidigo:
# Forbid the following identifiers (list of regexp).
forbid:
- '\bioutil\b(# Use io and os packages instead of ioutil)?'
- '\brequire\.New\b(# Use package-level functions with explicit TestingT)?'
- '\bassert\.New\b(# Use package-level functions with explicit TestingT)?'
# Exclude godoc examples from forbidigo checks.

19
agent/agent.go

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@ -2141,7 +2140,7 @@ func (a *Agent) readPersistedServiceConfigs() (map[structs.ServiceID]*structs.Se
out := make(map[structs.ServiceID]*structs.ServiceConfigResponse)
configDir := filepath.Join(a.config.DataDir, serviceConfigDir)
files, err := ioutil.ReadDir(configDir)
files, err := os.ReadDir(configDir)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
@ -2163,7 +2162,7 @@ func (a *Agent) readPersistedServiceConfigs() (map[structs.ServiceID]*structs.Se
// Read the contents into a buffer
file := filepath.Join(configDir, fi.Name())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("failed reading service config file %q: %w", file, err)
}
@ -3374,7 +3373,7 @@ func (a *Agent) persistCheckState(check *checks.CheckTTL, status, output string)
tempFile := file + ".tmp"
// persistCheckState is called frequently, so don't use writeFileAtomic to avoid calling fsync here
if err := ioutil.WriteFile(tempFile, buf, 0600); err != nil {
if err := os.WriteFile(tempFile, buf, 0600); err != nil {
return fmt.Errorf("failed writing temp file %q: %s", tempFile, err)
}
if err := os.Rename(tempFile, file); err != nil {
@ -3389,12 +3388,12 @@ func (a *Agent) loadCheckState(check *structs.HealthCheck) error {
cid := check.CompoundCheckID()
// Try to read the persisted state for this check
file := filepath.Join(a.config.DataDir, checkStateDir, cid.StringHashSHA256())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
// try the md5 based name. This can be removed once we no longer support upgrades from versions that use MD5 hashing
oldFile := filepath.Join(a.config.DataDir, checkStateDir, cid.StringHashMD5())
buf, err = ioutil.ReadFile(oldFile)
buf, err = os.ReadFile(oldFile)
if err != nil {
if os.IsNotExist(err) {
return nil
@ -3596,7 +3595,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig, snap map[structs.CheckI
// Load any persisted services
svcDir := filepath.Join(a.config.DataDir, servicesDir)
files, err := ioutil.ReadDir(svcDir)
files, err := os.ReadDir(svcDir)
if err != nil {
if os.IsNotExist(err) {
return nil
@ -3617,7 +3616,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig, snap map[structs.CheckI
// Read the contents into a buffer
file := filepath.Join(svcDir, fi.Name())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("failed reading service file %q: %w", file, err)
}
@ -3760,7 +3759,7 @@ func (a *Agent) loadChecks(conf *config.RuntimeConfig, snap map[structs.CheckID]
// Load any persisted checks
checkDir := filepath.Join(a.config.DataDir, checksDir)
files, err := ioutil.ReadDir(checkDir)
files, err := os.ReadDir(checkDir)
if err != nil {
if os.IsNotExist(err) {
return nil
@ -3775,7 +3774,7 @@ func (a *Agent) loadChecks(conf *config.RuntimeConfig, snap map[structs.CheckID]
// Read the contents into a buffer
file := filepath.Join(checkDir, fi.Name())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("failed reading check file %q: %w", file, err)
}

5
agent/agent_endpoint_test.go

@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
@ -1763,7 +1762,7 @@ func TestAgent_ReloadDoesNotTriggerWatch(t *testing.T) {
}
dc1 := "dc1"
tmpFileRaw, err := ioutil.TempFile("", "rexec")
tmpFileRaw, err := os.CreateTemp("", "rexec")
require.NoError(t, err)
tmpFile := tmpFileRaw.Name()
defer os.Remove(tmpFile)
@ -1802,7 +1801,7 @@ func TestAgent_ReloadDoesNotTriggerWatch(t *testing.T) {
contentsStr := ""
// Wait for watch to be populated
for i := 1; i < 7; i++ {
contents, err := ioutil.ReadFile(tmpFile)
contents, err := os.ReadFile(tmpFile)
if err != nil {
t.Fatalf("should be able to read file, but had: %#v", err)
}

99
agent/agent_test.go

@ -9,7 +9,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/http"
@ -2328,7 +2327,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
if err != nil {
t.Fatalf("err: %s", err)
}
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -2349,7 +2348,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
if err != nil {
t.Fatalf("err: %s", err)
}
content, err = ioutil.ReadFile(file)
content, err = os.ReadFile(file)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -2418,7 +2417,7 @@ func testAgent_persistedService_compat(t *testing.T, extraHCL string) {
if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {
t.Fatalf("err: %s", err)
}
if err := ioutil.WriteFile(file, encoded, 0600); err != nil {
if err := os.WriteFile(file, encoded, 0600); err != nil {
t.Fatalf("err: %s", err)
}
@ -2473,7 +2472,7 @@ func testAgent_persistedService_compat_hash(t *testing.T, extraHCL string) {
if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {
t.Fatalf("err: %s", err)
}
if err := ioutil.WriteFile(file, encoded, 0600); err != nil {
if err := os.WriteFile(file, encoded, 0600); err != nil {
t.Fatalf("err: %s", err)
}
@ -2492,7 +2491,7 @@ func testAgent_persistedService_compat_hash(t *testing.T, extraHCL string) {
if err := os.MkdirAll(filepath.Dir(configFile), 0700); err != nil {
t.Fatalf("err: %s", err)
}
if err := ioutil.WriteFile(configFile, encodedConfig, 0600); err != nil {
if err := os.WriteFile(configFile, encodedConfig, 0600); err != nil {
t.Fatalf("err: %s", err)
}
@ -2673,7 +2672,7 @@ func TestAgent_PersistCheck(t *testing.T) {
})
require.NoError(t, err)
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
require.NoError(t, err)
require.Equal(t, expected, content)
@ -2688,7 +2687,7 @@ func TestAgent_PersistCheck(t *testing.T) {
Source: "local",
})
require.NoError(t, err)
content, err = ioutil.ReadFile(file)
content, err = os.ReadFile(file)
require.NoError(t, err)
require.Equal(t, expected, content)
a.Shutdown()
@ -3719,7 +3718,7 @@ func TestAgent_persistCheckState(t *testing.T) {
// Check the persisted file exists and has the content
file := filepath.Join(a.Config.DataDir, checkStateDir, cid.StringHashSHA256())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -5138,9 +5137,9 @@ func TestAutoConfig_Integration(t *testing.T) {
caFile := filepath.Join(cfgDir, "cacert.pem")
keyFile := filepath.Join(cfgDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(cacert), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(key), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(cacert), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(key), 0600))
// generate a gossip key
gossipKey := make([]byte, 32)
@ -5267,7 +5266,7 @@ func TestAutoConfig_Integration(t *testing.T) {
require.NotEqual(r, cert1, client.Agent.tlsConfigurator.Cert())
// check that the on disk certs match expectations
data, err := ioutil.ReadFile(filepath.Join(client.DataDir, "auto-config.json"))
data, err := os.ReadFile(filepath.Join(client.DataDir, "auto-config.json"))
require.NoError(r, err)
rdr := strings.NewReader(string(data))
@ -5302,9 +5301,9 @@ func TestAgent_AutoEncrypt(t *testing.T) {
caFile := filepath.Join(cfgDir, "cacert.pem")
keyFile := filepath.Join(cfgDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(cacert), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(key), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(cacert), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(key), 0600))
hclConfig := TestACLConfigWithParams(nil) + `
verify_incoming = true
@ -5498,9 +5497,9 @@ func TestAgent_AutoReloadDoReload_WhenCertAndKeyUpdated(t *testing.T) {
caFile := filepath.Join(certsDir, "cacert.pem")
keyFile := filepath.Join(certsDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKey), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKey), 0600))
// generate a gossip key
gossipKey := make([]byte, 32)
@ -5540,8 +5539,8 @@ func TestAgent_AutoReloadDoReload_WhenCertAndKeyUpdated(t *testing.T) {
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
})
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert2), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKey2), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert2), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKey2), 0600))
retry.Run(t, func(r *retry.R) {
aeCert2 := srv.tlsConfigurator.Cert()
@ -5579,9 +5578,9 @@ func TestAgent_AutoReloadDoNotReload_WhenCaUpdated(t *testing.T) {
caFile := filepath.Join(certsDir, "cacert.pem")
keyFile := filepath.Join(certsDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKey), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKey), 0600))
// generate a gossip key
gossipKey := make([]byte, 32)
@ -5614,7 +5613,7 @@ func TestAgent_AutoReloadDoNotReload_WhenCaUpdated(t *testing.T) {
ca2, _, err := tlsutil.GenerateCA(tlsutil.CAOpts{Signer: signer})
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca2), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca2), 0600))
// wait a bit to see if it get updated.
time.Sleep(time.Second)
@ -5653,9 +5652,9 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
caFile := filepath.Join(certsDir, "cacert.pem")
keyFile := filepath.Join(certsDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKey), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKey), 0600))
// generate a gossip key
gossipKey := make([]byte, 32)
@ -5667,7 +5666,7 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
hclConfig := TestACLConfigWithParams(nil)
configFile := testutil.TempDir(t, "config") + "/config.hcl"
require.NoError(t, ioutil.WriteFile(configFile, []byte(`
require.NoError(t, os.WriteFile(configFile, []byte(`
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5699,8 +5698,8 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
})
require.NoError(t, err)
certFileNew := filepath.Join(certsDir, "cert_new.pem")
require.NoError(t, ioutil.WriteFile(certFileNew, []byte(certNew), 0600))
require.NoError(t, ioutil.WriteFile(configFile, []byte(`
require.NoError(t, os.WriteFile(certFileNew, []byte(certNew), 0600))
require.NoError(t, os.WriteFile(configFile, []byte(`
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5723,7 +5722,7 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
require.Equal(r, cert1Key, cert.PrivateKey)
})
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKeyNew), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKeyNew), 0600))
// cert should change as we did not update the associated key
time.Sleep(1 * time.Second)
@ -5762,9 +5761,9 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
caFile := filepath.Join(certsDir, "cacert.pem")
keyFile := filepath.Join(certsDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKey), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKey), 0600))
// generate a gossip key
gossipKey := make([]byte, 32)
@ -5776,7 +5775,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
hclConfig := TestACLConfigWithParams(nil)
configFile := testutil.TempDir(t, "config") + "/config.hcl"
require.NoError(t, ioutil.WriteFile(configFile, []byte(`
require.NoError(t, os.WriteFile(configFile, []byte(`
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5809,7 +5808,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
})
require.NoError(t, err)
certFileNew := filepath.Join(certsDir, "cert_new.pem")
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKeyNew), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKeyNew), 0600))
// cert should not change as we did not update the associated key
time.Sleep(1 * time.Second)
retry.Run(t, func(r *retry.R) {
@ -5819,8 +5818,8 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
require.Equal(r, cert1Key, cert.PrivateKey)
})
require.NoError(t, ioutil.WriteFile(certFileNew, []byte(certNew), 0600))
require.NoError(t, ioutil.WriteFile(configFile, []byte(`
require.NoError(t, os.WriteFile(certFileNew, []byte(certNew), 0600))
require.NoError(t, os.WriteFile(configFile, []byte(`
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5854,7 +5853,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
})
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKeyNew2), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKeyNew2), 0600))
// cert should not change as we did not update the associated cert
time.Sleep(1 * time.Second)
retry.Run(t, func(r *retry.R) {
@ -5864,7 +5863,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
require.Equal(r, cert2Key, cert.PrivateKey)
})
require.NoError(t, ioutil.WriteFile(certFileNew, []byte(certNew2), 0600))
require.NoError(t, os.WriteFile(certFileNew, []byte(certNew2), 0600))
// cert should change as we did update the associated key
time.Sleep(1 * time.Second)
@ -5902,9 +5901,9 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
caFile := filepath.Join(certsDir, "cacert.pem")
keyFile := filepath.Join(certsDir, "key.pem")
require.NoError(t, ioutil.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKey), 0600))
require.NoError(t, os.WriteFile(certFile, []byte(cert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKey), 0600))
// generate a gossip key
gossipKey := make([]byte, 32)
@ -5916,7 +5915,7 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
hclConfig := TestACLConfigWithParams(nil)
configFile := testutil.TempDir(t, "config") + "/config.hcl"
require.NoError(t, ioutil.WriteFile(configFile, []byte(`
require.NoError(t, os.WriteFile(configFile, []byte(`
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5952,8 +5951,8 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
})
require.NoError(t, err)
certFileNew := filepath.Join(certsDir, "cert_new.pem")
require.NoError(t, ioutil.WriteFile(certFileNew, []byte(certNew), 0600))
require.NoError(t, ioutil.WriteFile(configFile, []byte(`
require.NoError(t, os.WriteFile(certFileNew, []byte(certNew), 0600))
require.NoError(t, os.WriteFile(configFile, []byte(`
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5976,7 +5975,7 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
require.Equal(r, cert1Key, cert.PrivateKey)
})
require.NoError(t, ioutil.WriteFile(keyFile, []byte(privateKeyNew), 0600))
require.NoError(t, os.WriteFile(keyFile, []byte(privateKeyNew), 0600))
// cert should change as we did not update the associated key
time.Sleep(coalesceInterval * 2)
@ -6181,7 +6180,7 @@ cloud {
func getExpectedCaPoolByFile(t *testing.T) *x509.CertPool {
pool := x509.NewCertPool()
data, err := ioutil.ReadFile("../test/ca/root.cer")
data, err := os.ReadFile("../test/ca/root.cer")
require.NoError(t, err)
if !pool.AppendCertsFromPEM(data) {
t.Fatal("could not add test ca ../test/ca/root.cer to pool")
@ -6197,7 +6196,7 @@ func getExpectedCaPoolByDir(t *testing.T) *x509.CertPool {
for _, entry := range entries {
filename := path.Join("../test/ca_path", entry.Name())
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
require.NoError(t, err)
if !pool.AppendCertsFromPEM(data) {

4
agent/auto-config/auto_config.go

@ -3,7 +3,7 @@ package autoconf
import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"time"
@ -208,7 +208,7 @@ func (ac *AutoConfig) introToken() (string, error) {
token := conf.IntroToken
if token == "" {
// load the intro token from the file
content, err := ioutil.ReadFile(conf.IntroTokenFile)
content, err := os.ReadFile(conf.IntroTokenFile)
if err != nil {
return "", fmt.Errorf("Failed to read intro token from file: %w", err)
}

5
agent/auto-config/auto_config_test.go

@ -4,7 +4,6 @@ import (
"context"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -309,7 +308,7 @@ func TestInitialConfiguration_restored(t *testing.T) {
}
data, err := pbMarshaler.MarshalToString(response)
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(persistedFile, []byte(data), 0600))
require.NoError(t, os.WriteFile(persistedFile, []byte(data), 0600))
// recording the initial configuration even when restoring is going to update
// the agent token in the token store
@ -1139,7 +1138,7 @@ func TestIntroToken(t *testing.T) {
tokenFromFile := "8ae34d3a-8adf-446a-b236-69874597cb5b"
tokenFromConfig := "3ad9b572-ea42-4e47-9cd0-53a398a98abf"
require.NoError(t, ioutil.WriteFile(tokenFile.Name(), []byte(tokenFromFile), 0600))
require.NoError(t, os.WriteFile(tokenFile.Name(), []byte(tokenFromFile), 0600))
type testCase struct {
config *config.RuntimeConfig

5
agent/auto-config/persist.go

@ -2,7 +2,6 @@ package autoconf
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -39,7 +38,7 @@ func (ac *AutoConfig) readPersistedAutoConfig() (*pbautoconf.AutoConfigResponse,
path := filepath.Join(ac.config.DataDir, autoConfigFileName)
ac.logger.Debug("attempting to restore any persisted configuration", "path", path)
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err == nil {
rdr := strings.NewReader(string(content))
@ -75,7 +74,7 @@ func (ac *AutoConfig) persistAutoConfig(resp *pbautoconf.AutoConfigResponse) err
path := filepath.Join(ac.config.DataDir, autoConfigFileName)
err = ioutil.WriteFile(path, []byte(serialized), 0660)
err = os.WriteFile(path, []byte(serialized), 0660)
if err != nil {
return fmt.Errorf("failed to write auto-config configurations: %w", err)
}

3
agent/checks/check.go

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@ -860,7 +859,7 @@ func (c *CheckDocker) Start() {
}
if c.Logger == nil {
c.Logger = hclog.New(&hclog.LoggerOptions{Output: ioutil.Discard})
c.Logger = hclog.New(&hclog.LoggerOptions{Output: io.Discard})
}
if c.Shell == "" {

3
agent/checks/docker.go

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@ -106,7 +105,7 @@ func (c *DockerClient) call(method, uri string, v interface{}) (*circbuf.Buffer,
if err := json.NewEncoder(&b).Encode(v); err != nil {
return nil, 0, err
}
req.Body = ioutil.NopCloser(&b)
req.Body = io.NopCloser(&b)
req.Header.Set("Content-Type", "application/json")
}

6
agent/checks/grpc_test.go

@ -4,7 +4,7 @@ import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"os"
@ -110,7 +110,7 @@ func TestGRPC_Proxied(t *testing.T) {
notif := mock.NewNotify()
logger := hclog.New(&hclog.LoggerOptions{
Name: uniqueID(),
Output: ioutil.Discard,
Output: io.Discard,
})
statusHandler := NewStatusHandler(notif, logger, 0, 0, 0)
@ -144,7 +144,7 @@ func TestGRPC_NotProxied(t *testing.T) {
notif := mock.NewNotify()
logger := hclog.New(&hclog.LoggerOptions{
Name: uniqueID(),
Output: ioutil.Discard,
Output: io.Discard,
})
statusHandler := NewStatusHandler(notif, logger, 0, 0, 0)

3
agent/config/builder.go

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
@ -277,7 +276,7 @@ func (b *builder) sourcesFromPath(path string, format string) ([]Source, error)
// newSourceFromFile creates a Source from the contents of the file at path.
func newSourceFromFile(path string, format string) (Source, error) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("config: failed to read %s: %s", path, err)
}

9
agent/config/builder_test.go

@ -2,7 +2,6 @@ package config
import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -104,7 +103,7 @@ func TestNewBuilder_PopulatesSourcesFromConfigFiles_WithConfigFormat(t *testing.
// TODO: this would be much nicer with gotest.tools/fs
func setupConfigFiles(t *testing.T) []string {
t.Helper()
path, err := ioutil.TempDir("", t.Name())
path, err := os.MkdirTemp("", t.Name())
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(path) })
@ -113,13 +112,13 @@ func setupConfigFiles(t *testing.T) []string {
require.NoError(t, err)
for _, dir := range []string{path, subpath} {
err = ioutil.WriteFile(filepath.Join(dir, "a.hcl"), []byte("content a"), 0644)
err = os.WriteFile(filepath.Join(dir, "a.hcl"), []byte("content a"), 0644)
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "b.json"), []byte("content b"), 0644)
err = os.WriteFile(filepath.Join(dir, "b.json"), []byte("content b"), 0644)
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "c.yaml"), []byte("content c"), 0644)
err = os.WriteFile(filepath.Join(dir, "c.yaml"), []byte("content c"), 0644)
require.NoError(t, err)
}
return []string{

5
agent/config/golden_test.go

@ -2,7 +2,6 @@ package config
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -26,11 +25,11 @@ func golden(t *testing.T, actual, filename string) string {
if dir := filepath.Dir(path); dir != "." {
require.NoError(t, os.MkdirAll(dir, 0755))
}
err := ioutil.WriteFile(path, []byte(actual), 0644)
err := os.WriteFile(path, []byte(actual), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(path)
expected, err := os.ReadFile(path)
require.NoError(t, err)
return string(expected)
}

3
agent/config/runtime_test.go

@ -7,7 +7,6 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"net"
"net/netip"
"os"
@ -7190,7 +7189,7 @@ func writeFile(path string, data []byte) {
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
panic(err)
}
if err := ioutil.WriteFile(path, data, 0640); err != nil {
if err := os.WriteFile(path, data, 0640); err != nil {
panic(err)
}
}

6
agent/connect/ca/provider_vault.go

@ -6,7 +6,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
@ -489,7 +489,7 @@ func (v *VaultProvider) getCA(namespace, path string) (string, error) {
return "", err
}
bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
@ -518,7 +518,7 @@ func (v *VaultProvider) getCAChain(namespace, path string) (string, error) {
return "", err
}
raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

4
agent/connect/ca/provider_vault_test.go

@ -4,7 +4,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"sync/atomic"
"testing"
"time"
@ -340,7 +340,7 @@ func TestVaultCAProvider_Bootstrap(t *testing.T) {
req := client.NewRequest("GET", "/v1/"+tc.backendPath+"ca/pem")
resp, err := client.RawRequest(req)
require.NoError(t, err)
bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, cert, string(bytes)+"\n")

8
agent/connect/ca/testing.go

@ -3,7 +3,7 @@ package ca
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"strings"
@ -77,7 +77,7 @@ func CASigningKeyTypeCases() []CASigningKeyTypes {
// TestConsulProvider creates a new ConsulProvider, taking care to stub out it's
// Logger so that logging calls don't panic. If logging output is important
func TestConsulProvider(t testing.T, d ConsulProviderStateDelegate) *ConsulProvider {
logger := hclog.New(&hclog.LoggerOptions{Output: ioutil.Discard})
logger := hclog.New(&hclog.LoggerOptions{Output: io.Discard})
provider := &ConsulProvider{Delegate: d, logger: logger}
return provider
}
@ -155,8 +155,8 @@ func runTestVault(t testing.T) (*TestVaultServer, error) {
}
cmd := exec.Command(vaultBinaryName, args...)
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
if err := cmd.Start(); err != nil {
return nil, err
}

15
agent/connect/testing_ca_test.go

@ -2,7 +2,6 @@ package connect
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -34,13 +33,13 @@ func testCAAndLeaf(t *testing.T, keyType string, keyBits int) {
leaf, _ := TestLeaf(t, "web", ca)
// Create a temporary directory for storing the certs
td, err := ioutil.TempDir("", "consul")
td, err := os.MkdirTemp("", "consul")
require.NoError(t, err)
defer os.RemoveAll(td)
// Write the cert
require.NoError(t, ioutil.WriteFile(filepath.Join(td, "ca.pem"), []byte(ca.RootCert), 0644))
require.NoError(t, ioutil.WriteFile(filepath.Join(td, "leaf.pem"), []byte(leaf[:]), 0644))
require.NoError(t, os.WriteFile(filepath.Join(td, "ca.pem"), []byte(ca.RootCert), 0644))
require.NoError(t, os.WriteFile(filepath.Join(td, "leaf.pem"), []byte(leaf[:]), 0644))
// Use OpenSSL to verify so we have an external, known-working process
// that can verify this outside of our own implementations.
@ -66,7 +65,7 @@ func testCAAndLeaf_xc(t *testing.T, keyType string, keyBits int) {
leaf2, _ := TestLeaf(t, "web", ca2)
// Create a temporary directory for storing the certs
td, err := ioutil.TempDir("", "consul")
td, err := os.MkdirTemp("", "consul")
assert.Nil(t, err)
defer os.RemoveAll(td)
@ -74,9 +73,9 @@ func testCAAndLeaf_xc(t *testing.T, keyType string, keyBits int) {
xcbundle := []byte(ca1.RootCert)
xcbundle = append(xcbundle, '\n')
xcbundle = append(xcbundle, []byte(ca2.SigningCert)...)
assert.Nil(t, ioutil.WriteFile(filepath.Join(td, "ca.pem"), xcbundle, 0644))
assert.Nil(t, ioutil.WriteFile(filepath.Join(td, "leaf1.pem"), []byte(leaf1), 0644))
assert.Nil(t, ioutil.WriteFile(filepath.Join(td, "leaf2.pem"), []byte(leaf2), 0644))
assert.Nil(t, os.WriteFile(filepath.Join(td, "ca.pem"), xcbundle, 0644))
assert.Nil(t, os.WriteFile(filepath.Join(td, "leaf1.pem"), []byte(leaf1), 0644))
assert.Nil(t, os.WriteFile(filepath.Join(td, "leaf2.pem"), []byte(leaf2), 0644))
// OpenSSL verify the cross-signed leaf (leaf2)
{

4
agent/connect_ca_endpoint_test.go

@ -4,7 +4,7 @@ import (
"bytes"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
@ -287,7 +287,7 @@ func TestConnectCARoots_PEMEncoding(t *testing.T) {
resp := recorder.Result()
require.Equal(t, resp.Header.Get("Content-Type"), "application/pem-certificate-chain")
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
require.NoError(t, err)
// expecting the root cert from dc1 and an intermediate in dc2

3
agent/consul/acl_endpoint.go

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -125,7 +124,7 @@ func (a *ACL) fileBootstrapResetIndex() uint64 {
path := filepath.Join(a.srv.config.DataDir, aclBootstrapReset)
// Read the file
raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
if !os.IsNotExist(err) {
a.logger.Error("bootstrap: failed to read path",

5
agent/consul/acl_endpoint_test.go

@ -2,7 +2,6 @@ package consul
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -61,7 +60,7 @@ func TestACLEndpoint_BootstrapTokens(t *testing.T) {
require.NoError(t, err)
resetPath := filepath.Join(dir, "acl-bootstrap-reset")
require.NoError(t, ioutil.WriteFile(resetPath, []byte(fmt.Sprintf("%d", resetIdx)), 0600))
require.NoError(t, os.WriteFile(resetPath, []byte(fmt.Sprintf("%d", resetIdx)), 0600))
oldID := out.AccessorID
// Finally, make sure that another attempt is rejected.
@ -2944,7 +2943,7 @@ func TestACLEndpoint_AuthMethodSet(t *testing.T) {
t.Parallel()
tempDir, err := ioutil.TempDir("", "consul")
tempDir, err := os.MkdirTemp("", "consul")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(tempDir) })
_, srv, codec := testACLServerWithConfig(t, nil, false)

6
agent/consul/authmethod/kubeauth/testing.go

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"encoding/pem"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@ -43,7 +43,7 @@ type TestAPIServer struct {
func StartTestAPIServer(t testing.T) *TestAPIServer {
s := &TestAPIServer{}
s.srv = httptest.NewUnstartedServer(s)
s.srv.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
s.srv.Config.ErrorLog = log.New(io.Discard, "", 0)
s.srv.StartTLS()
bs := s.srv.TLS.Certificates[0].Certificate[0]
@ -162,7 +162,7 @@ func (s *TestAPIServer) handleTokenReview(w http.ResponseWriter, req *http.Reque
}
defer req.Body.Close()
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return

12
agent/consul/auto_config_endpoint_test.go

@ -8,10 +8,10 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/url"
"os"
"path"
"testing"
"time"
@ -162,15 +162,15 @@ func TestAutoConfigInitialConfiguration(t *testing.T) {
c.AutoConfigAuthzAllowReuse = true
cafile := path.Join(c.DataDir, "cacert.pem")
err := ioutil.WriteFile(cafile, []byte(cacert), 0600)
err := os.WriteFile(cafile, []byte(cacert), 0600)
require.NoError(t, err)
certfile := path.Join(c.DataDir, "cert.pem")
err = ioutil.WriteFile(certfile, []byte(cert), 0600)
err = os.WriteFile(certfile, []byte(cert), 0600)
require.NoError(t, err)
keyfile := path.Join(c.DataDir, "key.pem")
err = ioutil.WriteFile(keyfile, []byte(key), 0600)
err = os.WriteFile(keyfile, []byte(key), 0600)
require.NoError(t, err)
c.TLSConfig.InternalRPC.CAFile = cafile
@ -426,7 +426,7 @@ func TestAutoConfig_updateTLSSettingsInConfig(t *testing.T) {
dir := testutil.TempDir(t, "auto-config-tls-settings")
cafile := path.Join(dir, "cacert.pem")
err = ioutil.WriteFile(cafile, []byte(cacert), 0600)
err = os.WriteFile(cafile, []byte(cacert), 0600)
require.NoError(t, err)
type testCase struct {
@ -632,7 +632,7 @@ func TestAutoConfig_updateTLSCertificatesInConfig(t *testing.T) {
// will error if it cannot load the CA certificate from disk
dir := testutil.TempDir(t, "auto-config-tls-certificate")
cafile := path.Join(dir, "cacert.pem")
err = ioutil.WriteFile(cafile, []byte(cacert), 0600)
err = os.WriteFile(cafile, []byte(cacert), 0600)
require.NoError(t, err)
// translate the roots response to protobuf to be embedded

3
agent/consul/leader_connect_test.go

@ -4,7 +4,6 @@ import (
"context"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -1457,7 +1456,7 @@ func TestNewCARoot(t *testing.T) {
func readTestData(t *testing.T, name string) string {
t.Helper()
path := filepath.Join("testdata", name)
bs, err := ioutil.ReadFile(path)
bs, err := os.ReadFile(path)
if err != nil {
t.Fatalf("failed reading fixture file %s: %s", name, err)
}

4
agent/consul/leader_peering_test.go

@ -6,8 +6,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"testing"
"time"
@ -480,7 +480,7 @@ func TestLeader_PeeringSync_FailsForTLSError(t *testing.T) {
}, `transport: authentication handshake failed: x509: certificate is valid for server.dc1.peering.11111111-2222-3333-4444-555555555555.consul, not wrong.name`)
})
t.Run("bad-ca-roots", func(t *testing.T) {
wrongRoot, err := ioutil.ReadFile("../../test/client_certs/rootca.crt")
wrongRoot, err := os.ReadFile("../../test/client_certs/rootca.crt")
require.NoError(t, err)
testLeader_PeeringSync_failsForTLSError(t, func(token *structs.PeeringToken) {

9
agent/consul/rpc_test.go

@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"net"
"os"
@ -1390,13 +1389,13 @@ func TestRPC_AuthorizeRaftRPC(t *testing.T) {
require.NoError(t, err)
dir := testutil.TempDir(t, "certs")
err = ioutil.WriteFile(filepath.Join(dir, "ca.pem"), []byte(caPEM), 0600)
err = os.WriteFile(filepath.Join(dir, "ca.pem"), []byte(caPEM), 0600)
require.NoError(t, err)
intermediatePEM, intermediatePK, err := tlsutil.GenerateCert(tlsutil.CertOpts{IsCA: true, CA: caPEM, Signer: caSigner, Days: 5})
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, "intermediate.pem"), []byte(intermediatePEM), 0600)
err = os.WriteFile(filepath.Join(dir, "intermediate.pem"), []byte(intermediatePEM), 0600)
require.NoError(t, err)
newCert := func(t *testing.T, caPEM, pk, node, name string) {
@ -1415,9 +1414,9 @@ func TestRPC_AuthorizeRaftRPC(t *testing.T) {
})
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, node+"-"+name+".pem"), []byte(pem), 0600)
err = os.WriteFile(filepath.Join(dir, node+"-"+name+".pem"), []byte(pem), 0600)
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir, node+"-"+name+".key"), []byte(key), 0600)
err = os.WriteFile(filepath.Join(dir, node+"-"+name+".key"), []byte(key), 0600)
require.NoError(t, err)
}

3
agent/consul/server.go

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -966,7 +965,7 @@ func (s *Server) setupRaft() error {
peersFile := filepath.Join(path, "peers.json")
peersInfoFile := filepath.Join(path, "peers.info")
if _, err := os.Stat(peersInfoFile); os.IsNotExist(err) {
if err := ioutil.WriteFile(peersInfoFile, []byte(peersInfoContent), 0755); err != nil {
if err := os.WriteFile(peersInfoFile, []byte(peersInfoContent), 0755); err != nil {
return fmt.Errorf("failed to write peers.info file: %v", err)
}

3
agent/consul/snapshot_endpoint.go

@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"time"
@ -138,7 +137,7 @@ func (s *Server) dispatchSnapshotRequest(args *structs.SnapshotRequest, in io.Re
// Give the caller back an empty reader since there's nothing to
// stream back.
return ioutil.NopCloser(bytes.NewReader([]byte(""))), nil
return io.NopCloser(bytes.NewReader([]byte(""))), nil
default:
return nil, fmt.Errorf("unrecognized snapshot op %q", args.Op)

9
agent/hcp/bootstrap/bootstrap.go

@ -10,7 +10,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -219,11 +218,11 @@ func persistTLSCerts(dataDir string, bsCfg *hcp.BootstrapConfig) error {
return err
}
if err := ioutil.WriteFile(filepath.Join(dir, certFileName), []byte(bsCfg.TLSCert), 0600); err != nil {
if err := os.WriteFile(filepath.Join(dir, certFileName), []byte(bsCfg.TLSCert), 0600); err != nil {
return err
}
if err := ioutil.WriteFile(filepath.Join(dir, keyFileName), []byte(bsCfg.TLSCertKey), 0600); err != nil {
if err := os.WriteFile(filepath.Join(dir, keyFileName), []byte(bsCfg.TLSCertKey), 0600); err != nil {
return err
}
@ -256,7 +255,7 @@ func persistBootstrapConfig(dataDir, cfgJSON string) error {
// Persist the important bits we got from bootstrapping. The TLS certs are
// already persisted, just need to persist the config we are going to add.
name := filepath.Join(dataDir, subDir, configFileName)
return ioutil.WriteFile(name, []byte(cfgJSON), 0600)
return os.WriteFile(name, []byte(cfgJSON), 0600)
}
func loadPersistedBootstrapConfig(rc *config.RuntimeConfig, ui UI) (string, bool) {
@ -281,7 +280,7 @@ func loadPersistedBootstrapConfig(rc *config.RuntimeConfig, ui UI) (string, bool
}
name := filepath.Join(rc.DataDir, subDir, configFileName)
jsonBs, err := ioutil.ReadFile(name)
jsonBs, err := os.ReadFile(name)
if err != nil {
ui.Warn(fmt.Sprintf("failed to read local bootstrap config file, ignoring local files: %s", err))
return "", false

8
agent/hcp/manager_test.go

@ -1,7 +1,7 @@
package hcp
import (
"io/ioutil"
"io"
"testing"
"time"
@ -20,7 +20,7 @@ func TestManager_Run(t *testing.T) {
client.EXPECT().PushServerStatus(mock.Anything, &ServerStatus{ID: t.Name()}).Return(nil).Once()
mgr := NewManager(ManagerConfig{
Client: client,
Logger: hclog.New(&hclog.LoggerOptions{Output: ioutil.Discard}),
Logger: hclog.New(&hclog.LoggerOptions{Output: io.Discard}),
StatusFn: statusF,
})
mgr.testUpdateSent = updateCh
@ -51,7 +51,7 @@ func TestManager_SendUpdate(t *testing.T) {
client.EXPECT().PushServerStatus(mock.Anything, &ServerStatus{ID: t.Name()}).Return(nil).Twice()
mgr := NewManager(ManagerConfig{
Client: client,
Logger: hclog.New(&hclog.LoggerOptions{Output: ioutil.Discard}),
Logger: hclog.New(&hclog.LoggerOptions{Output: io.Discard}),
StatusFn: statusF,
})
mgr.testUpdateSent = updateCh
@ -81,7 +81,7 @@ func TestManager_SendUpdate_Periodic(t *testing.T) {
client.EXPECT().PushServerStatus(mock.Anything, &ServerStatus{ID: t.Name()}).Return(nil).Twice()
mgr := NewManager(ManagerConfig{
Client: client,
Logger: hclog.New(&hclog.LoggerOptions{Output: ioutil.Discard}),
Logger: hclog.New(&hclog.LoggerOptions{Output: io.Discard}),
StatusFn: statusF,
MaxInterval: time.Second,
MinInterval: 100 * time.Millisecond,

9
agent/http_test.go

@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
@ -92,7 +91,7 @@ func TestHTTPServer_UnixSocket(t *testing.T) {
}
defer resp.Body.Close()
if body, err := ioutil.ReadAll(resp.Body); err != nil || len(body) == 0 {
if body, err := io.ReadAll(resp.Body); err != nil || len(body) == 0 {
t.Fatalf("bad: %s %v", body, err)
}
}
@ -111,7 +110,7 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) {
socket := filepath.Join(tempDir, "test.sock")
// Create a regular file at the socket path
if err := ioutil.WriteFile(socket, []byte("hello world"), 0644); err != nil {
if err := os.WriteFile(socket, []byte("hello world"), 0644); err != nil {
t.Fatalf("err: %s", err)
}
fi, err := os.Stat(socket)
@ -210,7 +209,7 @@ func TestSetupHTTPServer_HTTP2(t *testing.T) {
t.Fatalf("err: %v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -738,7 +737,7 @@ func testPrettyPrint(pretty string, t *testing.T) {
expected, _ := json.MarshalIndent(r, "", " ")
expected = append(expected, "\n"...)
actual, err := ioutil.ReadAll(resp.Body)
actual, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("err: %s", err)
}

3
agent/keyring.go

@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -186,7 +185,7 @@ func loadKeyringFile(c *serf.Config) error {
return err
}
keyringData, err := ioutil.ReadFile(c.KeyringFile)
keyringData, err := os.ReadFile(c.KeyringFile)
if err != nil {
return err
}

6
agent/keyring_test.go

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -267,7 +267,7 @@ func TestAgent_InitKeyring(t *testing.T) {
t.Fatalf("err: %s", err)
}
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -281,7 +281,7 @@ func TestAgent_InitKeyring(t *testing.T) {
}
// Content should still be the same
content, err = ioutil.ReadFile(file)
content, err = os.ReadFile(file)
if err != nil {
t.Fatalf("err: %s", err)
}

8
agent/metrics_test.go

@ -4,9 +4,9 @@ import (
"context"
"crypto/x509"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
@ -337,7 +337,7 @@ func TestHTTPHandlers_AgentMetrics_TLSCertExpiry_Prometheus(t *testing.T) {
require.NoError(t, err)
caPath := filepath.Join(dir, "ca.pem")
err = ioutil.WriteFile(caPath, []byte(caPEM), 0600)
err = os.WriteFile(caPath, []byte(caPEM), 0600)
require.NoError(t, err)
signer, err := tlsutil.ParseSigner(caPK)
@ -353,11 +353,11 @@ func TestHTTPHandlers_AgentMetrics_TLSCertExpiry_Prometheus(t *testing.T) {
require.NoError(t, err)
certPath := filepath.Join(dir, "cert.pem")
err = ioutil.WriteFile(certPath, []byte(pem), 0600)
err = os.WriteFile(certPath, []byte(pem), 0600)
require.NoError(t, err)
keyPath := filepath.Join(dir, "cert.key")
err = ioutil.WriteFile(keyPath, []byte(key), 0600)
err = os.WriteFile(keyPath, []byte(key), 0600)
require.NoError(t, err)
hcl := fmt.Sprintf(`

5
agent/nodeid.go

@ -3,7 +3,6 @@ package agent
import (
"crypto/sha512"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -36,7 +35,7 @@ func newNodeIDFromConfig(config *config.RuntimeConfig, logger hclog.Logger) (typ
// Load saved state, if any. Since a user could edit this, we also validate it.
filename := filepath.Join(config.DataDir, "node-id")
if _, err := os.Stat(filename); err == nil {
rawID, err := ioutil.ReadFile(filename)
rawID, err := os.ReadFile(filename)
if err != nil {
return "", err
}
@ -56,7 +55,7 @@ func newNodeIDFromConfig(config *config.RuntimeConfig, logger hclog.Logger) (typ
if err := lib.EnsurePath(filename, false); err != nil {
return "", err
}
if err := ioutil.WriteFile(filename, []byte(id), 0600); err != nil {
if err := os.WriteFile(filename, []byte(id), 0600); err != nil {
return "", fmt.Errorf("failed to write NodeID to disk: %w", err)
}
return types.NodeID(id), nil

6
agent/nodeid_test.go

@ -2,7 +2,7 @@ package agent
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -59,7 +59,7 @@ func TestNewNodeIDFromConfig(t *testing.T) {
t.Run("invalid NodeID in file", func(t *testing.T) {
cfg.NodeID = ""
filename := filepath.Join(cfg.DataDir, "node-id")
err := ioutil.WriteFile(filename, []byte("adf4238a!882b!9ddc!4a9d!5b6758e4159e"), 0600)
err := os.WriteFile(filename, []byte("adf4238a!882b!9ddc!4a9d!5b6758e4159e"), 0600)
require.NoError(t, err)
_, err = newNodeIDFromConfig(cfg, logger)
@ -70,7 +70,7 @@ func TestNewNodeIDFromConfig(t *testing.T) {
t.Run("valid NodeID in file", func(t *testing.T) {
cfg.NodeID = ""
filename := filepath.Join(cfg.DataDir, "node-id")
err := ioutil.WriteFile(filename, []byte("ADF4238a-882b-9ddc-4a9d-5b6758e4159e"), 0600)
err := os.WriteFile(filename, []byte("ADF4238a-882b-9ddc-4a9d-5b6758e4159e"), 0600)
require.NoError(t, err)
nodeID, err := newNodeIDFromConfig(cfg, logger)

6
agent/pool/peek_test.go

@ -5,7 +5,7 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"testing"
"time"
@ -55,7 +55,7 @@ func TestPeekForTLS_not_TLS(t *testing.T) {
require.NoError(t, err)
require.False(t, isTLS)
all, err := ioutil.ReadAll(wrapped)
all, err := io.ReadAll(wrapped)
require.NoError(t, err)
require.Equal(t, tc.connData, all)
})
@ -160,7 +160,7 @@ func testPeekForTLS_withTLS(t *testing.T, connData []byte) {
return
}
all, err := ioutil.ReadAll(tlsConn)
all, err := io.ReadAll(tlsConn)
if err != nil {
serverErrCh <- err
return

4
agent/proxycfg/testing.go

@ -3,7 +3,7 @@ package proxycfg
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
@ -923,7 +923,7 @@ func golden(t testing.T, name string) string {
t.Helper()
golden := filepath.Join(projectRoot(), "../", "/xds/testdata", name+".golden")
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
return string(expected)

3
agent/remote_exec.go

@ -3,7 +3,6 @@ package agent
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
osexec "os/exec"
"path"
@ -145,7 +144,7 @@ func (a *Agent) handleRemoteExec(msg *UserEvent) {
// Check if this is a script, we may need to spill to disk
var script string
if len(spec.Script) != 0 {
tmpFile, err := ioutil.TempFile("", "rexec")
tmpFile, err := os.CreateTemp("", "rexec")
if err != nil {
a.logger.Debug("failed to make tmp file", "error", err)
exitCode = 255

8
agent/routine-leak-checker/leak_test.go

@ -2,7 +2,7 @@ package leakcheck
import (
"crypto/x509"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -51,9 +51,9 @@ func setupPrimaryServer(t *testing.T) *agent.TestAgent {
keyPath := filepath.Join(d, "key.pem")
caPath := filepath.Join(d, "cacert.pem")
require.NoError(t, ioutil.WriteFile(certPath, []byte(certPEM), 0600))
require.NoError(t, ioutil.WriteFile(keyPath, []byte(keyPEM), 0600))
require.NoError(t, ioutil.WriteFile(caPath, []byte(caPEM), 0600))
require.NoError(t, os.WriteFile(certPath, []byte(certPEM), 0600))
require.NoError(t, os.WriteFile(keyPath, []byte(keyPEM), 0600))
require.NoError(t, os.WriteFile(caPath, []byte(caPEM), 0600))
aclParams := agent.DefaultTestACLConfigParams()
aclParams.PrimaryDatacenter = "primary"

6
agent/rpc/peering/service_test.go

@ -5,8 +5,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"net"
"os"
"path"
"testing"
"time"
@ -69,7 +69,7 @@ func TestPeeringService_GenerateToken(t *testing.T) {
signer, _, _ := tlsutil.GeneratePrivateKey()
ca, _, _ := tlsutil.GenerateCA(tlsutil.CAOpts{Signer: signer})
cafile := path.Join(dir, "cacert.pem")
require.NoError(t, ioutil.WriteFile(cafile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(cafile, []byte(ca), 0600))
// TODO(peering): see note on newTestServer, refactor to not use this
s := newTestServer(t, func(c *consul.Config) {
@ -181,7 +181,7 @@ func TestPeeringService_GenerateTokenExternalAddress(t *testing.T) {
signer, _, _ := tlsutil.GeneratePrivateKey()
ca, _, _ := tlsutil.GenerateCA(tlsutil.CAOpts{Signer: signer})
cafile := path.Join(dir, "cacert.pem")
require.NoError(t, ioutil.WriteFile(cafile, []byte(ca), 0600))
require.NoError(t, os.WriteFile(cafile, []byte(ca), 0600))
// TODO(peering): see note on newTestServer, refactor to not use this
s := newTestServer(t, func(c *consul.Config) {

3
agent/service_manager_test.go

@ -3,7 +3,6 @@ package agent
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -802,7 +801,7 @@ func expectJSONFile(t *testing.T, file string, expect interface{}, fixupContentB
expected, err := json.Marshal(expect)
require.NoError(t, err)
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
require.NoError(t, err)
if fixupContentBeforeCompareFn != nil {

3
agent/token/persistence.go

@ -3,7 +3,6 @@ package token
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -142,7 +141,7 @@ func readPersistedFromFile(filename string) (persistedTokens, error) {
LegacyAgentMaster string `json:"agent_master"`
}
buf, err := ioutil.ReadFile(filename)
buf, err := os.ReadFile(filename)
switch {
case os.IsNotExist(err):
// non-existence is not an error we care about

14
agent/token/persistence_test.go

@ -1,7 +1,7 @@
package token
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -63,7 +63,7 @@ func TestStore_Load(t *testing.T) {
"replication" : "lima"
}`
require.NoError(t, ioutil.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, os.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, store.Load(cfg, logger))
// no updates since token persistence is not enabled
@ -92,7 +92,7 @@ func TestStore_Load(t *testing.T) {
}
tokens := `{"agent_master": "juliett"}`
require.NoError(t, ioutil.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, os.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, store.Load(cfg, logger))
require.Equal(t, "juliett", store.AgentRecoveryToken())
@ -115,7 +115,7 @@ func TestStore_Load(t *testing.T) {
ACLReplicationToken: "tango",
}
require.NoError(t, ioutil.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, os.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, store.Load(cfg, logger))
require.Equal(t, "mike", store.AgentToken())
@ -139,7 +139,7 @@ func TestStore_Load(t *testing.T) {
ACLReplicationToken: "zulu",
}
require.NoError(t, ioutil.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, os.WriteFile(tokenFile, []byte(tokens), 0600))
require.NoError(t, store.Load(cfg, logger))
require.Equal(t, "uniform", store.AgentToken())
@ -158,7 +158,7 @@ func TestStore_Load(t *testing.T) {
ACLReplicationToken: "four",
}
require.NoError(t, ioutil.WriteFile(tokenFile, []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 0600))
require.NoError(t, os.WriteFile(tokenFile, []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 0600))
err := store.Load(cfg, logger)
require.Error(t, err)
require.Contains(t, err.Error(), "failed to decode tokens file")
@ -179,7 +179,7 @@ func TestStore_Load(t *testing.T) {
ACLReplicationToken: "foxtrot",
}
require.NoError(t, ioutil.WriteFile(tokenFile, []byte("[1,2,3]"), 0600))
require.NoError(t, os.WriteFile(tokenFile, []byte("[1,2,3]"), 0600))
err := store.Load(cfg, logger)
require.Error(t, err)
require.Contains(t, err.Error(), "failed to decode tokens file")

4
agent/ui_endpoint_test.go

@ -6,10 +6,10 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"sync/atomic"
"testing"
@ -49,7 +49,7 @@ func TestUIIndex(t *testing.T) {
// Create file
path := filepath.Join(a.Config.UIConfig.Dir, "my-file")
if err := ioutil.WriteFile(path, []byte("test"), 0644); err != nil {
if err := os.WriteFile(path, []byte("test"), 0644); err != nil {
t.Fatalf("err: %v", err)
}

5
agent/uiserver/uiserver_test.go

@ -3,7 +3,6 @@ package uiserver
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -380,7 +379,7 @@ func TestCustomDir(t *testing.T) {
defer os.RemoveAll(uiDir)
path := filepath.Join(uiDir, "test-file")
require.NoError(t, ioutil.WriteFile(path, []byte("test"), 0644))
require.NoError(t, os.WriteFile(path, []byte("test"), 0644))
cfg := basicUIEnabledConfig()
cfg.UIConfig.Dir = uiDir
@ -427,7 +426,7 @@ func TestCompiledJS(t *testing.T) {
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, rec.Result().Header["Content-Type"][0], "application/javascript")
wantCompiled, err := ioutil.ReadFile("testdata/compiled-metrics-providers-golden.js")
wantCompiled, err := os.ReadFile("testdata/compiled-metrics-providers-golden.js")
require.NoError(t, err)
require.Equal(t, rec.Body.String(), string(wantCompiled))
})

8
agent/watch_handler_test.go

@ -1,7 +1,7 @@
package agent
import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
@ -20,14 +20,14 @@ func TestMakeWatchHandler(t *testing.T) {
script := "bash -c 'echo $CONSUL_INDEX >> handler_index_out && cat >> handler_out'"
handler := makeWatchHandler(testutil.Logger(t), script)
handler(100, []string{"foo", "bar", "baz"})
raw, err := ioutil.ReadFile("handler_out")
raw, err := os.ReadFile("handler_out")
if err != nil {
t.Fatalf("err: %v", err)
}
if string(raw) != "[\"foo\",\"bar\",\"baz\"]\n" {
t.Fatalf("bad: %s", raw)
}
raw, err = ioutil.ReadFile("handler_index_out")
raw, err = os.ReadFile("handler_index_out")
if err != nil {
t.Fatalf("err: %v", err)
}
@ -47,7 +47,7 @@ func TestMakeHTTPWatchHandler(t *testing.T) {
if customHeader != "abc" {
t.Fatalf("bad: %s", idx)
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("err: %v", err)
}

9
agent/xds/golden_test.go

@ -3,7 +3,6 @@ package xds
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -88,7 +87,7 @@ func golden(t *testing.T, name, subname, latestSubname, got string) string {
latestExpected := ""
if latestSubname != "" && subname != latestSubname {
latestGolden := filepath.Join("testdata", fmt.Sprintf("%s.%s.golden", name, latestSubname))
raw, err := ioutil.ReadFile(latestGolden)
raw, err := os.ReadFile(latestGolden)
require.NoError(t, err, "%q %q %q", name, subname, latestSubname)
latestExpected = string(raw)
}
@ -110,11 +109,11 @@ func golden(t *testing.T, name, subname, latestSubname, got string) string {
return got
}
require.NoError(t, ioutil.WriteFile(golden, []byte(got), 0644))
require.NoError(t, os.WriteFile(golden, []byte(got), 0644))
return got
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
if latestExpected != "" && os.IsNotExist(err) {
// In readonly mode if a specific golden file isn't found, we fallback
// on the latest one.
@ -127,7 +126,7 @@ func golden(t *testing.T, name, subname, latestSubname, got string) string {
func loadTestResource(t *testing.T, name string) string {
t.Helper()
expected, err := ioutil.ReadFile(filepath.Join("testdata", name+".golden"))
expected, err := os.ReadFile(filepath.Join("testdata", name+".golden"))
require.NoError(t, err)
return string(expected)
}

5
api/acl.go

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/url"
"time"
@ -1047,7 +1046,7 @@ func (a *ACL) RulesTranslate(rules io.Reader) (string, error) {
parseQueryMeta(resp, qm)
qm.RequestTime = rtt
ruleBytes, err := ioutil.ReadAll(resp.Body)
ruleBytes, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Failed to read translated rule body: %v", err)
}
@ -1074,7 +1073,7 @@ func (a *ACL) RulesTranslateToken(tokenID string) (string, error) {
parseQueryMeta(resp, qm)
qm.RequestTime = rtt
ruleBytes, err := ioutil.ReadAll(resp.Body)
ruleBytes, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Failed to read translated rule body: %v", err)
}

3
api/agent_test.go

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/http/httputil"
@ -104,7 +103,7 @@ func TestAPI_AgentReload(t *testing.T) {
// Update the config file with a service definition
config := `{"service":{"name":"redis", "port":1234, "Meta": {"some": "meta"}}}`
err = ioutil.WriteFile(configFile.Name(), []byte(config), 0644)
err = os.WriteFile(configFile.Name(), []byte(config), 0644)
if err != nil {
t.Fatalf("err: %v", err)
}

9
api/api_test.go

@ -5,7 +5,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
@ -618,15 +617,15 @@ func TestAPI_SetupTLSConfig(t *testing.T) {
assertDeepEqual(t, expectedCaPoolByDir, cc.RootCAs, cmpCertPool)
// Load certs in-memory
certPEM, err := ioutil.ReadFile("../test/hostname/Alice.crt")
certPEM, err := os.ReadFile("../test/hostname/Alice.crt")
if err != nil {
t.Fatalf("err: %v", err)
}
keyPEM, err := ioutil.ReadFile("../test/hostname/Alice.key")
keyPEM, err := os.ReadFile("../test/hostname/Alice.key")
if err != nil {
t.Fatalf("err: %v", err)
}
caPEM, err := ioutil.ReadFile("../test/hostname/CertAuth.crt")
caPEM, err := os.ReadFile("../test/hostname/CertAuth.crt")
if err != nil {
t.Fatalf("err: %v", err)
}
@ -1191,7 +1190,7 @@ func getExpectedCaPoolByDir(t *testing.T) *x509.CertPool {
for _, entry := range entries {
filename := path.Join("../test/ca_path", entry.Name())
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
require.NoError(t, err)
if !pool.AppendCertsFromPEM(data) {

31
api/go.mod

@ -1,6 +1,6 @@
module github.com/hashicorp/consul/api
go 1.12
go 1.18
replace github.com/hashicorp/consul/sdk => ../sdk
@ -10,15 +10,36 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-hclog v0.12.0
github.com/hashicorp/go-rootcerts v1.0.2
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.10.1
github.com/mitchellh/mapstructure v1.4.1
github.com/stretchr/testify v1.7.0
)
require (
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.3 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/miekg/dns v1.1.41 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/stretchr/objx v0.1.0 // indirect
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

6
api/go.sum

@ -47,7 +47,6 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR
github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0=
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@ -77,7 +76,6 @@ github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxd
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -118,8 +116,6 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@ -135,8 +131,6 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1N
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

3
api/mock_api_test.go

@ -3,7 +3,6 @@ package api
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
@ -39,7 +38,7 @@ func (m *mockAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var body interface{}
if r.Body != nil {
bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err == nil && len(bodyBytes) > 0 {
body = bodyBytes

4
api/operator_license.go

@ -1,7 +1,7 @@
package api
import (
"io/ioutil"
"io"
"strings"
"time"
)
@ -71,7 +71,7 @@ func (op *Operator) LicenseGetSigned(q *QueryOptions) (string, error) {
return "", err
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

6
command/acl/authmethod/create/authmethod_create_test.go

@ -3,7 +3,7 @@ package authmethodcreate
import (
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -468,7 +468,7 @@ func TestAuthMethodCreateCommand_k8s(t *testing.T) {
})
caFile := filepath.Join(testDir, "ca.crt")
require.NoError(t, ioutil.WriteFile(caFile, []byte(ca.RootCert), 0600))
require.NoError(t, os.WriteFile(caFile, []byte(ca.RootCert), 0600))
t.Run("create k8s with cert file", func(t *testing.T) {
name := getTestName(t)
@ -540,7 +540,7 @@ func TestAuthMethodCreateCommand_config(t *testing.T) {
name := getTestName(t)
configFile := filepath.Join(testDir, "config.json")
jsonConfig := `{"SessionID":"foo"}`
require.NoError(t, ioutil.WriteFile(configFile, []byte(jsonConfig), 0644))
require.NoError(t, os.WriteFile(configFile, []byte(jsonConfig), 0644))
args := []string{
"-http-addr=" + a.HTTPAddr(),

8
command/acl/authmethod/update/authmethod_update_test.go

@ -3,7 +3,7 @@ package authmethodupdate
import (
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -455,7 +455,7 @@ func TestAuthMethodUpdateCommand_k8s(t *testing.T) {
})
ca2File := filepath.Join(testDir, "ca2.crt")
require.NoError(t, ioutil.WriteFile(ca2File, []byte(ca2.RootCert), 0600))
require.NoError(t, os.WriteFile(ca2File, []byte(ca2.RootCert), 0600))
t.Run("update all fields with cert file", func(t *testing.T) {
name := createAuthMethod(t)
@ -750,7 +750,7 @@ func TestAuthMethodUpdateCommand_k8s_noMerge(t *testing.T) {
})
ca2File := filepath.Join(testDir, "ca2.crt")
require.NoError(t, ioutil.WriteFile(ca2File, []byte(ca2.RootCert), 0600))
require.NoError(t, os.WriteFile(ca2File, []byte(ca2.RootCert), 0600))
t.Run("update all fields with cert file", func(t *testing.T) {
name := createAuthMethod(t)
@ -849,7 +849,7 @@ func TestAuthMethodUpdateCommand_config(t *testing.T) {
methodName := createAuthMethod(t)
configFile := filepath.Join(testDir, "config.json")
jsonConfig := `{"SessionID":"update"}`
require.NoError(t, ioutil.WriteFile(configFile, []byte(jsonConfig), 0644))
require.NoError(t, os.WriteFile(configFile, []byte(jsonConfig), 0644))
args := []string{
"-http-addr=" + a.HTTPAddr(),

6
command/acl/policy/create/policy_create_test.go

@ -2,7 +2,7 @@ package policycreate
import (
"encoding/json"
"io/ioutil"
"os"
"strings"
"testing"
@ -47,7 +47,7 @@ func TestPolicyCreateCommand(t *testing.T) {
cmd := New(ui)
rules := []byte("service \"\" { policy = \"write\" }")
err := ioutil.WriteFile(testDir+"/rules.hcl", rules, 0644)
err := os.WriteFile(testDir+"/rules.hcl", rules, 0644)
require.NoError(t, err)
args := []string{
@ -87,7 +87,7 @@ func TestPolicyCreateCommand_JSON(t *testing.T) {
cmd := New(ui)
rules := []byte("service \"\" { policy = \"write\" }")
err := ioutil.WriteFile(testDir+"/rules.hcl", rules, 0644)
err := os.WriteFile(testDir+"/rules.hcl", rules, 0644)
require.NoError(t, err)
args := []string{

6
command/acl/policy/update/policy_update_test.go

@ -2,7 +2,7 @@ package policyupdate
import (
"encoding/json"
"io/ioutil"
"os"
"strings"
"testing"
@ -47,7 +47,7 @@ func TestPolicyUpdateCommand(t *testing.T) {
cmd := New(ui)
rules := []byte("service \"\" { policy = \"write\" }")
err := ioutil.WriteFile(testDir+"/rules.hcl", rules, 0644)
err := os.WriteFile(testDir+"/rules.hcl", rules, 0644)
assert.NoError(t, err)
// Create a policy
@ -97,7 +97,7 @@ func TestPolicyUpdateCommand_JSON(t *testing.T) {
cmd := New(ui)
rules := []byte("service \"\" { policy = \"write\" }")
err := ioutil.WriteFile(testDir+"/rules.hcl", rules, 0644)
err := os.WriteFile(testDir+"/rules.hcl", rules, 0644)
assert.NoError(t, err)
// Create a policy

6
command/acl/role/formatter_test.go

@ -3,7 +3,7 @@ package role
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
@ -22,11 +22,11 @@ func golden(t *testing.T, name, got string) string {
golden := filepath.Join("testdata", name+".golden")
if *update && got != "" {
err := ioutil.WriteFile(golden, []byte(got), 0644)
err := os.WriteFile(golden, []byte(got), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
return string(expected)

4
command/acl/rules/translate_test.go

@ -2,7 +2,7 @@ package rules
import (
"io"
"io/ioutil"
"os"
"strings"
"testing"
@ -52,7 +52,7 @@ func TestRulesTranslateCommand(t *testing.T) {
// From a file
t.Run("file", func(t *testing.T) {
err := ioutil.WriteFile(testDir+"/rules.hcl", []byte(rules), 0644)
err := os.WriteFile(testDir+"/rules.hcl", []byte(rules), 0644)
require.NoError(t, err)
args := []string{

6
command/acl/token/formatter_test.go

@ -3,7 +3,7 @@ package token
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
@ -23,11 +23,11 @@ func golden(t *testing.T, name, got string) string {
golden := filepath.Join("testdata", name+".golden")
if *update && got != "" {
err := ioutil.WriteFile(golden, []byte(got), 0644)
err := os.WriteFile(golden, []byte(got), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
return string(expected)

4
command/agent/agent.go

@ -4,7 +4,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"os/signal"
"path/filepath"
@ -218,7 +218,7 @@ func (c *cmd) run(args []string) int {
if config.Logging.LogJSON {
// Hide all non-error output when JSON logging is enabled.
ui.Ui = &cli.BasicUI{
BasicUi: mcli.BasicUi{ErrorWriter: c.ui.Stderr(), Writer: ioutil.Discard},
BasicUi: mcli.BasicUi{ErrorWriter: c.ui.Stderr(), Writer: io.Discard},
}
}

4
command/connect/ca/set/connect_ca_set.go

@ -4,7 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags"
@ -66,7 +66,7 @@ func (c *cmd) Run(args []string) int {
return 1
}
bytes, err := ioutil.ReadFile(c.configFile.String())
bytes, err := os.ReadFile(c.configFile.String())
if err != nil {
c.UI.Error(fmt.Sprintf("Error reading config file: %s", err))
return 1

7
command/connect/envoy/envoy_test.go

@ -3,7 +3,6 @@ package envoy
import (
"encoding/json"
"flag"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
@ -998,7 +997,7 @@ func TestGenerateConfig(t *testing.T) {
if len(tc.Files) > 0 {
for fn, fv := range tc.Files {
fullname := filepath.Join(testDir, fn)
require.NoError(t, ioutil.WriteFile(fullname, []byte(fv), 0600))
require.NoError(t, os.WriteFile(fullname, []byte(fv), 0600))
}
}
@ -1049,10 +1048,10 @@ func TestGenerateConfig(t *testing.T) {
// If we got the arg handling write, verify output
golden := filepath.Join("testdata", tc.Name+".golden")
if *update {
ioutil.WriteFile(golden, actual, 0644)
os.WriteFile(golden, actual, 0644)
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
require.Equal(t, string(expected), string(actual))
})

3
command/connect/envoy/exec_test.go

@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
@ -234,7 +233,7 @@ func TestHelperProcess(t *testing.T) {
os.Exit(1)
}
d, err := ioutil.ReadFile(data.ConfigPath)
d, err := os.ReadFile(data.ConfigPath)
if err != nil {
fmt.Fprintf(os.Stderr, "could not read provided --config-path file %q: %v\n", data.ConfigPath, err)
os.Exit(1)

4
command/flags/http.go

@ -2,7 +2,7 @@ package flags
import (
"flag"
"io/ioutil"
"os"
"strings"
"github.com/hashicorp/consul/api"
@ -131,7 +131,7 @@ func (f *HTTPFlags) ReadTokenFile() (string, error) {
return "", nil
}
data, err := ioutil.ReadFile(tokenFile)
data, err := os.ReadFile(tokenFile)
if err != nil {
return "", err
}

3
command/helpers/helpers.go

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"time"
@ -15,7 +14,7 @@ import (
)
func loadFromFile(path string) (string, error) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return "", fmt.Errorf("Failed to read file: %v", err)
}

3
command/kv/imp/kv_import.go

@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path"
@ -123,7 +122,7 @@ func (c *cmd) dataFromArgs(args []string) (string, error) {
switch data[0] {
case '@':
data, err := ioutil.ReadFile(data[1:])
data, err := os.ReadFile(data[1:])
if err != nil {
return "", fmt.Errorf("Failed to read file: %s", err)
}

18
command/lock/lock_test.go

@ -1,7 +1,7 @@
package lock
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -63,7 +63,7 @@ func TestLockCommand(t *testing.T) {
}
// Check for the file
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -92,7 +92,7 @@ func TestLockCommand_NoShell(t *testing.T) {
}
// Check for the file
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -121,7 +121,7 @@ func TestLockCommand_TryLock(t *testing.T) {
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -159,7 +159,7 @@ func TestLockCommand_TrySemaphore(t *testing.T) {
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -197,7 +197,7 @@ func TestLockCommand_MonitorRetry_Lock_Default(t *testing.T) {
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -236,7 +236,7 @@ func TestLockCommand_MonitorRetry_Semaphore_Default(t *testing.T) {
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -275,7 +275,7 @@ func TestLockCommand_MonitorRetry_Lock_Arg(t *testing.T) {
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -314,7 +314,7 @@ func TestLockCommand_MonitorRetry_Semaphore_Arg(t *testing.T) {
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
_, err := ioutil.ReadFile(filePath)
_, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("err: %v", err)
}

4
command/login/login.go

@ -3,7 +3,7 @@ package login
import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/hashicorp/consul/api"
@ -112,7 +112,7 @@ func (c *cmd) bearerTokenLogin() int {
c.UI.Error("Missing required '-bearer-token-file' flag")
return 1
} else {
data, err := ioutil.ReadFile(c.bearerTokenFile)
data, err := os.ReadFile(c.bearerTokenFile)
if err != nil {
c.UI.Error(err.Error())
return 1

17
command/login/login_test.go

@ -2,7 +2,6 @@ package login
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -173,7 +172,7 @@ func TestLoginCommand(t *testing.T) {
t.Run("bearer-token-file is empty", func(t *testing.T) {
defer os.Remove(tokenSinkFile)
require.NoError(t, ioutil.WriteFile(bearerTokenFile, []byte(""), 0600))
require.NoError(t, os.WriteFile(bearerTokenFile, []byte(""), 0600))
ui := cli.NewMockUi()
cmd := New(ui)
@ -191,7 +190,7 @@ func TestLoginCommand(t *testing.T) {
require.Contains(t, ui.ErrorWriter.String(), "No bearer token found in")
})
require.NoError(t, ioutil.WriteFile(bearerTokenFile, []byte("demo-token"), 0600))
require.NoError(t, os.WriteFile(bearerTokenFile, []byte("demo-token"), 0600))
t.Run("try login with no method configured", func(t *testing.T) {
defer os.Remove(tokenSinkFile)
@ -285,7 +284,7 @@ func TestLoginCommand(t *testing.T) {
require.Empty(t, ui.ErrorWriter.String())
require.Empty(t, ui.OutputWriter.String())
raw, err := ioutil.ReadFile(tokenSinkFile)
raw, err := os.ReadFile(tokenSinkFile)
require.NoError(t, err)
token := strings.TrimSpace(string(raw))
@ -309,7 +308,7 @@ func TestLoginCommand_k8s(t *testing.T) {
bearerTokenFile := filepath.Join(testDir, "bearer.token")
// the "B" jwt will be the one being reviewed
require.NoError(t, ioutil.WriteFile(bearerTokenFile, []byte(acl.TestKubernetesJWT_B), 0600))
require.NoError(t, os.WriteFile(bearerTokenFile, []byte(acl.TestKubernetesJWT_B), 0600))
// spin up a fake api server
testSrv := kubeauth.StartTestAPIServer(t)
@ -372,7 +371,7 @@ func TestLoginCommand_k8s(t *testing.T) {
require.Empty(t, ui.ErrorWriter.String())
require.Empty(t, ui.OutputWriter.String())
raw, err := ioutil.ReadFile(tokenSinkFile)
raw, err := os.ReadFile(tokenSinkFile)
require.NoError(t, err)
token := strings.TrimSpace(string(raw))
@ -487,7 +486,7 @@ func TestLoginCommand_jwt(t *testing.T) {
// Drop a JWT on disk.
jwtData, err := oidcauthtest.SignJWT(privKey, cl, privateCl)
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(bearerTokenFile, []byte(jwtData), 0600))
require.NoError(t, os.WriteFile(bearerTokenFile, []byte(jwtData), 0600))
defer os.Remove(tokenSinkFile)
ui := cli.NewMockUi()
@ -506,7 +505,7 @@ func TestLoginCommand_jwt(t *testing.T) {
require.Empty(t, ui.ErrorWriter.String())
require.Empty(t, ui.OutputWriter.String())
raw, err := ioutil.ReadFile(tokenSinkFile)
raw, err := os.ReadFile(tokenSinkFile)
require.NoError(t, err)
token := strings.TrimSpace(string(raw))
@ -660,7 +659,7 @@ func TestLoginCommand_aws_iam(t *testing.T) {
code := cmd.Run(args)
require.Equal(t, 0, code, ui.ErrorWriter.String())
raw, err := ioutil.ReadFile(tokenSinkFile)
raw, err := os.ReadFile(tokenSinkFile)
require.NoError(t, err)
token := strings.TrimSpace(string(raw))

3
command/logout/logout_test.go

@ -225,9 +225,6 @@ func TestLogoutCommand_k8s(t *testing.T) {
require.Contains(t, ui.ErrorWriter.String(), "403 (Permission denied: token wasn't created via login)")
})
// go to the trouble of creating a login token
// require.NoError(t, ioutil.WriteFile(bearerTokenFile, []byte(acl.TestKubernetesJWT_B), 0600))
// spin up a fake api server
testSrv := kubeauth.StartTestAPIServer(t)
defer testSrv.Stop()

8
command/operator/autopilot/state/operator_autopilot_state_test.go

@ -3,7 +3,7 @@ package state
import (
"encoding/json"
"flag"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -25,11 +25,11 @@ func golden(t *testing.T, name, got string) string {
golden := filepath.Join("testdata", name+".golden")
if *update && got != "" {
err := ioutil.WriteFile(golden, []byte(got), 0644)
err := os.WriteFile(golden, []byte(got), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
return string(expected)
@ -111,7 +111,7 @@ func TestStateCommand_Formatter(t *testing.T) {
for _, name := range cases {
t.Run(name, func(t *testing.T) {
statePath := filepath.Join("testdata", name, "state.json")
input, err := ioutil.ReadFile(statePath)
input, err := os.ReadFile(statePath)
require.NoError(t, err)
var state api.AutopilotState

3
command/snapshot/inspect/snapshot_inspect.go

@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"sort"
@ -123,7 +122,7 @@ func (c *cmd) Run(args []string) int {
readFile = f
// Assume the meta is colocated and error if not.
metaRaw, err := ioutil.ReadFile(path.Join(path.Dir(file), "meta.json"))
metaRaw, err := os.ReadFile(path.Join(path.Dir(file), "meta.json"))
if err != nil {
c.UI.Error(fmt.Sprintf("Error reading meta.json from internal snapshot dir: %s", err))
return 1

6
command/snapshot/inspect/snapshot_inspect_test.go

@ -2,7 +2,7 @@ package inspect
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -21,11 +21,11 @@ func golden(t *testing.T, name, got string) string {
golden := filepath.Join("testdata", name+".golden")
if *update && got != "" {
err := ioutil.WriteFile(golden, []byte(got), 0644)
err := os.WriteFile(golden, []byte(got), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
return string(expected)

5
command/snapshot/restore/snapshot_restore_test.go

@ -4,7 +4,6 @@ import (
"crypto/rand"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -135,7 +134,7 @@ func TestSnapshotRestoreCommand_TruncatedSnapshot(t *testing.T) {
require.NoError(t, err)
defer rc.Close()
inputData, err = ioutil.ReadAll(rc)
inputData, err = io.ReadAll(rc)
require.NoError(t, err)
}
@ -150,7 +149,7 @@ func TestSnapshotRestoreCommand_TruncatedSnapshot(t *testing.T) {
c := New(ui)
file := filepath.Join(dir, "backup.tgz")
require.NoError(t, ioutil.WriteFile(file, data, 0644))
require.NoError(t, os.WriteFile(file, data, 0644))
args := []string{
"-http-addr=" + a.HTTPAddr(),
file,

4
command/snapshot/save/snapshot_save_test.go

@ -3,7 +3,7 @@ package save
import (
"crypto/rand"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
@ -136,7 +136,7 @@ func TestSnapshotSaveCommand_TruncatedStream(t *testing.T) {
require.NoError(t, err)
defer rc.Close()
inputData, err = ioutil.ReadAll(rc)
inputData, err = io.ReadAll(rc)
require.NoError(t, err)
}

5
command/tls/ca/create/tls_ca_create_test.go

@ -4,7 +4,6 @@ import (
"crypto"
"crypto/x509"
"io/fs"
"io/ioutil"
"os"
"strings"
"testing"
@ -130,9 +129,9 @@ func expectFiles(t *testing.T, caPath, keyPath string) (*x509.Certificate, crypt
t.Fatalf("private key file %s: permissions: want: %o; have: %o", keyPath, want, have)
}
caData, err := ioutil.ReadFile(caPath)
caData, err := os.ReadFile(caPath)
require.NoError(t, err)
keyData, err := ioutil.ReadFile(keyPath)
keyData, err := os.ReadFile(keyPath)
require.NoError(t, err)
ca, err := connect.ParseCert(string(caData))

6
command/tls/cert/create/tls_cert_create.go

@ -4,8 +4,8 @@ import (
"crypto/x509"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
"github.com/hashicorp/consul/command/flags"
@ -150,12 +150,12 @@ func (c *cmd) Run(args []string) int {
caFile := strings.Replace(c.ca, "#DOMAIN#", c.domain, 1)
keyFile := strings.Replace(c.key, "#DOMAIN#", c.domain, 1)
cert, err := ioutil.ReadFile(caFile)
cert, err := os.ReadFile(caFile)
if err != nil {
c.UI.Error(fmt.Sprintf("Error reading CA: %s", err))
return 1
}
key, err := ioutil.ReadFile(keyFile)
key, err := os.ReadFile(keyFile)
if err != nil {
c.UI.Error(fmt.Sprintf("Error reading CA key: %s", err))
return 1

5
command/tls/cert/create/tls_cert_create_test.go

@ -4,7 +4,6 @@ import (
"crypto"
"crypto/x509"
"io/fs"
"io/ioutil"
"net"
"os"
"strings"
@ -252,9 +251,9 @@ func expectFiles(t *testing.T, certPath, keyPath string) (*x509.Certificate, cry
t.Fatalf("private key file %s: permissions: want: %o; have: %o", keyPath, want, have)
}
certData, err := ioutil.ReadFile(certPath)
certData, err := os.ReadFile(certPath)
require.NoError(t, err)
keyData, err := ioutil.ReadFile(keyPath)
keyData, err := os.ReadFile(keyPath)
require.NoError(t, err)
cert, err := connect.ParseCert(string(certData))

16
command/validate/validate_test.go

@ -1,7 +1,7 @@
package validate
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
@ -34,7 +34,7 @@ func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) {
td := testutil.TempDir(t, "consul")
fp := filepath.Join(td, "config.json")
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
err := os.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
require.Nilf(t, err, "err: %s", err)
cmd := New(cli.NewMockUi())
@ -49,7 +49,7 @@ func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) {
td := testutil.TempDir(t, "consul")
fp := filepath.Join(td, "json.conf")
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
err := os.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
require.Nilf(t, err, "err: %s", err)
cmd := New(cli.NewMockUi())
@ -64,7 +64,7 @@ func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) {
td := testutil.TempDir(t, "consul")
fp := filepath.Join(td, "hcl.conf")
err := ioutil.WriteFile(fp, []byte("bind_addr = \"10.0.0.1\"\ndata_dir = \""+td+"\""), 0644)
err := os.WriteFile(fp, []byte("bind_addr = \"10.0.0.1\"\ndata_dir = \""+td+"\""), 0644)
require.Nilf(t, err, "err: %s", err)
cmd := New(cli.NewMockUi())
@ -79,7 +79,7 @@ func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) {
td := testutil.TempDir(t, "consul")
fp := filepath.Join(td, "json.conf")
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
err := os.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
require.Nilf(t, err, "err: %s", err)
cmd := New(cli.NewMockUi())
@ -93,7 +93,7 @@ func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) {
t.Parallel()
td := testutil.TempDir(t, "consul")
err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
err := os.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
require.Nilf(t, err, "err: %s", err)
cmd := New(cli.NewMockUi())
@ -108,7 +108,7 @@ func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) {
td := testutil.TempDir(t, "consul")
fp := filepath.Join(td, "hcl.conf")
err := ioutil.WriteFile(fp, []byte(`bind_addr = "10.0.0.1"\ndata_dir = "`+td+`"`), 0644)
err := os.WriteFile(fp, []byte(`bind_addr = "10.0.0.1"\ndata_dir = "`+td+`"`), 0644)
require.Nilf(t, err, "err: %s", err)
cmd := New(cli.NewMockUi())
@ -123,7 +123,7 @@ func TestValidateCommand_Quiet(t *testing.T) {
td := testutil.TempDir(t, "consul")
fp := filepath.Join(td, "config.json")
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
err := os.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
require.Nilf(t, err, "err: %s", err)
ui := cli.NewMockUi()

6
command/version/formatter_test.go

@ -3,7 +3,7 @@ package version
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
@ -21,11 +21,11 @@ func golden(t *testing.T, name, got string) string {
golden := filepath.Join("testdata", name+".golden")
if *update && got != "" {
err := ioutil.WriteFile(golden, []byte(got), 0644)
err := os.WriteFile(golden, []byte(got), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(golden)
expected, err := os.ReadFile(golden)
require.NoError(t, err)
return string(expected)

3
command/watch/watch_test.go

@ -1,7 +1,6 @@
package watch
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -58,7 +57,7 @@ func TestWatchCommand_loadToken(t *testing.T) {
testDir := testutil.TempDir(t, "watchtest")
fullname := filepath.Join(testDir, "token.txt")
require.NoError(t, ioutil.WriteFile(fullname, []byte(testToken), 0600))
require.NoError(t, os.WriteFile(fullname, []byte(testToken), 0600))
resetEnv := func() {
os.Unsetenv("CONSUL_HTTP_TOKEN")

3
connect/certgen/certgen.go

@ -31,7 +31,6 @@ package main // import "github.com/hashicorp/consul/connect/certgen"
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
@ -86,7 +85,7 @@ func main() {
func writeFile(name, content string) {
fmt.Println("Writing ", name)
err := ioutil.WriteFile(name, []byte(content), 0600)
err := os.WriteFile(name, []byte(content), 0600)
if err != nil {
log.Fatalf("failed writing file: %s", err)
}

3
connect/service_test.go

@ -7,7 +7,6 @@ import (
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"net/http"
"reflect"
"sort"
@ -255,7 +254,7 @@ func TestService_HTTPClient(t *testing.T) {
r.Check(err)
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
r.Check(err)
got := string(bodyBytes)

4
connect/tls.go

@ -5,9 +5,9 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"strings"
"sync"
@ -89,7 +89,7 @@ func devTLSConfigFromFiles(caFile, certFile,
roots := x509.NewCertPool()
bs, err := ioutil.ReadFile(caFile)
bs, err := os.ReadFile(caFile)
if err != nil {
return nil, err
}

3
go.sum

@ -396,7 +396,6 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
@ -612,7 +611,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@ -1143,7 +1141,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=

4
internal/go-sso/oidcauth/oidcauthtest/testing.go

@ -14,7 +14,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
@ -82,7 +82,7 @@ func Start(t TestingT) *Server {
s.jwks = jwks
s.httpServer = httptest.NewUnstartedServer(s)
s.httpServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
s.httpServer.Config.ErrorLog = log.New(io.Discard, "", 0)
s.httpServer.StartTLS()
t.Cleanup(s.httpServer.Close)

5
internal/testing/golden/golden.go

@ -2,7 +2,6 @@ package golden
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -26,11 +25,11 @@ func Get(t *testing.T, actual, filename string) string {
if dir := filepath.Dir(path); dir != "." {
require.NoError(t, os.MkdirAll(dir, 0755))
}
err := ioutil.WriteFile(path, []byte(actual), 0644)
err := os.WriteFile(path, []byte(actual), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(path)
expected, err := os.ReadFile(path)
require.NoError(t, err)
return string(expected)
}

4
internal/tools/proto-gen-rpc-glue/main_test.go

@ -39,11 +39,11 @@ func golden(t *testing.T, actual, path string) string {
if dir := filepath.Dir(path); dir != "." {
require.NoError(t, os.MkdirAll(dir, 0755))
}
err := ioutil.WriteFile(path, []byte(actual), 0644)
err := os.WriteFile(path, []byte(actual), 0644)
require.NoError(t, err)
}
expected, err := ioutil.ReadFile(path)
expected, err := os.ReadFile(path)
require.NoError(t, err)
return string(expected)
}

5
lib/file/atomic_test.go

@ -1,7 +1,6 @@
package file
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -13,7 +12,7 @@ import (
// tests that it just writes the file properly. I would love to test this
// better but I'm not sure how. -mitchellh
func TestWriteAtomic(t *testing.T) {
td, err := ioutil.TempDir("", "lib-file")
td, err := os.MkdirTemp("", "lib-file")
require.NoError(t, err)
defer os.RemoveAll(td)
@ -25,7 +24,7 @@ func TestWriteAtomic(t *testing.T) {
require.NoError(t, WriteAtomic(path, expected))
// Read and verify
actual, err := ioutil.ReadFile(path)
actual, err := os.ReadFile(path)
require.NoError(t, err)
require.Equal(t, expected, actual)
}

7
logging/logfile_test.go

@ -1,7 +1,6 @@
package logging
import (
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -44,7 +43,7 @@ func TestLogFile_openNew(t *testing.T) {
_, err = logFile.Write([]byte(msg))
require.NoError(t, err)
content, err := ioutil.ReadFile(logFile.FileInfo.Name())
content, err := os.ReadFile(logFile.FileInfo.Name())
require.NoError(t, err)
require.Contains(t, string(content), msg)
}
@ -79,11 +78,11 @@ func TestLogFile_PruneFiles(t *testing.T) {
sort.Strings(logFiles)
require.Len(t, logFiles, 2)
content, err := ioutil.ReadFile(filepath.Join(tempDir, logFiles[0]))
content, err := os.ReadFile(filepath.Join(tempDir, logFiles[0]))
require.NoError(t, err)
require.Contains(t, string(content), "Second File")
content, err = ioutil.ReadFile(filepath.Join(tempDir, logFiles[1]))
content, err = os.ReadFile(filepath.Join(tempDir, logFiles[1]))
require.NoError(t, err)
require.Contains(t, string(content), "Third File")
}

4
main.go

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
@ -24,7 +24,7 @@ func main() {
}
func realMain() int {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
ui := &cli.BasicUI{
BasicUi: mcli.BasicUi{Writer: os.Stdout, ErrorWriter: os.Stderr},

4
sdk/freeport/ephemeral_linux.go

@ -5,7 +5,7 @@ package freeport
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strconv"
)
@ -15,7 +15,7 @@ const ephemeralPortRangeProcFile = "/proc/sys/net/ipv4/ip_local_port_range"
var ephemeralPortRangePatt = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s*$`)
func getEphemeralPortRange() (int, int, error) {
out, err := ioutil.ReadFile(ephemeralPortRangeProcFile)
out, err := os.ReadFile(ephemeralPortRangeProcFile)
if err != nil {
return 0, 0, err
}

14
sdk/go.mod

@ -1,17 +1,23 @@
module github.com/hashicorp/consul/sdk
go 1.12
go 1.18
require (
github.com/fatih/color v1.9.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-hclog v0.12.0
github.com/hashicorp/go-uuid v1.0.1
github.com/kr/pretty v0.2.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

5
sdk/testutil/io.go

@ -1,7 +1,6 @@
package testutil
import (
"io/ioutil"
"os"
"strings"
"testing"
@ -19,7 +18,7 @@ func TempDir(t testing.TB, name string) string {
}
name = t.Name() + "-" + name
name = strings.Replace(name, "/", "_", -1)
d, err := ioutil.TempDir("", name)
d, err := os.MkdirTemp("", name)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -45,7 +44,7 @@ func TempFile(t testing.TB, name string) *os.File {
}
name = t.Name() + "-" + name
name = strings.Replace(name, "/", "_", -1)
f, err := ioutil.TempFile("", name)
f, err := os.CreateTemp("", name)
if err != nil {
t.Fatalf("err: %s", err)
}

5
sdk/testutil/server.go

@ -16,7 +16,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@ -255,7 +254,7 @@ func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, er
// Use test name for tmpdir if available
prefix = strings.Replace(t.Name(), "/", "_", -1)
}
tmpdir, err := ioutil.TempDir("", prefix)
tmpdir, err := os.MkdirTemp("", prefix)
if err != nil {
return nil, errors.Wrap(err, "failed to create tempdir")
}
@ -274,7 +273,7 @@ func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, er
t.Logf("CONFIG JSON: %s", string(b))
configFile := filepath.Join(tmpdir, "config.json")
if err := ioutil.WriteFile(configFile, b, 0644); err != nil {
if err := os.WriteFile(configFile, b, 0644); err != nil {
os.RemoveAll(tmpdir)
return nil, errors.Wrap(err, "failed writing config content")
}

5
sdk/testutil/server_methods.go

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"testing"
@ -53,7 +52,7 @@ func (s *TestServer) GetKV(t testing.TB, key string) []byte {
resp := s.get(t, "/v1/kv/"+key)
defer resp.Body.Close()
raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read body: %s", err)
}
@ -93,7 +92,7 @@ func (s *TestServer) ListKV(t testing.TB, prefix string) []string {
resp := s.get(t, "/v1/kv/"+prefix+"?keys")
defer resp.Body.Close()
raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read body: %s", err)
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save