github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/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  	tlsConfig := tlsconfig.ServerDefault()
    12  	if hostname == DefaultNamespace || hostname == IndexHostname {
    13  		// v2 mirrors
    14  		for _, mirror := range s.config.Mirrors {
    15  			if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") {
    16  				mirror = "https://" + mirror
    17  			}
    18  			mirrorURL, err := url.Parse(mirror)
    19  			if err != nil {
    20  				return nil, err
    21  			}
    22  			mirrorTLSConfig, err := s.tlsConfigForMirror(mirrorURL)
    23  			if err != nil {
    24  				return nil, err
    25  			}
    26  			endpoints = append(endpoints, APIEndpoint{
    27  				URL: mirrorURL,
    28  				// guess mirrors are v2
    29  				Version:      APIVersion2,
    30  				Mirror:       true,
    31  				TrimHostname: true,
    32  				TLSConfig:    mirrorTLSConfig,
    33  			})
    34  		}
    35  		// v2 registry
    36  		endpoints = append(endpoints, APIEndpoint{
    37  			URL:          DefaultV2Registry,
    38  			Version:      APIVersion2,
    39  			Official:     true,
    40  			TrimHostname: true,
    41  			TLSConfig:    tlsConfig,
    42  		})
    43  
    44  		return endpoints, nil
    45  	}
    46  
    47  	tlsConfig, err = s.tlsConfig(hostname)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	endpoints = []APIEndpoint{
    53  		{
    54  			URL: &url.URL{
    55  				Scheme: "https",
    56  				Host:   hostname,
    57  			},
    58  			Version:      APIVersion2,
    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  			TrimHostname: true,
    72  			// used to check if supposed to be secure via InsecureSkipVerify
    73  			TLSConfig: tlsConfig,
    74  		})
    75  	}
    76  
    77  	return endpoints, nil
    78  }