Skip to content

Commit

Permalink
add additional query string to provisioning state poller and use loca…
Browse files Browse the repository at this point in the history
…tion url instead of origin url
  • Loading branch information
wuxu92 committed Oct 9, 2024
1 parent 4d383f2 commit 505c843
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.fleet/
.idea/
.vscode/
.DS_Store
tmp/
vendor/
36 changes: 34 additions & 2 deletions sdk/client/resourcemanager/poller_provisioning_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func provisioningStatePollerFromResponse(response *client.Response, lroIsSelfRef
}

resourcePath := originalUri
if pollingUriStr := pollingUriForLongRunningOperation(response); pollingUriStr != "" {
if pollingUri, err := url.ParseRequestURI(pollingUriStr); err == nil {
resourcePath = pollingUri.RequestURI()
}
}
if !lroIsSelfReference {
// if it's a self-reference (such as API Management's API/API Schema)
path, err := resourceManagerResourcePathFromUri(originalUri)
Expand All @@ -74,7 +79,8 @@ func (p *provisioningStatePoller) Poll(ctx context.Context) (*pollers.PollResult
},
HttpMethod: http.MethodGet,
OptionsObject: provisioningStateOptions{
apiVersion: p.apiVersion,
apiVersion: p.apiVersion,
additionalParams: additonalParamsFromUri(p.resourcePath),
},
Path: p.resourcePath,
}
Expand Down Expand Up @@ -182,8 +188,11 @@ func resourceManagerResourcePathFromUri(input string) (*string, error) {

var _ client.Options = provisioningStateOptions{}

// For APIM API resource, the query string in the polling URI is not always the same as the original request URI.
// These query strings are required for the polling request, otherwise, it will respond with 404 Not Found instead of a 400 Bad Request.
type provisioningStateOptions struct {
apiVersion string
apiVersion string
additionalParams map[string]string
}

func (p provisioningStateOptions) ToHeaders() *client.Headers {
Expand All @@ -196,6 +205,29 @@ func (p provisioningStateOptions) ToOData() *odata.Query {

func (p provisioningStateOptions) ToQuery() *client.QueryParams {
q := client.QueryParams{}
for k, v := range p.additionalParams {
q.Append(k, v)
}
q.Append("api-version", p.apiVersion)
return &q
}

// APIM API resource need the asyncId parameter to get the real provisioning state.
var additionalParamKeys = map[string]bool{
"asyncId": true,
}

func additonalParamsFromUri(uri string) map[string]string {
if u, err := url.ParseRequestURI(uri); err == nil {
if u.RawQuery != "" {
additionalParams := map[string]string{}
for k, v := range u.Query() {
if additionalParamKeys[k] {
additionalParams[k] = v[0]
}
}
return additionalParams
}
}
return nil
}

0 comments on commit 505c843

Please sign in to comment.