github.com/kobeld/docker@v1.12.0-rc1/registry/service_v2.go (about)

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