Skip to content

Commit

Permalink
Clean up code from deprecations #94 (#96)
Browse files Browse the repository at this point in the history
* Enable staticcheck for deprications

* Stop using depricated io/ioutil

* Stop using depricated strings.Title

* Stop using depricated os.SEEK_SET

* Stop using depricated rand.Seed

* Stop using depricated google.golang.org/genproto/googleapis/cloud/kms/v1
  • Loading branch information
TheRealSpaceShip authored Aug 5, 2024
1 parent a361136 commit e6a146b
Show file tree
Hide file tree
Showing 31 changed files with 67 additions and 63 deletions.
3 changes: 1 addition & 2 deletions cmd/hub/api/cloudaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -556,7 +555,7 @@ func cloudSpecificCredentials(provider, region string, args []string) (string, m
return "", nil, fmt.Errorf("Unable to open credentials file: %v", err)
}
defer file.Close()
data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return "", nil, fmt.Errorf("Unable to read credentials file `%s`: %v", credentialsFile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/hub/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -609,7 +608,7 @@ func readImportSecrets(secretsOrder []Secret, pems io.Reader) ([]Secret, error)
}
log.Printf("Reading TLS auth certs and key%s", stdin)
}
pemBytes, err := ioutil.ReadAll(pems)
pemBytes, err := io.ReadAll(pems)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/hub/api/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package api
import (
"errors"
"hash/crc64"
"io"
"os"

"github.com/epam/hubctl/cmd/hub/filecache"
Expand Down Expand Up @@ -50,7 +51,7 @@ func storeAccessToken(apiBaseUrl, loginToken string, tokens *SigninResponse) err
return errors.New("No cache file created")
}
defer file.Close()
_, err = file.Seek(0, os.SEEK_SET)
_, err = file.Seek(0, io.SeekStart)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package aws
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -110,7 +110,7 @@ func ReadS3(s3path string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("Failed to GET S3 object `%s`: %v\n\t%s", s3path, err, optionsHelp)
}
data, err := ioutil.ReadAll(obj.Body)
data, err := io.ReadAll(obj.Body)
if err != nil {
return nil, fmt.Errorf("Failed to read S3 object `%s`: %v", s3path, err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/azure/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package azure
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -95,7 +95,7 @@ func ReadStorageBlob(path string) ([]byte, error) {
return nil, err
}
defer reader.Close()
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return nil, fmt.Errorf("Failed to read Azure storage blob `%s`: %v", path, err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/hub/cmd/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -109,7 +109,7 @@ func installApplication(args []string) error {
if createRaw {
api.RawInstallApplication(os.Stdin, waitAndTailDeployLogs)
} else {
createBytes, err := ioutil.ReadAll(os.Stdin)
createBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(createBytes) < 3 {
return fmt.Errorf("Unable to read data (read %d bytes): %v", len(createBytes), err)
}
Expand All @@ -133,7 +133,7 @@ func patchApplication(args []string) error {
if patchRaw {
api.RawPatchApplication(selector, os.Stdin, waitAndTailDeployLogs)
} else {
patchBytes, err := ioutil.ReadAll(os.Stdin)
patchBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(patchBytes) < 3 {
return fmt.Errorf("Unable to read patch data (read %d bytes): %v", len(patchBytes), err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/hub/cmd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -137,7 +137,7 @@ func createComponent(args []string) error {
if createRaw {
api.RawCreateComponent(os.Stdin)
} else {
createBytes, err := ioutil.ReadAll(os.Stdin)
createBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(createBytes) < 3 {
return fmt.Errorf("Unable to read data (read %d bytes): %v", len(createBytes), err)
}
Expand All @@ -161,7 +161,7 @@ func patchComponent(args []string) error {
if patchRaw {
api.RawPatchComponent(selector, os.Stdin)
} else {
patchBytes, err := ioutil.ReadAll(os.Stdin)
patchBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(patchBytes) < 3 {
return fmt.Errorf("Unable to read patch data (read %d bytes): %v", len(patchBytes), err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -152,7 +152,7 @@ func patchEnvironment(args []string) error {
if patchRaw {
api.RawPatchEnvironment(selector, os.Stdin)
} else {
patchBytes, err := ioutil.ReadAll(os.Stdin)
patchBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(patchBytes) < 3 {
return fmt.Errorf("Unable to read patch data (read %d bytes): %v", len(patchBytes), err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/hub/cmd/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strconv"

Expand Down Expand Up @@ -254,7 +254,7 @@ func createInstance(args []string) error {
if createRaw {
api.RawCreateStackInstance(os.Stdin)
} else {
createBytes, err := ioutil.ReadAll(os.Stdin)
createBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(createBytes) < 3 {
return fmt.Errorf("Unable to read data (read %d bytes): %v", len(createBytes), err)
}
Expand All @@ -278,7 +278,7 @@ func patchInstance(args []string) error {
if patchRaw {
api.RawPatchStackInstance(selector, os.Stdin, patchReplace)
} else {
patchBytes, err := ioutil.ReadAll(os.Stdin)
patchBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(patchBytes) < 3 {
return fmt.Errorf("Unable to read patch data (read %d bytes): %v", len(patchBytes), err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/cmd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package cmd
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -89,7 +89,7 @@ func createSecret(entityKind string, args []string) error {
value = value[len(maybeKey)+1:]
}
if value == "-" {
valueBytes, err := ioutil.ReadAll(os.Stdin)
valueBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(valueBytes) == 0 {
return fmt.Errorf("Bad secret value read from stdin (read %d bytes): %s",
len(valueBytes), util.Errors2(err))
Expand Down
6 changes: 3 additions & 3 deletions cmd/hub/cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -166,7 +166,7 @@ func createTemplate(args []string) error {
if createRaw {
api.RawCreateTemplate(os.Stdin)
} else {
createBytes, err := ioutil.ReadAll(os.Stdin)
createBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(createBytes) < 3 {
return fmt.Errorf("Unable to read data (read %d bytes): %v", len(createBytes), err)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func patchTemplate(args []string) error {
if patchRaw {
api.RawPatchTemplate(selector, os.Stdin)
} else {
patchBytes, err := ioutil.ReadAll(os.Stdin)
patchBytes, err := io.ReadAll(os.Stdin)
if err != nil || len(patchBytes) < 3 {
return fmt.Errorf("Unable to read patch data (read %d bytes): %v", len(patchBytes), err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand Down Expand Up @@ -104,7 +104,7 @@ func otpEncode(args []string) error {
log.Fatalf("Unable to decode base64 random: %v", err)
}

input, err := ioutil.ReadAll(os.Stdin)
input, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Unable to read input (read %d bytes): %v", len(input), err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/hub/compose/elaborate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"sort"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/yaml.v2"

"github.com/epam/hubctl/cmd/hub/config"
Expand Down Expand Up @@ -204,7 +206,7 @@ func elaborate(manifestFilename string, parametersFilenames []string, overrides
if len(stackManifest.Components) > 0 {
components = fmt.Sprintf("with components: %s", strings.Join(stackManifest.Lifecycle.Order, ", "))
}
log.Printf("*** %s %s %s", strings.Title(stackManifest.Kind), stackManifest.Meta.Name,
log.Printf("*** %s %s %s", cases.Title(language.Und).String(stackManifest.Kind), stackManifest.Meta.Name,
components)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/filecache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package filecache
import (
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand All @@ -33,7 +33,7 @@ func ReadCache(flag int) (*os.File, *FileCache, error) {
}
return nil, nil, err
}
yamlBytes, err := ioutil.ReadAll(file)
yamlBytes, err := io.ReadAll(file)
if err != nil {
file.Close()
return nil, nil, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/hub/gcp/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package gcp
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -95,7 +95,7 @@ func ReadGCS(path string) ([]byte, error) {
return nil, err
}
defer reader.Close()
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return nil, fmt.Errorf("Failed to read GCS object `%s`: %v", path, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/hub/gcp/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

kms "cloud.google.com/go/kms/apiv1"
kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
"cloud.google.com/go/kms/apiv1/kmspb"
)

const aes256KeySize = 32
Expand Down
6 changes: 3 additions & 3 deletions cmd/hub/kube/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package kube
import (
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -125,7 +125,7 @@ func readKubeconfig(filename string) (*KubeConfig, error) {
return nil, fmt.Errorf("Unable to open `%s`: %v", filename, err)
}
defer file.Close()
content, err := ioutil.ReadAll(file)
content, err := io.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("Unable to read `%s`: %v", filename, err)
}
Expand All @@ -148,7 +148,7 @@ func writeKubeconfig(filename string, config *KubeConfig) error {
if err != nil {
return fmt.Errorf("Unable to marshall `%s`: %v", filename, err)
}
_, err = file.Seek(0, os.SEEK_SET)
_, err = file.Seek(0, io.SeekStart)
if err != nil {
return fmt.Errorf("Unable to seek `%s`: %v", filename, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/hub/lifecycle/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package lifecycle

import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -57,7 +56,7 @@ func AskParameter(parameter manifest.Parameter,
}
}
if filename != "" {
bytes, err := ioutil.ReadFile(filename)
bytes, err := os.ReadFile(filename)
if err != nil {
return "(error)", fmt.Errorf("Error reading `%s`: %v", filename, err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/hub/lifecycle/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
"io"
"log"
"os"
"strings"
"time"

"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/yaml.v2"

"github.com/epam/hubctl/cmd/hub/config"
Expand Down Expand Up @@ -136,7 +137,7 @@ func BackupCreate(request *Request, bundles []string, jsonOutput, allowPartial b
}

if config.Verbose {
log.Printf("%s %v", strings.Title(verb), implementsBackup)
log.Printf("%s %v", cases.Title(language.Und).String(verb), implementsBackup)
}

bundle := state.BackupManifest{
Expand Down
Loading

0 comments on commit e6a146b

Please sign in to comment.