service_v2.go 1.7 KB

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