Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update deprecated API calls #332

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"time"

grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
Expand Down Expand Up @@ -152,7 +152,7 @@ func appendRootCAs(tlsConfig *tls.Config, caFile string) error {
return nil
}

ca, err := ioutil.ReadFile(caFile)
ca, err := os.ReadFile(caFile)
if err != nil {
return fmt.Errorf("could not read CA file (%s): %w", caFile, err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $ nginx-agent completion fish > ~/.config/fish/completions/nginx-agent.fish
`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish"},
Args: cobra.ExactValidArgs(1),
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
var err error

Expand Down
5 changes: 2 additions & 3 deletions src/core/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package core
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -926,7 +925,7 @@ func TestGetContainerID(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mountInfoFile, err := ioutil.TempFile(os.TempDir(), "mountInfo-")
mountInfoFile, err := os.CreateTemp(os.TempDir(), "mountInfo-")
if err != nil {
t.Fatalf("Cannot create temporary file: %v", err)
}
Expand Down Expand Up @@ -1012,7 +1011,7 @@ func TestCGroupV1Check(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mountInfoFile, err := ioutil.TempFile(os.TempDir(), "cGroupV1Check-")
mountInfoFile, err := os.CreateTemp(os.TempDir(), "cGroupV1Check-")
if err != nil {
t.Fatalf("Cannot create temporary file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -191,7 +191,7 @@ func getDefaultNetworkInterfaceCrossPlatform() (string, error) {
}
defer f.Close()

output, err := ioutil.ReadAll(f)
output, err := io.ReadAll(f)
if err != nil {
return "", fmt.Errorf("Can't read contents of %s", linuxFile)
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/nginx-app-protect/nap/attack_signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package nap

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

"github.com/nginx/agent/v2/src/core"
Expand All @@ -30,7 +30,7 @@ func getAttackSignaturesVersion(versionFile string) (string, error) {
}

// Get the version bytes
versionBytes, err := ioutil.ReadFile(versionFile)
versionBytes, err := os.ReadFile(versionFile)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/nginx-app-protect/nap/nap_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package nap

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -187,7 +186,7 @@ func setUpFile(file string, content []byte) error {
if err != nil {
return err
}
err = ioutil.WriteFile(file, content, 0644)
err = os.WriteFile(file, content, 0644)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/nginx-app-protect/nap/threat_campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package nap

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

"github.com/nginx/agent/v2/src/core"
Expand All @@ -30,7 +30,7 @@ func getThreatCampaignsVersion(versionFile string) (string, error) {
}

// Get the version bytes
versionBytes, err := ioutil.ReadFile(versionFile)
versionBytes, err := os.ReadFile(versionFile)
if err != nil {
return "", err
}
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/agent_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/nginx/agent/v2/src/core/metrics"
"io"
"io/fs"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -490,7 +489,7 @@ func TestMtls_forApi(t *testing.T) {
Multiplier: backoff.BACKOFF_MULTIPLIER,
}
err = backoff.WaitUntil(ctx, backoffSetting, func() error {
_, err := ioutil.ReadFile("../../build/certs/server.crt")
_, err := os.ReadFile("../../build/certs/server.crt")
return err
})

Expand Down Expand Up @@ -532,11 +531,11 @@ func TestMtls_forApi(t *testing.T) {
}

func getConfig(t *testing.T) *tls.Config {
crt, err := ioutil.ReadFile("../../build/certs/client.crt")
crt, err := os.ReadFile("../../build/certs/client.crt")
assert.NoError(t, err)
key, err := ioutil.ReadFile("../../build/certs/client.key")
key, err := os.ReadFile("../../build/certs/client.key")
assert.NoError(t, err)
ca, err := ioutil.ReadFile("../../build/certs/ca.pem")
ca, err := os.ReadFile("../../build/certs/ca.pem")
assert.NoError(t, err)

cert, err := tls.X509KeyPair(crt, key)
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/file_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package plugins

import (
"context"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -488,7 +487,7 @@ func TestWatcherProcess(t *testing.T) {
}

func writeFile(t *testing.T, file string) {
err := ioutil.WriteFile(file, []byte{}, 0644)
err := os.WriteFile(file, []byte{}, 0644)
if err != nil {
t.Fatalf("failed to write file: %v", err)
}
Expand All @@ -508,7 +507,7 @@ func writeFiles(t *testing.T, dirs []string) (ret []string) {
}

func updateFile(t *testing.T, file, content string) {
err := ioutil.WriteFile(file, []byte(content), 0644)
err := os.WriteFile(file, []byte(content), 0644)
if err != nil {
t.Fatalf("failed to update file: %v", err)
}
Expand Down
16 changes: 8 additions & 8 deletions test/integration/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const frameSeparator = ';'

func TestReaderIsAbleToHandleMultipleClients(t *testing.T) {
mu := &sync.Mutex{}
rand.Seed(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", rand.Int63())
source := rand.NewSource(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", source.Int63())

r := reader.NewReader(addr)
outChannel := r.OutChannel()
Expand Down Expand Up @@ -82,8 +82,8 @@ func TestReaderIsAbleToHandleMultipleClients(t *testing.T) {

func TestReaderIsAbleToHandlePartiallySendFrame(t *testing.T) {
mu := &sync.Mutex{}
rand.Seed(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", rand.Int63())
source := rand.NewSource(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", source.Int63())

r := reader.NewReader(addr)
outChannel := r.OutChannel()
Expand Down Expand Up @@ -130,8 +130,8 @@ func TestReaderIsAbleToHandlePartiallySendFrame(t *testing.T) {

func TestReaderIsAbleToCloseOngoingConnections(t *testing.T) {
mu := &sync.Mutex{}
rand.Seed(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", rand.Int63())
source := rand.NewSource(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", source.Int63())

r := reader.NewReader(addr)
outChannel := r.OutChannel()
Expand Down Expand Up @@ -179,8 +179,8 @@ func TestReaderIsAbleToCloseOngoingConnections(t *testing.T) {

func TestReaderWithGeneratedData(t *testing.T) {
mu := &sync.Mutex{}
rand.Seed(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", rand.Int63())
source := rand.NewSource(time.Now().Unix())
addr := fmt.Sprintf("/tmp/advanced_metrics_reader_test_%d.sr", source.Int63())

r := reader.NewReader(addr)
outChannel := r.OutChannel()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions test/utils/symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"encoding/json"
"io/ioutil"
"os"
)

Expand All @@ -27,7 +26,7 @@ func LoadSymbolsFile() (*Symbols, error) {
symFile = symbolsFileLocal
}

content, err := ioutil.ReadFile(symFile)
content, err := os.ReadFile(symFile)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package utils
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"

log "github.com/sirupsen/logrus"

Expand All @@ -16,7 +16,7 @@ func LoadKeyPair() credentials.TransportCredentials {
log.Fatalf("Load server certification failed: %v", err)
}

data, err := ioutil.ReadFile("certs/client/ca.crt")
data, err := os.ReadFile("certs/client/ca.crt")
if err != nil {
log.Fatalf("can't read ca file: %v", err)
}
Expand Down
Loading