From 8202ccd6998e6bf8aa34c8d9d7527e08d326397b Mon Sep 17 00:00:00 2001 From: Josh Dolitsky Date: Wed, 7 Jul 2021 15:44:43 -0500 Subject: [PATCH] Remove LoginResult/LogoutResult types Signed-off-by: Josh Dolitsky --- .../experimental/action/registry_login.go | 3 +- .../experimental/action/registry_logout.go | 3 +- internal/experimental/registry/client.go | 36 +++++-------------- internal/experimental/registry/client_test.go | 15 ++++---- pkg/repo/repotest/server.go | 2 +- 5 files changed, 18 insertions(+), 41 deletions(-) diff --git a/internal/experimental/action/registry_login.go b/internal/experimental/action/registry_login.go index 5e9f97db7..8312f3c57 100644 --- a/internal/experimental/action/registry_login.go +++ b/internal/experimental/action/registry_login.go @@ -37,9 +37,8 @@ func NewRegistryLogin(cfg *action.Configuration) *RegistryLogin { // Run executes the registry login operation func (a *RegistryLogin) Run(out io.Writer, hostname string, username string, password string, insecure bool) error { - _, err := a.cfg.RegistryClient.Login( + return a.cfg.RegistryClient.Login( hostname, registry.LoginOptBasicAuth(username, password), registry.LoginOptInsecure(insecure)) - return err } diff --git a/internal/experimental/action/registry_logout.go b/internal/experimental/action/registry_logout.go index 092e4adb8..039515c7e 100644 --- a/internal/experimental/action/registry_logout.go +++ b/internal/experimental/action/registry_logout.go @@ -36,6 +36,5 @@ func NewRegistryLogout(cfg *action.Configuration) *RegistryLogout { // Run executes the registry logout operation func (a *RegistryLogout) Run(out io.Writer, hostname string) error { - _, err := a.cfg.RegistryClient.Logout(hostname) - return err + return a.cfg.RegistryClient.Logout(hostname) } diff --git a/internal/experimental/registry/client.go b/internal/experimental/registry/client.go index 820d94195..2e8b089aa 100644 --- a/internal/experimental/registry/client.go +++ b/internal/experimental/registry/client.go @@ -109,11 +109,6 @@ type ( // LoginOption allows specifying various settings on login LoginOption func(*loginOperation) - // LoginResult is the result returned upon successful login - LoginResult struct { - Host string `json:"host"` - } - loginOperation struct { username string password string @@ -122,7 +117,7 @@ type ( ) // Login logs into a registry -func (c *Client) Login(host string, options ...LoginOption) (*LoginResult, error) { +func (c *Client) Login(host string, options ...LoginOption) error { operation := &loginOperation{} for _, option := range options { option(operation) @@ -137,15 +132,11 @@ func (c *Client) Login(host string, options ...LoginOption) (*LoginResult, error if operation.insecure { authorizerLoginOpts = append(authorizerLoginOpts, auth.WithLoginInsecure()) } - err := c.authorizer.LoginWithOpts(authorizerLoginOpts...) - if err != nil { - return nil, err - } - result := &LoginResult{ - Host: host, + if err := c.authorizer.LoginWithOpts(authorizerLoginOpts...); err != nil { + return err } fmt.Fprintln(c.out, "Login Succeeded") - return result, nil + return nil } // LoginOptBasicAuth returns a function that sets the username/password settings on login @@ -167,29 +158,20 @@ type ( // LogoutOption allows specifying various settings on logout LogoutOption func(*logoutOperation) - // LogoutResult is the result returned upon successful logout. - LogoutResult struct { - Host string `json:"host"` - } - logoutOperation struct{} ) // Logout logs out of a registry -func (c *Client) Logout(host string, opts ...LogoutOption) (*LogoutResult, error) { +func (c *Client) Logout(host string, opts ...LogoutOption) error { operation := &logoutOperation{} for _, opt := range opts { opt(operation) } - err := c.authorizer.Logout(ctx(c.out, c.debug), host) - if err != nil { - return nil, err - } - result := &LogoutResult{ - Host: host, + if err := c.authorizer.Logout(ctx(c.out, c.debug), host); err != nil { + return err } - fmt.Fprintf(c.out, "Removing login credentials for %s\n", result.Host) - return result, nil + fmt.Fprintf(c.out, "Removing login credentials for %s\n", host) + return nil } type ( diff --git a/internal/experimental/registry/client_test.go b/internal/experimental/registry/client_test.go index c402731f9..90e0174a9 100644 --- a/internal/experimental/registry/client_test.go +++ b/internal/experimental/registry/client_test.go @@ -110,27 +110,25 @@ func (suite *RegistryClientTestSuite) TearDownSuite() { } func (suite *RegistryClientTestSuite) Test_0_Login() { - _, err := suite.RegistryClient.Login(suite.DockerRegistryHost, + err := suite.RegistryClient.Login(suite.DockerRegistryHost, LoginOptBasicAuth("badverybad", "ohsobad"), LoginOptInsecure(false)) suite.NotNil(err, "error logging into registry with bad credentials") - _, err = suite.RegistryClient.Login(suite.DockerRegistryHost, + err = suite.RegistryClient.Login(suite.DockerRegistryHost, LoginOptBasicAuth("badverybad", "ohsobad"), LoginOptInsecure(true)) suite.NotNil(err, "error logging into registry with bad credentials, insecure mode") - result, err := suite.RegistryClient.Login(suite.DockerRegistryHost, + err = suite.RegistryClient.Login(suite.DockerRegistryHost, LoginOptBasicAuth(testUsername, testPassword), LoginOptInsecure(false)) suite.Nil(err, "no error logging into registry with good credentials") - suite.Equal(suite.DockerRegistryHost, result.Host, "result.Host is as expected") - _, err = suite.RegistryClient.Login(suite.DockerRegistryHost, + err = suite.RegistryClient.Login(suite.DockerRegistryHost, LoginOptBasicAuth(testUsername, testPassword), LoginOptInsecure(true)) suite.Nil(err, "no error logging into registry with good credentials, insecure mode") - suite.Equal(suite.DockerRegistryHost, result.Host, "result.Host is as expected") } func (suite *RegistryClientTestSuite) Test_1_Push() { @@ -297,12 +295,11 @@ func (suite *RegistryClientTestSuite) Test_2_Pull() { } func (suite *RegistryClientTestSuite) Test_3_Logout() { - _, err := suite.RegistryClient.Logout("this-host-aint-real:5000") + err := suite.RegistryClient.Logout("this-host-aint-real:5000") suite.NotNil(err, "error logging out of registry that has no entry") - result, err := suite.RegistryClient.Logout(suite.DockerRegistryHost) + err = suite.RegistryClient.Logout(suite.DockerRegistryHost) suite.Nil(err, "no error logging out of registry") - suite.Equal(suite.DockerRegistryHost, result.Host, "result.Host is as expected") } func (suite *RegistryClientTestSuite) Test_4_ManInTheMiddle() { diff --git a/pkg/repo/repotest/server.go b/pkg/repo/repotest/server.go index 56585a749..40d8783c5 100644 --- a/pkg/repo/repotest/server.go +++ b/pkg/repo/repotest/server.go @@ -143,7 +143,7 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) { t.Fatalf("error creating registry client") } - _, err = registryClient.Login( + err = registryClient.Login( srv.RegistryURL, ociRegistry.LoginOptBasicAuth(srv.TestUsername, srv.TestPassword), ociRegistry.LoginOptInsecure(false))