@@ -14,14 +14,15 @@ import (
1414)
1515
1616type repositoryEndpoint struct {
17- info * registry.RepositoryInfo
18- endpoint registry.APIEndpoint
19- actions []string
17+ repoName reference.Named
18+ indexInfo * registrytypes.IndexInfo
19+ endpoint registry.APIEndpoint
20+ actions []string
2021}
2122
2223// Name returns the repository name
2324func (r repositoryEndpoint ) Name () string {
24- return reference .Path (r .info . Name )
25+ return reference .Path (r .repoName )
2526}
2627
2728// BaseURL returns the endpoint url
@@ -30,32 +31,36 @@ func (r repositoryEndpoint) BaseURL() string {
3031}
3132
3233func newDefaultRepositoryEndpoint (ref reference.Named , insecure bool ) (repositoryEndpoint , error ) {
34+ repoName := reference .TrimNamed (ref )
3335 repoInfo , _ := registry .ParseRepositoryInfo (ref )
34- endpoint , err := getDefaultEndpointFromRepoInfo (repoInfo )
36+ indexInfo := repoInfo .Index
37+
38+ endpoint , err := getDefaultEndpoint (ref , ! indexInfo .Secure )
3539 if err != nil {
3640 return repositoryEndpoint {}, err
3741 }
3842 if insecure {
3943 endpoint .TLSConfig .InsecureSkipVerify = true
4044 }
41- return repositoryEndpoint {info : repoInfo , endpoint : endpoint }, nil
45+ return repositoryEndpoint {
46+ repoName : repoName ,
47+ indexInfo : indexInfo ,
48+ endpoint : endpoint ,
49+ }, nil
4250}
4351
44- func getDefaultEndpointFromRepoInfo (repoInfo * registry.RepositoryInfo ) (registry.APIEndpoint , error ) {
45- var err error
46-
47- options := registry.ServiceOptions {}
48- registryService , err := registry .NewService (options )
52+ func getDefaultEndpoint (repoName reference.Named , insecure bool ) (registry.APIEndpoint , error ) {
53+ registryService , err := registry .NewService (registry.ServiceOptions {})
4954 if err != nil {
5055 return registry.APIEndpoint {}, err
5156 }
52- endpoints , err := registryService .LookupPushEndpoints (reference .Domain (repoInfo . Name ))
57+ endpoints , err := registryService .LookupPushEndpoints (reference .Domain (repoName ))
5358 if err != nil {
5459 return registry.APIEndpoint {}, err
5560 }
5661 // Default to the highest priority endpoint to return
5762 endpoint := endpoints [0 ]
58- if ! repoInfo . Index . Secure {
63+ if insecure {
5964 for _ , ep := range endpoints {
6065 if ep .URL .Scheme == "http" {
6166 endpoint = ep
0 commit comments