github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/registry/service_v2.go (about) 1 package registry // import "github.com/docker/docker/registry" 2 3 import ( 4 "net/url" 5 "strings" 6 7 "github.com/docker/go-connections/tlsconfig" 8 ) 9 10 func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) { 11 tlsConfig := tlsconfig.ServerDefault() 12 13 ana := allowNondistributableArtifacts(s.config, hostname) 14 15 if hostname == DefaultNamespace || hostname == IndexHostname { 16 for _, mirror := range s.config.Mirrors { 17 if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") { 18 mirror = "https://" + mirror 19 } 20 mirrorURL, err := url.Parse(mirror) 21 if err != nil { 22 return nil, err 23 } 24 mirrorTLSConfig, err := s.tlsConfigForMirror(mirrorURL) 25 if err != nil { 26 return nil, err 27 } 28 endpoints = append(endpoints, APIEndpoint{ 29 URL: mirrorURL, 30 Version: APIVersion2, 31 Mirror: true, 32 TrimHostname: true, 33 TLSConfig: mirrorTLSConfig, 34 }) 35 } 36 endpoints = append(endpoints, APIEndpoint{ 37 URL: DefaultV2Registry, 38 Version: APIVersion2, 39 Official: true, 40 TrimHostname: true, 41 TLSConfig: tlsConfig, 42 43 AllowNondistributableArtifacts: ana, 44 }) 45 46 return endpoints, nil 47 } 48 49 tlsConfig, err = s.tlsConfig(hostname) 50 if err != nil { 51 return nil, err 52 } 53 54 endpoints = []APIEndpoint{ 55 { 56 URL: &url.URL{ 57 Scheme: "https", 58 Host: hostname, 59 }, 60 Version: APIVersion2, 61 AllowNondistributableArtifacts: ana, 62 TrimHostname: true, 63 TLSConfig: tlsConfig, 64 }, 65 } 66 67 if tlsConfig.InsecureSkipVerify { 68 endpoints = append(endpoints, APIEndpoint{ 69 URL: &url.URL{ 70 Scheme: "http", 71 Host: hostname, 72 }, 73 Version: APIVersion2, 74 AllowNondistributableArtifacts: ana, 75 TrimHostname: true, 76 // used to check if supposed to be secure via InsecureSkipVerify 77 TLSConfig: tlsConfig, 78 }) 79 } 80 81 return endpoints, nil 82 }