Skip to content

Commit

Permalink
Merge pull request #25 from rightscale/fix_double_body_read
Browse files Browse the repository at this point in the history
Remove double read of access token response for non-200 codes so the actual error message comes through
  • Loading branch information
douglaswth authored Jun 30, 2020
2 parents 1286f3a + 0ef4821 commit f070cbe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions auth/refresh_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"regexp"
"time"

goahttp "goa.design/goa/http"
goahttp "goa.design/goa/v3/http"
)

// refreshTokenSource contains the logic to create new session using OAuth tokens
Expand Down Expand Up @@ -61,10 +61,6 @@ func (ts *refreshTokenSource) TokenString() (string, error) {
}
defer resp.Body.Close()

jsonBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Authentication failed (failed to read response): %s", err)
}
if resp.StatusCode != 200 {
body, err := ioutil.ReadAll(resp.Body)
var msg string
Expand All @@ -77,6 +73,10 @@ func (ts *refreshTokenSource) TokenString() (string, error) {
return "", fmt.Errorf("Authentication failed: %s%s", resp.Status, msg)
}

jsonBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Authentication failed (failed to read response): %s", err)
}
var g Grant
err = json.Unmarshal(jsonBytes, &g)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/fpt/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.1.4 / 2020-06-30
-------------------
* Remove double read of access token response for non-200 codes so the actual error message comes through

v1.1.3 / 2020-06-26
-------------------
* Fix an incorrect use of `fmt.Printf` without a format to use `fmt.Print` instead
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/douglaswth/rsrdp v0.0.0-20151016234338-276cfcdf9e52 // indirect
github.com/douglaswth/rsrdp v0.0.0-20151016234338-276cfcdf9e52
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/jessevdk/go-flags v1.4.0 // indirect
Expand All @@ -18,7 +18,6 @@ require (
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d
github.com/spf13/afero v1.2.0 // indirect
github.com/spf13/viper v1.3.1
goa.design/goa v1.0.1-0.20190123214405-b70dea21c455
goa.design/goa/v3 v3.0.6
goa.design/plugins/v3 v3.0.6
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea/go.mod h
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
goa.design/goa v1.0.1-0.20190123214405-b70dea21c455 h1:8fsnD0i0VNaNbPZld+JdrOe6VHbFE10vejJtTmj4gqM=
goa.design/goa v1.0.1-0.20190123214405-b70dea21c455/go.mod h1:NnzBwdNktihbNek+pPiFMQP9PPFsUt8MMPPyo9opDSo=
goa.design/goa/v3 v3.0.6 h1:+h46Nymbp7ZvRuWwNpAra+l96KKHXjznYiWPKnz8G9I=
goa.design/goa/v3 v3.0.6/go.mod h1:sEWV8VRLZenziAnHcIHjjGvlC2pwEvNblwBtMuyPwqQ=
goa.design/plugins/v3 v3.0.6 h1:hL3jioHp4z6KQ5L0RnbbB4zE8/U+btbWXgTYBElo/BI=
Expand Down

0 comments on commit f070cbe

Please sign in to comment.