diff --git a/cli/command/completion/functions.go b/cli/command/completion/functions.go index 6aa42e5799ae..c2e18640630a 100644 --- a/cli/command/completion/functions.go +++ b/cli/command/completion/functions.go @@ -7,8 +7,6 @@ import ( "github.com/docker/cli/cli/command/formatter" "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/volume" "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -79,7 +77,7 @@ func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(conta // VolumeNames offers completion for volumes func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, err := dockerCLI.Client().VolumeList(cmd.Context(), volume.ListOptions{}) + list, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{}) if err != nil { return nil, cobra.ShellCompDirectiveError } @@ -94,7 +92,7 @@ func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc { // NetworkNames offers completion for networks func NetworkNames(dockerCLI APIClientProvider) cobra.CompletionFunc { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, err := dockerCLI.Client().NetworkList(cmd.Context(), network.ListOptions{}) + list, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{}) if err != nil { return nil, cobra.ShellCompDirectiveError } diff --git a/cli/command/completion/functions_test.go b/cli/command/completion/functions_test.go index a7ef293958c4..29a8ecabcd78 100644 --- a/cli/command/completion/functions_test.go +++ b/cli/command/completion/functions_test.go @@ -32,7 +32,7 @@ type fakeClient struct { client.Client containerListFunc func(options container.ListOptions) ([]container.Summary, error) imageListFunc func(options image.ListOptions) ([]image.Summary, error) - networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) + networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) volumeListFunc func(filter filters.Args) (volume.ListResponse, error) } @@ -50,14 +50,14 @@ func (c *fakeClient) ImageList(_ context.Context, options image.ListOptions) ([] return []image.Summary{}, nil } -func (c *fakeClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { +func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { if c.networkListFunc != nil { return c.networkListFunc(ctx, options) } return []network.Inspect{}, nil } -func (c *fakeClient) VolumeList(_ context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (c *fakeClient) VolumeList(_ context.Context, options client.VolumeListOptions) (volume.ListResponse, error) { if c.volumeListFunc != nil { return c.volumeListFunc(options.Filters) } @@ -273,7 +273,7 @@ func TestCompleteNetworkNames(t *testing.T) { for _, tc := range tests { t.Run(tc.doc, func(t *testing.T) { comp := NetworkNames(fakeCLI{&fakeClient{ - networkListFunc: func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { + networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { if tc.expDirective == cobra.ShellCompDirectiveError { return nil, errors.New("some error occurred") } diff --git a/cli/command/config/client_test.go b/cli/command/config/client_test.go index c3815d04e158..ceaeb06ca3b6 100644 --- a/cli/command/config/client_test.go +++ b/cli/command/config/client_test.go @@ -11,7 +11,7 @@ type fakeClient struct { client.Client configCreateFunc func(context.Context, swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) configInspectFunc func(context.Context, string) (swarm.Config, []byte, error) - configListFunc func(context.Context, swarm.ConfigListOptions) ([]swarm.Config, error) + configListFunc func(context.Context, client.ConfigListOptions) ([]swarm.Config, error) configRemoveFunc func(string) error } @@ -29,7 +29,7 @@ func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm return swarm.Config{}, nil, nil } -func (c *fakeClient) ConfigList(ctx context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { +func (c *fakeClient) ConfigList(ctx context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { if c.configListFunc != nil { return c.configListFunc(ctx, options) } diff --git a/cli/command/config/cmd.go b/cli/command/config/cmd.go index 09e46a690f52..d4d60df4d305 100644 --- a/cli/command/config/cmd.go +++ b/cli/command/config/cmd.go @@ -5,7 +5,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/internal/commands" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -37,7 +37,7 @@ func newConfigCommand(dockerCLI command.Cli) *cobra.Command { // completeNames offers completion for swarm configs func completeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, err := dockerCLI.Client().ConfigList(cmd.Context(), swarm.ConfigListOptions{}) + list, err := dockerCLI.Client().ConfigList(cmd.Context(), client.ConfigListOptions{}) if err != nil { return nil, cobra.ShellCompDirectiveError } diff --git a/cli/command/config/ls.go b/cli/command/config/ls.go index 07db2f73f149..154738949848 100644 --- a/cli/command/config/ls.go +++ b/cli/command/config/ls.go @@ -11,7 +11,7 @@ import ( flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/fvbommel/sortorder" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -48,7 +48,7 @@ func newConfigListCommand(dockerCLI command.Cli) *cobra.Command { func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error { apiClient := dockerCLI.Client() - configs, err := apiClient.ConfigList(ctx, swarm.ConfigListOptions{Filters: options.filter.Value()}) + configs, err := apiClient.ConfigList(ctx, client.ConfigListOptions{Filters: options.filter.Value()}) if err != nil { return err } diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index 7e3b4b263b94..e817c303f0bf 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -19,7 +20,7 @@ import ( func TestConfigListErrors(t *testing.T) { testCases := []struct { args []string - configListFunc func(context.Context, swarm.ConfigListOptions) ([]swarm.Config, error) + configListFunc func(context.Context, client.ConfigListOptions) ([]swarm.Config, error) expectedError string }{ { @@ -27,7 +28,7 @@ func TestConfigListErrors(t *testing.T) { expectedError: "accepts no argument", }, { - configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{}, errors.New("error listing configs") }, expectedError: "error listing configs", @@ -48,7 +49,7 @@ func TestConfigListErrors(t *testing.T) { func TestConfigList(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *builders.Config(builders.ConfigID("ID-1-foo"), builders.ConfigName("1-foo"), @@ -78,7 +79,7 @@ func TestConfigList(t *testing.T) { func TestConfigListWithQuietOption(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), *builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{ @@ -95,7 +96,7 @@ func TestConfigListWithQuietOption(t *testing.T) { func TestConfigListWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), *builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{ @@ -114,7 +115,7 @@ func TestConfigListWithConfigFormat(t *testing.T) { func TestConfigListWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), *builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{ @@ -131,7 +132,7 @@ func TestConfigListWithFormat(t *testing.T) { func TestConfigListWithFilter(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0])) assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0])) return []swarm.Config{ diff --git a/cli/command/container/client_test.go b/cli/command/container/client_test.go index 182f6d5670a0..7e6ede8ff8ab 100644 --- a/cli/command/container/client_test.go +++ b/cli/command/container/client_test.go @@ -32,7 +32,7 @@ type fakeClient struct { waitFunc func(string) (<-chan container.WaitResponse, <-chan error) containerListFunc func(container.ListOptions) ([]container.Summary, error) containerExportFunc func(string) (io.ReadCloser, error) - containerExecResizeFunc func(id string, options container.ResizeOptions) error + containerExecResizeFunc func(id string, options client.ContainerResizeOptions) error containerRemoveFunc func(ctx context.Context, containerID string, options container.RemoveOptions) error containerRestartFunc func(ctx context.Context, containerID string, options container.StopOptions) error containerStopFunc func(ctx context.Context, containerID string, options container.StopOptions) error @@ -159,7 +159,7 @@ func (f *fakeClient) ContainerExport(_ context.Context, containerID string) (io. return nil, nil } -func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options container.ResizeOptions) error { +func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options client.ContainerResizeOptions) error { if f.containerExecResizeFunc != nil { return f.containerExecResizeFunc(id, options) } diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 395d6e39acc6..44dce2d26443 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -1016,7 +1016,7 @@ func TestParseLabelfileVariables(t *testing.T) { func TestParseEntryPoint(t *testing.T) { config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"}) assert.NilError(t, err) - assert.Check(t, is.DeepEqual([]string(config.Entrypoint), []string{"anything"})) + assert.Check(t, is.DeepEqual(config.Entrypoint, []string{"anything"})) } func TestValidateDevice(t *testing.T) { diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index 75aabdc7a37b..eee267c28ece 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -18,6 +18,7 @@ import ( "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/filters" + "github.com/moby/moby/client" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -164,7 +165,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions) // is not valid for filtering containers. f := options.Filters.Clone() f.Add("type", string(events.ContainerEventType)) - eventChan, errChan := apiClient.Events(ctx, events.ListOptions{ + eventChan, errChan := apiClient.Events(ctx, client.EventsListOptions{ Filters: f, }) diff --git a/cli/command/container/tty.go b/cli/command/container/tty.go index ebe1dd1cab85..6d040450ed49 100644 --- a/cli/command/container/tty.go +++ b/cli/command/container/tty.go @@ -9,7 +9,6 @@ import ( "time" "github.com/docker/cli/cli/command" - "github.com/moby/moby/api/types/container" "github.com/moby/moby/client" "github.com/moby/sys/signal" "github.com/sirupsen/logrus" @@ -21,7 +20,7 @@ func resizeTtyTo(ctx context.Context, apiClient client.ContainerAPIClient, id st return nil } - options := container.ResizeOptions{ + options := client.ContainerResizeOptions{ Height: height, Width: width, } diff --git a/cli/command/container/tty_test.go b/cli/command/container/tty_test.go index a6fee5f6a773..8175ba619087 100644 --- a/cli/command/container/tty_test.go +++ b/cli/command/container/tty_test.go @@ -8,14 +8,14 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/internal/test" - "github.com/moby/moby/api/types/container" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) func TestInitTtySizeErrors(t *testing.T) { expectedError := "failed to resize tty, using default size\n" - fakeContainerExecResizeFunc := func(id string, options container.ResizeOptions) error { + fakeContainerExecResizeFunc := func(id string, options client.ContainerResizeOptions) error { return errors.New("Error response from daemon: no such exec") } fakeResizeTtyFunc := func(ctx context.Context, cli command.Cli, id string, isExec bool) error { diff --git a/cli/command/container/utils.go b/cli/command/container/utils.go index d21c6c455aa5..364e4a7fda3d 100644 --- a/cli/command/container/utils.go +++ b/cli/command/container/utils.go @@ -69,7 +69,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co f.Add("container", containerID) eventCtx, cancel := context.WithCancel(ctx) - eventq, errq := apiClient.Events(eventCtx, events.ListOptions{ + eventq, errq := apiClient.Events(eventCtx, client.EventsListOptions{ Filters: f, }) diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index 01446efea5b1..60dfb91b42f2 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -344,7 +344,7 @@ func (c *ContainerContext) Networks() string { // DisplayablePorts returns formatted string representing open ports of container // e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" // it's used by command 'docker ps' -func DisplayablePorts(ports []container.Port) string { +func DisplayablePorts(ports []container.PortSummary) string { type portGroup struct { first uint16 last uint16 @@ -410,7 +410,7 @@ func formGroup(key string, start, last uint16) string { return group + "/" + groupType } -func comparePorts(i, j container.Port) bool { +func comparePorts(i, j container.PortSummary) bool { if i.PrivatePort != j.PrivatePort { return i.PrivatePort < j.PrivatePort } diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index b5a96950c1bc..594ced3b47d0 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -137,7 +137,7 @@ func TestContainerPsContext(t *testing.T) { call: ctx.CreatedAt, }, { - container: container.Summary{Ports: []container.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, + container: container.Summary{Ports: []container.PortSummary{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, trunc: true, expValue: "8080/tcp", call: ctx.Ports, @@ -586,7 +586,7 @@ func TestContainerBackCompat(t *testing.T) { ImageManifestDescriptor: nil, Command: "/bin/sh", Created: createdAtTime.UTC().Unix(), - Ports: []container.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}, + Ports: []container.PortSummary{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}, SizeRw: 123, SizeRootFs: 12345, Labels: map[string]string{"label1": "value1", "label2": "value2"}, @@ -633,14 +633,14 @@ func TestContainerBackCompat(t *testing.T) { } type ports struct { - ports []container.Port + ports []container.PortSummary expected string } func TestDisplayablePorts(t *testing.T) { cases := []ports{ { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 9988, Type: "tcp", @@ -649,7 +649,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 9988, Type: "udp", @@ -658,7 +658,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "0.0.0.0", PrivatePort: 9988, @@ -668,7 +668,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "0.0.0.0:0->9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "::", PrivatePort: 9988, @@ -678,7 +678,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "[::]:0->9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 9988, PublicPort: 8899, @@ -688,7 +688,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "4.3.2.1", PrivatePort: 9988, @@ -699,7 +699,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "4.3.2.1:8899->9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "::1", PrivatePort: 9988, @@ -710,7 +710,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "[::1]:8899->9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "4.3.2.1", PrivatePort: 9988, @@ -721,7 +721,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "4.3.2.1:9988->9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "::1", PrivatePort: 9988, @@ -732,7 +732,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "[::1]:9988->9988/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 9988, Type: "udp", @@ -744,7 +744,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp, 9988/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "1.2.3.4", PublicPort: 9998, @@ -760,7 +760,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "1.2.3.4:9998-9999->9998-9999/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "::1", PublicPort: 9998, @@ -776,7 +776,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "[::1]:9998-9999->9998-9999/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "1.2.3.4", PublicPort: 8887, @@ -792,7 +792,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "::1", PublicPort: 8887, @@ -808,7 +808,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "[::1]:8887->9998/udp, [::1]:8888->9999/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 9998, Type: "udp", @@ -820,7 +820,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9998-9999/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "1.2.3.4", PrivatePort: 6677, @@ -835,7 +835,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp, 1.2.3.4:7766->6677/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { IP: "1.2.3.4", PrivatePort: 9988, @@ -861,7 +861,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "4.3.2.1:3322->2233/tcp, [::1]:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 9988, PublicPort: 8899, @@ -881,7 +881,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp", }, { - ports: []container.Port{ + ports: []container.PortSummary{ { PrivatePort: 80, Type: "tcp", diff --git a/cli/command/idresolver/client_test.go b/cli/command/idresolver/client_test.go index a559634d0a1c..f9db43da5703 100644 --- a/cli/command/idresolver/client_test.go +++ b/cli/command/idresolver/client_test.go @@ -20,7 +20,7 @@ func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, nodeID string) (swa return swarm.Node{}, []byte{}, nil } -func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ client.ServiceInspectOptions) (swarm.Service, []byte, error) { if cli.serviceInspectFunc != nil { return cli.serviceInspectFunc(serviceID) } diff --git a/cli/command/idresolver/idresolver.go b/cli/command/idresolver/idresolver.go index 1b87edcdd312..430037e61003 100644 --- a/cli/command/idresolver/idresolver.go +++ b/cli/command/idresolver/idresolver.go @@ -43,7 +43,7 @@ func (r *IDResolver) get(ctx context.Context, t any, id string) (string, error) } return id, nil case swarm.Service: - service, _, err := r.client.ServiceInspectWithRaw(ctx, id, swarm.ServiceInspectOptions{}) + service, _, err := r.client.ServiceInspectWithRaw(ctx, id, client.ServiceInspectOptions{}) if err != nil { // TODO(thaJeztah): should error-handling be more specific, or is it ok to ignore any error? return id, nil //nolint:nilerr // ignore nil-error being returned, as this is a best-effort. diff --git a/cli/command/image/push.go b/cli/command/image/push.go index f81ebe0916ef..5c3da6c72ff2 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -18,9 +18,9 @@ import ( "github.com/docker/cli/internal/jsonstream" "github.com/docker/cli/internal/registry" "github.com/docker/cli/internal/tui" + "github.com/moby/moby/api/pkg/authconfig" "github.com/moby/moby/api/types/auxprogress" "github.com/moby/moby/api/types/image" - registrytypes "github.com/moby/moby/api/types/registry" "github.com/morikuni/aec" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" @@ -111,7 +111,7 @@ To push the complete multi-platform image, remove the --platform flag. // Resolve the Auth config relevant for this server authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), indexInfo) - encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig) + encodedAuth, err := authconfig.Encode(authConfig) if err != nil { return err } diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index b78765b6e4c8..c751a8a6c939 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -12,6 +12,7 @@ import ( "github.com/docker/cli/cli/streams" "github.com/docker/cli/cli/trust" "github.com/docker/cli/internal/jsonstream" + "github.com/moby/moby/api/pkg/authconfig" "github.com/moby/moby/api/types/image" registrytypes "github.com/moby/moby/api/types/registry" "github.com/opencontainers/go-digest" @@ -149,7 +150,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) // imagePullPrivileged pulls the image and displays it to the output func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, opts pullOptions) error { - encodedAuth, err := registrytypes.EncodeAuthConfig(*imgRefAndAuth.AuthConfig()) + encodedAuth, err := authconfig.Encode(*imgRefAndAuth.AuthConfig()) if err != nil { return err } diff --git a/cli/command/network/client_test.go b/cli/command/network/client_test.go index 184795d2ca5e..064b6effb72d 100644 --- a/cli/command/network/client_test.go +++ b/cli/command/network/client_test.go @@ -14,9 +14,9 @@ type fakeClient struct { networkConnectFunc func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error networkRemoveFunc func(ctx context.Context, networkID string) error - networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) + networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) networkPruneFunc func(ctx context.Context, pruneFilters filters.Args) (network.PruneReport, error) - networkInspectFunc func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, []byte, error) + networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, []byte, error) } func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) { @@ -40,7 +40,7 @@ func (c *fakeClient) NetworkDisconnect(ctx context.Context, networkID, container return nil } -func (c *fakeClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { +func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { if c.networkListFunc != nil { return c.networkListFunc(ctx, options) } @@ -54,7 +54,7 @@ func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string) error return nil } -func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, opts network.InspectOptions) (network.Inspect, []byte, error) { +func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, opts client.NetworkInspectOptions) (network.Inspect, []byte, error) { if c.networkInspectFunc != nil { return c.networkInspectFunc(ctx, networkID, opts) } diff --git a/cli/command/network/inspect.go b/cli/command/network/inspect.go index 76a79d96fce7..51ef3bedcf1f 100644 --- a/cli/command/network/inspect.go +++ b/cli/command/network/inspect.go @@ -12,7 +12,6 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/inspect" flagsHelper "github.com/docker/cli/cli/flags" - "github.com/moby/moby/api/types/network" "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -45,6 +44,6 @@ func newInspectCommand(dockerCLI command.Cli) *cobra.Command { func runInspect(ctx context.Context, apiClient client.NetworkAPIClient, output io.Writer, opts inspectOptions) error { return inspect.Inspect(output, opts.names, opts.format, func(name string) (any, []byte, error) { - return apiClient.NetworkInspectWithRaw(ctx, name, network.InspectOptions{Verbose: opts.verbose}) + return apiClient.NetworkInspectWithRaw(ctx, name, client.NetworkInspectOptions{Verbose: opts.verbose}) }) } diff --git a/cli/command/network/list.go b/cli/command/network/list.go index 0833a37416a9..6ebd6e21b65d 100644 --- a/cli/command/network/list.go +++ b/cli/command/network/list.go @@ -11,7 +11,7 @@ import ( flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/fvbommel/sortorder" - "github.com/moby/moby/api/types/network" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -47,7 +47,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error { apiClient := dockerCLI.Client() - networkResources, err := apiClient.NetworkList(ctx, network.ListOptions{Filters: options.filter.Value()}) + networkResources, err := apiClient.NetworkList(ctx, client.NetworkListOptions{Filters: options.filter.Value()}) if err != nil { return err } diff --git a/cli/command/network/list_test.go b/cli/command/network/list_test.go index df0d93d34956..243dced61f73 100644 --- a/cli/command/network/list_test.go +++ b/cli/command/network/list_test.go @@ -11,6 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/network" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -18,11 +19,11 @@ import ( func TestNetworkListErrors(t *testing.T) { testCases := []struct { - networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) + networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) expectedError string }{ { - networkListFunc: func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { + networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { return []network.Summary{}, errors.New("error creating network") }, expectedError: "error creating network", @@ -44,7 +45,7 @@ func TestNetworkListErrors(t *testing.T) { func TestNetworkList(t *testing.T) { testCases := []struct { doc string - networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) + networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) flags map[string]string golden string }{ @@ -54,8 +55,8 @@ func TestNetworkList(t *testing.T) { "filter": "image.name=ubuntu", }, golden: "network-list.golden", - networkListFunc: func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { - expectedOpts := network.ListOptions{ + networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { + expectedOpts := client.NetworkListOptions{ Filters: filters.NewArgs(filters.Arg("image.name", "ubuntu")), } assert.Check(t, is.DeepEqual(expectedOpts, options, cmp.AllowUnexported(filters.Args{}))) @@ -72,7 +73,7 @@ func TestNetworkList(t *testing.T) { "format": "{{ .Name }}", }, golden: "network-list-sort.golden", - networkListFunc: func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { + networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { return []network.Summary{ *builders.NetworkResource(builders.NetworkResourceName("network-2-foo")), *builders.NetworkResource(builders.NetworkResourceName("network-1-foo")), diff --git a/cli/command/network/remove.go b/cli/command/network/remove.go index 78a605e052a3..1694c6cf3de6 100644 --- a/cli/command/network/remove.go +++ b/cli/command/network/remove.go @@ -10,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/internal/prompt" - "github.com/moby/moby/api/types/network" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -48,7 +48,7 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, networks []string, op status := 0 for _, name := range networks { - nw, _, err := apiClient.NetworkInspectWithRaw(ctx, name, network.InspectOptions{}) + nw, _, err := apiClient.NetworkInspectWithRaw(ctx, name, client.NetworkInspectOptions{}) if err == nil && nw.Ingress { r, err := prompt.Confirm(ctx, dockerCLI.In(), dockerCLI.Out(), ingressWarning) if err != nil { diff --git a/cli/command/network/remove_test.go b/cli/command/network/remove_test.go index ef22ce908523..a020091caa88 100644 --- a/cli/command/network/remove_test.go +++ b/cli/command/network/remove_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/moby/moby/api/types/network" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -110,7 +111,7 @@ func TestNetworkRemovePromptTermination(t *testing.T) { networkRemoveFunc: func(ctx context.Context, networkID string) error { return errors.New("fakeClient networkRemoveFunc should not be called") }, - networkInspectFunc: func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, []byte, error) { + networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, []byte, error) { return network.Inspect{ ID: "existing-network", Name: "existing-network", diff --git a/cli/command/node/client_test.go b/cli/command/node/client_test.go index 2bca128b7111..a3ac56b6fb0d 100644 --- a/cli/command/node/client_test.go +++ b/cli/command/node/client_test.go @@ -16,8 +16,8 @@ type fakeClient struct { nodeRemoveFunc func() error nodeUpdateFunc func(nodeID string, version swarm.Version, node swarm.NodeSpec) error taskInspectFunc func(taskID string) (swarm.Task, []byte, error) - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) - serviceInspectFunc func(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) + serviceInspectFunc func(ctx context.Context, serviceID string, opts client.ServiceInspectOptions) (swarm.Service, []byte, error) } func (cli *fakeClient) NodeInspectWithRaw(context.Context, string) (swarm.Node, []byte, error) { @@ -27,14 +27,14 @@ func (cli *fakeClient) NodeInspectWithRaw(context.Context, string) (swarm.Node, return swarm.Node{}, []byte{}, nil } -func (cli *fakeClient) NodeList(context.Context, swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *fakeClient) NodeList(context.Context, client.NodeListOptions) ([]swarm.Node, error) { if cli.nodeListFunc != nil { return cli.nodeListFunc() } return []swarm.Node{}, nil } -func (cli *fakeClient) NodeRemove(context.Context, string, swarm.NodeRemoveOptions) error { +func (cli *fakeClient) NodeRemove(context.Context, string, client.NodeRemoveOptions) error { if cli.nodeRemoveFunc != nil { return cli.nodeRemoveFunc() } @@ -62,14 +62,14 @@ func (cli *fakeClient) TaskInspectWithRaw(_ context.Context, taskID string) (swa return swarm.Task{}, []byte{}, nil } -func (cli *fakeClient) TaskList(_ context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { +func (cli *fakeClient) TaskList(_ context.Context, options client.TaskListOptions) ([]swarm.Task, error) { if cli.taskListFunc != nil { return cli.taskListFunc(options) } return []swarm.Task{}, nil } -func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts client.ServiceInspectOptions) (swarm.Service, []byte, error) { if cli.serviceInspectFunc != nil { return cli.serviceInspectFunc(ctx, serviceID, opts) } diff --git a/cli/command/node/cmd.go b/cli/command/node/cmd.go index 711277925ca8..c9df158900ce 100644 --- a/cli/command/node/cmd.go +++ b/cli/command/node/cmd.go @@ -7,7 +7,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/internal/commands" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -55,7 +54,7 @@ func Reference(ctx context.Context, apiClient client.APIClient, ref string) (str // get a more specific error message. // // FIXME(thaJeztah): this should not require calling a Swarm endpoint, and we could just suffice with info / ping (which has swarm status). - _, err = apiClient.NodeList(ctx, swarm.NodeListOptions{}) + _, err = apiClient.NodeList(ctx, client.NodeListOptions{}) if err != nil { return "", err } diff --git a/cli/command/node/completion.go b/cli/command/node/completion.go index 8215c0a3186c..43d77345e56b 100644 --- a/cli/command/node/completion.go +++ b/cli/command/node/completion.go @@ -4,7 +4,7 @@ import ( "os" "github.com/docker/cli/cli/command/completion" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -17,7 +17,7 @@ func completeNodeNames(dockerCLI completion.APIClientProvider) cobra.CompletionF // https://github.com/docker/cli/blob/f9ced58158d5e0b358052432244b483774a1983d/contrib/completion/bash/docker#L41-L43 showIDs := os.Getenv("DOCKER_COMPLETION_SHOW_NODE_IDS") == "yes" return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, err := dockerCLI.Client().NodeList(cmd.Context(), swarm.NodeListOptions{}) + list, err := dockerCLI.Client().NodeList(cmd.Context(), client.NodeListOptions{}) if err != nil { return nil, cobra.ShellCompDirectiveError } diff --git a/cli/command/node/list.go b/cli/command/node/list.go index 6561ed47f657..4acbb215889c 100644 --- a/cli/command/node/list.go +++ b/cli/command/node/list.go @@ -11,8 +11,8 @@ import ( flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/fvbommel/sortorder" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/system" + "github.com/moby/moby/client" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -53,7 +53,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error { apiClient := dockerCLI.Client() - nodes, err := apiClient.NodeList(ctx, swarm.NodeListOptions{ + nodes, err := apiClient.NodeList(ctx, client.NodeListOptions{ Filters: options.filter.Value(), }) if err != nil { diff --git a/cli/command/node/ps.go b/cli/command/node/ps.go index 37df147cff3f..52ebc586f32d 100644 --- a/cli/command/node/ps.go +++ b/cli/command/node/ps.go @@ -11,6 +11,7 @@ import ( "github.com/docker/cli/cli/command/task" "github.com/docker/cli/opts" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -83,7 +84,7 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error filter := options.filter.Value() filter.Add("node", node.ID) - nodeTasks, err := apiClient.TaskList(ctx, swarm.TaskListOptions{Filters: filter}) + nodeTasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter}) if err != nil { errs = append(errs, err.Error()) continue diff --git a/cli/command/node/ps_test.go b/cli/command/node/ps_test.go index 4fa143d76262..6ad9a7f0fa56 100644 --- a/cli/command/node/ps_test.go +++ b/cli/command/node/ps_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/system" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -22,7 +23,7 @@ func TestNodePsErrors(t *testing.T) { flags map[string]string infoFunc func() (system.Info, error) nodeInspectFunc func() (swarm.Node, []byte, error) - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) taskInspectFunc func(taskID string) (swarm.Task, []byte, error) expectedError string }{ @@ -41,7 +42,7 @@ func TestNodePsErrors(t *testing.T) { }, { args: []string{"nodeID"}, - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{}, errors.New("error returning the task list") }, expectedError: "error returning the task list", @@ -72,9 +73,9 @@ func TestNodePs(t *testing.T) { flags map[string]string infoFunc func() (system.Info, error) nodeInspectFunc func() (swarm.Node, []byte, error) - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) taskInspectFunc func(taskID string) (swarm.Task, []byte, error) - serviceInspectFunc func(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) + serviceInspectFunc func(ctx context.Context, serviceID string, opts client.ServiceInspectOptions) (swarm.Service, []byte, error) }{ { name: "simple", @@ -82,7 +83,7 @@ func TestNodePs(t *testing.T) { nodeInspectFunc: func() (swarm.Node, []byte, error) { return *builders.Node(), []byte{}, nil }, - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{ *builders.Task(builders.WithStatus(builders.Timestamp(time.Now().Add(-2*time.Hour)), builders.PortStatus([]swarm.PortConfig{ { @@ -93,7 +94,7 @@ func TestNodePs(t *testing.T) { }))), }, nil }, - serviceInspectFunc: func(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { + serviceInspectFunc: func(ctx context.Context, serviceID string, opts client.ServiceInspectOptions) (swarm.Service, []byte, error) { return swarm.Service{ ID: serviceID, Spec: swarm.ServiceSpec{ @@ -110,7 +111,7 @@ func TestNodePs(t *testing.T) { nodeInspectFunc: func() (swarm.Node, []byte, error) { return *builders.Node(), []byte{}, nil }, - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{ *builders.Task(builders.TaskID("taskID1"), builders.TaskServiceID("failure"), builders.WithStatus(builders.Timestamp(time.Now().Add(-2*time.Hour)), builders.StatusErr("a task error"))), @@ -120,7 +121,7 @@ func TestNodePs(t *testing.T) { builders.WithStatus(builders.Timestamp(time.Now().Add(-4*time.Hour)), builders.StatusErr("a task error"))), }, nil }, - serviceInspectFunc: func(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { + serviceInspectFunc: func(ctx context.Context, serviceID string, opts client.ServiceInspectOptions) (swarm.Service, []byte, error) { return swarm.Service{ ID: serviceID, Spec: swarm.ServiceSpec{ diff --git a/cli/command/node/remove.go b/cli/command/node/remove.go index f36df26c8305..b9a4a96ea832 100644 --- a/cli/command/node/remove.go +++ b/cli/command/node/remove.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -38,7 +38,7 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, nodeIDs []string, opt var errs []error for _, id := range nodeIDs { - if err := apiClient.NodeRemove(ctx, id, swarm.NodeRemoveOptions{Force: opts.force}); err != nil { + if err := apiClient.NodeRemove(ctx, id, client.NodeRemoveOptions{Force: opts.force}); err != nil { errs = append(errs, err) continue } diff --git a/cli/command/registry.go b/cli/command/registry.go index 2a727e32b103..05e07dda1a1c 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -16,6 +16,7 @@ import ( "github.com/docker/cli/cli/streams" "github.com/docker/cli/internal/prompt" "github.com/docker/cli/internal/tui" + "github.com/moby/moby/api/pkg/authconfig" registrytypes "github.com/moby/moby/api/types/registry" "github.com/morikuni/aec" ) @@ -58,19 +59,19 @@ func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serve if !isDefaultRegistry { serverAddress = credentials.ConvertToHostname(serverAddress) } - authconfig := configtypes.AuthConfig{} + authCfg := configtypes.AuthConfig{} var err error if checkCredStore { - authconfig, err = cfg.GetAuthConfig(serverAddress) + authCfg, err = cfg.GetAuthConfig(serverAddress) if err != nil { return registrytypes.AuthConfig{ ServerAddress: serverAddress, }, err } } - authconfig.ServerAddress = serverAddress - authconfig.IdentityToken = "" - return registrytypes.AuthConfig(authconfig), nil + authCfg.ServerAddress = serverAddress + authCfg.IdentityToken = "" + return registrytypes.AuthConfig(authCfg), nil } // PromptUserForCredentials handles the CLI prompt for the user to input @@ -185,7 +186,7 @@ func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (strin return "", err } - encodedAuth, err := registrytypes.EncodeAuthConfig(registrytypes.AuthConfig(authConfig)) + encodedAuth, err := authconfig.Encode(registrytypes.AuthConfig(authConfig)) if err != nil { return "", err } diff --git a/cli/command/registry/search.go b/cli/command/registry/search.go index ff42de5ca46c..fe3cfc05782d 100644 --- a/cli/command/registry/search.go +++ b/cli/command/registry/search.go @@ -10,7 +10,9 @@ import ( "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/internal/commands" "github.com/docker/cli/opts" + "github.com/moby/moby/api/pkg/authconfig" registrytypes "github.com/moby/moby/api/types/registry" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -62,7 +64,7 @@ func runSearch(ctx context.Context, dockerCli command.Cli, options searchOptions return err } - results, err := dockerCli.Client().ImageSearch(ctx, options.term, registrytypes.SearchOptions{ + results, err := dockerCli.Client().ImageSearch(ctx, options.term, client.ImageSearchOptions{ RegistryAuth: encodedAuth, PrivilegeFunc: nil, Filters: options.filter.Value(), @@ -100,7 +102,7 @@ func getAuth(dockerCLI command.Cli, reposName string) (encodedAuth string, err e // "no credentials found"). We'll get an error when search failed, // so fine to ignore in most situations. authConfig, _ := dockerCLI.ConfigFile().GetAuthConfig(authCfgKey) - return registrytypes.EncodeAuthConfig(registrytypes.AuthConfig(authConfig)) + return authconfig.Encode(registrytypes.AuthConfig(authConfig)) } // splitReposSearchTerm breaks a search term into an index name and remote name diff --git a/cli/command/registry_test.go b/cli/command/registry_test.go index 6e4dfbbec88e..5de2f76fd74a 100644 --- a/cli/command/registry_test.go +++ b/cli/command/registry_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/config/configfile" configtypes "github.com/docker/cli/cli/config/types" + "github.com/moby/moby/api/pkg/authconfig" "github.com/moby/moby/api/types/registry" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -58,14 +59,14 @@ func TestGetDefaultAuthConfig(t *testing.T) { }, } cfg := configfile.New("filename") - for _, authconfig := range testAuthConfigs { - assert.Check(t, cfg.GetCredentialsStore(authconfig.ServerAddress).Store(configtypes.AuthConfig(authconfig))) + for _, authCfg := range testAuthConfigs { + assert.Check(t, cfg.GetCredentialsStore(authCfg.ServerAddress).Store(configtypes.AuthConfig(authCfg))) } for _, tc := range testCases { serverAddress := tc.inputServerAddress - authconfig, err := command.GetDefaultAuthConfig(cfg, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/") + authCfg, err := command.GetDefaultAuthConfig(cfg, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/") assert.NilError(t, err) - assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, authconfig)) + assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, authCfg)) } } @@ -78,8 +79,8 @@ func TestGetDefaultAuthConfig_HelperError(t *testing.T) { ServerAddress: serverAddress, } const isDefaultRegistry = false // registry is not "https://index.docker.io/v1/" - authconfig, err := command.GetDefaultAuthConfig(cfg, true, serverAddress, isDefaultRegistry) - assert.Check(t, is.DeepEqual(expectedAuthConfig, authconfig)) + authCfg, err := command.GetDefaultAuthConfig(cfg, true, serverAddress, isDefaultRegistry) + assert.Check(t, is.DeepEqual(expectedAuthConfig, authCfg)) assert.Check(t, is.ErrorContains(err, "docker-credential-fake-does-not-exist")) } @@ -185,7 +186,7 @@ func TestRetrieveAuthTokenFromImage(t *testing.T) { imageRef := path.Join(tc.prefix, remoteRef) actual, err := command.RetrieveAuthTokenFromImage(&cfg, imageRef) assert.NilError(t, err) - expectedAuthCfg, err := registry.EncodeAuthConfig(tc.expectedAuthCfg) + expectedAuthCfg, err := authconfig.Encode(tc.expectedAuthCfg) assert.NilError(t, err) assert.Equal(t, actual, expectedAuthCfg) } diff --git a/cli/command/service/client_test.go b/cli/command/service/client_test.go index e15cb3489654..6c02b2075056 100644 --- a/cli/command/service/client_test.go +++ b/cli/command/service/client_test.go @@ -12,30 +12,30 @@ import ( type fakeClient struct { client.Client - serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) - serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) - serviceListFunc func(context.Context, swarm.ServiceListOptions) ([]swarm.Service, error) - taskListFunc func(context.Context, swarm.TaskListOptions) ([]swarm.Task, error) + serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) + serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) + serviceListFunc func(context.Context, client.ServiceListOptions) ([]swarm.Service, error) + taskListFunc func(context.Context, client.TaskListOptions) ([]swarm.Task, error) infoFunc func(ctx context.Context) (system.Info, error) - networkInspectFunc func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) - nodeListFunc func(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) + networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, error) + nodeListFunc func(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error) } -func (f *fakeClient) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (f *fakeClient) NodeList(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error) { if f.nodeListFunc != nil { return f.nodeListFunc(ctx, options) } return nil, nil } -func (f *fakeClient) TaskList(ctx context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { +func (f *fakeClient) TaskList(ctx context.Context, options client.TaskListOptions) ([]swarm.Task, error) { if f.taskListFunc != nil { return f.taskListFunc(ctx, options) } return nil, nil } -func (f *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (f *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) { if f.serviceInspectWithRawFunc != nil { return f.serviceInspectWithRawFunc(ctx, serviceID, options) } @@ -43,7 +43,7 @@ func (f *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string return *builders.Service(builders.ServiceID(serviceID)), []byte{}, nil } -func (f *fakeClient) ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { +func (f *fakeClient) ServiceList(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { if f.serviceListFunc != nil { return f.serviceListFunc(ctx, options) } @@ -51,7 +51,7 @@ func (f *fakeClient) ServiceList(ctx context.Context, options swarm.ServiceListO return nil, nil } -func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { +func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { if f.serviceUpdateFunc != nil { return f.serviceUpdateFunc(ctx, serviceID, version, service, options) } @@ -66,7 +66,7 @@ func (f *fakeClient) Info(ctx context.Context) (system.Info, error) { return f.infoFunc(ctx) } -func (f *fakeClient) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) { +func (f *fakeClient) NetworkInspect(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, error) { if f.networkInspectFunc != nil { return f.networkInspectFunc(ctx, networkID, options) } diff --git a/cli/command/service/completion.go b/cli/command/service/completion.go index a13f5a8da36c..363419bb4c7d 100644 --- a/cli/command/service/completion.go +++ b/cli/command/service/completion.go @@ -4,7 +4,7 @@ import ( "os" "github.com/docker/cli/cli/command/completion" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func completeServiceNames(dockerCLI completion.APIClientProvider) cobra.Completi // https://github.com/docker/cli/blob/f9ced58158d5e0b358052432244b483774a1983d/contrib/completion/bash/docker#L41-L43 showIDs := os.Getenv("DOCKER_COMPLETION_SHOW_SERVICE_IDS") == "yes" return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - list, err := dockerCLI.Client().ServiceList(cmd.Context(), swarm.ServiceListOptions{}) + list, err := dockerCLI.Client().ServiceList(cmd.Context(), client.ServiceListOptions{}) if err != nil { return nil, cobra.ShellCompDirectiveError } diff --git a/cli/command/service/create.go b/cli/command/service/create.go index f1871a1d8d68..3f54193d5e3a 100644 --- a/cli/command/service/create.go +++ b/cli/command/service/create.go @@ -101,7 +101,7 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command { func runCreate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *serviceOptions) error { apiClient := dockerCLI.Client() - createOpts := swarm.ServiceCreateOptions{} + createOpts := client.ServiceCreateOptions{} service, err := opts.ToService(ctx, apiClient, flags) if err != nil { diff --git a/cli/command/service/create_test.go b/cli/command/service/create_test.go index bf13a7f0f860..ad26af9a2a92 100644 --- a/cli/command/service/create_test.go +++ b/cli/command/service/create_test.go @@ -6,6 +6,7 @@ import ( "github.com/docker/cli/opts/swarmopts" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -13,9 +14,9 @@ import ( // fakeConfigAPIClientList is used to let us pass a closure as a // ConfigAPIClient, to use as ConfigList. for all the other methods in the // interface, it does nothing, not even return an error, so don't use them -type fakeConfigAPIClientList func(context.Context, swarm.ConfigListOptions) ([]swarm.Config, error) +type fakeConfigAPIClientList func(context.Context, client.ConfigListOptions) ([]swarm.Config, error) -func (f fakeConfigAPIClientList) ConfigList(ctx context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) { +func (f fakeConfigAPIClientList) ConfigList(ctx context.Context, opts client.ConfigListOptions) ([]swarm.Config, error) { return f(ctx, opts) } @@ -66,7 +67,7 @@ func TestSetConfigsWithCredSpecAndConfigs(t *testing.T) { } // set up a function to use as the list function - var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) { + var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts client.ConfigListOptions) ([]swarm.Config, error) { f := opts.Filters // we're expecting the filter to have names "foo" and "bar" @@ -146,7 +147,7 @@ func TestSetConfigsOnlyCredSpec(t *testing.T) { } // set up a function to use as the list function - var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) { + var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts client.ConfigListOptions) ([]swarm.Config, error) { f := opts.Filters names := f.Get("name") @@ -197,7 +198,7 @@ func TestSetConfigsOnlyConfigs(t *testing.T) { }, } - var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) { + var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts client.ConfigListOptions) ([]swarm.Config, error) { f := opts.Filters names := f.Get("name") @@ -258,7 +259,7 @@ func TestSetConfigsNoConfigs(t *testing.T) { }, } - var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) { + var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts client.ConfigListOptions) ([]swarm.Config, error) { // assert false -- we should never call this function assert.Assert(t, false, "we should not be listing configs") return nil, nil diff --git a/cli/command/service/inspect.go b/cli/command/service/inspect.go index e3ef15590de7..f144fe9de22d 100644 --- a/cli/command/service/inspect.go +++ b/cli/command/service/inspect.go @@ -13,8 +13,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/formatter" flagsHelper "github.com/docker/cli/cli/flags" - "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -66,7 +65,7 @@ func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) getRef := func(ref string) (any, []byte, error) { // Service inspect shows defaults values in empty fields. - service, _, err := apiClient.ServiceInspectWithRaw(ctx, ref, swarm.ServiceInspectOptions{InsertDefaults: true}) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, ref, client.ServiceInspectOptions{InsertDefaults: true}) if err == nil || !errdefs.IsNotFound(err) { return service, nil, err } @@ -74,7 +73,7 @@ func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) } getNetwork := func(ref string) (any, []byte, error) { - nw, _, err := apiClient.NetworkInspectWithRaw(ctx, ref, network.InspectOptions{Scope: "swarm"}) + nw, _, err := apiClient.NetworkInspectWithRaw(ctx, ref, client.NetworkInspectOptions{Scope: "swarm"}) if err == nil || !errdefs.IsNotFound(err) { return nw, nil, err } diff --git a/cli/command/service/list.go b/cli/command/service/list.go index d961f0ec9f12..479dbb1259a2 100644 --- a/cli/command/service/list.go +++ b/cli/command/service/list.go @@ -56,7 +56,7 @@ func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) er err error ) - listOpts := swarm.ServiceListOptions{ + listOpts := client.ServiceListOptions{ Filters: options.filter.Value(), // When not running "quiet", also get service status (number of running // and desired tasks). Note that this is only supported on API v1.41 and @@ -146,7 +146,7 @@ func AppendServiceStatus(ctx context.Context, c client.APIClient, services []swa return services, nil } - tasks, err := c.TaskList(ctx, swarm.TaskListOptions{Filters: taskFilter}) + tasks, err := c.TaskList(ctx, client.TaskListOptions{Filters: taskFilter}) if err != nil { return nil, err } @@ -183,7 +183,7 @@ func AppendServiceStatus(ctx context.Context, c client.APIClient, services []swa } func getActiveNodes(ctx context.Context, c client.NodeAPIClient) (map[string]struct{}, error) { - nodes, err := c.NodeList(ctx, swarm.NodeListOptions{}) + nodes, err := c.NodeList(ctx, client.NodeListOptions{}) if err != nil { return nil, err } diff --git a/cli/command/service/list_test.go b/cli/command/service/list_test.go index df8024e2abae..479e9a9539d7 100644 --- a/cli/command/service/list_test.go +++ b/cli/command/service/list_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -18,7 +19,7 @@ import ( func TestServiceListOrder(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ newService("a57dbe8", "service-1-foo"), newService("a57dbdd", "service-10-foo"), @@ -172,7 +173,7 @@ func TestServiceListServiceStatus(t *testing.T) { tc.cluster = generateCluster(t, tc.opts) } cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { if !options.Status || versions.LessThan(tc.opts.apiVersion, "1.41") { // Don't return "ServiceStatus" if not requested, or on older API versions for i := range tc.cluster.services { @@ -181,10 +182,10 @@ func TestServiceListServiceStatus(t *testing.T) { } return tc.cluster.services, nil }, - taskListFunc: func(context.Context, swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(context.Context, client.TaskListOptions) ([]swarm.Task, error) { return tc.cluster.tasks, nil }, - nodeListFunc: func(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { + nodeListFunc: func(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error) { return tc.cluster.nodes, nil }, }) diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index 99e7c3697c41..ef9916a15435 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -90,7 +90,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, opts *logsOptions) erro logfunc func(context.Context, string, container.LogsOptions) (io.ReadCloser, error) ) - service, _, err := apiClient.ServiceInspectWithRaw(ctx, opts.target, swarm.ServiceInspectOptions{}) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, opts.target, client.ServiceInspectOptions{}) if err != nil { // if it's any error other than service not found, it's Real if !errdefs.IsNotFound(err) { diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 3e02e775e993..f8560b01826e 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -16,7 +16,6 @@ import ( gogotypes "github.com/gogo/protobuf/types" "github.com/google/shlex" "github.com/moby/moby/api/types/container" - "github.com/moby/moby/api/types/network" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" "github.com/moby/swarmkit/v2/api" @@ -400,8 +399,11 @@ func (c *credentialSpecOpt) Value() *swarm.CredentialSpec { } func resolveNetworkID(ctx context.Context, apiClient client.NetworkAPIClient, networkIDOrName string) (string, error) { - nw, err := apiClient.NetworkInspect(ctx, networkIDOrName, network.InspectOptions{Scope: "swarm"}) - return nw.ID, err + nw, err := apiClient.NetworkInspect(ctx, networkIDOrName, client.NetworkInspectOptions{Scope: "swarm"}) + if err != nil { + return "", err + } + return nw.ID, nil } func convertNetworks(networks opts.NetworkOpt) []swarm.NetworkAttachmentConfig { diff --git a/cli/command/service/opts_test.go b/cli/command/service/opts_test.go index d89c13fe2df4..750641f90ab2 100644 --- a/cli/command/service/opts_test.go +++ b/cli/command/service/opts_test.go @@ -10,6 +10,7 @@ import ( "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/network" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -191,7 +192,7 @@ func TestToServiceNetwork(t *testing.T) { } apiClient := &fakeClient{ - networkInspectFunc: func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) { + networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, error) { for _, nw := range nws { if nw.ID == networkID || nw.Name == networkID { return nw, nil diff --git a/cli/command/service/parse.go b/cli/command/service/parse.go index 22930c5322b0..5ade15e59b10 100644 --- a/cli/command/service/parse.go +++ b/cli/command/service/parse.go @@ -4,25 +4,25 @@ import ( "context" "github.com/moby/moby/api/types/filters" - swarmtypes "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" "github.com/pkg/errors" ) // ParseSecrets retrieves the secrets with the requested names and fills // secret IDs into the secret references. -func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, requestedSecrets []*swarmtypes.SecretReference) ([]*swarmtypes.SecretReference, error) { +func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, requestedSecrets []*swarm.SecretReference) ([]*swarm.SecretReference, error) { if len(requestedSecrets) == 0 { - return []*swarmtypes.SecretReference{}, nil + return []*swarm.SecretReference{}, nil } - secretRefs := make(map[string]*swarmtypes.SecretReference) + secretRefs := make(map[string]*swarm.SecretReference) for _, secret := range requestedSecrets { if _, exists := secretRefs[secret.File.Name]; exists { return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName) } - secretRef := new(swarmtypes.SecretReference) + secretRef := new(swarm.SecretReference) *secretRef = *secret secretRefs[secret.File.Name] = secretRef } @@ -32,7 +32,7 @@ func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, request args.Add("name", s.SecretName) } - secrets, err := apiClient.SecretList(ctx, swarmtypes.SecretListOptions{ + secrets, err := apiClient.SecretList(ctx, swarm.SecretListOptions{ Filters: args, }) if err != nil { @@ -44,7 +44,7 @@ func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, request foundSecrets[secret.Spec.Annotations.Name] = secret.ID } - addedSecrets := []*swarmtypes.SecretReference{} + addedSecrets := []*swarm.SecretReference{} for _, ref := range secretRefs { id, ok := foundSecrets[ref.SecretName] @@ -63,9 +63,9 @@ func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, request // ParseConfigs retrieves the configs from the requested names and converts // them to config references to use with the spec -func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, requestedConfigs []*swarmtypes.ConfigReference) ([]*swarmtypes.ConfigReference, error) { +func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, requestedConfigs []*swarm.ConfigReference) ([]*swarm.ConfigReference, error) { if len(requestedConfigs) == 0 { - return []*swarmtypes.ConfigReference{}, nil + return []*swarm.ConfigReference{}, nil } // the configRefs map has two purposes: it prevents duplication of config @@ -79,12 +79,12 @@ func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, request // are in use for the same Config, and we should deduplicate // such ConfigReferences, as no matter how many times the Config is used, // it is only needed to be referenced once. - configRefs := make(map[string]*swarmtypes.ConfigReference) - runtimeRefs := make(map[string]*swarmtypes.ConfigReference) + configRefs := make(map[string]*swarm.ConfigReference) + runtimeRefs := make(map[string]*swarm.ConfigReference) for _, config := range requestedConfigs { // copy the config, so we don't mutate the args - configRef := new(swarmtypes.ConfigReference) + configRef := new(swarm.ConfigReference) *configRef = *config if config.Runtime != nil { @@ -112,7 +112,7 @@ func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, request args.Add("name", s.ConfigName) } - configs, err := apiClient.ConfigList(ctx, swarmtypes.ConfigListOptions{ + configs, err := apiClient.ConfigList(ctx, client.ConfigListOptions{ Filters: args, }) if err != nil { @@ -124,7 +124,7 @@ func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, request foundConfigs[config.Spec.Annotations.Name] = config.ID } - addedConfigs := []*swarmtypes.ConfigReference{} + addedConfigs := []*swarm.ConfigReference{} for _, ref := range configRefs { id, ok := foundConfigs[ref.ConfigName] diff --git a/cli/command/service/progress/progress.go b/cli/command/service/progress/progress.go index 95e8e94535fe..b39a05e2a875 100644 --- a/cli/command/service/progress/progress.go +++ b/cli/command/service/progress/progress.go @@ -88,7 +88,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID ) for { - service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, swarm.ServiceInspectOptions{}) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, client.ServiceInspectOptions{}) if err != nil { return err } @@ -142,7 +142,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID return nil } - tasks, err := apiClient.TaskList(ctx, swarm.TaskListOptions{Filters: filters.NewArgs( + tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filters.NewArgs( filters.KeyValuePair{Key: "service", Value: service.ID}, filters.KeyValuePair{Key: "_up-to-date", Value: "true"}, )}) @@ -216,7 +216,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID // // TODO(thaJeztah): this should really be a filter on [apiClient.NodeList] instead of being filtered on the client side. func getActiveNodes(ctx context.Context, apiClient client.NodeAPIClient) (map[string]struct{}, error) { - nodes, err := apiClient.NodeList(ctx, swarm.NodeListOptions{}) + nodes, err := apiClient.NodeList(ctx, client.NodeListOptions{}) if err != nil { return nil, err } diff --git a/cli/command/service/ps.go b/cli/command/service/ps.go index 2a25fed36e07..cbde36e06ac2 100644 --- a/cli/command/service/ps.go +++ b/cli/command/service/ps.go @@ -12,7 +12,6 @@ import ( "github.com/docker/cli/cli/command/task" "github.com/docker/cli/opts" "github.com/moby/moby/api/types/filters" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -68,7 +67,7 @@ func runPS(ctx context.Context, dockerCli command.Cli, options psOptions) error return err } - tasks, err := apiClient.TaskList(ctx, swarm.TaskListOptions{Filters: filter}) + tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter}) if err != nil { return err } @@ -98,11 +97,11 @@ func createFilter(ctx context.Context, apiClient client.APIClient, options psOpt serviceIDFilter.Add("id", service) serviceNameFilter.Add("name", service) } - serviceByIDList, err := apiClient.ServiceList(ctx, swarm.ServiceListOptions{Filters: serviceIDFilter}) + serviceByIDList, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceIDFilter}) if err != nil { return filter, nil, err } - serviceByNameList, err := apiClient.ServiceList(ctx, swarm.ServiceListOptions{Filters: serviceNameFilter}) + serviceByNameList, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceNameFilter}) if err != nil { return filter, nil, err } diff --git a/cli/command/service/ps_test.go b/cli/command/service/ps_test.go index 033a1950969f..fc6e3b2a8a8e 100644 --- a/cli/command/service/ps_test.go +++ b/cli/command/service/ps_test.go @@ -10,13 +10,14 @@ import ( "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/system" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) func TestCreateFilter(t *testing.T) { apiClient := &fakeClient{ - serviceListFunc: func(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ {ID: "idmatch"}, {ID: "idprefixmatch"}, @@ -48,7 +49,7 @@ func TestCreateFilter(t *testing.T) { func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) { apiClient := &fakeClient{ - serviceListFunc: func(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ {ID: "aaaone"}, {ID: "aaatwo"}, @@ -75,7 +76,7 @@ func TestCreateFilterNoneFound(t *testing.T) { func TestRunPSWarnsOnNotFound(t *testing.T) { apiClient := &fakeClient{ - serviceListFunc: func(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ {ID: "foo"}, }, nil @@ -96,10 +97,10 @@ func TestRunPSWarnsOnNotFound(t *testing.T) { func TestRunPSQuiet(t *testing.T) { apiClient := &fakeClient{ - serviceListFunc: func(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{{ID: "foo"}}, nil }, - taskListFunc: func(ctx context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(ctx context.Context, options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{{ID: "sxabyp0obqokwekpun4rjo0b3"}}, nil }, } diff --git a/cli/command/service/rollback.go b/cli/command/service/rollback.go index 853fbc9b8871..37d544f5eda7 100644 --- a/cli/command/service/rollback.go +++ b/cli/command/service/rollback.go @@ -7,8 +7,8 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -43,12 +43,12 @@ func newRollbackCommand(dockerCli command.Cli) *cobra.Command { func runRollback(ctx context.Context, dockerCLI command.Cli, options *serviceOptions, serviceID string) error { apiClient := dockerCLI.Client() - service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, swarm.ServiceInspectOptions{}) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, client.ServiceInspectOptions{}) if err != nil { return err } - response, err := apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, swarm.ServiceUpdateOptions{ + response, err := apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, client.ServiceUpdateOptions{ Rollback: "previous", // TODO(thaJeztah): this should have a const defined }) if err != nil { diff --git a/cli/command/service/rollback_test.go b/cli/command/service/rollback_test.go index d8af909cfd0c..9c378a3db384 100644 --- a/cli/command/service/rollback_test.go +++ b/cli/command/service/rollback_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -17,7 +18,7 @@ func TestRollback(t *testing.T) { testCases := []struct { name string args []string - serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) + serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) expectedDockerCliErr string }{ { @@ -27,7 +28,7 @@ func TestRollback(t *testing.T) { { name: "rollback-service-with-warnings", args: []string{"service-id"}, - serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { + serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { response := swarm.ServiceUpdateResponse{} response.Warnings = []string{ @@ -58,8 +59,8 @@ func TestRollbackWithErrors(t *testing.T) { testCases := []struct { name string args []string - serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) - serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) + serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) + serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, opts client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) expectedError string }{ { @@ -74,7 +75,7 @@ func TestRollbackWithErrors(t *testing.T) { { name: "service-does-not-exists", args: []string{"service-id"}, - serviceInspectWithRawFunc: func(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { + serviceInspectWithRawFunc: func(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) { return swarm.Service{}, []byte{}, fmt.Errorf("no such services: %s", serviceID) }, expectedError: "no such services: service-id", @@ -82,7 +83,7 @@ func TestRollbackWithErrors(t *testing.T) { { name: "service-update-failed", args: []string{"service-id"}, - serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { + serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, opts client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { return swarm.ServiceUpdateResponse{}, fmt.Errorf("no such services: %s", serviceID) }, expectedError: "no such services: service-id", diff --git a/cli/command/service/scale.go b/cli/command/service/scale.go index 35ed73d0a993..9c1653e52344 100644 --- a/cli/command/service/scale.go +++ b/cli/command/service/scale.go @@ -9,7 +9,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" "github.com/spf13/cobra" @@ -94,7 +93,7 @@ func runScale(ctx context.Context, dockerCLI command.Cli, options *scaleOptions, } func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64) (warnings []string, _ error) { - service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, swarm.ServiceInspectOptions{}) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, client.ServiceInspectOptions{}) if err != nil { return nil, err } @@ -109,7 +108,7 @@ func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, ser return nil, errors.New("scale can only be used with replicated or replicated-job mode") } - response, err := apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, swarm.ServiceUpdateOptions{}) + response, err := apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, client.ServiceUpdateOptions{}) if err != nil { return nil, err } diff --git a/cli/command/service/update.go b/cli/command/service/update.go index 54c386d01972..c084204c0079 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -14,7 +14,6 @@ import ( "github.com/docker/cli/opts/swarmopts" "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/mount" - "github.com/moby/moby/api/types/network" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" @@ -155,7 +154,7 @@ func newListOptsVarWithValidator(validator opts.ValidatorFctType) *opts.ListOpts func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, options *serviceOptions, serviceID string) error { apiClient := dockerCLI.Client() - service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, swarm.ServiceInspectOptions{}) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, client.ServiceInspectOptions{}) if err != nil { return err } @@ -200,7 +199,7 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, } } - updateOpts := swarm.ServiceUpdateOptions{} + updateOpts := client.ServiceUpdateOptions{} if serverSideRollback { updateOpts.Rollback = "previous" } @@ -1328,7 +1327,7 @@ func updateNetworks(ctx context.Context, apiClient client.NetworkAPIClient, flag toRemove := buildToRemoveSet(flags, flagNetworkRemove) idsToRemove := make(map[string]struct{}) for networkIDOrName := range toRemove { - nw, err := apiClient.NetworkInspect(ctx, networkIDOrName, network.InspectOptions{Scope: "swarm"}) + nw, err := apiClient.NetworkInspect(ctx, networkIDOrName, client.NetworkInspectOptions{Scope: "swarm"}) if err != nil { return err } diff --git a/cli/command/service/update_test.go b/cli/command/service/update_test.go index 1cc9ab0e8227..41924de18857 100644 --- a/cli/command/service/update_test.go +++ b/cli/command/service/update_test.go @@ -12,6 +12,7 @@ import ( "github.com/moby/moby/api/types/mount" "github.com/moby/moby/api/types/network" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -852,7 +853,7 @@ func TestUpdateNetworks(t *testing.T) { } apiClient := &fakeClient{ - networkInspectFunc: func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) { + networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, error) { for _, nw := range nws { if nw.ID == networkID || nw.Name == networkID { return nw, nil @@ -1202,7 +1203,7 @@ func TestUpdateGetUpdatedConfigs(t *testing.T) { // fakeConfigAPIClientList is actually defined in create_test.go, // but we'll use it here as well - var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts swarm.ConfigListOptions) ([]swarm.Config, error) { + var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts client.ConfigListOptions) ([]swarm.Config, error) { names := opts.Filters.Get("name") assert.Equal(t, len(names), len(tc.lookupConfigs)) diff --git a/cli/command/stack/client_test.go b/cli/command/stack/client_test.go index 570ae1178259..c2b3cbf02d6e 100644 --- a/cli/command/stack/client_test.go +++ b/cli/command/stack/client_test.go @@ -27,15 +27,15 @@ type fakeClient struct { removedSecrets []string removedConfigs []string - serviceListFunc func(options swarm.ServiceListOptions) ([]swarm.Service, error) - networkListFunc func(options network.ListOptions) ([]network.Summary, error) + serviceListFunc func(options client.ServiceListOptions) ([]swarm.Service, error) + networkListFunc func(options client.NetworkListOptions) ([]network.Summary, error) secretListFunc func(options swarm.SecretListOptions) ([]swarm.Secret, error) - configListFunc func(options swarm.ConfigListOptions) ([]swarm.Config, error) - nodeListFunc func(options swarm.NodeListOptions) ([]swarm.Node, error) - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) + configListFunc func(options client.ConfigListOptions) ([]swarm.Config, error) + nodeListFunc func(options client.NodeListOptions) ([]swarm.Node, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) nodeInspectWithRaw func(ref string) (swarm.Node, []byte, error) - serviceUpdateFunc func(serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) + serviceUpdateFunc func(serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) serviceRemoveFunc func(serviceID string) error networkRemoveFunc func(networkID string) error @@ -54,7 +54,7 @@ func (cli *fakeClient) ClientVersion() string { return cli.version } -func (cli *fakeClient) ServiceList(_ context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { +func (cli *fakeClient) ServiceList(_ context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { if cli.serviceListFunc != nil { return cli.serviceListFunc(options) } @@ -69,7 +69,7 @@ func (cli *fakeClient) ServiceList(_ context.Context, options swarm.ServiceListO return servicesList, nil } -func (cli *fakeClient) NetworkList(_ context.Context, options network.ListOptions) ([]network.Summary, error) { +func (cli *fakeClient) NetworkList(_ context.Context, options client.NetworkListOptions) ([]network.Summary, error) { if cli.networkListFunc != nil { return cli.networkListFunc(options) } @@ -99,7 +99,7 @@ func (cli *fakeClient) SecretList(_ context.Context, options swarm.SecretListOpt return secretsList, nil } -func (cli *fakeClient) ConfigList(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { +func (cli *fakeClient) ConfigList(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { if cli.configListFunc != nil { return cli.configListFunc(options) } @@ -114,14 +114,14 @@ func (cli *fakeClient) ConfigList(_ context.Context, options swarm.ConfigListOpt return configsList, nil } -func (cli *fakeClient) TaskList(_ context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { +func (cli *fakeClient) TaskList(_ context.Context, options client.TaskListOptions) ([]swarm.Task, error) { if cli.taskListFunc != nil { return cli.taskListFunc(options) } return []swarm.Task{}, nil } -func (cli *fakeClient) NodeList(_ context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *fakeClient) NodeList(_ context.Context, options client.NodeListOptions) ([]swarm.Node, error) { if cli.nodeListFunc != nil { return cli.nodeListFunc(options) } @@ -135,7 +135,7 @@ func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm. return swarm.Node{}, nil, nil } -func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { +func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { if cli.serviceUpdateFunc != nil { return cli.serviceUpdateFunc(serviceID, version, service, options) } @@ -179,7 +179,7 @@ func (cli *fakeClient) ConfigRemove(_ context.Context, configID string) error { return nil } -func (*fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (*fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ client.ServiceInspectOptions) (swarm.Service, []byte, error) { return swarm.Service{ ID: serviceID, Spec: swarm.ServiceSpec{ diff --git a/cli/command/stack/list_test.go b/cli/command/stack/list_test.go index a47ccdf7eb19..63401f2dfbd1 100644 --- a/cli/command/stack/list_test.go +++ b/cli/command/stack/list_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -16,7 +17,7 @@ func TestListErrors(t *testing.T) { testCases := []struct { args []string flags map[string]string - serviceListFunc func(options swarm.ServiceListOptions) ([]swarm.Service, error) + serviceListFunc func(options client.ServiceListOptions) ([]swarm.Service, error) expectedError string }{ { @@ -32,14 +33,14 @@ func TestListErrors(t *testing.T) { }, { args: []string{}, - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{}, errors.New("error getting services") }, expectedError: "error getting services", }, { args: []string{}, - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{*builders.Service()}, nil }, expectedError: "cannot get label", @@ -114,7 +115,7 @@ func TestStackList(t *testing.T) { ) } cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return services, nil }, }) diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index e3dfd044dfb3..283bd23855f4 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -18,7 +19,7 @@ import ( func TestStackPsErrors(t *testing.T) { testCases := []struct { args []string - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) expectedError string }{ { @@ -31,7 +32,7 @@ func TestStackPsErrors(t *testing.T) { }, { args: []string{"foo"}, - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return nil, errors.New("error getting tasks") }, expectedError: "error getting tasks", @@ -54,7 +55,7 @@ func TestStackPsErrors(t *testing.T) { func TestStackPs(t *testing.T) { testCases := []struct { doc string - taskListFunc func(swarm.TaskListOptions) ([]swarm.Task, error) + taskListFunc func(client.TaskListOptions) ([]swarm.Task, error) nodeInspectWithRaw func(string) (swarm.Node, []byte, error) config configfile.ConfigFile args []string @@ -69,7 +70,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithEmptyStack", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{}, nil }, args: []string{"foo"}, @@ -77,7 +78,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithQuietOption", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task(builders.TaskID("id-foo"))}, nil }, args: []string{"foo"}, @@ -88,7 +89,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithNoTruncOption", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task(builders.TaskID("xn4cypcov06f2w8gsbaf2lst3"))}, nil }, args: []string{"foo"}, @@ -100,7 +101,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithNoResolveOption", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task( builders.TaskNodeID("id-node-foo"), )}, nil @@ -117,7 +118,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithFormat", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task(builders.TaskServiceID("service-id-foo"))}, nil }, args: []string{"foo"}, @@ -128,7 +129,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithConfigFormat", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task(builders.TaskServiceID("service-id-foo"))}, nil }, config: configfile.ConfigFile{ @@ -139,7 +140,7 @@ func TestStackPs(t *testing.T) { }, { doc: "WithoutFormat", - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task( builders.TaskID("id-foo"), builders.TaskServiceID("service-id-foo"), diff --git a/cli/command/stack/services_test.go b/cli/command/stack/services_test.go index 237c601261ff..51d2b8d38e20 100644 --- a/cli/command/stack/services_test.go +++ b/cli/command/stack/services_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -18,37 +19,37 @@ func TestStackServicesErrors(t *testing.T) { testCases := []struct { args []string flags map[string]string - serviceListFunc func(options swarm.ServiceListOptions) ([]swarm.Service, error) - nodeListFunc func(options swarm.NodeListOptions) ([]swarm.Node, error) - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) + serviceListFunc func(options client.ServiceListOptions) ([]swarm.Service, error) + nodeListFunc func(options client.NodeListOptions) ([]swarm.Node, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) expectedError string }{ { args: []string{"foo"}, - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return nil, errors.New("error getting services") }, expectedError: "error getting services", }, { args: []string{"foo"}, - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{*builders.Service(builders.GlobalService())}, nil }, - nodeListFunc: func(options swarm.NodeListOptions) ([]swarm.Node, error) { + nodeListFunc: func(options client.NodeListOptions) ([]swarm.Node, error) { return nil, errors.New("error getting nodes") }, - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task()}, nil }, expectedError: "error getting nodes", }, { args: []string{"foo"}, - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{*builders.Service(builders.GlobalService())}, nil }, - taskListFunc: func(options swarm.TaskListOptions) ([]swarm.Task, error) { + taskListFunc: func(options client.TaskListOptions) ([]swarm.Task, error) { return nil, errors.New("error getting tasks") }, expectedError: "error getting tasks", @@ -58,7 +59,7 @@ func TestStackServicesErrors(t *testing.T) { flags: map[string]string{ "format": "{{invalid format}}", }, - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{*builders.Service()}, nil }, expectedError: "template parsing error", @@ -95,7 +96,7 @@ func TestRunServicesWithEmptyName(t *testing.T) { func TestStackServicesEmptyServiceList(t *testing.T) { fakeCli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{}, nil }, }) @@ -108,7 +109,7 @@ func TestStackServicesEmptyServiceList(t *testing.T) { func TestStackServicesWithQuietOption(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{*builders.Service(builders.ServiceID("id-foo"))}, nil }, }) @@ -121,7 +122,7 @@ func TestStackServicesWithQuietOption(t *testing.T) { func TestStackServicesWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ *builders.Service(builders.ServiceName("service-name-foo")), }, nil @@ -136,7 +137,7 @@ func TestStackServicesWithFormat(t *testing.T) { func TestStackServicesWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ *builders.Service(builders.ServiceName("service-name-foo")), }, nil @@ -153,7 +154,7 @@ func TestStackServicesWithConfigFormat(t *testing.T) { func TestStackServicesWithoutFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{*builders.Service( builders.ServiceName("name-foo"), builders.ServiceID("id-foo"), diff --git a/cli/command/stack/swarm/client_test.go b/cli/command/stack/swarm/client_test.go index 5f8842283c3a..65e37b0c7a45 100644 --- a/cli/command/stack/swarm/client_test.go +++ b/cli/command/stack/swarm/client_test.go @@ -27,15 +27,15 @@ type fakeClient struct { removedSecrets []string removedConfigs []string - serviceListFunc func(options swarm.ServiceListOptions) ([]swarm.Service, error) - networkListFunc func(options network.ListOptions) ([]network.Summary, error) + serviceListFunc func(options client.ServiceListOptions) ([]swarm.Service, error) + networkListFunc func(options client.NetworkListOptions) ([]network.Summary, error) secretListFunc func(options swarm.SecretListOptions) ([]swarm.Secret, error) - configListFunc func(options swarm.ConfigListOptions) ([]swarm.Config, error) - nodeListFunc func(options swarm.NodeListOptions) ([]swarm.Node, error) - taskListFunc func(options swarm.TaskListOptions) ([]swarm.Task, error) + configListFunc func(options client.ConfigListOptions) ([]swarm.Config, error) + nodeListFunc func(options client.NodeListOptions) ([]swarm.Node, error) + taskListFunc func(options client.TaskListOptions) ([]swarm.Task, error) nodeInspectWithRaw func(ref string) (swarm.Node, []byte, error) - serviceUpdateFunc func(serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) + serviceUpdateFunc func(serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) serviceRemoveFunc func(serviceID string) error networkRemoveFunc func(networkID string) error @@ -54,7 +54,7 @@ func (cli *fakeClient) ClientVersion() string { return cli.version } -func (cli *fakeClient) ServiceList(_ context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { +func (cli *fakeClient) ServiceList(_ context.Context, options client.ServiceListOptions) ([]swarm.Service, error) { if cli.serviceListFunc != nil { return cli.serviceListFunc(options) } @@ -69,7 +69,7 @@ func (cli *fakeClient) ServiceList(_ context.Context, options swarm.ServiceListO return servicesList, nil } -func (cli *fakeClient) NetworkList(_ context.Context, options network.ListOptions) ([]network.Summary, error) { +func (cli *fakeClient) NetworkList(_ context.Context, options client.NetworkListOptions) ([]network.Summary, error) { if cli.networkListFunc != nil { return cli.networkListFunc(options) } @@ -99,7 +99,7 @@ func (cli *fakeClient) SecretList(_ context.Context, options swarm.SecretListOpt return secretsList, nil } -func (cli *fakeClient) ConfigList(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { +func (cli *fakeClient) ConfigList(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { if cli.configListFunc != nil { return cli.configListFunc(options) } @@ -114,14 +114,14 @@ func (cli *fakeClient) ConfigList(_ context.Context, options swarm.ConfigListOpt return configsList, nil } -func (cli *fakeClient) TaskList(_ context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { +func (cli *fakeClient) TaskList(_ context.Context, options client.TaskListOptions) ([]swarm.Task, error) { if cli.taskListFunc != nil { return cli.taskListFunc(options) } return []swarm.Task{}, nil } -func (cli *fakeClient) NodeList(_ context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *fakeClient) NodeList(_ context.Context, options client.NodeListOptions) ([]swarm.Node, error) { if cli.nodeListFunc != nil { return cli.nodeListFunc(options) } @@ -135,7 +135,7 @@ func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm. return swarm.Node{}, nil, nil } -func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { +func (cli *fakeClient) ServiceUpdate(_ context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { if cli.serviceUpdateFunc != nil { return cli.serviceUpdateFunc(serviceID, version, service, options) } diff --git a/cli/command/stack/swarm/common.go b/cli/command/stack/swarm/common.go index d25b0d2169ff..b5bd9568ef7b 100644 --- a/cli/command/stack/swarm/common.go +++ b/cli/command/stack/swarm/common.go @@ -30,11 +30,11 @@ func getAllStacksFilter() filters.Args { } func getStackServices(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Service, error) { - return apiclient.ServiceList(ctx, swarm.ServiceListOptions{Filters: getStackFilter(namespace)}) + return apiclient.ServiceList(ctx, client.ServiceListOptions{Filters: getStackFilter(namespace)}) } func getStackNetworks(ctx context.Context, apiclient client.APIClient, namespace string) ([]network.Summary, error) { - return apiclient.NetworkList(ctx, network.ListOptions{Filters: getStackFilter(namespace)}) + return apiclient.NetworkList(ctx, client.NetworkListOptions{Filters: getStackFilter(namespace)}) } func getStackSecrets(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Secret, error) { @@ -42,9 +42,9 @@ func getStackSecrets(ctx context.Context, apiclient client.APIClient, namespace } func getStackConfigs(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Config, error) { - return apiclient.ConfigList(ctx, swarm.ConfigListOptions{Filters: getStackFilter(namespace)}) + return apiclient.ConfigList(ctx, client.ConfigListOptions{Filters: getStackFilter(namespace)}) } func getStackTasks(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Task, error) { - return apiclient.TaskList(ctx, swarm.TaskListOptions{Filters: getStackFilter(namespace)}) + return apiclient.TaskList(ctx, client.TaskListOptions{Filters: getStackFilter(namespace)}) } diff --git a/cli/command/stack/swarm/deploy_composefile.go b/cli/command/stack/swarm/deploy_composefile.go index 7632eddd5264..ab02f5a8ef80 100644 --- a/cli/command/stack/swarm/deploy_composefile.go +++ b/cli/command/stack/swarm/deploy_composefile.go @@ -95,7 +95,7 @@ func validateExternalNetworks(ctx context.Context, apiClient client.NetworkAPICl // local-scoped networks, so there's no need to inspect them. continue } - nw, err := apiClient.NetworkInspect(ctx, networkName, network.InspectOptions{}) + nw, err := apiClient.NetworkInspect(ctx, networkName, client.NetworkInspectOptions{}) switch { case errdefs.IsNotFound(err): return fmt.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed", networkName) @@ -220,7 +220,7 @@ func deployServices(ctx context.Context, dockerCLI command.Cli, services map[str if service, exists := existingServiceMap[name]; exists { _, _ = fmt.Fprintf(out, "Updating service %s (id: %s)\n", name, service.ID) - updateOpts := swarm.ServiceUpdateOptions{EncodedRegistryAuth: encodedAuth} + updateOpts := client.ServiceUpdateOptions{EncodedRegistryAuth: encodedAuth} switch resolveImage { case ResolveImageAlways: @@ -265,7 +265,7 @@ func deployServices(ctx context.Context, dockerCLI command.Cli, services map[str } else { _, _ = fmt.Fprintln(out, "Creating service", name) - createOpts := swarm.ServiceCreateOptions{EncodedRegistryAuth: encodedAuth} + createOpts := client.ServiceCreateOptions{EncodedRegistryAuth: encodedAuth} // query registry if flag disabling it was not set if resolveImage == ResolveImageAlways || resolveImage == ResolveImageChanged { diff --git a/cli/command/stack/swarm/deploy_composefile_test.go b/cli/command/stack/swarm/deploy_composefile_test.go index a9299eca539c..18ab6253782f 100644 --- a/cli/command/stack/swarm/deploy_composefile_test.go +++ b/cli/command/stack/swarm/deploy_composefile_test.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/internal/test/network" networktypes "github.com/moby/moby/api/types/network" + "github.com/moby/moby/client" "gotest.tools/v3/assert" ) @@ -49,13 +50,13 @@ func TestValidateExternalNetworks(t *testing.T) { } for _, testcase := range testcases { - client := &network.FakeClient{ - NetworkInspectFunc: func(_ context.Context, _ string, _ networktypes.InspectOptions) (networktypes.Inspect, error) { + fakeAPIClient := &network.FakeClient{ + NetworkInspectFunc: func(_ context.Context, _ string, _ client.NetworkInspectOptions) (networktypes.Inspect, error) { return testcase.inspectResponse, testcase.inspectError }, } networks := []string{testcase.network} - err := validateExternalNetworks(context.Background(), client, networks) + err := validateExternalNetworks(context.Background(), fakeAPIClient, networks) if testcase.expectedMsg == "" { assert.NilError(t, err) } else { diff --git a/cli/command/stack/swarm/deploy_test.go b/cli/command/stack/swarm/deploy_test.go index 14342b07e600..2ac4f5da3dfe 100644 --- a/cli/command/stack/swarm/deploy_test.go +++ b/cli/command/stack/swarm/deploy_test.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli/compose/convert" "github.com/docker/cli/internal/test" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -32,12 +33,12 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) { namespace := convert.NewNamespace("mystack") var ( - receivedOptions swarm.ServiceUpdateOptions + receivedOptions client.ServiceUpdateOptions receivedService swarm.ServiceSpec ) - client := test.NewFakeCli(&fakeClient{ - serviceListFunc: func(options swarm.ServiceListOptions) ([]swarm.Service, error) { + fakeCli := test.NewFakeCli(&fakeClient{ + serviceListFunc: func(options client.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ { Spec: swarm.ServiceSpec{ @@ -55,7 +56,7 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) { }, }, nil }, - serviceUpdateFunc: func(serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { + serviceUpdateFunc: func(serviceID string, version swarm.Version, service swarm.ServiceSpec, options client.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { receivedOptions = options receivedService = service return swarm.ServiceUpdateResponse{}, nil @@ -97,14 +98,14 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) { }, }, } - _, err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged) + _, err := deployServices(ctx, fakeCli, spec, namespace, false, ResolveImageChanged) assert.NilError(t, err) assert.Check(t, is.Equal(receivedOptions.QueryRegistry, tc.expectedQueryRegistry)) assert.Check(t, is.Equal(receivedService.TaskTemplate.ContainerSpec.Image, tc.expectedImage)) assert.Check(t, is.Equal(receivedService.TaskTemplate.ForceUpdate, tc.expectedForceUpdate)) receivedService = swarm.ServiceSpec{} - receivedOptions = swarm.ServiceUpdateOptions{} + receivedOptions = client.ServiceUpdateOptions{} }) } } diff --git a/cli/command/stack/swarm/list.go b/cli/command/stack/swarm/list.go index 084e05d7a7eb..947302142545 100644 --- a/cli/command/stack/swarm/list.go +++ b/cli/command/stack/swarm/list.go @@ -5,7 +5,6 @@ import ( "github.com/docker/cli/cli/command/stack/formatter" "github.com/docker/cli/cli/compose/convert" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" "github.com/pkg/errors" ) @@ -14,7 +13,7 @@ import ( func GetStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]*formatter.Stack, error) { services, err := apiClient.ServiceList( ctx, - swarm.ServiceListOptions{Filters: getAllStacksFilter()}) + client.ServiceListOptions{Filters: getAllStacksFilter()}) if err != nil { return nil, err } diff --git a/cli/command/stack/swarm/ps.go b/cli/command/stack/swarm/ps.go index 5bb6ab5866f2..4e2596c77126 100644 --- a/cli/command/stack/swarm/ps.go +++ b/cli/command/stack/swarm/ps.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/command/idresolver" "github.com/docker/cli/cli/command/stack/options" "github.com/docker/cli/cli/command/task" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" ) // RunPS is the swarm implementation of docker stack ps @@ -16,7 +16,7 @@ func RunPS(ctx context.Context, dockerCLI command.Cli, opts options.PS) error { filter := getStackFilterFromOpt(opts.Namespace, opts.Filter) apiClient := dockerCLI.Client() - tasks, err := apiClient.TaskList(ctx, swarm.TaskListOptions{Filters: filter}) + tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter}) if err != nil { return err } diff --git a/cli/command/stack/swarm/services.go b/cli/command/stack/swarm/services.go index dd589afd079c..652b2629bba4 100644 --- a/cli/command/stack/swarm/services.go +++ b/cli/command/stack/swarm/services.go @@ -7,16 +7,17 @@ import ( "github.com/docker/cli/cli/command/service" "github.com/docker/cli/cli/command/stack/options" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" ) // GetServices is the swarm implementation of listing stack services -func GetServices(ctx context.Context, dockerCli command.Cli, opts options.Services) ([]swarm.Service, error) { +func GetServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) ([]swarm.Service, error) { var ( - err error - client = dockerCli.Client() + err error + apiClient = dockerCLI.Client() ) - listOpts := swarm.ServiceListOptions{ + listOpts := client.ServiceListOptions{ Filters: getStackFilterFromOpt(opts.Namespace, opts.Filter), // When not running "quiet", also get service status (number of running // and desired tasks). Note that this is only supported on API v1.41 and @@ -25,7 +26,7 @@ func GetServices(ctx context.Context, dockerCli command.Cli, opts options.Servic Status: !opts.Quiet, } - services, err := client.ServiceList(ctx, listOpts) + services, err := apiClient.ServiceList(ctx, listOpts) if err != nil { return nil, err } @@ -43,7 +44,7 @@ func GetServices(ctx context.Context, dockerCli command.Cli, opts options.Servic // situations where the client uses the "default" version. To account for // these situations, we do a quick check for services that do not have // a ServiceStatus set, and perform a lookup for those. - services, err = service.AppendServiceStatus(ctx, client, services) + services, err = service.AppendServiceStatus(ctx, apiClient, services) if err != nil { return nil, err } diff --git a/cli/command/swarm/ca.go b/cli/command/swarm/ca.go index a2c8898152be..64e8fc36d7e9 100644 --- a/cli/command/swarm/ca.go +++ b/cli/command/swarm/ca.go @@ -12,6 +12,7 @@ import ( "github.com/docker/cli/cli/command/swarm/progress" "github.com/docker/cli/internal/jsonstream" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -83,7 +84,7 @@ func runCA(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opt } updateSwarmSpec(&swarmInspect.Spec, flags, opts) - if err := apiClient.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, swarm.UpdateFlags{}); err != nil { + if err := apiClient.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, client.SwarmUpdateFlags{}); err != nil { return err } diff --git a/cli/command/swarm/ca_test.go b/cli/command/swarm/ca_test.go index 1655d9f7deff..127f60e11fa5 100644 --- a/cli/command/swarm/ca_test.go +++ b/cli/command/swarm/ca_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -167,7 +168,7 @@ type swarmUpdateRecorder struct { spec swarm.Spec } -func (s *swarmUpdateRecorder) swarmUpdate(sp swarm.Spec, _ swarm.UpdateFlags) error { +func (s *swarmUpdateRecorder) swarmUpdate(sp swarm.Spec, _ client.SwarmUpdateFlags) error { s.spec = sp return nil } diff --git a/cli/command/swarm/client_test.go b/cli/command/swarm/client_test.go index 063d302d62c8..4aceef07a0c9 100644 --- a/cli/command/swarm/client_test.go +++ b/cli/command/swarm/client_test.go @@ -17,7 +17,7 @@ type fakeClient struct { swarmGetUnlockKeyFunc func() (swarm.UnlockKeyResponse, error) swarmJoinFunc func() error swarmLeaveFunc func() error - swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error + swarmUpdateFunc func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error swarmUnlockFunc func(req swarm.UnlockRequest) error } @@ -70,7 +70,7 @@ func (cli *fakeClient) SwarmLeave(context.Context, bool) error { return nil } -func (cli *fakeClient) SwarmUpdate(_ context.Context, _ swarm.Version, swarmSpec swarm.Spec, flags swarm.UpdateFlags) error { +func (cli *fakeClient) SwarmUpdate(_ context.Context, _ swarm.Version, swarmSpec swarm.Spec, flags client.SwarmUpdateFlags) error { if cli.swarmUpdateFunc != nil { return cli.swarmUpdateFunc(swarmSpec, flags) } diff --git a/cli/command/swarm/join_token.go b/cli/command/swarm/join_token.go index c62795ec9d8f..51cee2aebcba 100644 --- a/cli/command/swarm/join_token.go +++ b/cli/command/swarm/join_token.go @@ -6,7 +6,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -57,7 +57,7 @@ func runJoinToken(ctx context.Context, dockerCLI command.Cli, opts joinTokenOpti return err } - err = apiClient.SwarmUpdate(ctx, sw.Version, sw.Spec, swarm.UpdateFlags{ + err = apiClient.SwarmUpdate(ctx, sw.Version, sw.Spec, client.SwarmUpdateFlags{ RotateWorkerToken: worker, RotateManagerToken: manager, }) diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index 1c9be083078b..faa00b698f08 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/system" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -21,7 +22,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { flags map[string]string infoFunc func() (system.Info, error) swarmInspectFunc func() (swarm.Swarm, error) - swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error + swarmUpdateFunc func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error nodeInspectFunc func() (swarm.Node, []byte, error) expectedError string }{ @@ -65,7 +66,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { flags: map[string]string{ flagRotate: "true", }, - swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { + swarmUpdateFunc: func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error { return errors.New("error updating the swarm") }, expectedError: "error updating the swarm", diff --git a/cli/command/swarm/progress/root_rotation.go b/cli/command/swarm/progress/root_rotation.go index 9cf164f31ea1..44bf0135fd3b 100644 --- a/cli/command/swarm/progress/root_rotation.go +++ b/cli/command/swarm/progress/root_rotation.go @@ -25,7 +25,7 @@ const ( ) // RootRotationProgress outputs progress information for convergence of a root rotation. -func RootRotationProgress(ctx context.Context, dclient client.APIClient, progressWriter io.WriteCloser) error { +func RootRotationProgress(ctx context.Context, apiClient client.APIClient, progressWriter io.WriteCloser) error { defer progressWriter.Close() progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false) @@ -42,7 +42,7 @@ func RootRotationProgress(ctx context.Context, dclient client.APIClient, progres var done bool for { - info, err := dclient.SwarmInspect(ctx) + info, err := apiClient.SwarmInspect(ctx) if err != nil { return err } @@ -51,7 +51,7 @@ func RootRotationProgress(ctx context.Context, dclient client.APIClient, progres return nil } - nodes, err := dclient.NodeList(ctx, swarm.NodeListOptions{}) + nodes, err := apiClient.NodeList(ctx, client.NodeListOptions{}) if err != nil { return err } diff --git a/cli/command/swarm/unlock_key.go b/cli/command/swarm/unlock_key.go index 0488f94baeba..c60ebe0ad6e7 100644 --- a/cli/command/swarm/unlock_key.go +++ b/cli/command/swarm/unlock_key.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -46,7 +46,7 @@ func runUnlockKey(ctx context.Context, dockerCLI command.Cli, opts unlockKeyOpti apiClient := dockerCLI.Client() if opts.rotate { - flags := swarm.UpdateFlags{RotateManagerUnlockKey: true} + flags := client.SwarmUpdateFlags{RotateManagerUnlockKey: true} sw, err := apiClient.SwarmInspect(ctx) if err != nil { diff --git a/cli/command/swarm/unlock_key_test.go b/cli/command/swarm/unlock_key_test.go index 71668401d2c4..6b846d416e7e 100644 --- a/cli/command/swarm/unlock_key_test.go +++ b/cli/command/swarm/unlock_key_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -19,7 +20,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { args []string flags map[string]string swarmInspectFunc func() (swarm.Swarm, error) - swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error + swarmUpdateFunc func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error swarmGetUnlockKeyFunc func() (swarm.UnlockKeyResponse, error) expectedError string }{ @@ -56,7 +57,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { swarmInspectFunc: func() (swarm.Swarm, error) { return *builders.Swarm(builders.Autolock()), nil }, - swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { + swarmUpdateFunc: func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error { return errors.New("error updating the swarm") }, expectedError: "error updating the swarm", @@ -104,7 +105,7 @@ func TestSwarmUnlockKey(t *testing.T) { name string flags map[string]string swarmInspectFunc func() (swarm.Swarm, error) - swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error + swarmUpdateFunc func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error swarmGetUnlockKeyFunc func() (swarm.UnlockKeyResponse, error) }{ { diff --git a/cli/command/swarm/update.go b/cli/command/swarm/update.go index 53413d4a6f9d..a1ab47209a08 100644 --- a/cli/command/swarm/update.go +++ b/cli/command/swarm/update.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -44,8 +44,6 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command { func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts swarmOptions) error { apiClient := dockerCLI.Client() - var updateFlags swarm.UpdateFlags - swarmInspect, err := apiClient.SwarmInspect(ctx) if err != nil { return err @@ -57,7 +55,7 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, curAutoLock := swarmInspect.Spec.EncryptionConfig.AutoLockManagers - err = apiClient.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, updateFlags) + err = apiClient.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, client.SwarmUpdateFlags{}) if err != nil { return err } diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index 56012373fd46..1f4218ef7a1f 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -20,7 +21,7 @@ func TestSwarmUpdateErrors(t *testing.T) { args []string flags map[string]string swarmInspectFunc func() (swarm.Swarm, error) - swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error + swarmUpdateFunc func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error swarmGetUnlockKeyFunc func() (swarm.UnlockKeyResponse, error) expectedError string }{ @@ -44,7 +45,7 @@ func TestSwarmUpdateErrors(t *testing.T) { flags: map[string]string{ flagTaskHistoryLimit: "10", }, - swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { + swarmUpdateFunc: func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error { return errors.New("error updating the swarm") }, expectedError: "error updating the swarm", @@ -95,7 +96,7 @@ func TestSwarmUpdate(t *testing.T) { args []string flags map[string]string swarmInspectFunc func() (swarm.Swarm, error) - swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error + swarmUpdateFunc func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error swarmGetUnlockKeyFunc func() (swarm.UnlockKeyResponse, error) }{ { @@ -115,7 +116,7 @@ func TestSwarmUpdate(t *testing.T) { swarmInspectFunc: func() (swarm.Swarm, error) { return *swarmInfo, nil }, - swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { + swarmUpdateFunc: func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error { if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 { return errors.New("historyLimit not correctly set") } @@ -154,7 +155,7 @@ func TestSwarmUpdate(t *testing.T) { flagTaskHistoryLimit: "10", flagAutolock: "true", }, - swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { + swarmUpdateFunc: func(swarm swarm.Spec, flags client.SwarmUpdateFlags) error { if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 { return errors.New("historyLimit not correctly set") } diff --git a/cli/command/system/client_test.go b/cli/command/system/client_test.go index 327967ab805e..3a24e6464df9 100644 --- a/cli/command/system/client_test.go +++ b/cli/command/system/client_test.go @@ -21,14 +21,14 @@ type fakeClient struct { version string containerListFunc func(context.Context, container.ListOptions) ([]container.Summary, error) containerPruneFunc func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) - eventsFn func(context.Context, events.ListOptions) (<-chan events.Message, <-chan error) + eventsFn func(context.Context, client.EventsListOptions) (<-chan events.Message, <-chan error) imageListFunc func(ctx context.Context, options image.ListOptions) ([]image.Summary, error) infoFunc func(ctx context.Context) (system.Info, error) - networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) + networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) networkPruneFunc func(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error) - nodeListFunc func(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) + nodeListFunc func(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error) serverVersion func(ctx context.Context) (types.Version, error) - volumeListFunc func(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) + volumeListFunc func(ctx context.Context, options client.VolumeListOptions) (volume.ListResponse, error) } func (cli *fakeClient) ClientVersion() string { @@ -49,7 +49,7 @@ func (cli *fakeClient) ContainersPrune(ctx context.Context, pruneFilters filters return container.PruneReport{}, nil } -func (cli *fakeClient) Events(ctx context.Context, opts events.ListOptions) (<-chan events.Message, <-chan error) { +func (cli *fakeClient) Events(ctx context.Context, opts client.EventsListOptions) (<-chan events.Message, <-chan error) { return cli.eventsFn(ctx, opts) } @@ -67,7 +67,7 @@ func (cli *fakeClient) Info(ctx context.Context) (system.Info, error) { return system.Info{}, nil } -func (cli *fakeClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { +func (cli *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) { if cli.networkListFunc != nil { return cli.networkListFunc(ctx, options) } @@ -81,7 +81,7 @@ func (cli *fakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Ar return network.PruneReport{}, nil } -func (cli *fakeClient) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *fakeClient) NodeList(ctx context.Context, options client.NodeListOptions) ([]swarm.Node, error) { if cli.nodeListFunc != nil { return cli.nodeListFunc(ctx, options) } @@ -92,7 +92,7 @@ func (cli *fakeClient) ServerVersion(ctx context.Context) (types.Version, error) return cli.serverVersion(ctx) } -func (cli *fakeClient) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (cli *fakeClient) VolumeList(ctx context.Context, options client.VolumeListOptions) (volume.ListResponse, error) { if cli.volumeListFunc != nil { return cli.volumeListFunc(ctx, options) } diff --git a/cli/command/system/completion.go b/cli/command/system/completion.go index 4bbafbc9d064..3e0f493be9fd 100644 --- a/cli/command/system/completion.go +++ b/cli/command/system/completion.go @@ -6,9 +6,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/swarm" - "github.com/moby/moby/api/types/volume" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -197,7 +195,7 @@ func imageNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []st // networkNames contacts the API to get a list of network names. // In case of an error, an empty list is returned. func networkNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []string { - list, err := dockerCLI.Client().NetworkList(cmd.Context(), network.ListOptions{}) + list, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{}) if err != nil { return []string{} } @@ -211,7 +209,7 @@ func networkNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) [] // nodeNames contacts the API to get a list of node names. // In case of an error, an empty list is returned. func nodeNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []string { - list, err := dockerCLI.Client().NodeList(cmd.Context(), swarm.NodeListOptions{}) + list, err := dockerCLI.Client().NodeList(cmd.Context(), client.NodeListOptions{}) if err != nil { return []string{} } @@ -225,7 +223,7 @@ func nodeNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []str // volumeNames contacts the API to get a list of volume names. // In case of an error, an empty list is returned. func volumeNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []string { - list, err := dockerCLI.Client().VolumeList(cmd.Context(), volume.ListOptions{}) + list, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{}) if err != nil { return []string{} } diff --git a/cli/command/system/completion_test.go b/cli/command/system/completion_test.go index ecea8a4fa6d4..d7d251d15d47 100644 --- a/cli/command/system/completion_test.go +++ b/cli/command/system/completion_test.go @@ -14,6 +14,7 @@ import ( "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/system" "github.com/moby/moby/api/types/volume" + "github.com/moby/moby/client" "github.com/spf13/cobra" "gotest.tools/v3/assert" ) @@ -89,7 +90,7 @@ func TestCompleteEventFilter(t *testing.T) { }, { client: &fakeClient{ - networkListFunc: func(_ context.Context, _ network.ListOptions) ([]network.Summary, error) { + networkListFunc: func(_ context.Context, _ client.NetworkListOptions) ([]network.Summary, error) { return []network.Summary{ *builders.NetworkResource(builders.NetworkResourceName("nw1")), *builders.NetworkResource(builders.NetworkResourceName("nw2")), @@ -101,7 +102,7 @@ func TestCompleteEventFilter(t *testing.T) { }, { client: &fakeClient{ - networkListFunc: func(_ context.Context, _ network.ListOptions) ([]network.Summary, error) { + networkListFunc: func(_ context.Context, _ client.NetworkListOptions) ([]network.Summary, error) { return nil, errors.New("API error") }, }, @@ -110,7 +111,7 @@ func TestCompleteEventFilter(t *testing.T) { }, { client: &fakeClient{ - nodeListFunc: func(_ context.Context, _ swarm.NodeListOptions) ([]swarm.Node, error) { + nodeListFunc: func(_ context.Context, _ client.NodeListOptions) ([]swarm.Node, error) { return []swarm.Node{ *builders.Node(builders.Hostname("n1")), }, nil @@ -121,7 +122,7 @@ func TestCompleteEventFilter(t *testing.T) { }, { client: &fakeClient{ - nodeListFunc: func(_ context.Context, _ swarm.NodeListOptions) ([]swarm.Node, error) { + nodeListFunc: func(_ context.Context, _ client.NodeListOptions) ([]swarm.Node, error) { return []swarm.Node{}, errors.New("API error") }, }, @@ -130,7 +131,7 @@ func TestCompleteEventFilter(t *testing.T) { }, { client: &fakeClient{ - volumeListFunc: func(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { + volumeListFunc: func(ctx context.Context, options client.VolumeListOptions) (volume.ListResponse, error) { return volume.ListResponse{ Volumes: []*volume.Volume{ builders.Volume(builders.VolumeName("v1")), @@ -144,7 +145,7 @@ func TestCompleteEventFilter(t *testing.T) { }, { client: &fakeClient{ - volumeListFunc: func(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { + volumeListFunc: func(ctx context.Context, options client.VolumeListOptions) (volume.ListResponse, error) { return volume.ListResponse{}, errors.New("API error") }, }, diff --git a/cli/command/system/df.go b/cli/command/system/df.go index f5ae60e445f3..e0e7da959c73 100644 --- a/cli/command/system/df.go +++ b/cli/command/system/df.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/formatter" flagsHelper "github.com/docker/cli/cli/flags" - "github.com/moby/moby/api/types/system" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -42,7 +42,7 @@ func newDiskUsageCommand(dockerCli command.Cli) *cobra.Command { func runDiskUsage(ctx context.Context, dockerCli command.Cli, opts diskUsageOptions) error { // TODO expose types.DiskUsageOptions.Types as flag on the command-line and/or as separate commands (docker container df / docker container usage) - du, err := dockerCli.Client().DiskUsage(ctx, system.DiskUsageOptions{}) + du, err := dockerCli.Client().DiskUsage(ctx, client.DiskUsageOptions{}) if err != nil { return err } diff --git a/cli/command/system/events.go b/cli/command/system/events.go index 9ba72526f84a..ebd0e7f9a3bf 100644 --- a/cli/command/system/events.go +++ b/cli/command/system/events.go @@ -17,6 +17,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/cli/templates" "github.com/moby/moby/api/types/events" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -64,7 +65,7 @@ func runEvents(ctx context.Context, dockerCLI command.Cli, options *eventsOption } } ctx, cancel := context.WithCancel(ctx) - evts, errs := dockerCLI.Client().Events(ctx, events.ListOptions{ + evts, errs := dockerCLI.Client().Events(ctx, client.EventsListOptions{ Since: options.since, Until: options.until, Filters: options.filter.Value(), diff --git a/cli/command/system/events_test.go b/cli/command/system/events_test.go index c2301f88eeb8..daab8069d3e9 100644 --- a/cli/command/system/events_test.go +++ b/cli/command/system/events_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/moby/moby/api/types/events" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -59,7 +60,7 @@ func TestEventsFormat(t *testing.T) { // Set to UTC timezone as timestamps in output are // printed in the current timezone t.Setenv("TZ", "UTC") - cli := test.NewFakeCli(&fakeClient{eventsFn: func(context.Context, events.ListOptions) (<-chan events.Message, <-chan error) { + fakeCLI := test.NewFakeCli(&fakeClient{eventsFn: func(context.Context, client.EventsListOptions) (<-chan events.Message, <-chan error) { messages := make(chan events.Message) errs := make(chan error, 1) go func() { @@ -70,14 +71,14 @@ func TestEventsFormat(t *testing.T) { }() return messages, errs }}) - cmd := newEventsCommand(cli) + cmd := newEventsCommand(fakeCLI) cmd.SetArgs(tc.args) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) assert.Check(t, cmd.Execute()) - out := cli.OutBuffer().String() + out := fakeCLI.OutBuffer().String() assert.Check(t, golden.String(out, fmt.Sprintf("docker-events-%s.golden", strings.ReplaceAll(tc.name, " ", "-")))) - cli.OutBuffer().Reset() + fakeCLI.OutBuffer().Reset() }) } } diff --git a/cli/command/system/inspect.go b/cli/command/system/inspect.go index a99d2d42df7d..64d47b9168cc 100644 --- a/cli/command/system/inspect.go +++ b/cli/command/system/inspect.go @@ -16,8 +16,6 @@ import ( "github.com/docker/cli/cli/command/inspect" flagsHelper "github.com/docker/cli/cli/flags" "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -124,7 +122,7 @@ func inspectImages(ctx context.Context, dockerCli command.Cli) inspect.GetRefFun func inspectNetwork(ctx context.Context, dockerCli command.Cli) inspect.GetRefFunc { return func(ref string) (any, []byte, error) { - return dockerCli.Client().NetworkInspectWithRaw(ctx, ref, network.InspectOptions{}) + return dockerCli.Client().NetworkInspectWithRaw(ctx, ref, client.NetworkInspectOptions{}) } } @@ -137,7 +135,7 @@ func inspectNode(ctx context.Context, dockerCli command.Cli) inspect.GetRefFunc func inspectService(ctx context.Context, dockerCli command.Cli) inspect.GetRefFunc { return func(ref string) (any, []byte, error) { // Service inspect shows defaults values in empty fields. - return dockerCli.Client().ServiceInspectWithRaw(ctx, ref, swarm.ServiceInspectOptions{InsertDefaults: true}) + return dockerCli.Client().ServiceInspectWithRaw(ctx, ref, client.ServiceInspectOptions{InsertDefaults: true}) } } diff --git a/cli/command/task/client_test.go b/cli/command/task/client_test.go index 8402db8f107a..d0020bb58373 100644 --- a/cli/command/task/client_test.go +++ b/cli/command/task/client_test.go @@ -10,7 +10,7 @@ import ( type fakeClient struct { client.APIClient nodeInspectWithRaw func(ref string) (swarm.Node, []byte, error) - serviceInspectWithRaw func(ref string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) + serviceInspectWithRaw func(ref string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) } func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm.Node, []byte, error) { @@ -20,7 +20,7 @@ func (cli *fakeClient) NodeInspectWithRaw(_ context.Context, ref string) (swarm. return swarm.Node{}, nil, nil } -func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, ref string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, ref string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) { if cli.serviceInspectWithRaw != nil { return cli.serviceInspectWithRaw(ref, options) } diff --git a/cli/command/task/print_test.go b/cli/command/task/print_test.go index e4b9967ca564..658860dc8700 100644 --- a/cli/command/task/print_test.go +++ b/cli/command/task/print_test.go @@ -10,13 +10,14 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) func TestTaskPrintSorted(t *testing.T) { apiClient := &fakeClient{ - serviceInspectWithRaw: func(ref string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { + serviceInspectWithRaw: func(ref string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) { if ref == "service-id-one" { return *builders.Service(builders.ServiceName("service-name-1")), nil, nil } @@ -108,7 +109,7 @@ func TestTaskPrintWithIndentation(t *testing.T) { const trunc = false const noResolve = false apiClient := &fakeClient{ - serviceInspectWithRaw: func(ref string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { + serviceInspectWithRaw: func(ref string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) { return *builders.Service(builders.ServiceName("service-name-foo")), nil, nil }, nodeInspectWithRaw: func(ref string) (swarm.Node, []byte, error) { @@ -144,7 +145,7 @@ func TestTaskPrintWithResolution(t *testing.T) { const trunc = false const noResolve = false apiClient := &fakeClient{ - serviceInspectWithRaw: func(ref string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { + serviceInspectWithRaw: func(ref string, options client.ServiceInspectOptions) (swarm.Service, []byte, error) { return *builders.Service(builders.ServiceName("service-name-foo")), nil, nil }, nodeInspectWithRaw: func(ref string) (swarm.Node, []byte, error) { diff --git a/cli/command/trust/sign.go b/cli/command/trust/sign.go index 540ee1e63bb2..c77cb12b0121 100644 --- a/cli/command/trust/sign.go +++ b/cli/command/trust/sign.go @@ -13,8 +13,8 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/trust" + "github.com/moby/moby/api/pkg/authconfig" imagetypes "github.com/moby/moby/api/types/image" - registrytypes "github.com/moby/moby/api/types/registry" "github.com/moby/moby/client" "github.com/spf13/cobra" notaryclient "github.com/theupdateframework/notary/client" @@ -93,7 +93,7 @@ func runSignImage(ctx context.Context, dockerCLI command.Cli, options signOption _, _ = fmt.Fprintf(dockerCLI.Err(), "Signing and pushing trust data for local image %s, may overwrite remote trust data\n", imageName) authConfig := command.ResolveAuthConfig(dockerCLI.ConfigFile(), imgRefAndAuth.RepoInfo().Index) - encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig) + encodedAuth, err := authconfig.Encode(authConfig) if err != nil { return err } diff --git a/cli/command/volume/client_test.go b/cli/command/volume/client_test.go index bd555b7de580..5e611cfd67aa 100644 --- a/cli/command/volume/client_test.go +++ b/cli/command/volume/client_test.go @@ -31,7 +31,7 @@ func (c *fakeClient) VolumeInspect(_ context.Context, volumeID string) (volume.V return volume.Volume{}, nil } -func (c *fakeClient) VolumeList(_ context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (c *fakeClient) VolumeList(_ context.Context, options client.VolumeListOptions) (volume.ListResponse, error) { if c.volumeListFunc != nil { return c.volumeListFunc(options.Filters) } diff --git a/cli/command/volume/list.go b/cli/command/volume/list.go index f689e9a14d8e..3580dad85f1e 100644 --- a/cli/command/volume/list.go +++ b/cli/command/volume/list.go @@ -11,7 +11,7 @@ import ( flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/fvbommel/sortorder" - "github.com/moby/moby/api/types/volume" + "github.com/moby/moby/client" "github.com/spf13/cobra" ) @@ -53,7 +53,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error { apiClient := dockerCLI.Client() - volumes, err := apiClient.VolumeList(ctx, volume.ListOptions{Filters: options.filter.Value()}) + volumes, err := apiClient.VolumeList(ctx, client.VolumeListOptions{Filters: options.filter.Value()}) if err != nil { return err } diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 31afd65e1158..6c03f79beb35 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -571,7 +571,7 @@ func TestConvertServiceConfigs(t *testing.T) { }, } apiClient := &fakeClient{ - configListFunc: func(opts swarm.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(opts client.ConfigListOptions) ([]swarm.Config, error) { assert.Check(t, is.Contains(opts.Filters.Get("name"), "foo_config")) assert.Check(t, is.Contains(opts.Filters.Get("name"), "bar_config")) assert.Check(t, is.Contains(opts.Filters.Get("name"), "baz_config")) @@ -615,7 +615,7 @@ func TestConvertServiceConfigs(t *testing.T) { type fakeClient struct { client.Client secretListFunc func(swarm.SecretListOptions) ([]swarm.Secret, error) - configListFunc func(swarm.ConfigListOptions) ([]swarm.Config, error) + configListFunc func(client.ConfigListOptions) ([]swarm.Config, error) } func (c *fakeClient) SecretList(_ context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) { @@ -625,7 +625,7 @@ func (c *fakeClient) SecretList(_ context.Context, options swarm.SecretListOptio return []swarm.Secret{}, nil } -func (c *fakeClient) ConfigList(_ context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { +func (c *fakeClient) ConfigList(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) { if c.configListFunc != nil { return c.configListFunc(options) } diff --git a/internal/test/builders/container.go b/internal/test/builders/container.go index 7ad4091bca5c..45e98682373f 100644 --- a/internal/test/builders/container.go +++ b/internal/test/builders/container.go @@ -45,12 +45,12 @@ func WithName(name string) func(*container.Summary) { } // WithPort adds a port mapping to the container -func WithPort(privatePort, publicPort uint16, builders ...func(*container.Port)) func(*container.Summary) { +func WithPort(privatePort, publicPort uint16, builders ...func(summary *container.PortSummary)) func(*container.Summary) { return func(c *container.Summary) { if c.Ports == nil { - c.Ports = []container.Port{} + c.Ports = []container.PortSummary{} } - port := &container.Port{ + port := &container.PortSummary{ PrivatePort: privatePort, PublicPort: publicPort, } @@ -71,18 +71,18 @@ func WithSize(size int64) func(*container.Summary) { } // IP sets the ip of the port -func IP(ip string) func(*container.Port) { - return func(p *container.Port) { +func IP(ip string) func(*container.PortSummary) { + return func(p *container.PortSummary) { p.IP = ip } } // TCP sets the port to tcp -func TCP(p *container.Port) { +func TCP(p *container.PortSummary) { p.Type = "tcp" } // UDP sets the port to udp -func UDP(p *container.Port) { +func UDP(p *container.PortSummary) { p.Type = "udp" } diff --git a/internal/test/network/client.go b/internal/test/network/client.go index 83a4dbfeae46..783aeae9f0b5 100644 --- a/internal/test/network/client.go +++ b/internal/test/network/client.go @@ -10,11 +10,11 @@ import ( // FakeClient is a fake NetworkAPIClient type FakeClient struct { client.NetworkAPIClient - NetworkInspectFunc func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) + NetworkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, error) } // NetworkInspect fakes inspecting a network -func (c *FakeClient) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) { +func (c *FakeClient) NetworkInspect(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, error) { if c.NetworkInspectFunc != nil { return c.NetworkInspectFunc(ctx, networkID, options) } diff --git a/vendor.mod b/vendor.mod index 50471ef00e67..9bcc1b273d97 100644 --- a/vendor.mod +++ b/vendor.mod @@ -28,8 +28,8 @@ require ( github.com/google/uuid v1.6.0 github.com/mattn/go-runewidth v0.0.16 github.com/moby/go-archive v0.1.0 - github.com/moby/moby/api v1.52.0-alpha.1 - github.com/moby/moby/client v0.1.0-alpha.0 + github.com/moby/moby/api v1.52.0-alpha.1.0.20250826164402-7145e7666b8f // master + github.com/moby/moby/client v0.1.0-alpha.0.0.20250826164402-7145e7666b8f // master github.com/moby/patternmatcher v0.6.0 github.com/moby/swarmkit/v2 v2.0.0 github.com/moby/sys/atomicwriter v0.1.0 diff --git a/vendor.sum b/vendor.sum index 71dae72c4473..9b204acaf66b 100644 --- a/vendor.sum +++ b/vendor.sum @@ -170,10 +170,10 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ= github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo= -github.com/moby/moby/api v1.52.0-alpha.1 h1:fzxPD0h6l4LmvPd/rySW7T3G45G8eFTo9qEAEp5UZX0= -github.com/moby/moby/api v1.52.0-alpha.1/go.mod h1:MuA35dxT3DVZpImg0ORGCoZtT2dC1jgPjwH9/CQ/afQ= -github.com/moby/moby/client v0.1.0-alpha.0 h1:1Q393KgwO8L3SznKE+xGZJVDdApgcSM0vIhAEff+acc= -github.com/moby/moby/client v0.1.0-alpha.0/go.mod h1:pVMvmGeD4P9tbgBtEHZKW993Qkj4d1Nu6qhiW3GGJ6k= +github.com/moby/moby/api v1.52.0-alpha.1.0.20250826164402-7145e7666b8f h1:faKJR1203hI97HWd0Y4cNBEKLy4nWdkjYpqP4D+j+nk= +github.com/moby/moby/api v1.52.0-alpha.1.0.20250826164402-7145e7666b8f/go.mod h1:8sBV0soUREiudtow4vqJGOxa4GyHI5vLQmvgKdHq5Ok= +github.com/moby/moby/client v0.1.0-alpha.0.0.20250826164402-7145e7666b8f h1:AoyUekdtDsiajk9W2+n0zWR+926oRcuy9AHZSX0whJw= +github.com/moby/moby/client v0.1.0-alpha.0.0.20250826164402-7145e7666b8f/go.mod h1:7pOYrEHdG7I0dNZEC+yqk/p8ZOxGMR1KgoexzCEDe0w= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/swarmkit/v2 v2.0.0 h1:jkWQKQaJ4ltA61/mC9UdPe1McLma55RUcacTO+pPweY= diff --git a/vendor/github.com/moby/moby/api/pkg/authconfig/authconfig.go b/vendor/github.com/moby/moby/api/pkg/authconfig/authconfig.go new file mode 100644 index 000000000000..51f883e1c236 --- /dev/null +++ b/vendor/github.com/moby/moby/api/pkg/authconfig/authconfig.go @@ -0,0 +1,92 @@ +package authconfig + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "errors" + "fmt" + "io" + + "github.com/moby/moby/api/types/registry" +) + +// Encode serializes the auth configuration as a base64url encoded +// ([RFC4648, section 5]) JSON string for sending through the X-Registry-Auth header. +// +// [RFC4648, section 5]: https://tools.ietf.org/html/rfc4648#section-5 +func Encode(authConfig registry.AuthConfig) (string, error) { + // Older daemons (or registries) may not handle an empty string, + // which resulted in an "io.EOF" when unmarshaling or decoding. + // + // FIXME(thaJeztah): find exactly what code-paths are impacted by this. + // if authConfig == (AuthConfig{}) { return "", nil } + buf, err := json.Marshal(authConfig) + if err != nil { + return "", errInvalidParameter{err} + } + return base64.URLEncoding.EncodeToString(buf), nil +} + +// Decode decodes base64url encoded ([RFC4648, section 5]) JSON +// authentication information as sent through the X-Registry-Auth header. +// +// This function always returns an [AuthConfig], even if an error occurs. It is up +// to the caller to decide if authentication is required, and if the error can +// be ignored. +// +// [RFC4648, section 5]: https://tools.ietf.org/html/rfc4648#section-5 +func Decode(authEncoded string) (*registry.AuthConfig, error) { + if authEncoded == "" { + return ®istry.AuthConfig{}, nil + } + + decoded, err := base64.URLEncoding.DecodeString(authEncoded) + if err != nil { + var e base64.CorruptInputError + if errors.As(err, &e) { + return ®istry.AuthConfig{}, invalid(errors.New("must be a valid base64url-encoded string")) + } + return ®istry.AuthConfig{}, invalid(err) + } + + if bytes.Equal(decoded, []byte("{}")) { + return ®istry.AuthConfig{}, nil + } + + return decode(bytes.NewReader(decoded)) +} + +// DecodeRequestBody decodes authentication information as sent as JSON in the +// body of a request. This function is to provide backward compatibility with old +// clients and API versions. Current clients and API versions expect authentication +// to be provided through the X-Registry-Auth header. +// +// Like [Decode], this function always returns an [AuthConfig], even if an +// error occurs. It is up to the caller to decide if authentication is required, +// and if the error can be ignored. +func DecodeRequestBody(r io.ReadCloser) (*registry.AuthConfig, error) { + return decode(r) +} + +func decode(r io.Reader) (*registry.AuthConfig, error) { + authConfig := ®istry.AuthConfig{} + if err := json.NewDecoder(r).Decode(authConfig); err != nil { + // always return an (empty) AuthConfig to increase compatibility with + // the existing API. + return ®istry.AuthConfig{}, invalid(fmt.Errorf("invalid JSON: %w", err)) + } + return authConfig, nil +} + +func invalid(err error) error { + return errInvalidParameter{fmt.Errorf("invalid X-Registry-Auth header: %w", err)} +} + +type errInvalidParameter struct{ error } + +func (errInvalidParameter) InvalidParameter() {} + +func (e errInvalidParameter) Cause() error { return e.error } + +func (e errInvalidParameter) Unwrap() error { return e.error } diff --git a/vendor/github.com/moby/moby/api/types/build/disk_usage.go b/vendor/github.com/moby/moby/api/types/build/disk_usage.go deleted file mode 100644 index e969b6d615f2..000000000000 --- a/vendor/github.com/moby/moby/api/types/build/disk_usage.go +++ /dev/null @@ -1,8 +0,0 @@ -package build - -// CacheDiskUsage contains disk usage for the build cache. -type CacheDiskUsage struct { - TotalSize int64 - Reclaimable int64 - Items []*CacheRecord -} diff --git a/vendor/github.com/moby/moby/api/types/container/config.go b/vendor/github.com/moby/moby/api/types/container/config.go index 6ea9e079ddaf..4c507cab93cd 100644 --- a/vendor/github.com/moby/moby/api/types/container/config.go +++ b/vendor/github.com/moby/moby/api/types/container/config.go @@ -4,7 +4,6 @@ import ( "time" dockerspec "github.com/moby/docker-image-spec/specs-go/v1" - "github.com/moby/moby/api/types/strslice" ) // MinimumDuration puts a minimum on user configured duration. @@ -52,13 +51,13 @@ type Config struct { OpenStdin bool // Open stdin StdinOnce bool // If true, close stdin after the 1 attached client disconnects. Env []string // List of environment variable to set in the container - Cmd strslice.StrSlice // Command to run when starting the container + Cmd []string // Command to run when starting the container Healthcheck *HealthConfig `json:",omitempty"` // Healthcheck describes how to check the container is healthy ArgsEscaped bool `json:",omitempty"` // True if command is already escaped (meaning treat as a command line) (Windows specific). Image string // Name of the image as it was passed by the operator (e.g. could be symbolic) Volumes map[string]struct{} // List of volumes (mounts) used for the container WorkingDir string // Current directory (PWD) in the command will be launched - Entrypoint strslice.StrSlice // Entrypoint to run when starting the container + Entrypoint []string // Entrypoint to run when starting the container NetworkDisabled bool `json:",omitempty"` // Is network disabled // Mac Address of the container. // @@ -68,5 +67,5 @@ type Config struct { Labels map[string]string // List of labels set to this container StopSignal string `json:",omitempty"` // Signal to stop a container StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container - Shell strslice.StrSlice `json:",omitempty"` // Shell for shell-form of RUN, CMD, ENTRYPOINT + Shell []string `json:",omitempty"` // Shell for shell-form of RUN, CMD, ENTRYPOINT } diff --git a/vendor/github.com/moby/moby/api/types/container/container.go b/vendor/github.com/moby/moby/api/types/container/container.go index 56e5ac47362d..80d5ec9c97f5 100644 --- a/vendor/github.com/moby/moby/api/types/container/container.go +++ b/vendor/github.com/moby/moby/api/types/container/container.go @@ -104,7 +104,7 @@ type Summary struct { ImageManifestDescriptor *ocispec.Descriptor `json:"ImageManifestDescriptor,omitempty"` Command string Created int64 - Ports []Port + Ports []PortSummary SizeRw int64 `json:",omitempty"` SizeRootFs int64 `json:",omitempty"` Labels map[string]string diff --git a/vendor/github.com/moby/moby/api/types/container/disk_usage.go b/vendor/github.com/moby/moby/api/types/container/disk_usage.go deleted file mode 100644 index 05b6cbe9c709..000000000000 --- a/vendor/github.com/moby/moby/api/types/container/disk_usage.go +++ /dev/null @@ -1,8 +0,0 @@ -package container - -// DiskUsage contains disk usage for containers. -type DiskUsage struct { - TotalSize int64 - Reclaimable int64 - Items []*Summary -} diff --git a/vendor/github.com/moby/moby/api/types/container/hostconfig.go b/vendor/github.com/moby/moby/api/types/container/hostconfig.go index 65d430053230..0fb65e19218c 100644 --- a/vendor/github.com/moby/moby/api/types/container/hostconfig.go +++ b/vendor/github.com/moby/moby/api/types/container/hostconfig.go @@ -9,7 +9,6 @@ import ( "github.com/moby/moby/api/types/blkiodev" "github.com/moby/moby/api/types/mount" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/strslice" ) // CgroupnsMode represents the cgroup namespace mode of the container @@ -435,8 +434,8 @@ type HostConfig struct { Annotations map[string]string `json:",omitempty"` // Arbitrary non-identifying metadata attached to container and provided to the runtime // Applicable to UNIX platforms - CapAdd strslice.StrSlice // List of kernel capabilities to add to the container - CapDrop strslice.StrSlice // List of kernel capabilities to remove from the container + CapAdd []string // List of kernel capabilities to add to the container + CapDrop []string // List of kernel capabilities to remove from the container CgroupnsMode CgroupnsMode // Cgroup namespace mode to use for the container DNS []string `json:"Dns"` // List of DNS server to lookup DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for diff --git a/vendor/github.com/moby/moby/api/types/container/options.go b/vendor/github.com/moby/moby/api/types/container/options.go index b94152cb4767..9a8618af26e5 100644 --- a/vendor/github.com/moby/moby/api/types/container/options.go +++ b/vendor/github.com/moby/moby/api/types/container/options.go @@ -2,14 +2,6 @@ package container import "github.com/moby/moby/api/types/filters" -// ResizeOptions holds parameters to resize a TTY. -// It can be used to resize container TTYs and -// exec process TTYs too. -type ResizeOptions struct { - Height uint - Width uint -} - // AttachOptions holds parameters to attach to a container. type AttachOptions struct { Stream bool diff --git a/vendor/github.com/moby/moby/api/types/container/port.go b/vendor/github.com/moby/moby/api/types/container/port_summary.go similarity index 82% rename from vendor/github.com/moby/moby/api/types/container/port.go rename to vendor/github.com/moby/moby/api/types/container/port_summary.go index bbaa317fdb5b..3956224dcc6e 100644 --- a/vendor/github.com/moby/moby/api/types/container/port.go +++ b/vendor/github.com/moby/moby/api/types/container/port_summary.go @@ -5,11 +5,12 @@ package container // This file was generated by the swagger tool. // Editing this file might prove futile when you re-run the swagger generate command -// Port An open port on a container +// PortSummary Describes a port-mapping between the container and the host. +// // Example: {"PrivatePort":8080,"PublicPort":80,"Type":"tcp"} // -// swagger:model Port -type Port struct { +// swagger:model PortSummary +type PortSummary struct { // Host IP address that the container's port is mapped to IP string `json:"IP,omitempty"` diff --git a/vendor/github.com/moby/moby/api/types/events/events.go b/vendor/github.com/moby/moby/api/types/events/events.go index d5bf3059d6f1..bcbc0b239105 100644 --- a/vendor/github.com/moby/moby/api/types/events/events.go +++ b/vendor/github.com/moby/moby/api/types/events/events.go @@ -1,7 +1,5 @@ package events -import "github.com/moby/moby/api/types/filters" - // Type is used for event-types. type Type string @@ -130,10 +128,3 @@ type Message struct { Time int64 `json:"time,omitempty"` TimeNano int64 `json:"timeNano,omitempty"` } - -// ListOptions holds parameters to filter events with. -type ListOptions struct { - Since string - Until string - Filters filters.Args -} diff --git a/vendor/github.com/moby/moby/api/types/image/disk_usage.go b/vendor/github.com/moby/moby/api/types/image/disk_usage.go deleted file mode 100644 index b29d925cac48..000000000000 --- a/vendor/github.com/moby/moby/api/types/image/disk_usage.go +++ /dev/null @@ -1,8 +0,0 @@ -package image - -// DiskUsage contains disk usage for images. -type DiskUsage struct { - TotalSize int64 - Reclaimable int64 - Items []*Summary -} diff --git a/vendor/github.com/moby/moby/api/types/network/endpoint.go b/vendor/github.com/moby/moby/api/types/network/endpoint.go index cdc06c6c9001..39b732e0e7e2 100644 --- a/vendor/github.com/moby/moby/api/types/network/endpoint.go +++ b/vendor/github.com/moby/moby/api/types/network/endpoint.go @@ -3,7 +3,9 @@ package network import ( "errors" "fmt" + "maps" "net" + "slices" ) // EndpointSettings stores the network endpoint details @@ -39,25 +41,16 @@ type EndpointSettings struct { // Copy makes a deep copy of `EndpointSettings` func (es *EndpointSettings) Copy() *EndpointSettings { - epCopy := *es - if es.IPAMConfig != nil { - epCopy.IPAMConfig = es.IPAMConfig.Copy() - } - - if es.Links != nil { - links := make([]string, 0, len(es.Links)) - epCopy.Links = append(links, es.Links...) - } - - if es.Aliases != nil { - aliases := make([]string, 0, len(es.Aliases)) - epCopy.Aliases = append(aliases, es.Aliases...) + if es == nil { + return nil } - if len(es.DNSNames) > 0 { - epCopy.DNSNames = make([]string, len(es.DNSNames)) - copy(epCopy.DNSNames, es.DNSNames) - } + epCopy := *es + epCopy.IPAMConfig = es.IPAMConfig.Copy() + epCopy.Links = slices.Clone(es.Links) + epCopy.Aliases = slices.Clone(es.Aliases) + epCopy.DNSNames = slices.Clone(es.DNSNames) + epCopy.DriverOpts = maps.Clone(es.DriverOpts) return &epCopy } @@ -71,9 +64,11 @@ type EndpointIPAMConfig struct { // Copy makes a copy of the endpoint ipam config func (cfg *EndpointIPAMConfig) Copy() *EndpointIPAMConfig { + if cfg == nil { + return nil + } cfgCopy := *cfg - cfgCopy.LinkLocalIPs = make([]string, 0, len(cfg.LinkLocalIPs)) - cfgCopy.LinkLocalIPs = append(cfgCopy.LinkLocalIPs, cfg.LinkLocalIPs...) + cfgCopy.LinkLocalIPs = slices.Clone(cfg.LinkLocalIPs) return &cfgCopy } diff --git a/vendor/github.com/moby/moby/api/types/network/network.go b/vendor/github.com/moby/moby/api/types/network/network.go index f9a206f1890d..1adb075711ac 100644 --- a/vendor/github.com/moby/moby/api/types/network/network.go +++ b/vendor/github.com/moby/moby/api/types/network/network.go @@ -45,17 +45,6 @@ type CreateOptions struct { Labels map[string]string // Labels holds metadata specific to the network being created. } -// ListOptions holds parameters to filter the list of networks with. -type ListOptions struct { - Filters filters.Args -} - -// InspectOptions holds parameters to inspect network. -type InspectOptions struct { - Scope string - Verbose bool -} - // ConnectOptions represents the data to be used to connect a container to the // network. type ConnectOptions struct { diff --git a/vendor/github.com/moby/moby/api/types/registry/authconfig.go b/vendor/github.com/moby/moby/api/types/registry/authconfig.go index 56703705a26e..e4b797da431d 100644 --- a/vendor/github.com/moby/moby/api/types/registry/authconfig.go +++ b/vendor/github.com/moby/moby/api/types/registry/authconfig.go @@ -1,14 +1,6 @@ package registry -import ( - "bytes" - "context" - "encoding/base64" - "encoding/json" - "errors" - "fmt" - "io" -) +import "context" // AuthHeader is the name of the header used to send encoded registry // authorization credentials for registry operations (push/pull). @@ -33,8 +25,8 @@ type AuthConfig struct { Auth string `json:"auth,omitempty"` // Email is an optional value associated with the username. - // This field is deprecated and will be removed in a later - // version of docker. + // + // Deprecated: This field is deprecated since docker 1.11 (API v1.23) and will be removed in the next release. Email string `json:"email,omitempty"` ServerAddress string `json:"serveraddress,omitempty"` @@ -46,85 +38,3 @@ type AuthConfig struct { // RegistryToken is a bearer token to be sent to a registry RegistryToken string `json:"registrytoken,omitempty"` } - -// EncodeAuthConfig serializes the auth configuration as a base64url encoded -// ([RFC4648, section 5]) JSON string for sending through the X-Registry-Auth header. -// -// [RFC4648, section 5]: https://tools.ietf.org/html/rfc4648#section-5 -func EncodeAuthConfig(authConfig AuthConfig) (string, error) { - // Older daemons (or registries) may not handle an empty string, - // which resulted in an "io.EOF" when unmarshaling or decoding. - // - // FIXME(thaJeztah): find exactly what code-paths are impacted by this. - // if authConfig == (AuthConfig{}) { return "", nil } - buf, err := json.Marshal(authConfig) - if err != nil { - return "", errInvalidParameter{err} - } - return base64.URLEncoding.EncodeToString(buf), nil -} - -// DecodeAuthConfig decodes base64url encoded ([RFC4648, section 5]) JSON -// authentication information as sent through the X-Registry-Auth header. -// -// This function always returns an [AuthConfig], even if an error occurs. It is up -// to the caller to decide if authentication is required, and if the error can -// be ignored. -// -// [RFC4648, section 5]: https://tools.ietf.org/html/rfc4648#section-5 -func DecodeAuthConfig(authEncoded string) (*AuthConfig, error) { - if authEncoded == "" { - return &AuthConfig{}, nil - } - - decoded, err := base64.URLEncoding.DecodeString(authEncoded) - if err != nil { - var e base64.CorruptInputError - if errors.As(err, &e) { - return &AuthConfig{}, invalid(errors.New("must be a valid base64url-encoded string")) - } - return &AuthConfig{}, invalid(err) - } - - if bytes.Equal(decoded, []byte("{}")) { - return &AuthConfig{}, nil - } - - return decodeAuthConfigFromReader(bytes.NewReader(decoded)) -} - -// DecodeAuthConfigBody decodes authentication information as sent as JSON in the -// body of a request. This function is to provide backward compatibility with old -// clients and API versions. Current clients and API versions expect authentication -// to be provided through the X-Registry-Auth header. -// -// Like [DecodeAuthConfig], this function always returns an [AuthConfig], even if an -// error occurs. It is up to the caller to decide if authentication is required, -// and if the error can be ignored. -// -// Deprecated: this function is no longer used and will be removed in the next release. -func DecodeAuthConfigBody(rdr io.ReadCloser) (*AuthConfig, error) { - return decodeAuthConfigFromReader(rdr) -} - -func decodeAuthConfigFromReader(rdr io.Reader) (*AuthConfig, error) { - authConfig := &AuthConfig{} - if err := json.NewDecoder(rdr).Decode(authConfig); err != nil { - // always return an (empty) AuthConfig to increase compatibility with - // the existing API. - return &AuthConfig{}, invalid(fmt.Errorf("invalid JSON: %w", err)) - } - return authConfig, nil -} - -func invalid(err error) error { - return errInvalidParameter{fmt.Errorf("invalid X-Registry-Auth header: %w", err)} -} - -type errInvalidParameter struct{ error } - -func (errInvalidParameter) InvalidParameter() {} - -func (e errInvalidParameter) Cause() error { return e.error } - -func (e errInvalidParameter) Unwrap() error { return e.error } diff --git a/vendor/github.com/moby/moby/api/types/registry/search.go b/vendor/github.com/moby/moby/api/types/registry/search.go index 17d77f212270..bd79462f6079 100644 --- a/vendor/github.com/moby/moby/api/types/registry/search.go +++ b/vendor/github.com/moby/moby/api/types/registry/search.go @@ -1,26 +1,5 @@ package registry -import ( - "context" - - "github.com/moby/moby/api/types/filters" -) - -// SearchOptions holds parameters to search images with. -type SearchOptions struct { - RegistryAuth string - - // PrivilegeFunc is a function that clients can supply to retry operations - // after getting an authorization error. This function returns the registry - // authentication header value in base64 encoded format, or an error if the - // privilege request fails. - // - // For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig]. - PrivilegeFunc func(context.Context) (string, error) - Filters filters.Args - Limit int -} - // SearchResult describes a search result returned from a registry type SearchResult struct { // StarCount indicates the number of stars this repository has diff --git a/vendor/github.com/moby/moby/api/types/strslice/strslice.go b/vendor/github.com/moby/moby/api/types/strslice/strslice.go deleted file mode 100644 index bad493fb89fd..000000000000 --- a/vendor/github.com/moby/moby/api/types/strslice/strslice.go +++ /dev/null @@ -1,30 +0,0 @@ -package strslice - -import "encoding/json" - -// StrSlice represents a string or an array of strings. -// We need to override the json decoder to accept both options. -type StrSlice []string - -// UnmarshalJSON decodes the byte slice whether it's a string or an array of -// strings. This method is needed to implement json.Unmarshaler. -func (e *StrSlice) UnmarshalJSON(b []byte) error { - if len(b) == 0 { - // With no input, we preserve the existing value by returning nil and - // leaving the target alone. This allows defining default values for - // the type. - return nil - } - - p := make([]string, 0, 1) - if err := json.Unmarshal(b, &p); err != nil { - var s string - if err := json.Unmarshal(b, &s); err != nil { - return err - } - p = append(p, s) - } - - *e = p - return nil -} diff --git a/vendor/github.com/moby/moby/api/types/swarm/config.go b/vendor/github.com/moby/moby/api/types/swarm/config.go index f8e7f4a6f9c8..b029f2af8567 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/config.go +++ b/vendor/github.com/moby/moby/api/types/swarm/config.go @@ -2,8 +2,6 @@ package swarm import ( "os" - - "github.com/moby/moby/api/types/filters" ) // Config represents a config. @@ -55,8 +53,3 @@ type ConfigCreateResponse struct { // ID is the id of the created config. ID string } - -// ConfigListOptions holds parameters to list configs -type ConfigListOptions struct { - Filters filters.Args -} diff --git a/vendor/github.com/moby/moby/api/types/swarm/node.go b/vendor/github.com/moby/moby/api/types/swarm/node.go index 3e503ef24b2b..9523799b6794 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/node.go +++ b/vendor/github.com/moby/moby/api/types/swarm/node.go @@ -1,7 +1,5 @@ package swarm -import "github.com/moby/moby/api/types/filters" - // Node represents a node. type Node struct { ID string @@ -139,13 +137,3 @@ const ( type Topology struct { Segments map[string]string `json:",omitempty"` } - -// NodeListOptions holds parameters to list nodes with. -type NodeListOptions struct { - Filters filters.Args -} - -// NodeRemoveOptions holds parameters to remove nodes with. -type NodeRemoveOptions struct { - Force bool -} diff --git a/vendor/github.com/moby/moby/api/types/swarm/service.go b/vendor/github.com/moby/moby/api/types/swarm/service.go index 58749aa3550a..63e543a42410 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/service.go +++ b/vendor/github.com/moby/moby/api/types/swarm/service.go @@ -2,8 +2,6 @@ package swarm import ( "time" - - "github.com/moby/moby/api/types/filters" ) // Service represents a service. @@ -205,68 +203,8 @@ type JobStatus struct { LastExecution time.Time `json:",omitempty"` } -// ServiceCreateOptions contains the options to use when creating a service. -type ServiceCreateOptions struct { - // EncodedRegistryAuth is the encoded registry authorization credentials to - // use when updating the service. - // - // This field follows the format of the X-Registry-Auth header. - EncodedRegistryAuth string - - // QueryRegistry indicates whether the service update requires - // contacting a registry. A registry may be contacted to retrieve - // the image digest and manifest, which in turn can be used to update - // platform or other information about the service. - QueryRegistry bool -} - // Values for RegistryAuthFrom in ServiceUpdateOptions const ( RegistryAuthFromSpec = "spec" RegistryAuthFromPreviousSpec = "previous-spec" ) - -// ServiceUpdateOptions contains the options to be used for updating services. -type ServiceUpdateOptions struct { - // EncodedRegistryAuth is the encoded registry authorization credentials to - // use when updating the service. - // - // This field follows the format of the X-Registry-Auth header. - EncodedRegistryAuth string - - // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate - // into this field. While it does open API users up to racy writes, most - // users may not need that level of consistency in practice. - - // RegistryAuthFrom specifies where to find the registry authorization - // credentials if they are not given in EncodedRegistryAuth. Valid - // values are "spec" and "previous-spec". - RegistryAuthFrom string - - // Rollback indicates whether a server-side rollback should be - // performed. When this is set, the provided spec will be ignored. - // The valid values are "previous" and "none". An empty value is the - // same as "none". - Rollback string - - // QueryRegistry indicates whether the service update requires - // contacting a registry. A registry may be contacted to retrieve - // the image digest and manifest, which in turn can be used to update - // platform or other information about the service. - QueryRegistry bool -} - -// ServiceListOptions holds parameters to list services with. -type ServiceListOptions struct { - Filters filters.Args - - // Status indicates whether the server should include the service task - // count of running and desired tasks. - Status bool -} - -// ServiceInspectOptions holds parameters related to the "service inspect" -// operation. -type ServiceInspectOptions struct { - InsertDefaults bool -} diff --git a/vendor/github.com/moby/moby/api/types/swarm/swarm.go b/vendor/github.com/moby/moby/api/types/swarm/swarm.go index 38f3e6666d1e..4c37a982d170 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/swarm.go +++ b/vendor/github.com/moby/moby/api/types/swarm/swarm.go @@ -229,13 +229,6 @@ type Peer struct { Addr string } -// UpdateFlags contains flags for SwarmUpdate. -type UpdateFlags struct { - RotateWorkerToken bool - RotateManagerToken bool - RotateManagerUnlockKey bool -} - // UnlockKeyResponse contains the response for Engine API: // GET /swarm/unlockkey type UnlockKeyResponse struct { diff --git a/vendor/github.com/moby/moby/api/types/swarm/task.go b/vendor/github.com/moby/moby/api/types/swarm/task.go index 180676d5f0a0..1dcbc4d6f8ed 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/task.go +++ b/vendor/github.com/moby/moby/api/types/swarm/task.go @@ -2,8 +2,6 @@ package swarm import ( "time" - - "github.com/moby/moby/api/types/filters" ) // TaskState represents the state of a task. @@ -223,8 +221,3 @@ type VolumeAttachment struct { // in the ContainerSpec, that this volume fulfills. Target string `json:",omitempty"` } - -// TaskListOptions holds parameters to list tasks with. -type TaskListOptions struct { - Filters filters.Args -} diff --git a/vendor/github.com/moby/moby/api/types/system/disk_usage.go b/vendor/github.com/moby/moby/api/types/system/disk_usage.go index 0f8308c9b9a2..3468109efab6 100644 --- a/vendor/github.com/moby/moby/api/types/system/disk_usage.go +++ b/vendor/github.com/moby/moby/api/types/system/disk_usage.go @@ -21,13 +21,6 @@ const ( BuildCacheObject DiskUsageObject = "build-cache" ) -// DiskUsageOptions holds parameters for system disk usage query. -type DiskUsageOptions struct { - // Types specifies what object types to include in the response. If empty, - // all object types are returned. - Types []DiskUsageObject -} - // DiskUsage contains response of Engine API: // GET "/system/df" type DiskUsage struct { diff --git a/vendor/github.com/moby/moby/api/types/volume/disk_usage.go b/vendor/github.com/moby/moby/api/types/volume/disk_usage.go deleted file mode 100644 index 3d716c6e00d9..000000000000 --- a/vendor/github.com/moby/moby/api/types/volume/disk_usage.go +++ /dev/null @@ -1,8 +0,0 @@ -package volume - -// DiskUsage contains disk usage for volumes. -type DiskUsage struct { - TotalSize int64 - Reclaimable int64 - Items []*Volume -} diff --git a/vendor/github.com/moby/moby/api/types/volume/options.go b/vendor/github.com/moby/moby/api/types/volume/prune_report.go similarity index 53% rename from vendor/github.com/moby/moby/api/types/volume/options.go rename to vendor/github.com/moby/moby/api/types/volume/prune_report.go index 7237f2db8d08..7f501d01a7ce 100644 --- a/vendor/github.com/moby/moby/api/types/volume/options.go +++ b/vendor/github.com/moby/moby/api/types/volume/prune_report.go @@ -1,12 +1,5 @@ package volume -import "github.com/moby/moby/api/types/filters" - -// ListOptions holds parameters to list volumes. -type ListOptions struct { - Filters filters.Args -} - // PruneReport contains the response for Engine API: // POST "/volumes/prune" type PruneReport struct { diff --git a/vendor/github.com/moby/moby/client/README.md b/vendor/github.com/moby/moby/client/README.md index 4b0e7530cb9f..05d9e284e863 100644 --- a/vendor/github.com/moby/moby/client/README.md +++ b/vendor/github.com/moby/moby/client/README.md @@ -1,5 +1,11 @@ # Go client for the Docker Engine API +[![PkgGoDev](https://pkg.go.dev/badge/github.com/moby/moby/client)](https://pkg.go.dev/github.com/moby/moby/client) +![GitHub License](https://img.shields.io/github/license/moby/moby) +[![Go Report Card](https://goreportcard.com/badge/github.com/moby/moby/client)](https://goreportcard.com/report/github.com/moby/moby/client) +[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/moby/moby/badge)](https://scorecard.dev/viewer/?uri=github.com/moby/moby) +[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/10989/badge)](https://www.bestpractices.dev/projects/10989) + The `docker` command uses this package to communicate with the daemon. It can also be used by your own Go applications to do anything the command-line interface does; running containers, pulling or pushing images, etc. diff --git a/vendor/github.com/moby/moby/client/build_cancel.go b/vendor/github.com/moby/moby/client/build_cancel.go index a1b83c0030c4..f39b8761611f 100644 --- a/vendor/github.com/moby/moby/client/build_cancel.go +++ b/vendor/github.com/moby/moby/client/build_cancel.go @@ -12,6 +12,6 @@ func (cli *Client) BuildCancel(ctx context.Context, id string) error { query.Set("id", id) resp, err := cli.post(ctx, "/build/cancel", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/checkpoint_create.go b/vendor/github.com/moby/moby/client/checkpoint_create.go index 0dd07d237451..ef325a82dd6a 100644 --- a/vendor/github.com/moby/moby/client/checkpoint_create.go +++ b/vendor/github.com/moby/moby/client/checkpoint_create.go @@ -14,6 +14,6 @@ func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, opt } resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, options, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/checkpoint_delete.go b/vendor/github.com/moby/moby/client/checkpoint_delete.go index 15d6075c5a45..87f3f88218c0 100644 --- a/vendor/github.com/moby/moby/client/checkpoint_delete.go +++ b/vendor/github.com/moby/moby/client/checkpoint_delete.go @@ -20,6 +20,6 @@ func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, opt } resp, err := cli.delete(ctx, "/containers/"+containerID+"/checkpoints/"+options.CheckpointID, query, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index a8b786274853..c686f535f5fd 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -72,7 +72,7 @@ type ContainerAPIClient interface { ContainerExecAttach(ctx context.Context, execID string, options container.ExecAttachOptions) (HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (container.ExecCreateResponse, error) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) - ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error + ContainerExecResize(ctx context.Context, execID string, options ContainerResizeOptions) error ContainerExecStart(ctx context.Context, execID string, options container.ExecStartOptions) error ContainerExport(ctx context.Context, container string) (io.ReadCloser, error) ContainerInspect(ctx context.Context, container string) (container.InspectResponse, error) @@ -83,7 +83,7 @@ type ContainerAPIClient interface { ContainerPause(ctx context.Context, container string) error ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error ContainerRename(ctx context.Context, container, newContainerName string) error - ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error + ContainerResize(ctx context.Context, container string, options ContainerResizeOptions) error ContainerRestart(ctx context.Context, container string, options container.StopOptions) error ContainerStatPath(ctx context.Context, container, path string) (container.PathStat, error) ContainerStats(ctx context.Context, container string, stream bool) (StatsResponseReader, error) @@ -116,7 +116,7 @@ type ImageAPIClient interface { ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error) - ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) + ImageSearch(ctx context.Context, term string, options ImageSearchOptions) ([]registry.SearchResult, error) ImageTag(ctx context.Context, image, ref string) error ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error) @@ -131,9 +131,9 @@ type NetworkAPIClient interface { NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) NetworkDisconnect(ctx context.Context, network, container string, force bool) error - NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error) - NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error) - NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) + NetworkInspect(ctx context.Context, network string, options NetworkInspectOptions) (network.Inspect, error) + NetworkInspectWithRaw(ctx context.Context, network string, options NetworkInspectOptions) (network.Inspect, []byte, error) + NetworkList(ctx context.Context, options NetworkListOptions) ([]network.Summary, error) NetworkRemove(ctx context.Context, network string) error NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error) } @@ -141,8 +141,8 @@ type NetworkAPIClient interface { // NodeAPIClient defines API client methods for the nodes type NodeAPIClient interface { NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) - NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) - NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error + NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) + NodeRemove(ctx context.Context, nodeID string, options NodeRemoveOptions) error NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error } @@ -162,15 +162,15 @@ type PluginAPIClient interface { // ServiceAPIClient defines API client methods for the services type ServiceAPIClient interface { - ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) - ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) - ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) + ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) + ServiceInspectWithRaw(ctx context.Context, serviceID string, options ServiceInspectOptions) (swarm.Service, []byte, error) + ServiceList(ctx context.Context, options ServiceListOptions) ([]swarm.Service, error) ServiceRemove(ctx context.Context, serviceID string) error - ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) + ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error) TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) - TaskList(ctx context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) + TaskList(ctx context.Context, options TaskListOptions) ([]swarm.Task, error) } // SwarmAPIClient defines API client methods for the swarm @@ -181,15 +181,15 @@ type SwarmAPIClient interface { SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error SwarmLeave(ctx context.Context, force bool) error SwarmInspect(ctx context.Context) (swarm.Swarm, error) - SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error + SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags SwarmUpdateFlags) error } // SystemAPIClient defines API client methods for the system type SystemAPIClient interface { - Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error) + Events(ctx context.Context, options EventsListOptions) (<-chan events.Message, <-chan error) Info(ctx context.Context) (system.Info, error) RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error) - DiskUsage(ctx context.Context, options system.DiskUsageOptions) (system.DiskUsage, error) + DiskUsage(ctx context.Context, options DiskUsageOptions) (system.DiskUsage, error) Ping(ctx context.Context) (types.Ping, error) } @@ -198,7 +198,7 @@ type VolumeAPIClient interface { VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) - VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) + VolumeList(ctx context.Context, options VolumeListOptions) (volume.ListResponse, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, pruneFilter filters.Args) (volume.PruneReport, error) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error @@ -215,7 +215,7 @@ type SecretAPIClient interface { // ConfigAPIClient defines API client methods for configs type ConfigAPIClient interface { - ConfigList(ctx context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) + ConfigList(ctx context.Context, options ConfigListOptions) ([]swarm.Config, error) ConfigCreate(ctx context.Context, config swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) ConfigRemove(ctx context.Context, id string) error ConfigInspectWithRaw(ctx context.Context, name string) (swarm.Config, []byte, error) diff --git a/vendor/github.com/moby/moby/client/config_list.go b/vendor/github.com/moby/moby/client/config_list.go index aae9c0d4e32f..b32b361b8ac6 100644 --- a/vendor/github.com/moby/moby/client/config_list.go +++ b/vendor/github.com/moby/moby/client/config_list.go @@ -10,7 +10,7 @@ import ( ) // ConfigList returns the list of configs. -func (cli *Client) ConfigList(ctx context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { +func (cli *Client) ConfigList(ctx context.Context, options ConfigListOptions) ([]swarm.Config, error) { if err := cli.NewVersionError(ctx, "1.30", "config list"); err != nil { return nil, err } diff --git a/vendor/github.com/moby/moby/client/config_update.go b/vendor/github.com/moby/moby/client/config_update.go index a55f01beff66..93037479471d 100644 --- a/vendor/github.com/moby/moby/client/config_update.go +++ b/vendor/github.com/moby/moby/client/config_update.go @@ -19,6 +19,6 @@ func (cli *Client) ConfigUpdate(ctx context.Context, id string, version swarm.Ve query := url.Values{} query.Set("version", version.String()) resp, err := cli.post(ctx, "/configs/"+id+"/update", query, config, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_commit.go b/vendor/github.com/moby/moby/client/container_commit.go index fcdb115afe3b..797309852a17 100644 --- a/vendor/github.com/moby/moby/client/container_commit.go +++ b/vendor/github.com/moby/moby/client/container_commit.go @@ -24,7 +24,7 @@ func (cli *Client) ContainerCommit(ctx context.Context, containerID string, opti return container.CommitResponse{}, err } - if _, isCanonical := ref.(reference.Canonical); isCanonical { + if _, ok := ref.(reference.Digested); ok { return container.CommitResponse{}, errors.New("refusing to create a tag with a digest reference") } ref = reference.TagNameOnly(ref) diff --git a/vendor/github.com/moby/moby/client/container_exec.go b/vendor/github.com/moby/moby/client/container_exec.go index 2b42e2f5d1d9..8739c2967b76 100644 --- a/vendor/github.com/moby/moby/client/container_exec.go +++ b/vendor/github.com/moby/moby/client/container_exec.go @@ -58,7 +58,7 @@ func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config config.ConsoleSize = nil } resp, err := cli.post(ctx, "/exec/"+execID+"/start", nil, config, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } @@ -91,13 +91,13 @@ func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, confi // ContainerExecInspect returns information about a specific exec process on the docker host. func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) { - var response container.ExecInspect resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil) + defer ensureReaderClosed(resp) if err != nil { - return response, err + return container.ExecInspect{}, err } + var response container.ExecInspect err = json.NewDecoder(resp.Body).Decode(&response) - ensureReaderClosed(resp) return response, err } diff --git a/vendor/github.com/moby/moby/client/container_kill.go b/vendor/github.com/moby/moby/client/container_kill.go index 251ae479a38f..d198337fd91d 100644 --- a/vendor/github.com/moby/moby/client/container_kill.go +++ b/vendor/github.com/moby/moby/client/container_kill.go @@ -18,6 +18,6 @@ func (cli *Client) ContainerKill(ctx context.Context, containerID, signal string } resp, err := cli.post(ctx, "/containers/"+containerID+"/kill", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_logs.go b/vendor/github.com/moby/moby/client/container_logs.go index 693f830b63e1..d98f625123c2 100644 --- a/vendor/github.com/moby/moby/client/container_logs.go +++ b/vendor/github.com/moby/moby/client/container_logs.go @@ -8,7 +8,7 @@ import ( "time" "github.com/moby/moby/api/types/container" - timetypes "github.com/moby/moby/api/types/time" + "github.com/moby/moby/client/internal/timestamp" ) // ContainerLogs returns the logs generated by a container in an [io.ReadCloser]. @@ -53,7 +53,7 @@ func (cli *Client) ContainerLogs(ctx context.Context, containerID string, option } if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, time.Now()) + ts, err := timestamp.GetTimestamp(options.Since, time.Now()) if err != nil { return nil, fmt.Errorf(`invalid value for "since": %w`, err) } @@ -61,7 +61,7 @@ func (cli *Client) ContainerLogs(ctx context.Context, containerID string, option } if options.Until != "" { - ts, err := timetypes.GetTimestamp(options.Until, time.Now()) + ts, err := timestamp.GetTimestamp(options.Until, time.Now()) if err != nil { return nil, fmt.Errorf(`invalid value for "until": %w`, err) } diff --git a/vendor/github.com/moby/moby/client/container_pause.go b/vendor/github.com/moby/moby/client/container_pause.go index 59b3e2d86584..c3488b9723f6 100644 --- a/vendor/github.com/moby/moby/client/container_pause.go +++ b/vendor/github.com/moby/moby/client/container_pause.go @@ -10,6 +10,6 @@ func (cli *Client) ContainerPause(ctx context.Context, containerID string) error } resp, err := cli.post(ctx, "/containers/"+containerID+"/pause", nil, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_rename.go b/vendor/github.com/moby/moby/client/container_rename.go index 4c030228cdd3..9eba310d5aa5 100644 --- a/vendor/github.com/moby/moby/client/container_rename.go +++ b/vendor/github.com/moby/moby/client/container_rename.go @@ -15,6 +15,6 @@ func (cli *Client) ContainerRename(ctx context.Context, containerID, newContaine query := url.Values{} query.Set("name", newContainerName) resp, err := cli.post(ctx, "/containers/"+containerID+"/rename", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_resize.go b/vendor/github.com/moby/moby/client/container_resize.go index 7b52a97d46dc..bba1b8335489 100644 --- a/vendor/github.com/moby/moby/client/container_resize.go +++ b/vendor/github.com/moby/moby/client/container_resize.go @@ -4,12 +4,18 @@ import ( "context" "net/url" "strconv" - - "github.com/moby/moby/api/types/container" ) +// ContainerResizeOptions holds parameters to resize a TTY. +// It can be used to resize container TTYs and +// exec process TTYs too. +type ContainerResizeOptions struct { + Height uint + Width uint +} + // ContainerResize changes the size of the pseudo-TTY for a container. -func (cli *Client) ContainerResize(ctx context.Context, containerID string, options container.ResizeOptions) error { +func (cli *Client) ContainerResize(ctx context.Context, containerID string, options ContainerResizeOptions) error { containerID, err := trimID("container", containerID) if err != nil { return err @@ -18,7 +24,7 @@ func (cli *Client) ContainerResize(ctx context.Context, containerID string, opti } // ContainerExecResize changes the size of the tty for an exec process running inside a container. -func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error { +func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options ContainerResizeOptions) error { execID, err := trimID("exec", execID) if err != nil { return err @@ -33,6 +39,6 @@ func (cli *Client) resize(ctx context.Context, basePath string, height, width ui query.Set("w", strconv.FormatUint(uint64(width), 10)) resp, err := cli.post(ctx, basePath+"/resize", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_restart.go b/vendor/github.com/moby/moby/client/container_restart.go index 34d03dcb1f70..ba4a76a85bf2 100644 --- a/vendor/github.com/moby/moby/client/container_restart.go +++ b/vendor/github.com/moby/moby/client/container_restart.go @@ -36,6 +36,6 @@ func (cli *Client) ContainerRestart(ctx context.Context, containerID string, opt } } resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_start.go b/vendor/github.com/moby/moby/client/container_start.go index e6c35223ee78..37ef68cb4752 100644 --- a/vendor/github.com/moby/moby/client/container_start.go +++ b/vendor/github.com/moby/moby/client/container_start.go @@ -23,6 +23,6 @@ func (cli *Client) ContainerStart(ctx context.Context, containerID string, optio } resp, err := cli.post(ctx, "/containers/"+containerID+"/start", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_stop.go b/vendor/github.com/moby/moby/client/container_stop.go index 8ea2e6bd356c..361464eea4e1 100644 --- a/vendor/github.com/moby/moby/client/container_stop.go +++ b/vendor/github.com/moby/moby/client/container_stop.go @@ -40,6 +40,6 @@ func (cli *Client) ContainerStop(ctx context.Context, containerID string, option } } resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/container_unpause.go b/vendor/github.com/moby/moby/client/container_unpause.go index 5910115b7a1a..edaf236c1f43 100644 --- a/vendor/github.com/moby/moby/client/container_unpause.go +++ b/vendor/github.com/moby/moby/client/container_unpause.go @@ -10,6 +10,6 @@ func (cli *Client) ContainerUnpause(ctx context.Context, containerID string) err } resp, err := cli.post(ctx, "/containers/"+containerID+"/unpause", nil, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/hijack.go b/vendor/github.com/moby/moby/client/hijack.go index 46608d93cbbd..f06f53a32312 100644 --- a/vendor/github.com/moby/moby/client/hijack.go +++ b/vendor/github.com/moby/moby/client/hijack.go @@ -14,7 +14,7 @@ import ( ) // postHijacked sends a POST request and hijacks the connection. -func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body interface{}, headers map[string][]string) (HijackedResponse, error) { +func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body any, headers map[string][]string) (HijackedResponse, error) { jsonBody, err := jsonEncode(body) if err != nil { return HijackedResponse{}, err diff --git a/vendor/github.com/moby/moby/client/image_push.go b/vendor/github.com/moby/moby/client/image_push.go index 1ac5f43f5579..e4a96a7eb8c7 100644 --- a/vendor/github.com/moby/moby/client/image_push.go +++ b/vendor/github.com/moby/moby/client/image_push.go @@ -25,7 +25,7 @@ func (cli *Client) ImagePush(ctx context.Context, image string, options image.Pu return nil, err } - if _, isCanonical := ref.(reference.Canonical); isCanonical { + if _, ok := ref.(reference.Digested); ok { return nil, errors.New("cannot push a digest reference") } diff --git a/vendor/github.com/moby/moby/client/image_search.go b/vendor/github.com/moby/moby/client/image_search.go index 807fb69316cb..a2fca5deda04 100644 --- a/vendor/github.com/moby/moby/client/image_search.go +++ b/vendor/github.com/moby/moby/client/image_search.go @@ -14,7 +14,7 @@ import ( // ImageSearch makes the docker host search by a term in a remote registry. // The list of results is not sorted in any fashion. -func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) { +func (cli *Client) ImageSearch(ctx context.Context, term string, options ImageSearchOptions) ([]registry.SearchResult, error) { var results []registry.SearchResult query := url.Values{} query.Set("term", term) diff --git a/vendor/github.com/moby/moby/client/image_search_opts.go b/vendor/github.com/moby/moby/client/image_search_opts.go new file mode 100644 index 000000000000..d2e9b7bdfe03 --- /dev/null +++ b/vendor/github.com/moby/moby/client/image_search_opts.go @@ -0,0 +1,22 @@ +package client + +import ( + "context" + + "github.com/moby/moby/api/types/filters" +) + +// ImageSearchOptions holds parameters to search images with. +type ImageSearchOptions struct { + RegistryAuth string + + // PrivilegeFunc is a function that clients can supply to retry operations + // after getting an authorization error. This function returns the registry + // authentication header value in base64 encoded format, or an error if the + // privilege request fails. + // + // For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig]. + PrivilegeFunc func(context.Context) (string, error) + Filters filters.Args + Limit int +} diff --git a/vendor/github.com/moby/moby/client/image_tag.go b/vendor/github.com/moby/moby/client/image_tag.go index 2d9fc2a80a13..417322496aa6 100644 --- a/vendor/github.com/moby/moby/client/image_tag.go +++ b/vendor/github.com/moby/moby/client/image_tag.go @@ -20,7 +20,7 @@ func (cli *Client) ImageTag(ctx context.Context, source, target string) error { return fmt.Errorf("error parsing reference: %q is not a valid repository/tag: %w", target, err) } - if _, isCanonical := ref.(reference.Canonical); isCanonical { + if _, ok := ref.(reference.Digested); ok { return errors.New("refusing to create a tag with a digest reference") } @@ -33,6 +33,6 @@ func (cli *Client) ImageTag(ctx context.Context, source, target string) error { } resp, err := cli.post(ctx, "/images/"+source+"/tag", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/api/types/time/timestamp.go b/vendor/github.com/moby/moby/client/internal/timestamp/timestamp.go similarity index 99% rename from vendor/github.com/moby/moby/api/types/time/timestamp.go rename to vendor/github.com/moby/moby/client/internal/timestamp/timestamp.go index 0e1df38a43f8..7b175f0c93b4 100644 --- a/vendor/github.com/moby/moby/api/types/time/timestamp.go +++ b/vendor/github.com/moby/moby/client/internal/timestamp/timestamp.go @@ -1,4 +1,4 @@ -package time +package timestamp import ( "fmt" diff --git a/vendor/github.com/moby/moby/client/network_connect.go b/vendor/github.com/moby/moby/client/network_connect.go index 0f76056f1a8f..74a856e83382 100644 --- a/vendor/github.com/moby/moby/client/network_connect.go +++ b/vendor/github.com/moby/moby/client/network_connect.go @@ -23,6 +23,6 @@ func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID st EndpointConfig: config, } resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, nc, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/network_disconnect.go b/vendor/github.com/moby/moby/client/network_disconnect.go index 09063fcc32b6..5f52c84d48c4 100644 --- a/vendor/github.com/moby/moby/client/network_disconnect.go +++ b/vendor/github.com/moby/moby/client/network_disconnect.go @@ -23,6 +23,6 @@ func (cli *Client) NetworkDisconnect(ctx context.Context, networkID, containerID Force: force, } resp, err := cli.post(ctx, "/networks/"+networkID+"/disconnect", nil, nd, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/network_inspect.go b/vendor/github.com/moby/moby/client/network_inspect.go index 83d91f55c974..83e8cd1cb34d 100644 --- a/vendor/github.com/moby/moby/client/network_inspect.go +++ b/vendor/github.com/moby/moby/client/network_inspect.go @@ -11,13 +11,13 @@ import ( ) // NetworkInspect returns the information for a specific network configured in the docker host. -func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) { +func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options NetworkInspectOptions) (network.Inspect, error) { networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID, options) return networkResource, err } // NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation. -func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, []byte, error) { +func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options NetworkInspectOptions) (network.Inspect, []byte, error) { networkID, err := trimID("network", networkID) if err != nil { return network.Inspect{}, nil, err diff --git a/vendor/github.com/moby/moby/client/network_inspect_opts.go b/vendor/github.com/moby/moby/client/network_inspect_opts.go new file mode 100644 index 000000000000..d83f113e17b4 --- /dev/null +++ b/vendor/github.com/moby/moby/client/network_inspect_opts.go @@ -0,0 +1,7 @@ +package client + +// NetworkInspectOptions holds parameters to inspect network. +type NetworkInspectOptions struct { + Scope string + Verbose bool +} diff --git a/vendor/github.com/moby/moby/client/network_list.go b/vendor/github.com/moby/moby/client/network_list.go index 5069c3bfe4c1..2dd9525931a9 100644 --- a/vendor/github.com/moby/moby/client/network_list.go +++ b/vendor/github.com/moby/moby/client/network_list.go @@ -11,7 +11,7 @@ import ( ) // NetworkList returns the list of networks configured in the docker host. -func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { +func (cli *Client) NetworkList(ctx context.Context, options NetworkListOptions) ([]network.Summary, error) { query := url.Values{} if options.Filters.Len() > 0 { filterJSON, err := filters.ToJSON(options.Filters) diff --git a/vendor/github.com/moby/moby/client/network_list_opts.go b/vendor/github.com/moby/moby/client/network_list_opts.go new file mode 100644 index 000000000000..d42c908d2d3e --- /dev/null +++ b/vendor/github.com/moby/moby/client/network_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// NetworkListOptions holds parameters to filter the list of networks with. +type NetworkListOptions struct { + Filters filters.Args +} diff --git a/vendor/github.com/moby/moby/client/node_list.go b/vendor/github.com/moby/moby/client/node_list.go index f6d2cad23e04..96e9caba1d74 100644 --- a/vendor/github.com/moby/moby/client/node_list.go +++ b/vendor/github.com/moby/moby/client/node_list.go @@ -10,7 +10,7 @@ import ( ) // NodeList returns the list of nodes. -func (cli *Client) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *Client) NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/vendor/github.com/moby/moby/client/node_remove.go b/vendor/github.com/moby/moby/client/node_remove.go index 9499a5efbc43..b630ecffd4bd 100644 --- a/vendor/github.com/moby/moby/client/node_remove.go +++ b/vendor/github.com/moby/moby/client/node_remove.go @@ -3,12 +3,10 @@ package client import ( "context" "net/url" - - "github.com/moby/moby/api/types/swarm" ) // NodeRemove removes a Node. -func (cli *Client) NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error { +func (cli *Client) NodeRemove(ctx context.Context, nodeID string, options NodeRemoveOptions) error { nodeID, err := trimID("node", nodeID) if err != nil { return err diff --git a/vendor/github.com/moby/moby/client/node_update.go b/vendor/github.com/moby/moby/client/node_update.go index 0265d4fc015c..6dfa11b3a688 100644 --- a/vendor/github.com/moby/moby/client/node_update.go +++ b/vendor/github.com/moby/moby/client/node_update.go @@ -17,6 +17,6 @@ func (cli *Client) NodeUpdate(ctx context.Context, nodeID string, version swarm. query := url.Values{} query.Set("version", version.String()) resp, err := cli.post(ctx, "/nodes/"+nodeID+"/update", query, node, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/ping.go b/vendor/github.com/moby/moby/client/ping.go index 974e8ad15697..96ee7bef665d 100644 --- a/vendor/github.com/moby/moby/client/ping.go +++ b/vendor/github.com/moby/moby/client/ping.go @@ -19,63 +19,56 @@ import ( // for other non-success status codes, failing to connect to the API, or failing // to parse the API response. func (cli *Client) Ping(ctx context.Context) (types.Ping, error) { - var ping types.Ping - // Using cli.buildRequest() + cli.doRequest() instead of cli.sendRequest() // because ping requests are used during API version negotiation, so we want // to hit the non-versioned /_ping endpoint, not /v1.xx/_ping req, err := cli.buildRequest(ctx, http.MethodHead, path.Join(cli.basePath, "/_ping"), nil, nil) if err != nil { - return ping, err + return types.Ping{}, err } resp, err := cli.doRequest(req) - if err != nil { - if IsErrConnectionFailed(err) { - return ping, err - } - // We managed to connect, but got some error; continue and try GET request. - } else { - defer ensureReaderClosed(resp) - switch resp.StatusCode { - case http.StatusOK, http.StatusInternalServerError: - // Server handled the request, so parse the response - return parsePingResponse(cli, resp) - } + defer ensureReaderClosed(resp) + if err == nil && resp.StatusCode == http.StatusOK { + // Fast-path; successfully connected using a HEAD request and + // we got a "OK" (200) status. For non-200 status-codes, we fall + // back to doing a GET request, as a HEAD request won't have a + // response-body to get error details from. + return newPingResponse(resp), nil } - // HEAD failed; fallback to GET. + // HEAD failed or returned a non-OK status; fallback to GET. req.Method = http.MethodGet resp, err = cli.doRequest(req) defer ensureReaderClosed(resp) if err != nil { - return ping, err + // Failed to connect. + return types.Ping{}, err } - return parsePingResponse(cli, resp) + + // GET request succeeded but may have returned a non-200 status. + // Return a Ping response, together with any error returned by + // the API server. + return newPingResponse(resp), checkResponseErr(resp) } -func parsePingResponse(cli *Client, resp *http.Response) (types.Ping, error) { +func newPingResponse(resp *http.Response) types.Ping { if resp == nil { - return types.Ping{}, nil - } - - var ping types.Ping - if resp.Header == nil { - return ping, cli.checkResponseErr(resp) - } - ping.APIVersion = resp.Header.Get("Api-Version") - ping.OSType = resp.Header.Get("Ostype") - if resp.Header.Get("Docker-Experimental") == "true" { - ping.Experimental = true - } - if bv := resp.Header.Get("Builder-Version"); bv != "" { - ping.BuilderVersion = build.BuilderVersion(bv) + return types.Ping{} } + var swarmStatus *swarm.Status if si := resp.Header.Get("Swarm"); si != "" { state, role, _ := strings.Cut(si, "/") - ping.SwarmStatus = &swarm.Status{ + swarmStatus = &swarm.Status{ NodeState: swarm.LocalNodeState(state), ControlAvailable: role == "manager", } } - return ping, cli.checkResponseErr(resp) + + return types.Ping{ + APIVersion: resp.Header.Get("Api-Version"), + OSType: resp.Header.Get("Ostype"), + Experimental: resp.Header.Get("Docker-Experimental") == "true", + BuilderVersion: build.BuilderVersion(resp.Header.Get("Builder-Version")), + SwarmStatus: swarmStatus, + } } diff --git a/vendor/github.com/moby/moby/client/pkg/jsonmessage/jsonmessage.go b/vendor/github.com/moby/moby/client/pkg/jsonmessage/jsonmessage.go index bbb9581b2fdd..ff4b40a666c1 100644 --- a/vendor/github.com/moby/moby/client/pkg/jsonmessage/jsonmessage.go +++ b/vendor/github.com/moby/moby/client/pkg/jsonmessage/jsonmessage.go @@ -126,9 +126,6 @@ type JSONMessage struct { Status string `json:"status,omitempty"` Progress *JSONProgress `json:"progressDetail,omitempty"` ID string `json:"id,omitempty"` - From string `json:"from,omitempty"` - Time int64 `json:"time,omitempty"` - TimeNano int64 `json:"timeNano,omitempty"` Error *jsonstream.Error `json:"errorDetail,omitempty"` Aux *json.RawMessage `json:"aux,omitempty"` // Aux contains out-of-band data, such as digests for push signing and image id after building. } @@ -177,17 +174,9 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error { } else if jm.Progress != nil && jm.Progress.String() != "" { // disable progressbar in non-terminal return nil } - if jm.TimeNano != 0 { - _, _ = fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(RFC3339NanoFixed)) - } else if jm.Time != 0 { - _, _ = fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(RFC3339NanoFixed)) - } if jm.ID != "" { _, _ = fmt.Fprintf(out, "%s: ", jm.ID) } - if jm.From != "" { - _, _ = fmt.Fprintf(out, "(from %s) ", jm.From) - } if jm.Progress != nil && isTerminal { _, _ = fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) } else if jm.Stream != "" { diff --git a/vendor/github.com/moby/moby/client/plugin_create.go b/vendor/github.com/moby/moby/client/plugin_create.go index b1216c1224f1..c143db7061e5 100644 --- a/vendor/github.com/moby/moby/client/plugin_create.go +++ b/vendor/github.com/moby/moby/client/plugin_create.go @@ -21,6 +21,6 @@ func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, cr query.Set("name", createOptions.RepoName) resp, err := cli.postRaw(ctx, "/plugins/create", query, createContext, headers) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/plugin_disable.go b/vendor/github.com/moby/moby/client/plugin_disable.go index 3f728ab30459..b368dc6e58ea 100644 --- a/vendor/github.com/moby/moby/client/plugin_disable.go +++ b/vendor/github.com/moby/moby/client/plugin_disable.go @@ -21,6 +21,6 @@ func (cli *Client) PluginDisable(ctx context.Context, name string, options Plugi query.Set("force", "1") } resp, err := cli.post(ctx, "/plugins/"+name+"/disable", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/plugin_enable.go b/vendor/github.com/moby/moby/client/plugin_enable.go index 5d534c456d9b..c79361a47363 100644 --- a/vendor/github.com/moby/moby/client/plugin_enable.go +++ b/vendor/github.com/moby/moby/client/plugin_enable.go @@ -21,6 +21,6 @@ func (cli *Client) PluginEnable(ctx context.Context, name string, options Plugin query.Set("timeout", strconv.Itoa(options.Timeout)) resp, err := cli.post(ctx, "/plugins/"+name+"/enable", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/plugin_set.go b/vendor/github.com/moby/moby/client/plugin_set.go index f0e4a0c30522..f60631160238 100644 --- a/vendor/github.com/moby/moby/client/plugin_set.go +++ b/vendor/github.com/moby/moby/client/plugin_set.go @@ -12,6 +12,6 @@ func (cli *Client) PluginSet(ctx context.Context, name string, args []string) er } resp, err := cli.post(ctx, "/plugins/"+name+"/set", nil, args, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/request.go b/vendor/github.com/moby/moby/client/request.go index 803ff6d2a65a..cd6643b1c407 100644 --- a/vendor/github.com/moby/moby/client/request.go +++ b/vendor/github.com/moby/moby/client/request.go @@ -28,7 +28,7 @@ func (cli *Client) get(ctx context.Context, path string, query url.Values, heade } // post sends an http POST request to the API. -func (cli *Client) post(ctx context.Context, path string, query url.Values, body interface{}, headers http.Header) (*http.Response, error) { +func (cli *Client) post(ctx context.Context, path string, query url.Values, body any, headers http.Header) (*http.Response, error) { jsonBody, headers, err := prepareJSONRequest(body, headers) if err != nil { return nil, err @@ -40,7 +40,7 @@ func (cli *Client) postRaw(ctx context.Context, path string, query url.Values, b return cli.sendRequest(ctx, http.MethodPost, path, query, body, headers) } -func (cli *Client) put(ctx context.Context, path string, query url.Values, body interface{}, headers http.Header) (*http.Response, error) { +func (cli *Client) put(ctx context.Context, path string, query url.Values, body any, headers http.Header) (*http.Response, error) { jsonBody, headers, err := prepareJSONRequest(body, headers) if err != nil { return nil, err @@ -70,7 +70,7 @@ func (cli *Client) delete(ctx context.Context, path string, query url.Values, he // // TODO(thaJeztah): should this return an error if a different Content-Type is already set? // TODO(thaJeztah): is "nil" the appropriate approach for an empty body, or should we use [http.NoBody] (or similar)? -func prepareJSONRequest(body interface{}, headers http.Header) (io.Reader, http.Header, error) { +func prepareJSONRequest(body any, headers http.Header) (io.Reader, http.Header, error) { if body == nil { return nil, headers, nil } @@ -123,16 +123,22 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u } resp, err := cli.doRequest(req) - switch { - case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded): - return nil, err - case err == nil: - return resp, cli.checkResponseErr(resp) - default: + if err != nil { + // Failed to connect or context error. return resp, err } + + // Successfully made a request; return the response and handle any + // API HTTP response errors. + return resp, checkResponseErr(resp) } +// doRequest sends an HTTP request and returns an HTTP response. It is a +// wrapper around [http.Client.Do] with extra handling to decorate errors. +// +// Otherwise, it behaves identical to [http.Client.Do]; an error is returned +// when failing to make a connection, On error, any Response can be ignored. +// A non-2xx status code doesn't cause an error. func (cli *Client) doRequest(req *http.Request) (*http.Response, error) { resp, err := cli.client.Do(req) if err == nil { @@ -203,7 +209,7 @@ func (cli *Client) doRequest(req *http.Request) (*http.Response, error) { return nil, errConnectionFailed{fmt.Errorf("error during connect: %w", err)} } -func (cli *Client) checkResponseErr(serverResp *http.Response) (retErr error) { +func checkResponseErr(serverResp *http.Response) (retErr error) { if serverResp == nil { return nil } @@ -309,7 +315,7 @@ func (cli *Client) addHeaders(req *http.Request, headers http.Header) *http.Requ return req } -func jsonEncode(data interface{}) (io.Reader, error) { +func jsonEncode(data any) (io.Reader, error) { var params bytes.Buffer if data != nil { if err := json.NewEncoder(¶ms).Encode(data); err != nil { diff --git a/vendor/github.com/moby/moby/client/secret_update.go b/vendor/github.com/moby/moby/client/secret_update.go index d7cb9953614d..ebc2007d5b7a 100644 --- a/vendor/github.com/moby/moby/client/secret_update.go +++ b/vendor/github.com/moby/moby/client/secret_update.go @@ -19,6 +19,6 @@ func (cli *Client) SecretUpdate(ctx context.Context, id string, version swarm.Ve query := url.Values{} query.Set("version", version.String()) resp, err := cli.post(ctx, "/secrets/"+id+"/update", query, secret, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/service_create.go b/vendor/github.com/moby/moby/client/service_create.go index e593ab91f200..a1ee6e8f647f 100644 --- a/vendor/github.com/moby/moby/client/service_create.go +++ b/vendor/github.com/moby/moby/client/service_create.go @@ -16,7 +16,7 @@ import ( ) // ServiceCreate creates a new service. -func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) { +func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) { var response swarm.ServiceCreateResponse // Make sure we negotiated (if the client is configured to do so), @@ -154,7 +154,7 @@ func imageDigestAndPlatforms(ctx context.Context, cli DistributionAPIClient, ima func imageWithDigestString(image string, dgst digest.Digest) string { namedRef, err := reference.ParseNormalizedNamed(image) if err == nil { - if _, isCanonical := namedRef.(reference.Canonical); !isCanonical { + if _, hasDigest := namedRef.(reference.Digested); !hasDigest { // ensure that image gets a default tag if none is provided img, err := reference.WithDigest(namedRef, dgst) if err == nil { diff --git a/vendor/github.com/moby/moby/client/service_inspect.go b/vendor/github.com/moby/moby/client/service_inspect.go index dab40392a294..ab79f91d34d3 100644 --- a/vendor/github.com/moby/moby/client/service_inspect.go +++ b/vendor/github.com/moby/moby/client/service_inspect.go @@ -12,7 +12,7 @@ import ( ) // ServiceInspectWithRaw returns the service information and the raw data. -func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts ServiceInspectOptions) (swarm.Service, []byte, error) { serviceID, err := trimID("service", serviceID) if err != nil { return swarm.Service{}, nil, err diff --git a/vendor/github.com/moby/moby/client/service_list.go b/vendor/github.com/moby/moby/client/service_list.go index 78b039d19859..5eaeae8ee5e6 100644 --- a/vendor/github.com/moby/moby/client/service_list.go +++ b/vendor/github.com/moby/moby/client/service_list.go @@ -10,7 +10,7 @@ import ( ) // ServiceList returns the list of services. -func (cli *Client) ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { +func (cli *Client) ServiceList(ctx context.Context, options ServiceListOptions) ([]swarm.Service, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/vendor/github.com/moby/moby/client/service_logs.go b/vendor/github.com/moby/moby/client/service_logs.go index 5214aebfe67e..7062914aecdb 100644 --- a/vendor/github.com/moby/moby/client/service_logs.go +++ b/vendor/github.com/moby/moby/client/service_logs.go @@ -8,7 +8,7 @@ import ( "time" "github.com/moby/moby/api/types/container" - timetypes "github.com/moby/moby/api/types/time" + "github.com/moby/moby/client/internal/timestamp" ) // ServiceLogs returns the logs generated by a service in an [io.ReadCloser]. @@ -29,7 +29,7 @@ func (cli *Client) ServiceLogs(ctx context.Context, serviceID string, options co } if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, time.Now()) + ts, err := timestamp.GetTimestamp(options.Since, time.Now()) if err != nil { return nil, fmt.Errorf(`invalid value for "since": %w`, err) } diff --git a/vendor/github.com/moby/moby/client/service_update.go b/vendor/github.com/moby/moby/client/service_update.go index 159d393ad59d..0449c33161d3 100644 --- a/vendor/github.com/moby/moby/client/service_update.go +++ b/vendor/github.com/moby/moby/client/service_update.go @@ -15,7 +15,7 @@ import ( // conflicting writes. It must be the value as set *before* the update. // You can find this value in the [swarm.Service.Meta] field, which can // be found using [Client.ServiceInspectWithRaw]. -func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { +func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { serviceID, err := trimID("service", serviceID) if err != nil { return swarm.ServiceUpdateResponse{}, err diff --git a/vendor/github.com/moby/moby/client/swarm_config_list_options.go b/vendor/github.com/moby/moby/client/swarm_config_list_options.go new file mode 100644 index 000000000000..91d4690c6a3a --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_config_list_options.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// ConfigListOptions holds parameters to list configs +type ConfigListOptions struct { + Filters filters.Args +} diff --git a/vendor/github.com/moby/moby/client/swarm_join.go b/vendor/github.com/moby/moby/client/swarm_join.go index b1445930154d..7a9fa076d67f 100644 --- a/vendor/github.com/moby/moby/client/swarm_join.go +++ b/vendor/github.com/moby/moby/client/swarm_join.go @@ -9,6 +9,6 @@ import ( // SwarmJoin joins the swarm. func (cli *Client) SwarmJoin(ctx context.Context, req swarm.JoinRequest) error { resp, err := cli.post(ctx, "/swarm/join", nil, req, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/swarm_leave.go b/vendor/github.com/moby/moby/client/swarm_leave.go index 709e5adb3536..fb0fe3b5d579 100644 --- a/vendor/github.com/moby/moby/client/swarm_leave.go +++ b/vendor/github.com/moby/moby/client/swarm_leave.go @@ -12,6 +12,6 @@ func (cli *Client) SwarmLeave(ctx context.Context, force bool) error { query.Set("force", "1") } resp, err := cli.post(ctx, "/swarm/leave", query, nil, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/swarm_node_list_opts.go b/vendor/github.com/moby/moby/client/swarm_node_list_opts.go new file mode 100644 index 000000000000..9fb8c4245d54 --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_node_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// NodeListOptions holds parameters to list nodes with. +type NodeListOptions struct { + Filters filters.Args +} diff --git a/vendor/github.com/moby/moby/client/swarm_node_remove_opts.go b/vendor/github.com/moby/moby/client/swarm_node_remove_opts.go new file mode 100644 index 000000000000..85bc12f81225 --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_node_remove_opts.go @@ -0,0 +1,6 @@ +package client + +// NodeRemoveOptions holds parameters to remove nodes with. +type NodeRemoveOptions struct { + Force bool +} diff --git a/vendor/github.com/moby/moby/client/swarm_service_create_opts.go b/vendor/github.com/moby/moby/client/swarm_service_create_opts.go new file mode 100644 index 000000000000..504502ecf747 --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_service_create_opts.go @@ -0,0 +1,16 @@ +package client + +// ServiceCreateOptions contains the options to use when creating a service. +type ServiceCreateOptions struct { + // EncodedRegistryAuth is the encoded registry authorization credentials to + // use when updating the service. + // + // This field follows the format of the X-Registry-Auth header. + EncodedRegistryAuth string + + // QueryRegistry indicates whether the service update requires + // contacting a registry. A registry may be contacted to retrieve + // the image digest and manifest, which in turn can be used to update + // platform or other information about the service. + QueryRegistry bool +} diff --git a/vendor/github.com/moby/moby/client/swarm_service_inspect_opts.go b/vendor/github.com/moby/moby/client/swarm_service_inspect_opts.go new file mode 100644 index 000000000000..691f3634e4d3 --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_service_inspect_opts.go @@ -0,0 +1,7 @@ +package client + +// ServiceInspectOptions holds parameters related to the "service inspect" +// operation. +type ServiceInspectOptions struct { + InsertDefaults bool +} diff --git a/vendor/github.com/moby/moby/client/swarm_service_list_opts.go b/vendor/github.com/moby/moby/client/swarm_service_list_opts.go new file mode 100644 index 000000000000..9b82376ac123 --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_service_list_opts.go @@ -0,0 +1,12 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// ServiceListOptions holds parameters to list services with. +type ServiceListOptions struct { + Filters filters.Args + + // Status indicates whether the server should include the service task + // count of running and desired tasks. + Status bool +} diff --git a/vendor/github.com/moby/moby/client/swarm_service_update_opts.go b/vendor/github.com/moby/moby/client/swarm_service_update_opts.go new file mode 100644 index 000000000000..cf0cc41239dc --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_service_update_opts.go @@ -0,0 +1,31 @@ +package client + +// ServiceUpdateOptions contains the options to be used for updating services. +type ServiceUpdateOptions struct { + // EncodedRegistryAuth is the encoded registry authorization credentials to + // use when updating the service. + // + // This field follows the format of the X-Registry-Auth header. + EncodedRegistryAuth string + + // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate + // into this field. While it does open API users up to racy writes, most + // users may not need that level of consistency in practice. + + // RegistryAuthFrom specifies where to find the registry authorization + // credentials if they are not given in EncodedRegistryAuth. Valid + // values are "spec" and "previous-spec". + RegistryAuthFrom string + + // Rollback indicates whether a server-side rollback should be + // performed. When this is set, the provided spec will be ignored. + // The valid values are "previous" and "none". An empty value is the + // same as "none". + Rollback string + + // QueryRegistry indicates whether the service update requires + // contacting a registry. A registry may be contacted to retrieve + // the image digest and manifest, which in turn can be used to update + // platform or other information about the service. + QueryRegistry bool +} diff --git a/vendor/github.com/moby/moby/client/swarm_task_list_opts.go b/vendor/github.com/moby/moby/client/swarm_task_list_opts.go new file mode 100644 index 000000000000..87e38135cdbd --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_task_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// TaskListOptions holds parameters to list tasks with. +type TaskListOptions struct { + Filters filters.Args +} diff --git a/vendor/github.com/moby/moby/client/swarm_unlock.go b/vendor/github.com/moby/moby/client/swarm_unlock.go index 3d8d68b67adc..5eb3d59399d1 100644 --- a/vendor/github.com/moby/moby/client/swarm_unlock.go +++ b/vendor/github.com/moby/moby/client/swarm_unlock.go @@ -9,6 +9,6 @@ import ( // SwarmUnlock unlocks locked swarm. func (cli *Client) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error { resp, err := cli.post(ctx, "/swarm/unlock", nil, req, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/swarm_update.go b/vendor/github.com/moby/moby/client/swarm_update.go index 948d07b7a8f4..b6a077eae1bd 100644 --- a/vendor/github.com/moby/moby/client/swarm_update.go +++ b/vendor/github.com/moby/moby/client/swarm_update.go @@ -9,13 +9,13 @@ import ( ) // SwarmUpdate updates the swarm. -func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error { +func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags SwarmUpdateFlags) error { query := url.Values{} query.Set("version", version.String()) query.Set("rotateWorkerToken", strconv.FormatBool(flags.RotateWorkerToken)) query.Set("rotateManagerToken", strconv.FormatBool(flags.RotateManagerToken)) query.Set("rotateManagerUnlockKey", strconv.FormatBool(flags.RotateManagerUnlockKey)) resp, err := cli.post(ctx, "/swarm/update", query, swarm, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/github.com/moby/moby/client/swarm_update_flags.go b/vendor/github.com/moby/moby/client/swarm_update_flags.go new file mode 100644 index 000000000000..536f865035cc --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_update_flags.go @@ -0,0 +1,8 @@ +package client + +// SwarmUpdateFlags contains flags for SwarmUpdate. +type SwarmUpdateFlags struct { + RotateWorkerToken bool + RotateManagerToken bool + RotateManagerUnlockKey bool +} diff --git a/vendor/github.com/moby/moby/client/system_disk_usage.go b/vendor/github.com/moby/moby/client/system_disk_usage.go index a26ad99d82d8..6f78952cbd5b 100644 --- a/vendor/github.com/moby/moby/client/system_disk_usage.go +++ b/vendor/github.com/moby/moby/client/system_disk_usage.go @@ -10,7 +10,7 @@ import ( ) // DiskUsage requests the current data usage from the daemon -func (cli *Client) DiskUsage(ctx context.Context, options system.DiskUsageOptions) (system.DiskUsage, error) { +func (cli *Client) DiskUsage(ctx context.Context, options DiskUsageOptions) (system.DiskUsage, error) { var query url.Values if len(options.Types) > 0 { query = url.Values{} diff --git a/vendor/github.com/moby/moby/client/system_disk_usage_opts.go b/vendor/github.com/moby/moby/client/system_disk_usage_opts.go new file mode 100644 index 000000000000..e671b0cb7d9f --- /dev/null +++ b/vendor/github.com/moby/moby/client/system_disk_usage_opts.go @@ -0,0 +1,10 @@ +package client + +import "github.com/moby/moby/api/types/system" + +// DiskUsageOptions holds parameters for system disk usage query. +type DiskUsageOptions struct { + // Types specifies what object types to include in the response. If empty, + // all object types are returned. + Types []system.DiskUsageObject +} diff --git a/vendor/github.com/moby/moby/client/system_events.go b/vendor/github.com/moby/moby/client/system_events.go index 01d528fb443b..d67bd4793c42 100644 --- a/vendor/github.com/moby/moby/client/system_events.go +++ b/vendor/github.com/moby/moby/client/system_events.go @@ -8,15 +8,22 @@ import ( "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/filters" - timetypes "github.com/moby/moby/api/types/time" "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/internal/timestamp" ) +// EventsListOptions holds parameters to filter events with. +type EventsListOptions struct { + Since string + Until string + Filters filters.Args +} + // Events returns a stream of events in the daemon. It's up to the caller to close the stream // by cancelling the context. Once the stream has been completely read an [io.EOF] error is // sent over the error channel. If an error is sent, all processing is stopped. It's up // to the caller to reopen the stream in the event of an error by reinvoking this method. -func (cli *Client) Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error) { +func (cli *Client) Events(ctx context.Context, options EventsListOptions) (<-chan events.Message, <-chan error) { messages := make(chan events.Message) errs := make(chan error, 1) @@ -78,12 +85,12 @@ func (cli *Client) Events(ctx context.Context, options events.ListOptions) (<-ch return messages, errs } -func buildEventsQueryParams(cliVersion string, options events.ListOptions) (url.Values, error) { +func buildEventsQueryParams(cliVersion string, options EventsListOptions) (url.Values, error) { query := url.Values{} ref := time.Now() if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, ref) + ts, err := timestamp.GetTimestamp(options.Since, ref) if err != nil { return nil, err } @@ -91,7 +98,7 @@ func buildEventsQueryParams(cliVersion string, options events.ListOptions) (url. } if options.Until != "" { - ts, err := timetypes.GetTimestamp(options.Until, ref) + ts, err := timestamp.GetTimestamp(options.Until, ref) if err != nil { return nil, err } diff --git a/vendor/github.com/moby/moby/client/task_list.go b/vendor/github.com/moby/moby/client/task_list.go index b0e612cfca83..67ba443c5495 100644 --- a/vendor/github.com/moby/moby/client/task_list.go +++ b/vendor/github.com/moby/moby/client/task_list.go @@ -10,7 +10,7 @@ import ( ) // TaskList returns the list of tasks. -func (cli *Client) TaskList(ctx context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { +func (cli *Client) TaskList(ctx context.Context, options TaskListOptions) ([]swarm.Task, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/vendor/github.com/moby/moby/client/task_logs.go b/vendor/github.com/moby/moby/client/task_logs.go index 075c4d06070f..3b6c31c1733f 100644 --- a/vendor/github.com/moby/moby/client/task_logs.go +++ b/vendor/github.com/moby/moby/client/task_logs.go @@ -7,7 +7,7 @@ import ( "time" "github.com/moby/moby/api/types/container" - timetypes "github.com/moby/moby/api/types/time" + "github.com/moby/moby/client/internal/timestamp" ) // TaskLogs returns the logs generated by a task in an [io.ReadCloser]. @@ -23,7 +23,7 @@ func (cli *Client) TaskLogs(ctx context.Context, taskID string, options containe } if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, time.Now()) + ts, err := timestamp.GetTimestamp(options.Since, time.Now()) if err != nil { return nil, err } diff --git a/vendor/github.com/moby/moby/client/volume_list.go b/vendor/github.com/moby/moby/client/volume_list.go index 656dfb05dea0..8a4d6af7dd4e 100644 --- a/vendor/github.com/moby/moby/client/volume_list.go +++ b/vendor/github.com/moby/moby/client/volume_list.go @@ -11,7 +11,7 @@ import ( ) // VolumeList returns the volumes configured in the docker host. -func (cli *Client) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (cli *Client) VolumeList(ctx context.Context, options VolumeListOptions) (volume.ListResponse, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/vendor/github.com/moby/moby/client/volume_list_opts.go b/vendor/github.com/moby/moby/client/volume_list_opts.go new file mode 100644 index 000000000000..f59aef94cda1 --- /dev/null +++ b/vendor/github.com/moby/moby/client/volume_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// VolumeListOptions holds parameters to list volumes. +type VolumeListOptions struct { + Filters filters.Args +} diff --git a/vendor/github.com/moby/moby/client/volume_update.go b/vendor/github.com/moby/moby/client/volume_update.go index 50a16e2c0f25..7094c9937e36 100644 --- a/vendor/github.com/moby/moby/client/volume_update.go +++ b/vendor/github.com/moby/moby/client/volume_update.go @@ -23,6 +23,6 @@ func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, version sw query.Set("version", version.String()) resp, err := cli.put(ctx, "/volumes/"+volumeID, query, options, nil) - ensureReaderClosed(resp) + defer ensureReaderClosed(resp) return err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 9120ff4da5a1..b780cea425e0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -168,8 +168,9 @@ github.com/moby/docker-image-spec/specs-go/v1 github.com/moby/go-archive github.com/moby/go-archive/compression github.com/moby/go-archive/tarheader -# github.com/moby/moby/api v1.52.0-alpha.1 +# github.com/moby/moby/api v1.52.0-alpha.1.0.20250826164402-7145e7666b8f ## explicit; go 1.23.0 +github.com/moby/moby/api/pkg/authconfig github.com/moby/moby/api/pkg/progress github.com/moby/moby/api/pkg/stdcopy github.com/moby/moby/api/pkg/streamformatter @@ -189,15 +190,14 @@ github.com/moby/moby/api/types/network github.com/moby/moby/api/types/plugin github.com/moby/moby/api/types/registry github.com/moby/moby/api/types/storage -github.com/moby/moby/api/types/strslice github.com/moby/moby/api/types/swarm github.com/moby/moby/api/types/system -github.com/moby/moby/api/types/time github.com/moby/moby/api/types/versions github.com/moby/moby/api/types/volume -# github.com/moby/moby/client v0.1.0-alpha.0 +# github.com/moby/moby/client v0.1.0-alpha.0.0.20250826164402-7145e7666b8f ## explicit; go 1.23.0 github.com/moby/moby/client +github.com/moby/moby/client/internal/timestamp github.com/moby/moby/client/pkg/jsonmessage github.com/moby/moby/client/pkg/stringid # github.com/moby/patternmatcher v0.6.0