Browse code

Define PushResult in api types

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/12/23 04:44:09
Showing 3 changed files
... ...
@@ -547,3 +547,12 @@ type SecretCreateResponse struct {
547 547
 type SecretListOptions struct {
548 548
 	Filters filters.Args
549 549
 }
550
+
551
+// PushResult contains the tag, manifest digest, and manifest size from the
552
+// push. It's used to signal this information to the trust code in the client
553
+// so it can sign the manifest if necessary.
554
+type PushResult struct {
555
+	Tag    string
556
+	Digest string
557
+	Size   int
558
+}
... ...
@@ -9,19 +9,17 @@ import (
9 9
 	"path"
10 10
 	"sort"
11 11
 
12
-	"golang.org/x/net/context"
13
-
14 12
 	"github.com/Sirupsen/logrus"
15 13
 	"github.com/docker/distribution/digest"
16 14
 	"github.com/docker/docker/api/types"
17 15
 	"github.com/docker/docker/cli/command"
18 16
 	"github.com/docker/docker/cli/trust"
19
-	"github.com/docker/docker/distribution"
20 17
 	"github.com/docker/docker/pkg/jsonmessage"
21 18
 	"github.com/docker/docker/reference"
22 19
 	"github.com/docker/docker/registry"
23 20
 	"github.com/docker/notary/client"
24 21
 	"github.com/docker/notary/tuf/data"
22
+	"golang.org/x/net/context"
25 23
 )
26 24
 
27 25
 type target struct {
... ...
@@ -52,17 +50,19 @@ func trustedPush(ctx context.Context, cli *command.DockerCli, repoInfo *registry
52 52
 			return
53 53
 		}
54 54
 
55
-		var pushResult distribution.PushResult
55
+		var pushResult types.PushResult
56 56
 		err := json.Unmarshal(*aux, &pushResult)
57
-		if err == nil && pushResult.Tag != "" && pushResult.Digest.Validate() == nil {
58
-			h, err := hex.DecodeString(pushResult.Digest.Hex())
59
-			if err != nil {
60
-				target = nil
61
-				return
57
+		if err == nil && pushResult.Tag != "" {
58
+			if dgst, err := digest.ParseDigest(pushResult.Digest); err == nil {
59
+				h, err := hex.DecodeString(dgst.Hex())
60
+				if err != nil {
61
+					target = nil
62
+					return
63
+				}
64
+				target.Name = pushResult.Tag
65
+				target.Hashes = data.Hashes{string(dgst.Algorithm()): h}
66
+				target.Length = int64(pushResult.Size)
62 67
 			}
63
-			target.Name = pushResult.Tag
64
-			target.Hashes = data.Hashes{string(pushResult.Digest.Algorithm()): h}
65
-			target.Length = int64(pushResult.Size)
66 68
 		}
67 69
 	}
68 70
 
... ...
@@ -18,6 +18,7 @@ import (
18 18
 	"github.com/docker/distribution/manifest/schema2"
19 19
 	distreference "github.com/docker/distribution/reference"
20 20
 	"github.com/docker/distribution/registry/client"
21
+	apitypes "github.com/docker/docker/api/types"
21 22
 	"github.com/docker/docker/distribution/metadata"
22 23
 	"github.com/docker/docker/distribution/xfer"
23 24
 	"github.com/docker/docker/layer"
... ...
@@ -33,15 +34,6 @@ const (
33 33
 	middleLayerMaximumSize = 10 * (1 << 20)  // 10MB
34 34
 )
35 35
 
36
-// PushResult contains the tag, manifest digest, and manifest size from the
37
-// push. It's used to signal this information to the trust code in the client
38
-// so it can sign the manifest if necessary.
39
-type PushResult struct {
40
-	Tag    string
41
-	Digest digest.Digest
42
-	Size   int
43
-}
44
-
45 36
 type v2Pusher struct {
46 37
 	v2MetadataService metadata.V2MetadataService
47 38
 	ref               reference.Named
... ...
@@ -225,7 +217,7 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, id
225 225
 
226 226
 	// Signal digest to the trust client so it can sign the
227 227
 	// push, if appropriate.
228
-	progress.Aux(p.config.ProgressOutput, PushResult{Tag: ref.Tag(), Digest: manifestDigest, Size: len(canonicalManifest)})
228
+	progress.Aux(p.config.ProgressOutput, apitypes.PushResult{Tag: ref.Tag(), Digest: manifestDigest.String(), Size: len(canonicalManifest)})
229 229
 
230 230
 	return nil
231 231
 }