Skip to content

Commit 6ea40bd

Browse files
committed
cli/command/image: notaryClientProvider: don't require arguments
This interface is used in tests to provide a dummy notary client, but none of the tests require any arguments, so let's remove them. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c3317b0 commit 6ea40bd

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

cli/command/image/trust.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ type target struct {
3131

3232
// notaryClientProvider is used in tests to provide a dummy notary client.
3333
type notaryClientProvider interface {
34-
NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
34+
NotaryClient() (notaryclient.Repository, error)
3535
}
3636

3737
// 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) {
38+
func newNotaryClient(cli command.Streams, repoInfo *trust.RepositoryInfo, authConfig *registrytypes.AuthConfig) (notaryclient.Repository, error) {
3939
if ncp, ok := cli.(notaryClientProvider); ok {
4040
// notaryClientProvider is used in tests to provide a dummy notary client.
41-
return ncp.NotaryClient(imgRefAndAuth, []string{"pull"})
41+
return ncp.NotaryClient()
4242
}
43-
return trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig(), "pull")
43+
return trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, authConfig, "pull")
4444
}
4545

4646
// pushTrustedReference pushes a canonical reference to the trust server.
@@ -107,7 +107,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
107107
}
108108

109109
func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) ([]target, error) {
110-
notaryRepo, err := newNotaryClient(cli, imgRefAndAuth)
110+
notaryRepo, err := newNotaryClient(cli, imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig())
111111
if err != nil {
112112
return nil, fmt.Errorf("error establishing connection to trust repository: %w", err)
113113
}
@@ -186,7 +186,7 @@ func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedT
186186
return nil, err
187187
}
188188

189-
notaryRepo, err := newNotaryClient(cli, imgRefAndAuth)
189+
notaryRepo, err := newNotaryClient(cli, imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig())
190190
if err != nil {
191191
return nil, fmt.Errorf("error establishing connection to trust repository: %w", err)
192192
}

cli/command/trust/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ type trustKey struct {
5252

5353
// notaryClientProvider is used in tests to provide a dummy notary client.
5454
type notaryClientProvider interface {
55-
NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (client.Repository, error)
55+
NotaryClient(actions []string) (client.Repository, error)
5656
}
5757

5858
// newNotaryClient provides a Notary Repository to interact with signed metadata for an image.
5959
func newNotaryClient(cli command.Streams, imgRefAndAuth trust.ImageRefAndAuth, actions []string) (client.Repository, error) {
6060
if ncp, ok := cli.(notaryClientProvider); ok {
6161
// notaryClientProvider is used in tests to provide a dummy notary client.
62-
return ncp.NotaryClient(imgRefAndAuth, actions)
62+
return ncp.NotaryClient(actions)
6363
}
6464
return trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig(), actions...)
6565
}

internal/test/cli.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import (
1212
"github.com/docker/cli/cli/context/store"
1313
manifeststore "github.com/docker/cli/cli/manifest/store"
1414
"github.com/docker/cli/cli/streams"
15-
"github.com/docker/cli/cli/trust"
1615
"github.com/docker/cli/internal/registryclient"
1716
"github.com/moby/moby/client"
1817
notaryclient "github.com/theupdateframework/notary/client"
1918
)
2019

2120
// NotaryClientFuncType defines a function that returns a fake notary client
22-
type NotaryClientFuncType func(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
21+
type NotaryClientFuncType func() (notaryclient.Repository, error)
2322

2423
// FakeCli emulates the default DockerCli
2524
type FakeCli struct {
@@ -169,9 +168,9 @@ func (c *FakeCli) SetNotaryClient(notaryClientFunc NotaryClientFuncType) {
169168
}
170169

171170
// NotaryClient returns an err for testing unless defined
172-
func (c *FakeCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) {
171+
func (c *FakeCli) NotaryClient() (notaryclient.Repository, error) {
173172
if c.notaryClientFunc != nil {
174-
return c.notaryClientFunc(imgRefAndAuth, actions)
173+
return c.notaryClientFunc()
175174
}
176175
return nil, errors.New("no notary client available unless defined")
177176
}

internal/test/notary/client.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package notary
22

33
import (
4-
"github.com/docker/cli/cli/trust"
54
"github.com/theupdateframework/notary/client"
65
"github.com/theupdateframework/notary/client/changelist"
76
"github.com/theupdateframework/notary/cryptoservice"
@@ -12,7 +11,7 @@ import (
1211
)
1312

1413
// GetOfflineNotaryRepository returns a OfflineNotaryRepository
15-
func GetOfflineNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) {
14+
func GetOfflineNotaryRepository() (client.Repository, error) {
1615
return OfflineNotaryRepository{}, nil
1716
}
1817

@@ -146,7 +145,7 @@ func (OfflineNotaryRepository) GetGUN() data.GUN {
146145
}
147146

148147
// GetUninitializedNotaryRepository returns an UninitializedNotaryRepository
149-
func GetUninitializedNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) {
148+
func GetUninitializedNotaryRepository() (client.Repository, error) {
150149
return UninitializedNotaryRepository{}, nil
151150
}
152151

@@ -207,7 +206,7 @@ func (UninitializedNotaryRepository) RotateKey(data.RoleName, bool, []string) er
207206
}
208207

209208
// GetEmptyTargetsNotaryRepository returns an EmptyTargetsNotaryRepository
210-
func GetEmptyTargetsNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) {
209+
func GetEmptyTargetsNotaryRepository() (client.Repository, error) {
211210
return EmptyTargetsNotaryRepository{}, nil
212211
}
213212

@@ -285,7 +284,7 @@ func (EmptyTargetsNotaryRepository) RotateKey(data.RoleName, bool, []string) err
285284
}
286285

287286
// GetLoadedNotaryRepository returns a LoadedNotaryRepository
288-
func GetLoadedNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) {
287+
func GetLoadedNotaryRepository() (client.Repository, error) {
289288
return LoadedNotaryRepository{}, nil
290289
}
291290

@@ -511,7 +510,7 @@ func (l LoadedNotaryRepository) GetCryptoService() signed.CryptoService {
511510
}
512511

513512
// GetLoadedWithNoSignersNotaryRepository returns a LoadedWithNoSignersNotaryRepository
514-
func GetLoadedWithNoSignersNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) {
513+
func GetLoadedWithNoSignersNotaryRepository([]string) (client.Repository, error) {
515514
return LoadedWithNoSignersNotaryRepository{}, nil
516515
}
517516

0 commit comments

Comments
 (0)