Skip to content

Commit 4477cad

Browse files
committed
preserve error type in loginoptions
1 parent 0074c3a commit 4477cad

File tree

8 files changed

+13
-6
lines changed

8 files changed

+13
-6
lines changed

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
}

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, ioutil.Discard)
11161117
}
11171118

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

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{

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{

pkg/oc/cli/cmd/login/loginoptions.go

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ func (o *LoginOptions) gatherAuthInfo() error {
238238
fmt.Fprintf(o.ErrOut, "error: %v - %v\n", err, suggestion)
239239
}
240240

241-
// TODO: set errout
242241
// return error as-is, as method caller expects to check its type
243242
return err
244243
}

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

test/integration/oauth_oidc_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ func TestOAuthOIDC(t *testing.T) {
156156

157157
// Attempt a login using a redirecting auth proxy
158158
loginOutput := &bytes.Buffer{}
159+
loginErrOutput := &bytes.Buffer{}
159160
loginOptions := &login.LoginOptions{
160161
Server: clientConfig.Host,
161162
CAFile: masterCAFile,
162163
StartingKubeConfig: &clientcmdapi.Config{},
163164
Reader: bytes.NewBufferString("mylogin\nmypassword\n"),
164165
Out: loginOutput,
166+
ErrOut: loginErrOutput,
165167
}
166168
if err := loginOptions.GatherInfo(); err != nil {
167169
t.Fatalf("Error logging in: %v\n%v", err, loginOutput.String())

test/integration/oauth_request_header_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,14 @@ func TestOAuthRequestHeader(t *testing.T) {
304304

305305
// Attempt a login using a redirecting auth proxy
306306
loginOutput := &bytes.Buffer{}
307+
loginErrOutput := &bytes.Buffer{}
307308
loginOptions := &login.LoginOptions{
308309
Server: anonConfig.Host,
309310
CAFile: masterCAFile,
310311
StartingKubeConfig: &clientcmdapi.Config{},
311312
Reader: bytes.NewBufferString("myusername\nmypassword\n"),
312313
Out: loginOutput,
314+
ErrOut: loginErrOutput,
313315
}
314316
if err := loginOptions.GatherInfo(); err != nil {
315317
t.Fatalf("Error trying to determine server info: %v\n%v", err, loginOutput.String())

0 commit comments

Comments
 (0)