|
@@ -10,11 +10,11 @@ import (
|
|
|
"sort"
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
+ "github.com/docker/distribution/reference"
|
|
|
"github.com/docker/docker/api/types"
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
"github.com/docker/docker/cli/trust"
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
|
|
- "github.com/docker/docker/reference"
|
|
|
"github.com/docker/docker/registry"
|
|
|
"github.com/docker/notary/client"
|
|
|
"github.com/docker/notary/tuf/data"
|
|
@@ -30,7 +30,7 @@ type target struct {
|
|
|
|
|
|
// trustedPush handles content trust pushing of an image
|
|
|
func trustedPush(ctx context.Context, cli *command.DockerCli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
|
|
|
- responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref.String(), requestPrivilege)
|
|
|
+ responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref, requestPrivilege)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -202,7 +202,7 @@ func addTargetToAllSignableRoles(repo *client.NotaryRepository, target *client.T
|
|
|
}
|
|
|
|
|
|
// imagePushPrivileged push the image
|
|
|
-func imagePushPrivileged(ctx context.Context, cli *command.DockerCli, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
|
|
|
+func imagePushPrivileged(ctx context.Context, cli *command.DockerCli, authConfig types.AuthConfig, ref reference.Named, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
|
|
|
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -212,7 +212,7 @@ func imagePushPrivileged(ctx context.Context, cli *command.DockerCli, authConfig
|
|
|
PrivilegeFunc: requestPrivilege,
|
|
|
}
|
|
|
|
|
|
- return cli.Client().ImagePush(ctx, ref, options)
|
|
|
+ return cli.Client().ImagePush(ctx, reference.FamiliarString(ref), options)
|
|
|
}
|
|
|
|
|
|
// trustedPull handles content trust pulling of an image
|
|
@@ -229,12 +229,12 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
|
|
|
// List all targets
|
|
|
targets, err := notaryRepo.ListTargets(trust.ReleasesRole, data.CanonicalTargetsRole)
|
|
|
if err != nil {
|
|
|
- return trust.NotaryError(repoInfo.FullName(), err)
|
|
|
+ return trust.NotaryError(ref.Name(), err)
|
|
|
}
|
|
|
for _, tgt := range targets {
|
|
|
t, err := convertTarget(tgt.Target)
|
|
|
if err != nil {
|
|
|
- fmt.Fprintf(cli.Out(), "Skipping target for %q\n", repoInfo.Name())
|
|
|
+ fmt.Fprintf(cli.Out(), "Skipping target for %q\n", reference.FamiliarName(ref))
|
|
|
continue
|
|
|
}
|
|
|
// Only list tags in the top level targets role or the releases delegation role - ignore
|
|
@@ -245,17 +245,17 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
|
|
|
refs = append(refs, t)
|
|
|
}
|
|
|
if len(refs) == 0 {
|
|
|
- return trust.NotaryError(repoInfo.FullName(), fmt.Errorf("No trusted tags for %s", repoInfo.FullName()))
|
|
|
+ return trust.NotaryError(ref.Name(), fmt.Errorf("No trusted tags for %s", ref.Name()))
|
|
|
}
|
|
|
} else {
|
|
|
t, err := notaryRepo.GetTargetByName(tagged.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
|
|
|
if err != nil {
|
|
|
- return trust.NotaryError(repoInfo.FullName(), err)
|
|
|
+ return trust.NotaryError(ref.Name(), err)
|
|
|
}
|
|
|
// Only get the tag if it's in the top level targets role or the releases delegation role
|
|
|
// ignore it if it's in any other delegation roles
|
|
|
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
|
|
|
- return trust.NotaryError(repoInfo.FullName(), fmt.Errorf("No trust data for %s", tagged.Tag()))
|
|
|
+ return trust.NotaryError(ref.Name(), fmt.Errorf("No trust data for %s", tagged.Tag()))
|
|
|
}
|
|
|
|
|
|
logrus.Debugf("retrieving target for %s role\n", t.Role)
|
|
@@ -272,24 +272,21 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
|
|
|
if displayTag != "" {
|
|
|
displayTag = ":" + displayTag
|
|
|
}
|
|
|
- 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), reference.FamiliarName(ref), displayTag, r.digest)
|
|
|
|
|
|
- ref, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest)
|
|
|
+ trustedRef, err := reference.WithDigest(reference.TrimNamed(ref), r.digest)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := imagePullPrivileged(ctx, cli, authConfig, ref.String(), requestPrivilege, false); err != nil {
|
|
|
+ if err := imagePullPrivileged(ctx, cli, authConfig, reference.FamiliarString(trustedRef), requestPrivilege, false); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- tagged, err := reference.WithTag(repoInfo, r.name)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- trustedRef, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest)
|
|
|
+ tagged, err := reference.WithTag(reference.TrimNamed(ref), r.name)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
if err := TagTrusted(ctx, cli, trustedRef, tagged); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -375,7 +372,11 @@ func convertTarget(t client.Target) (target, error) {
|
|
|
|
|
|
// TagTrusted tags a trusted ref
|
|
|
func TagTrusted(ctx context.Context, cli *command.DockerCli, trustedRef reference.Canonical, ref reference.NamedTagged) error {
|
|
|
- fmt.Fprintf(cli.Out(), "Tagging %s as %s\n", trustedRef.String(), ref.String())
|
|
|
+ // Use familiar references when interacting with client and output
|
|
|
+ familiarRef := reference.FamiliarString(ref)
|
|
|
+ trustedFamiliarRef := reference.FamiliarString(trustedRef)
|
|
|
+
|
|
|
+ fmt.Fprintf(cli.Out(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
|
|
|
|
|
|
- return cli.Client().ImageTag(ctx, trustedRef.String(), ref.String())
|
|
|
+ return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
|
|
|
}
|