From 4477cad33d9f36583e10905fd3ac4141b17ec0a7 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 1 Nov 2017 21:09:09 -0400 Subject: [PATCH] preserve error type in loginoptions --- pkg/oc/bootstrap/docker/openshift/login.go | 3 ++- pkg/oc/bootstrap/docker/up.go | 3 ++- pkg/oc/cli/cli.go | 2 +- pkg/oc/cli/cmd/login/login.go | 3 ++- pkg/oc/cli/cmd/login/loginoptions.go | 1 - test/integration/login_test.go | 3 ++- test/integration/oauth_oidc_test.go | 2 ++ test/integration/oauth_request_header_test.go | 2 ++ 8 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/oc/bootstrap/docker/openshift/login.go b/pkg/oc/bootstrap/docker/openshift/login.go index 2d17b8b4f97b..d7dfe00f950a 100644 --- a/pkg/oc/bootstrap/docker/openshift/login.go +++ b/pkg/oc/bootstrap/docker/openshift/login.go @@ -18,7 +18,7 @@ import ( ) // Login logs into the specified server using given credentials and CA file -func Login(username, password, server, configDir string, f *clientcmd.Factory, c *cobra.Command, out io.Writer) error { +func Login(username, password, server, configDir string, f *clientcmd.Factory, c *cobra.Command, out, errOut io.Writer) error { existingConfig, err := f.OpenShiftClientConfig().RawConfig() if err != nil { if !os.IsNotExist(err) { @@ -72,6 +72,7 @@ func Login(username, password, server, configDir string, f *clientcmd.Factory, c Username: username, Password: password, Out: output, + ErrOut: errOut, StartingKubeConfig: newConfig, PathOptions: config.NewPathOptions(c), } diff --git a/pkg/oc/bootstrap/docker/up.go b/pkg/oc/bootstrap/docker/up.go index 0d554f313534..5e3e5312d12f 100644 --- a/pkg/oc/bootstrap/docker/up.go +++ b/pkg/oc/bootstrap/docker/up.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "io/ioutil" "net" "os" "path/filepath" @@ -1112,7 +1113,7 @@ func (c *ClientStartConfig) RegisterTemplateServiceBroker(out io.Writer) error { // Login logs into the new server and sets up a default user and project func (c *ClientStartConfig) Login(out io.Writer) error { server := c.OpenShiftHelper().Master(c.ServerIP) - return openshift.Login(initialUser, initialPassword, server, c.LocalConfigDir, c.originalFactory, c.command, out) + return openshift.Login(initialUser, initialPassword, server, c.LocalConfigDir, c.originalFactory, c.command, out, ioutil.Discard) } // CreateProject creates a new project for the current user diff --git a/pkg/oc/cli/cli.go b/pkg/oc/cli/cli.go index 68797546c626..a93111926948 100644 --- a/pkg/oc/cli/cli.go +++ b/pkg/oc/cli/cli.go @@ -86,7 +86,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) * f := clientcmd.New(cmds.PersistentFlags()) - loginCmd := login.NewCmdLogin(fullName, f, in, out) + loginCmd := login.NewCmdLogin(fullName, f, in, out, errout) secretcmds := secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, in, out, errout, fullName+" edit") groups := ktemplates.CommandGroups{ diff --git a/pkg/oc/cli/cmd/login/login.go b/pkg/oc/cli/cmd/login/login.go index d259ffcbaa86..a139a2a77d6f 100644 --- a/pkg/oc/cli/cmd/login/login.go +++ b/pkg/oc/cli/cmd/login/login.go @@ -46,10 +46,11 @@ var ( ) // NewCmdLogin implements the OpenShift cli login command -func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out io.Writer) *cobra.Command { +func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out, errOut io.Writer) *cobra.Command { options := &LoginOptions{ Reader: reader, Out: out, + ErrOut: errOut, } cmds := &cobra.Command{ diff --git a/pkg/oc/cli/cmd/login/loginoptions.go b/pkg/oc/cli/cmd/login/loginoptions.go index aafde886592a..916f56e97664 100644 --- a/pkg/oc/cli/cmd/login/loginoptions.go +++ b/pkg/oc/cli/cmd/login/loginoptions.go @@ -238,7 +238,6 @@ func (o *LoginOptions) gatherAuthInfo() error { fmt.Fprintf(o.ErrOut, "error: %v - %v\n", err, suggestion) } - // TODO: set errout // return error as-is, as method caller expects to check its type return err } diff --git a/test/integration/login_test.go b/test/integration/login_test.go index 6d0985bdcd60..e8d39036e422 100644 --- a/test/integration/login_test.go +++ b/test/integration/login_test.go @@ -139,7 +139,8 @@ func newLoginOptions(server string, username string, password string, insecure b Password: password, InsecureTLS: insecure, - Out: ioutil.Discard, + Out: ioutil.Discard, + ErrOut: ioutil.Discard, } return loginOptions diff --git a/test/integration/oauth_oidc_test.go b/test/integration/oauth_oidc_test.go index 5604c7c87dec..eff2fdf135ea 100644 --- a/test/integration/oauth_oidc_test.go +++ b/test/integration/oauth_oidc_test.go @@ -156,12 +156,14 @@ func TestOAuthOIDC(t *testing.T) { // Attempt a login using a redirecting auth proxy loginOutput := &bytes.Buffer{} + loginErrOutput := &bytes.Buffer{} loginOptions := &login.LoginOptions{ Server: clientConfig.Host, CAFile: masterCAFile, StartingKubeConfig: &clientcmdapi.Config{}, Reader: bytes.NewBufferString("mylogin\nmypassword\n"), Out: loginOutput, + ErrOut: loginErrOutput, } if err := loginOptions.GatherInfo(); err != nil { t.Fatalf("Error logging in: %v\n%v", err, loginOutput.String()) diff --git a/test/integration/oauth_request_header_test.go b/test/integration/oauth_request_header_test.go index fe4fa55b33a4..98af30a23a46 100644 --- a/test/integration/oauth_request_header_test.go +++ b/test/integration/oauth_request_header_test.go @@ -304,12 +304,14 @@ func TestOAuthRequestHeader(t *testing.T) { // Attempt a login using a redirecting auth proxy loginOutput := &bytes.Buffer{} + loginErrOutput := &bytes.Buffer{} loginOptions := &login.LoginOptions{ Server: anonConfig.Host, CAFile: masterCAFile, StartingKubeConfig: &clientcmdapi.Config{}, Reader: bytes.NewBufferString("myusername\nmypassword\n"), Out: loginOutput, + ErrOut: loginErrOutput, } if err := loginOptions.GatherInfo(); err != nil { t.Fatalf("Error trying to determine server info: %v\n%v", err, loginOutput.String())