cli/command: internalize constructing RegistryClient
The CLI.RegistryClient method is 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. This patch inlines the code where needed, skipping the wrapper Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
3b5dff2783
commit
985b58e7e1
@ -1,6 +1,7 @@
|
||||
package manifest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
@ -8,6 +9,8 @@ import (
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/config"
|
||||
"github.com/docker/cli/cli/manifest/store"
|
||||
registryclient "github.com/docker/cli/cli/registry/client"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@ -27,6 +30,7 @@ type annotateOptions struct {
|
||||
type manifestStoreProvider interface {
|
||||
// ManifestStore returns a store for local manifests
|
||||
ManifestStore() store.Store
|
||||
RegistryClient(bool) registryclient.RegistryClient
|
||||
}
|
||||
|
||||
// newManifestStore returns a store for local manifests
|
||||
@ -40,6 +44,19 @@ func newManifestStore(dockerCLI command.Cli) store.Store {
|
||||
return store.NewStore(filepath.Join(config.Dir(), "manifests"))
|
||||
}
|
||||
|
||||
// newRegistryClient returns a client for communicating with a Docker distribution
|
||||
// registry
|
||||
func newRegistryClient(dockerCLI command.Cli, allowInsecure bool) registryclient.RegistryClient {
|
||||
if msp, ok := dockerCLI.(manifestStoreProvider); ok {
|
||||
// manifestStoreProvider is used in tests to provide a dummy store.
|
||||
return msp.RegistryClient(allowInsecure)
|
||||
}
|
||||
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
|
||||
return command.ResolveAuthConfig(dockerCLI.ConfigFile(), index)
|
||||
}
|
||||
return registryclient.NewRegistryClient(resolver, command.UserAgent(), allowInsecure)
|
||||
}
|
||||
|
||||
// NewAnnotateCommand creates a new `docker manifest annotate` command
|
||||
func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
var opts annotateOptions
|
||||
|
@ -75,7 +75,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
|
||||
}
|
||||
|
||||
// Next try a remote manifest
|
||||
registryClient := dockerCli.RegistryClient(opts.insecure)
|
||||
registryClient := newRegistryClient(dockerCli, opts.insecure)
|
||||
imageManifest, err := registryClient.GetManifest(ctx, namedRef)
|
||||
if err == nil {
|
||||
return printManifest(dockerCli, imageManifest, opts)
|
||||
|
@ -248,7 +248,7 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere
|
||||
}
|
||||
|
||||
func pushList(ctx context.Context, dockerCLI command.Cli, req pushRequest) error {
|
||||
rclient := dockerCLI.RegistryClient(req.insecure)
|
||||
rclient := newRegistryClient(dockerCLI, req.insecure)
|
||||
|
||||
if err := mountBlobs(ctx, rclient, req.targetRef, req.manifestBlobs); err != nil {
|
||||
return err
|
||||
|
@ -69,15 +69,15 @@ func normalizeReference(ref string) (reference.Named, error) {
|
||||
|
||||
// getManifest from the local store, and fallback to the remote registry if it
|
||||
// doesn't exist locally
|
||||
func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
|
||||
data, err := newManifestStore(dockerCli).Get(listRef, namedRef)
|
||||
func getManifest(ctx context.Context, dockerCLI command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
|
||||
data, err := newManifestStore(dockerCLI).Get(listRef, namedRef)
|
||||
switch {
|
||||
case store.IsNotFound(err):
|
||||
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
|
||||
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
|
||||
case err != nil:
|
||||
return types.ImageManifest{}, err
|
||||
case len(data.Raw) == 0:
|
||||
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
|
||||
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
|
||||
default:
|
||||
return data, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user