service_v2.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. ana := allowNondistributableArtifacts(s.config, hostname)
  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. AllowNondistributableArtifacts: ana,
  55. TrimHostname: true,
  56. TLSConfig: tlsConfig,
  57. },
  58. }
  59. if tlsConfig.InsecureSkipVerify {
  60. endpoints = append(endpoints, APIEndpoint{
  61. URL: &url.URL{
  62. Scheme: "http",
  63. Host: hostname,
  64. },
  65. Version: APIVersion2,
  66. AllowNondistributableArtifacts: ana,
  67. TrimHostname: true,
  68. // used to check if supposed to be secure via InsecureSkipVerify
  69. TLSConfig: tlsConfig,
  70. })
  71. }
  72. return endpoints, nil
  73. }