Skip to content

Commit f235ce3

Browse files
committed
preserve error type in loginoptions
1 parent ea8f407 commit f235ce3

File tree

8 files changed

+15
-14
lines changed

8 files changed

+15
-14
lines changed

Diff for: pkg/oc/bootstrap/docker/openshift/login.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
// Login logs into the specified server using given credentials and CA file
21-
func Login(username, password, server, configDir string, f *clientcmd.Factory, c *cobra.Command, out io.Writer) error {
21+
func Login(username, password, server, configDir string, f *clientcmd.Factory, c *cobra.Command, out, errOut io.Writer) error {
2222
existingConfig, err := f.OpenShiftClientConfig().RawConfig()
2323
if err != nil {
2424
if !os.IsNotExist(err) {
@@ -72,6 +72,7 @@ func Login(username, password, server, configDir string, f *clientcmd.Factory, c
7272
Username: username,
7373
Password: password,
7474
Out: output,
75+
ErrOut: errOut,
7576
StartingKubeConfig: newConfig,
7677
PathOptions: config.NewPathOptions(c),
7778
}

Diff for: pkg/oc/bootstrap/docker/up.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7+
"io/ioutil"
78
"net"
89
"os"
910
"path/filepath"
@@ -1112,7 +1113,7 @@ func (c *ClientStartConfig) RegisterTemplateServiceBroker(out io.Writer) error {
11121113
// Login logs into the new server and sets up a default user and project
11131114
func (c *ClientStartConfig) Login(out io.Writer) error {
11141115
server := c.OpenShiftHelper().Master(c.ServerIP)
1115-
return openshift.Login(initialUser, initialPassword, server, c.LocalConfigDir, c.originalFactory, c.command, out)
1116+
return openshift.Login(initialUser, initialPassword, server, c.LocalConfigDir, c.originalFactory, c.command, out, out)
11161117
}
11171118

11181119
// CreateProject creates a new project for the current user

Diff for: pkg/oc/cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
8686

8787
f := clientcmd.New(cmds.PersistentFlags())
8888

89-
loginCmd := login.NewCmdLogin(fullName, f, in, out)
89+
loginCmd := login.NewCmdLogin(fullName, f, in, out, errout)
9090
secretcmds := secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, in, out, errout, fullName+" edit")
9191

9292
groups := ktemplates.CommandGroups{

Diff for: pkg/oc/cli/cmd/login/login.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ var (
4646
)
4747

4848
// NewCmdLogin implements the OpenShift cli login command
49-
func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out io.Writer) *cobra.Command {
49+
func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out, errOut io.Writer) *cobra.Command {
5050
options := &LoginOptions{
5151
Reader: reader,
5252
Out: out,
53+
ErrOut: errOut,
5354
}
5455

5556
cmds := &cobra.Command{

Diff for: pkg/oc/cli/cmd/login/loginoptions.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"net"
10-
"net/http"
1110
"os"
1211
"path/filepath"
1312
"time"
@@ -56,6 +55,7 @@ type LoginOptions struct {
5655
Config *restclient.Config
5756
Reader io.Reader
5857
Out io.Writer
58+
ErrOut io.Writer
5959

6060
// cert data to be used when authenticating
6161
CertFile string
@@ -226,15 +226,10 @@ func (o *LoginOptions) gatherAuthInfo() error {
226226
token, err := tokencmd.RequestToken(o.Config, o.Reader, o.Username, o.Password)
227227
if err != nil {
228228
suggestion := "verify you have provided the correct host and port and that the server is currently running."
229+
fmt.Fprintf(o.ErrOut, "error: %v - %v\n", err, suggestion)
229230

230-
// if internal error occurs, suggest making sure
231-
// client is connecting to the right host:port
232-
if statusErr, ok := err.(*kerrors.StatusError); ok {
233-
if statusErr.Status().Code == http.StatusInternalServerError {
234-
return fmt.Errorf("error: The server was unable to respond - %v", suggestion)
235-
}
236-
}
237-
return fmt.Errorf("%v - %v", err, suggestion)
231+
// return error as-is, as method caller expects to check its type
232+
return err
238233
}
239234
clientConfig.BearerToken = token
240235

Diff for: test/integration/login_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ func newLoginOptions(server string, username string, password string, insecure b
139139
Password: password,
140140
InsecureTLS: insecure,
141141

142-
Out: ioutil.Discard,
142+
Out: ioutil.Discard,
143+
ErrOut: ioutil.Discard,
143144
}
144145

145146
return loginOptions

Diff for: test/integration/oauth_oidc_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func TestOAuthOIDC(t *testing.T) {
162162
StartingKubeConfig: &clientcmdapi.Config{},
163163
Reader: bytes.NewBufferString("mylogin\nmypassword\n"),
164164
Out: loginOutput,
165+
ErrOut: ioutil.Discard,
165166
}
166167
if err := loginOptions.GatherInfo(); err != nil {
167168
t.Fatalf("Error logging in: %v\n%v", err, loginOutput.String())

Diff for: test/integration/oauth_request_header_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func TestOAuthRequestHeader(t *testing.T) {
310310
StartingKubeConfig: &clientcmdapi.Config{},
311311
Reader: bytes.NewBufferString("myusername\nmypassword\n"),
312312
Out: loginOutput,
313+
ErrOut: ioutil.Discard,
313314
}
314315
if err := loginOptions.GatherInfo(); err != nil {
315316
t.Fatalf("Error trying to determine server info: %v\n%v", err, loginOutput.String())

0 commit comments

Comments
 (0)