Update to go-autorest v7.0.5. (#3554)

This commit is contained in:
Christopher Boumenot 2016-05-18 17:18:46 -07:00 committed by Chris Bednarski
parent b67ee530c8
commit dca2b515a3
6 changed files with 37 additions and 28 deletions

17
Godeps/Godeps.json generated
View File

@ -1,7 +1,6 @@
{
"ImportPath": "github.com/mitchellh/packer",
"GoVersion": "go1.6",
"GodepVersion": "v62",
"Deps": [
{
"ImportPath": "github.com/ActiveState/tail",
@ -40,23 +39,23 @@
},
{
"ImportPath": "github.com/Azure/go-autorest/autorest",
"Comment": "v7.0.4",
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
"Comment": "v7.0.5",
"Rev": "4bdf29b663ebad9598d2c391b73a4b46bdedbf42"
},
{
"ImportPath": "github.com/Azure/go-autorest/autorest/azure",
"Comment": "v7.0.4",
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
"Comment": "v7.0.5",
"Rev": "4bdf29b663ebad9598d2c391b73a4b46bdedbf42"
},
{
"ImportPath": "github.com/Azure/go-autorest/autorest/date",
"Comment": "v7.0.4",
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
"Comment": "v7.0.5",
"Rev": "4bdf29b663ebad9598d2c391b73a4b46bdedbf42"
},
{
"ImportPath": "github.com/Azure/go-autorest/autorest/to",
"Comment": "v7.0.4",
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
"Comment": "v7.0.5",
"Rev": "4bdf29b663ebad9598d2c391b73a4b46bdedbf42"
},
{
"ImportPath": "github.com/Azure/go-ntlmssp",

View File

@ -39,6 +39,10 @@ func DoPollForAsynchronous(delay time.Duration) autorest.SendDecorator {
if err != nil {
return resp, err
}
pollingCodes := []int{http.StatusAccepted, http.StatusCreated, http.StatusOK}
if !autorest.ResponseHasStatusCode(resp, pollingCodes...) {
return resp, nil
}
ps := pollingState{}
for err == nil {
@ -224,10 +228,6 @@ func updatePollingState(resp *http.Response, ps *pollingState) error {
ps.uri = req.URL.String()
}
}
if ps.uri == "" {
return autorest.NewError("azure", "updatePollingState", "Azure Polling Error - Unable to obtain polling URI for %s %s", req.Method, req.RequestURI)
}
}
// Read and interpret the response (saving the Body in case no polling is necessary)
@ -262,6 +262,10 @@ func updatePollingState(resp *http.Response, ps *pollingState) error {
}
}
if ps.state == operationInProgress && ps.uri == "" {
return autorest.NewError("azure", "updatePollingState", "Azure Polling Error - Unable to obtain polling URI for %s %s", resp.Request.Method, resp.Request.URL)
}
// For failed operation, check for error code and message in
// -- Operation resource
// -- Response

View File

@ -34,13 +34,13 @@ func SaveToken(path string, mode os.FileMode, token Token) error {
return fmt.Errorf("failed to create directory (%s) to store token in: %v", dir, err)
}
newFile, err := ioutil.TempFile(os.TempDir(), "token")
newFile, err := ioutil.TempFile(dir, "token")
if err != nil {
return fmt.Errorf("failed to create the temp file to write the token: %v", err)
}
tempPath := newFile.Name()
if json.NewEncoder(newFile).Encode(token); err != nil {
if err := json.NewEncoder(newFile).Encode(token); err != nil {
return fmt.Errorf("failed to encode token to file (%s) while saving token: %v", tempPath, err)
}
if err := newFile.Close(); err != nil {
@ -49,7 +49,7 @@ func SaveToken(path string, mode os.FileMode, token Token) error {
// Atomic replace to avoid multi-writer file corruptions
if err := os.Rename(tempPath, path); err != nil {
return fmt.Errorf("failed to move temporary token to desired output location. source=(%s). destination=(%s). error = %v", tempPath, path, err)
return fmt.Errorf("failed to move temporary token to desired output location. src=%s dst=%s: %v", tempPath, path, err)
}
if err := os.Chmod(path, mode); err != nil {
return fmt.Errorf("failed to chmod the token file %s: %v", path, err)

View File

@ -2,6 +2,7 @@ package autorest
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
@ -53,7 +54,9 @@ func (li LoggingInspector) WithInspection() PrepareDecorator {
defer r.Body.Close()
r.Body = ioutil.NopCloser(io.TeeReader(r.Body, &body))
r.Write(&b)
if err := r.Write(&b); err != nil {
return nil, fmt.Errorf("Failed to write response: %v", err)
}
li.Logger.Printf(requestFormat, b.String())
@ -76,7 +79,9 @@ func (li LoggingInspector) ByInspecting() RespondDecorator {
defer resp.Body.Close()
resp.Body = ioutil.NopCloser(io.TeeReader(resp.Body, &body))
resp.Write(&b)
if err := resp.Write(&b); err != nil {
return fmt.Errorf("Failed to write response: %v", err)
}
li.Logger.Printf(responseFormat, b.String())

View File

@ -95,7 +95,9 @@ func ByClosing() RespondDecorator {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if resp != nil && resp.Body != nil {
resp.Body.Close()
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("Error closing the response body: %v", err)
}
}
return err
})
@ -109,7 +111,9 @@ func ByClosingIfError() RespondDecorator {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err != nil && resp != nil && resp.Body != nil {
resp.Body.Close()
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("Error closing the response body: %v", err)
}
}
return err
})

View File

@ -71,7 +71,7 @@ func SendWithSender(s Sender, r *http.Request, decorators ...SendDecorator) (*ht
func AfterDelay(d time.Duration) SendDecorator {
return func(s Sender) Sender {
return SenderFunc(func(r *http.Request) (*http.Response, error) {
if DelayForBackoff(d, 1, r.Cancel) != nil {
if !DelayForBackoff(d, 1, r.Cancel) {
return nil, fmt.Errorf("autorest: AfterDelay canceled before full delay")
}
return s.Do(r)
@ -223,15 +223,12 @@ func WithLogging(logger *log.Logger) SendDecorator {
// DelayForBackoff invokes time.After for the supplied backoff duration raised to the power of
// passed attempt (i.e., an exponential backoff delay). Backoff may be zero. The delay may be
// canceled by closing the passed channel.
func DelayForBackoff(backoff time.Duration, attempt int, cancel <-chan struct{}) error {
if cancel == nil {
cancel = make(chan struct{})
}
// canceled by closing the passed channel. If terminated early, returns false.
func DelayForBackoff(backoff time.Duration, attempt int, cancel <-chan struct{}) bool {
select {
case <-time.After(time.Duration(math.Pow(float64(backoff), float64(attempt)))):
return true
case <-cancel:
return fmt.Errorf("autorest: Delay canceled")
return false
}
return nil
}