1
0
mirror of synced 2026-02-06 19:05:55 +00:00

chore: remove deprecated io/ioutil

Signed-off-by: Dmitry Rybin <ayrowa@yandex.ru>
This commit is contained in:
Dmitry Rybin
2021-07-30 20:49:44 +02:00
parent d40685ab62
commit 7f425efa6b
18 changed files with 30 additions and 45 deletions

View File

@@ -20,7 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
@@ -55,7 +54,7 @@ func Generate(options Options, manifestsBase string) (*manifestgen.Manifest, err
} else {
// download the manifests base from GitHub
if manifestsBase == "" {
manifestsBase, err = ioutil.TempDir("", options.Namespace)
manifestsBase, err = os.MkdirTemp("", options.Namespace)
if err != nil {
return nil, fmt.Errorf("temp dir error: %w", err)
}
@@ -78,7 +77,7 @@ func Generate(options Options, manifestsBase string) (*manifestgen.Manifest, err
}
}
content, err := ioutil.ReadFile(output)
content, err := os.ReadFile(output)
if err != nil {
return nil, err
}

View File

@@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
@@ -103,12 +102,12 @@ func generate(base string, options Options) error {
// workaround for kustomize not being able to patch the SA in ClusterRoleBindings
defaultNS := MakeDefaultOptions().Namespace
if defaultNS != options.Namespace {
rbac, err := ioutil.ReadFile(rbacFile)
rbac, err := os.ReadFile(rbacFile)
if err != nil {
return fmt.Errorf("reading rbac file failed: %w", err)
}
rbac = bytes.ReplaceAll(rbac, []byte(defaultNS), []byte(options.Namespace))
if err := ioutil.WriteFile(rbacFile, rbac, os.ModePerm); err != nil {
if err := os.WriteFile(rbacFile, rbac, os.ModePerm); err != nil {
return fmt.Errorf("replacing service account namespace in rbac failed: %w", err)
}
}

View File

@@ -17,7 +17,6 @@ limitations under the License.
package kustomization
import (
"io/ioutil"
"os"
"path/filepath"
@@ -113,7 +112,7 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
}, nil
}
kd, err := ioutil.ReadFile(abskfile)
kd, err := os.ReadFile(abskfile)
if err != nil {
return nil, err
}

View File

@@ -18,7 +18,6 @@ package manifestgen
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -46,7 +45,7 @@ func (m *Manifest) WriteFile(rootDir string) (string, error) {
return "", fmt.Errorf("unable to create dir, error: %w", err)
}
if err := ioutil.WriteFile(output, []byte(m.Content), os.ModePerm); err != nil {
if err := os.WriteFile(output, []byte(m.Content), os.ModePerm); err != nil {
return "", fmt.Errorf("unable to write file, error: %w", err)
}
return output, nil

View File

@@ -19,8 +19,8 @@ package sourcesecret
import (
"bytes"
"fmt"
"io/ioutil"
"net"
"os"
"path"
"time"
@@ -62,17 +62,17 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
var caFile []byte
if options.CAFilePath != "" {
if caFile, err = ioutil.ReadFile(options.CAFilePath); err != nil {
if caFile, err = os.ReadFile(options.CAFilePath); err != nil {
return nil, fmt.Errorf("failed to read CA file: %w", err)
}
}
var certFile, keyFile []byte
if options.CertFilePath != "" && options.KeyFilePath != "" {
if certFile, err = ioutil.ReadFile(options.CertFilePath); err != nil {
if certFile, err = os.ReadFile(options.CertFilePath); err != nil {
return nil, fmt.Errorf("failed to read cert file: %w", err)
}
if keyFile, err = ioutil.ReadFile(options.KeyFilePath); err != nil {
if keyFile, err = os.ReadFile(options.KeyFilePath); err != nil {
return nil, fmt.Errorf("failed to read key file: %w", err)
}
}
@@ -129,7 +129,7 @@ func buildSecret(keypair *ssh.KeyPair, hostKey, caFile, certFile, keyFile []byte
}
func loadKeyPair(path string, password string) (*ssh.KeyPair, error) {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to open private key file: %w", err)
}

View File

@@ -17,7 +17,6 @@ limitations under the License.
package sourcesecret
import (
"io/ioutil"
"os"
"reflect"
"testing"
@@ -43,8 +42,8 @@ func Test_passwordLoadKeyPair(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pk, _ := ioutil.ReadFile(tt.privateKeyPath)
ppk, _ := ioutil.ReadFile(tt.publicKeyPath)
pk, _ := os.ReadFile(tt.privateKeyPath)
ppk, _ := os.ReadFile(tt.publicKeyPath)
got, err := loadKeyPair(tt.privateKeyPath, tt.password)
if err != nil {
@@ -65,7 +64,7 @@ func Test_passwordLoadKeyPair(t *testing.T) {
func Test_PasswordlessLoadKeyPair(t *testing.T) {
for algo, privateKey := range testdata.PEMBytes {
t.Run(algo, func(t *testing.T) {
f, err := ioutil.TempFile("", "test-private-key-")
f, err := os.CreateTemp("", "test-private-key-")
if err != nil {
t.Fatalf("unable to create temporary file. err: %s", err)
}
@@ -81,7 +80,7 @@ func Test_PasswordlessLoadKeyPair(t *testing.T) {
return
}
pk, _ := ioutil.ReadFile(f.Name())
pk, _ := os.ReadFile(f.Name())
if !reflect.DeepEqual(got.PrivateKey, pk) {
t.Errorf("PrivateKey %s != %s", got.PrivateKey, string(privateKey))
}