Skip to content

Commit

Permalink
Use case-insensitive string comparison for polling state. (#201)
Browse files Browse the repository at this point in the history
We have seen a case where the polling state string is all lower case
which caused an infinite loop while polling.
  • Loading branch information
jhendrixMSFT authored and marstr committed Nov 17, 2017
1 parent 0b0c957 commit c67b24a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
### Bug Fixes

- Update the AccessTokensPath() to read access tokens path through AZURE_ACCESS_TOKEN_FILE. If this
environment variable is not set, it will fall back to use default path set by Azure CLI.
environment variable is not set, it will fall back to use default path set by Azure CLI.
- Use case-insensitive string comparison for polling states.

## v9.4.0

Expand Down
13 changes: 4 additions & 9 deletions autorest/azure/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,15 @@ func getAsyncOperation(resp *http.Response) string {
}

func hasSucceeded(state string) bool {
return state == operationSucceeded
return strings.EqualFold(state, operationSucceeded)
}

func hasTerminated(state string) bool {
switch state {
case operationCanceled, operationFailed, operationSucceeded:
return true
default:
return false
}
return strings.EqualFold(state, operationCanceled) || strings.EqualFold(state, operationFailed) || strings.EqualFold(state, operationSucceeded)
}

func hasFailed(state string) bool {
return state == operationFailed
return strings.EqualFold(state, operationFailed)
}

type provisioningTracker interface {
Expand Down Expand Up @@ -426,7 +421,7 @@ func updatePollingState(resp *http.Response, ps *pollingState) error {
}
}

if ps.State == operationInProgress && ps.URI == "" {
if strings.EqualFold(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)
}

Expand Down

0 comments on commit c67b24a

Please sign in to comment.