Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.48.0
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15-alpine as builder
FROM golang:1.19-alpine as builder

ENV BUILD_IN_DOCKER true
ARG VERSION
Expand Down
4 changes: 2 additions & 2 deletions internal/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ func GetAPIKey(ctx context.Context, secretKey string) (*Token, error) {
}

token := &LoginResponse{}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/args/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func RegisterMarshalFunc(i interface{}, marshalFunc MarshalFunc) {
// It will take care of pointers resolution, nested structs, etc.
//
// If this function is called with:
// - a marshalable value: [ "${keys.join(.)}=${marshaledValue}" ]
// - a go struct: [ "${keys.join(.)}.field1=${marshaledField1}", ... ]
// - a go map: [ "${keys.join(.)}.key1=${marshaledValue1}", ... ]
// - a go slice: [ "${keys.join(.)}.0=${marshaledValue0}", ... ]
// - a marshal-able value: [ "${keys.join(.)}=${marshaledValue}" ]
// - a go struct: [ "${keys.join(.)}.field1=${marshaledField1}", ... ]
// - a go map: [ "${keys.join(.)}.key1=${marshaledValue1}", ... ]
// - a go slice: [ "${keys.join(.)}.0=${marshaledValue0}", ... ]
//
// src: the value to marshal
// keys: the parent keys used by recursion (nil on first level)
Expand Down
10 changes: 5 additions & 5 deletions internal/core/arg_file_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
"strings"

Expand All @@ -27,13 +27,13 @@ func loadArgsFileContent(cmd *Command, cmdArgs interface{}) error {
for _, v := range fieldValues {
switch i := v.Interface().(type) {
case io.Reader:
b, err := ioutil.ReadAll(i)
b, err := io.ReadAll(i)
if err != nil {
return fmt.Errorf("could not read argument: %s", err)
}

if strings.HasPrefix(string(b), "@") {
content, err := ioutil.ReadFile(string(b)[1:])
content, err := os.ReadFile(string(b)[1:])
if err != nil {
return fmt.Errorf("could not open requested file: %s", err)
}
Expand All @@ -42,15 +42,15 @@ func loadArgsFileContent(cmd *Command, cmdArgs interface{}) error {
}
case *string:
if strings.HasPrefix(*i, "@") {
content, err := ioutil.ReadFile((*i)[1:])
content, err := os.ReadFile((*i)[1:])
if err != nil {
return fmt.Errorf("could not open requested file: %s", err)
}
v.SetString(string(content))
}
case string:
if strings.HasPrefix(i, "@") {
content, err := ioutil.ReadFile(i[1:])
content, err := os.ReadFile(i[1:])
if err != nil {
return fmt.Errorf("could not open requested file: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/core/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewAutoCompleteCommandNode() *AutoCompleteNode {
}
}

// NewArgAutoCompleteNode creates a new node corresponding to a command argument.
// NewAutoCompleteArgNode creates a new node corresponding to a command argument.
// These nodes are leaf nodes.
func NewAutoCompleteArgNode(cmd *Command, argSpec *ArgSpec) *AutoCompleteNode {
return &AutoCompleteNode{
Expand All @@ -123,11 +123,11 @@ func NewAutoCompleteArgNode(cmd *Command, argSpec *ArgSpec) *AutoCompleteNode {
}
}

// NewFlagAutoCompleteNode returns a node representing a Flag.
// NewAutoCompleteFlagNode returns a node representing a Flag.
// It creates the children node with possible values if they exist.
// It sets parent.children as children of the lowest nodes:
// the lowest node is the flag if it has no possible value ;
// or the lowest nodes are the possible values if the exist.
// the lowest node is the flag if it has no possible value ;
// or the lowest nodes are the possible values if the exist.
func NewAutoCompleteFlagNode(parent *AutoCompleteNode, flagSpec *FlagSpec) *AutoCompleteNode {
node := &AutoCompleteNode{
Children: make(map[string]*AutoCompleteNode),
Expand Down
4 changes: 2 additions & 2 deletions internal/core/build_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -111,7 +111,7 @@ func getLatestVersion(client *http.Client) (*version.Version, error) {
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/command_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core
import (
"context"
"fmt"
"io/ioutil"
"io"
"strings"

"github.com/scaleway/scaleway-sdk-go/scw"
Expand Down Expand Up @@ -127,7 +127,7 @@ func sdkStdTypeInterceptor(ctx context.Context, args interface{}, runner Command
switch sdkValue := res.(type) {
case *scw.File:
ExtractLogger(ctx).Debug("Intercepting scw.File type, rendering as string")
fileContent, err := ioutil.ReadAll(sdkValue.Content)
fileContent, err := io.ReadAll(sdkValue.Content)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions internal/core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -330,7 +329,7 @@ func Test(config *TestConfig) func(t *testing.T) {
}

if config.TmpHomeDir {
dir, err := ioutil.TempDir(os.TempDir(), "scw")
dir, err := os.MkdirTemp(os.TempDir(), "scw")
require.NoError(t, err)
defer func() {
err = os.RemoveAll(dir)
Expand Down Expand Up @@ -582,10 +581,10 @@ func TestCheckGolden() TestCheck {
// In order to avoid diff in goldens we set all timestamp to the same date
if *UpdateGoldens {
require.NoError(t, os.MkdirAll(path.Dir(goldenPath), 0755))
require.NoError(t, ioutil.WriteFile(goldenPath, []byte(actual), 0644)) //nolint:gosec
require.NoError(t, os.WriteFile(goldenPath, []byte(actual), 0644)) //nolint:gosec
}

expected, err := ioutil.ReadFile(goldenPath)
expected, err := os.ReadFile(goldenPath)
require.NoError(t, err, "expected to find golden file %s", goldenPath)
assert.Equal(t, string(expected), actual)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package docgen
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"regexp"
"strings"
Expand All @@ -29,7 +29,7 @@ type tplResource struct {

const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"

// Generate markdown documentation for a given list of commands
// GenerateDocs generates markdown documentation for a given list of commands
func GenerateDocs(commands *core.Commands, outDir string) error {
// Prepare data that will be sent to template engine
data := &tplData{
Expand Down Expand Up @@ -77,7 +77,7 @@ func GenerateDocs(commands *core.Commands, outDir string) error {
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(outDir, name+".md"), []byte(namespaceDoc), 0600)
err = os.WriteFile(path.Join(outDir, name+".md"), []byte(namespaceDoc), 0600)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/namespaces/account/v2alpha1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package account

import (
"context"
"io/ioutil"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -47,7 +46,7 @@ func InitRun(ctx context.Context, argsI interface{}) (i interface{}, e error) {
relativePath := path.Join(".ssh", keyName)
filename := path.Join(core.ExtractUserHomeDir(ctx), relativePath)
shortenedFilename = "~/" + relativePath
localSSHKeyContent, err = ioutil.ReadFile(filename)
localSSHKeyContent, err = os.ReadFile(filename)
// If we managed to load an ssh key, let's stop there
if err == nil {
break
Expand Down
3 changes: 1 addition & 2 deletions internal/namespaces/account/v2alpha1/custom_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package account

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -23,7 +22,7 @@ func Test_initCommand(t *testing.T) {
if err != nil {
return err
}
err = ioutil.WriteFile(pathToPublicKey, []byte(content), 0644)
err = os.WriteFile(pathToPublicKey, []byte(content), 0644)
return err
}
return err
Expand Down
4 changes: 2 additions & 2 deletions internal/namespaces/autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package autocomplete
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -197,7 +197,7 @@ func InstallCommandRun(ctx context.Context, argsI interface{}) (i interface{}, e
}

// Early exit if eval line is already present in the shell configuration.
shellConfigurationFileContent, err := ioutil.ReadAll(f)
shellConfigurationFileContent, err := io.ReadAll(f)
if err != nil {
return nil, err
}
Expand Down
2 changes: 0 additions & 2 deletions internal/namespaces/baremetal/v1/baremetal_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"github.com/scaleway/scaleway-sdk-go/scw"
)

//
// Server
//
func Test_ListServer(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
Expand Down
3 changes: 2 additions & 1 deletion internal/namespaces/baremetal/v1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func createServer(metaKey string) core.BeforeFunc {

// deleteServer deletes a server
// previously registered in the context Meta at metaKey.
// nolint:unparam
//
//nolint:unparam
func deleteServer(metaKey string) core.AfterFunc {
return core.ExecAfterCmd("scw baremetal server delete zone=nl-ams-1 {{ ." + metaKey + ".ID }}")
}
Expand Down
2 changes: 0 additions & 2 deletions internal/namespaces/config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,7 @@ func configResetCommand() *core.Command {
}
}

//
// Helper functions
//
func getProfileValue(profile *scw.Profile, fieldName string) (interface{}, error) {
field, err := getProfileField(profile, fieldName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/namespaces/feedback/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func (i issue) openInBrowser(ctx context.Context) error {

switch runtime.GOOS {
case linux:
openCmd = exec.Command("xdg-open", i.getURL()) // nolint:gosec
openCmd = exec.Command("xdg-open", i.getURL()) //nolint:gosec
case windows:
openCmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", i.getURL()) // nolint:gosec
openCmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", i.getURL()) //nolint:gosec
case darwin:
openCmd = exec.Command("open", i.getURL()) // nolint:gosec
openCmd = exec.Command("open", i.getURL()) //nolint:gosec
default:
return fmt.Errorf("unsupported platform")
}
Expand Down
7 changes: 3 additions & 4 deletions internal/namespaces/init/custom_init_autocomplete_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package init

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -62,7 +61,7 @@ eval "$(scw autocomplete script shell=zsh)"
}
homeDir := ctx.OverrideEnv["HOME"]
filePath := path.Join(homeDir, ".zshrc")
fileContent, err := ioutil.ReadFile(filePath)
fileContent, err := os.ReadFile(filePath)
require.NoError(t, err)
require.Equal(t, evalLine, string(fileContent))
},
Expand Down Expand Up @@ -111,7 +110,7 @@ eval (scw autocomplete script shell=fish)
}
homeDir := ctx.OverrideEnv["HOME"]
filePath := path.Join(homeDir, ".config", "fish", "config.fish")
fileContent, err := ioutil.ReadFile(filePath)
fileContent, err := os.ReadFile(filePath)
require.NoError(t, err)
require.Equal(t, evalLine, string(fileContent))
},
Expand Down Expand Up @@ -154,7 +153,7 @@ eval "$(scw autocomplete script shell=bash)"
default:
t.Fatalf("unsupported OS")
}
fileContent, err := ioutil.ReadFile(filePath)
fileContent, err := os.ReadFile(filePath)
if err != nil {
require.NoError(t, err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/namespaces/init/custom_init_ssh_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package init

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -27,7 +26,7 @@ func setUpSSHKeyLocallyWithKeyName(key string, name string) core.BeforeFunc {
}

// Write the configuration file
err = ioutil.WriteFile(keyPath, []byte(key), 0600)
err = os.WriteFile(keyPath, []byte(key), 0600)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/namespaces/instance/v1/custom_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ func imageListBuilder(c *core.Command) *core.Command {
}

// imageDeleteBuilder override delete command to:
// - add a with-snapshots parameter

// - add a with-snapshots parameter
func imageDeleteBuilder(c *core.Command) *core.Command {
type customDeleteImageRequest struct {
*instance.DeleteImageRequest
Expand Down
1 change: 0 additions & 1 deletion internal/namespaces/instance/v1/custom_server_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ func buildVolumes(api *instance.API, zone scw.Zone, serverName, rootVolume strin
// A valid volume format is either
// - a "creation" format: ^((local|l|block|b):)?\d+GB?$ (size is handled by go-humanize, so other sizes are supported)
// - a UUID format
//
func buildVolumeTemplate(api *instance.API, zone scw.Zone, flagV string) (*instance.VolumeServerTemplate, error) {
parts := strings.Split(strings.TrimSpace(flagV), ":")

Expand Down
5 changes: 2 additions & 3 deletions internal/namespaces/instance/v1/custom_user_data_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package instance

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -60,7 +59,7 @@ func Test_UserDataFileUpload(t *testing.T) {
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic"),
func(ctx *core.BeforeFuncCtx) error {
file, _ := ioutil.TempFile("", "test")
file, _ := os.CreateTemp("", "test")
_, _ = file.WriteString(content)
ctx.Meta["filePath"] = file.Name()
return nil
Expand All @@ -83,7 +82,7 @@ func Test_UserDataFileUpload(t *testing.T) {
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic"),
func(ctx *core.BeforeFuncCtx) error {
file, _ := ioutil.TempFile("", "test")
file, _ := os.CreateTemp("", "test")
_, _ = file.WriteString(content)
ctx.Meta["filePath"] = file.Name()
return nil
Expand Down
Loading