@@ -30,6 +30,20 @@ type target struct {
3030 size int64
3131}
3232
33+ // notaryClientProvider is used in tests to provide a dummy notary client.
34+ type notaryClientProvider interface {
35+ NotaryClient (imgRefAndAuth trust.ImageRefAndAuth , actions []string ) (client.Repository , error )
36+ }
37+
38+ // newNotaryClient provides a Notary Repository to interact with signed metadata for an image.
39+ func newNotaryClient (cli command.Streams , imgRefAndAuth trust.ImageRefAndAuth ) (client.Repository , error ) {
40+ if ncp , ok := cli .(notaryClientProvider ); ok {
41+ // notaryClientProvider is used in tests to provide a dummy notary client.
42+ return ncp .NotaryClient (imgRefAndAuth , []string {"pull" })
43+ }
44+ return trust .GetNotaryRepository (cli .In (), cli .Out (), command .UserAgent (), imgRefAndAuth .RepoInfo (), imgRefAndAuth .AuthConfig (), "pull" )
45+ }
46+
3347// TrustedPush handles content trust pushing of an image
3448func TrustedPush (ctx context.Context , cli command.Cli , repoInfo * registry.RepositoryInfo , ref reference.Named , authConfig registrytypes.AuthConfig , options image.PushOptions ) error {
3549 responseBody , err := cli .Client ().ImagePush (ctx , reference .FamiliarString (ref ), options )
@@ -200,7 +214,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
200214}
201215
202216func getTrustedPullTargets (cli command.Cli , imgRefAndAuth trust.ImageRefAndAuth ) ([]target , error ) {
203- notaryRepo , err := cli . NotaryClient ( imgRefAndAuth , trust . ActionsPullOnly )
217+ notaryRepo , err := newNotaryClient ( cli , imgRefAndAuth )
204218 if err != nil {
205219 return nil , errors .Wrap (err , "error establishing connection to trust repository" )
206220 }
@@ -280,7 +294,7 @@ func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedT
280294 return nil , err
281295 }
282296
283- notaryRepo , err := cli . NotaryClient ( imgRefAndAuth , [] string { "pull" } )
297+ notaryRepo , err := newNotaryClient ( cli , imgRefAndAuth )
284298 if err != nil {
285299 return nil , errors .Wrap (err , "error establishing connection to trust repository" )
286300 }
0 commit comments