github.com/fntlnz/docker@v1.9.0-rc3/registry/service_v2.go (about)

     1  package registry
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/docker/distribution/registry/client/auth"
     8  	"github.com/docker/docker/pkg/tlsconfig"
     9  )
    10  
    11  func (s *Service) lookupV2Endpoints(repoName string) (endpoints []APIEndpoint, err error) {
    12  	var cfg = tlsconfig.ServerDefault
    13  	tlsConfig := &cfg
    14  	if strings.HasPrefix(repoName, DefaultNamespace+"/") {
    15  		// v2 mirrors
    16  		for _, mirror := range s.Config.Mirrors {
    17  			mirrorTLSConfig, err := s.tlsConfigForMirror(mirror)
    18  			if err != nil {
    19  				return nil, err
    20  			}
    21  			endpoints = append(endpoints, APIEndpoint{
    22  				URL: mirror,
    23  				// guess mirrors are v2
    24  				Version:      APIVersion2,
    25  				Mirror:       true,
    26  				TrimHostname: true,
    27  				TLSConfig:    mirrorTLSConfig,
    28  			})
    29  		}
    30  		// v2 registry
    31  		endpoints = append(endpoints, APIEndpoint{
    32  			URL:          DefaultV2Registry,
    33  			Version:      APIVersion2,
    34  			Official:     true,
    35  			TrimHostname: true,
    36  			TLSConfig:    tlsConfig,
    37  		})
    38  
    39  		return endpoints, nil
    40  	}
    41  
    42  	slashIndex := strings.IndexRune(repoName, '/')
    43  	if slashIndex <= 0 {
    44  		return nil, fmt.Errorf("invalid repo name: missing '/':  %s", repoName)
    45  	}
    46  	hostname := repoName[:slashIndex]
    47  
    48  	tlsConfig, err = s.TLSConfig(hostname)
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  
    53  	v2Versions := []auth.APIVersion{
    54  		{
    55  			Type:    "registry",
    56  			Version: "2.0",
    57  		},
    58  	}
    59  	endpoints = []APIEndpoint{
    60  		{
    61  			URL:           "https://" + hostname,
    62  			Version:       APIVersion2,
    63  			TrimHostname:  true,
    64  			TLSConfig:     tlsConfig,
    65  			VersionHeader: DefaultRegistryVersionHeader,
    66  			Versions:      v2Versions,
    67  		},
    68  	}
    69  
    70  	if tlsConfig.InsecureSkipVerify {
    71  		endpoints = append(endpoints, APIEndpoint{
    72  			URL:          "http://" + hostname,
    73  			Version:      APIVersion2,
    74  			TrimHostname: true,
    75  			// used to check if supposed to be secure via InsecureSkipVerify
    76  			TLSConfig:     tlsConfig,
    77  			VersionHeader: DefaultRegistryVersionHeader,
    78  			Versions:      v2Versions,
    79  		})
    80  	}
    81  
    82  	return endpoints, nil
    83  }