mirror of https://github.com/helm/helm.git
Remove LoginResult/LogoutResult types
Signed-off-by: Josh Dolitsky <josh@dolit.ski>
This commit is contained in:
parent
593eac8876
commit
8202ccd699
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
if err := c.authorizer.Logout(ctx(c.out, c.debug), host); err != nil {
|
||||
return err
|
||||
}
|
||||
result := &LogoutResult{
|
||||
Host: host,
|
||||
}
|
||||
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 (
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue