Skip to content

Commit

Permalink
Merge pull request #479 from rishabh96b/rm-ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco authored Oct 29, 2021
2 parents c915c5c + b8cebd3 commit 0cd63f8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
3 changes: 1 addition & 2 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -284,7 +283,7 @@ func (r *KustomizationReconciler) reconcile(
revision := source.GetArtifact().Revision

// create tmp dir
tmpDir, err := ioutil.TempDir("", kustomization.Name)
tmpDir, err := os.MkdirTemp("", kustomization.Name)
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return kustomizev1.KustomizationNotReady(
Expand Down
13 changes: 6 additions & 7 deletions controllers/kustomization_decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -65,7 +64,7 @@ func NewDecryptor(kubeClient client.Client,

func NewTempDecryptor(kubeClient client.Client,
kustomization kustomizev1.Kustomization) (*KustomizeDecryptor, func(), error) {
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("decryptor-%s-", kustomization.Name))
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("decryptor-%s-", kustomization.Name))
if err != nil {
return nil, nil, fmt.Errorf("tmp dir error: %w", err)
}
Expand Down Expand Up @@ -140,7 +139,7 @@ func (kd *KustomizeDecryptor) ImportKeys(ctx context.Context) error {
return fmt.Errorf("decryption secret error: %w", err)
}

tmpDir, err := ioutil.TempDir("", kd.kustomization.Name)
tmpDir, err := os.MkdirTemp("", kd.kustomization.Name)
if err != nil {
return fmt.Errorf("tmp dir error: %w", err)
}
Expand All @@ -154,7 +153,7 @@ func (kd *KustomizeDecryptor) ImportKeys(ctx context.Context) error {
if err != nil {
return err
}
if err := ioutil.WriteFile(keyPath, file, os.ModePerm); err != nil {
if err := os.WriteFile(keyPath, file, os.ModePerm); err != nil {
return fmt.Errorf("unable to write key to storage: %w", err)
}
if err := kd.gpgImport(keyPath); err != nil {
Expand Down Expand Up @@ -185,7 +184,7 @@ func (kd *KustomizeDecryptor) gpgImport(path string) error {

func (kd *KustomizeDecryptor) decryptDotEnvFiles(dirpath string) error {
kustomizePath := filepath.Join(dirpath, konfig.DefaultKustomizationFileName())
ksData, err := ioutil.ReadFile(kustomizePath)
ksData, err := os.ReadFile(kustomizePath)
if err != nil {
return nil
}
Expand Down Expand Up @@ -224,7 +223,7 @@ func (kd *KustomizeDecryptor) decryptDotEnvFiles(dirpath string) error {
}

envPath := filepath.Join(dirpath, envFile)
data, err := ioutil.ReadFile(envPath)
data, err := os.ReadFile(envPath)
if err != nil {
return err
}
Expand All @@ -235,7 +234,7 @@ func (kd *KustomizeDecryptor) decryptDotEnvFiles(dirpath string) error {
return err
}

err = ioutil.WriteFile(envPath, out, 0644)
err = os.WriteFile(envPath, out, 0644)
if err != nil {
return fmt.Errorf("error writing to file: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/kustomization_decryptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package controllers
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -71,9 +71,9 @@ func TestKustomizationReconciler_Decryptor(t *testing.T) {
err = applyGitRepository(overlayRepositoryName, overlayArtifactUrl, "main/"+overlayChecksum, overlayChecksum)
g.Expect(err).NotTo(HaveOccurred())

pgpKey, err := ioutil.ReadFile("testdata/sops/pgp.asc")
pgpKey, err := os.ReadFile("testdata/sops/pgp.asc")
g.Expect(err).ToNot(HaveOccurred())
ageKey, err := ioutil.ReadFile("testdata/sops/age.txt")
ageKey, err := os.ReadFile("testdata/sops/age.txt")
g.Expect(err).ToNot(HaveOccurred())

sopsSecretKey := types.NamespacedName{
Expand Down
7 changes: 3 additions & 4 deletions controllers/kustomization_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,7 +53,7 @@ func (kg *KustomizeGenerator) WriteFile(dirPath string) error {

kfile := filepath.Join(dirPath, konfig.DefaultKustomizationFileName())

data, err := ioutil.ReadFile(kfile)
data, err := os.ReadFile(kfile)
if err != nil {
return err
}
Expand Down Expand Up @@ -114,7 +113,7 @@ func (kg *KustomizeGenerator) WriteFile(dirPath string) error {
return err
}

return ioutil.WriteFile(kfile, kd, os.ModePerm)
return os.WriteFile(kfile, kd, os.ModePerm)
}

func checkKustomizeImageExists(images []kustypes.Image, imageName string) (bool, int) {
Expand Down Expand Up @@ -215,7 +214,7 @@ func (kg *KustomizeGenerator) generateKustomization(dirPath string) error {
return err
}

return ioutil.WriteFile(kfile, kd, os.ModePerm)
return os.WriteFile(kfile, kd, os.ModePerm)
}

func adaptSelector(selector *kustomize.Selector) (output *kustypes.Selector) {
Expand Down
6 changes: 3 additions & 3 deletions internal/sops/pgp/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -162,7 +162,7 @@ func (key *MasterKey) encryptWithCryptoOpenPGP(dataKey []byte) error {
if err != nil {
return err
}
b, err := ioutil.ReadAll(encbuf)
b, err := io.ReadAll(encbuf)
if err != nil {
return err
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func (key *MasterKey) decryptWithCryptoOpenpgp() ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("Reading PGP message failed: %s", err)
}
if b, err := ioutil.ReadAll(md.UnverifiedBody); err == nil {
if b, err := io.ReadAll(md.UnverifiedBody); err == nil {
return b, nil
}
return nil, fmt.Errorf("The key could not be decrypted with any of the PGP entries")
Expand Down

0 comments on commit 0cd63f8

Please sign in to comment.