Skip to content

Commit

Permalink
Replace deprecated io/util references (#193)
Browse files Browse the repository at this point in the history
Signed-off-by: Din Music <din.music@din-cloud.com>
  • Loading branch information
MusicDin authored Apr 15, 2024
1 parent 4795451 commit ca9f64c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 25 deletions.
5 changes: 2 additions & 3 deletions cmd/meta_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

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

"github.com/MusicDin/kubitect/pkg/app"
Expand Down Expand Up @@ -76,8 +76,7 @@ func clusters(ctx app.AppContext, local bool) (MetaClusters, error) {
path = ctx.ClustersDir()
}

files, err := ioutil.ReadDir(path)

files, err := os.ReadDir(path)
if err != nil {
return nil, fmt.Errorf("failed to read clusters directory: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package embed
import (
"embed"
"io/fs"
"io/ioutil"
"os"
"path"
)
Expand Down Expand Up @@ -93,7 +92,7 @@ func MirrorResource(resPath, dstPath string) error {

resDstPath := path.Join(dstPath, resPath)
os.MkdirAll(path.Dir(resDstPath), os.ModePerm)
return ioutil.WriteFile(resDstPath, content, os.ModePerm)
return os.WriteFile(resDstPath, content, os.ModePerm)
}

mirrorDir := func(fPath string, f fs.DirEntry, err error) error {
Expand All @@ -112,7 +111,7 @@ func MirrorResource(resPath, dstPath string) error {
return err
}

return ioutil.WriteFile(resDstPath, content, os.ModePerm)
return os.WriteFile(resDstPath, content, os.ModePerm)
}

return fs.WalkDir(efs, resPath, mirrorDir)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cluster

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestSync_InvalidInfraConfig(t *testing.T) {
err := os.MkdirAll(path.Dir(c.InfrastructureConfigPath()), 0777)
require.NoError(t, err)

err = ioutil.WriteFile(c.InfrastructureConfigPath(), []byte(cfg), 0777)
err = os.WriteFile(c.InfrastructureConfigPath(), []byte(cfg), 0777)
require.NoError(t, err)

assert.ErrorContains(t, c.Sync(), "infrastructure file (produced by Terraform) is invalid")
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cluster

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -34,7 +33,7 @@ func WriteConfigMockFile(t *testing.T) string {
cfg := "value: test"
cfgPath := path.Join(t.TempDir(), "cfg.yaml")

err := ioutil.WriteFile(cfgPath, []byte(cfg), os.ModePerm)
err := os.WriteFile(cfgPath, []byte(cfg), os.ModePerm)
assert.NoError(t, err)

return cfgPath
Expand Down
3 changes: 1 addition & 2 deletions pkg/tools/virtualenv/virtualenv_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package virtualenv

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -16,7 +15,7 @@ func MockReqFile(t *testing.T) string {
reqFile := "netaddr==0.7.19"
reqPath := path.Join(t.TempDir(), "requirements.txt")

err := ioutil.WriteFile(reqPath, []byte(reqFile), os.ModePerm)
err := os.WriteFile(reqPath, []byte(reqFile), os.ModePerm)
require.NoError(t, err)

return reqPath
Expand Down
5 changes: 2 additions & 3 deletions pkg/utils/file/file_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package file

import (
"io/ioutil"
"os"
"path"
"strings"
Expand All @@ -21,7 +20,7 @@ func tmpFile(t *testing.T, name string, content ...string) string {
fPath := path.Join(t.TempDir(), name)
fData := strings.Join(content, " ")

err := ioutil.WriteFile(fPath, []byte(fData), os.ModePerm)
err := os.WriteFile(fPath, []byte(fData), os.ModePerm)
require.NoErrorf(t, err, "failed creating tmp file (%s): %v", name, err)

return fPath
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestWriteYaml(t *testing.T) {
err := WriteYaml(T{7}, fPath, os.ModePerm)
require.NoError(t, err)

f, err := ioutil.ReadFile(fPath)
f, err := os.ReadFile(fPath)
assert.Equal(t, "value: 7\n", string(f))
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/utils/keygen/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"path"

Expand All @@ -27,7 +26,7 @@ type (
// Note that the directory to which the key is
// written must exist.
func (k key) Write(path string) error {
return ioutil.WriteFile(path, k.value, 0600)
return os.WriteFile(path, k.value, 0600)
}

type (
Expand Down Expand Up @@ -93,14 +92,14 @@ func ReadKeyPair(dir, keyName string) (KeyPair, error) {
var pair keyPair

privKeyPath := path.Join(dir, keyName)
pair.private.value, err = ioutil.ReadFile(privKeyPath)
pair.private.value, err = os.ReadFile(privKeyPath)
if err != nil {
return nil, NewKeyFileError("private", keyName, err)
}

pubKeyName := keyName + ".pub"
pubKeyPath := path.Join(dir, pubKeyName)
pair.public.value, err = ioutil.ReadFile(pubKeyPath)
pair.public.value, err = os.ReadFile(pubKeyPath)
if err != nil {
return nil, NewKeyFileError("public", keyName+".pub", err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/utils/keygen/keygen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keygen

import (
"errors"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -20,7 +19,7 @@ func TestKeyWrite(t *testing.T) {
err := key.Write(keyPath)
require.NoError(t, err)

keyFile, err := ioutil.ReadFile(keyPath)
keyFile, err := os.ReadFile(keyPath)
require.NoError(t, err)
assert.Equal(t, "test", string(keyFile))
}
Expand Down Expand Up @@ -134,12 +133,12 @@ func TestKeyPair_Write(t *testing.T) {
require.NoError(t, kp.Write(tmpDir, keyName))

privKeyPath := path.Join(tmpDir, keyName)
privKey, err := ioutil.ReadFile(privKeyPath)
privKey, err := os.ReadFile(privKeyPath)
require.NoError(t, err)
require.Contains(t, string(privKey), "RSA PRIVATE KEY")

pubKeyPath := path.Join(tmpDir, keyName+".pub")
pubKey, err := ioutil.ReadFile(pubKeyPath)
pubKey, err := os.ReadFile(pubKeyPath)
require.NoError(t, err)
assert.Contains(t, string(pubKey), "ssh-rsa")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/template/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package template

import (
"bytes"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -106,7 +105,7 @@ func write(dstPath string, bytes []byte) error {
return err
}

return ioutil.WriteFile(dstPath, bytes, 0644)
return os.WriteFile(dstPath, bytes, 0644)
}

// TrimTemplate trims alls leading and trailing spaces from each line
Expand Down

0 comments on commit ca9f64c

Please sign in to comment.