From 5322affc9f6f02f51b926ea2e650935c37ff2bd7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 24 Jul 2025 20:07:22 +0200 Subject: [PATCH] internal/registry: remove duplicate endpoint methods now that we no longer need to account for mirrors, these were identical, so just use a single one. Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/endpoint.go | 3 ++- cli/registry/client/fetcher.go | 4 ++-- internal/registry/service.go | 14 +------------- internal/registry/service_v2.go | 27 ++++++++------------------- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index 631a5bdf4..5b6cf4a5a 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -1,6 +1,7 @@ package client import ( + "context" "net" "net/http" "net/url" @@ -55,7 +56,7 @@ func getDefaultEndpoint(repoName reference.Named, insecure bool) (registry.APIEn if err != nil { return registry.APIEndpoint{}, err } - endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoName)) + endpoints, err := registryService.Endpoints(context.TODO(), reference.Domain(repoName)) if err != nil { return registry.APIEndpoint{}, err } diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index e169179d1..c8687d9d9 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -283,10 +283,10 @@ func allEndpoints(namedRef reference.Named, insecure bool) ([]registry.APIEndpoi } registryService, err := registry.NewService(serviceOpts) if err != nil { - return []registry.APIEndpoint{}, err + return nil, err } repoInfo, _ := registry.ParseRepositoryInfo(namedRef) - endpoints, err := registryService.LookupPullEndpoints(reference.Domain(repoInfo.Name)) + endpoints, err := registryService.Endpoints(context.TODO(), reference.Domain(repoInfo.Name)) logrus.Debugf("endpoints for %s: %v", namedRef, endpoints) return endpoints, err } diff --git a/internal/registry/service.go b/internal/registry/service.go index 91b624462..ed5b3e00e 100644 --- a/internal/registry/service.go +++ b/internal/registry/service.go @@ -49,7 +49,7 @@ func (s *Service) Auth(ctx context.Context, authConfig *registry.AuthConfig, use } // Lookup endpoints for authentication. - endpoints, err := s.lookupV2Endpoints(ctx, registryHostName) + endpoints, err := s.Endpoints(ctx, registryHostName) if err != nil { if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { return "", err @@ -85,15 +85,3 @@ type APIEndpoint struct { URL *url.URL TLSConfig *tls.Config } - -// LookupPullEndpoints creates a list of v2 endpoints to try to pull from, in order of preference. -// It gives preference to mirrors over the actual registry, and HTTPS over plain HTTP. -func (s *Service) LookupPullEndpoints(hostname string) ([]APIEndpoint, error) { - return s.lookupV2Endpoints(context.TODO(), hostname) -} - -// LookupPushEndpoints creates a list of v2 endpoints to try to push to, in order of preference. -// It gives preference to HTTPS over plain HTTP. Mirrors are not included. -func (s *Service) LookupPushEndpoints(hostname string) ([]APIEndpoint, error) { - return s.lookupV2Endpoints(context.TODO(), hostname) -} diff --git a/internal/registry/service_v2.go b/internal/registry/service_v2.go index 0f0059533..ccfb5ac50 100644 --- a/internal/registry/service_v2.go +++ b/internal/registry/service_v2.go @@ -7,15 +7,12 @@ import ( "github.com/docker/go-connections/tlsconfig" ) -func (s *Service) lookupV2Endpoints(ctx context.Context, hostname string) ([]APIEndpoint, error) { - var endpoints []APIEndpoint +func (s *Service) Endpoints(ctx context.Context, hostname string) ([]APIEndpoint, error) { if hostname == DefaultNamespace || hostname == IndexHostname { - endpoints = append(endpoints, APIEndpoint{ + return []APIEndpoint{{ URL: DefaultV2Registry, TLSConfig: tlsconfig.ServerDefault(), - }) - - return endpoints, nil + }}, nil } tlsConfig, err := newTLSConfig(ctx, hostname, s.config.isSecureIndex(hostname)) @@ -23,22 +20,14 @@ func (s *Service) lookupV2Endpoints(ctx context.Context, hostname string) ([]API return nil, err } - endpoints = []APIEndpoint{ - { - URL: &url.URL{ - Scheme: "https", - Host: hostname, - }, - TLSConfig: tlsConfig, - }, - } + endpoints := []APIEndpoint{{ + URL: &url.URL{Scheme: "https", Host: hostname}, + TLSConfig: tlsConfig, + }} if tlsConfig.InsecureSkipVerify { endpoints = append(endpoints, APIEndpoint{ - URL: &url.URL{ - Scheme: "http", - Host: hostname, - }, + URL: &url.URL{Scheme: "http", Host: hostname}, // used to check if supposed to be secure via InsecureSkipVerify TLSConfig: tlsConfig, })