-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preserve err type loginoptions #17138
preserve err type loginoptions #17138
Conversation
/test extended_gssapi |
7f7e973
to
4477cad
Compare
loginOptions := &login.LoginOptions{ | ||
Server: anonConfig.Host, | ||
CAFile: masterCAFile, | ||
StartingKubeConfig: &clientcmdapi.Config{}, | ||
Reader: bytes.NewBufferString("myusername\nmypassword\n"), | ||
Out: loginOutput, | ||
ErrOut: loginErrOutput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ioutil.Discard
test/integration/oauth_oidc_test.go
Outdated
loginOptions := &login.LoginOptions{ | ||
Server: clientConfig.Host, | ||
CAFile: masterCAFile, | ||
StartingKubeConfig: &clientcmdapi.Config{}, | ||
Reader: bytes.NewBufferString("mylogin\nmypassword\n"), | ||
Out: loginOutput, | ||
ErrOut: loginErrOutput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ioutil.Discard
pkg/oc/bootstrap/docker/up.go
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably debatable if this should use ioutil.Discard or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @csrwng
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative would be to wire each handler to receive a second io.Writer for errs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the same writer for both? (out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the more info we can return to users about failures, etc. the better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, went ahead and re-used out
for both
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
@@ -231,10 +232,14 @@ func (o *LoginOptions) gatherAuthInfo() error { | |||
// client is connecting to the right host:port | |||
if statusErr, ok := err.(*kerrors.StatusError); ok { | |||
if statusErr.Status().Code == http.StatusInternalServerError { | |||
return fmt.Errorf("error: The server was unable to respond - %v", suggestion) | |||
fmt.Fprintf(o.ErrOut, "error: The server was unable to respond - %v", suggestion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a newline at the end and you probably want to print the error as well. Not special casing StatusInternalServerError
would also be reasonable thing to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will go ahead and remove the special case for internal server err - the error we print is pretty much the same as the one below this
Do not forget to squash. |
f235ce3
to
21e025b
Compare
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
@@ -226,15 +226,10 @@ func (o *LoginOptions) gatherAuthInfo() error { | |||
token, err := tokencmd.RequestToken(o.Config, o.Reader, o.Username, o.Password) | |||
if err != nil { | |||
suggestion := "verify you have provided the correct host and port and that the server is currently running." | |||
fmt.Fprintf(o.ErrOut, "error: %v - %v\n", err, suggestion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No point in making the suggestion var now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought it might help this line not get too long - will update though
@juanvallejo we need some kind of test (unit preferred) to make sure #17150 does not happen. |
8e76c1c
to
b366e91
Compare
d63700e
to
df1e76b
Compare
@enj thanks, added a unit test. ptal |
/test extended_conformance_gce |
/kind bug |
@@ -30,7 +30,7 @@ const ( | |||
// See IETF Draft: | |||
// https://tools.ietf.org/html/draft-ietf-oauth-discovery-04#section-2 | |||
// Copied from pkg/cmd/server/origin/nonapiserver.go | |||
oauthMetadataEndpoint = "/.well-known/oauth-authorization-server" | |||
OauthMetadataEndpoint = "/.well-known/oauth-authorization-server" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not export this, it is already a copy from a different file. Hard code the string, it can never change.
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/spf13/pflag" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space seems out of place.
func (r *oauthMetadataResponse) Serialize() string { | ||
b, err := json.Marshal(r.metadata) | ||
if err != nil { | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail the test on this.
|
||
if r.URL.Path == tokencmd.OauthMetadataEndpoint { | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, metadataResponse.Serialize()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just write the raw bytes?
TokenEndpoint: server.URL + "/oauth/token", | ||
CodeChallengeMethodsSupported: []string{"plain", "S256"}, | ||
} | ||
defer server.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move up.
} | ||
|
||
if !kapierrs.IsUnauthorized(err) { | ||
t.Fatalf("expecting error of type metav1.StatusReasonUnauthorized, but got %v", reflect.TypeOf(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can just do %T
to get the type.
return loginOptions | ||
} | ||
|
||
func defaultClientConfig(flags *pflag.FlagSet) kclientcmd.ClientConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flags, wat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, had originally grabbed these two helpers from here. Went ahead and cleaned the test up - no longer need them here
clientConfig := defaultClientConfig(flagset) | ||
flagset.Parse(flags) | ||
|
||
startingConfig, _ := clientConfig.RawConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is an error, it should fail the test.
metadataResponse := &oauthMetadataResponse{} | ||
|
||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
invoked <- struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a check to fail the test if this would dead lock the buffered channel.
5693551
to
1a24880
Compare
@enj thanks for the review, comments addressed |
/lgtm Approving since this is all auth code. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: enj, juanvallejo Assign the PR to them by writing The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
1a24880
to
b3b6b08
Compare
b3b6b08
to
0c94fae
Compare
Automatic merge from submit-queue (batch tested with PRs 17178, 17141, 17138). |
Fixes #17136
Fixes #17150
Preserves the error type returned in https://github.com/openshift/origin/blob/master/pkg/oc/cli/cmd/login/loginoptions.go#L237
cc @openshift/cli-review