Update go-autorest library to v7.2.3

To include https://github.com/Azure/go-autorest/pull/107
Improves https://github.com/kubernetes/kubernetes/issues/35180
This commit is contained in:
Alexander Block 2017-01-18 14:47:31 +01:00
parent fe69dcf861
commit f812c2f2ac
5 changed files with 27 additions and 15 deletions

20
Godeps/Godeps.json generated
View File

@ -63,28 +63,28 @@
}, },
{ {
"ImportPath": "github.com/Azure/go-autorest/autorest", "ImportPath": "github.com/Azure/go-autorest/autorest",
"Comment": "v7.2.2-8-ge0c77ec", "Comment": "v7.2.3",
"Rev": "e0c77ecbe74311e03f2a629834d2110f031f1453" "Rev": "d7c034a8af24eda120dd6460bfcd6d9ed14e43ca"
}, },
{ {
"ImportPath": "github.com/Azure/go-autorest/autorest/azure", "ImportPath": "github.com/Azure/go-autorest/autorest/azure",
"Comment": "v7.2.2-8-ge0c77ec", "Comment": "v7.2.3",
"Rev": "e0c77ecbe74311e03f2a629834d2110f031f1453" "Rev": "d7c034a8af24eda120dd6460bfcd6d9ed14e43ca"
}, },
{ {
"ImportPath": "github.com/Azure/go-autorest/autorest/date", "ImportPath": "github.com/Azure/go-autorest/autorest/date",
"Comment": "v7.2.2-8-ge0c77ec", "Comment": "v7.2.3",
"Rev": "e0c77ecbe74311e03f2a629834d2110f031f1453" "Rev": "d7c034a8af24eda120dd6460bfcd6d9ed14e43ca"
}, },
{ {
"ImportPath": "github.com/Azure/go-autorest/autorest/to", "ImportPath": "github.com/Azure/go-autorest/autorest/to",
"Comment": "v7.2.2-8-ge0c77ec", "Comment": "v7.2.3",
"Rev": "e0c77ecbe74311e03f2a629834d2110f031f1453" "Rev": "d7c034a8af24eda120dd6460bfcd6d9ed14e43ca"
}, },
{ {
"ImportPath": "github.com/Azure/go-autorest/autorest/validation", "ImportPath": "github.com/Azure/go-autorest/autorest/validation",
"Comment": "v7.2.2-8-ge0c77ec", "Comment": "v7.2.3",
"Rev": "e0c77ecbe74311e03f2a629834d2110f031f1453" "Rev": "d7c034a8af24eda120dd6460bfcd6d9ed14e43ca"
}, },
{ {
"ImportPath": "github.com/MakeNowJust/heredoc", "ImportPath": "github.com/MakeNowJust/heredoc",

View File

@ -302,7 +302,7 @@ func (spt *ServicePrincipalToken) refreshInternal(resource string) error {
var newToken Token var newToken Token
err = autorest.Respond(resp, err = autorest.Respond(resp,
autorest.WithErrorUnlessOK(), autorest.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&newToken), autorest.ByUnmarshallingJSON(&newToken),
autorest.ByClosing()) autorest.ByClosing())
if err != nil { if err != nil {

View File

@ -28,6 +28,9 @@ type DetailedError struct {
// Message is the error message. // Message is the error message.
Message string Message string
// Service Error is the response body of failed API in bytes
ServiceError []byte
} }
// NewError creates a new Error conforming object from the passed packageType, method, and // NewError creates a new Error conforming object from the passed packageType, method, and

View File

@ -165,17 +165,24 @@ func ByUnmarshallingXML(v interface{}) RespondDecorator {
} }
// WithErrorUnlessStatusCode returns a RespondDecorator that emits an error unless the response // WithErrorUnlessStatusCode returns a RespondDecorator that emits an error unless the response
// StatusCode is among the set passed. Since these are artificial errors, the response body // StatusCode is among the set passed. On error, response body is fully read into a buffer and
// may still require closing. // presented in the returned error, as well as in the response body.
func WithErrorUnlessStatusCode(codes ...int) RespondDecorator { func WithErrorUnlessStatusCode(codes ...int) RespondDecorator {
return func(r Responder) Responder { return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error { return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp) err := r.Respond(resp)
if err == nil && !ResponseHasStatusCode(resp, codes...) { if err == nil && !ResponseHasStatusCode(resp, codes...) {
err = NewErrorWithResponse("autorest", "WithErrorUnlessStatusCode", resp, "%v %v failed with %s", derr := NewErrorWithResponse("autorest", "WithErrorUnlessStatusCode", resp, "%v %v failed with %s",
resp.Request.Method, resp.Request.Method,
resp.Request.URL, resp.Request.URL,
resp.Status) resp.Status)
if resp.Body != nil {
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
derr.ServiceError = b
resp.Body = ioutil.NopCloser(bytes.NewReader(b))
}
err = derr
} }
return err return err
}) })

View File

@ -73,7 +73,7 @@ func SendWithSender(s Sender, r *http.Request, decorators ...SendDecorator) (*ht
func AfterDelay(d time.Duration) SendDecorator { func AfterDelay(d time.Duration) SendDecorator {
return func(s Sender) Sender { return func(s Sender) Sender {
return SenderFunc(func(r *http.Request) (*http.Response, error) { return SenderFunc(func(r *http.Request) (*http.Response, error) {
if !DelayForBackoff(d, 1, r.Cancel) { if !DelayForBackoff(d, 0, r.Cancel) {
return nil, fmt.Errorf("autorest: AfterDelay canceled before full delay") return nil, fmt.Errorf("autorest: AfterDelay canceled before full delay")
} }
return s.Do(r) return s.Do(r)
@ -257,6 +257,8 @@ func WithLogging(logger *log.Logger) SendDecorator {
// passed attempt (i.e., an exponential backoff delay). Backoff duration is in seconds and can set // passed attempt (i.e., an exponential backoff delay). Backoff duration is in seconds and can set
// to zero for no delay. The delay may be canceled by closing the passed channel. If terminated early, // to zero for no delay. The delay may be canceled by closing the passed channel. If terminated early,
// returns false. // returns false.
// Note: Passing attempt 1 will result in doubling "backoff" duration. Treat this as a zero-based attempt
// count.
func DelayForBackoff(backoff time.Duration, attempt int, cancel <-chan struct{}) bool { func DelayForBackoff(backoff time.Duration, attempt int, cancel <-chan struct{}) bool {
select { select {
case <-time.After(time.Duration(backoff.Seconds()*math.Pow(2, float64(attempt))) * time.Second): case <-time.After(time.Duration(backoff.Seconds()*math.Pow(2, float64(attempt))) * time.Second):