From a6946d0fbf8ca1cfeb2c566b6299e9ba2bed7843 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 26 Sep 2025 18:53:04 +0200 Subject: [PATCH] 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 --- cli/command/image/trust.go | 12 ++++++------ cli/command/trust/common.go | 4 ++-- cli/command/trust/inspect_test.go | 5 ++--- cli/command/trust/revoke_test.go | 3 +-- internal/test/cli.go | 7 +++---- internal/test/notary/client.go | 11 +++++------ 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index 55b1ff401..eecbf3263 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -31,16 +31,16 @@ type target struct { // notaryClientProvider is used in tests to provide a dummy notary client. type notaryClientProvider interface { - NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) + NotaryClient() (notaryclient.Repository, error) } // newNotaryClient provides a Notary Repository to interact with signed metadata for an image. -func newNotaryClient(cli command.Streams, imgRefAndAuth trust.ImageRefAndAuth) (notaryclient.Repository, error) { +func newNotaryClient(cli command.Streams, repoInfo *trust.RepositoryInfo, authConfig *registrytypes.AuthConfig) (notaryclient.Repository, error) { if ncp, ok := cli.(notaryClientProvider); ok { // notaryClientProvider is used in tests to provide a dummy notary client. - return ncp.NotaryClient(imgRefAndAuth, []string{"pull"}) + return ncp.NotaryClient() } - return trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig(), "pull") + return trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, authConfig, "pull") } // pushTrustedReference pushes a canonical reference to the trust server. @@ -107,7 +107,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image } func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) ([]target, error) { - notaryRepo, err := newNotaryClient(cli, imgRefAndAuth) + notaryRepo, err := newNotaryClient(cli, imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig()) if err != nil { return nil, fmt.Errorf("error establishing connection to trust repository: %w", err) } @@ -186,7 +186,7 @@ func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedT return nil, err } - notaryRepo, err := newNotaryClient(cli, imgRefAndAuth) + notaryRepo, err := newNotaryClient(cli, imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig()) if err != nil { return nil, fmt.Errorf("error establishing connection to trust repository: %w", err) } diff --git a/cli/command/trust/common.go b/cli/command/trust/common.go index 615051774..437b43972 100644 --- a/cli/command/trust/common.go +++ b/cli/command/trust/common.go @@ -52,14 +52,14 @@ type trustKey struct { // notaryClientProvider is used in tests to provide a dummy notary client. type notaryClientProvider interface { - NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (client.Repository, error) + NotaryClient() (client.Repository, error) } // newNotaryClient provides a Notary Repository to interact with signed metadata for an image. func newNotaryClient(cli command.Streams, imgRefAndAuth trust.ImageRefAndAuth, actions []string) (client.Repository, error) { if ncp, ok := cli.(notaryClientProvider); ok { // notaryClientProvider is used in tests to provide a dummy notary client. - return ncp.NotaryClient(imgRefAndAuth, actions) + return ncp.NotaryClient() } return trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig(), actions...) } diff --git a/cli/command/trust/inspect_test.go b/cli/command/trust/inspect_test.go index 5823f3290..1f0333461 100644 --- a/cli/command/trust/inspect_test.go +++ b/cli/command/trust/inspect_test.go @@ -4,7 +4,6 @@ import ( "io" "testing" - "github.com/docker/cli/cli/trust" "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/notary" "github.com/theupdateframework/notary/client" @@ -48,7 +47,7 @@ func TestTrustInspectCommandRepositoryErrors(t *testing.T) { testCases := []struct { doc string args []string - notaryRepository func(trust.ImageRefAndAuth, []string) (client.Repository, error) + notaryRepository func() (client.Repository, error) err string golden string }{ @@ -100,7 +99,7 @@ func TestTrustInspectCommand(t *testing.T) { testCases := []struct { doc string args []string - notaryRepository func(trust.ImageRefAndAuth, []string) (client.Repository, error) + notaryRepository func() (client.Repository, error) golden string }{ { diff --git a/cli/command/trust/revoke_test.go b/cli/command/trust/revoke_test.go index da1e48ecf..8ec078c8e 100644 --- a/cli/command/trust/revoke_test.go +++ b/cli/command/trust/revoke_test.go @@ -5,7 +5,6 @@ import ( "io" "testing" - "github.com/docker/cli/cli/trust" "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/notary" "github.com/theupdateframework/notary/client" @@ -60,7 +59,7 @@ func TestTrustRevokeCommand(t *testing.T) { testCases := []struct { doc string - notaryRepository func(trust.ImageRefAndAuth, []string) (client.Repository, error) + notaryRepository func() (client.Repository, error) args []string expectedErr string expectedMessage string diff --git a/internal/test/cli.go b/internal/test/cli.go index 8a3a69dea..175a10d17 100644 --- a/internal/test/cli.go +++ b/internal/test/cli.go @@ -12,14 +12,13 @@ import ( "github.com/docker/cli/cli/context/store" manifeststore "github.com/docker/cli/cli/manifest/store" "github.com/docker/cli/cli/streams" - "github.com/docker/cli/cli/trust" "github.com/docker/cli/internal/registryclient" "github.com/moby/moby/client" notaryclient "github.com/theupdateframework/notary/client" ) // NotaryClientFuncType defines a function that returns a fake notary client -type NotaryClientFuncType func(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) +type NotaryClientFuncType func() (notaryclient.Repository, error) // FakeCli emulates the default DockerCli type FakeCli struct { @@ -169,9 +168,9 @@ func (c *FakeCli) SetNotaryClient(notaryClientFunc NotaryClientFuncType) { } // NotaryClient returns an err for testing unless defined -func (c *FakeCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) { +func (c *FakeCli) NotaryClient() (notaryclient.Repository, error) { if c.notaryClientFunc != nil { - return c.notaryClientFunc(imgRefAndAuth, actions) + return c.notaryClientFunc() } return nil, errors.New("no notary client available unless defined") } diff --git a/internal/test/notary/client.go b/internal/test/notary/client.go index a948ad62c..fde935afa 100644 --- a/internal/test/notary/client.go +++ b/internal/test/notary/client.go @@ -1,7 +1,6 @@ package notary import ( - "github.com/docker/cli/cli/trust" "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/client/changelist" "github.com/theupdateframework/notary/cryptoservice" @@ -12,7 +11,7 @@ import ( ) // GetOfflineNotaryRepository returns a OfflineNotaryRepository -func GetOfflineNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) { +func GetOfflineNotaryRepository() (client.Repository, error) { return OfflineNotaryRepository{}, nil } @@ -146,7 +145,7 @@ func (OfflineNotaryRepository) GetGUN() data.GUN { } // GetUninitializedNotaryRepository returns an UninitializedNotaryRepository -func GetUninitializedNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) { +func GetUninitializedNotaryRepository() (client.Repository, error) { return UninitializedNotaryRepository{}, nil } @@ -207,7 +206,7 @@ func (UninitializedNotaryRepository) RotateKey(data.RoleName, bool, []string) er } // GetEmptyTargetsNotaryRepository returns an EmptyTargetsNotaryRepository -func GetEmptyTargetsNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) { +func GetEmptyTargetsNotaryRepository() (client.Repository, error) { return EmptyTargetsNotaryRepository{}, nil } @@ -285,7 +284,7 @@ func (EmptyTargetsNotaryRepository) RotateKey(data.RoleName, bool, []string) err } // GetLoadedNotaryRepository returns a LoadedNotaryRepository -func GetLoadedNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) { +func GetLoadedNotaryRepository() (client.Repository, error) { return LoadedNotaryRepository{}, nil } @@ -511,7 +510,7 @@ func (l LoadedNotaryRepository) GetCryptoService() signed.CryptoService { } // GetLoadedWithNoSignersNotaryRepository returns a LoadedWithNoSignersNotaryRepository -func GetLoadedWithNoSignersNotaryRepository(trust.ImageRefAndAuth, []string) (client.Repository, error) { +func GetLoadedWithNoSignersNotaryRepository() (client.Repository, error) { return LoadedWithNoSignersNotaryRepository{}, nil }