github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/moby/registry/service_v2.go (about)

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