From 874be028c3df36bf75016fa0f5d9f8065a1f6bc2 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 10 Nov 2016 15:59:02 -0800 Subject: [PATCH] Update for distribution vendor Handle updates to reference package. Updates for refactoring of challenge manager. Signed-off-by: Derek McGowan (github: dmcgowan) Upstream-commit: c85eb008416f352327b67dce351101591cd5f781 Component: engine --- components/engine/cli/command/image/trust.go | 9 +++++---- components/engine/daemon/image_pull.go | 2 +- components/engine/distribution/pull.go | 2 +- components/engine/distribution/pull_v2.go | 2 +- components/engine/distribution/push_v2.go | 2 +- components/engine/migrate/v1/migratev1.go | 2 +- components/engine/reference/reference.go | 5 +++++ components/engine/registry/auth.go | 5 +++-- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/components/engine/cli/command/image/trust.go b/components/engine/cli/command/image/trust.go index b8de6a5245..d1106b532e 100644 --- a/components/engine/cli/command/image/trust.go +++ b/components/engine/cli/command/image/trust.go @@ -20,6 +20,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution/digest" "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/docker/api/types" 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) - ref, err := reference.WithDigest(repoInfo, r.digest) + ref, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest) if err != nil { return err } @@ -305,7 +306,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry if err != nil { return err } - trustedRef, err := reference.WithDigest(repoInfo, r.digest) + trustedRef, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest) if err != nil { return err } @@ -434,7 +435,7 @@ func GetNotaryRepository(streams command.Streams, repoInfo *registry.RepositoryI return nil, err } - challengeManager := auth.NewSimpleChallengeManager() + challengeManager := challenge.NewSimpleManager() resp, err := pingClient.Do(req) 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) { diff --git a/components/engine/daemon/image_pull.go b/components/engine/daemon/image_pull.go index f0b8f55701..7dc1a2d0d9 100644 --- a/components/engine/daemon/image_pull.go +++ b/components/engine/daemon/image_pull.go @@ -33,7 +33,7 @@ func (daemon *Daemon) PullImage(ctx context.Context, image, tag string, metaHead var dgst digest.Digest dgst, err = digest.ParseDigest(tag) if err == nil { - ref, err = reference.WithDigest(ref, dgst) + ref, err = reference.WithDigest(reference.TrimNamed(ref), dgst) } else { ref, err = reference.WithTag(ref, tag) } diff --git a/components/engine/distribution/pull.go b/components/engine/distribution/pull.go index ea630f03bc..4fab438800 100644 --- a/components/engine/distribution/pull.go +++ b/components/engine/distribution/pull.go @@ -206,7 +206,7 @@ func ValidateRepoName(name string) 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 { return err } diff --git a/components/engine/distribution/pull_v2.go b/components/engine/distribution/pull_v2.go index 3a2015a41e..d62200ddaa 100644 --- a/components/engine/distribution/pull_v2.go +++ b/components/engine/distribution/pull_v2.go @@ -671,7 +671,7 @@ func (p *v2Puller) pullManifestList(ctx context.Context, ref reference.Named, mf return "", "", err } - manifestRef, err := reference.WithDigest(ref, manifestDigest) + manifestRef, err := reference.WithDigest(reference.TrimNamed(ref), manifestDigest) if err != nil { return "", "", err } diff --git a/components/engine/distribution/push_v2.go b/components/engine/distribution/push_v2.go index 2362f1f752..f2a1f02714 100644 --- a/components/engine/distribution/push_v2.go +++ b/components/engine/distribution/push_v2.go @@ -331,7 +331,7 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress. continue } - canonicalRef, err := distreference.WithDigest(remoteRef, mountCandidate.Digest) + canonicalRef, err := distreference.WithDigest(distreference.TrimNamed(remoteRef), mountCandidate.Digest) if err != nil { logrus.Errorf("failed to make canonical reference: %v", err) continue diff --git a/components/engine/migrate/v1/migratev1.go b/components/engine/migrate/v1/migratev1.go index 90bf627dfe..bc42dd2ca4 100644 --- a/components/engine/migrate/v1/migratev1.go +++ b/components/engine/migrate/v1/migratev1.go @@ -331,7 +331,7 @@ func migrateRefs(root, driverName string, rs refAdder, mappings map[string]image continue } 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 { logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err) continue diff --git a/components/engine/reference/reference.go b/components/engine/reference/reference.go index b22961b39d..996fc50704 100644 --- a/components/engine/reference/reference.go +++ b/components/engine/reference/reference.go @@ -70,6 +70,11 @@ func ParseNamed(s string) (Named, error) { 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 // is invalid ErrReferenceInvalidFormat will be returned. func WithName(name string) (Named, error) { diff --git a/components/engine/registry/auth.go b/components/engine/registry/auth.go index 0bf0450b2c..5da3563f9b 100644 --- a/components/engine/registry/auth.go +++ b/components/engine/registry/auth.go @@ -10,6 +10,7 @@ import ( "github.com/Sirupsen/logrus" "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/docker/api/types" 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 // whether v2 was confirmed by the response. If a response is received but // 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 ( foundV2 = false 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 { return nil, foundV2, PingResponseError{ Err: err,