service_v2.go 2.4 KB

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