github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/registry/service_v2.go (about) 1 package registry // import "github.com/demonoid81/moby/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 if hostname == DefaultNamespace || hostname == IndexHostname { 13 // v2 mirrors 14 for _, mirror := range s.config.Mirrors { 15 if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") { 16 mirror = "https://" + mirror 17 } 18 mirrorURL, err := url.Parse(mirror) 19 if err != nil { 20 return nil, err 21 } 22 mirrorTLSConfig, err := s.tlsConfigForMirror(mirrorURL) 23 if err != nil { 24 return nil, err 25 } 26 endpoints = append(endpoints, APIEndpoint{ 27 URL: mirrorURL, 28 // guess mirrors are v2 29 Version: APIVersion2, 30 Mirror: true, 31 TrimHostname: true, 32 TLSConfig: mirrorTLSConfig, 33 }) 34 } 35 // v2 registry 36 endpoints = append(endpoints, APIEndpoint{ 37 URL: DefaultV2Registry, 38 Version: APIVersion2, 39 Official: true, 40 TrimHostname: true, 41 TLSConfig: tlsConfig, 42 }) 43 44 return endpoints, nil 45 } 46 47 ana := allowNondistributableArtifacts(s.config, hostname) 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 }