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 <github@gone.nl>
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user