diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index fad29def4c02..c7844e8d18a4 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -289,7 +289,7 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru } // TrustedReference returns the canonical trusted reference for an image reference -func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged, rs registry.Service) (reference.Canonical, error) { +func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged, rs trust.RepositoryInfoResolver) (reference.Canonical, error) { imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, rs, AuthResolver(cli), ref.String()) if err != nil { return nil, err diff --git a/cli/command/plugin/install.go b/cli/command/plugin/install.go index 9a9e443b40b0..fa947a7e3570 100644 --- a/cli/command/plugin/install.go +++ b/cli/command/plugin/install.go @@ -54,26 +54,14 @@ func newInstallCommand(dockerCli command.Cli) *cobra.Command { return cmd } -type pluginRegistryService struct { - registry.Service -} - -func (s pluginRegistryService) ResolveRepository(name reference.Named) (*registry.RepositoryInfo, error) { - repoInfo, err := s.Service.ResolveRepository(name) +func resolvePlugnRepository(name reference.Named) (*registry.RepositoryInfo, error) { + repoInfo, err := registry.ParseRepositoryInfo(name) if repoInfo != nil { repoInfo.Class = "plugin" } return repoInfo, err } -func newRegistryService() (registry.Service, error) { - svc, err := registry.NewService(registry.ServiceOptions{}) - if err != nil { - return nil, err - } - return pluginRegistryService{Service: svc}, nil -} - func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOptions, cmdName string) (types.PluginInstallOptions, error) { // Names with both tag and digest will be treated by the daemon // as a pull by digest with a local name for the tag @@ -98,12 +86,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti return types.PluginInstallOptions{}, errors.Errorf("invalid name: %s", ref.String()) } - ctx := context.Background() - svc, err := newRegistryService() - if err != nil { - return types.PluginInstallOptions{}, err - } - trusted, err := image.TrustedReference(ctx, dockerCli, nt, svc) + trusted, err := image.TrustedReference(context.Background(), dockerCli, nt, resolvePlugnRepository) if err != nil { return types.PluginInstallOptions{}, err } diff --git a/cli/trust/trust.go b/cli/trust/trust.go index 457f799fda3f..42ff62e967f9 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -299,9 +299,12 @@ type ImageRefAndAuth struct { digest digest.Digest } +// RepositoryInfoResolver returns repository info for the given reference. +type RepositoryInfoResolver func(name reference.Named) (*registry.RepositoryInfo, error) + // GetImageReferencesAndAuth retrieves the necessary reference and auth information for an image name // as an ImageRefAndAuth struct -func GetImageReferencesAndAuth(ctx context.Context, rs registry.Service, +func GetImageReferencesAndAuth(ctx context.Context, resolveFn RepositoryInfoResolver, authResolver func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig, imgName string, ) (ImageRefAndAuth, error) { @@ -312,8 +315,8 @@ func GetImageReferencesAndAuth(ctx context.Context, rs registry.Service, // Resolve the Repository name from fqn to RepositoryInfo var repoInfo *registry.RepositoryInfo - if rs != nil { - repoInfo, err = rs.ResolveRepository(ref) + if resolveFn != nil { + repoInfo, err = resolveFn(ref) } else { repoInfo, err = registry.ParseRepositoryInfo(ref) }