Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: provisioning state poller allow additional parameters #1090

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading