Skip to content

Commit

Permalink
Merge pull request #17606 from php-coder/test_response_code
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 17217, 17597, 17606).

Fail fast when request to /.well-known/oauth-authorization-server fails

Improves error reporting. See here for more details: #17574 (comment)

Prior this change `hack/test-cmd.sh` could fail with the error:

> error: Missing configuration - verify you have provided the correct host and port and that the server is currently running.

Now, the message has more details:

> error: couldn't get https://10.34.129.148:28443/.well-known/oauth-authorization-server: unexpected status 403 were returned - verify you have provided the correct host and port and that the server is currently running.

PTAL @enj @simo5
  • Loading branch information
openshift-merge-robot authored Dec 6, 2017
2 parents 4c5d83c + 51e0daf commit e9bb78b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/cmd/util/tokencmd/request_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,18 @@ func (o *RequestTokenOptions) SetDefaultOsinConfig() error {
if err != nil {
return err
}
resp, err := request(rt, strings.TrimRight(o.ClientConfig.Host, "/")+oauthMetadataEndpoint, nil)

requestURL := strings.TrimRight(o.ClientConfig.Host, "/") + oauthMetadataEndpoint
resp, err := request(rt, requestURL, nil)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("couldn't get %v: unexpected response status %v", requestURL, resp.StatusCode)
}

metadata := &util.OauthAuthorizationServerMetadata{}
if err := json.NewDecoder(resp.Body).Decode(metadata); err != nil {
return err
Expand Down

0 comments on commit e9bb78b

Please sign in to comment.