Skip to content

Commit e37d814

Browse files
committed
cli/command/image: deprecate TagTrusted, move to cli/trust
This function was shared between "image" and "container" packages, all of which needed the trust package, so move it there instead. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent d804360 commit e37d814

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

cli/command/container/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/docker/cli/cli/command/image"
1616
"github.com/docker/cli/cli/internal/jsonstream"
1717
"github.com/docker/cli/cli/streams"
18+
"github.com/docker/cli/cli/trust"
1819
"github.com/docker/cli/opts"
1920
"github.com/docker/docker/api/types/container"
2021
imagetypes "github.com/docker/docker/api/types/image"
@@ -242,7 +243,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
242243
return err
243244
}
244245
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
245-
return image.TagTrusted(ctx, dockerCli, trustedRef, taggedRef)
246+
return trust.TagTrusted(ctx, dockerCli.Client(), dockerCli.Err(), trustedRef, taggedRef)
246247
}
247248
return nil
248249
}

cli/command/image/build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/docker/cli/cli/command/image/build"
2323
"github.com/docker/cli/cli/internal/jsonstream"
2424
"github.com/docker/cli/cli/streams"
25+
"github.com/docker/cli/cli/trust"
2526
"github.com/docker/cli/opts"
2627
"github.com/docker/docker/api"
2728
"github.com/docker/docker/api/types"
@@ -406,7 +407,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
406407
// Since the build was successful, now we must tag any of the resolved
407408
// images from the above Dockerfile rewrite.
408409
for _, resolved := range resolvedTags {
409-
if err := TagTrusted(ctx, dockerCli, resolved.digestRef, resolved.tagRef); err != nil {
410+
if err := trust.TagTrusted(ctx, dockerCli.Client(), dockerCli.Err(), resolved.digestRef, resolved.tagRef); err != nil {
410411
return err
411412
}
412413
}

cli/command/image/trust.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
104104
return err
105105
}
106106

107-
if err := TagTrusted(ctx, cli, trustedRef, tagged); err != nil {
107+
// Use familiar references when interacting with client and output
108+
familiarRef := reference.FamiliarString(tagged)
109+
trustedFamiliarRef := reference.FamiliarString(trustedRef)
110+
_, _ = fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
111+
if err := cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef); err != nil {
108112
return err
109113
}
110114
}
@@ -225,15 +229,13 @@ func convertTarget(t client.Target) (target, error) {
225229
}, nil
226230
}
227231

228-
// TagTrusted tags a trusted ref
232+
// TagTrusted tags a trusted ref. It is a shallow wrapper around APIClient.ImageTag
233+
// that updates the given image references to their familiar format for tagging
234+
// and printing.
235+
//
236+
// Deprecated: this function was only used internally, and will be removed in the next release.
229237
func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canonical, ref reference.NamedTagged) error {
230-
// Use familiar references when interacting with client and output
231-
familiarRef := reference.FamiliarString(ref)
232-
trustedFamiliarRef := reference.FamiliarString(trustedRef)
233-
234-
_, _ = fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
235-
236-
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
238+
return trust.TagTrusted(ctx, cli.Client(), cli.Err(), trustedRef, ref)
237239
}
238240

239241
// AuthResolver returns an auth resolver function from a command.Cli

cli/trust/trust_tag.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package trust
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io"
7+
8+
"github.com/distribution/reference"
9+
"github.com/docker/docker/client"
10+
)
11+
12+
// TagTrusted tags a trusted ref. It is a shallow wrapper around [client.Client.ImageTag]
13+
// that updates the given image references to their familiar format for tagging
14+
// and printing.
15+
func TagTrusted(ctx context.Context, apiClient client.ImageAPIClient, out io.Writer, trustedRef reference.Canonical, ref reference.NamedTagged) error {
16+
// Use familiar references when interacting with client and output
17+
familiarRef := reference.FamiliarString(ref)
18+
trustedFamiliarRef := reference.FamiliarString(trustedRef)
19+
20+
_, _ = fmt.Fprintf(out, "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
21+
return apiClient.ImageTag(ctx, trustedFamiliarRef, familiarRef)
22+
}

0 commit comments

Comments
 (0)