registry/service_v2.go
39f2f15a
 package registry
 
 import (
79db131a
 	"net/url"
39f2f15a
 	"strings"
 
8e034802
 	"github.com/docker/go-connections/tlsconfig"
39f2f15a
 )
 
636c276f
 func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
7a8c7b47
 	tlsConfig := tlsconfig.ServerDefault()
43f1682c
 	if hostname == DefaultNamespace || hostname == IndexHostname {
39f2f15a
 		// v2 mirrors
59586d02
 		for _, mirror := range s.config.Mirrors {
79db131a
 			if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") {
 				mirror = "https://" + mirror
 			}
 			mirrorURL, err := url.Parse(mirror)
 			if err != nil {
 				return nil, err
 			}
 			mirrorTLSConfig, err := s.tlsConfigForMirror(mirrorURL)
39f2f15a
 			if err != nil {
 				return nil, err
 			}
 			endpoints = append(endpoints, APIEndpoint{
79db131a
 				URL: mirrorURL,
39f2f15a
 				// guess mirrors are v2
 				Version:      APIVersion2,
 				Mirror:       true,
 				TrimHostname: true,
 				TLSConfig:    mirrorTLSConfig,
 			})
 		}
 		// v2 registry
 		endpoints = append(endpoints, APIEndpoint{
 			URL:          DefaultV2Registry,
 			Version:      APIVersion2,
 			Official:     true,
 			TrimHostname: true,
 			TLSConfig:    tlsConfig,
 		})
 
 		return endpoints, nil
 	}
 
582803f0
 	tlsConfig, err = s.tlsConfig(hostname)
39f2f15a
 	if err != nil {
 		return nil, err
 	}
 
 	endpoints = []APIEndpoint{
 		{
79db131a
 			URL: &url.URL{
 				Scheme: "https",
 				Host:   hostname,
 			},
a57478d6
 			Version:      APIVersion2,
 			TrimHostname: true,
 			TLSConfig:    tlsConfig,
39f2f15a
 		},
 	}
 
 	if tlsConfig.InsecureSkipVerify {
 		endpoints = append(endpoints, APIEndpoint{
79db131a
 			URL: &url.URL{
 				Scheme: "http",
 				Host:   hostname,
 			},
39f2f15a
 			Version:      APIVersion2,
 			TrimHostname: true,
 			// used to check if supposed to be secure via InsecureSkipVerify
a57478d6
 			TLSConfig: tlsConfig,
39f2f15a
 		})
 	}
 
 	return endpoints, nil
 }