@@ -10,13 +10,9 @@ import (
1010 "github.com/distribution/reference"
1111 "github.com/docker/cli/cli/command"
1212 "github.com/docker/cli/cli/config"
13- "github.com/docker/cli/cli/streams"
1413 "github.com/docker/cli/cli/trust"
15- "github.com/docker/cli/internal/jsonstream"
1614 "github.com/docker/cli/internal/registry"
17- "github.com/moby/moby/api/pkg/authconfig"
1815 registrytypes "github.com/moby/moby/api/types/registry"
19- "github.com/moby/moby/client"
2016 "github.com/opencontainers/go-digest"
2117 "github.com/sirupsen/logrus"
2218 notaryclient "github.com/theupdateframework/notary/client"
@@ -31,16 +27,16 @@ type target struct {
3127
3228// notaryClientProvider is used in tests to provide a dummy notary client.
3329type notaryClientProvider interface {
34- NotaryClient (imgRefAndAuth trust. ImageRefAndAuth , actions [] string ) (notaryclient.Repository , error )
30+ NotaryClient () (notaryclient.Repository , error )
3531}
3632
3733// newNotaryClient provides a Notary Repository to interact with signed metadata for an image.
38- func newNotaryClient (cli command.Streams , imgRefAndAuth trust.ImageRefAndAuth ) (notaryclient.Repository , error ) {
34+ func newNotaryClient (cli command.Streams , repoInfo * trust.RepositoryInfo , authConfig * registrytypes. AuthConfig ) (notaryclient.Repository , error ) {
3935 if ncp , ok := cli .(notaryClientProvider ); ok {
4036 // notaryClientProvider is used in tests to provide a dummy notary client.
41- return ncp .NotaryClient (imgRefAndAuth , [] string { "pull" } )
37+ return ncp .NotaryClient ()
4238 }
43- return trust .GetNotaryRepository (cli .In (), cli .Out (), command .UserAgent (), imgRefAndAuth . RepoInfo (), imgRefAndAuth . AuthConfig () , "pull" )
39+ return trust .GetNotaryRepository (cli .In (), cli .Out (), command .UserAgent (), repoInfo , authConfig , "pull" )
4440}
4541
4642// pushTrustedReference pushes a canonical reference to the trust server.
@@ -81,7 +77,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
8177 if err != nil {
8278 return err
8379 }
84- if err := imagePullPrivileged (ctx , cli , updatedImgRefAndAuth , pullOptions {
80+ if err := imagePullPrivileged (ctx , cli , updatedImgRefAndAuth . Reference (), updatedImgRefAndAuth . AuthConfig () , pullOptions {
8581 all : false ,
8682 platform : opts .platform ,
8783 quiet : opts .quiet ,
@@ -107,7 +103,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
107103}
108104
109105func getTrustedPullTargets (cli command.Cli , imgRefAndAuth trust.ImageRefAndAuth ) ([]target , error ) {
110- notaryRepo , err := newNotaryClient (cli , imgRefAndAuth )
106+ notaryRepo , err := newNotaryClient (cli , imgRefAndAuth . RepoInfo (), imgRefAndAuth . AuthConfig () )
111107 if err != nil {
112108 return nil , fmt .Errorf ("error establishing connection to trust repository: %w" , err )
113109 }
@@ -155,38 +151,14 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
155151 return []target {r }, err
156152}
157153
158- // imagePullPrivileged pulls the image and displays it to the output
159- func imagePullPrivileged (ctx context.Context , cli command.Cli , imgRefAndAuth trust.ImageRefAndAuth , opts pullOptions ) error {
160- encodedAuth , err := authconfig .Encode (* imgRefAndAuth .AuthConfig ())
161- if err != nil {
162- return err
163- }
164- responseBody , err := cli .Client ().ImagePull (ctx , reference .FamiliarString (imgRefAndAuth .Reference ()), client.ImagePullOptions {
165- RegistryAuth : encodedAuth ,
166- PrivilegeFunc : nil ,
167- All : opts .all ,
168- Platform : opts .platform ,
169- })
170- if err != nil {
171- return err
172- }
173- defer responseBody .Close ()
174-
175- out := cli .Out ()
176- if opts .quiet {
177- out = streams .NewOut (io .Discard )
178- }
179- return jsonstream .Display (ctx , responseBody , out )
180- }
181-
182154// TrustedReference returns the canonical trusted reference for an image reference
183155func TrustedReference (ctx context.Context , cli command.Cli , ref reference.NamedTagged ) (reference.Canonical , error ) {
184156 imgRefAndAuth , err := trust .GetImageReferencesAndAuth (ctx , authResolver (cli ), ref .String ())
185157 if err != nil {
186158 return nil , err
187159 }
188160
189- notaryRepo , err := newNotaryClient (cli , imgRefAndAuth )
161+ notaryRepo , err := newNotaryClient (cli , imgRefAndAuth . RepoInfo (), imgRefAndAuth . AuthConfig () )
190162 if err != nil {
191163 return nil , fmt .Errorf ("error establishing connection to trust repository: %w" , err )
192164 }
0 commit comments