From 8ad07217dc92fa81806d4eb64a4eb04cf5c99b15 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 4 Mar 2025 14:54:51 +0100 Subject: [PATCH] cli/command: deprecate Cli.RegistryClient 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. It is no longer used in our code, which constructs the client in packages that need it, so we can deprecate this method. Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 12 ------------ cli/command/cli_deprecated.go | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 7d15602156..e056334f46 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -21,13 +21,11 @@ import ( "github.com/docker/cli/cli/context/store" "github.com/docker/cli/cli/debug" cliflags "github.com/docker/cli/cli/flags" - registryclient "github.com/docker/cli/cli/registry/client" "github.com/docker/cli/cli/streams" "github.com/docker/cli/cli/version" dopts "github.com/docker/cli/opts" "github.com/docker/docker/api" "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/go-connections/tlsconfig" @@ -54,7 +52,6 @@ type Cli interface { ServerInfo() ServerInfo DefaultVersion() string CurrentVersion() string - RegistryClient(bool) registryclient.RegistryClient ContentTrustEnabled() bool BuildKitEnabled() (bool, error) ContextStore() store.Store @@ -227,15 +224,6 @@ func (cli *DockerCli) HooksEnabled() bool { return false } -// RegistryClient returns a client for communicating with a Docker distribution -// registry -func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient { - resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig { - return ResolveAuthConfig(cli.ConfigFile(), index) - } - return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure) -} - // WithInitializeClient is passed to DockerCli.Initialize by callers who wish to set a particular API Client for use by the CLI. func WithInitializeClient(makeClient func(dockerCli *DockerCli) (client.APIClient, error)) CLIOption { return func(dockerCli *DockerCli) error { diff --git a/cli/command/cli_deprecated.go b/cli/command/cli_deprecated.go index d6e38a607a..15fac1a6e3 100644 --- a/cli/command/cli_deprecated.go +++ b/cli/command/cli_deprecated.go @@ -1,11 +1,14 @@ package command import ( + "context" "path/filepath" "github.com/docker/cli/cli/config" manifeststore "github.com/docker/cli/cli/manifest/store" + registryclient "github.com/docker/cli/cli/registry/client" "github.com/docker/cli/cli/trust" + "github.com/docker/docker/api/types/registry" notaryclient "github.com/theupdateframework/notary/client" ) @@ -21,6 +24,12 @@ type DeprecatedManifestClient interface { // // Deprecated: use [manifeststore.NewStore] instead. This method is no longer used and will be removed in the next release. ManifestStore() manifeststore.Store + + // RegistryClient returns a client for communicating with a Docker distribution + // registry. + // + // Deprecated: use [registryclient.NewRegistryClient]. This method is no longer used and will be removed in the next release. + RegistryClient(bool) registryclient.RegistryClient } // NotaryClient provides a Notary Repository to interact with signed metadata for an image @@ -34,3 +43,14 @@ func (cli *DockerCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions func (*DockerCli) ManifestStore() manifeststore.Store { return manifeststore.NewStore(filepath.Join(config.Dir(), "manifests")) } + +// RegistryClient returns a client for communicating with a Docker distribution +// registry +// +// Deprecated: use [registryclient.NewRegistryClient]. This method is no longer used and will be removed in the next release. +func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient { + resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig { + return ResolveAuthConfig(cli.ConfigFile(), index) + } + return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure) +}