Remove LoginResult/LogoutResult types

Signed-off-by: Josh Dolitsky <josh@dolit.ski>
pull/9782/head
Josh Dolitsky 3 years ago
parent 593eac8876
commit 8202ccd699
No known key found for this signature in database
GPG Key ID: B2B93673243A65FB

@ -37,9 +37,8 @@ func NewRegistryLogin(cfg *action.Configuration) *RegistryLogin {
// Run executes the registry login operation // Run executes the registry login operation
func (a *RegistryLogin) Run(out io.Writer, hostname string, username string, password string, insecure bool) error { 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, hostname,
registry.LoginOptBasicAuth(username, password), registry.LoginOptBasicAuth(username, password),
registry.LoginOptInsecure(insecure)) registry.LoginOptInsecure(insecure))
return err
} }

@ -36,6 +36,5 @@ func NewRegistryLogout(cfg *action.Configuration) *RegistryLogout {
// Run executes the registry logout operation // Run executes the registry logout operation
func (a *RegistryLogout) Run(out io.Writer, hostname string) error { func (a *RegistryLogout) Run(out io.Writer, hostname string) error {
_, err := a.cfg.RegistryClient.Logout(hostname) return a.cfg.RegistryClient.Logout(hostname)
return err
} }

@ -109,11 +109,6 @@ type (
// LoginOption allows specifying various settings on login // LoginOption allows specifying various settings on login
LoginOption func(*loginOperation) LoginOption func(*loginOperation)
// LoginResult is the result returned upon successful login
LoginResult struct {
Host string `json:"host"`
}
loginOperation struct { loginOperation struct {
username string username string
password string password string
@ -122,7 +117,7 @@ type (
) )
// Login logs into a registry // 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{} operation := &loginOperation{}
for _, option := range options { for _, option := range options {
option(operation) option(operation)
@ -137,15 +132,11 @@ func (c *Client) Login(host string, options ...LoginOption) (*LoginResult, error
if operation.insecure { if operation.insecure {
authorizerLoginOpts = append(authorizerLoginOpts, auth.WithLoginInsecure()) authorizerLoginOpts = append(authorizerLoginOpts, auth.WithLoginInsecure())
} }
err := c.authorizer.LoginWithOpts(authorizerLoginOpts...) if err := c.authorizer.LoginWithOpts(authorizerLoginOpts...); err != nil {
if err != nil { return err
return nil, err
}
result := &LoginResult{
Host: host,
} }
fmt.Fprintln(c.out, "Login Succeeded") fmt.Fprintln(c.out, "Login Succeeded")
return result, nil return nil
} }
// LoginOptBasicAuth returns a function that sets the username/password settings on login // 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 allows specifying various settings on logout
LogoutOption func(*logoutOperation) LogoutOption func(*logoutOperation)
// LogoutResult is the result returned upon successful logout.
LogoutResult struct {
Host string `json:"host"`
}
logoutOperation struct{} logoutOperation struct{}
) )
// Logout logs out of a registry // 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{} operation := &logoutOperation{}
for _, opt := range opts { for _, opt := range opts {
opt(operation) opt(operation)
} }
err := c.authorizer.Logout(ctx(c.out, c.debug), host) if err := c.authorizer.Logout(ctx(c.out, c.debug), host); err != nil {
if err != nil { return err
return nil, err
}
result := &LogoutResult{
Host: host,
} }
fmt.Fprintf(c.out, "Removing login credentials for %s\n", result.Host) fmt.Fprintf(c.out, "Removing login credentials for %s\n", host)
return result, nil return nil
} }
type ( type (

@ -110,27 +110,25 @@ func (suite *RegistryClientTestSuite) TearDownSuite() {
} }
func (suite *RegistryClientTestSuite) Test_0_Login() { func (suite *RegistryClientTestSuite) Test_0_Login() {
_, err := suite.RegistryClient.Login(suite.DockerRegistryHost, err := suite.RegistryClient.Login(suite.DockerRegistryHost,
LoginOptBasicAuth("badverybad", "ohsobad"), LoginOptBasicAuth("badverybad", "ohsobad"),
LoginOptInsecure(false)) LoginOptInsecure(false))
suite.NotNil(err, "error logging into registry with bad credentials") 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"), LoginOptBasicAuth("badverybad", "ohsobad"),
LoginOptInsecure(true)) LoginOptInsecure(true))
suite.NotNil(err, "error logging into registry with bad credentials, insecure mode") 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), LoginOptBasicAuth(testUsername, testPassword),
LoginOptInsecure(false)) LoginOptInsecure(false))
suite.Nil(err, "no error logging into registry with good credentials") 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), LoginOptBasicAuth(testUsername, testPassword),
LoginOptInsecure(true)) LoginOptInsecure(true))
suite.Nil(err, "no error logging into registry with good credentials, insecure mode") 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() { func (suite *RegistryClientTestSuite) Test_1_Push() {
@ -297,12 +295,11 @@ func (suite *RegistryClientTestSuite) Test_2_Pull() {
} }
func (suite *RegistryClientTestSuite) Test_3_Logout() { 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") 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.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() { func (suite *RegistryClientTestSuite) Test_4_ManInTheMiddle() {

@ -143,7 +143,7 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) {
t.Fatalf("error creating registry client") t.Fatalf("error creating registry client")
} }
_, err = registryClient.Login( err = registryClient.Login(
srv.RegistryURL, srv.RegistryURL,
ociRegistry.LoginOptBasicAuth(srv.TestUsername, srv.TestPassword), ociRegistry.LoginOptBasicAuth(srv.TestUsername, srv.TestPassword),
ociRegistry.LoginOptInsecure(false)) ociRegistry.LoginOptInsecure(false))

Loading…
Cancel
Save