Skip to content

Commit 2a98e2a

Browse files
committed
cli/command: remove RegistryClient from CLI interface
This method was a shallow wrapper around registryclient.NewRegistryClient but due to its signature resulted in various dependencies becoming a dependency of the "command" package. Consequence of this was that cli-plugins, which need the cli/command package, would also get those dependencies. Thie patch: - Removes the RegistryClient method from the interface - Inlines the code where needed, skipping the wrapper - Define a local interface for some tests where a dummy store was used. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b004f8a commit 2a98e2a

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

cli/command/cli.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ import (
2121
"github.com/docker/cli/cli/context/store"
2222
"github.com/docker/cli/cli/debug"
2323
cliflags "github.com/docker/cli/cli/flags"
24-
registryclient "github.com/docker/cli/cli/registry/client"
2524
"github.com/docker/cli/cli/streams"
2625
"github.com/docker/cli/cli/version"
2726
dopts "github.com/docker/cli/opts"
2827
"github.com/docker/docker/api"
2928
"github.com/docker/docker/api/types"
30-
"github.com/docker/docker/api/types/registry"
3129
"github.com/docker/docker/api/types/swarm"
3230
"github.com/docker/docker/client"
3331
"github.com/docker/go-connections/tlsconfig"
@@ -54,7 +52,6 @@ type Cli interface {
5452
ServerInfo() ServerInfo
5553
DefaultVersion() string
5654
CurrentVersion() string
57-
RegistryClient(bool) registryclient.RegistryClient
5855
ContentTrustEnabled() bool
5956
BuildKitEnabled() (bool, error)
6057
ContextStore() store.Store
@@ -225,15 +222,6 @@ func (cli *DockerCli) HooksEnabled() bool {
225222
return false
226223
}
227224

228-
// RegistryClient returns a client for communicating with a Docker distribution
229-
// registry
230-
func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient {
231-
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
232-
return ResolveAuthConfig(cli.ConfigFile(), index)
233-
}
234-
return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure)
235-
}
236-
237225
// WithInitializeClient is passed to DockerCli.Initialize by callers who wish to set a particular API Client for use by the CLI.
238226
func WithInitializeClient(makeClient func(dockerCli *DockerCli) (client.APIClient, error)) CLIOption {
239227
return func(dockerCli *DockerCli) error {

cli/command/manifest/annotate.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package manifest
22

33
import (
4+
"context"
45
"fmt"
56
"path/filepath"
67

78
"github.com/docker/cli/cli"
89
"github.com/docker/cli/cli/command"
910
"github.com/docker/cli/cli/config"
1011
"github.com/docker/cli/cli/manifest/store"
12+
registryclient "github.com/docker/cli/cli/registry/client"
13+
"github.com/docker/docker/api/types/registry"
1114
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1215
"github.com/pkg/errors"
1316
"github.com/spf13/cobra"
@@ -27,6 +30,7 @@ type annotateOptions struct {
2730
type manifestStoreProvider interface {
2831
// ManifestStore returns a store for local manifests
2932
ManifestStore() store.Store
33+
RegistryClient(bool) registryclient.RegistryClient
3034
}
3135

3236
// newManifestStore returns a store for local manifests
@@ -40,6 +44,19 @@ func newManifestStore(dockerCLI command.Cli) store.Store {
4044
return store.NewStore(filepath.Join(config.Dir(), "manifests"))
4145
}
4246

47+
// newRegistryClient returns a client for communicating with a Docker distribution
48+
// registry
49+
func newRegistryClient(dockerCLI command.Cli, allowInsecure bool) registryclient.RegistryClient {
50+
if msp, ok := dockerCLI.(manifestStoreProvider); ok {
51+
// manifestStoreProvider is used in tests to provide a dummy store.
52+
return msp.RegistryClient(allowInsecure)
53+
}
54+
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
55+
return command.ResolveAuthConfig(dockerCLI.ConfigFile(), index)
56+
}
57+
return registryclient.NewRegistryClient(resolver, command.UserAgent(), allowInsecure)
58+
}
59+
4360
// NewAnnotateCommand creates a new `docker manifest annotate` command
4461
func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
4562
var opts annotateOptions

cli/command/manifest/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
7575
}
7676

7777
// Next try a remote manifest
78-
registryClient := dockerCli.RegistryClient(opts.insecure)
78+
registryClient := newRegistryClient(dockerCli, opts.insecure)
7979
imageManifest, err := registryClient.GetManifest(ctx, namedRef)
8080
if err == nil {
8181
return printManifest(dockerCli, imageManifest, opts)

cli/command/manifest/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere
248248
}
249249

250250
func pushList(ctx context.Context, dockerCLI command.Cli, req pushRequest) error {
251-
rclient := dockerCLI.RegistryClient(req.insecure)
251+
rclient := newRegistryClient(dockerCLI, req.insecure)
252252

253253
if err := mountBlobs(ctx, rclient, req.targetRef, req.manifestBlobs); err != nil {
254254
return err

cli/command/manifest/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ func normalizeReference(ref string) (reference.Named, error) {
6969

7070
// getManifest from the local store, and fallback to the remote registry if it
7171
// doesn't exist locally
72-
func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
73-
data, err := newManifestStore(dockerCli).Get(listRef, namedRef)
72+
func getManifest(ctx context.Context, dockerCLI command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
73+
data, err := newManifestStore(dockerCLI).Get(listRef, namedRef)
7474
switch {
7575
case store.IsNotFound(err):
76-
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
76+
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
7777
case err != nil:
7878
return types.ImageManifest{}, err
7979
case len(data.Raw) == 0:
80-
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
80+
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
8181
default:
8282
return data, nil
8383
}

0 commit comments

Comments
 (0)