Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0a3d9c3
cli/command/checkpoint: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
54b7933
cli/command/config: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
b4d152f
cli/command/container: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
8d0c8ef
cli/command/context: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
5c97f5c
cli/command/image: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
5237d94
cli/command/manifest: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
4f3c38a
cli/command/context: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
2230012
cli/command/node: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
d06eafc
cli/command/plugin: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
0dfc556
cli/command/registry: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
6589323
cli/command/secret: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
b061531
cli/command/service: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
7c6baba
cli/command/stack: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
b5cd20f
cli/command/swarm: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
3d4a0c1
cli/command/system: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
65e4b0e
cli/command/trust: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
03d93a9
cli/command/volume: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
8efbfcc
cli/command: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
38e8653
cli/compose: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
fc37f52
cli/config: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
cec1b29
cli/context: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
f8211f7
cli/manifest: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
dc4e683
cli/trust: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
a0f0a4f
cli: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
f471347
cmd/docker: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
58d486b
docs/yaml: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
ac72d64
e2e: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
8793cdd
internal/test: remove deprecated io/ioutil
thaJeztah Feb 25, 2022
3f681a2
man: remove deprecated io/ioutil and use t.TempDir()
thaJeztah Feb 25, 2022
d228386
opts: remove deprecated io/ioutil and use t.Cleanup()
thaJeztah Feb 25, 2022
e501531
cli-plugins/manager: remove uses of deprecated io/ioutil
thaJeztah Feb 25, 2022
0573ec2
format (GoDoc) comments with Go 1.19 to prepare for go updates
thaJeztah Jul 13, 2022
01c5120
linting: use consts from stdlib (usestdlibvars)
thaJeztah Sep 2, 2022
f9a2af0
linting: remove unused nolint comments (nolintlint)
thaJeztah Sep 2, 2022
c06cb42
linting: ST1019: package is being imported more than once (stylecheck)
thaJeztah Sep 2, 2022
8dc18ce
linting: os.Setenv() can be replaced by `t.Setenv()` (tenv)
thaJeztah Sep 2, 2022
43c1e3d
linting: ST1017: don't use Yoda conditions (stylecheck)
thaJeztah Sep 2, 2022
d3a4ff8
linting: exclude ST1005: error strings should not be capitalized (sty…
corhere Mar 1, 2023
b8dd4ca
linting: G112: Potential Slowloris Attack
thaJeztah Sep 3, 2022
2d955cb
linting: assigned to src, but reassigned without using the value (was…
thaJeztah Sep 3, 2022
48151d4
golangci-lint: update to v1.49.0 for compatibilty with go1.19
thaJeztah Sep 2, 2022
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
22 changes: 18 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
linters:
enable:
- bodyclose
- deadcode
- dogsled
- gocyclo
- goimports
Expand All @@ -13,14 +12,12 @@ linters:
- megacheck
- misspell
- nakedret
- revive
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- revive
- varcheck

disable:
- errcheck
Expand Down Expand Up @@ -93,6 +90,12 @@ issues:
linters:
- gosec

# G113 Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772)
# only affects gp < 1.16.14. and go < 1.17.7
- text: "(G113)"
linters:
- gosec

# Looks like the match in "EXC0007" above doesn't catch this one
# TODO: consider upstreaming this to golangci-lint's default exclusion rules
- text: "G204: Subprocess launched with a potential tainted input or cmd arguments"
Expand All @@ -104,12 +107,23 @@ issues:
linters:
- gosec

# TODO: make sure all packages have a description. Currently, there's 67 packages without.
- text: "package-comments: should have a package comment"
linters:
- revive

# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- errcheck
- gosec

# Fixing these lints would change user-facing output, which would be
# undesirable to introduce in a patch release.
- text: "ST1005: error strings should not be capitalized"
linters:
- stylecheck

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

Expand Down
5 changes: 2 additions & 3 deletions cli-plugins/manager/manager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package manager

import (
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -57,12 +56,12 @@ func getPluginDirs(dockerCli command.Cli) ([]string, error) {
}

func addPluginCandidatesFromDir(res map[string][]string, d string) error {
dentries, err := ioutil.ReadDir(d)
dentries, err := os.ReadDir(d)
if err != nil {
return err
}
for _, dentry := range dentries {
switch dentry.Mode() & os.ModeType {
switch dentry.Type() & os.ModeType {
case 0, os.ModeSymlink:
// Regular file or symlink, keep going
default:
Expand Down
2 changes: 0 additions & 2 deletions cli-plugins/manager/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type Plugin struct {
// is set, and is always a `pluginError`, but the `Plugin` is still
// returned with no error. An error is only returned due to a
// non-recoverable error.
//
// nolint: gocyclo
func newPlugin(c Candidate, rootcmd *cobra.Command) (Plugin, error) {
path := c.Path()
if path == "" {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/checkpoint/create_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package checkpoint

import (
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -41,7 +41,7 @@ func TestCheckpointCreateErrors(t *testing.T) {
})
cmd := newCreateCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/checkpoint/list_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package checkpoint

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

"github.com/docker/cli/internal/test"
Expand Down Expand Up @@ -41,7 +41,7 @@ func TestCheckpointListErrors(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/checkpoint/remove_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package checkpoint

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

"github.com/docker/cli/internal/test"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestCheckpointRemoveErrors(t *testing.T) {
})
cmd := newRemoveCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"context"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -279,7 +278,7 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
store := &ContextStoreWithDefault{
Store: store.New(cliconfig.ContextStoreDir(), storeConfig),
Resolver: func() (*DefaultContext, error) {
return ResolveDefaultContext(opts, configFile, storeConfig, ioutil.Discard)
return ResolveDefaultContext(opts, configFile, storeConfig, io.Discard)
},
}
contextName, err := resolveContextName(opts, configFile, store)
Expand Down
26 changes: 8 additions & 18 deletions cli/command/cli_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,13 @@ func contentTrustEnabled(t *testing.T) bool {

// NB: Do not t.Parallel() this test -- it messes with the process environment.
func TestWithContentTrustFromEnv(t *testing.T) {
envvar := "DOCKER_CONTENT_TRUST"
if orig, ok := os.LookupEnv(envvar); ok {
defer func() {
os.Setenv(envvar, orig)
}()
} else {
defer func() {
os.Unsetenv(envvar)
}()
}

os.Setenv(envvar, "true")
assert.Assert(t, contentTrustEnabled(t))
os.Setenv(envvar, "false")
assert.Assert(t, !contentTrustEnabled(t))
os.Setenv(envvar, "invalid")
assert.Assert(t, contentTrustEnabled(t))
const envvar = "DOCKER_CONTENT_TRUST"
t.Setenv(envvar, "true")
assert.Check(t, contentTrustEnabled(t))
t.Setenv(envvar, "false")
assert.Check(t, !contentTrustEnabled(t))
t.Setenv(envvar, "invalid")
assert.Check(t, contentTrustEnabled(t))
os.Unsetenv(envvar)
assert.Assert(t, !contentTrustEnabled(t))
assert.Check(t, !contentTrustEnabled(t))
}
10 changes: 5 additions & 5 deletions cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"crypto/x509"
"fmt"
"io/ioutil"
"io"
"os"
"runtime"
"testing"
Expand Down Expand Up @@ -275,23 +275,23 @@ func TestNewDockerCliAndOperators(t *testing.T) {
outbuf := bytes.NewBuffer(nil)
errbuf := bytes.NewBuffer(nil)
err = cli.Apply(
WithInputStream(ioutil.NopCloser(inbuf)),
WithInputStream(io.NopCloser(inbuf)),
WithOutputStream(outbuf),
WithErrorStream(errbuf),
)
assert.NilError(t, err)
// Check input stream
inputStream, err := ioutil.ReadAll(cli.In())
inputStream, err := io.ReadAll(cli.In())
assert.NilError(t, err)
assert.Equal(t, string(inputStream), "input")
// Check output stream
fmt.Fprintf(cli.Out(), "output")
outputStream, err := ioutil.ReadAll(outbuf)
outputStream, err := io.ReadAll(outbuf)
assert.NilError(t, err)
assert.Equal(t, string(outputStream), "output")
// Check error stream
fmt.Fprintf(cli.Err(), "error")
errStream, err := ioutil.ReadAll(errbuf)
errStream, err := io.ReadAll(errbuf)
assert.NilError(t, err)
assert.Equal(t, string(errStream), "error")
}
Expand Down
3 changes: 1 addition & 2 deletions cli/command/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -61,7 +60,7 @@ func RunConfigCreate(dockerCli command.Cli, options CreateOptions) error {
defer file.Close()
}

configData, err := ioutil.ReadAll(in)
configData, err := io.ReadAll(in)
if err != nil {
return errors.Errorf("Error reading content from %q: %v", options.File, err)
}
Expand Down
7 changes: 4 additions & 3 deletions cli/command/config/create_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package config

import (
"io/ioutil"
"io"
"os"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestConfigCreateErrors(t *testing.T) {
}),
)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
}
name := "foo"

data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile))
data, err := os.ReadFile(filepath.Join("testdata", configDataFile))
assert.NilError(t, err)

expected := swarm.ConfigSpec{
Expand Down
4 changes: 2 additions & 2 deletions cli/command/config/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

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

Expand Down Expand Up @@ -59,7 +59,7 @@ func TestConfigInspectErrors(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/config/ls_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -40,7 +40,7 @@ func TestConfigListErrors(t *testing.T) {
}),
)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cli/command/config/remove_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -36,7 +36,7 @@ func TestConfigRemoveErrors(t *testing.T) {
}),
)
cmd.SetArgs(tc.args)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestConfigRemoveContinueAfterError(t *testing.T) {

cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names)
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
assert.Error(t, cmd.Execute(), "error removing config: foo")
assert.Check(t, is.DeepEqual(names, removedConfigs))
}
4 changes: 2 additions & 2 deletions cli/command/container/attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package container

import (
"fmt"
"io/ioutil"
"io"
"testing"

"github.com/docker/cli/cli"
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
}
for _, tc := range testCases {
cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
cmd.SetOut(ioutil.Discard)
cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args)
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
}
Expand Down
6 changes: 4 additions & 2 deletions cli/command/container/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
// in a valid LOCALPATH, like `file:name.txt`. We can resolve this ambiguity by
// requiring a LOCALPATH with a `:` to be made explicit with a relative or
// absolute path:
// `/path/to/file:name.txt` or `./file:name.txt`
//
// `/path/to/file:name.txt` or `./file:name.txt`
//
// This is apparently how `scp` handles this as well:
// http://www.cyberciti.biz/faq/rsync-scp-file-name-with-colon-punctuation-in-it/
//
// http://www.cyberciti.biz/faq/rsync-scp-file-name-with-colon-punctuation-in-it/
//
// We can't simply check for a filepath separator because container names may
// have a separator, e.g., "host0/cname1" if container is in a Docker cluster,
Expand Down
5 changes: 2 additions & 3 deletions cli/command/container/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package container

import (
"io"
"io/ioutil"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestRunCopyFromContainerToStdout(t *testing.T) {
fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Check(t, is.Equal("container", container))
return ioutil.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil
return io.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil
},
}
options := copyOptions{source: "container:/path", destination: "-"}
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
assert.Check(t, is.Equal("", cli.OutBuffer().String()))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))

content, err := ioutil.ReadFile(destDir.Join("file1"))
content, err := os.ReadFile(destDir.Join("file1"))
assert.NilError(t, err)
assert.Check(t, is.Equal("content\n", string(content)))
}
Expand Down
Loading