1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Update for distribution vendor

Handle updates to reference package.
Updates for refactoring of challenge manager.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2016-11-10 15:59:02 -08:00
parent 60ecc132c5
commit c85eb00841
No known key found for this signature in database
GPG key ID: F58C5D0A4405ACDB
8 changed files with 18 additions and 11 deletions

View file

@ -20,6 +20,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/distribution/digest" "github.com/docker/distribution/digest"
"github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/auth"
"github.com/docker/distribution/registry/client/auth/challenge"
"github.com/docker/distribution/registry/client/transport" "github.com/docker/distribution/registry/client/transport"
"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"
@ -291,7 +292,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
} }
fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), repoInfo.Name(), displayTag, r.digest) fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), repoInfo.Name(), displayTag, r.digest)
ref, err := reference.WithDigest(repoInfo, r.digest) ref, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest)
if err != nil { if err != nil {
return err return err
} }
@ -305,7 +306,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
if err != nil { if err != nil {
return err return err
} }
trustedRef, err := reference.WithDigest(repoInfo, r.digest) trustedRef, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest)
if err != nil { if err != nil {
return err return err
} }
@ -434,7 +435,7 @@ func GetNotaryRepository(streams command.Streams, repoInfo *registry.RepositoryI
return nil, err return nil, err
} }
challengeManager := auth.NewSimpleChallengeManager() challengeManager := challenge.NewSimpleManager()
resp, err := pingClient.Do(req) resp, err := pingClient.Do(req)
if err != nil { if err != nil {
@ -523,7 +524,7 @@ func TrustedReference(ctx context.Context, cli *command.DockerCli, ref reference
} }
return reference.WithDigest(ref, r.digest) return reference.WithDigest(reference.TrimNamed(ref), r.digest)
} }
func convertTarget(t client.Target) (target, error) { func convertTarget(t client.Target) (target, error) {

View file

@ -33,7 +33,7 @@ func (daemon *Daemon) PullImage(ctx context.Context, image, tag string, metaHead
var dgst digest.Digest var dgst digest.Digest
dgst, err = digest.ParseDigest(tag) dgst, err = digest.ParseDigest(tag)
if err == nil { if err == nil {
ref, err = reference.WithDigest(ref, dgst) ref, err = reference.WithDigest(reference.TrimNamed(ref), dgst)
} else { } else {
ref, err = reference.WithTag(ref, tag) ref, err = reference.WithTag(ref, tag)
} }

View file

@ -206,7 +206,7 @@ func ValidateRepoName(name string) error {
} }
func addDigestReference(store reference.Store, ref reference.Named, dgst digest.Digest, id digest.Digest) error { func addDigestReference(store reference.Store, ref reference.Named, dgst digest.Digest, id digest.Digest) error {
dgstRef, err := reference.WithDigest(ref, dgst) dgstRef, err := reference.WithDigest(reference.TrimNamed(ref), dgst)
if err != nil { if err != nil {
return err return err
} }

View file

@ -671,7 +671,7 @@ func (p *v2Puller) pullManifestList(ctx context.Context, ref reference.Named, mf
return "", "", err return "", "", err
} }
manifestRef, err := reference.WithDigest(ref, manifestDigest) manifestRef, err := reference.WithDigest(reference.TrimNamed(ref), manifestDigest)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }

View file

@ -331,7 +331,7 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress.
continue continue
} }
canonicalRef, err := distreference.WithDigest(remoteRef, mountCandidate.Digest) canonicalRef, err := distreference.WithDigest(distreference.TrimNamed(remoteRef), mountCandidate.Digest)
if err != nil { if err != nil {
logrus.Errorf("failed to make canonical reference: %v", err) logrus.Errorf("failed to make canonical reference: %v", err)
continue continue

View file

@ -331,7 +331,7 @@ func migrateRefs(root, driverName string, rs refAdder, mappings map[string]image
continue continue
} }
if dgst, err := digest.ParseDigest(tag); err == nil { if dgst, err := digest.ParseDigest(tag); err == nil {
canonical, err := reference.WithDigest(ref, dgst) canonical, err := reference.WithDigest(reference.TrimNamed(ref), dgst)
if err != nil { if err != nil {
logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err) logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err)
continue continue

View file

@ -70,6 +70,11 @@ func ParseNamed(s string) (Named, error) {
return r, nil return r, nil
} }
// TrimNamed removes any tag or digest from the named reference
func TrimNamed(ref Named) Named {
return &namedRef{distreference.TrimNamed(ref)}
}
// WithName returns a named object representing the given string. If the input // WithName returns a named object representing the given string. If the input
// is invalid ErrReferenceInvalidFormat will be returned. // is invalid ErrReferenceInvalidFormat will be returned.
func WithName(name string) (Named, error) { func WithName(name string) (Named, error) {

View file

@ -10,6 +10,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/auth"
"github.com/docker/distribution/registry/client/auth/challenge"
"github.com/docker/distribution/registry/client/transport" "github.com/docker/distribution/registry/client/transport"
"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"
@ -255,7 +256,7 @@ func (err PingResponseError) Error() string {
// challenge manager for the supported authentication types and // challenge manager for the supported authentication types and
// whether v2 was confirmed by the response. If a response is received but // whether v2 was confirmed by the response. If a response is received but
// cannot be interpreted a PingResponseError will be returned. // cannot be interpreted a PingResponseError will be returned.
func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (auth.ChallengeManager, bool, error) { func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.Manager, bool, error) {
var ( var (
foundV2 = false foundV2 = false
v2Version = auth.APIVersion{ v2Version = auth.APIVersion{
@ -291,7 +292,7 @@ func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (auth.Challe
} }
} }
challengeManager := auth.NewSimpleChallengeManager() challengeManager := challenge.NewSimpleManager()
if err := challengeManager.AddResponse(resp); err != nil { if err := challengeManager.AddResponse(resp); err != nil {
return nil, foundV2, PingResponseError{ return nil, foundV2, PingResponseError{
Err: err, Err: err,