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

Define PushResult in api types

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2016-12-22 11:44:09 -08:00
parent b81f47a288
commit 13222160e8
3 changed files with 23 additions and 22 deletions

View file

@ -547,3 +547,12 @@ type SecretCreateResponse struct {
type SecretListOptions struct { type SecretListOptions struct {
Filters filters.Args Filters filters.Args
} }
// PushResult contains the tag, manifest digest, and manifest size from the
// push. It's used to signal this information to the trust code in the client
// so it can sign the manifest if necessary.
type PushResult struct {
Tag string
Digest string
Size int
}

View file

@ -9,19 +9,17 @@ import (
"path" "path"
"sort" "sort"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/distribution/digest" "github.com/docker/distribution/digest"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/trust" "github.com/docker/docker/cli/trust"
"github.com/docker/docker/distribution"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/docker/notary/client" "github.com/docker/notary/client"
"github.com/docker/notary/tuf/data" "github.com/docker/notary/tuf/data"
"golang.org/x/net/context"
) )
type target struct { type target struct {
@ -52,17 +50,19 @@ func trustedPush(ctx context.Context, cli *command.DockerCli, repoInfo *registry
return return
} }
var pushResult distribution.PushResult var pushResult types.PushResult
err := json.Unmarshal(*aux, &pushResult) err := json.Unmarshal(*aux, &pushResult)
if err == nil && pushResult.Tag != "" && pushResult.Digest.Validate() == nil { if err == nil && pushResult.Tag != "" {
h, err := hex.DecodeString(pushResult.Digest.Hex()) if dgst, err := digest.ParseDigest(pushResult.Digest); err == nil {
if err != nil { h, err := hex.DecodeString(dgst.Hex())
target = nil if err != nil {
return target = nil
return
}
target.Name = pushResult.Tag
target.Hashes = data.Hashes{string(dgst.Algorithm()): h}
target.Length = int64(pushResult.Size)
} }
target.Name = pushResult.Tag
target.Hashes = data.Hashes{string(pushResult.Digest.Algorithm()): h}
target.Length = int64(pushResult.Size)
} }
} }

View file

@ -18,6 +18,7 @@ import (
"github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/manifest/schema2"
distreference "github.com/docker/distribution/reference" distreference "github.com/docker/distribution/reference"
"github.com/docker/distribution/registry/client" "github.com/docker/distribution/registry/client"
apitypes "github.com/docker/docker/api/types"
"github.com/docker/docker/distribution/metadata" "github.com/docker/docker/distribution/metadata"
"github.com/docker/docker/distribution/xfer" "github.com/docker/docker/distribution/xfer"
"github.com/docker/docker/layer" "github.com/docker/docker/layer"
@ -33,15 +34,6 @@ const (
middleLayerMaximumSize = 10 * (1 << 20) // 10MB middleLayerMaximumSize = 10 * (1 << 20) // 10MB
) )
// PushResult contains the tag, manifest digest, and manifest size from the
// push. It's used to signal this information to the trust code in the client
// so it can sign the manifest if necessary.
type PushResult struct {
Tag string
Digest digest.Digest
Size int
}
type v2Pusher struct { type v2Pusher struct {
v2MetadataService metadata.V2MetadataService v2MetadataService metadata.V2MetadataService
ref reference.Named ref reference.Named
@ -225,7 +217,7 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, id
// Signal digest to the trust client so it can sign the // Signal digest to the trust client so it can sign the
// push, if appropriate. // push, if appropriate.
progress.Aux(p.config.ProgressOutput, PushResult{Tag: ref.Tag(), Digest: manifestDigest, Size: len(canonicalManifest)}) progress.Aux(p.config.ProgressOutput, apitypes.PushResult{Tag: ref.Tag(), Digest: manifestDigest.String(), Size: len(canonicalManifest)})
return nil return nil
} }