service_v2.go 1.7 KB

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