@@ -13,22 +13,18 @@ import (
1313 "github.com/docker/cli/cli/command"
1414 "github.com/docker/cli/cli/command/completion"
1515 "github.com/docker/cli/cli/streams"
16- "github.com/docker/cli/cli/trust"
1716 "github.com/docker/cli/internal/jsonstream"
18- "github.com/moby/moby/api/pkg/authconfig"
19- registrytypes "github.com/moby/moby/api/types/registry"
2017 "github.com/moby/moby/client"
2118 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2219 "github.com/spf13/cobra"
2320)
2421
2522// pullOptions defines what and how to pull.
2623type pullOptions struct {
27- remote string
28- all bool
29- platform string
30- quiet bool
31- untrusted bool
24+ remote string
25+ all bool
26+ platform string
27+ quiet bool
3228}
3329
3430// newPullCommand creates a new `docker pull` command
@@ -57,7 +53,11 @@ func newPullCommand(dockerCLI command.Cli) *cobra.Command {
5753
5854 flags .BoolVarP (& opts .all , "all-tags" , "a" , false , "Download all tagged images in the repository" )
5955 flags .BoolVarP (& opts .quiet , "quiet" , "q" , false , "Suppress verbose output" )
60- flags .BoolVar (& opts .untrusted , "disable-content-trust" , ! trust .Enabled (), "Skip image verification" )
56+
57+ // TODO(thaJeztah): DEPRECATED: remove in v29.1 or v30
58+ flags .Bool ("disable-content-trust" , true , "Skip image verification (deprecated)" )
59+ _ = flags .MarkDeprecated ("disable-content-trust" , "support for docker content trust was removed" )
60+
6161 flags .StringVar (& opts .platform , "platform" , os .Getenv ("DOCKER_DEFAULT_PLATFORM" ), "Set platform if server is multi-platform capable" )
6262 _ = flags .SetAnnotation ("platform" , "version" , []string {"1.32" })
6363 _ = cmd .RegisterFlagCompletionFunc ("platform" , completion .Platforms ())
@@ -80,46 +80,22 @@ func runPull(ctx context.Context, dockerCLI command.Cli, opts pullOptions) error
8080 }
8181 }
8282
83+ var ociPlatforms []ocispec.Platform
8384 if opts .platform != "" {
8485 // TODO(thaJeztah): add a platform option-type / flag-type.
85- if _ , err = platforms .Parse (opts .platform ); err != nil {
86+ p , err := platforms .Parse (opts .platform )
87+ if err != nil {
8688 return err
8789 }
90+ ociPlatforms = append (ociPlatforms , p )
8891 }
8992
90- imgRefAndAuth , err := trust . GetImageReferencesAndAuth ( ctx , authResolver ( dockerCLI ), distributionRef .String ())
93+ encodedAuth , err := command . RetrieveAuthTokenFromImage ( dockerCLI . ConfigFile ( ), distributionRef .String ())
9194 if err != nil {
9295 return err
9396 }
9497
95- // Check if reference has a digest
96- _ , isCanonical := distributionRef .(reference.Canonical )
97- if ! opts .untrusted && ! isCanonical {
98- if err := trustedPull (ctx , dockerCLI , imgRefAndAuth , opts ); err != nil {
99- return err
100- }
101- } else {
102- if err := imagePullPrivileged (ctx , dockerCLI , imgRefAndAuth .Reference (), imgRefAndAuth .AuthConfig (), opts ); err != nil {
103- return err
104- }
105- }
106- _ , _ = fmt .Fprintln (dockerCLI .Out (), imgRefAndAuth .Reference ().String ())
107- return nil
108- }
109-
110- // imagePullPrivileged pulls the image and displays it to the output
111- func imagePullPrivileged (ctx context.Context , dockerCLI command.Cli , ref reference.Named , authConfig * registrytypes.AuthConfig , opts pullOptions ) error {
112- encodedAuth , err := authconfig .Encode (* authConfig )
113- if err != nil {
114- return err
115- }
116- var ociPlatforms []ocispec.Platform
117- if opts .platform != "" {
118- // Already validated.
119- ociPlatforms = append (ociPlatforms , platforms .MustParse (opts .platform ))
120- }
121-
122- responseBody , err := dockerCLI .Client ().ImagePull (ctx , reference .FamiliarString (ref ), client.ImagePullOptions {
98+ responseBody , err := dockerCLI .Client ().ImagePull (ctx , reference .FamiliarString (distributionRef ), client.ImagePullOptions {
12399 RegistryAuth : encodedAuth ,
124100 PrivilegeFunc : nil ,
125101 All : opts .all ,
@@ -134,5 +110,9 @@ func imagePullPrivileged(ctx context.Context, dockerCLI command.Cli, ref referen
134110 if opts .quiet {
135111 out = streams .NewOut (io .Discard )
136112 }
137- return jsonstream .Display (ctx , responseBody , out )
113+ if err := jsonstream .Display (ctx , responseBody , out ); err != nil {
114+ return err
115+ }
116+ _ , _ = fmt .Fprintln (dockerCLI .Out (), distributionRef .String ())
117+ return nil
138118}
0 commit comments