Do not fall back to the V1 protocol when we know we are talking to a V2 registry

If we detect a Docker-Distribution-Api-Version header indicating that
the registry speaks the V2 protocol, no fallback to V1 should take
place.

The same applies if a V2 registry operation succeeds while attempting a
push or pull.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2015-12-04 13:42:33 -08:00
parent 46683f6192
commit 5717c8243d
2 changed files with 11 additions and 25 deletions

View file

@ -6,7 +6,6 @@ import (
"net/url" "net/url"
"strings" "strings"
"github.com/docker/distribution/registry/client/auth"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
@ -127,8 +126,6 @@ type APIEndpoint struct {
Official bool Official bool
TrimHostname bool TrimHostname bool
TLSConfig *tls.Config TLSConfig *tls.Config
VersionHeader string
Versions []auth.APIVersion
} }
// ToV1Endpoint returns a V1 API endpoint based on the APIEndpoint // ToV1Endpoint returns a V1 API endpoint based on the APIEndpoint

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/docker/distribution/registry/client/auth"
"github.com/docker/docker/pkg/tlsconfig" "github.com/docker/docker/pkg/tlsconfig"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
) )
@ -52,20 +51,12 @@ func (s *Service) lookupV2Endpoints(repoName reference.Named) (endpoints []APIEn
return nil, err return nil, err
} }
v2Versions := []auth.APIVersion{
{
Type: "registry",
Version: "2.0",
},
}
endpoints = []APIEndpoint{ endpoints = []APIEndpoint{
{ {
URL: "https://" + hostname, URL: "https://" + hostname,
Version: APIVersion2, Version: APIVersion2,
TrimHostname: true, TrimHostname: true,
TLSConfig: tlsConfig, TLSConfig: tlsConfig,
VersionHeader: DefaultRegistryVersionHeader,
Versions: v2Versions,
}, },
} }
@ -76,8 +67,6 @@ func (s *Service) lookupV2Endpoints(repoName reference.Named) (endpoints []APIEn
TrimHostname: true, TrimHostname: true,
// used to check if supposed to be secure via InsecureSkipVerify // used to check if supposed to be secure via InsecureSkipVerify
TLSConfig: tlsConfig, TLSConfig: tlsConfig,
VersionHeader: DefaultRegistryVersionHeader,
Versions: v2Versions,
}) })
} }