Skip to content

Commit

Permalink
CI-1658: Remove deprecated ioutil package
Browse files Browse the repository at this point in the history
Implement go-staticcheck suggestions.

Replaces ioutil with new functions in the os package.
Each function in the os package is a direct replacement for the
previously used functions in the ioutil package.

For more context see these:
- go-critic/go-critic#1019
- golang/go#42026
  • Loading branch information
Nabil372 committed Nov 30, 2022
1 parent ae30df8 commit fcf3f0c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions apis/vault/v1alpha1/secretsinjector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1alpha1

import (
"fmt"
"io/ioutil"
"os"
"time"

corev1 "k8s.io/api/core/v1"
Expand All @@ -15,7 +15,7 @@ import (
)

func mustPodFixture(path string) *corev1.Pod {
podFixtureYAML, _ := ioutil.ReadFile(path)
podFixtureYAML, _ := os.ReadFile(path)
decoder := scheme.Codecs.UniversalDeserializer()
obj, _, _ := decoder.Decode(podFixtureYAML, nil, nil)
return obj.(*corev1.Pod)
Expand Down
4 changes: 2 additions & 2 deletions apis/workloads/v1alpha1/console_authorisation_webhook_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package v1alpha1

import (
"io/ioutil"
"net/http"
"os"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -14,7 +14,7 @@ import (
func mustConsoleAuthorisationFixture(path string) *ConsoleAuthorisation {
consoleAuthorisation := &ConsoleAuthorisation{}

consoleAuthorisationFixtureYAML, _ := ioutil.ReadFile(path)
consoleAuthorisationFixtureYAML, _ := os.ReadFile(path)

decoder := serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer()
if err := runtime.DecodeInto(decoder, consoleAuthorisationFixtureYAML, consoleAuthorisation); err != nil {
Expand Down
9 changes: 4 additions & 5 deletions cmd/theatre-secrets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
execpkg "os/exec"
Expand Down Expand Up @@ -243,7 +242,7 @@ func mainError(ctx context.Context, command string) (err error) {
path := file.filesystemPath
if path == "" {
// generate file path prefixed by key
tempFilePath, err := ioutil.TempFile("", fmt.Sprintf("%s-*", key))
tempFilePath, err := os.CreateTemp("", fmt.Sprintf("%s-*", key))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to write temporary file for key %s", key))
}
Expand All @@ -264,7 +263,7 @@ func mainError(ctx context.Context, command string) (err error) {
)

// write file with value of envMap[key]
if err := ioutil.WriteFile(path, []byte(secretEnv[file.vaultKey]), 0600); err != nil {
if err := os.WriteFile(path, []byte(secretEnv[file.vaultKey]), 0600); err != nil {
return errors.Wrap(err,
fmt.Sprintf("failed to write file with key %s to path %s", key, path))
}
Expand Down Expand Up @@ -304,7 +303,7 @@ func mainError(ctx context.Context, command string) (err error) {
// in cluster auth but falling back to other detection methods if that fails.
func getKubernetesToken(tokenFileOverride string) (string, error) {
if tokenFileOverride != "" {
tokenBytes, err := ioutil.ReadFile(tokenFileOverride)
tokenBytes, err := os.ReadFile(tokenFileOverride)

return string(tokenBytes), errors.Wrap(err, "failed to read kubernetes token file")
}
Expand Down Expand Up @@ -470,7 +469,7 @@ type Config struct {
func loadConfigFromFile(configFile string) (Config, error) {
var cfg Config

yamlContent, err := ioutil.ReadFile(configFile)
yamlContent, err := os.ReadFile(configFile)
if err != nil {
return cfg, errors.Wrap(err, "failed to open config file")
}
Expand Down
20 changes: 11 additions & 9 deletions cmd/vault-manager/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -46,15 +46,17 @@ func (r *Runner) Name() string {
//
// It does several things:
//
// - Mounts a kv2 secrets engine at secret/
// - Creates a Kubernetes auth backend mounted at auth/kubernetes
// - Configures the Kubernetes backend to authenticate against the currently detected
// Kubernetes API server (the current cluster, if run from within)
// - For all successful Kubernetes logins, the user is assigned a token that maps to a
// cluster-reader policy, which permits reading of secrets from:
// - Mounts a kv2 secrets engine at secret/
//
// secret/data/kubernetes/{namespace}/{service-account-name}/*
// - Creates a Kubernetes auth backend mounted at auth/kubernetes
//
// - Configures the Kubernetes backend to authenticate against the currently detected
// Kubernetes API server (the current cluster, if run from within)
//
// - For all successful Kubernetes logins, the user is assigned a token that maps to a
// cluster-reader policy, which permits reading of secrets from:
//
// secret/data/kubernetes/{namespace}/{service-account-name}/*
func (r *Runner) Prepare(logger kitlog.Logger, config *rest.Config) error {
cfg := api.DefaultConfig()
cfg.Address = "http://localhost:8200"
Expand Down Expand Up @@ -110,7 +112,7 @@ func (r *Runner) Prepare(logger kitlog.Logger, config *rest.Config) error {
var ca []byte = config.CAData

if len(ca) == 0 {
ca, err = ioutil.ReadFile(config.CAFile)
ca, err = os.ReadFile(config.CAFile)
if err != nil {
return errors.Wrap(err, "could not parse certificate for kubernetes")
}
Expand Down

0 comments on commit fcf3f0c

Please sign in to comment.