@@ -3,10 +3,13 @@ package client
33import (
44 "errors"
55 "fmt"
6- "net/url"
76
87 "github.com/docker/distribution/reference"
8+ "github.com/docker/docker/api/client/lib"
9+ "github.com/docker/docker/api/types"
910 Cli "github.com/docker/docker/cli"
11+ "github.com/docker/docker/cliconfig"
12+ "github.com/docker/docker/pkg/jsonmessage"
1013 flag "github.com/docker/docker/pkg/mflag"
1114 "github.com/docker/docker/registry"
1215 tagpkg "github.com/docker/docker/tag"
@@ -62,15 +65,34 @@ func (cli *DockerCli) CmdPull(args ...string) error {
6265 return err
6366 }
6467
68+ authConfig := registry .ResolveAuthConfig (cli .configFile , repoInfo .Index )
69+ requestPrivilege := cli .registryAuthenticationPrivilegedFunc (repoInfo .Index , "pull" )
70+
6571 if isTrusted () && ! ref .HasDigest () {
6672 // Check if tag is digest
67- authConfig := registry .ResolveAuthConfig (cli .configFile , repoInfo .Index )
68- return cli .trustedPull (repoInfo , ref , authConfig )
73+ return cli .trustedPull (repoInfo , ref , authConfig , requestPrivilege )
74+ }
75+
76+ return cli .imagePullPrivileged (authConfig , distributionRef .String (), "" , requestPrivilege )
77+ }
78+
79+ func (cli * DockerCli ) imagePullPrivileged (authConfig cliconfig.AuthConfig , imageID , tag string , requestPrivilege lib.RequestPrivilegeFunc ) error {
80+
81+ encodedAuth , err := authConfig .EncodeToBase64 ()
82+ if err != nil {
83+ return err
84+ }
85+ options := types.ImagePullOptions {
86+ ImageID : imageID ,
87+ Tag : tag ,
88+ RegistryAuth : encodedAuth ,
6989 }
7090
71- v := url.Values {}
72- v .Set ("fromImage" , distributionRef .String ())
91+ responseBody , err := cli .client .ImagePull (options , requestPrivilege )
92+ if err != nil {
93+ return err
94+ }
95+ defer responseBody .Close ()
7396
74- _ , _ , err = cli .clientRequestAttemptLogin ("POST" , "/images/create?" + v .Encode (), nil , cli .out , repoInfo .Index , "pull" )
75- return err
97+ return jsonmessage .DisplayJSONMessagesStream (responseBody , cli .out , cli .outFd , cli .isTerminalOut )
7698}
0 commit comments