Browse code

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)

Derek McGowan authored on 2016/11/11 08:59:02
Showing 8 changed files
... ...
@@ -20,6 +20,7 @@ import (
20 20
 	"github.com/Sirupsen/logrus"
21 21
 	"github.com/docker/distribution/digest"
22 22
 	"github.com/docker/distribution/registry/client/auth"
23
+	"github.com/docker/distribution/registry/client/auth/challenge"
23 24
 	"github.com/docker/distribution/registry/client/transport"
24 25
 	"github.com/docker/docker/api/types"
25 26
 	registrytypes "github.com/docker/docker/api/types/registry"
... ...
@@ -291,7 +292,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
291 291
 		}
292 292
 		fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), repoInfo.Name(), displayTag, r.digest)
293 293
 
294
-		ref, err := reference.WithDigest(repoInfo, r.digest)
294
+		ref, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest)
295 295
 		if err != nil {
296 296
 			return err
297 297
 		}
... ...
@@ -305,7 +306,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
305 305
 			if err != nil {
306 306
 				return err
307 307
 			}
308
-			trustedRef, err := reference.WithDigest(repoInfo, r.digest)
308
+			trustedRef, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest)
309 309
 			if err != nil {
310 310
 				return err
311 311
 			}
... ...
@@ -434,7 +435,7 @@ func GetNotaryRepository(streams command.Streams, repoInfo *registry.RepositoryI
434 434
 		return nil, err
435 435
 	}
436 436
 
437
-	challengeManager := auth.NewSimpleChallengeManager()
437
+	challengeManager := challenge.NewSimpleManager()
438 438
 
439 439
 	resp, err := pingClient.Do(req)
440 440
 	if err != nil {
... ...
@@ -523,7 +524,7 @@ func TrustedReference(ctx context.Context, cli *command.DockerCli, ref reference
523 523
 
524 524
 	}
525 525
 
526
-	return reference.WithDigest(ref, r.digest)
526
+	return reference.WithDigest(reference.TrimNamed(ref), r.digest)
527 527
 }
528 528
 
529 529
 func convertTarget(t client.Target) (target, error) {
... ...
@@ -33,7 +33,7 @@ func (daemon *Daemon) PullImage(ctx context.Context, image, tag string, metaHead
33 33
 		var dgst digest.Digest
34 34
 		dgst, err = digest.ParseDigest(tag)
35 35
 		if err == nil {
36
-			ref, err = reference.WithDigest(ref, dgst)
36
+			ref, err = reference.WithDigest(reference.TrimNamed(ref), dgst)
37 37
 		} else {
38 38
 			ref, err = reference.WithTag(ref, tag)
39 39
 		}
... ...
@@ -206,7 +206,7 @@ func ValidateRepoName(name string) error {
206 206
 }
207 207
 
208 208
 func addDigestReference(store reference.Store, ref reference.Named, dgst digest.Digest, id digest.Digest) error {
209
-	dgstRef, err := reference.WithDigest(ref, dgst)
209
+	dgstRef, err := reference.WithDigest(reference.TrimNamed(ref), dgst)
210 210
 	if err != nil {
211 211
 		return err
212 212
 	}
... ...
@@ -671,7 +671,7 @@ func (p *v2Puller) pullManifestList(ctx context.Context, ref reference.Named, mf
671 671
 		return "", "", err
672 672
 	}
673 673
 
674
-	manifestRef, err := reference.WithDigest(ref, manifestDigest)
674
+	manifestRef, err := reference.WithDigest(reference.TrimNamed(ref), manifestDigest)
675 675
 	if err != nil {
676 676
 		return "", "", err
677 677
 	}
... ...
@@ -331,7 +331,7 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress.
331 331
 				continue
332 332
 			}
333 333
 
334
-			canonicalRef, err := distreference.WithDigest(remoteRef, mountCandidate.Digest)
334
+			canonicalRef, err := distreference.WithDigest(distreference.TrimNamed(remoteRef), mountCandidate.Digest)
335 335
 			if err != nil {
336 336
 				logrus.Errorf("failed to make canonical reference: %v", err)
337 337
 				continue
... ...
@@ -331,7 +331,7 @@ func migrateRefs(root, driverName string, rs refAdder, mappings map[string]image
331 331
 					continue
332 332
 				}
333 333
 				if dgst, err := digest.ParseDigest(tag); err == nil {
334
-					canonical, err := reference.WithDigest(ref, dgst)
334
+					canonical, err := reference.WithDigest(reference.TrimNamed(ref), dgst)
335 335
 					if err != nil {
336 336
 						logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err)
337 337
 						continue
... ...
@@ -70,6 +70,11 @@ func ParseNamed(s string) (Named, error) {
70 70
 	return r, nil
71 71
 }
72 72
 
73
+// TrimNamed removes any tag or digest from the named reference
74
+func TrimNamed(ref Named) Named {
75
+	return &namedRef{distreference.TrimNamed(ref)}
76
+}
77
+
73 78
 // WithName returns a named object representing the given string. If the input
74 79
 // is invalid ErrReferenceInvalidFormat will be returned.
75 80
 func WithName(name string) (Named, error) {
... ...
@@ -10,6 +10,7 @@ import (
10 10
 
11 11
 	"github.com/Sirupsen/logrus"
12 12
 	"github.com/docker/distribution/registry/client/auth"
13
+	"github.com/docker/distribution/registry/client/auth/challenge"
13 14
 	"github.com/docker/distribution/registry/client/transport"
14 15
 	"github.com/docker/docker/api/types"
15 16
 	registrytypes "github.com/docker/docker/api/types/registry"
... ...
@@ -255,7 +256,7 @@ func (err PingResponseError) Error() string {
255 255
 // challenge manager for the supported authentication types and
256 256
 // whether v2 was confirmed by the response. If a response is received but
257 257
 // cannot be interpreted a PingResponseError will be returned.
258
-func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (auth.ChallengeManager, bool, error) {
258
+func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.Manager, bool, error) {
259 259
 	var (
260 260
 		foundV2   = false
261 261
 		v2Version = auth.APIVersion{
... ...
@@ -291,7 +292,7 @@ func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (auth.Challe
291 291
 		}
292 292
 	}
293 293
 
294
-	challengeManager := auth.NewSimpleChallengeManager()
294
+	challengeManager := challenge.NewSimpleManager()
295 295
 	if err := challengeManager.AddResponse(resp); err != nil {
296 296
 		return nil, foundV2, PingResponseError{
297 297
 			Err: err,