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

style: replace usage of deprecated "io/ioutil" golang package #97

Merged
merged 1 commit into from
Feb 28, 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
2 changes: 1 addition & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
}
},
"postCreateCommand": "mkdir -p /go/src/github.com/Azure && ln -sf /workspaces/aks-engine-azurestack /go/src/github.com/Azure/aks-engine-azurestack"
}
}
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ linters:
linters-settings:
govet:
check-shadowing: true
staticcheck:
# Deprecated: use the global `run.go` instead.
go: "1.19"
checks: ["all", "-SA1019"]
10 changes: 5 additions & 5 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"math/rand"
"os"
"path"
Expand Down Expand Up @@ -146,7 +146,7 @@ func (dc *deployCmd) mergeAPIModel() error {
if dc.apimodelPath == "" {
log.Infoln("no --api-model was specified, using default model")
var f *os.File
f, err = ioutil.TempFile("", fmt.Sprintf("%s-default-api-model_%s-%s_", filepath.Base(os.Args[0]), BuildSHA, GitTreeState))
f, err = os.CreateTemp("", fmt.Sprintf("%s-default-api-model_%s-%s_", filepath.Base(os.Args[0]), BuildSHA, GitTreeState))
if err != nil {
return errors.Wrap(err, "error creating temp file for default API model")
}
Expand Down Expand Up @@ -203,10 +203,10 @@ func (dc *deployCmd) loadAPIModel() error {
}

if dc.caCertificatePath != "" {
if caCertificateBytes, err = ioutil.ReadFile(dc.caCertificatePath); err != nil {
if caCertificateBytes, err = os.ReadFile(dc.caCertificatePath); err != nil {
return errors.Wrap(err, "failed to read CA certificate file")
}
if caKeyBytes, err = ioutil.ReadFile(dc.caPrivateKeyPath); err != nil {
if caKeyBytes, err = os.ReadFile(dc.caPrivateKeyPath); err != nil {
return errors.Wrap(err, "failed to read CA private key file")
}

Expand Down Expand Up @@ -478,7 +478,7 @@ func (dc *deployCmd) run() error {
); err != nil {
if res.Response.Response != nil && res.Body != nil {
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)
log.Errorf(string(body))
}
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
Expand Down Expand Up @@ -1207,7 +1206,7 @@ func TestAPIModelWithContainerMonitoringAddonWithWorkspaceGuidAndKeyConfigInCmd(
}

func makeTmpFile(t *testing.T, name string) (string, func()) {
tmpF, err := ioutil.TempFile(os.TempDir(), name)
tmpF, err := os.CreateTemp(os.TempDir(), name)
if err != nil {
t.Fatalf("unable to create file: %s", err.Error())
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

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

Expand Down Expand Up @@ -168,10 +167,10 @@ func (gc *generateCmd) loadAPIModel() error {
return errors.New("--ca-certificate-path and --ca-private-key-path must be specified together")
}
if gc.caCertificatePath != "" {
if caCertificateBytes, err = ioutil.ReadFile(gc.caCertificatePath); err != nil {
if caCertificateBytes, err = os.ReadFile(gc.caCertificatePath); err != nil {
return errors.Wrap(err, "failed to read CA certificate file")
}
if caKeyBytes, err = ioutil.ReadFile(gc.caPrivateKeyPath); err != nil {
if caKeyBytes, err = os.ReadFile(gc.caPrivateKeyPath); err != nil {
return errors.Wrap(err, "failed to read CA private key file")
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/get_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -191,7 +190,7 @@ func (glc *getLogsCmd) loadAPIModel() (err error) {

func (glc *getLogsCmd) init() (err error) {
if glc.linuxScriptPath != "" {
sc, err := ioutil.ReadFile(glc.linuxScriptPath)
sc, err := os.ReadFile(glc.linuxScriptPath)
if err != nil {
return errors.Wrapf(err, "error reading log collection script %s", glc.linuxScriptPath)
}
Expand All @@ -204,7 +203,7 @@ func (glc *getLogsCmd) init() (err error) {
PrivateKeyPath: glc.linuxSSHPrivateKeyPath,
}
if glc.windowsScriptPath != "" {
sc, err := ioutil.ReadFile(glc.windowsScriptPath)
sc, err := os.ReadFile(glc.windowsScriptPath)
if err != nil {
return errors.Wrapf(err, "error reading log collection script %s", glc.windowsScriptPath)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -325,7 +324,7 @@ func getCompletionCmd(root *cobra.Command) *cobra.Command {

func writeCustomCloudProfile(cs *api.ContainerService) error {

tmpFile, err := ioutil.TempFile("", "azurestackcloud.json")
tmpFile, err := os.CreateTemp("", "azurestackcloud.json")
tmpFileName := tmpFile.Name()
if err != nil {
return err
Expand All @@ -337,7 +336,7 @@ func writeCustomCloudProfile(cs *api.ContainerService) error {
if err != nil {
return err
}
if err = ioutil.WriteFile(tmpFileName, []byte(content), os.ModeAppend); err != nil {
if err = os.WriteFile(tmpFileName, []byte(content), os.ModeAppend); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -129,6 +128,7 @@ func TestGetSelectedCloudFromAzConfig(t *testing.T) {
`), "myCloud"},
} {
t.Run(test.desc, func(t *testing.T) {
test := test
t.Parallel()

f, err := ini.Load(test.data)
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestWriteCustomCloudProfile(t *testing.T) {
t.Fatalf("failed to write custom cloud profile: file %s does not exist", environmentFilePath)
}

azurestackenvironment, err := ioutil.ReadFile(environmentFilePath)
azurestackenvironment, err := os.ReadFile(environmentFilePath)
if err != nil {
t.Fatalf("failed to write custom cloud profile: can not read file %s ", environmentFilePath)
}
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestWriteArtifacts(t *testing.T) {
}

func makeTmpDir(t *testing.T) (string, func()) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "_tmp_dir")
tmpDir, err := os.MkdirTemp(os.TempDir(), "_tmp_dir")
if err != nil {
t.Fatalf("unable to create dir: %s", err.Error())
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/rotate_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (rcc *rotateCertsCmd) validateArgs() (err error) {
return errors.Errorf("error creating output directory (%s)", rcc.outputDirectory)
}
}
if _, err := ioutil.ReadDir(rcc.outputDirectory); err != nil {
if _, err := os.ReadDir(rcc.outputDirectory); err != nil {
return errors.Wrapf(err, "reading output directory %s", rcc.outputDirectory)
}
return nil
Expand Down Expand Up @@ -654,7 +653,7 @@ func (rcc *rotateCertsCmd) getKubeClient() (*kubernetes.CompositeClientSet, erro
configPathSuffix := path.Join("kubeconfig", fmt.Sprintf("kubeconfig.%s.json", rcc.location))

oldConfigPath := path.Join(rcc.backupDirectory, configPathSuffix)
oldConfig, err := ioutil.ReadFile(oldConfigPath)
oldConfig, err := os.ReadFile(oldConfigPath)
if err != nil {
return nil, errors.Wrapf(err, "reading %s", oldConfigPath)
}
Expand All @@ -664,7 +663,7 @@ func (rcc *rotateCertsCmd) getKubeClient() (*kubernetes.CompositeClientSet, erro
}

newConfigPath := path.Join(rcc.outputDirectory, configPathSuffix)
newConfig, err := ioutil.ReadFile(newConfigPath)
newConfig, err := os.ReadFile(newConfigPath)
if err != nil {
return nil, errors.Wrapf(err, "reading %s", newConfigPath)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -379,7 +378,7 @@ func (uc *upgradeCmd) run(cmd *cobra.Command, args []string) error {
if err != nil {
return errors.Wrap(err, "reading --kubeconfig")
}
content, err = ioutil.ReadFile(path)
content, err = os.ReadFile(path)
if err != nil {
return errors.Wrap(err, "reading --kubeconfig")
}
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/fatih/structs v1.1.0
github.com/golang/mock v1.4.1
github.com/golang/mock v1.4.4
github.com/google/go-cmp v0.5.5
github.com/google/uuid v1.1.2
github.com/imdario/mergo v0.3.6
Expand All @@ -30,8 +30,8 @@ require (
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.5
github.com/x-cray/logrus-prefixed-formatter v0.5.2
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/text v0.7.0
gopkg.in/go-playground/validator.v9 v9.25.0
gopkg.in/ini.v1 v1.41.0
Expand Down Expand Up @@ -69,13 +69,13 @@ require (
github.com/nxadm/tail v1.4.4 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
Loading