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

refactor: move from io/ioutil to io and os packages #566

Merged
merged 1 commit into from
Oct 17, 2022
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
6 changes: 3 additions & 3 deletions cmd/createUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -139,7 +139,7 @@ func loopUntilPodIsReady(dryRun bool) {
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.Println("vault is availbale but the body is not what is expected ", err)
continue
Expand Down Expand Up @@ -216,7 +216,7 @@ func initializeVaultAndAutoUnseal(dryRun bool) {
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.Panic(err)
}
Expand Down
17 changes: 7 additions & 10 deletions internal/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"

coreV1Types "k8s.io/client-go/kubernetes/typed/core/v1"

"github.com/spf13/viper"

"os"
"strings"
"time"

"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/argocdModel"
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/viper"
yaml2 "gopkg.in/yaml.v2"
coreV1Types "k8s.io/client-go/kubernetes/typed/core/v1"
)

var ArgocdSecretClient coreV1Types.SecretInterface
Expand Down Expand Up @@ -106,7 +103,7 @@ func Sync(httpClient pkg.HTTPDoer, applicationName string, argoCDToken string) (
return res.StatusCode, "", nil
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return res.StatusCode, "", err
}
Expand Down Expand Up @@ -156,7 +153,7 @@ func GetArgoCDToken(username string, password string) (string, error) {
return "", errors.New("unable to retrieve ArgoCD token")
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -229,7 +226,7 @@ func GetArgocdAuthToken(dryRun bool) string {
log.Print("HTTP status NOK")
continue
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.Print("error sending POST request to get argocd auth token:", err)
continue
Expand Down Expand Up @@ -319,7 +316,7 @@ func CreateInitalArgoRepository(githubURL string) error {
return err
}

err = ioutil.WriteFile(fmt.Sprintf("%s/argocd-init-values.yaml", config.K1FolderPath), argoYaml, 0644)
err = os.WriteFile(fmt.Sprintf("%s/argocd-init-values.yaml", config.K1FolderPath), argoYaml, 0644)
if err != nil {
log.Printf("error: could not write argocd-init-values.yaml %s", err)
return err
Expand Down
6 changes: 3 additions & 3 deletions internal/ciTools/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ciTools

import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"

"github.com/kubefirst/kubefirst/configs"
Expand Down Expand Up @@ -44,7 +44,7 @@ func SedBucketName(old, new string) error {
cfg := configs.ReadConfig()
providerFile := fmt.Sprintf("%s/ci/terraform/base/provider.tf", cfg.K1FolderPath)

fileData, err := ioutil.ReadFile(providerFile)
fileData, err := os.ReadFile(providerFile)
if err != nil {
return err
}
Expand All @@ -53,7 +53,7 @@ func SedBucketName(old, new string) error {
fileString = strings.ReplaceAll(fileString, old, new)
fileData = []byte(fileString)

err = ioutil.WriteFile(providerFile, fileData, 0o600)
err = os.WriteFile(providerFile, fileData, 0o600)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/flagset/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package flagset
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strconv"
Expand Down Expand Up @@ -60,7 +60,7 @@ func Test_DefineSource_set_by_flag(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -78,7 +78,7 @@ func Test_DefineSource_set_by_var(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -96,7 +96,7 @@ func Test_DefineSource_notSet(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func Test_DefineSource_set_by_flag_bool(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand Down
18 changes: 9 additions & 9 deletions internal/flagset/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package flagset
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -64,7 +64,7 @@ func Test_Init_k3d_basic(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -84,7 +84,7 @@ func Test_Init_aws_basic_missing_hostzone(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -104,7 +104,7 @@ func Test_Init_aws_basic_missing_profile(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -124,7 +124,7 @@ func Test_Init_aws_basic_with_profile(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -144,7 +144,7 @@ func Test_Init_aws_basic_with_arn(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -163,7 +163,7 @@ func Test_Init_aws_basic_with_profile_and_arn(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -183,7 +183,7 @@ func Test_Init_by_var_k3d(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand All @@ -207,7 +207,7 @@ func Test_Init_by_var_aws_profile(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Error(err)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ssl
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -182,7 +181,7 @@ func RestoreSSL(dryRun bool, includeMetaphorApps bool) error {
log.Print(path)
//clean yaml
//TODO filter yaml extension
files, err := ioutil.ReadDir(fmt.Sprintf("%s/%s", filepath.Join(config.CertsPath, path), "/"))
files, err := os.ReadDir(fmt.Sprintf("%s/%s", filepath.Join(config.CertsPath, path), "/"))
if err != nil {
log.Println("Error RestoreSSL:", err)
return fmt.Errorf("erro: %s", err)
Expand All @@ -192,7 +191,7 @@ func RestoreSSL(dryRun bool, includeMetaphorApps bool) error {
log.Println(f.Name())
pathyaml := fmt.Sprintf("%s/%s", filepath.Join(config.CertsPath, path), f.Name())

yfile, err := ioutil.ReadFile(pathyaml)
yfile, err := os.ReadFile(pathyaml)

if err != nil {
log.Println("Error RestoreSSL:", err)
Expand Down Expand Up @@ -222,7 +221,7 @@ func RestoreSSL(dryRun bool, includeMetaphorApps bool) error {
return fmt.Errorf("erro: %s", err)
}

err = ioutil.WriteFile(fmt.Sprintf("%s%s", pathyaml, ".clean"), dataCleaned, 0644)
err = os.WriteFile(fmt.Sprintf("%s%s", pathyaml, ".clean"), dataCleaned, 0644)

if err != nil {
log.Println("Error RestoreSSL:", err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pkg
import (
"errors"
"fmt"
"io/ioutil"
"log"
"math/rand"
"net/url"
Expand Down Expand Up @@ -75,7 +74,7 @@ func DetokenizeDirectory(path string, fi os.FileInfo, err error) error {
}

if matched {
read, err := ioutil.ReadFile(path)
read, err := os.ReadFile(path)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -234,7 +233,7 @@ func DetokenizeDirectory(path string, fi os.FileInfo, err error) error {
log.Panic(err)
}
} else {
err = ioutil.WriteFile(path, []byte(newContents), 0)
err = os.WriteFile(path, []byte(newContents), 0)
if err != nil {
log.Panic(err)
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"log"
"os"
"strings"

"github.com/caarlos0/sshmarshal"
goGitSsh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/kubefirst/kubefirst/configs"
"github.com/spf13/viper"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/ssh"
"io/ioutil"
"log"
"strings"
)

func CreateSshKeyPair() {
Expand Down Expand Up @@ -76,7 +77,7 @@ configs:
%s
`, strings.ReplaceAll(privateKey, "\n", "\n ")))

err := ioutil.WriteFile(fmt.Sprintf("%s/argocd-init-values.yaml", config.K1FolderPath), argocdInitValuesYaml, 0644)
err := os.WriteFile(fmt.Sprintf("%s/argocd-init-values.yaml", config.K1FolderPath), argocdInitValuesYaml, 0644)
if err != nil {
log.Panicf("error: could not write argocd-init-values.yaml %s", err)
}
Expand Down Expand Up @@ -143,14 +144,14 @@ func generateGitHubKeys() (string, string, error) {
// todo: function not in use, can we remove it?
func ModConfigYaml() {

file, err := ioutil.ReadFile("./config.yaml")
file, err := os.ReadFile("./config.yaml")
if err != nil {
log.Println("error reading file", err)
}

newFile := strings.Replace(string(file), "allow-keyless: false", "allow-keyless: true", -1)

err = ioutil.WriteFile("./config.yaml", []byte(newFile), 0)
err = os.WriteFile("./config.yaml", []byte(newFile), 0)
if err != nil {
panic(err)
}
Expand Down