Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 4870fc3

Browse files
committed
Fix ioutil deprecation lint error
1 parent 1869c47 commit 4870fc3

24 files changed

Lines changed: 53 additions & 68 deletions

internals/cli/mlock/mlock_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build dragonfly freebsd linux openbsd solaris
1+
//go:build dragonfly || freebsd || linux || openbsd || solaris
22

33
package mlock
44

internals/cli/ui/ask.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"strconv"
109
"strings"
@@ -74,8 +73,8 @@ func AskSecret(io IO, question string) (string, error) {
7473

7574
// AskMultiline prints out the question and reads back the input until an EOF is reached.
7675
// The input is displayed to the user.
77-
func AskMultiline(io IO, question string) ([]byte, error) {
78-
promptIn, promptOut, err := io.Prompts()
76+
func AskMultiline(IO IO, question string) ([]byte, error) {
77+
promptIn, promptOut, err := IO.Prompts()
7978
if err != nil {
8079
return nil, err
8180
}
@@ -85,7 +84,7 @@ func AskMultiline(io IO, question string) ([]byte, error) {
8584
return nil, err
8685
}
8786

88-
raw, err := ioutil.ReadAll(promptIn)
87+
raw, err := io.ReadAll(promptIn)
8988
if err != nil {
9089
return nil, err
9190
}

internals/cli/ui/io_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build darwin linux
1+
//go:build darwin || linux
22

33
package ui
44

internals/secrethub/clear.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package secrethub
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76

87
"github.com/secrethub/secrethub-cli/internals/cli"
@@ -45,7 +44,7 @@ func (cmd *ClearCommand) Run() error {
4544
return ErrFileNotFound(cmd.in)
4645
}
4746

48-
spec, err := ioutil.ReadFile(cmd.in)
47+
spec, err := os.ReadFile(cmd.in)
4948
if err != nil {
5049
return ErrCannotReadFile(cmd.in, err)
5150
}

internals/secrethub/env_source.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"os"
1110
"path/filepath"
1211
"strings"
@@ -53,7 +52,7 @@ func newEnvironment(io ui.IO, newClient newClientFunc) *environment {
5352
io: io,
5453
newClient: newClient,
5554
osEnv: os.Environ(),
56-
readFile: ioutil.ReadFile,
55+
readFile: os.ReadFile,
5756
osStat: os.Stat,
5857
templateVars: make(map[string]string),
5958
envar: make(map[string]string),
@@ -348,7 +347,7 @@ type EnvDir map[string]value
348347
// NewEnvDir sources environment variables from files in a given directory,
349348
// using the file name as key and contents as value.
350349
func NewEnvDir(path string) (EnvDir, error) {
351-
files, err := ioutil.ReadDir(path)
350+
files, err := os.ReadDir(path)
352351
if err != nil {
353352
return nil, ErrReadEnvDir(err)
354353
}
@@ -357,7 +356,7 @@ func NewEnvDir(path string) (EnvDir, error) {
357356
for _, f := range files {
358357
if !f.IsDir() {
359358
filePath := filepath.Join(path, f.Name())
360-
fileContent, err := ioutil.ReadFile(filePath)
359+
fileContent, err := os.ReadFile(filePath)
361360
if err != nil {
362361
return nil, ErrReadEnvFile(f.Name(), err)
363362
}
@@ -603,12 +602,12 @@ const (
603602
// it is wrapped in either single or double quotes.
604603
//
605604
// Rules:
606-
// - Empty values become empty values (e.g. `''`and `""` both evaluate to the empty string ``).
607-
// - Inner quotes are maintained (e.g. `{"foo":"bar"}` remains unchanged).
608-
// - Single and double quoted values are escaped (e.g. `'foo'` and `"foo"` both evaluate to `foo`).
609-
// - Single and double qouted values maintain whitespace from both ends (e.g. `" foo "` becomes ` foo `)
610-
// - Inputs with either leading or trailing whitespace are considered unquoted,
611-
// so make sure you sanitize your inputs before calling this function.
605+
// - Empty values become empty values (e.g. ``and `""` both evaluate to the empty string ).
606+
// - Inner quotes are maintained (e.g. `{"foo":"bar"}` remains unchanged).
607+
// - Single and double quoted values are escaped (e.g. `'foo'` and `"foo"` both evaluate to `foo`).
608+
// - Single and double qouted values maintain whitespace from both ends (e.g. `" foo "` becomes ` foo `)
609+
// - Inputs with either leading or trailing whitespace are considered unquoted,
610+
// so make sure you sanitize your inputs before calling this function.
612611
func trimQuotes(s string) (string, bool) {
613612
n := len(s)
614613
if n > 1 &&
@@ -621,7 +620,7 @@ func trimQuotes(s string) (string, bool) {
621620
}
622621

623622
func parseYML(r io.Reader) ([]envvar, error) {
624-
contents, err := ioutil.ReadAll(r)
623+
contents, err := io.ReadAll(r)
625624
if err != nil {
626625
return nil, err
627626
}

internals/secrethub/inject.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package secrethub
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"os"
77
"path/filepath"
88

@@ -86,7 +86,7 @@ func (cmd *InjectCommand) Run() error {
8686
var raw []byte
8787

8888
if cmd.inFile != "" {
89-
raw, err = ioutil.ReadFile(cmd.inFile)
89+
raw, err = os.ReadFile(cmd.inFile)
9090
if err != nil {
9191
return ErrReadFile(cmd.inFile, err)
9292
}
@@ -95,7 +95,7 @@ func (cmd *InjectCommand) Run() error {
9595
return ErrNoDataOnStdin
9696
}
9797

98-
raw, err = ioutil.ReadAll(cmd.io.Input())
98+
raw, err = io.ReadAll(cmd.io.Input())
9999
if err != nil {
100100
return err
101101
}
@@ -164,7 +164,7 @@ func (cmd *InjectCommand) Run() error {
164164
}
165165
}
166166

167-
err = ioutil.WriteFile(cmd.outFile, posix.AddNewLine(out), cmd.fileMode.FileMode())
167+
err = os.WriteFile(cmd.outFile, posix.AddNewLine(out), cmd.fileMode.FileMode())
168168
if err != nil {
169169
return ErrCannotWrite(cmd.outFile, err)
170170
}

internals/secrethub/list_formatters.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package secrethub
33
import (
44
"encoding/json"
55
"fmt"
6-
"golang.org/x/text/cases"
7-
"golang.org/x/text/language"
86
"io"
97
"strings"
8+
9+
"golang.org/x/text/cases"
10+
"golang.org/x/text/language"
1011
)
1112

1213
type listFormatter interface {

internals/secrethub/main_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package secrethub
22

33
import (
4-
"io/ioutil"
54
"log"
65
"os"
76
"path/filepath"
@@ -78,7 +77,7 @@ func (td testDataDir) cleanup() error {
7877
func (td testDataDir) tempDir(tb testing.TB) (string, func()) {
7978
tb.Helper()
8079

81-
path, err := ioutil.TempDir(td.root, "")
80+
path, err := os.MkdirTemp(td.root, "")
8281
assert.OK(tb, err)
8382

8483
// Log it to make debugging easier.

internals/secrethub/migrate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"strings"
109

@@ -292,7 +291,7 @@ func (cmd *MigratePlanCommand) Run() error {
292291
return err
293292
}
294293

295-
err = ioutil.WriteFile(cmd.outFile, out, cmd.fileMode.FileMode())
294+
err = os.WriteFile(cmd.outFile, out, cmd.fileMode.FileMode())
296295
if err != nil {
297296
return err
298297
}
@@ -721,7 +720,7 @@ func (w indentedWriter) Write(p []byte) (n int, err error) {
721720
}
722721

723722
func getPlan(planFile string) (*plan, error) {
724-
contents, err := ioutil.ReadFile(planFile)
723+
contents, err := os.ReadFile(planFile)
725724
if err != nil {
726725
return nil, err
727726
}

internals/secrethub/migrate_config_envfile.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package secrethub
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"regexp"
87

@@ -29,7 +28,7 @@ func (cmd *MigrateConfigEnvfileCommand) Run() error {
2928
filepath = "secrethub.env"
3029
}
3130

32-
inFileContents, err := ioutil.ReadFile(filepath)
31+
inFileContents, err := os.ReadFile(filepath)
3332
if err != nil {
3433
return ErrReadFile(filepath, err)
3534
}
@@ -49,7 +48,7 @@ func (cmd *MigrateConfigEnvfileCommand) Run() error {
4948
return ErrReadFile(filepath, err)
5049
}
5150

52-
err = ioutil.WriteFile(".env", []byte(output), inFileInfo.Mode())
51+
err = os.WriteFile(".env", []byte(output), inFileInfo.Mode())
5352
if err != nil {
5453
return err
5554
}

0 commit comments

Comments
 (0)