39f2f15a |
package registry
import ( |
79db131a |
"net/url" |
39f2f15a |
"strings"
|
8e034802 |
"github.com/docker/go-connections/tlsconfig" |
39f2f15a |
)
|
f2d481a2 |
func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) { |
39f2f15a |
var cfg = tlsconfig.ServerDefault
tlsConfig := &cfg |
e896d1d7 |
if hostname == DefaultNamespace || hostname == DefaultV1Registry.Host { |
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
}
tlsConfig, err = s.TLSConfig(hostname)
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
} |