From c9da813d7d207f23b0355485cce9078e5730f42d Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 8 Jun 2023 10:06:52 -0700 Subject: [PATCH 1/2] armresources 1.2.0-beta.1 release --- .../resources/armresources/CHANGELOG.md | 6 + .../resources/armresources/README.md | 25 + .../resources/armresources/autorest.md | 8 +- .../resources/armresources/build.go | 2 +- .../resources/armresources/client.go | 231 ++- .../resources/armresources/client_factory.go | 3 +- .../resources/armresources/constants.go | 97 +- .../deploymentoperations_client.go | 88 +- .../armresources/deployments_client.go | 706 +++++-- .../fake/deploymentoperations_server.go | 487 +++++ .../armresources/fake/deployments_server.go | 1801 +++++++++++++++++ .../resources/armresources/fake/internal.go | 78 + .../armresources/fake/operations_server.go | 90 + .../fake/providerresourcetypes_server.go | 99 + .../armresources/fake/providers_server.go | 358 ++++ .../fake/resourcegroups_server.go | 342 ++++ .../resources/armresources/fake/server.go | 656 ++++++ .../armresources/fake/tags_server.go | 354 ++++ .../armresources/fake/time_rfc3339.go | 86 + .../resources/armresources/go.mod | 10 +- .../resources/armresources/go.sum | 20 +- .../resources/armresources/models.go | 3 +- .../resources/armresources/models_serde.go | 3 +- .../armresources/operations_client.go | 5 +- .../providerresourcetypes_client.go | 18 +- .../armresources/providers_client.go | 99 +- .../armresources/resourcegroups_client.go | 113 +- .../resources/armresources/response_types.go | 3 +- .../resources/armresources/tags_client.go | 126 +- .../resources/armresources/time_rfc3339.go | 3 +- 30 files changed, 5468 insertions(+), 452 deletions(-) create mode 100644 sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/deployments_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/operations_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/providers_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/tags_server.go create mode 100644 sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go diff --git a/sdk/resourcemanager/resources/armresources/CHANGELOG.md b/sdk/resourcemanager/resources/armresources/CHANGELOG.md index 5a20e9c9b934..0730e6d1833f 100644 --- a/sdk/resourcemanager/resources/armresources/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armresources/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0-beta.1 (2023-06-08) + +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + ## 1.1.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armresources/README.md b/sdk/resourcemanager/resources/armresources/README.md index 675c52705cc5..6b718d4b4295 100644 --- a/sdk/resourcemanager/resources/armresources/README.md +++ b/sdk/resourcemanager/resources/armresources/README.md @@ -60,6 +60,31 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewClient() ``` +## Fakes +The `fake` package provides implementations for fake servers that can be used for testing. +To create a fake server, declare an instance of the required fake server type(s). +```go +myFakeServer := fake.Server{} +``` +Next, provide func implementations for the methods you wish to fake. +The named return variables can be used to simplify return value construction. +```go +myFakeServer.CheckExistence = func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *armresources.ClientCheckExistenceOptions) (resp azfake.Responder[armresources.ClientCheckExistenceResponse], errResp azfake.ErrorResponder) { + // TODO: resp.SetResponse(/* your fake ClientCheckExistenceResponse response */) + return +} +``` +You connect the fake server to a client instance during construction through the optional transport. +Use `NewTokenCredential()` from `azcore/fake` to obtain a fake credential. +```go +import azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" +client, err := armresources.NewClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewServerTransport(&myFakeServer), + }, +}) +``` + ## More sample code - [Deployment](https://aka.ms/azsdk/go/mgmt/samples?path=sdk/resourcemanager/resource/deployment) diff --git a/sdk/resourcemanager/resources/armresources/autorest.md b/sdk/resourcemanager/resources/armresources/autorest.md index 2767ecb00d9e..f89bf48982ca 100644 --- a/sdk/resourcemanager/resources/armresources/autorest.md +++ b/sdk/resourcemanager/resources/armresources/autorest.md @@ -8,6 +8,10 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.1 +module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources +module-version: 1.2.0-beta.1 package-resources: true -``` \ No newline at end of file +azcore-version: 1.7.0-beta.2 +generate-fakes: true +inject-spans: true +``` diff --git a/sdk/resourcemanager/resources/armresources/build.go b/sdk/resourcemanager/resources/armresources/build.go index 546b96f36c1c..3c8d4bf05f5f 100644 --- a/sdk/resourcemanager/resources/armresources/build.go +++ b/sdk/resourcemanager/resources/armresources/build.go @@ -2,6 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // This file enables 'go generate' to regenerate this specific SDK -//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armresources +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.50" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armresources package armresources diff --git a/sdk/resourcemanager/resources/armresources/client.go b/sdk/resourcemanager/resources/armresources/client.go index 4d78cab13732..8b984cbd51f8 100644 --- a/sdk/resourcemanager/resources/armresources/client.go +++ b/sdk/resourcemanager/resources/armresources/client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -56,18 +55,24 @@ func NewClient(subscriptionID string, credential azcore.TokenCredential, options // - apiVersion - The API version to use for the operation. // - options - ClientCheckExistenceOptions contains the optional parameters for the Client.CheckExistence method. func (client *Client) CheckExistence(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *ClientCheckExistenceOptions) (ClientCheckExistenceResponse, error) { + var err error + const operationName = "Client.CheckExistence" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion, options) if err != nil { return ClientCheckExistenceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientCheckExistenceResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return ClientCheckExistenceResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ClientCheckExistenceResponse{}, err } - return ClientCheckExistenceResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return ClientCheckExistenceResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceCreateRequest creates the CheckExistence request. @@ -110,18 +115,24 @@ func (client *Client) checkExistenceCreateRequest(ctx context.Context, resourceG // - apiVersion - The API version to use for the operation. // - options - ClientCheckExistenceByIDOptions contains the optional parameters for the Client.CheckExistenceByID method. func (client *Client) CheckExistenceByID(ctx context.Context, resourceID string, apiVersion string, options *ClientCheckExistenceByIDOptions) (ClientCheckExistenceByIDResponse, error) { + var err error + const operationName = "Client.CheckExistenceByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceByIDCreateRequest(ctx, resourceID, apiVersion, options) if err != nil { return ClientCheckExistenceByIDResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientCheckExistenceByIDResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return ClientCheckExistenceByIDResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ClientCheckExistenceByIDResponse{}, err } - return ClientCheckExistenceByIDResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return ClientCheckExistenceByIDResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceByIDCreateRequest creates the CheckExistenceByID request. @@ -157,7 +168,8 @@ func (client *Client) BeginCreateOrUpdate(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller[ClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -168,18 +180,24 @@ func (client *Client) BeginCreateOrUpdate(ctx context.Context, resourceGroupName // // Generated from API version 2021-04-01 func (client *Client) createOrUpdate(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, parameters GenericResource, options *ClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -211,7 +229,10 @@ func (client *Client) createOrUpdateCreateRequest(ctx context.Context, resourceG reqQP.Set("api-version", apiVersion) req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateByID - Create a resource by ID. @@ -230,7 +251,8 @@ func (client *Client) BeginCreateOrUpdateByID(ctx context.Context, resourceID st if err != nil { return nil, err } - return runtime.NewPoller[ClientCreateOrUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientCreateOrUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -241,18 +263,24 @@ func (client *Client) BeginCreateOrUpdateByID(ctx context.Context, resourceID st // // Generated from API version 2021-04-01 func (client *Client) createOrUpdateByID(ctx context.Context, resourceID string, apiVersion string, parameters GenericResource, options *ClientBeginCreateOrUpdateByIDOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginCreateOrUpdateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateByIDCreateRequest(ctx, resourceID, apiVersion, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateByIDCreateRequest creates the CreateOrUpdateByID request. @@ -267,7 +295,10 @@ func (client *Client) createOrUpdateByIDCreateRequest(ctx context.Context, resou reqQP.Set("api-version", apiVersion) req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a resource. @@ -287,7 +318,8 @@ func (client *Client) BeginDelete(ctx context.Context, resourceGroupName string, if err != nil { return nil, err } - return runtime.NewPoller[ClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -298,18 +330,24 @@ func (client *Client) BeginDelete(ctx context.Context, resourceGroupName string, // // Generated from API version 2021-04-01 func (client *Client) deleteOperation(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *ClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -358,7 +396,8 @@ func (client *Client) BeginDeleteByID(ctx context.Context, resourceID string, ap if err != nil { return nil, err } - return runtime.NewPoller[ClientDeleteByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientDeleteByIDResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientDeleteByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -369,18 +408,24 @@ func (client *Client) BeginDeleteByID(ctx context.Context, resourceID string, ap // // Generated from API version 2021-04-01 func (client *Client) deleteByID(ctx context.Context, resourceID string, apiVersion string, options *ClientBeginDeleteByIDOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginDeleteByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteByIDCreateRequest(ctx, resourceID, apiVersion, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteByIDCreateRequest creates the DeleteByID request. @@ -410,18 +455,25 @@ func (client *Client) deleteByIDCreateRequest(ctx context.Context, resourceID st // - apiVersion - The API version to use for the operation. // - options - ClientGetOptions contains the optional parameters for the Client.Get method. func (client *Client) Get(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *ClientGetOptions) (ClientGetResponse, error) { + var err error + const operationName = "Client.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion, options) if err != nil { return ClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -474,18 +526,25 @@ func (client *Client) getHandleResponse(resp *http.Response) (ClientGetResponse, // - apiVersion - The API version to use for the operation. // - options - ClientGetByIDOptions contains the optional parameters for the Client.GetByID method. func (client *Client) GetByID(ctx context.Context, resourceID string, apiVersion string, options *ClientGetByIDOptions) (ClientGetByIDResponse, error) { + var err error + const operationName = "Client.GetByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByIDCreateRequest(ctx, resourceID, apiVersion, options) if err != nil { return ClientGetByIDResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetByIDResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetByIDResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetByIDResponse{}, err } - return client.getByIDHandleResponse(resp) + resp, err := client.getByIDHandleResponse(httpResp) + return resp, err } // getByIDCreateRequest creates the GetByID request. @@ -522,6 +581,7 @@ func (client *Client) NewListPager(options *ClientListOptions) *runtime.Pager[Cl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListPager") var req *policy.Request var err error if page == nil { @@ -541,6 +601,7 @@ func (client *Client) NewListPager(options *ClientListOptions) *runtime.Pager[Cl } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -592,6 +653,7 @@ func (client *Client) NewListByResourceGroupPager(resourceGroupName string, opti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListByResourceGroupResponse) (ClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -611,6 +673,7 @@ func (client *Client) NewListByResourceGroupPager(resourceGroupName string, opti } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -670,7 +733,8 @@ func (client *Client) BeginMoveResources(ctx context.Context, sourceResourceGrou if err != nil { return nil, err } - return runtime.NewPoller[ClientMoveResourcesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientMoveResourcesResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientMoveResourcesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -684,18 +748,24 @@ func (client *Client) BeginMoveResources(ctx context.Context, sourceResourceGrou // // Generated from API version 2021-04-01 func (client *Client) moveResources(ctx context.Context, sourceResourceGroupName string, parameters MoveInfo, options *ClientBeginMoveResourcesOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginMoveResources" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.moveResourcesCreateRequest(ctx, sourceResourceGroupName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // moveResourcesCreateRequest creates the MoveResources request. @@ -717,7 +787,10 @@ func (client *Client) moveResourcesCreateRequest(ctx context.Context, sourceReso reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginUpdate - Updates a resource. @@ -738,7 +811,8 @@ func (client *Client) BeginUpdate(ctx context.Context, resourceGroupName string, if err != nil { return nil, err } - return runtime.NewPoller[ClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -749,18 +823,24 @@ func (client *Client) BeginUpdate(ctx context.Context, resourceGroupName string, // // Generated from API version 2021-04-01 func (client *Client) update(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, parameters GenericResource, options *ClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -792,7 +872,10 @@ func (client *Client) updateCreateRequest(ctx context.Context, resourceGroupName reqQP.Set("api-version", apiVersion) req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginUpdateByID - Updates a resource by ID. @@ -810,7 +893,8 @@ func (client *Client) BeginUpdateByID(ctx context.Context, resourceID string, ap if err != nil { return nil, err } - return runtime.NewPoller[ClientUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientUpdateByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -821,18 +905,24 @@ func (client *Client) BeginUpdateByID(ctx context.Context, resourceID string, ap // // Generated from API version 2021-04-01 func (client *Client) updateByID(ctx context.Context, resourceID string, apiVersion string, parameters GenericResource, options *ClientBeginUpdateByIDOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginUpdateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateByIDCreateRequest(ctx, resourceID, apiVersion, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateByIDCreateRequest creates the UpdateByID request. @@ -847,7 +937,10 @@ func (client *Client) updateByIDCreateRequest(ctx context.Context, resourceID st reqQP.Set("api-version", apiVersion) req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginValidateMoveResources - This operation checks whether the specified resources can be moved to the target. The resources @@ -869,7 +962,8 @@ func (client *Client) BeginValidateMoveResources(ctx context.Context, sourceReso if err != nil { return nil, err } - return runtime.NewPoller[ClientValidateMoveResourcesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ClientValidateMoveResourcesResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ClientValidateMoveResourcesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -884,18 +978,24 @@ func (client *Client) BeginValidateMoveResources(ctx context.Context, sourceReso // // Generated from API version 2021-04-01 func (client *Client) validateMoveResources(ctx context.Context, sourceResourceGroupName string, parameters MoveInfo, options *ClientBeginValidateMoveResourcesOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginValidateMoveResources" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.validateMoveResourcesCreateRequest(ctx, sourceResourceGroupName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // validateMoveResourcesCreateRequest creates the ValidateMoveResources request. @@ -917,5 +1017,8 @@ func (client *Client) validateMoveResourcesCreateRequest(ctx context.Context, so reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/resources/armresources/client_factory.go b/sdk/resourcemanager/resources/armresources/client_factory.go index 3b42ee504554..9206a4ff5f5a 100644 --- a/sdk/resourcemanager/resources/armresources/client_factory.go +++ b/sdk/resourcemanager/resources/armresources/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources diff --git a/sdk/resourcemanager/resources/armresources/constants.go b/sdk/resourcemanager/resources/armresources/constants.go index 2e355a761fe2..0c8d99ceb9bb 100644 --- a/sdk/resourcemanager/resources/armresources/constants.go +++ b/sdk/resourcemanager/resources/armresources/constants.go @@ -3,15 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources const ( moduleName = "armresources" - moduleVersion = "v1.1.1" + moduleVersion = "v1.2.0-beta.1" ) // AliasPathAttributes - The attributes of the token that the alias path is referring to. @@ -72,17 +71,17 @@ func PossibleAliasPathTokenTypeValues() []AliasPathTokenType { type AliasPatternType string const ( - // AliasPatternTypeNotSpecified - NotSpecified is not allowed. - AliasPatternTypeNotSpecified AliasPatternType = "NotSpecified" // AliasPatternTypeExtract - Extract is the only allowed value. AliasPatternTypeExtract AliasPatternType = "Extract" + // AliasPatternTypeNotSpecified - NotSpecified is not allowed. + AliasPatternTypeNotSpecified AliasPatternType = "NotSpecified" ) // PossibleAliasPatternTypeValues returns the possible values for the AliasPatternType const type. func PossibleAliasPatternTypeValues() []AliasPatternType { return []AliasPatternType{ - AliasPatternTypeNotSpecified, AliasPatternTypeExtract, + AliasPatternTypeNotSpecified, } } @@ -90,20 +89,20 @@ func PossibleAliasPatternTypeValues() []AliasPatternType { type AliasType string const ( + // AliasTypeMask - Alias value is secret. + AliasTypeMask AliasType = "Mask" // AliasTypeNotSpecified - Alias type is unknown (same as not providing alias type). AliasTypeNotSpecified AliasType = "NotSpecified" // AliasTypePlainText - Alias value is not secret. AliasTypePlainText AliasType = "PlainText" - // AliasTypeMask - Alias value is secret. - AliasTypeMask AliasType = "Mask" ) // PossibleAliasTypeValues returns the possible values for the AliasType const type. func PossibleAliasTypeValues() []AliasType { return []AliasType{ + AliasTypeMask, AliasTypeNotSpecified, AliasTypePlainText, - AliasTypeMask, } } @@ -117,18 +116,18 @@ const ( // ChangeTypeDelete - The resource exists in the current state and is missing from the desired state. The resource will be // deleted when the deployment is executed. ChangeTypeDelete ChangeType = "Delete" - // ChangeTypeIgnore - The resource exists in the current state and is missing from the desired state. The resource will not - // be deployed or modified when the deployment is executed. - ChangeTypeIgnore ChangeType = "Ignore" // ChangeTypeDeploy - The resource exists in the current state and the desired state and will be redeployed when the deployment // is executed. The properties of the resource may or may not change. ChangeTypeDeploy ChangeType = "Deploy" - // ChangeTypeNoChange - The resource exists in the current state and the desired state and will be redeployed when the deployment - // is executed. The properties of the resource will not change. - ChangeTypeNoChange ChangeType = "NoChange" + // ChangeTypeIgnore - The resource exists in the current state and is missing from the desired state. The resource will not + // be deployed or modified when the deployment is executed. + ChangeTypeIgnore ChangeType = "Ignore" // ChangeTypeModify - The resource exists in the current state and the desired state and will be redeployed when the deployment // is executed. The properties of the resource will change. ChangeTypeModify ChangeType = "Modify" + // ChangeTypeNoChange - The resource exists in the current state and the desired state and will be redeployed when the deployment + // is executed. The properties of the resource will not change. + ChangeTypeNoChange ChangeType = "NoChange" // ChangeTypeUnsupported - The resource is not supported by What-If. ChangeTypeUnsupported ChangeType = "Unsupported" ) @@ -138,10 +137,10 @@ func PossibleChangeTypeValues() []ChangeType { return []ChangeType{ ChangeTypeCreate, ChangeTypeDelete, - ChangeTypeIgnore, ChangeTypeDeploy, - ChangeTypeNoChange, + ChangeTypeIgnore, ChangeTypeModify, + ChangeTypeNoChange, ChangeTypeUnsupported, } } @@ -154,15 +153,15 @@ func PossibleChangeTypeValues() []ChangeType { type DeploymentMode string const ( - DeploymentModeIncremental DeploymentMode = "Incremental" DeploymentModeComplete DeploymentMode = "Complete" + DeploymentModeIncremental DeploymentMode = "Incremental" ) // PossibleDeploymentModeValues returns the possible values for the DeploymentMode const type. func PossibleDeploymentModeValues() []DeploymentMode { return []DeploymentMode{ - DeploymentModeIncremental, DeploymentModeComplete, + DeploymentModeIncremental, } } @@ -219,6 +218,8 @@ func PossibleOnErrorDeploymentTypeValues() []OnErrorDeploymentType { type PropertyChangeType string const ( + // PropertyChangeTypeArray - The property is an array and contains nested changes. + PropertyChangeTypeArray PropertyChangeType = "Array" // PropertyChangeTypeCreate - The property does not exist in the current state but is present in the desired state. The property // will be created when the deployment is executed. PropertyChangeTypeCreate PropertyChangeType = "Create" @@ -228,8 +229,6 @@ const ( // PropertyChangeTypeModify - The property exists in both current and desired state and is different. The value of the property // will change when the deployment is executed. PropertyChangeTypeModify PropertyChangeType = "Modify" - // PropertyChangeTypeArray - The property is an array and contains nested changes. - PropertyChangeTypeArray PropertyChangeType = "Array" // PropertyChangeTypeNoEffect - The property will not be set or updated. PropertyChangeTypeNoEffect PropertyChangeType = "NoEffect" ) @@ -237,10 +236,10 @@ const ( // PossiblePropertyChangeTypeValues returns the possible values for the PropertyChangeType const type. func PossiblePropertyChangeTypeValues() []PropertyChangeType { return []PropertyChangeType{ + PropertyChangeTypeArray, PropertyChangeTypeCreate, PropertyChangeTypeDelete, PropertyChangeTypeModify, - PropertyChangeTypeArray, PropertyChangeTypeNoEffect, } } @@ -269,42 +268,42 @@ func PossibleProviderAuthorizationConsentStateValues() []ProviderAuthorizationCo type ProvisioningOperation string const ( - // ProvisioningOperationNotSpecified - The provisioning operation is not specified. - ProvisioningOperationNotSpecified ProvisioningOperation = "NotSpecified" + // ProvisioningOperationAction - The provisioning operation is action. + ProvisioningOperationAction ProvisioningOperation = "Action" + // ProvisioningOperationAzureAsyncOperationWaiting - The provisioning operation is waiting Azure async operation. + ProvisioningOperationAzureAsyncOperationWaiting ProvisioningOperation = "AzureAsyncOperationWaiting" // ProvisioningOperationCreate - The provisioning operation is create. ProvisioningOperationCreate ProvisioningOperation = "Create" // ProvisioningOperationDelete - The provisioning operation is delete. ProvisioningOperationDelete ProvisioningOperation = "Delete" - // ProvisioningOperationWaiting - The provisioning operation is waiting. - ProvisioningOperationWaiting ProvisioningOperation = "Waiting" - // ProvisioningOperationAzureAsyncOperationWaiting - The provisioning operation is waiting Azure async operation. - ProvisioningOperationAzureAsyncOperationWaiting ProvisioningOperation = "AzureAsyncOperationWaiting" - // ProvisioningOperationResourceCacheWaiting - The provisioning operation is waiting for resource cache. - ProvisioningOperationResourceCacheWaiting ProvisioningOperation = "ResourceCacheWaiting" - // ProvisioningOperationAction - The provisioning operation is action. - ProvisioningOperationAction ProvisioningOperation = "Action" - // ProvisioningOperationRead - The provisioning operation is read. - ProvisioningOperationRead ProvisioningOperation = "Read" - // ProvisioningOperationEvaluateDeploymentOutput - The provisioning operation is evaluate output. - ProvisioningOperationEvaluateDeploymentOutput ProvisioningOperation = "EvaluateDeploymentOutput" // ProvisioningOperationDeploymentCleanup - The provisioning operation is cleanup. This operation is part of the 'complete' // mode deployment. ProvisioningOperationDeploymentCleanup ProvisioningOperation = "DeploymentCleanup" + // ProvisioningOperationEvaluateDeploymentOutput - The provisioning operation is evaluate output. + ProvisioningOperationEvaluateDeploymentOutput ProvisioningOperation = "EvaluateDeploymentOutput" + // ProvisioningOperationNotSpecified - The provisioning operation is not specified. + ProvisioningOperationNotSpecified ProvisioningOperation = "NotSpecified" + // ProvisioningOperationRead - The provisioning operation is read. + ProvisioningOperationRead ProvisioningOperation = "Read" + // ProvisioningOperationResourceCacheWaiting - The provisioning operation is waiting for resource cache. + ProvisioningOperationResourceCacheWaiting ProvisioningOperation = "ResourceCacheWaiting" + // ProvisioningOperationWaiting - The provisioning operation is waiting. + ProvisioningOperationWaiting ProvisioningOperation = "Waiting" ) // PossibleProvisioningOperationValues returns the possible values for the ProvisioningOperation const type. func PossibleProvisioningOperationValues() []ProvisioningOperation { return []ProvisioningOperation{ - ProvisioningOperationNotSpecified, + ProvisioningOperationAction, + ProvisioningOperationAzureAsyncOperationWaiting, ProvisioningOperationCreate, ProvisioningOperationDelete, - ProvisioningOperationWaiting, - ProvisioningOperationAzureAsyncOperationWaiting, - ProvisioningOperationResourceCacheWaiting, - ProvisioningOperationAction, - ProvisioningOperationRead, - ProvisioningOperationEvaluateDeploymentOutput, ProvisioningOperationDeploymentCleanup, + ProvisioningOperationEvaluateDeploymentOutput, + ProvisioningOperationNotSpecified, + ProvisioningOperationRead, + ProvisioningOperationResourceCacheWaiting, + ProvisioningOperationWaiting, } } @@ -348,19 +347,19 @@ func PossibleProvisioningStateValues() []ProvisioningState { type ResourceIdentityType string const ( + ResourceIdentityTypeNone ResourceIdentityType = "None" ResourceIdentityTypeSystemAssigned ResourceIdentityType = "SystemAssigned" - ResourceIdentityTypeUserAssigned ResourceIdentityType = "UserAssigned" ResourceIdentityTypeSystemAssignedUserAssigned ResourceIdentityType = "SystemAssigned, UserAssigned" - ResourceIdentityTypeNone ResourceIdentityType = "None" + ResourceIdentityTypeUserAssigned ResourceIdentityType = "UserAssigned" ) // PossibleResourceIdentityTypeValues returns the possible values for the ResourceIdentityType const type. func PossibleResourceIdentityTypeValues() []ResourceIdentityType { return []ResourceIdentityType{ + ResourceIdentityTypeNone, ResourceIdentityTypeSystemAssigned, - ResourceIdentityTypeUserAssigned, ResourceIdentityTypeSystemAssignedUserAssigned, - ResourceIdentityTypeNone, + ResourceIdentityTypeUserAssigned, } } @@ -390,14 +389,14 @@ func PossibleTagsPatchOperationValues() []TagsPatchOperation { type WhatIfResultFormat string const ( - WhatIfResultFormatResourceIDOnly WhatIfResultFormat = "ResourceIdOnly" WhatIfResultFormatFullResourcePayloads WhatIfResultFormat = "FullResourcePayloads" + WhatIfResultFormatResourceIDOnly WhatIfResultFormat = "ResourceIdOnly" ) // PossibleWhatIfResultFormatValues returns the possible values for the WhatIfResultFormat const type. func PossibleWhatIfResultFormatValues() []WhatIfResultFormat { return []WhatIfResultFormat{ - WhatIfResultFormatResourceIDOnly, WhatIfResultFormatFullResourcePayloads, + WhatIfResultFormatResourceIDOnly, } } diff --git a/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go b/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go index d990b7609509..76fe51416b30 100644 --- a/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go +++ b/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -55,18 +54,25 @@ func NewDeploymentOperationsClient(subscriptionID string, credential azcore.Toke // - options - DeploymentOperationsClientGetOptions contains the optional parameters for the DeploymentOperationsClient.Get // method. func (client *DeploymentOperationsClient) Get(ctx context.Context, resourceGroupName string, deploymentName string, operationID string, options *DeploymentOperationsClientGetOptions) (DeploymentOperationsClientGetResponse, error) { + var err error + const operationName = "DeploymentOperationsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceGroupName, deploymentName, operationID, options) if err != nil { return DeploymentOperationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentOperationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentOperationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -118,18 +124,25 @@ func (client *DeploymentOperationsClient) getHandleResponse(resp *http.Response) // - options - DeploymentOperationsClientGetAtManagementGroupScopeOptions contains the optional parameters for the DeploymentOperationsClient.GetAtManagementGroupScope // method. func (client *DeploymentOperationsClient) GetAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, operationID string, options *DeploymentOperationsClientGetAtManagementGroupScopeOptions) (DeploymentOperationsClientGetAtManagementGroupScopeResponse, error) { + var err error + const operationName = "DeploymentOperationsClient.GetAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, operationID, options) if err != nil { return DeploymentOperationsClientGetAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentOperationsClientGetAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientGetAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentOperationsClientGetAtManagementGroupScopeResponse{}, err } - return client.getAtManagementGroupScopeHandleResponse(resp) + resp, err := client.getAtManagementGroupScopeHandleResponse(httpResp) + return resp, err } // getAtManagementGroupScopeCreateRequest creates the GetAtManagementGroupScope request. @@ -177,18 +190,25 @@ func (client *DeploymentOperationsClient) getAtManagementGroupScopeHandleRespons // - options - DeploymentOperationsClientGetAtScopeOptions contains the optional parameters for the DeploymentOperationsClient.GetAtScope // method. func (client *DeploymentOperationsClient) GetAtScope(ctx context.Context, scope string, deploymentName string, operationID string, options *DeploymentOperationsClientGetAtScopeOptions) (DeploymentOperationsClientGetAtScopeResponse, error) { + var err error + const operationName = "DeploymentOperationsClient.GetAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtScopeCreateRequest(ctx, scope, deploymentName, operationID, options) if err != nil { return DeploymentOperationsClientGetAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentOperationsClientGetAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientGetAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentOperationsClientGetAtScopeResponse{}, err } - return client.getAtScopeHandleResponse(resp) + resp, err := client.getAtScopeHandleResponse(httpResp) + return resp, err } // getAtScopeCreateRequest creates the GetAtScope request. @@ -232,18 +252,25 @@ func (client *DeploymentOperationsClient) getAtScopeHandleResponse(resp *http.Re // - options - DeploymentOperationsClientGetAtSubscriptionScopeOptions contains the optional parameters for the DeploymentOperationsClient.GetAtSubscriptionScope // method. func (client *DeploymentOperationsClient) GetAtSubscriptionScope(ctx context.Context, deploymentName string, operationID string, options *DeploymentOperationsClientGetAtSubscriptionScopeOptions) (DeploymentOperationsClientGetAtSubscriptionScopeResponse, error) { + var err error + const operationName = "DeploymentOperationsClient.GetAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtSubscriptionScopeCreateRequest(ctx, deploymentName, operationID, options) if err != nil { return DeploymentOperationsClientGetAtSubscriptionScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentOperationsClientGetAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientGetAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentOperationsClientGetAtSubscriptionScopeResponse{}, err } - return client.getAtSubscriptionScopeHandleResponse(resp) + resp, err := client.getAtSubscriptionScopeHandleResponse(httpResp) + return resp, err } // getAtSubscriptionScopeCreateRequest creates the GetAtSubscriptionScope request. @@ -290,18 +317,25 @@ func (client *DeploymentOperationsClient) getAtSubscriptionScopeHandleResponse(r // - options - DeploymentOperationsClientGetAtTenantScopeOptions contains the optional parameters for the DeploymentOperationsClient.GetAtTenantScope // method. func (client *DeploymentOperationsClient) GetAtTenantScope(ctx context.Context, deploymentName string, operationID string, options *DeploymentOperationsClientGetAtTenantScopeOptions) (DeploymentOperationsClientGetAtTenantScopeResponse, error) { + var err error + const operationName = "DeploymentOperationsClient.GetAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtTenantScopeCreateRequest(ctx, deploymentName, operationID, options) if err != nil { return DeploymentOperationsClientGetAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentOperationsClientGetAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientGetAtTenantScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentOperationsClientGetAtTenantScopeResponse{}, err } - return client.getAtTenantScopeHandleResponse(resp) + resp, err := client.getAtTenantScopeHandleResponse(httpResp) + return resp, err } // getAtTenantScopeCreateRequest creates the GetAtTenantScope request. @@ -348,6 +382,7 @@ func (client *DeploymentOperationsClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListResponse) (DeploymentOperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -367,6 +402,7 @@ func (client *DeploymentOperationsClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -421,6 +457,7 @@ func (client *DeploymentOperationsClient) NewListAtManagementGroupScopePager(gro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtManagementGroupScopeResponse) (DeploymentOperationsClientListAtManagementGroupScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtManagementGroupScopePager") var req *policy.Request var err error if page == nil { @@ -440,6 +477,7 @@ func (client *DeploymentOperationsClient) NewListAtManagementGroupScopePager(gro } return client.listAtManagementGroupScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -490,6 +528,7 @@ func (client *DeploymentOperationsClient) NewListAtScopePager(scope string, depl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtScopeResponse) (DeploymentOperationsClientListAtScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtScopePager") var req *policy.Request var err error if page == nil { @@ -509,6 +548,7 @@ func (client *DeploymentOperationsClient) NewListAtScopePager(scope string, depl } return client.listAtScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -555,6 +595,7 @@ func (client *DeploymentOperationsClient) NewListAtSubscriptionScopePager(deploy return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtSubscriptionScopeResponse) (DeploymentOperationsClientListAtSubscriptionScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtSubscriptionScopePager") var req *policy.Request var err error if page == nil { @@ -574,6 +615,7 @@ func (client *DeploymentOperationsClient) NewListAtSubscriptionScopePager(deploy } return client.listAtSubscriptionScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -623,6 +665,7 @@ func (client *DeploymentOperationsClient) NewListAtTenantScopePager(deploymentNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtTenantScopeResponse) (DeploymentOperationsClientListAtTenantScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtTenantScopePager") var req *policy.Request var err error if page == nil { @@ -642,6 +685,7 @@ func (client *DeploymentOperationsClient) NewListAtTenantScopePager(deploymentNa } return client.listAtTenantScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armresources/deployments_client.go b/sdk/resourcemanager/resources/armresources/deployments_client.go index 11d005c641ef..7350d1edefb2 100644 --- a/sdk/resourcemanager/resources/armresources/deployments_client.go +++ b/sdk/resourcemanager/resources/armresources/deployments_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -53,18 +52,25 @@ func NewDeploymentsClient(subscriptionID string, credential azcore.TokenCredenti // - options - DeploymentsClientCalculateTemplateHashOptions contains the optional parameters for the DeploymentsClient.CalculateTemplateHash // method. func (client *DeploymentsClient) CalculateTemplateHash(ctx context.Context, templateParam any, options *DeploymentsClientCalculateTemplateHashOptions) (DeploymentsClientCalculateTemplateHashResponse, error) { + var err error + const operationName = "DeploymentsClient.CalculateTemplateHash" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.calculateTemplateHashCreateRequest(ctx, templateParam, options) if err != nil { return DeploymentsClientCalculateTemplateHashResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCalculateTemplateHashResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientCalculateTemplateHashResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCalculateTemplateHashResponse{}, err } - return client.calculateTemplateHashHandleResponse(resp) + resp, err := client.calculateTemplateHashHandleResponse(httpResp) + return resp, err } // calculateTemplateHashCreateRequest creates the CalculateTemplateHash request. @@ -78,7 +84,10 @@ func (client *DeploymentsClient) calculateTemplateHashCreateRequest(ctx context. reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, templateParam) + if err := runtime.MarshalAsJSON(req, templateParam); err != nil { + return nil, err + } + return req, nil } // calculateTemplateHashHandleResponse handles the CalculateTemplateHash response. @@ -100,16 +109,22 @@ func (client *DeploymentsClient) calculateTemplateHashHandleResponse(resp *http. // - deploymentName - The name of the deployment. // - options - DeploymentsClientCancelOptions contains the optional parameters for the DeploymentsClient.Cancel method. func (client *DeploymentsClient) Cancel(ctx context.Context, resourceGroupName string, deploymentName string, options *DeploymentsClientCancelOptions) (DeploymentsClientCancelResponse, error) { + var err error + const operationName = "DeploymentsClient.Cancel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelCreateRequest(ctx, resourceGroupName, deploymentName, options) if err != nil { return DeploymentsClientCancelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCancelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return DeploymentsClientCancelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCancelResponse{}, err } return DeploymentsClientCancelResponse{}, nil } @@ -151,16 +166,22 @@ func (client *DeploymentsClient) cancelCreateRequest(ctx context.Context, resour // - options - DeploymentsClientCancelAtManagementGroupScopeOptions contains the optional parameters for the DeploymentsClient.CancelAtManagementGroupScope // method. func (client *DeploymentsClient) CancelAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, options *DeploymentsClientCancelAtManagementGroupScopeOptions) (DeploymentsClientCancelAtManagementGroupScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CancelAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) if err != nil { return DeploymentsClientCancelAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCancelAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return DeploymentsClientCancelAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCancelAtManagementGroupScopeResponse{}, err } return DeploymentsClientCancelAtManagementGroupScopeResponse{}, nil } @@ -198,16 +219,22 @@ func (client *DeploymentsClient) cancelAtManagementGroupScopeCreateRequest(ctx c // - options - DeploymentsClientCancelAtScopeOptions contains the optional parameters for the DeploymentsClient.CancelAtScope // method. func (client *DeploymentsClient) CancelAtScope(ctx context.Context, scope string, deploymentName string, options *DeploymentsClientCancelAtScopeOptions) (DeploymentsClientCancelAtScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CancelAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelAtScopeCreateRequest(ctx, scope, deploymentName, options) if err != nil { return DeploymentsClientCancelAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCancelAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return DeploymentsClientCancelAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCancelAtScopeResponse{}, err } return DeploymentsClientCancelAtScopeResponse{}, nil } @@ -241,16 +268,22 @@ func (client *DeploymentsClient) cancelAtScopeCreateRequest(ctx context.Context, // - options - DeploymentsClientCancelAtSubscriptionScopeOptions contains the optional parameters for the DeploymentsClient.CancelAtSubscriptionScope // method. func (client *DeploymentsClient) CancelAtSubscriptionScope(ctx context.Context, deploymentName string, options *DeploymentsClientCancelAtSubscriptionScopeOptions) (DeploymentsClientCancelAtSubscriptionScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CancelAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientCancelAtSubscriptionScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCancelAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return DeploymentsClientCancelAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCancelAtSubscriptionScopeResponse{}, err } return DeploymentsClientCancelAtSubscriptionScopeResponse{}, nil } @@ -287,16 +320,22 @@ func (client *DeploymentsClient) cancelAtSubscriptionScopeCreateRequest(ctx cont // - options - DeploymentsClientCancelAtTenantScopeOptions contains the optional parameters for the DeploymentsClient.CancelAtTenantScope // method. func (client *DeploymentsClient) CancelAtTenantScope(ctx context.Context, deploymentName string, options *DeploymentsClientCancelAtTenantScopeOptions) (DeploymentsClientCancelAtTenantScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CancelAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelAtTenantScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientCancelAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCancelAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return DeploymentsClientCancelAtTenantScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCancelAtTenantScopeResponse{}, err } return DeploymentsClientCancelAtTenantScopeResponse{}, nil } @@ -327,18 +366,24 @@ func (client *DeploymentsClient) cancelAtTenantScopeCreateRequest(ctx context.Co // - options - DeploymentsClientCheckExistenceOptions contains the optional parameters for the DeploymentsClient.CheckExistence // method. func (client *DeploymentsClient) CheckExistence(ctx context.Context, resourceGroupName string, deploymentName string, options *DeploymentsClientCheckExistenceOptions) (DeploymentsClientCheckExistenceResponse, error) { + var err error + const operationName = "DeploymentsClient.CheckExistence" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceCreateRequest(ctx, resourceGroupName, deploymentName, options) if err != nil { return DeploymentsClientCheckExistenceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCheckExistenceResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return DeploymentsClientCheckExistenceResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCheckExistenceResponse{}, err } - return DeploymentsClientCheckExistenceResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return DeploymentsClientCheckExistenceResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceCreateRequest creates the CheckExistence request. @@ -375,18 +420,24 @@ func (client *DeploymentsClient) checkExistenceCreateRequest(ctx context.Context // - options - DeploymentsClientCheckExistenceAtManagementGroupScopeOptions contains the optional parameters for the DeploymentsClient.CheckExistenceAtManagementGroupScope // method. func (client *DeploymentsClient) CheckExistenceAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, options *DeploymentsClientCheckExistenceAtManagementGroupScopeOptions) (DeploymentsClientCheckExistenceAtManagementGroupScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CheckExistenceAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) if err != nil { return DeploymentsClientCheckExistenceAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCheckExistenceAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return DeploymentsClientCheckExistenceAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCheckExistenceAtManagementGroupScopeResponse{}, err } - return DeploymentsClientCheckExistenceAtManagementGroupScopeResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return DeploymentsClientCheckExistenceAtManagementGroupScopeResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceAtManagementGroupScopeCreateRequest creates the CheckExistenceAtManagementGroupScope request. @@ -419,18 +470,24 @@ func (client *DeploymentsClient) checkExistenceAtManagementGroupScopeCreateReque // - options - DeploymentsClientCheckExistenceAtScopeOptions contains the optional parameters for the DeploymentsClient.CheckExistenceAtScope // method. func (client *DeploymentsClient) CheckExistenceAtScope(ctx context.Context, scope string, deploymentName string, options *DeploymentsClientCheckExistenceAtScopeOptions) (DeploymentsClientCheckExistenceAtScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CheckExistenceAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceAtScopeCreateRequest(ctx, scope, deploymentName, options) if err != nil { return DeploymentsClientCheckExistenceAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCheckExistenceAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return DeploymentsClientCheckExistenceAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCheckExistenceAtScopeResponse{}, err } - return DeploymentsClientCheckExistenceAtScopeResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return DeploymentsClientCheckExistenceAtScopeResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceAtScopeCreateRequest creates the CheckExistenceAtScope request. @@ -459,18 +516,24 @@ func (client *DeploymentsClient) checkExistenceAtScopeCreateRequest(ctx context. // - options - DeploymentsClientCheckExistenceAtSubscriptionScopeOptions contains the optional parameters for the DeploymentsClient.CheckExistenceAtSubscriptionScope // method. func (client *DeploymentsClient) CheckExistenceAtSubscriptionScope(ctx context.Context, deploymentName string, options *DeploymentsClientCheckExistenceAtSubscriptionScopeOptions) (DeploymentsClientCheckExistenceAtSubscriptionScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CheckExistenceAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientCheckExistenceAtSubscriptionScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCheckExistenceAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return DeploymentsClientCheckExistenceAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCheckExistenceAtSubscriptionScopeResponse{}, err } - return DeploymentsClientCheckExistenceAtSubscriptionScopeResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return DeploymentsClientCheckExistenceAtSubscriptionScopeResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceAtSubscriptionScopeCreateRequest creates the CheckExistenceAtSubscriptionScope request. @@ -502,18 +565,24 @@ func (client *DeploymentsClient) checkExistenceAtSubscriptionScopeCreateRequest( // - options - DeploymentsClientCheckExistenceAtTenantScopeOptions contains the optional parameters for the DeploymentsClient.CheckExistenceAtTenantScope // method. func (client *DeploymentsClient) CheckExistenceAtTenantScope(ctx context.Context, deploymentName string, options *DeploymentsClientCheckExistenceAtTenantScopeOptions) (DeploymentsClientCheckExistenceAtTenantScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.CheckExistenceAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceAtTenantScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientCheckExistenceAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientCheckExistenceAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return DeploymentsClientCheckExistenceAtTenantScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientCheckExistenceAtTenantScopeResponse{}, err } - return DeploymentsClientCheckExistenceAtTenantScopeResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return DeploymentsClientCheckExistenceAtTenantScopeResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceAtTenantScopeCreateRequest creates the CheckExistenceAtTenantScope request. @@ -550,7 +619,8 @@ func (client *DeploymentsClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -561,18 +631,24 @@ func (client *DeploymentsClient) BeginCreateOrUpdate(ctx context.Context, resour // // Generated from API version 2021-04-01 func (client *DeploymentsClient) createOrUpdate(ctx context.Context, resourceGroupName string, deploymentName string, parameters Deployment, options *DeploymentsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -598,7 +674,10 @@ func (client *DeploymentsClient) createOrUpdateCreateRequest(ctx context.Context reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateAtManagementGroupScope - You can provide the template and parameters directly in the request or link @@ -617,7 +696,8 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtManagementGroupScope(ctx c if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -629,18 +709,24 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtManagementGroupScope(ctx c // // Generated from API version 2021-04-01 func (client *DeploymentsClient) createOrUpdateAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, parameters ScopedDeployment, options *DeploymentsClientBeginCreateOrUpdateAtManagementGroupScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginCreateOrUpdateAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateAtManagementGroupScopeCreateRequest creates the CreateOrUpdateAtManagementGroupScope request. @@ -662,7 +748,10 @@ func (client *DeploymentsClient) createOrUpdateAtManagementGroupScopeCreateReque reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateAtScope - You can provide the template and parameters directly in the request or link to JSON files. @@ -680,7 +769,8 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtScope(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientCreateOrUpdateAtScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -691,18 +781,24 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtScope(ctx context.Context, // // Generated from API version 2021-04-01 func (client *DeploymentsClient) createOrUpdateAtScope(ctx context.Context, scope string, deploymentName string, parameters Deployment, options *DeploymentsClientBeginCreateOrUpdateAtScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginCreateOrUpdateAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtScopeCreateRequest(ctx, scope, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateAtScopeCreateRequest creates the CreateOrUpdateAtScope request. @@ -721,7 +817,10 @@ func (client *DeploymentsClient) createOrUpdateAtScopeCreateRequest(ctx context. reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateAtSubscriptionScope - You can provide the template and parameters directly in the request or link to @@ -739,7 +838,8 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtSubscriptionScope(ctx cont if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -751,18 +851,24 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtSubscriptionScope(ctx cont // // Generated from API version 2021-04-01 func (client *DeploymentsClient) createOrUpdateAtSubscriptionScope(ctx context.Context, deploymentName string, parameters Deployment, options *DeploymentsClientBeginCreateOrUpdateAtSubscriptionScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginCreateOrUpdateAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtSubscriptionScopeCreateRequest(ctx, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateAtSubscriptionScopeCreateRequest creates the CreateOrUpdateAtSubscriptionScope request. @@ -784,7 +890,10 @@ func (client *DeploymentsClient) createOrUpdateAtSubscriptionScopeCreateRequest( reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateAtTenantScope - You can provide the template and parameters directly in the request or link to JSON @@ -802,7 +911,8 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtTenantScope(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientCreateOrUpdateAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -813,18 +923,24 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtTenantScope(ctx context.Co // // Generated from API version 2021-04-01 func (client *DeploymentsClient) createOrUpdateAtTenantScope(ctx context.Context, deploymentName string, parameters ScopedDeployment, options *DeploymentsClientBeginCreateOrUpdateAtTenantScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginCreateOrUpdateAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtTenantScopeCreateRequest(ctx, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateAtTenantScopeCreateRequest creates the CreateOrUpdateAtTenantScope request. @@ -842,7 +958,10 @@ func (client *DeploymentsClient) createOrUpdateAtTenantScopeCreateRequest(ctx co reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - A template deployment that is currently running cannot be deleted. Deleting a template deployment removes @@ -865,7 +984,8 @@ func (client *DeploymentsClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -883,18 +1003,24 @@ func (client *DeploymentsClient) BeginDelete(ctx context.Context, resourceGroupN // // Generated from API version 2021-04-01 func (client *DeploymentsClient) deleteOperation(ctx context.Context, resourceGroupName string, deploymentName string, options *DeploymentsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, resourceGroupName, deploymentName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -943,7 +1069,8 @@ func (client *DeploymentsClient) BeginDeleteAtManagementGroupScope(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientDeleteAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientDeleteAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -960,18 +1087,24 @@ func (client *DeploymentsClient) BeginDeleteAtManagementGroupScope(ctx context.C // // Generated from API version 2021-04-01 func (client *DeploymentsClient) deleteAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, options *DeploymentsClientBeginDeleteAtManagementGroupScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginDeleteAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteAtManagementGroupScopeCreateRequest creates the DeleteAtManagementGroupScope request. @@ -1016,7 +1149,8 @@ func (client *DeploymentsClient) BeginDeleteAtScope(ctx context.Context, scope s if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientDeleteAtScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientDeleteAtScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1033,18 +1167,24 @@ func (client *DeploymentsClient) BeginDeleteAtScope(ctx context.Context, scope s // // Generated from API version 2021-04-01 func (client *DeploymentsClient) deleteAtScope(ctx context.Context, scope string, deploymentName string, options *DeploymentsClientBeginDeleteAtScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginDeleteAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtScopeCreateRequest(ctx, scope, deploymentName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteAtScopeCreateRequest creates the DeleteAtScope request. @@ -1085,7 +1225,8 @@ func (client *DeploymentsClient) BeginDeleteAtSubscriptionScope(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientDeleteAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientDeleteAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1102,18 +1243,24 @@ func (client *DeploymentsClient) BeginDeleteAtSubscriptionScope(ctx context.Cont // // Generated from API version 2021-04-01 func (client *DeploymentsClient) deleteAtSubscriptionScope(ctx context.Context, deploymentName string, options *DeploymentsClientBeginDeleteAtSubscriptionScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginDeleteAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteAtSubscriptionScopeCreateRequest creates the DeleteAtSubscriptionScope request. @@ -1157,7 +1304,8 @@ func (client *DeploymentsClient) BeginDeleteAtTenantScope(ctx context.Context, d if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientDeleteAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientDeleteAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1174,18 +1322,24 @@ func (client *DeploymentsClient) BeginDeleteAtTenantScope(ctx context.Context, d // // Generated from API version 2021-04-01 func (client *DeploymentsClient) deleteAtTenantScope(ctx context.Context, deploymentName string, options *DeploymentsClientBeginDeleteAtTenantScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginDeleteAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtTenantScopeCreateRequest(ctx, deploymentName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteAtTenantScopeCreateRequest creates the DeleteAtTenantScope request. @@ -1215,18 +1369,25 @@ func (client *DeploymentsClient) deleteAtTenantScopeCreateRequest(ctx context.Co // - options - DeploymentsClientExportTemplateOptions contains the optional parameters for the DeploymentsClient.ExportTemplate // method. func (client *DeploymentsClient) ExportTemplate(ctx context.Context, resourceGroupName string, deploymentName string, options *DeploymentsClientExportTemplateOptions) (DeploymentsClientExportTemplateResponse, error) { + var err error + const operationName = "DeploymentsClient.ExportTemplate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateCreateRequest(ctx, resourceGroupName, deploymentName, options) if err != nil { return DeploymentsClientExportTemplateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientExportTemplateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientExportTemplateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientExportTemplateResponse{}, err } - return client.exportTemplateHandleResponse(resp) + resp, err := client.exportTemplateHandleResponse(httpResp) + return resp, err } // exportTemplateCreateRequest creates the ExportTemplate request. @@ -1273,18 +1434,25 @@ func (client *DeploymentsClient) exportTemplateHandleResponse(resp *http.Respons // - options - DeploymentsClientExportTemplateAtManagementGroupScopeOptions contains the optional parameters for the DeploymentsClient.ExportTemplateAtManagementGroupScope // method. func (client *DeploymentsClient) ExportTemplateAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, options *DeploymentsClientExportTemplateAtManagementGroupScopeOptions) (DeploymentsClientExportTemplateAtManagementGroupScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.ExportTemplateAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) if err != nil { return DeploymentsClientExportTemplateAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientExportTemplateAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientExportTemplateAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientExportTemplateAtManagementGroupScopeResponse{}, err } - return client.exportTemplateAtManagementGroupScopeHandleResponse(resp) + resp, err := client.exportTemplateAtManagementGroupScopeHandleResponse(httpResp) + return resp, err } // exportTemplateAtManagementGroupScopeCreateRequest creates the ExportTemplateAtManagementGroupScope request. @@ -1327,18 +1495,25 @@ func (client *DeploymentsClient) exportTemplateAtManagementGroupScopeHandleRespo // - options - DeploymentsClientExportTemplateAtScopeOptions contains the optional parameters for the DeploymentsClient.ExportTemplateAtScope // method. func (client *DeploymentsClient) ExportTemplateAtScope(ctx context.Context, scope string, deploymentName string, options *DeploymentsClientExportTemplateAtScopeOptions) (DeploymentsClientExportTemplateAtScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.ExportTemplateAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtScopeCreateRequest(ctx, scope, deploymentName, options) if err != nil { return DeploymentsClientExportTemplateAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientExportTemplateAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientExportTemplateAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientExportTemplateAtScopeResponse{}, err } - return client.exportTemplateAtScopeHandleResponse(resp) + resp, err := client.exportTemplateAtScopeHandleResponse(httpResp) + return resp, err } // exportTemplateAtScopeCreateRequest creates the ExportTemplateAtScope request. @@ -1377,18 +1552,25 @@ func (client *DeploymentsClient) exportTemplateAtScopeHandleResponse(resp *http. // - options - DeploymentsClientExportTemplateAtSubscriptionScopeOptions contains the optional parameters for the DeploymentsClient.ExportTemplateAtSubscriptionScope // method. func (client *DeploymentsClient) ExportTemplateAtSubscriptionScope(ctx context.Context, deploymentName string, options *DeploymentsClientExportTemplateAtSubscriptionScopeOptions) (DeploymentsClientExportTemplateAtSubscriptionScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.ExportTemplateAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientExportTemplateAtSubscriptionScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientExportTemplateAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientExportTemplateAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientExportTemplateAtSubscriptionScopeResponse{}, err } - return client.exportTemplateAtSubscriptionScopeHandleResponse(resp) + resp, err := client.exportTemplateAtSubscriptionScopeHandleResponse(httpResp) + return resp, err } // exportTemplateAtSubscriptionScopeCreateRequest creates the ExportTemplateAtSubscriptionScope request. @@ -1430,18 +1612,25 @@ func (client *DeploymentsClient) exportTemplateAtSubscriptionScopeHandleResponse // - options - DeploymentsClientExportTemplateAtTenantScopeOptions contains the optional parameters for the DeploymentsClient.ExportTemplateAtTenantScope // method. func (client *DeploymentsClient) ExportTemplateAtTenantScope(ctx context.Context, deploymentName string, options *DeploymentsClientExportTemplateAtTenantScopeOptions) (DeploymentsClientExportTemplateAtTenantScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.ExportTemplateAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtTenantScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientExportTemplateAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientExportTemplateAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientExportTemplateAtTenantScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientExportTemplateAtTenantScopeResponse{}, err } - return client.exportTemplateAtTenantScopeHandleResponse(resp) + resp, err := client.exportTemplateAtTenantScopeHandleResponse(httpResp) + return resp, err } // exportTemplateAtTenantScopeCreateRequest creates the ExportTemplateAtTenantScope request. @@ -1479,18 +1668,25 @@ func (client *DeploymentsClient) exportTemplateAtTenantScopeHandleResponse(resp // - deploymentName - The name of the deployment. // - options - DeploymentsClientGetOptions contains the optional parameters for the DeploymentsClient.Get method. func (client *DeploymentsClient) Get(ctx context.Context, resourceGroupName string, deploymentName string, options *DeploymentsClientGetOptions) (DeploymentsClientGetResponse, error) { + var err error + const operationName = "DeploymentsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceGroupName, deploymentName, options) if err != nil { return DeploymentsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -1537,18 +1733,25 @@ func (client *DeploymentsClient) getHandleResponse(resp *http.Response) (Deploym // - options - DeploymentsClientGetAtManagementGroupScopeOptions contains the optional parameters for the DeploymentsClient.GetAtManagementGroupScope // method. func (client *DeploymentsClient) GetAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, options *DeploymentsClientGetAtManagementGroupScopeOptions) (DeploymentsClientGetAtManagementGroupScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.GetAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) if err != nil { return DeploymentsClientGetAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientGetAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientGetAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientGetAtManagementGroupScopeResponse{}, err } - return client.getAtManagementGroupScopeHandleResponse(resp) + resp, err := client.getAtManagementGroupScopeHandleResponse(httpResp) + return resp, err } // getAtManagementGroupScopeCreateRequest creates the GetAtManagementGroupScope request. @@ -1590,18 +1793,25 @@ func (client *DeploymentsClient) getAtManagementGroupScopeHandleResponse(resp *h // - deploymentName - The name of the deployment. // - options - DeploymentsClientGetAtScopeOptions contains the optional parameters for the DeploymentsClient.GetAtScope method. func (client *DeploymentsClient) GetAtScope(ctx context.Context, scope string, deploymentName string, options *DeploymentsClientGetAtScopeOptions) (DeploymentsClientGetAtScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.GetAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtScopeCreateRequest(ctx, scope, deploymentName, options) if err != nil { return DeploymentsClientGetAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientGetAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientGetAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientGetAtScopeResponse{}, err } - return client.getAtScopeHandleResponse(resp) + resp, err := client.getAtScopeHandleResponse(httpResp) + return resp, err } // getAtScopeCreateRequest creates the GetAtScope request. @@ -1640,18 +1850,25 @@ func (client *DeploymentsClient) getAtScopeHandleResponse(resp *http.Response) ( // - options - DeploymentsClientGetAtSubscriptionScopeOptions contains the optional parameters for the DeploymentsClient.GetAtSubscriptionScope // method. func (client *DeploymentsClient) GetAtSubscriptionScope(ctx context.Context, deploymentName string, options *DeploymentsClientGetAtSubscriptionScopeOptions) (DeploymentsClientGetAtSubscriptionScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.GetAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientGetAtSubscriptionScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientGetAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientGetAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientGetAtSubscriptionScopeResponse{}, err } - return client.getAtSubscriptionScopeHandleResponse(resp) + resp, err := client.getAtSubscriptionScopeHandleResponse(httpResp) + return resp, err } // getAtSubscriptionScopeCreateRequest creates the GetAtSubscriptionScope request. @@ -1693,18 +1910,25 @@ func (client *DeploymentsClient) getAtSubscriptionScopeHandleResponse(resp *http // - options - DeploymentsClientGetAtTenantScopeOptions contains the optional parameters for the DeploymentsClient.GetAtTenantScope // method. func (client *DeploymentsClient) GetAtTenantScope(ctx context.Context, deploymentName string, options *DeploymentsClientGetAtTenantScopeOptions) (DeploymentsClientGetAtTenantScopeResponse, error) { + var err error + const operationName = "DeploymentsClient.GetAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtTenantScopeCreateRequest(ctx, deploymentName, options) if err != nil { return DeploymentsClientGetAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DeploymentsClientGetAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientGetAtTenantScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DeploymentsClientGetAtTenantScopeResponse{}, err } - return client.getAtTenantScopeHandleResponse(resp) + resp, err := client.getAtTenantScopeHandleResponse(httpResp) + return resp, err } // getAtTenantScopeCreateRequest creates the GetAtTenantScope request. @@ -1746,6 +1970,7 @@ func (client *DeploymentsClient) NewListAtManagementGroupScopePager(groupID stri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtManagementGroupScopeResponse) (DeploymentsClientListAtManagementGroupScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtManagementGroupScopePager") var req *policy.Request var err error if page == nil { @@ -1765,6 +1990,7 @@ func (client *DeploymentsClient) NewListAtManagementGroupScopePager(groupID stri } return client.listAtManagementGroupScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -1813,6 +2039,7 @@ func (client *DeploymentsClient) NewListAtScopePager(scope string, options *Depl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtScopeResponse) (DeploymentsClientListAtScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtScopePager") var req *policy.Request var err error if page == nil { @@ -1832,6 +2059,7 @@ func (client *DeploymentsClient) NewListAtScopePager(scope string, options *Depl } return client.listAtScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -1876,6 +2104,7 @@ func (client *DeploymentsClient) NewListAtSubscriptionScopePager(options *Deploy return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtSubscriptionScopeResponse) (DeploymentsClientListAtSubscriptionScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtSubscriptionScopePager") var req *policy.Request var err error if page == nil { @@ -1895,6 +2124,7 @@ func (client *DeploymentsClient) NewListAtSubscriptionScopePager(options *Deploy } return client.listAtSubscriptionScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -1942,6 +2172,7 @@ func (client *DeploymentsClient) NewListAtTenantScopePager(options *DeploymentsC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtTenantScopeResponse) (DeploymentsClientListAtTenantScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtTenantScopePager") var req *policy.Request var err error if page == nil { @@ -1961,6 +2192,7 @@ func (client *DeploymentsClient) NewListAtTenantScopePager(options *DeploymentsC } return client.listAtTenantScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -2005,6 +2237,7 @@ func (client *DeploymentsClient) NewListByResourceGroupPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DeploymentsClientListByResourceGroupResponse) (DeploymentsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -2024,6 +2257,7 @@ func (client *DeploymentsClient) NewListByResourceGroupPager(resourceGroupName s } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -2080,7 +2314,8 @@ func (client *DeploymentsClient) BeginValidate(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientValidateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientValidateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientValidateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2091,18 +2326,24 @@ func (client *DeploymentsClient) BeginValidate(ctx context.Context, resourceGrou // // Generated from API version 2021-04-01 func (client *DeploymentsClient) validate(ctx context.Context, resourceGroupName string, deploymentName string, parameters Deployment, options *DeploymentsClientBeginValidateOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginValidate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.validateCreateRequest(ctx, resourceGroupName, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // validateCreateRequest creates the Validate request. @@ -2128,7 +2369,10 @@ func (client *DeploymentsClient) validateCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginValidateAtManagementGroupScope - Validates whether the specified template is syntactically correct and will be accepted @@ -2147,7 +2391,8 @@ func (client *DeploymentsClient) BeginValidateAtManagementGroupScope(ctx context if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientValidateAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientValidateAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2159,18 +2404,24 @@ func (client *DeploymentsClient) BeginValidateAtManagementGroupScope(ctx context // // Generated from API version 2021-04-01 func (client *DeploymentsClient) validateAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, parameters ScopedDeployment, options *DeploymentsClientBeginValidateAtManagementGroupScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginValidateAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.validateAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // validateAtManagementGroupScopeCreateRequest creates the ValidateAtManagementGroupScope request. @@ -2192,7 +2443,10 @@ func (client *DeploymentsClient) validateAtManagementGroupScopeCreateRequest(ctx reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginValidateAtScope - Validates whether the specified template is syntactically correct and will be accepted by Azure @@ -2211,7 +2465,8 @@ func (client *DeploymentsClient) BeginValidateAtScope(ctx context.Context, scope if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientValidateAtScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientValidateAtScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2223,18 +2478,24 @@ func (client *DeploymentsClient) BeginValidateAtScope(ctx context.Context, scope // // Generated from API version 2021-04-01 func (client *DeploymentsClient) validateAtScope(ctx context.Context, scope string, deploymentName string, parameters Deployment, options *DeploymentsClientBeginValidateAtScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginValidateAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.validateAtScopeCreateRequest(ctx, scope, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // validateAtScopeCreateRequest creates the ValidateAtScope request. @@ -2253,7 +2514,10 @@ func (client *DeploymentsClient) validateAtScopeCreateRequest(ctx context.Contex reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginValidateAtSubscriptionScope - Validates whether the specified template is syntactically correct and will be accepted @@ -2271,7 +2535,8 @@ func (client *DeploymentsClient) BeginValidateAtSubscriptionScope(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientValidateAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientValidateAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2283,18 +2548,24 @@ func (client *DeploymentsClient) BeginValidateAtSubscriptionScope(ctx context.Co // // Generated from API version 2021-04-01 func (client *DeploymentsClient) validateAtSubscriptionScope(ctx context.Context, deploymentName string, parameters Deployment, options *DeploymentsClientBeginValidateAtSubscriptionScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginValidateAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.validateAtSubscriptionScopeCreateRequest(ctx, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // validateAtSubscriptionScopeCreateRequest creates the ValidateAtSubscriptionScope request. @@ -2316,7 +2587,10 @@ func (client *DeploymentsClient) validateAtSubscriptionScopeCreateRequest(ctx co reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginValidateAtTenantScope - Validates whether the specified template is syntactically correct and will be accepted by @@ -2334,7 +2608,8 @@ func (client *DeploymentsClient) BeginValidateAtTenantScope(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[DeploymentsClientValidateAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DeploymentsClientValidateAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2346,18 +2621,24 @@ func (client *DeploymentsClient) BeginValidateAtTenantScope(ctx context.Context, // // Generated from API version 2021-04-01 func (client *DeploymentsClient) validateAtTenantScope(ctx context.Context, deploymentName string, parameters ScopedDeployment, options *DeploymentsClientBeginValidateAtTenantScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginValidateAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.validateAtTenantScopeCreateRequest(ctx, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusBadRequest) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // validateAtTenantScopeCreateRequest creates the ValidateAtTenantScope request. @@ -2375,7 +2656,10 @@ func (client *DeploymentsClient) validateAtTenantScopeCreateRequest(ctx context. reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginWhatIf - Returns changes that will be made by the deployment if executed at the scope of the resource group. @@ -2392,9 +2676,10 @@ func (client *DeploymentsClient) BeginWhatIf(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2405,18 +2690,24 @@ func (client *DeploymentsClient) BeginWhatIf(ctx context.Context, resourceGroupN // // Generated from API version 2021-04-01 func (client *DeploymentsClient) whatIf(ctx context.Context, resourceGroupName string, deploymentName string, parameters DeploymentWhatIf, options *DeploymentsClientBeginWhatIfOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginWhatIf" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.whatIfCreateRequest(ctx, resourceGroupName, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // whatIfCreateRequest creates the WhatIf request. @@ -2442,7 +2733,10 @@ func (client *DeploymentsClient) whatIfCreateRequest(ctx context.Context, resour reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginWhatIfAtManagementGroupScope - Returns changes that will be made by the deployment if executed at the scope of the @@ -2461,9 +2755,10 @@ func (client *DeploymentsClient) BeginWhatIfAtManagementGroupScope(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtManagementGroupScopeResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtManagementGroupScopeResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2475,18 +2770,24 @@ func (client *DeploymentsClient) BeginWhatIfAtManagementGroupScope(ctx context.C // // Generated from API version 2021-04-01 func (client *DeploymentsClient) whatIfAtManagementGroupScope(ctx context.Context, groupID string, deploymentName string, parameters ScopedDeploymentWhatIf, options *DeploymentsClientBeginWhatIfAtManagementGroupScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginWhatIfAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.whatIfAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // whatIfAtManagementGroupScopeCreateRequest creates the WhatIfAtManagementGroupScope request. @@ -2508,7 +2809,10 @@ func (client *DeploymentsClient) whatIfAtManagementGroupScopeCreateRequest(ctx c reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginWhatIfAtSubscriptionScope - Returns changes that will be made by the deployment if executed at the scope of the subscription. @@ -2525,9 +2829,10 @@ func (client *DeploymentsClient) BeginWhatIfAtSubscriptionScope(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtSubscriptionScopeResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtSubscriptionScopeResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2538,18 +2843,24 @@ func (client *DeploymentsClient) BeginWhatIfAtSubscriptionScope(ctx context.Cont // // Generated from API version 2021-04-01 func (client *DeploymentsClient) whatIfAtSubscriptionScope(ctx context.Context, deploymentName string, parameters DeploymentWhatIf, options *DeploymentsClientBeginWhatIfAtSubscriptionScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginWhatIfAtSubscriptionScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.whatIfAtSubscriptionScopeCreateRequest(ctx, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // whatIfAtSubscriptionScopeCreateRequest creates the WhatIfAtSubscriptionScope request. @@ -2571,7 +2882,10 @@ func (client *DeploymentsClient) whatIfAtSubscriptionScopeCreateRequest(ctx cont reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginWhatIfAtTenantScope - Returns changes that will be made by the deployment if executed at the scope of the tenant group. @@ -2588,9 +2902,10 @@ func (client *DeploymentsClient) BeginWhatIfAtTenantScope(ctx context.Context, d if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtTenantScopeResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtTenantScopeResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -2601,18 +2916,24 @@ func (client *DeploymentsClient) BeginWhatIfAtTenantScope(ctx context.Context, d // // Generated from API version 2021-04-01 func (client *DeploymentsClient) whatIfAtTenantScope(ctx context.Context, deploymentName string, parameters ScopedDeploymentWhatIf, options *DeploymentsClientBeginWhatIfAtTenantScopeOptions) (*http.Response, error) { + var err error + const operationName = "DeploymentsClient.BeginWhatIfAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.whatIfAtTenantScopeCreateRequest(ctx, deploymentName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // whatIfAtTenantScopeCreateRequest creates the WhatIfAtTenantScope request. @@ -2630,5 +2951,8 @@ func (client *DeploymentsClient) whatIfAtTenantScopeCreateRequest(ctx context.Co reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go b/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go new file mode 100644 index 000000000000..b78977ea7db8 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go @@ -0,0 +1,487 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "regexp" + "strconv" +) + +// DeploymentOperationsServer is a fake server for instances of the armresources.DeploymentOperationsClient type. +type DeploymentOperationsServer struct { + // Get is the fake for method DeploymentOperationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, deploymentName string, operationID string, options *armresources.DeploymentOperationsClientGetOptions) (resp azfake.Responder[armresources.DeploymentOperationsClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroupScope is the fake for method DeploymentOperationsClient.GetAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, operationID string, options *armresources.DeploymentOperationsClientGetAtManagementGroupScopeOptions) (resp azfake.Responder[armresources.DeploymentOperationsClientGetAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // GetAtScope is the fake for method DeploymentOperationsClient.GetAtScope + // HTTP status codes to indicate success: http.StatusOK + GetAtScope func(ctx context.Context, scope string, deploymentName string, operationID string, options *armresources.DeploymentOperationsClientGetAtScopeOptions) (resp azfake.Responder[armresources.DeploymentOperationsClientGetAtScopeResponse], errResp azfake.ErrorResponder) + + // GetAtSubscriptionScope is the fake for method DeploymentOperationsClient.GetAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusOK + GetAtSubscriptionScope func(ctx context.Context, deploymentName string, operationID string, options *armresources.DeploymentOperationsClientGetAtSubscriptionScopeOptions) (resp azfake.Responder[armresources.DeploymentOperationsClientGetAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // GetAtTenantScope is the fake for method DeploymentOperationsClient.GetAtTenantScope + // HTTP status codes to indicate success: http.StatusOK + GetAtTenantScope func(ctx context.Context, deploymentName string, operationID string, options *armresources.DeploymentOperationsClientGetAtTenantScopeOptions) (resp azfake.Responder[armresources.DeploymentOperationsClientGetAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DeploymentOperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, deploymentName string, options *armresources.DeploymentOperationsClientListOptions) (resp azfake.PagerResponder[armresources.DeploymentOperationsClientListResponse]) + + // NewListAtManagementGroupScopePager is the fake for method DeploymentOperationsClient.NewListAtManagementGroupScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtManagementGroupScopePager func(groupID string, deploymentName string, options *armresources.DeploymentOperationsClientListAtManagementGroupScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentOperationsClientListAtManagementGroupScopeResponse]) + + // NewListAtScopePager is the fake for method DeploymentOperationsClient.NewListAtScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtScopePager func(scope string, deploymentName string, options *armresources.DeploymentOperationsClientListAtScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentOperationsClientListAtScopeResponse]) + + // NewListAtSubscriptionScopePager is the fake for method DeploymentOperationsClient.NewListAtSubscriptionScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtSubscriptionScopePager func(deploymentName string, options *armresources.DeploymentOperationsClientListAtSubscriptionScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentOperationsClientListAtSubscriptionScopeResponse]) + + // NewListAtTenantScopePager is the fake for method DeploymentOperationsClient.NewListAtTenantScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtTenantScopePager func(deploymentName string, options *armresources.DeploymentOperationsClientListAtTenantScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentOperationsClientListAtTenantScopeResponse]) +} + +// NewDeploymentOperationsServerTransport creates a new instance of DeploymentOperationsServerTransport with the provided implementation. +// The returned DeploymentOperationsServerTransport instance is connected to an instance of armresources.DeploymentOperationsClient by way of the +// undefined.Transporter field. +func NewDeploymentOperationsServerTransport(srv *DeploymentOperationsServer) *DeploymentOperationsServerTransport { + return &DeploymentOperationsServerTransport{srv: srv} +} + +// DeploymentOperationsServerTransport connects instances of armresources.DeploymentOperationsClient to instances of DeploymentOperationsServer. +// Don't use this type directly, use NewDeploymentOperationsServerTransport instead. +type DeploymentOperationsServerTransport struct { + srv *DeploymentOperationsServer + newListPager *azfake.PagerResponder[armresources.DeploymentOperationsClientListResponse] + newListAtManagementGroupScopePager *azfake.PagerResponder[armresources.DeploymentOperationsClientListAtManagementGroupScopeResponse] + newListAtScopePager *azfake.PagerResponder[armresources.DeploymentOperationsClientListAtScopeResponse] + newListAtSubscriptionScopePager *azfake.PagerResponder[armresources.DeploymentOperationsClientListAtSubscriptionScopeResponse] + newListAtTenantScopePager *azfake.PagerResponder[armresources.DeploymentOperationsClientListAtTenantScopeResponse] +} + +// Do implements the policy.Transporter interface for DeploymentOperationsServerTransport. +func (d *DeploymentOperationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "DeploymentOperationsClient.Get": + resp, err = d.dispatchGet(req) + case "DeploymentOperationsClient.GetAtManagementGroupScope": + resp, err = d.dispatchGetAtManagementGroupScope(req) + case "DeploymentOperationsClient.GetAtScope": + resp, err = d.dispatchGetAtScope(req) + case "DeploymentOperationsClient.GetAtSubscriptionScope": + resp, err = d.dispatchGetAtSubscriptionScope(req) + case "DeploymentOperationsClient.GetAtTenantScope": + resp, err = d.dispatchGetAtTenantScope(req) + case "DeploymentOperationsClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DeploymentOperationsClient.NewListAtManagementGroupScopePager": + resp, err = d.dispatchNewListAtManagementGroupScopePager(req) + case "DeploymentOperationsClient.NewListAtScopePager": + resp, err = d.dispatchNewListAtScopePager(req) + case "DeploymentOperationsClient.NewListAtSubscriptionScopePager": + resp, err = d.dispatchNewListAtSubscriptionScopePager(req) + case "DeploymentOperationsClient.NewListAtTenantScopePager": + resp, err = d.dispatchNewListAtTenantScopePager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentOperation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchGetAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtManagementGroupScope not implemented")} + } + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentOperation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentOperation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchGetAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtSubscriptionScope not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentOperation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtTenantScope not implemented")} + } + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentOperation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if d.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/deployments/(?P[a-zA-Z0-9-_]+)/operations" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentOperationsClientListOptions + if topParam != nil { + options = &armresources.DeploymentOperationsClientListOptions{ + Top: topParam, + } + } + resp := d.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], options) + d.newListPager = &resp + server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armresources.DeploymentOperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListPager) { + d.newListPager = nil + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtManagementGroupScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtManagementGroupScopePager not implemented")} + } + if d.newListAtManagementGroupScopePager == nil { + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentOperationsClientListAtManagementGroupScopeOptions + if topParam != nil { + options = &armresources.DeploymentOperationsClientListAtManagementGroupScopeOptions{ + Top: topParam, + } + } + resp := d.srv.NewListAtManagementGroupScopePager(matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], options) + d.newListAtManagementGroupScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtManagementGroupScopePager, req, func(page *armresources.DeploymentOperationsClientListAtManagementGroupScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtManagementGroupScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtManagementGroupScopePager) { + d.newListAtManagementGroupScopePager = nil + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtScopePager not implemented")} + } + if d.newListAtScopePager == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentOperationsClientListAtScopeOptions + if topParam != nil { + options = &armresources.DeploymentOperationsClientListAtScopeOptions{ + Top: topParam, + } + } + resp := d.srv.NewListAtScopePager(matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], options) + d.newListAtScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtScopePager, req, func(page *armresources.DeploymentOperationsClientListAtScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtScopePager) { + d.newListAtScopePager = nil + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtSubscriptionScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtSubscriptionScopePager not implemented")} + } + if d.newListAtSubscriptionScopePager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentOperationsClientListAtSubscriptionScopeOptions + if topParam != nil { + options = &armresources.DeploymentOperationsClientListAtSubscriptionScopeOptions{ + Top: topParam, + } + } + resp := d.srv.NewListAtSubscriptionScopePager(matches[regex.SubexpIndex("deploymentName")], options) + d.newListAtSubscriptionScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtSubscriptionScopePager, req, func(page *armresources.DeploymentOperationsClientListAtSubscriptionScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtSubscriptionScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtSubscriptionScopePager) { + d.newListAtSubscriptionScopePager = nil + } + return resp, nil +} + +func (d *DeploymentOperationsServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtTenantScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtTenantScopePager not implemented")} + } + if d.newListAtTenantScopePager == nil { + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentOperationsClientListAtTenantScopeOptions + if topParam != nil { + options = &armresources.DeploymentOperationsClientListAtTenantScopeOptions{ + Top: topParam, + } + } + resp := d.srv.NewListAtTenantScopePager(matches[regex.SubexpIndex("deploymentName")], options) + d.newListAtTenantScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtTenantScopePager, req, func(page *armresources.DeploymentOperationsClientListAtTenantScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtTenantScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtTenantScopePager) { + d.newListAtTenantScopePager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/deployments_server.go b/sdk/resourcemanager/resources/armresources/fake/deployments_server.go new file mode 100644 index 000000000000..0512d1b4b1bd --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/deployments_server.go @@ -0,0 +1,1801 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "regexp" + "strconv" +) + +// DeploymentsServer is a fake server for instances of the armresources.DeploymentsClient type. +type DeploymentsServer struct { + // CalculateTemplateHash is the fake for method DeploymentsClient.CalculateTemplateHash + // HTTP status codes to indicate success: http.StatusOK + CalculateTemplateHash func(ctx context.Context, templateParam any, options *armresources.DeploymentsClientCalculateTemplateHashOptions) (resp azfake.Responder[armresources.DeploymentsClientCalculateTemplateHashResponse], errResp azfake.ErrorResponder) + + // Cancel is the fake for method DeploymentsClient.Cancel + // HTTP status codes to indicate success: http.StatusNoContent + Cancel func(ctx context.Context, resourceGroupName string, deploymentName string, options *armresources.DeploymentsClientCancelOptions) (resp azfake.Responder[armresources.DeploymentsClientCancelResponse], errResp azfake.ErrorResponder) + + // CancelAtManagementGroupScope is the fake for method DeploymentsClient.CancelAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusNoContent + CancelAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, options *armresources.DeploymentsClientCancelAtManagementGroupScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCancelAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // CancelAtScope is the fake for method DeploymentsClient.CancelAtScope + // HTTP status codes to indicate success: http.StatusNoContent + CancelAtScope func(ctx context.Context, scope string, deploymentName string, options *armresources.DeploymentsClientCancelAtScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCancelAtScopeResponse], errResp azfake.ErrorResponder) + + // CancelAtSubscriptionScope is the fake for method DeploymentsClient.CancelAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusNoContent + CancelAtSubscriptionScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientCancelAtSubscriptionScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCancelAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // CancelAtTenantScope is the fake for method DeploymentsClient.CancelAtTenantScope + // HTTP status codes to indicate success: http.StatusNoContent + CancelAtTenantScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientCancelAtTenantScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCancelAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // CheckExistence is the fake for method DeploymentsClient.CheckExistence + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistence func(ctx context.Context, resourceGroupName string, deploymentName string, options *armresources.DeploymentsClientCheckExistenceOptions) (resp azfake.Responder[armresources.DeploymentsClientCheckExistenceResponse], errResp azfake.ErrorResponder) + + // CheckExistenceAtManagementGroupScope is the fake for method DeploymentsClient.CheckExistenceAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistenceAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, options *armresources.DeploymentsClientCheckExistenceAtManagementGroupScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCheckExistenceAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // CheckExistenceAtScope is the fake for method DeploymentsClient.CheckExistenceAtScope + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistenceAtScope func(ctx context.Context, scope string, deploymentName string, options *armresources.DeploymentsClientCheckExistenceAtScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCheckExistenceAtScopeResponse], errResp azfake.ErrorResponder) + + // CheckExistenceAtSubscriptionScope is the fake for method DeploymentsClient.CheckExistenceAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistenceAtSubscriptionScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientCheckExistenceAtSubscriptionScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCheckExistenceAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // CheckExistenceAtTenantScope is the fake for method DeploymentsClient.CheckExistenceAtTenantScope + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistenceAtTenantScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientCheckExistenceAtTenantScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientCheckExistenceAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method DeploymentsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, deploymentName string, parameters armresources.Deployment, options *armresources.DeploymentsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateAtManagementGroupScope is the fake for method DeploymentsClient.BeginCreateOrUpdateAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, parameters armresources.ScopedDeployment, options *armresources.DeploymentsClientBeginCreateOrUpdateAtManagementGroupScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateAtScope is the fake for method DeploymentsClient.BeginCreateOrUpdateAtScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtScope func(ctx context.Context, scope string, deploymentName string, parameters armresources.Deployment, options *armresources.DeploymentsClientBeginCreateOrUpdateAtScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtScopeResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateAtSubscriptionScope is the fake for method DeploymentsClient.BeginCreateOrUpdateAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtSubscriptionScope func(ctx context.Context, deploymentName string, parameters armresources.Deployment, options *armresources.DeploymentsClientBeginCreateOrUpdateAtSubscriptionScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateAtTenantScope is the fake for method DeploymentsClient.BeginCreateOrUpdateAtTenantScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtTenantScope func(ctx context.Context, deploymentName string, parameters armresources.ScopedDeployment, options *armresources.DeploymentsClientBeginCreateOrUpdateAtTenantScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DeploymentsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, deploymentName string, options *armresources.DeploymentsClientBeginDeleteOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtManagementGroupScope is the fake for method DeploymentsClient.BeginDeleteAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDeleteAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, options *armresources.DeploymentsClientBeginDeleteAtManagementGroupScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientDeleteAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtScope is the fake for method DeploymentsClient.BeginDeleteAtScope + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDeleteAtScope func(ctx context.Context, scope string, deploymentName string, options *armresources.DeploymentsClientBeginDeleteAtScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientDeleteAtScopeResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtSubscriptionScope is the fake for method DeploymentsClient.BeginDeleteAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDeleteAtSubscriptionScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientBeginDeleteAtSubscriptionScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientDeleteAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtTenantScope is the fake for method DeploymentsClient.BeginDeleteAtTenantScope + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDeleteAtTenantScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientBeginDeleteAtTenantScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientDeleteAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // ExportTemplate is the fake for method DeploymentsClient.ExportTemplate + // HTTP status codes to indicate success: http.StatusOK + ExportTemplate func(ctx context.Context, resourceGroupName string, deploymentName string, options *armresources.DeploymentsClientExportTemplateOptions) (resp azfake.Responder[armresources.DeploymentsClientExportTemplateResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtManagementGroupScope is the fake for method DeploymentsClient.ExportTemplateAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, options *armresources.DeploymentsClientExportTemplateAtManagementGroupScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientExportTemplateAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtScope is the fake for method DeploymentsClient.ExportTemplateAtScope + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtScope func(ctx context.Context, scope string, deploymentName string, options *armresources.DeploymentsClientExportTemplateAtScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientExportTemplateAtScopeResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtSubscriptionScope is the fake for method DeploymentsClient.ExportTemplateAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtSubscriptionScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientExportTemplateAtSubscriptionScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientExportTemplateAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtTenantScope is the fake for method DeploymentsClient.ExportTemplateAtTenantScope + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtTenantScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientExportTemplateAtTenantScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientExportTemplateAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DeploymentsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, deploymentName string, options *armresources.DeploymentsClientGetOptions) (resp azfake.Responder[armresources.DeploymentsClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroupScope is the fake for method DeploymentsClient.GetAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, options *armresources.DeploymentsClientGetAtManagementGroupScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientGetAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // GetAtScope is the fake for method DeploymentsClient.GetAtScope + // HTTP status codes to indicate success: http.StatusOK + GetAtScope func(ctx context.Context, scope string, deploymentName string, options *armresources.DeploymentsClientGetAtScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientGetAtScopeResponse], errResp azfake.ErrorResponder) + + // GetAtSubscriptionScope is the fake for method DeploymentsClient.GetAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusOK + GetAtSubscriptionScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientGetAtSubscriptionScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientGetAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // GetAtTenantScope is the fake for method DeploymentsClient.GetAtTenantScope + // HTTP status codes to indicate success: http.StatusOK + GetAtTenantScope func(ctx context.Context, deploymentName string, options *armresources.DeploymentsClientGetAtTenantScopeOptions) (resp azfake.Responder[armresources.DeploymentsClientGetAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // NewListAtManagementGroupScopePager is the fake for method DeploymentsClient.NewListAtManagementGroupScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtManagementGroupScopePager func(groupID string, options *armresources.DeploymentsClientListAtManagementGroupScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentsClientListAtManagementGroupScopeResponse]) + + // NewListAtScopePager is the fake for method DeploymentsClient.NewListAtScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtScopePager func(scope string, options *armresources.DeploymentsClientListAtScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentsClientListAtScopeResponse]) + + // NewListAtSubscriptionScopePager is the fake for method DeploymentsClient.NewListAtSubscriptionScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtSubscriptionScopePager func(options *armresources.DeploymentsClientListAtSubscriptionScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentsClientListAtSubscriptionScopeResponse]) + + // NewListAtTenantScopePager is the fake for method DeploymentsClient.NewListAtTenantScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtTenantScopePager func(options *armresources.DeploymentsClientListAtTenantScopeOptions) (resp azfake.PagerResponder[armresources.DeploymentsClientListAtTenantScopeResponse]) + + // NewListByResourceGroupPager is the fake for method DeploymentsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armresources.DeploymentsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armresources.DeploymentsClientListByResourceGroupResponse]) + + // BeginValidate is the fake for method DeploymentsClient.BeginValidate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusBadRequest + BeginValidate func(ctx context.Context, resourceGroupName string, deploymentName string, parameters armresources.Deployment, options *armresources.DeploymentsClientBeginValidateOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientValidateResponse], errResp azfake.ErrorResponder) + + // BeginValidateAtManagementGroupScope is the fake for method DeploymentsClient.BeginValidateAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusBadRequest + BeginValidateAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, parameters armresources.ScopedDeployment, options *armresources.DeploymentsClientBeginValidateAtManagementGroupScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientValidateAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // BeginValidateAtScope is the fake for method DeploymentsClient.BeginValidateAtScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusBadRequest + BeginValidateAtScope func(ctx context.Context, scope string, deploymentName string, parameters armresources.Deployment, options *armresources.DeploymentsClientBeginValidateAtScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientValidateAtScopeResponse], errResp azfake.ErrorResponder) + + // BeginValidateAtSubscriptionScope is the fake for method DeploymentsClient.BeginValidateAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusBadRequest + BeginValidateAtSubscriptionScope func(ctx context.Context, deploymentName string, parameters armresources.Deployment, options *armresources.DeploymentsClientBeginValidateAtSubscriptionScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientValidateAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // BeginValidateAtTenantScope is the fake for method DeploymentsClient.BeginValidateAtTenantScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusBadRequest + BeginValidateAtTenantScope func(ctx context.Context, deploymentName string, parameters armresources.ScopedDeployment, options *armresources.DeploymentsClientBeginValidateAtTenantScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientValidateAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // BeginWhatIf is the fake for method DeploymentsClient.BeginWhatIf + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginWhatIf func(ctx context.Context, resourceGroupName string, deploymentName string, parameters armresources.DeploymentWhatIf, options *armresources.DeploymentsClientBeginWhatIfOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientWhatIfResponse], errResp azfake.ErrorResponder) + + // BeginWhatIfAtManagementGroupScope is the fake for method DeploymentsClient.BeginWhatIfAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginWhatIfAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, parameters armresources.ScopedDeploymentWhatIf, options *armresources.DeploymentsClientBeginWhatIfAtManagementGroupScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientWhatIfAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // BeginWhatIfAtSubscriptionScope is the fake for method DeploymentsClient.BeginWhatIfAtSubscriptionScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginWhatIfAtSubscriptionScope func(ctx context.Context, deploymentName string, parameters armresources.DeploymentWhatIf, options *armresources.DeploymentsClientBeginWhatIfAtSubscriptionScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientWhatIfAtSubscriptionScopeResponse], errResp azfake.ErrorResponder) + + // BeginWhatIfAtTenantScope is the fake for method DeploymentsClient.BeginWhatIfAtTenantScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginWhatIfAtTenantScope func(ctx context.Context, deploymentName string, parameters armresources.ScopedDeploymentWhatIf, options *armresources.DeploymentsClientBeginWhatIfAtTenantScopeOptions) (resp azfake.PollerResponder[armresources.DeploymentsClientWhatIfAtTenantScopeResponse], errResp azfake.ErrorResponder) +} + +// NewDeploymentsServerTransport creates a new instance of DeploymentsServerTransport with the provided implementation. +// The returned DeploymentsServerTransport instance is connected to an instance of armresources.DeploymentsClient by way of the +// undefined.Transporter field. +func NewDeploymentsServerTransport(srv *DeploymentsServer) *DeploymentsServerTransport { + return &DeploymentsServerTransport{srv: srv} +} + +// DeploymentsServerTransport connects instances of armresources.DeploymentsClient to instances of DeploymentsServer. +// Don't use this type directly, use NewDeploymentsServerTransport instead. +type DeploymentsServerTransport struct { + srv *DeploymentsServer + beginCreateOrUpdate *azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateResponse] + beginCreateOrUpdateAtManagementGroupScope *azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse] + beginCreateOrUpdateAtScope *azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtScopeResponse] + beginCreateOrUpdateAtSubscriptionScope *azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse] + beginCreateOrUpdateAtTenantScope *azfake.PollerResponder[armresources.DeploymentsClientCreateOrUpdateAtTenantScopeResponse] + beginDelete *azfake.PollerResponder[armresources.DeploymentsClientDeleteResponse] + beginDeleteAtManagementGroupScope *azfake.PollerResponder[armresources.DeploymentsClientDeleteAtManagementGroupScopeResponse] + beginDeleteAtScope *azfake.PollerResponder[armresources.DeploymentsClientDeleteAtScopeResponse] + beginDeleteAtSubscriptionScope *azfake.PollerResponder[armresources.DeploymentsClientDeleteAtSubscriptionScopeResponse] + beginDeleteAtTenantScope *azfake.PollerResponder[armresources.DeploymentsClientDeleteAtTenantScopeResponse] + newListAtManagementGroupScopePager *azfake.PagerResponder[armresources.DeploymentsClientListAtManagementGroupScopeResponse] + newListAtScopePager *azfake.PagerResponder[armresources.DeploymentsClientListAtScopeResponse] + newListAtSubscriptionScopePager *azfake.PagerResponder[armresources.DeploymentsClientListAtSubscriptionScopeResponse] + newListAtTenantScopePager *azfake.PagerResponder[armresources.DeploymentsClientListAtTenantScopeResponse] + newListByResourceGroupPager *azfake.PagerResponder[armresources.DeploymentsClientListByResourceGroupResponse] + beginValidate *azfake.PollerResponder[armresources.DeploymentsClientValidateResponse] + beginValidateAtManagementGroupScope *azfake.PollerResponder[armresources.DeploymentsClientValidateAtManagementGroupScopeResponse] + beginValidateAtScope *azfake.PollerResponder[armresources.DeploymentsClientValidateAtScopeResponse] + beginValidateAtSubscriptionScope *azfake.PollerResponder[armresources.DeploymentsClientValidateAtSubscriptionScopeResponse] + beginValidateAtTenantScope *azfake.PollerResponder[armresources.DeploymentsClientValidateAtTenantScopeResponse] + beginWhatIf *azfake.PollerResponder[armresources.DeploymentsClientWhatIfResponse] + beginWhatIfAtManagementGroupScope *azfake.PollerResponder[armresources.DeploymentsClientWhatIfAtManagementGroupScopeResponse] + beginWhatIfAtSubscriptionScope *azfake.PollerResponder[armresources.DeploymentsClientWhatIfAtSubscriptionScopeResponse] + beginWhatIfAtTenantScope *azfake.PollerResponder[armresources.DeploymentsClientWhatIfAtTenantScopeResponse] +} + +// Do implements the policy.Transporter interface for DeploymentsServerTransport. +func (d *DeploymentsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "DeploymentsClient.CalculateTemplateHash": + resp, err = d.dispatchCalculateTemplateHash(req) + case "DeploymentsClient.Cancel": + resp, err = d.dispatchCancel(req) + case "DeploymentsClient.CancelAtManagementGroupScope": + resp, err = d.dispatchCancelAtManagementGroupScope(req) + case "DeploymentsClient.CancelAtScope": + resp, err = d.dispatchCancelAtScope(req) + case "DeploymentsClient.CancelAtSubscriptionScope": + resp, err = d.dispatchCancelAtSubscriptionScope(req) + case "DeploymentsClient.CancelAtTenantScope": + resp, err = d.dispatchCancelAtTenantScope(req) + case "DeploymentsClient.CheckExistence": + resp, err = d.dispatchCheckExistence(req) + case "DeploymentsClient.CheckExistenceAtManagementGroupScope": + resp, err = d.dispatchCheckExistenceAtManagementGroupScope(req) + case "DeploymentsClient.CheckExistenceAtScope": + resp, err = d.dispatchCheckExistenceAtScope(req) + case "DeploymentsClient.CheckExistenceAtSubscriptionScope": + resp, err = d.dispatchCheckExistenceAtSubscriptionScope(req) + case "DeploymentsClient.CheckExistenceAtTenantScope": + resp, err = d.dispatchCheckExistenceAtTenantScope(req) + case "DeploymentsClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DeploymentsClient.BeginCreateOrUpdateAtManagementGroupScope": + resp, err = d.dispatchBeginCreateOrUpdateAtManagementGroupScope(req) + case "DeploymentsClient.BeginCreateOrUpdateAtScope": + resp, err = d.dispatchBeginCreateOrUpdateAtScope(req) + case "DeploymentsClient.BeginCreateOrUpdateAtSubscriptionScope": + resp, err = d.dispatchBeginCreateOrUpdateAtSubscriptionScope(req) + case "DeploymentsClient.BeginCreateOrUpdateAtTenantScope": + resp, err = d.dispatchBeginCreateOrUpdateAtTenantScope(req) + case "DeploymentsClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DeploymentsClient.BeginDeleteAtManagementGroupScope": + resp, err = d.dispatchBeginDeleteAtManagementGroupScope(req) + case "DeploymentsClient.BeginDeleteAtScope": + resp, err = d.dispatchBeginDeleteAtScope(req) + case "DeploymentsClient.BeginDeleteAtSubscriptionScope": + resp, err = d.dispatchBeginDeleteAtSubscriptionScope(req) + case "DeploymentsClient.BeginDeleteAtTenantScope": + resp, err = d.dispatchBeginDeleteAtTenantScope(req) + case "DeploymentsClient.ExportTemplate": + resp, err = d.dispatchExportTemplate(req) + case "DeploymentsClient.ExportTemplateAtManagementGroupScope": + resp, err = d.dispatchExportTemplateAtManagementGroupScope(req) + case "DeploymentsClient.ExportTemplateAtScope": + resp, err = d.dispatchExportTemplateAtScope(req) + case "DeploymentsClient.ExportTemplateAtSubscriptionScope": + resp, err = d.dispatchExportTemplateAtSubscriptionScope(req) + case "DeploymentsClient.ExportTemplateAtTenantScope": + resp, err = d.dispatchExportTemplateAtTenantScope(req) + case "DeploymentsClient.Get": + resp, err = d.dispatchGet(req) + case "DeploymentsClient.GetAtManagementGroupScope": + resp, err = d.dispatchGetAtManagementGroupScope(req) + case "DeploymentsClient.GetAtScope": + resp, err = d.dispatchGetAtScope(req) + case "DeploymentsClient.GetAtSubscriptionScope": + resp, err = d.dispatchGetAtSubscriptionScope(req) + case "DeploymentsClient.GetAtTenantScope": + resp, err = d.dispatchGetAtTenantScope(req) + case "DeploymentsClient.NewListAtManagementGroupScopePager": + resp, err = d.dispatchNewListAtManagementGroupScopePager(req) + case "DeploymentsClient.NewListAtScopePager": + resp, err = d.dispatchNewListAtScopePager(req) + case "DeploymentsClient.NewListAtSubscriptionScopePager": + resp, err = d.dispatchNewListAtSubscriptionScopePager(req) + case "DeploymentsClient.NewListAtTenantScopePager": + resp, err = d.dispatchNewListAtTenantScopePager(req) + case "DeploymentsClient.NewListByResourceGroupPager": + resp, err = d.dispatchNewListByResourceGroupPager(req) + case "DeploymentsClient.BeginValidate": + resp, err = d.dispatchBeginValidate(req) + case "DeploymentsClient.BeginValidateAtManagementGroupScope": + resp, err = d.dispatchBeginValidateAtManagementGroupScope(req) + case "DeploymentsClient.BeginValidateAtScope": + resp, err = d.dispatchBeginValidateAtScope(req) + case "DeploymentsClient.BeginValidateAtSubscriptionScope": + resp, err = d.dispatchBeginValidateAtSubscriptionScope(req) + case "DeploymentsClient.BeginValidateAtTenantScope": + resp, err = d.dispatchBeginValidateAtTenantScope(req) + case "DeploymentsClient.BeginWhatIf": + resp, err = d.dispatchBeginWhatIf(req) + case "DeploymentsClient.BeginWhatIfAtManagementGroupScope": + resp, err = d.dispatchBeginWhatIfAtManagementGroupScope(req) + case "DeploymentsClient.BeginWhatIfAtSubscriptionScope": + resp, err = d.dispatchBeginWhatIfAtSubscriptionScope(req) + case "DeploymentsClient.BeginWhatIfAtTenantScope": + resp, err = d.dispatchBeginWhatIfAtTenantScope(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCalculateTemplateHash(req *http.Request) (*http.Response, error) { + if d.srv.CalculateTemplateHash == nil { + return nil, &nonRetriableError{errors.New("method CalculateTemplateHash not implemented")} + } + body, err := server.UnmarshalRequestAsJSON[any](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CalculateTemplateHash(req.Context(), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TemplateHashResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCancel(req *http.Request) (*http.Response, error) { + if d.srv.Cancel == nil { + return nil, &nonRetriableError{errors.New("method Cancel not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.Cancel(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCancelAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.CancelAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method CancelAtManagementGroupScope not implemented")} + } + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CancelAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCancelAtScope(req *http.Request) (*http.Response, error) { + if d.srv.CancelAtScope == nil { + return nil, &nonRetriableError{errors.New("method CancelAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CancelAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCancelAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.CancelAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method CancelAtSubscriptionScope not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CancelAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCancelAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.CancelAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method CancelAtTenantScope not implemented")} + } + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CancelAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCheckExistence(req *http.Request) (*http.Response, error) { + if d.srv.CheckExistence == nil { + return nil, &nonRetriableError{errors.New("method CheckExistence not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CheckExistence(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCheckExistenceAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.CheckExistenceAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method CheckExistenceAtManagementGroupScope not implemented")} + } + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CheckExistenceAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCheckExistenceAtScope(req *http.Request) (*http.Response, error) { + if d.srv.CheckExistenceAtScope == nil { + return nil, &nonRetriableError{errors.New("method CheckExistenceAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CheckExistenceAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCheckExistenceAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.CheckExistenceAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method CheckExistenceAtSubscriptionScope not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CheckExistenceAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchCheckExistenceAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.CheckExistenceAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method CheckExistenceAtTenantScope not implemented")} + } + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.CheckExistenceAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if d.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.Deployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(d.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginCreateOrUpdate) { + d.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdateAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtManagementGroupScope not implemented")} + } + if d.beginCreateOrUpdateAtManagementGroupScope == nil { + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ScopedDeployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginCreateOrUpdateAtManagementGroupScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginCreateOrUpdateAtManagementGroupScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginCreateOrUpdateAtManagementGroupScope) { + d.beginCreateOrUpdateAtManagementGroupScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdateAtScope == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtScope not implemented")} + } + if d.beginCreateOrUpdateAtScope == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.Deployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginCreateOrUpdateAtScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginCreateOrUpdateAtScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginCreateOrUpdateAtScope) { + d.beginCreateOrUpdateAtScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdateAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtSubscriptionScope not implemented")} + } + if d.beginCreateOrUpdateAtSubscriptionScope == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.Deployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginCreateOrUpdateAtSubscriptionScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginCreateOrUpdateAtSubscriptionScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginCreateOrUpdateAtSubscriptionScope) { + d.beginCreateOrUpdateAtSubscriptionScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdateAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtTenantScope not implemented")} + } + if d.beginCreateOrUpdateAtTenantScope == nil { + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ScopedDeployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginCreateOrUpdateAtTenantScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginCreateOrUpdateAtTenantScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginCreateOrUpdateAtTenantScope) { + d.beginCreateOrUpdateAtTenantScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if d.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if d.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(d.beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginDelete) { + d.beginDelete = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginDeleteAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginDeleteAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteAtManagementGroupScope not implemented")} + } + if d.beginDeleteAtManagementGroupScope == nil { + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.BeginDeleteAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginDeleteAtManagementGroupScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginDeleteAtManagementGroupScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginDeleteAtManagementGroupScope) { + d.beginDeleteAtManagementGroupScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginDeleteAtScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginDeleteAtScope == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteAtScope not implemented")} + } + if d.beginDeleteAtScope == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.BeginDeleteAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginDeleteAtScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginDeleteAtScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginDeleteAtScope) { + d.beginDeleteAtScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginDeleteAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginDeleteAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteAtSubscriptionScope not implemented")} + } + if d.beginDeleteAtSubscriptionScope == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.BeginDeleteAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginDeleteAtSubscriptionScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginDeleteAtSubscriptionScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginDeleteAtSubscriptionScope) { + d.beginDeleteAtSubscriptionScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginDeleteAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginDeleteAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteAtTenantScope not implemented")} + } + if d.beginDeleteAtTenantScope == nil { + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.BeginDeleteAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginDeleteAtTenantScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginDeleteAtTenantScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginDeleteAtTenantScope) { + d.beginDeleteAtTenantScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchExportTemplate(req *http.Request) (*http.Response, error) { + if d.srv.ExportTemplate == nil { + return nil, &nonRetriableError{errors.New("method ExportTemplate not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.ExportTemplate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExportResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchExportTemplateAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.ExportTemplateAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method ExportTemplateAtManagementGroupScope not implemented")} + } + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.ExportTemplateAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExportResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchExportTemplateAtScope(req *http.Request) (*http.Response, error) { + if d.srv.ExportTemplateAtScope == nil { + return nil, &nonRetriableError{errors.New("method ExportTemplateAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.ExportTemplateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExportResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchExportTemplateAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.ExportTemplateAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method ExportTemplateAtSubscriptionScope not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.ExportTemplateAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExportResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchExportTemplateAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.ExportTemplateAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method ExportTemplateAtTenantScope not implemented")} + } + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.ExportTemplateAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExportResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExtended, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchGetAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtManagementGroupScope not implemented")} + } + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExtended, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExtended, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchGetAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtSubscriptionScope not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExtended, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.GetAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtTenantScope not implemented")} + } + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.GetAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DeploymentExtended, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchNewListAtManagementGroupScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtManagementGroupScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtManagementGroupScopePager not implemented")} + } + if d.newListAtManagementGroupScopePager == nil { + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentsClientListAtManagementGroupScopeOptions + if filterParam != nil || topParam != nil { + options = &armresources.DeploymentsClientListAtManagementGroupScopeOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListAtManagementGroupScopePager(matches[regex.SubexpIndex("groupId")], options) + d.newListAtManagementGroupScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtManagementGroupScopePager, req, func(page *armresources.DeploymentsClientListAtManagementGroupScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtManagementGroupScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtManagementGroupScopePager) { + d.newListAtManagementGroupScopePager = nil + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchNewListAtScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtScopePager not implemented")} + } + if d.newListAtScopePager == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentsClientListAtScopeOptions + if filterParam != nil || topParam != nil { + options = &armresources.DeploymentsClientListAtScopeOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListAtScopePager(matches[regex.SubexpIndex("scope")], options) + d.newListAtScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtScopePager, req, func(page *armresources.DeploymentsClientListAtScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtScopePager) { + d.newListAtScopePager = nil + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchNewListAtSubscriptionScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtSubscriptionScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtSubscriptionScopePager not implemented")} + } + if d.newListAtSubscriptionScopePager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentsClientListAtSubscriptionScopeOptions + if filterParam != nil || topParam != nil { + options = &armresources.DeploymentsClientListAtSubscriptionScopeOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListAtSubscriptionScopePager(options) + d.newListAtSubscriptionScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtSubscriptionScopePager, req, func(page *armresources.DeploymentsClientListAtSubscriptionScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtSubscriptionScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtSubscriptionScopePager) { + d.newListAtSubscriptionScopePager = nil + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAtTenantScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtTenantScopePager not implemented")} + } + if d.newListAtTenantScopePager == nil { + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentsClientListAtTenantScopeOptions + if filterParam != nil || topParam != nil { + options = &armresources.DeploymentsClientListAtTenantScopeOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListAtTenantScopePager(options) + d.newListAtTenantScopePager = &resp + server.PagerResponderInjectNextLinks(d.newListAtTenantScopePager, req, func(page *armresources.DeploymentsClientListAtTenantScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAtTenantScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListAtTenantScopePager) { + d.newListAtTenantScopePager = nil + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + } + if d.newListByResourceGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.DeploymentsClientListByResourceGroupOptions + if filterParam != nil || topParam != nil { + options = &armresources.DeploymentsClientListByResourceGroupOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], options) + d.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armresources.DeploymentsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListByResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(d.newListByResourceGroupPager) { + d.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginValidate(req *http.Request) (*http.Response, error) { + if d.srv.BeginValidate == nil { + return nil, &nonRetriableError{errors.New("method BeginValidate not implemented")} + } + if d.beginValidate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.Deployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginValidate = &respr + } + + resp, err := server.PollerResponderNext(d.beginValidate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusBadRequest}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusBadRequest", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginValidate) { + d.beginValidate = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginValidateAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginValidateAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method BeginValidateAtManagementGroupScope not implemented")} + } + if d.beginValidateAtManagementGroupScope == nil { + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ScopedDeployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginValidateAtManagementGroupScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginValidateAtManagementGroupScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusBadRequest}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusBadRequest", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginValidateAtManagementGroupScope) { + d.beginValidateAtManagementGroupScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginValidateAtScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginValidateAtScope == nil { + return nil, &nonRetriableError{errors.New("method BeginValidateAtScope not implemented")} + } + if d.beginValidateAtScope == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.Deployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginValidateAtScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginValidateAtScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusBadRequest}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusBadRequest", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginValidateAtScope) { + d.beginValidateAtScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginValidateAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginValidateAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method BeginValidateAtSubscriptionScope not implemented")} + } + if d.beginValidateAtSubscriptionScope == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.Deployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginValidateAtSubscriptionScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginValidateAtSubscriptionScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusBadRequest}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusBadRequest", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginValidateAtSubscriptionScope) { + d.beginValidateAtSubscriptionScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginValidateAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginValidateAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method BeginValidateAtTenantScope not implemented")} + } + if d.beginValidateAtTenantScope == nil { + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ScopedDeployment](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginValidateAtTenantScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginValidateAtTenantScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusBadRequest}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusBadRequest", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginValidateAtTenantScope) { + d.beginValidateAtTenantScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginWhatIf(req *http.Request) (*http.Response, error) { + if d.srv.BeginWhatIf == nil { + return nil, &nonRetriableError{errors.New("method BeginWhatIf not implemented")} + } + if d.beginWhatIf == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.DeploymentWhatIf](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIf(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginWhatIf = &respr + } + + resp, err := server.PollerResponderNext(d.beginWhatIf, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginWhatIf) { + d.beginWhatIf = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginWhatIfAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method BeginWhatIfAtManagementGroupScope not implemented")} + } + if d.beginWhatIfAtManagementGroupScope == nil { + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ScopedDeploymentWhatIf](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIfAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginWhatIfAtManagementGroupScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginWhatIfAtManagementGroupScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginWhatIfAtManagementGroupScope) { + d.beginWhatIfAtManagementGroupScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtSubscriptionScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginWhatIfAtSubscriptionScope == nil { + return nil, &nonRetriableError{errors.New("method BeginWhatIfAtSubscriptionScope not implemented")} + } + if d.beginWhatIfAtSubscriptionScope == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.DeploymentWhatIf](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIfAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginWhatIfAtSubscriptionScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginWhatIfAtSubscriptionScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginWhatIfAtSubscriptionScope) { + d.beginWhatIfAtSubscriptionScope = nil + } + + return resp, nil +} + +func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtTenantScope(req *http.Request) (*http.Response, error) { + if d.srv.BeginWhatIfAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method BeginWhatIfAtTenantScope not implemented")} + } + if d.beginWhatIfAtTenantScope == nil { + const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ScopedDeploymentWhatIf](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIfAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginWhatIfAtTenantScope = &respr + } + + resp, err := server.PollerResponderNext(d.beginWhatIfAtTenantScope, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(d.beginWhatIfAtTenantScope) { + d.beginWhatIfAtTenantScope = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/internal.go b/sdk/resourcemanager/resources/armresources/fake/internal.go new file mode 100644 index 000000000000..e9c8222f2199 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/internal.go @@ -0,0 +1,78 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "io" + "net/http" + "reflect" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +func getHeaderValue(h http.Header, k string) string { + v := h[k] + if len(v) == 0 { + return "" + } + return v[0] +} + +func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { + if v == "" { + return nil, nil + } + t, err := parse(v) + if err != nil { + return nil, err + } + return &t, err +} + +func parseWithCast[T any](v string, parse func(v string) (T, error)) (T, error) { + t, err := parse(v) + if err != nil { + return *new(T), err + } + return t, err +} + +func readRequestBody(req *http.Request) ([]byte, error) { + if req.Body == nil { + return nil, nil + } + body, err := io.ReadAll(req.Body) + if err != nil { + return nil, err + } + req.Body.Close() + return body, nil +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} diff --git a/sdk/resourcemanager/resources/armresources/fake/operations_server.go b/sdk/resourcemanager/resources/armresources/fake/operations_server.go new file mode 100644 index 000000000000..cef92be734be --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/operations_server.go @@ -0,0 +1,90 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" +) + +// OperationsServer is a fake server for instances of the armresources.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armresources.OperationsClientListOptions) (resp azfake.PagerResponder[armresources.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armresources.OperationsClient by way of the +// undefined.Transporter field. +func NewOperationsServerTransport(srv *OperationsServer) *OperationsServerTransport { + return &OperationsServerTransport{srv: srv} +} + +// OperationsServerTransport connects instances of armresources.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *azfake.PagerResponder[armresources.OperationsClientListResponse] +} + +// Do implements the policy.Transporter interface for OperationsServerTransport. +func (o *OperationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "OperationsClient.NewListPager": + resp, err = o.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (o *OperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if o.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if o.newListPager == nil { + resp := o.srv.NewListPager(nil) + o.newListPager = &resp + server.PagerResponderInjectNextLinks(o.newListPager, req, func(page *armresources.OperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(o.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(o.newListPager) { + o.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go b/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go new file mode 100644 index 000000000000..18e1a1b56d60 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go @@ -0,0 +1,99 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "regexp" +) + +// ProviderResourceTypesServer is a fake server for instances of the armresources.ProviderResourceTypesClient type. +type ProviderResourceTypesServer struct { + // List is the fake for method ProviderResourceTypesClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceProviderNamespace string, options *armresources.ProviderResourceTypesClientListOptions) (resp azfake.Responder[armresources.ProviderResourceTypesClientListResponse], errResp azfake.ErrorResponder) +} + +// NewProviderResourceTypesServerTransport creates a new instance of ProviderResourceTypesServerTransport with the provided implementation. +// The returned ProviderResourceTypesServerTransport instance is connected to an instance of armresources.ProviderResourceTypesClient by way of the +// undefined.Transporter field. +func NewProviderResourceTypesServerTransport(srv *ProviderResourceTypesServer) *ProviderResourceTypesServerTransport { + return &ProviderResourceTypesServerTransport{srv: srv} +} + +// ProviderResourceTypesServerTransport connects instances of armresources.ProviderResourceTypesClient to instances of ProviderResourceTypesServer. +// Don't use this type directly, use NewProviderResourceTypesServerTransport instead. +type ProviderResourceTypesServerTransport struct { + srv *ProviderResourceTypesServer +} + +// Do implements the policy.Transporter interface for ProviderResourceTypesServerTransport. +func (p *ProviderResourceTypesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ProviderResourceTypesClient.List": + resp, err = p.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *ProviderResourceTypesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if p.srv.List == nil { + return nil, &nonRetriableError{errors.New("method List not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/resourceTypes" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armresources.ProviderResourceTypesClientListOptions + if expandParam != nil { + options = &armresources.ProviderResourceTypesClientListOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.List(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ProviderResourceTypeListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/providers_server.go b/sdk/resourcemanager/resources/armresources/fake/providers_server.go new file mode 100644 index 000000000000..46b821433f55 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/providers_server.go @@ -0,0 +1,358 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "reflect" + "regexp" +) + +// ProvidersServer is a fake server for instances of the armresources.ProvidersClient type. +type ProvidersServer struct { + // Get is the fake for method ProvidersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceProviderNamespace string, options *armresources.ProvidersClientGetOptions) (resp azfake.Responder[armresources.ProvidersClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtTenantScope is the fake for method ProvidersClient.GetAtTenantScope + // HTTP status codes to indicate success: http.StatusOK + GetAtTenantScope func(ctx context.Context, resourceProviderNamespace string, options *armresources.ProvidersClientGetAtTenantScopeOptions) (resp azfake.Responder[armresources.ProvidersClientGetAtTenantScopeResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ProvidersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armresources.ProvidersClientListOptions) (resp azfake.PagerResponder[armresources.ProvidersClientListResponse]) + + // NewListAtTenantScopePager is the fake for method ProvidersClient.NewListAtTenantScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtTenantScopePager func(options *armresources.ProvidersClientListAtTenantScopeOptions) (resp azfake.PagerResponder[armresources.ProvidersClientListAtTenantScopeResponse]) + + // ProviderPermissions is the fake for method ProvidersClient.ProviderPermissions + // HTTP status codes to indicate success: http.StatusOK + ProviderPermissions func(ctx context.Context, resourceProviderNamespace string, options *armresources.ProvidersClientProviderPermissionsOptions) (resp azfake.Responder[armresources.ProvidersClientProviderPermissionsResponse], errResp azfake.ErrorResponder) + + // Register is the fake for method ProvidersClient.Register + // HTTP status codes to indicate success: http.StatusOK + Register func(ctx context.Context, resourceProviderNamespace string, options *armresources.ProvidersClientRegisterOptions) (resp azfake.Responder[armresources.ProvidersClientRegisterResponse], errResp azfake.ErrorResponder) + + // RegisterAtManagementGroupScope is the fake for method ProvidersClient.RegisterAtManagementGroupScope + // HTTP status codes to indicate success: http.StatusOK + RegisterAtManagementGroupScope func(ctx context.Context, resourceProviderNamespace string, groupID string, options *armresources.ProvidersClientRegisterAtManagementGroupScopeOptions) (resp azfake.Responder[armresources.ProvidersClientRegisterAtManagementGroupScopeResponse], errResp azfake.ErrorResponder) + + // Unregister is the fake for method ProvidersClient.Unregister + // HTTP status codes to indicate success: http.StatusOK + Unregister func(ctx context.Context, resourceProviderNamespace string, options *armresources.ProvidersClientUnregisterOptions) (resp azfake.Responder[armresources.ProvidersClientUnregisterResponse], errResp azfake.ErrorResponder) +} + +// NewProvidersServerTransport creates a new instance of ProvidersServerTransport with the provided implementation. +// The returned ProvidersServerTransport instance is connected to an instance of armresources.ProvidersClient by way of the +// undefined.Transporter field. +func NewProvidersServerTransport(srv *ProvidersServer) *ProvidersServerTransport { + return &ProvidersServerTransport{srv: srv} +} + +// ProvidersServerTransport connects instances of armresources.ProvidersClient to instances of ProvidersServer. +// Don't use this type directly, use NewProvidersServerTransport instead. +type ProvidersServerTransport struct { + srv *ProvidersServer + newListPager *azfake.PagerResponder[armresources.ProvidersClientListResponse] + newListAtTenantScopePager *azfake.PagerResponder[armresources.ProvidersClientListAtTenantScopeResponse] +} + +// Do implements the policy.Transporter interface for ProvidersServerTransport. +func (p *ProvidersServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ProvidersClient.Get": + resp, err = p.dispatchGet(req) + case "ProvidersClient.GetAtTenantScope": + resp, err = p.dispatchGetAtTenantScope(req) + case "ProvidersClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "ProvidersClient.NewListAtTenantScopePager": + resp, err = p.dispatchNewListAtTenantScopePager(req) + case "ProvidersClient.ProviderPermissions": + resp, err = p.dispatchProviderPermissions(req) + case "ProvidersClient.Register": + resp, err = p.dispatchRegister(req) + case "ProvidersClient.RegisterAtManagementGroupScope": + resp, err = p.dispatchRegisterAtManagementGroupScope(req) + case "ProvidersClient.Unregister": + resp, err = p.dispatchUnregister(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armresources.ProvidersClientGetOptions + if expandParam != nil { + options = &armresources.ProvidersClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Provider, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) { + if p.srv.GetAtTenantScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtTenantScope not implemented")} + } + const regexStr = "/providers/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armresources.ProvidersClientGetAtTenantScopeOptions + if expandParam != nil { + options = &armresources.ProvidersClientGetAtTenantScopeOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.GetAtTenantScope(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Provider, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armresources.ProvidersClientListOptions + if expandParam != nil { + options = &armresources.ProvidersClientListOptions{ + Expand: expandParam, + } + } + resp := p.srv.NewListPager(options) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armresources.ProvidersClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) { + if p.srv.NewListAtTenantScopePager == nil { + return nil, &nonRetriableError{errors.New("method NewListAtTenantScopePager not implemented")} + } + if p.newListAtTenantScopePager == nil { + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armresources.ProvidersClientListAtTenantScopeOptions + if expandParam != nil { + options = &armresources.ProvidersClientListAtTenantScopeOptions{ + Expand: expandParam, + } + } + resp := p.srv.NewListAtTenantScopePager(options) + p.newListAtTenantScopePager = &resp + server.PagerResponderInjectNextLinks(p.newListAtTenantScopePager, req, func(page *armresources.ProvidersClientListAtTenantScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListAtTenantScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListAtTenantScopePager) { + p.newListAtTenantScopePager = nil + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchProviderPermissions(req *http.Request) (*http.Response, error) { + if p.srv.ProviderPermissions == nil { + return nil, &nonRetriableError{errors.New("method ProviderPermissions not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/providerPermissions" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := p.srv.ProviderPermissions(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ProviderPermissionListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchRegister(req *http.Request) (*http.Response, error) { + if p.srv.Register == nil { + return nil, &nonRetriableError{errors.New("method Register not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/register" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ProviderRegistrationRequest](req) + if err != nil { + return nil, err + } + var options *armresources.ProvidersClientRegisterOptions + if !reflect.ValueOf(body).IsZero() { + options = &armresources.ProvidersClientRegisterOptions{ + Properties: &body, + } + } + respr, errRespr := p.srv.Register(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Provider, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchRegisterAtManagementGroupScope(req *http.Request) (*http.Response, error) { + if p.srv.RegisterAtManagementGroupScope == nil { + return nil, &nonRetriableError{errors.New("method RegisterAtManagementGroupScope not implemented")} + } + const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/register" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := p.srv.RegisterAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("groupId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProvidersServerTransport) dispatchUnregister(req *http.Request) (*http.Response, error) { + if p.srv.Unregister == nil { + return nil, &nonRetriableError{errors.New("method Unregister not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/unregister" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := p.srv.Unregister(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Provider, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go b/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go new file mode 100644 index 000000000000..efe6293085c1 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go @@ -0,0 +1,342 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "regexp" + "strconv" +) + +// ResourceGroupsServer is a fake server for instances of the armresources.ResourceGroupsClient type. +type ResourceGroupsServer struct { + // CheckExistence is the fake for method ResourceGroupsClient.CheckExistence + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistence func(ctx context.Context, resourceGroupName string, options *armresources.ResourceGroupsClientCheckExistenceOptions) (resp azfake.Responder[armresources.ResourceGroupsClientCheckExistenceResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdate is the fake for method ResourceGroupsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, parameters armresources.ResourceGroup, options *armresources.ResourceGroupsClientCreateOrUpdateOptions) (resp azfake.Responder[armresources.ResourceGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ResourceGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDelete func(ctx context.Context, resourceGroupName string, options *armresources.ResourceGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armresources.ResourceGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginExportTemplate is the fake for method ResourceGroupsClient.BeginExportTemplate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginExportTemplate func(ctx context.Context, resourceGroupName string, parameters armresources.ExportTemplateRequest, options *armresources.ResourceGroupsClientBeginExportTemplateOptions) (resp azfake.PollerResponder[armresources.ResourceGroupsClientExportTemplateResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ResourceGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, options *armresources.ResourceGroupsClientGetOptions) (resp azfake.Responder[armresources.ResourceGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ResourceGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armresources.ResourceGroupsClientListOptions) (resp azfake.PagerResponder[armresources.ResourceGroupsClientListResponse]) + + // Update is the fake for method ResourceGroupsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, parameters armresources.ResourceGroupPatchable, options *armresources.ResourceGroupsClientUpdateOptions) (resp azfake.Responder[armresources.ResourceGroupsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewResourceGroupsServerTransport creates a new instance of ResourceGroupsServerTransport with the provided implementation. +// The returned ResourceGroupsServerTransport instance is connected to an instance of armresources.ResourceGroupsClient by way of the +// undefined.Transporter field. +func NewResourceGroupsServerTransport(srv *ResourceGroupsServer) *ResourceGroupsServerTransport { + return &ResourceGroupsServerTransport{srv: srv} +} + +// ResourceGroupsServerTransport connects instances of armresources.ResourceGroupsClient to instances of ResourceGroupsServer. +// Don't use this type directly, use NewResourceGroupsServerTransport instead. +type ResourceGroupsServerTransport struct { + srv *ResourceGroupsServer + beginDelete *azfake.PollerResponder[armresources.ResourceGroupsClientDeleteResponse] + beginExportTemplate *azfake.PollerResponder[armresources.ResourceGroupsClientExportTemplateResponse] + newListPager *azfake.PagerResponder[armresources.ResourceGroupsClientListResponse] +} + +// Do implements the policy.Transporter interface for ResourceGroupsServerTransport. +func (r *ResourceGroupsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ResourceGroupsClient.CheckExistence": + resp, err = r.dispatchCheckExistence(req) + case "ResourceGroupsClient.CreateOrUpdate": + resp, err = r.dispatchCreateOrUpdate(req) + case "ResourceGroupsClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "ResourceGroupsClient.BeginExportTemplate": + resp, err = r.dispatchBeginExportTemplate(req) + case "ResourceGroupsClient.Get": + resp, err = r.dispatchGet(req) + case "ResourceGroupsClient.NewListPager": + resp, err = r.dispatchNewListPager(req) + case "ResourceGroupsClient.Update": + resp, err = r.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchCheckExistence(req *http.Request) (*http.Response, error) { + if r.srv.CheckExistence == nil { + return nil, &nonRetriableError{errors.New("method CheckExistence not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := r.srv.CheckExistence(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method CreateOrUpdate not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ResourceGroup](req) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if r.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + forceDeletionTypesParam := getOptional(qp.Get("forceDeletionTypes")) + var options *armresources.ResourceGroupsClientBeginDeleteOptions + if forceDeletionTypesParam != nil { + options = &armresources.ResourceGroupsClientBeginDeleteOptions{ + ForceDeletionTypes: forceDeletionTypesParam, + } + } + respr, errRespr := r.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(r.beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(r.beginDelete) { + r.beginDelete = nil + } + + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchBeginExportTemplate(req *http.Request) (*http.Response, error) { + if r.srv.BeginExportTemplate == nil { + return nil, &nonRetriableError{errors.New("method BeginExportTemplate not implemented")} + } + if r.beginExportTemplate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/exportTemplate" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ExportTemplateRequest](req) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginExportTemplate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginExportTemplate = &respr + } + + resp, err := server.PollerResponderNext(r.beginExportTemplate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(r.beginExportTemplate) { + r.beginExportTemplate = nil + } + + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := r.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if r.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.ResourceGroupsClientListOptions + if filterParam != nil || topParam != nil { + options = &armresources.ResourceGroupsClientListOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := r.srv.NewListPager(options) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armresources.ResourceGroupsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(r.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(r.newListPager) { + r.newListPager = nil + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if r.srv.Update == nil { + return nil, &nonRetriableError{errors.New("method Update not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.ResourceGroupPatchable](req) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/server.go b/sdk/resourcemanager/resources/armresources/fake/server.go new file mode 100644 index 000000000000..6def4ade1ab5 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/server.go @@ -0,0 +1,656 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "regexp" + "strconv" +) + +// Server is a fake server for instances of the armresources.Client type. +type Server struct { + // CheckExistence is the fake for method Client.CheckExistence + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistence func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *armresources.ClientCheckExistenceOptions) (resp azfake.Responder[armresources.ClientCheckExistenceResponse], errResp azfake.ErrorResponder) + + // CheckExistenceByID is the fake for method Client.CheckExistenceByID + // HTTP status codes to indicate success: http.StatusNoContent, http.StatusNotFound + CheckExistenceByID func(ctx context.Context, resourceID string, apiVersion string, options *armresources.ClientCheckExistenceByIDOptions) (resp azfake.Responder[armresources.ClientCheckExistenceByIDResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method Client.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, parameters armresources.GenericResource, options *armresources.ClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armresources.ClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateByID is the fake for method Client.BeginCreateOrUpdateByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdateByID func(ctx context.Context, resourceID string, apiVersion string, parameters armresources.GenericResource, options *armresources.ClientBeginCreateOrUpdateByIDOptions) (resp azfake.PollerResponder[armresources.ClientCreateOrUpdateByIDResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method Client.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *armresources.ClientBeginDeleteOptions) (resp azfake.PollerResponder[armresources.ClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteByID is the fake for method Client.BeginDeleteByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeleteByID func(ctx context.Context, resourceID string, apiVersion string, options *armresources.ClientBeginDeleteByIDOptions) (resp azfake.PollerResponder[armresources.ClientDeleteByIDResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method Client.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *armresources.ClientGetOptions) (resp azfake.Responder[armresources.ClientGetResponse], errResp azfake.ErrorResponder) + + // GetByID is the fake for method Client.GetByID + // HTTP status codes to indicate success: http.StatusOK + GetByID func(ctx context.Context, resourceID string, apiVersion string, options *armresources.ClientGetByIDOptions) (resp azfake.Responder[armresources.ClientGetByIDResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method Client.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armresources.ClientListOptions) (resp azfake.PagerResponder[armresources.ClientListResponse]) + + // NewListByResourceGroupPager is the fake for method Client.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armresources.ClientListByResourceGroupOptions) (resp azfake.PagerResponder[armresources.ClientListByResourceGroupResponse]) + + // BeginMoveResources is the fake for method Client.BeginMoveResources + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginMoveResources func(ctx context.Context, sourceResourceGroupName string, parameters armresources.MoveInfo, options *armresources.ClientBeginMoveResourcesOptions) (resp azfake.PollerResponder[armresources.ClientMoveResourcesResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method Client.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, parameters armresources.GenericResource, options *armresources.ClientBeginUpdateOptions) (resp azfake.PollerResponder[armresources.ClientUpdateResponse], errResp azfake.ErrorResponder) + + // BeginUpdateByID is the fake for method Client.BeginUpdateByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateByID func(ctx context.Context, resourceID string, apiVersion string, parameters armresources.GenericResource, options *armresources.ClientBeginUpdateByIDOptions) (resp azfake.PollerResponder[armresources.ClientUpdateByIDResponse], errResp azfake.ErrorResponder) + + // BeginValidateMoveResources is the fake for method Client.BeginValidateMoveResources + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginValidateMoveResources func(ctx context.Context, sourceResourceGroupName string, parameters armresources.MoveInfo, options *armresources.ClientBeginValidateMoveResourcesOptions) (resp azfake.PollerResponder[armresources.ClientValidateMoveResourcesResponse], errResp azfake.ErrorResponder) +} + +// NewServerTransport creates a new instance of ServerTransport with the provided implementation. +// The returned ServerTransport instance is connected to an instance of armresources.Client by way of the +// undefined.Transporter field. +func NewServerTransport(srv *Server) *ServerTransport { + return &ServerTransport{srv: srv} +} + +// ServerTransport connects instances of armresources.Client to instances of Server. +// Don't use this type directly, use NewServerTransport instead. +type ServerTransport struct { + srv *Server + beginCreateOrUpdate *azfake.PollerResponder[armresources.ClientCreateOrUpdateResponse] + beginCreateOrUpdateByID *azfake.PollerResponder[armresources.ClientCreateOrUpdateByIDResponse] + beginDelete *azfake.PollerResponder[armresources.ClientDeleteResponse] + beginDeleteByID *azfake.PollerResponder[armresources.ClientDeleteByIDResponse] + newListPager *azfake.PagerResponder[armresources.ClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armresources.ClientListByResourceGroupResponse] + beginMoveResources *azfake.PollerResponder[armresources.ClientMoveResourcesResponse] + beginUpdate *azfake.PollerResponder[armresources.ClientUpdateResponse] + beginUpdateByID *azfake.PollerResponder[armresources.ClientUpdateByIDResponse] + beginValidateMoveResources *azfake.PollerResponder[armresources.ClientValidateMoveResourcesResponse] +} + +// Do implements the policy.Transporter interface for ServerTransport. +func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "Client.CheckExistence": + resp, err = s.dispatchCheckExistence(req) + case "Client.CheckExistenceByID": + resp, err = s.dispatchCheckExistenceByID(req) + case "Client.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "Client.BeginCreateOrUpdateByID": + resp, err = s.dispatchBeginCreateOrUpdateByID(req) + case "Client.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "Client.BeginDeleteByID": + resp, err = s.dispatchBeginDeleteByID(req) + case "Client.Get": + resp, err = s.dispatchGet(req) + case "Client.GetByID": + resp, err = s.dispatchGetByID(req) + case "Client.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "Client.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "Client.BeginMoveResources": + resp, err = s.dispatchBeginMoveResources(req) + case "Client.BeginUpdate": + resp, err = s.dispatchBeginUpdate(req) + case "Client.BeginUpdateByID": + resp, err = s.dispatchBeginUpdateByID(req) + case "Client.BeginValidateMoveResources": + resp, err = s.dispatchBeginValidateMoveResources(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServerTransport) dispatchCheckExistence(req *http.Request) (*http.Response, error) { + if s.srv.CheckExistence == nil { + return nil, &nonRetriableError{errors.New("method CheckExistence not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + respr, errRespr := s.srv.CheckExistence(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchCheckExistenceByID(req *http.Request) (*http.Response, error) { + if s.srv.CheckExistenceByID == nil { + return nil, &nonRetriableError{errors.New("method CheckExistenceByID not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + respr, errRespr := s.srv.CheckExistenceByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if s.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + body, err := server.UnmarshalRequestAsJSON[armresources.GenericResource](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdateByID == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateByID not implemented")} + } + if s.beginCreateOrUpdateByID == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + body, err := server.UnmarshalRequestAsJSON[armresources.GenericResource](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdateByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdateByID = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdateByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdateByID) { + s.beginCreateOrUpdateByID = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if s.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + respr, errRespr := s.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(s.beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginDelete) { + s.beginDelete = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginDeleteByID(req *http.Request) (*http.Response, error) { + if s.srv.BeginDeleteByID == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteByID not implemented")} + } + if s.beginDeleteByID == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + respr, errRespr := s.srv.BeginDeleteByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginDeleteByID = &respr + } + + resp, err := server.PollerResponderNext(s.beginDeleteByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginDeleteByID) { + s.beginDeleteByID = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + respr, errRespr := s.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).GenericResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetByID(req *http.Request) (*http.Response, error) { + if s.srv.GetByID == nil { + return nil, &nonRetriableError{errors.New("method GetByID not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + respr, errRespr := s.srv.GetByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).GenericResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resources" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + expandParam := getOptional(qp.Get("$expand")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.ClientListOptions + if filterParam != nil || expandParam != nil || topParam != nil { + options = &armresources.ClientListOptions{ + Filter: filterParam, + Expand: expandParam, + Top: topParam, + } + } + resp := s.srv.NewListPager(options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armresources.ClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(s.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(s.newListPager) { + s.newListPager = nil + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + } + if s.newListByResourceGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/resources" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + filterParam := getOptional(qp.Get("$filter")) + expandParam := getOptional(qp.Get("$expand")) + topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armresources.ClientListByResourceGroupOptions + if filterParam != nil || expandParam != nil || topParam != nil { + options = &armresources.ClientListByResourceGroupOptions{ + Filter: filterParam, + Expand: expandParam, + Top: topParam, + } + } + resp := s.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], options) + s.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armresources.ClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(s.newListByResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(s.newListByResourceGroupPager) { + s.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (s *ServerTransport) dispatchBeginMoveResources(req *http.Request) (*http.Response, error) { + if s.srv.BeginMoveResources == nil { + return nil, &nonRetriableError{errors.New("method BeginMoveResources not implemented")} + } + if s.beginMoveResources == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/moveResources" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.MoveInfo](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginMoveResources(req.Context(), matches[regex.SubexpIndex("sourceResourceGroupName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginMoveResources = &respr + } + + resp, err := server.PollerResponderNext(s.beginMoveResources, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginMoveResources) { + s.beginMoveResources = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if s.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + body, err := server.UnmarshalRequestAsJSON[armresources.GenericResource](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginUpdate) { + s.beginUpdate = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginUpdateByID(req *http.Request) (*http.Response, error) { + if s.srv.BeginUpdateByID == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdateByID not implemented")} + } + if s.beginUpdateByID == nil { + const regexStr = "/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + body, err := server.UnmarshalRequestAsJSON[armresources.GenericResource](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdateByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginUpdateByID = &respr + } + + resp, err := server.PollerResponderNext(s.beginUpdateByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginUpdateByID) { + s.beginUpdateByID = nil + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginValidateMoveResources(req *http.Request) (*http.Response, error) { + if s.srv.BeginValidateMoveResources == nil { + return nil, &nonRetriableError{errors.New("method BeginValidateMoveResources not implemented")} + } + if s.beginValidateMoveResources == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/validateMoveResources" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.MoveInfo](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginValidateMoveResources(req.Context(), matches[regex.SubexpIndex("sourceResourceGroupName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginValidateMoveResources = &respr + } + + resp, err := server.PollerResponderNext(s.beginValidateMoveResources, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginValidateMoveResources) { + s.beginValidateMoveResources = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/tags_server.go b/sdk/resourcemanager/resources/armresources/fake/tags_server.go new file mode 100644 index 000000000000..9350f016692b --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/tags_server.go @@ -0,0 +1,354 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "net/http" + "regexp" +) + +// TagsServer is a fake server for instances of the armresources.TagsClient type. +type TagsServer struct { + // CreateOrUpdate is the fake for method TagsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, tagName string, options *armresources.TagsClientCreateOrUpdateOptions) (resp azfake.Responder[armresources.TagsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtScope is the fake for method TagsClient.CreateOrUpdateAtScope + // HTTP status codes to indicate success: http.StatusOK + CreateOrUpdateAtScope func(ctx context.Context, scope string, parameters armresources.TagsResource, options *armresources.TagsClientCreateOrUpdateAtScopeOptions) (resp azfake.Responder[armresources.TagsClientCreateOrUpdateAtScopeResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateValue is the fake for method TagsClient.CreateOrUpdateValue + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateValue func(ctx context.Context, tagName string, tagValue string, options *armresources.TagsClientCreateOrUpdateValueOptions) (resp azfake.Responder[armresources.TagsClientCreateOrUpdateValueResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method TagsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, tagName string, options *armresources.TagsClientDeleteOptions) (resp azfake.Responder[armresources.TagsClientDeleteResponse], errResp azfake.ErrorResponder) + + // DeleteAtScope is the fake for method TagsClient.DeleteAtScope + // HTTP status codes to indicate success: http.StatusOK + DeleteAtScope func(ctx context.Context, scope string, options *armresources.TagsClientDeleteAtScopeOptions) (resp azfake.Responder[armresources.TagsClientDeleteAtScopeResponse], errResp azfake.ErrorResponder) + + // DeleteValue is the fake for method TagsClient.DeleteValue + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteValue func(ctx context.Context, tagName string, tagValue string, options *armresources.TagsClientDeleteValueOptions) (resp azfake.Responder[armresources.TagsClientDeleteValueResponse], errResp azfake.ErrorResponder) + + // GetAtScope is the fake for method TagsClient.GetAtScope + // HTTP status codes to indicate success: http.StatusOK + GetAtScope func(ctx context.Context, scope string, options *armresources.TagsClientGetAtScopeOptions) (resp azfake.Responder[armresources.TagsClientGetAtScopeResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method TagsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armresources.TagsClientListOptions) (resp azfake.PagerResponder[armresources.TagsClientListResponse]) + + // UpdateAtScope is the fake for method TagsClient.UpdateAtScope + // HTTP status codes to indicate success: http.StatusOK + UpdateAtScope func(ctx context.Context, scope string, parameters armresources.TagsPatchResource, options *armresources.TagsClientUpdateAtScopeOptions) (resp azfake.Responder[armresources.TagsClientUpdateAtScopeResponse], errResp azfake.ErrorResponder) +} + +// NewTagsServerTransport creates a new instance of TagsServerTransport with the provided implementation. +// The returned TagsServerTransport instance is connected to an instance of armresources.TagsClient by way of the +// undefined.Transporter field. +func NewTagsServerTransport(srv *TagsServer) *TagsServerTransport { + return &TagsServerTransport{srv: srv} +} + +// TagsServerTransport connects instances of armresources.TagsClient to instances of TagsServer. +// Don't use this type directly, use NewTagsServerTransport instead. +type TagsServerTransport struct { + srv *TagsServer + newListPager *azfake.PagerResponder[armresources.TagsClientListResponse] +} + +// Do implements the policy.Transporter interface for TagsServerTransport. +func (t *TagsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "TagsClient.CreateOrUpdate": + resp, err = t.dispatchCreateOrUpdate(req) + case "TagsClient.CreateOrUpdateAtScope": + resp, err = t.dispatchCreateOrUpdateAtScope(req) + case "TagsClient.CreateOrUpdateValue": + resp, err = t.dispatchCreateOrUpdateValue(req) + case "TagsClient.Delete": + resp, err = t.dispatchDelete(req) + case "TagsClient.DeleteAtScope": + resp, err = t.dispatchDeleteAtScope(req) + case "TagsClient.DeleteValue": + resp, err = t.dispatchDeleteValue(req) + case "TagsClient.GetAtScope": + resp, err = t.dispatchGetAtScope(req) + case "TagsClient.NewListPager": + resp, err = t.dispatchNewListPager(req) + case "TagsClient.UpdateAtScope": + resp, err = t.dispatchUpdateAtScope(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (t *TagsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if t.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method CreateOrUpdate not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := t.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("tagName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TagDetails, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchCreateOrUpdateAtScope(req *http.Request) (*http.Response, error) { + if t.srv.CreateOrUpdateAtScope == nil { + return nil, &nonRetriableError{errors.New("method CreateOrUpdateAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.TagsResource](req) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.CreateOrUpdateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TagsResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchCreateOrUpdateValue(req *http.Request) (*http.Response, error) { + if t.srv.CreateOrUpdateValue == nil { + return nil, &nonRetriableError{errors.New("method CreateOrUpdateValue not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)/tagValues/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := t.srv.CreateOrUpdateValue(req.Context(), matches[regex.SubexpIndex("tagName")], matches[regex.SubexpIndex("tagValue")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TagValue, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if t.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("method Delete not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := t.srv.Delete(req.Context(), matches[regex.SubexpIndex("tagName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchDeleteAtScope(req *http.Request) (*http.Response, error) { + if t.srv.DeleteAtScope == nil { + return nil, &nonRetriableError{errors.New("method DeleteAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := t.srv.DeleteAtScope(req.Context(), matches[regex.SubexpIndex("scope")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchDeleteValue(req *http.Request) (*http.Response, error) { + if t.srv.DeleteValue == nil { + return nil, &nonRetriableError{errors.New("method DeleteValue not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)/tagValues/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := t.srv.DeleteValue(req.Context(), matches[regex.SubexpIndex("tagName")], matches[regex.SubexpIndex("tagValue")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) { + if t.srv.GetAtScope == nil { + return nil, &nonRetriableError{errors.New("method GetAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := t.srv.GetAtScope(req.Context(), matches[regex.SubexpIndex("scope")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TagsResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if t.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if t.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := t.srv.NewListPager(nil) + t.newListPager = &resp + server.PagerResponderInjectNextLinks(t.newListPager, req, func(page *armresources.TagsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(t.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(t.newListPager) { + t.newListPager = nil + } + return resp, nil +} + +func (t *TagsServerTransport) dispatchUpdateAtScope(req *http.Request) (*http.Response, error) { + if t.srv.UpdateAtScope == nil { + return nil, &nonRetriableError{errors.New("method UpdateAtScope not implemented")} + } + const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armresources.TagsPatchResource](req) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.UpdateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TagsResource, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go new file mode 100644 index 000000000000..45fe10cbc6df --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +const ( + utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` + utcLayout = "2006-01-02T15:04:05.999999999" + rfc3339JSON = `"` + time.RFC3339Nano + `"` +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +type timeRFC3339 time.Time + +func (t timeRFC3339) MarshalJSON() (json []byte, err error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t timeRFC3339) MarshalText() (text []byte, err error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *timeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcLayoutJSON + if tzOffsetRegex.Match(data) { + layout = rfc3339JSON + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { + layout := utcLayout + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = timeRFC3339(p) + return err +} + +func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*timeRFC3339)(t) +} + +func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || strings.EqualFold(string(data), "null") { + return nil + } + var aux timeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +} diff --git a/sdk/resourcemanager/resources/armresources/go.mod b/sdk/resourcemanager/resources/armresources/go.mod index 49b07d1790cc..11f2a0a0ac2a 100644 --- a/sdk/resourcemanager/resources/armresources/go.mod +++ b/sdk/resourcemanager/resources/armresources/go.mod @@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresour go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 @@ -11,7 +11,7 @@ require ( ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnaeon/go-vcr v1.1.0 // indirect @@ -21,9 +21,9 @@ require ( github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/sdk/resourcemanager/resources/armresources/go.sum b/sdk/resourcemanager/resources/armresources/go.sum index 66e5af2b127e..1391105aef01 100644 --- a/sdk/resourcemanager/resources/armresources/go.sum +++ b/sdk/resourcemanager/resources/armresources/go.sum @@ -1,9 +1,9 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2 h1:C3zKsGguxcLd8a2uEytB8+TFtBGd75bXRxEs0QBwsv0= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= @@ -31,12 +31,12 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/sdk/resourcemanager/resources/armresources/models.go b/sdk/resourcemanager/resources/armresources/models.go index 4c1ed376b59a..d841ed06037a 100644 --- a/sdk/resourcemanager/resources/armresources/models.go +++ b/sdk/resourcemanager/resources/armresources/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources diff --git a/sdk/resourcemanager/resources/armresources/models_serde.go b/sdk/resourcemanager/resources/armresources/models_serde.go index df592fc850b9..fe07f1f2d807 100644 --- a/sdk/resourcemanager/resources/armresources/models_serde.go +++ b/sdk/resourcemanager/resources/armresources/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources diff --git a/sdk/resourcemanager/resources/armresources/operations_client.go b/sdk/resourcemanager/resources/armresources/operations_client.go index bd4359ecee0a..326aadab0f0f 100644 --- a/sdk/resourcemanager/resources/armresources/operations_client.go +++ b/sdk/resourcemanager/resources/armresources/operations_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -48,6 +47,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -67,6 +67,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go b/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go index c4b54fa84461..7f160860a0af 100644 --- a/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go +++ b/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -52,18 +51,25 @@ func NewProviderResourceTypesClient(subscriptionID string, credential azcore.Tok // - options - ProviderResourceTypesClientListOptions contains the optional parameters for the ProviderResourceTypesClient.List // method. func (client *ProviderResourceTypesClient) List(ctx context.Context, resourceProviderNamespace string, options *ProviderResourceTypesClientListOptions) (ProviderResourceTypesClientListResponse, error) { + var err error + const operationName = "ProviderResourceTypesClient.List" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listCreateRequest(ctx, resourceProviderNamespace, options) if err != nil { return ProviderResourceTypesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProviderResourceTypesClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProviderResourceTypesClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProviderResourceTypesClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/resources/armresources/providers_client.go b/sdk/resourcemanager/resources/armresources/providers_client.go index cefb0e0393e7..21c52166aea5 100644 --- a/sdk/resourcemanager/resources/armresources/providers_client.go +++ b/sdk/resourcemanager/resources/armresources/providers_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -51,18 +50,25 @@ func NewProvidersClient(subscriptionID string, credential azcore.TokenCredential // - resourceProviderNamespace - The namespace of the resource provider. // - options - ProvidersClientGetOptions contains the optional parameters for the ProvidersClient.Get method. func (client *ProvidersClient) Get(ctx context.Context, resourceProviderNamespace string, options *ProvidersClientGetOptions) (ProvidersClientGetResponse, error) { + var err error + const operationName = "ProvidersClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceProviderNamespace, options) if err != nil { return ProvidersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProvidersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProvidersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -107,18 +113,25 @@ func (client *ProvidersClient) getHandleResponse(resp *http.Response) (Providers // - options - ProvidersClientGetAtTenantScopeOptions contains the optional parameters for the ProvidersClient.GetAtTenantScope // method. func (client *ProvidersClient) GetAtTenantScope(ctx context.Context, resourceProviderNamespace string, options *ProvidersClientGetAtTenantScopeOptions) (ProvidersClientGetAtTenantScopeResponse, error) { + var err error + const operationName = "ProvidersClient.GetAtTenantScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtTenantScopeCreateRequest(ctx, resourceProviderNamespace, options) if err != nil { return ProvidersClientGetAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProvidersClientGetAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientGetAtTenantScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProvidersClientGetAtTenantScopeResponse{}, err } - return client.getAtTenantScopeHandleResponse(resp) + resp, err := client.getAtTenantScopeHandleResponse(httpResp) + return resp, err } // getAtTenantScopeCreateRequest creates the GetAtTenantScope request. @@ -161,6 +174,7 @@ func (client *ProvidersClient) NewListPager(options *ProvidersClientListOptions) return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ProvidersClientListResponse) (ProvidersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProvidersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -180,6 +194,7 @@ func (client *ProvidersClient) NewListPager(options *ProvidersClientListOptions) } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -224,6 +239,7 @@ func (client *ProvidersClient) NewListAtTenantScopePager(options *ProvidersClien return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ProvidersClientListAtTenantScopeResponse) (ProvidersClientListAtTenantScopeResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProvidersClient.NewListAtTenantScopePager") var req *policy.Request var err error if page == nil { @@ -243,6 +259,7 @@ func (client *ProvidersClient) NewListAtTenantScopePager(options *ProvidersClien } return client.listAtTenantScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -280,18 +297,25 @@ func (client *ProvidersClient) listAtTenantScopeHandleResponse(resp *http.Respon // - options - ProvidersClientProviderPermissionsOptions contains the optional parameters for the ProvidersClient.ProviderPermissions // method. func (client *ProvidersClient) ProviderPermissions(ctx context.Context, resourceProviderNamespace string, options *ProvidersClientProviderPermissionsOptions) (ProvidersClientProviderPermissionsResponse, error) { + var err error + const operationName = "ProvidersClient.ProviderPermissions" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.providerPermissionsCreateRequest(ctx, resourceProviderNamespace, options) if err != nil { return ProvidersClientProviderPermissionsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProvidersClientProviderPermissionsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientProviderPermissionsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProvidersClientProviderPermissionsResponse{}, err } - return client.providerPermissionsHandleResponse(resp) + resp, err := client.providerPermissionsHandleResponse(httpResp) + return resp, err } // providerPermissionsCreateRequest creates the ProviderPermissions request. @@ -332,18 +356,25 @@ func (client *ProvidersClient) providerPermissionsHandleResponse(resp *http.Resp // - resourceProviderNamespace - The namespace of the resource provider to register. // - options - ProvidersClientRegisterOptions contains the optional parameters for the ProvidersClient.Register method. func (client *ProvidersClient) Register(ctx context.Context, resourceProviderNamespace string, options *ProvidersClientRegisterOptions) (ProvidersClientRegisterResponse, error) { + var err error + const operationName = "ProvidersClient.Register" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.registerCreateRequest(ctx, resourceProviderNamespace, options) if err != nil { return ProvidersClientRegisterResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProvidersClientRegisterResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientRegisterResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProvidersClientRegisterResponse{}, err } - return client.registerHandleResponse(resp) + resp, err := client.registerHandleResponse(httpResp) + return resp, err } // registerCreateRequest creates the Register request. @@ -366,7 +397,10 @@ func (client *ProvidersClient) registerCreateRequest(ctx context.Context, resour req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Properties != nil { - return req, runtime.MarshalAsJSON(req, *options.Properties) + if err := runtime.MarshalAsJSON(req, *options.Properties); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -389,16 +423,22 @@ func (client *ProvidersClient) registerHandleResponse(resp *http.Response) (Prov // - options - ProvidersClientRegisterAtManagementGroupScopeOptions contains the optional parameters for the ProvidersClient.RegisterAtManagementGroupScope // method. func (client *ProvidersClient) RegisterAtManagementGroupScope(ctx context.Context, resourceProviderNamespace string, groupID string, options *ProvidersClientRegisterAtManagementGroupScopeOptions) (ProvidersClientRegisterAtManagementGroupScopeResponse, error) { + var err error + const operationName = "ProvidersClient.RegisterAtManagementGroupScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.registerAtManagementGroupScopeCreateRequest(ctx, resourceProviderNamespace, groupID, options) if err != nil { return ProvidersClientRegisterAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProvidersClientRegisterAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientRegisterAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProvidersClientRegisterAtManagementGroupScopeResponse{}, err } return ProvidersClientRegisterAtManagementGroupScopeResponse{}, nil } @@ -432,18 +472,25 @@ func (client *ProvidersClient) registerAtManagementGroupScopeCreateRequest(ctx c // - resourceProviderNamespace - The namespace of the resource provider to unregister. // - options - ProvidersClientUnregisterOptions contains the optional parameters for the ProvidersClient.Unregister method. func (client *ProvidersClient) Unregister(ctx context.Context, resourceProviderNamespace string, options *ProvidersClientUnregisterOptions) (ProvidersClientUnregisterResponse, error) { + var err error + const operationName = "ProvidersClient.Unregister" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.unregisterCreateRequest(ctx, resourceProviderNamespace, options) if err != nil { return ProvidersClientUnregisterResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProvidersClientUnregisterResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientUnregisterResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProvidersClientUnregisterResponse{}, err } - return client.unregisterHandleResponse(resp) + resp, err := client.unregisterHandleResponse(httpResp) + return resp, err } // unregisterCreateRequest creates the Unregister request. diff --git a/sdk/resourcemanager/resources/armresources/resourcegroups_client.go b/sdk/resourcemanager/resources/armresources/resourcegroups_client.go index cf48c26f5191..123bf47a104f 100644 --- a/sdk/resourcemanager/resources/armresources/resourcegroups_client.go +++ b/sdk/resourcemanager/resources/armresources/resourcegroups_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -52,18 +51,24 @@ func NewResourceGroupsClient(subscriptionID string, credential azcore.TokenCrede // - options - ResourceGroupsClientCheckExistenceOptions contains the optional parameters for the ResourceGroupsClient.CheckExistence // method. func (client *ResourceGroupsClient) CheckExistence(ctx context.Context, resourceGroupName string, options *ResourceGroupsClientCheckExistenceOptions) (ResourceGroupsClientCheckExistenceResponse, error) { + var err error + const operationName = "ResourceGroupsClient.CheckExistence" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkExistenceCreateRequest(ctx, resourceGroupName, options) if err != nil { return ResourceGroupsClientCheckExistenceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceGroupsClientCheckExistenceResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent, http.StatusNotFound) { - return ResourceGroupsClientCheckExistenceResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ResourceGroupsClientCheckExistenceResponse{}, err } - return ResourceGroupsClientCheckExistenceResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}, nil + return ResourceGroupsClientCheckExistenceResponse{Success: httpResp.StatusCode >= 200 && httpResp.StatusCode < 300}, nil } // checkExistenceCreateRequest creates the CheckExistence request. @@ -98,18 +103,25 @@ func (client *ResourceGroupsClient) checkExistenceCreateRequest(ctx context.Cont // - options - ResourceGroupsClientCreateOrUpdateOptions contains the optional parameters for the ResourceGroupsClient.CreateOrUpdate // method. func (client *ResourceGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, parameters ResourceGroup, options *ResourceGroupsClientCreateOrUpdateOptions) (ResourceGroupsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ResourceGroupsClient.CreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, parameters, options) if err != nil { return ResourceGroupsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceGroupsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ResourceGroupsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ResourceGroupsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -131,7 +143,10 @@ func (client *ResourceGroupsClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -157,7 +172,8 @@ func (client *ResourceGroupsClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[ResourceGroupsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ResourceGroupsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ResourceGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -169,18 +185,24 @@ func (client *ResourceGroupsClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2021-04-01 func (client *ResourceGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, options *ResourceGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ResourceGroupsClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, resourceGroupName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -222,9 +244,10 @@ func (client *ResourceGroupsClient) BeginExportTemplate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ResourceGroupsClientExportTemplateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ResourceGroupsClientExportTemplateResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ResourceGroupsClientExportTemplateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -235,18 +258,24 @@ func (client *ResourceGroupsClient) BeginExportTemplate(ctx context.Context, res // // Generated from API version 2021-04-01 func (client *ResourceGroupsClient) exportTemplate(ctx context.Context, resourceGroupName string, parameters ExportTemplateRequest, options *ResourceGroupsClientBeginExportTemplateOptions) (*http.Response, error) { + var err error + const operationName = "ResourceGroupsClient.BeginExportTemplate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateCreateRequest(ctx, resourceGroupName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // exportTemplateCreateRequest creates the ExportTemplate request. @@ -268,7 +297,10 @@ func (client *ResourceGroupsClient) exportTemplateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // Get - Gets a resource group. @@ -278,18 +310,25 @@ func (client *ResourceGroupsClient) exportTemplateCreateRequest(ctx context.Cont // - resourceGroupName - The name of the resource group to get. The name is case insensitive. // - options - ResourceGroupsClientGetOptions contains the optional parameters for the ResourceGroupsClient.Get method. func (client *ResourceGroupsClient) Get(ctx context.Context, resourceGroupName string, options *ResourceGroupsClientGetOptions) (ResourceGroupsClientGetResponse, error) { + var err error + const operationName = "ResourceGroupsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceGroupName, options) if err != nil { return ResourceGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ResourceGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -333,6 +372,7 @@ func (client *ResourceGroupsClient) NewListPager(options *ResourceGroupsClientLi return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceGroupsClientListResponse) (ResourceGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceGroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -352,6 +392,7 @@ func (client *ResourceGroupsClient) NewListPager(options *ResourceGroupsClientLi } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -398,18 +439,25 @@ func (client *ResourceGroupsClient) listHandleResponse(resp *http.Response) (Res // - parameters - Parameters supplied to update a resource group. // - options - ResourceGroupsClientUpdateOptions contains the optional parameters for the ResourceGroupsClient.Update method. func (client *ResourceGroupsClient) Update(ctx context.Context, resourceGroupName string, parameters ResourceGroupPatchable, options *ResourceGroupsClientUpdateOptions) (ResourceGroupsClientUpdateResponse, error) { + var err error + const operationName = "ResourceGroupsClient.Update" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, resourceGroupName, parameters, options) if err != nil { return ResourceGroupsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceGroupsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceGroupsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ResourceGroupsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -431,7 +479,10 @@ func (client *ResourceGroupsClient) updateCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // updateHandleResponse handles the Update response. diff --git a/sdk/resourcemanager/resources/armresources/response_types.go b/sdk/resourcemanager/resources/armresources/response_types.go index f1a7793b52c0..01f1cfb79649 100644 --- a/sdk/resourcemanager/resources/armresources/response_types.go +++ b/sdk/resourcemanager/resources/armresources/response_types.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources diff --git a/sdk/resourcemanager/resources/armresources/tags_client.go b/sdk/resourcemanager/resources/armresources/tags_client.go index b508c6a2ef80..caa54194a255 100644 --- a/sdk/resourcemanager/resources/armresources/tags_client.go +++ b/sdk/resourcemanager/resources/armresources/tags_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources @@ -53,18 +52,25 @@ func NewTagsClient(subscriptionID string, credential azcore.TokenCredential, opt // - tagName - The name of the tag to create. // - options - TagsClientCreateOrUpdateOptions contains the optional parameters for the TagsClient.CreateOrUpdate method. func (client *TagsClient) CreateOrUpdate(ctx context.Context, tagName string, options *TagsClientCreateOrUpdateOptions) (TagsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "TagsClient.CreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, tagName, options) if err != nil { return TagsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return TagsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return TagsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -107,18 +113,25 @@ func (client *TagsClient) createOrUpdateHandleResponse(resp *http.Response) (Tag // - options - TagsClientCreateOrUpdateAtScopeOptions contains the optional parameters for the TagsClient.CreateOrUpdateAtScope // method. func (client *TagsClient) CreateOrUpdateAtScope(ctx context.Context, scope string, parameters TagsResource, options *TagsClientCreateOrUpdateAtScopeOptions) (TagsClientCreateOrUpdateAtScopeResponse, error) { + var err error + const operationName = "TagsClient.CreateOrUpdateAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtScopeCreateRequest(ctx, scope, parameters, options) if err != nil { return TagsClientCreateOrUpdateAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientCreateOrUpdateAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TagsClientCreateOrUpdateAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TagsClientCreateOrUpdateAtScopeResponse{}, err } - return client.createOrUpdateAtScopeHandleResponse(resp) + resp, err := client.createOrUpdateAtScopeHandleResponse(httpResp) + return resp, err } // createOrUpdateAtScopeCreateRequest creates the CreateOrUpdateAtScope request. @@ -133,7 +146,10 @@ func (client *TagsClient) createOrUpdateAtScopeCreateRequest(ctx context.Context reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateAtScopeHandleResponse handles the CreateOrUpdateAtScope response. @@ -155,18 +171,25 @@ func (client *TagsClient) createOrUpdateAtScopeHandleResponse(resp *http.Respons // - options - TagsClientCreateOrUpdateValueOptions contains the optional parameters for the TagsClient.CreateOrUpdateValue // method. func (client *TagsClient) CreateOrUpdateValue(ctx context.Context, tagName string, tagValue string, options *TagsClientCreateOrUpdateValueOptions) (TagsClientCreateOrUpdateValueResponse, error) { + var err error + const operationName = "TagsClient.CreateOrUpdateValue" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateValueCreateRequest(ctx, tagName, tagValue, options) if err != nil { return TagsClientCreateOrUpdateValueResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientCreateOrUpdateValueResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return TagsClientCreateOrUpdateValueResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return TagsClientCreateOrUpdateValueResponse{}, err } - return client.createOrUpdateValueHandleResponse(resp) + resp, err := client.createOrUpdateValueHandleResponse(httpResp) + return resp, err } // createOrUpdateValueCreateRequest creates the CreateOrUpdateValue request. @@ -213,16 +236,22 @@ func (client *TagsClient) createOrUpdateValueHandleResponse(resp *http.Response) // - tagName - The name of the tag. // - options - TagsClientDeleteOptions contains the optional parameters for the TagsClient.Delete method. func (client *TagsClient) Delete(ctx context.Context, tagName string, options *TagsClientDeleteOptions) (TagsClientDeleteResponse, error) { + var err error + const operationName = "TagsClient.Delete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, tagName, options) if err != nil { return TagsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return TagsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return TagsClientDeleteResponse{}, err } return TagsClientDeleteResponse{}, nil } @@ -256,16 +285,22 @@ func (client *TagsClient) deleteCreateRequest(ctx context.Context, tagName strin // - scope - The resource scope. // - options - TagsClientDeleteAtScopeOptions contains the optional parameters for the TagsClient.DeleteAtScope method. func (client *TagsClient) DeleteAtScope(ctx context.Context, scope string, options *TagsClientDeleteAtScopeOptions) (TagsClientDeleteAtScopeResponse, error) { + var err error + const operationName = "TagsClient.DeleteAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtScopeCreateRequest(ctx, scope, options) if err != nil { return TagsClientDeleteAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientDeleteAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TagsClientDeleteAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TagsClientDeleteAtScopeResponse{}, err } return TagsClientDeleteAtScopeResponse{}, nil } @@ -295,16 +330,22 @@ func (client *TagsClient) deleteAtScopeCreateRequest(ctx context.Context, scope // - tagValue - The value of the tag to delete. // - options - TagsClientDeleteValueOptions contains the optional parameters for the TagsClient.DeleteValue method. func (client *TagsClient) DeleteValue(ctx context.Context, tagName string, tagValue string, options *TagsClientDeleteValueOptions) (TagsClientDeleteValueResponse, error) { + var err error + const operationName = "TagsClient.DeleteValue" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteValueCreateRequest(ctx, tagName, tagValue, options) if err != nil { return TagsClientDeleteValueResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientDeleteValueResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return TagsClientDeleteValueResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return TagsClientDeleteValueResponse{}, err } return TagsClientDeleteValueResponse{}, nil } @@ -342,18 +383,25 @@ func (client *TagsClient) deleteValueCreateRequest(ctx context.Context, tagName // - scope - The resource scope. // - options - TagsClientGetAtScopeOptions contains the optional parameters for the TagsClient.GetAtScope method. func (client *TagsClient) GetAtScope(ctx context.Context, scope string, options *TagsClientGetAtScopeOptions) (TagsClientGetAtScopeResponse, error) { + var err error + const operationName = "TagsClient.GetAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtScopeCreateRequest(ctx, scope, options) if err != nil { return TagsClientGetAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientGetAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TagsClientGetAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TagsClientGetAtScopeResponse{}, err } - return client.getAtScopeHandleResponse(resp) + resp, err := client.getAtScopeHandleResponse(httpResp) + return resp, err } // getAtScopeCreateRequest creates the GetAtScope request. @@ -392,6 +440,7 @@ func (client *TagsClient) NewListPager(options *TagsClientListOptions) *runtime. return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *TagsClientListResponse) (TagsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TagsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -411,6 +460,7 @@ func (client *TagsClient) NewListPager(options *TagsClientListOptions) *runtime. } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -452,18 +502,25 @@ func (client *TagsClient) listHandleResponse(resp *http.Response) (TagsClientLis // - scope - The resource scope. // - options - TagsClientUpdateAtScopeOptions contains the optional parameters for the TagsClient.UpdateAtScope method. func (client *TagsClient) UpdateAtScope(ctx context.Context, scope string, parameters TagsPatchResource, options *TagsClientUpdateAtScopeOptions) (TagsClientUpdateAtScopeResponse, error) { + var err error + const operationName = "TagsClient.UpdateAtScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateAtScopeCreateRequest(ctx, scope, parameters, options) if err != nil { return TagsClientUpdateAtScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TagsClientUpdateAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TagsClientUpdateAtScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TagsClientUpdateAtScopeResponse{}, err } - return client.updateAtScopeHandleResponse(resp) + resp, err := client.updateAtScopeHandleResponse(httpResp) + return resp, err } // updateAtScopeCreateRequest creates the UpdateAtScope request. @@ -478,7 +535,10 @@ func (client *TagsClient) updateAtScopeCreateRequest(ctx context.Context, scope reqQP.Set("api-version", "2021-04-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // updateAtScopeHandleResponse handles the UpdateAtScope response. diff --git a/sdk/resourcemanager/resources/armresources/time_rfc3339.go b/sdk/resourcemanager/resources/armresources/time_rfc3339.go index cb02b976b396..b4726b97b180 100644 --- a/sdk/resourcemanager/resources/armresources/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armresources/time_rfc3339.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armresources From 24bbec809ed5dc83eac49c783ac1bb8e29e8b412 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Fri, 9 Jun 2023 15:50:05 -0700 Subject: [PATCH 2/2] update to latest code generator added testable fake example bump release date --- .../resources/armresources/CHANGELOG.md | 2 +- .../resources/armresources/build.go | 2 +- .../fake/deploymentoperations_server.go | 195 +++-- .../armresources/fake/deployments_server.go | 667 +++++++++++++----- .../armresources/fake/operations_server.go | 2 +- .../fake/providerresourcetypes_server.go | 19 +- .../armresources/fake/providers_server.go | 109 ++- .../fake/resourcegroups_server.go | 97 ++- .../resources/armresources/fake/server.go | 319 +++++++-- .../armresources/fake/tags_server.go | 111 ++- .../armresources/fake_example_test.go | 74 ++ 11 files changed, 1203 insertions(+), 394 deletions(-) create mode 100644 sdk/resourcemanager/resources/armresources/fake_example_test.go diff --git a/sdk/resourcemanager/resources/armresources/CHANGELOG.md b/sdk/resourcemanager/resources/armresources/CHANGELOG.md index 0730e6d1833f..b0eec9a19ff8 100644 --- a/sdk/resourcemanager/resources/armresources/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armresources/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.2.0-beta.1 (2023-06-08) +## 1.2.0-beta.1 (2023-06-12) ### Features Added diff --git a/sdk/resourcemanager/resources/armresources/build.go b/sdk/resourcemanager/resources/armresources/build.go index 3c8d4bf05f5f..d38f8bbde615 100644 --- a/sdk/resourcemanager/resources/armresources/build.go +++ b/sdk/resourcemanager/resources/armresources/build.go @@ -2,6 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // This file enables 'go generate' to regenerate this specific SDK -//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.50" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armresources +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.51" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armresources package armresources diff --git a/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go b/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go index b78977ea7db8..20425af3bc31 100644 --- a/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go @@ -18,6 +18,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "regexp" "strconv" ) @@ -128,15 +129,27 @@ func (d *DeploymentOperationsServerTransport) Do(req *http.Request) (*http.Respo func (d *DeploymentOperationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if d.srv.Get == nil { - return nil, &nonRetriableError{errors.New("method Get not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 4 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, operationIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -153,15 +166,27 @@ func (d *DeploymentOperationsServerTransport) dispatchGet(req *http.Request) (*h func (d *DeploymentOperationsServerTransport) dispatchGetAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroupScope not implemented")} } - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, operationIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -178,15 +203,27 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtManagementGroupScope( func (d *DeploymentOperationsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, operationIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -203,15 +240,23 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtScope(req *http.Reque func (d *DeploymentOperationsServerTransport) dispatchGetAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtSubscriptionScope not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameUnescaped, operationIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -228,15 +273,23 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtSubscriptionScope(req func (d *DeploymentOperationsServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtTenantScope not implemented")} } - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], matches[regex.SubexpIndex("operationId")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameUnescaped, operationIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -253,17 +306,29 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtTenantScope(req *http func (d *DeploymentOperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if d.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if d.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/deployments/(?P[a-zA-Z0-9-_]+)/operations" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -279,7 +344,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListPager(req *http.Req Top: topParam, } } - resp := d.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], options) + resp := d.srv.NewListPager(resourceGroupNameUnescaped, deploymentNameUnescaped, options) d.newListPager = &resp server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armresources.DeploymentOperationsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -300,17 +365,29 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListPager(req *http.Req func (d *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtManagementGroupScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtManagementGroupScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtManagementGroupScopePager not implemented")} } if d.newListAtManagementGroupScopePager == nil { - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -326,7 +403,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupSc Top: topParam, } } - resp := d.srv.NewListAtManagementGroupScopePager(matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], options) + resp := d.srv.NewListAtManagementGroupScopePager(groupIDUnescaped, deploymentNameUnescaped, options) d.newListAtManagementGroupScopePager = &resp server.PagerResponderInjectNextLinks(d.newListAtManagementGroupScopePager, req, func(page *armresources.DeploymentOperationsClientListAtManagementGroupScopeResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -347,17 +424,29 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupSc func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtScopePager not implemented")} } if d.newListAtScopePager == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -373,7 +462,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *h Top: topParam, } } - resp := d.srv.NewListAtScopePager(matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], options) + resp := d.srv.NewListAtScopePager(scopeUnescaped, deploymentNameUnescaped, options) d.newListAtScopePager = &resp server.PagerResponderInjectNextLinks(d.newListAtScopePager, req, func(page *armresources.DeploymentOperationsClientListAtScopeResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -394,17 +483,25 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *h func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtSubscriptionScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtSubscriptionScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtSubscriptionScopePager not implemented")} } if d.newListAtSubscriptionScopePager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -420,7 +517,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScope Top: topParam, } } - resp := d.srv.NewListAtSubscriptionScopePager(matches[regex.SubexpIndex("deploymentName")], options) + resp := d.srv.NewListAtSubscriptionScopePager(deploymentNameUnescaped, options) d.newListAtSubscriptionScopePager = &resp server.PagerResponderInjectNextLinks(d.newListAtSubscriptionScopePager, req, func(page *armresources.DeploymentOperationsClientListAtSubscriptionScopeResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -441,17 +538,25 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScope func (d *DeploymentOperationsServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtTenantScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtTenantScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtTenantScopePager not implemented")} } if d.newListAtTenantScopePager == nil { - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/operations" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -467,7 +572,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtTenantScopePager( Top: topParam, } } - resp := d.srv.NewListAtTenantScopePager(matches[regex.SubexpIndex("deploymentName")], options) + resp := d.srv.NewListAtTenantScopePager(deploymentNameUnescaped, options) d.newListAtTenantScopePager = &resp server.PagerResponderInjectNextLinks(d.newListAtTenantScopePager, req, func(page *armresources.DeploymentOperationsClientListAtTenantScopeResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/resources/armresources/fake/deployments_server.go b/sdk/resourcemanager/resources/armresources/fake/deployments_server.go index 0512d1b4b1bd..b49f2def0402 100644 --- a/sdk/resourcemanager/resources/armresources/fake/deployments_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/deployments_server.go @@ -18,6 +18,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "regexp" "strconv" ) @@ -357,7 +358,7 @@ func (d *DeploymentsServerTransport) Do(req *http.Request) (*http.Response, erro func (d *DeploymentsServerTransport) dispatchCalculateTemplateHash(req *http.Request) (*http.Response, error) { if d.srv.CalculateTemplateHash == nil { - return nil, &nonRetriableError{errors.New("method CalculateTemplateHash not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CalculateTemplateHash not implemented")} } body, err := server.UnmarshalRequestAsJSON[any](req) if err != nil { @@ -380,15 +381,23 @@ func (d *DeploymentsServerTransport) dispatchCalculateTemplateHash(req *http.Req func (d *DeploymentsServerTransport) dispatchCancel(req *http.Request) (*http.Response, error) { if d.srv.Cancel == nil { - return nil, &nonRetriableError{errors.New("method Cancel not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Cancel not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.Cancel(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Cancel(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -405,15 +414,23 @@ func (d *DeploymentsServerTransport) dispatchCancel(req *http.Request) (*http.Re func (d *DeploymentsServerTransport) dispatchCancelAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.CancelAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method CancelAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CancelAtManagementGroupScope not implemented")} } - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CancelAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CancelAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -430,15 +447,23 @@ func (d *DeploymentsServerTransport) dispatchCancelAtManagementGroupScope(req *h func (d *DeploymentsServerTransport) dispatchCancelAtScope(req *http.Request) (*http.Response, error) { if d.srv.CancelAtScope == nil { - return nil, &nonRetriableError{errors.New("method CancelAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CancelAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CancelAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CancelAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -455,15 +480,19 @@ func (d *DeploymentsServerTransport) dispatchCancelAtScope(req *http.Request) (* func (d *DeploymentsServerTransport) dispatchCancelAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.CancelAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method CancelAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CancelAtSubscriptionScope not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CancelAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CancelAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -480,15 +509,19 @@ func (d *DeploymentsServerTransport) dispatchCancelAtSubscriptionScope(req *http func (d *DeploymentsServerTransport) dispatchCancelAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.CancelAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method CancelAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CancelAtTenantScope not implemented")} } - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/cancel" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CancelAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CancelAtTenantScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -505,15 +538,23 @@ func (d *DeploymentsServerTransport) dispatchCancelAtTenantScope(req *http.Reque func (d *DeploymentsServerTransport) dispatchCheckExistence(req *http.Request) (*http.Response, error) { if d.srv.CheckExistence == nil { - return nil, &nonRetriableError{errors.New("method CheckExistence not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistence not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CheckExistence(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CheckExistence(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -530,15 +571,23 @@ func (d *DeploymentsServerTransport) dispatchCheckExistence(req *http.Request) ( func (d *DeploymentsServerTransport) dispatchCheckExistenceAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.CheckExistenceAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method CheckExistenceAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtManagementGroupScope not implemented")} } - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CheckExistenceAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CheckExistenceAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -555,15 +604,23 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtManagementGroupScop func (d *DeploymentsServerTransport) dispatchCheckExistenceAtScope(req *http.Request) (*http.Response, error) { if d.srv.CheckExistenceAtScope == nil { - return nil, &nonRetriableError{errors.New("method CheckExistenceAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CheckExistenceAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CheckExistenceAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -580,15 +637,19 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtScope(req *http.Req func (d *DeploymentsServerTransport) dispatchCheckExistenceAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.CheckExistenceAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method CheckExistenceAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtSubscriptionScope not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CheckExistenceAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CheckExistenceAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -605,15 +666,19 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtSubscriptionScope(r func (d *DeploymentsServerTransport) dispatchCheckExistenceAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.CheckExistenceAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method CheckExistenceAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtTenantScope not implemented")} } - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.CheckExistenceAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CheckExistenceAtTenantScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -630,12 +695,12 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtTenantScope(req *ht func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if d.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if d.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -643,7 +708,15 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdate(req *http.Reque if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -667,12 +740,12 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdate(req *http.Reque func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.BeginCreateOrUpdateAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtManagementGroupScope not implemented")} } if d.beginCreateOrUpdateAtManagementGroupScope == nil { - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -680,7 +753,15 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtManagementGrou if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], body, nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -704,12 +785,12 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtManagementGrou func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtScope(req *http.Request) (*http.Response, error) { if d.srv.BeginCreateOrUpdateAtScope == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtScope not implemented")} } if d.beginCreateOrUpdateAtScope == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -717,7 +798,15 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtScope(req *htt if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], body, nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -741,12 +830,12 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtScope(req *htt func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.BeginCreateOrUpdateAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtSubscriptionScope not implemented")} } if d.beginCreateOrUpdateAtSubscriptionScope == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -754,7 +843,11 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtSubscriptionSc if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtSubscriptionScope(req.Context(), deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -778,12 +871,12 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtSubscriptionSc func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.BeginCreateOrUpdateAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtTenantScope not implemented")} } if d.beginCreateOrUpdateAtTenantScope == nil { - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -791,7 +884,11 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtTenantScope(re if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdateAtTenantScope(req.Context(), deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -815,16 +912,24 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtTenantScope(re func (d *DeploymentsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if d.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if d.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -848,16 +953,24 @@ func (d *DeploymentsServerTransport) dispatchBeginDelete(req *http.Request) (*ht func (d *DeploymentsServerTransport) dispatchBeginDeleteAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.BeginDeleteAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtManagementGroupScope not implemented")} } if d.beginDeleteAtManagementGroupScope == nil { - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.BeginDeleteAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDeleteAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -881,16 +994,24 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtManagementGroupScope(r func (d *DeploymentsServerTransport) dispatchBeginDeleteAtScope(req *http.Request) (*http.Response, error) { if d.srv.BeginDeleteAtScope == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtScope not implemented")} } if d.beginDeleteAtScope == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.BeginDeleteAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDeleteAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -914,16 +1035,20 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtScope(req *http.Reques func (d *DeploymentsServerTransport) dispatchBeginDeleteAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.BeginDeleteAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtSubscriptionScope not implemented")} } if d.beginDeleteAtSubscriptionScope == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.BeginDeleteAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDeleteAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -947,16 +1072,20 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtSubscriptionScope(req func (d *DeploymentsServerTransport) dispatchBeginDeleteAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.BeginDeleteAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtTenantScope not implemented")} } if d.beginDeleteAtTenantScope == nil { - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.BeginDeleteAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDeleteAtTenantScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -980,15 +1109,23 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtTenantScope(req *http. func (d *DeploymentsServerTransport) dispatchExportTemplate(req *http.Request) (*http.Response, error) { if d.srv.ExportTemplate == nil { - return nil, &nonRetriableError{errors.New("method ExportTemplate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ExportTemplate not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.ExportTemplate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.ExportTemplate(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1005,15 +1142,23 @@ func (d *DeploymentsServerTransport) dispatchExportTemplate(req *http.Request) ( func (d *DeploymentsServerTransport) dispatchExportTemplateAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.ExportTemplateAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method ExportTemplateAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtManagementGroupScope not implemented")} } - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.ExportTemplateAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.ExportTemplateAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1030,15 +1175,23 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtManagementGroupScop func (d *DeploymentsServerTransport) dispatchExportTemplateAtScope(req *http.Request) (*http.Response, error) { if d.srv.ExportTemplateAtScope == nil { - return nil, &nonRetriableError{errors.New("method ExportTemplateAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.ExportTemplateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.ExportTemplateAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1055,15 +1208,19 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtScope(req *http.Req func (d *DeploymentsServerTransport) dispatchExportTemplateAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.ExportTemplateAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method ExportTemplateAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtSubscriptionScope not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.ExportTemplateAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.ExportTemplateAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1080,15 +1237,19 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtSubscriptionScope(r func (d *DeploymentsServerTransport) dispatchExportTemplateAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.ExportTemplateAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method ExportTemplateAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtTenantScope not implemented")} } - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/exportTemplate" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.ExportTemplateAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.ExportTemplateAtTenantScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1105,15 +1266,23 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtTenantScope(req *ht func (d *DeploymentsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if d.srv.Get == nil { - return nil, &nonRetriableError{errors.New("method Get not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1130,15 +1299,23 @@ func (d *DeploymentsServerTransport) dispatchGet(req *http.Request) (*http.Respo func (d *DeploymentsServerTransport) dispatchGetAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroupScope not implemented")} } - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1155,15 +1332,23 @@ func (d *DeploymentsServerTransport) dispatchGetAtManagementGroupScope(req *http func (d *DeploymentsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1180,15 +1365,19 @@ func (d *DeploymentsServerTransport) dispatchGetAtScope(req *http.Request) (*htt func (d *DeploymentsServerTransport) dispatchGetAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtSubscriptionScope not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1205,15 +1394,19 @@ func (d *DeploymentsServerTransport) dispatchGetAtSubscriptionScope(req *http.Re func (d *DeploymentsServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.GetAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtTenantScope not implemented")} } - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.GetAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1230,18 +1423,30 @@ func (d *DeploymentsServerTransport) dispatchGetAtTenantScope(req *http.Request) func (d *DeploymentsServerTransport) dispatchNewListAtManagementGroupScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtManagementGroupScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtManagementGroupScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtManagementGroupScopePager not implemented")} } if d.newListAtManagementGroupScopePager == nil { - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -1258,7 +1463,7 @@ func (d *DeploymentsServerTransport) dispatchNewListAtManagementGroupScopePager( Top: topParam, } } - resp := d.srv.NewListAtManagementGroupScopePager(matches[regex.SubexpIndex("groupId")], options) + resp := d.srv.NewListAtManagementGroupScopePager(groupIDUnescaped, options) d.newListAtManagementGroupScopePager = &resp server.PagerResponderInjectNextLinks(d.newListAtManagementGroupScopePager, req, func(page *armresources.DeploymentsClientListAtManagementGroupScopeResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -1279,18 +1484,30 @@ func (d *DeploymentsServerTransport) dispatchNewListAtManagementGroupScopePager( func (d *DeploymentsServerTransport) dispatchNewListAtScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtScopePager not implemented")} } if d.newListAtScopePager == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -1307,7 +1524,7 @@ func (d *DeploymentsServerTransport) dispatchNewListAtScopePager(req *http.Reque Top: topParam, } } - resp := d.srv.NewListAtScopePager(matches[regex.SubexpIndex("scope")], options) + resp := d.srv.NewListAtScopePager(scopeUnescaped, options) d.newListAtScopePager = &resp server.PagerResponderInjectNextLinks(d.newListAtScopePager, req, func(page *armresources.DeploymentsClientListAtScopeResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -1328,18 +1545,26 @@ func (d *DeploymentsServerTransport) dispatchNewListAtScopePager(req *http.Reque func (d *DeploymentsServerTransport) dispatchNewListAtSubscriptionScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtSubscriptionScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtSubscriptionScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtSubscriptionScopePager not implemented")} } if d.newListAtSubscriptionScopePager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -1377,12 +1602,20 @@ func (d *DeploymentsServerTransport) dispatchNewListAtSubscriptionScopePager(req func (d *DeploymentsServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) { if d.srv.NewListAtTenantScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtTenantScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtTenantScopePager not implemented")} } if d.newListAtTenantScopePager == nil { qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -1420,18 +1653,30 @@ func (d *DeploymentsServerTransport) dispatchNewListAtTenantScopePager(req *http func (d *DeploymentsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if d.srv.NewListByResourceGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } if d.newListByResourceGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -1448,7 +1693,7 @@ func (d *DeploymentsServerTransport) dispatchNewListByResourceGroupPager(req *ht Top: topParam, } } - resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], options) + resp := d.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, options) d.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armresources.DeploymentsClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -1469,12 +1714,12 @@ func (d *DeploymentsServerTransport) dispatchNewListByResourceGroupPager(req *ht func (d *DeploymentsServerTransport) dispatchBeginValidate(req *http.Request) (*http.Response, error) { if d.srv.BeginValidate == nil { - return nil, &nonRetriableError{errors.New("method BeginValidate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginValidate not implemented")} } if d.beginValidate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1482,7 +1727,15 @@ func (d *DeploymentsServerTransport) dispatchBeginValidate(req *http.Request) (* if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidate(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1506,12 +1759,12 @@ func (d *DeploymentsServerTransport) dispatchBeginValidate(req *http.Request) (* func (d *DeploymentsServerTransport) dispatchBeginValidateAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.BeginValidateAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method BeginValidateAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginValidateAtManagementGroupScope not implemented")} } if d.beginValidateAtManagementGroupScope == nil { - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1519,7 +1772,15 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtManagementGroupScope if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], body, nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1543,12 +1804,12 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtManagementGroupScope func (d *DeploymentsServerTransport) dispatchBeginValidateAtScope(req *http.Request) (*http.Response, error) { if d.srv.BeginValidateAtScope == nil { - return nil, &nonRetriableError{errors.New("method BeginValidateAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginValidateAtScope not implemented")} } if d.beginValidateAtScope == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1556,7 +1817,15 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtScope(req *http.Requ if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], matches[regex.SubexpIndex("deploymentName")], body, nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1580,12 +1849,12 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtScope(req *http.Requ func (d *DeploymentsServerTransport) dispatchBeginValidateAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.BeginValidateAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method BeginValidateAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginValidateAtSubscriptionScope not implemented")} } if d.beginValidateAtSubscriptionScope == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1593,7 +1862,11 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtSubscriptionScope(re if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtSubscriptionScope(req.Context(), deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1617,12 +1890,12 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtSubscriptionScope(re func (d *DeploymentsServerTransport) dispatchBeginValidateAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.BeginValidateAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method BeginValidateAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginValidateAtTenantScope not implemented")} } if d.beginValidateAtTenantScope == nil { - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/validate" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1630,7 +1903,11 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtTenantScope(req *htt if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginValidateAtTenantScope(req.Context(), deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1654,12 +1931,12 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtTenantScope(req *htt func (d *DeploymentsServerTransport) dispatchBeginWhatIf(req *http.Request) (*http.Response, error) { if d.srv.BeginWhatIf == nil { - return nil, &nonRetriableError{errors.New("method BeginWhatIf not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginWhatIf not implemented")} } if d.beginWhatIf == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1667,7 +1944,15 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIf(req *http.Request) (*ht if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIf(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("deploymentName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIf(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1691,12 +1976,12 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIf(req *http.Request) (*ht func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtManagementGroupScope(req *http.Request) (*http.Response, error) { if d.srv.BeginWhatIfAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method BeginWhatIfAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginWhatIfAtManagementGroupScope not implemented")} } if d.beginWhatIfAtManagementGroupScope == nil { - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1704,7 +1989,15 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtManagementGroupScope(r if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIfAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("groupId")], matches[regex.SubexpIndex("deploymentName")], body, nil) + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIfAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1728,12 +2021,12 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtManagementGroupScope(r func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtSubscriptionScope(req *http.Request) (*http.Response, error) { if d.srv.BeginWhatIfAtSubscriptionScope == nil { - return nil, &nonRetriableError{errors.New("method BeginWhatIfAtSubscriptionScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginWhatIfAtSubscriptionScope not implemented")} } if d.beginWhatIfAtSubscriptionScope == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1741,7 +2034,11 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtSubscriptionScope(req if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIfAtSubscriptionScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIfAtSubscriptionScope(req.Context(), deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1765,12 +2062,12 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtSubscriptionScope(req func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtTenantScope(req *http.Request) (*http.Response, error) { if d.srv.BeginWhatIfAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method BeginWhatIfAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginWhatIfAtTenantScope not implemented")} } if d.beginWhatIfAtTenantScope == nil { - const regexStr = "/providers/Microsoft.Resources/deployments/(?P[a-zA-Z0-9-_]+)/whatIf" + const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -1778,7 +2075,11 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtTenantScope(req *http. if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIfAtTenantScope(req.Context(), matches[regex.SubexpIndex("deploymentName")], body, nil) + deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginWhatIfAtTenantScope(req.Context(), deploymentNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/operations_server.go b/sdk/resourcemanager/resources/armresources/fake/operations_server.go index cef92be734be..f7e6dd1f5975 100644 --- a/sdk/resourcemanager/resources/armresources/fake/operations_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/operations_server.go @@ -67,7 +67,7 @@ func (o *OperationsServerTransport) Do(req *http.Request) (*http.Response, error func (o *OperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if o.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if o.newListPager == nil { resp := o.srv.NewListPager(nil) diff --git a/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go b/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go index 18e1a1b56d60..e6b9938697fa 100644 --- a/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go @@ -17,6 +17,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "regexp" ) @@ -67,23 +68,31 @@ func (p *ProviderResourceTypesServerTransport) Do(req *http.Request) (*http.Resp func (p *ProviderResourceTypesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { if p.srv.List == nil { - return nil, &nonRetriableError{errors.New("method List not implemented")} + return nil, &nonRetriableError{errors.New("fake for method List not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/resourceTypes" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceTypes` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } var options *armresources.ProviderResourceTypesClientListOptions if expandParam != nil { options = &armresources.ProviderResourceTypesClientListOptions{ Expand: expandParam, } } - respr, errRespr := p.srv.List(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + respr, errRespr := p.srv.List(req.Context(), resourceProviderNamespaceUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/providers_server.go b/sdk/resourcemanager/resources/armresources/fake/providers_server.go index 46b821433f55..0fb8d8e28a99 100644 --- a/sdk/resourcemanager/resources/armresources/fake/providers_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/providers_server.go @@ -18,6 +18,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "reflect" "regexp" ) @@ -113,23 +114,31 @@ func (p *ProvidersServerTransport) Do(req *http.Request) (*http.Response, error) func (p *ProvidersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if p.srv.Get == nil { - return nil, &nonRetriableError{errors.New("method Get not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } var options *armresources.ProvidersClientGetOptions if expandParam != nil { options = &armresources.ProvidersClientGetOptions{ Expand: expandParam, } } - respr, errRespr := p.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + respr, errRespr := p.srv.Get(req.Context(), resourceProviderNamespaceUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -146,23 +155,31 @@ func (p *ProvidersServerTransport) dispatchGet(req *http.Request) (*http.Respons func (p *ProvidersServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) { if p.srv.GetAtTenantScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtTenantScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtTenantScope not implemented")} } - const regexStr = "/providers/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } var options *armresources.ProvidersClientGetAtTenantScopeOptions if expandParam != nil { options = &armresources.ProvidersClientGetAtTenantScopeOptions{ Expand: expandParam, } } - respr, errRespr := p.srv.GetAtTenantScope(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + respr, errRespr := p.srv.GetAtTenantScope(req.Context(), resourceProviderNamespaceUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -179,17 +196,21 @@ func (p *ProvidersServerTransport) dispatchGetAtTenantScope(req *http.Request) ( func (p *ProvidersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if p.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if p.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armresources.ProvidersClientListOptions if expandParam != nil { options = &armresources.ProvidersClientListOptions{ @@ -217,11 +238,15 @@ func (p *ProvidersServerTransport) dispatchNewListPager(req *http.Request) (*htt func (p *ProvidersServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) { if p.srv.NewListAtTenantScopePager == nil { - return nil, &nonRetriableError{errors.New("method NewListAtTenantScopePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAtTenantScopePager not implemented")} } if p.newListAtTenantScopePager == nil { qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armresources.ProvidersClientListAtTenantScopeOptions if expandParam != nil { options = &armresources.ProvidersClientListAtTenantScopeOptions{ @@ -249,15 +274,19 @@ func (p *ProvidersServerTransport) dispatchNewListAtTenantScopePager(req *http.R func (p *ProvidersServerTransport) dispatchProviderPermissions(req *http.Request) (*http.Response, error) { if p.srv.ProviderPermissions == nil { - return nil, &nonRetriableError{errors.New("method ProviderPermissions not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ProviderPermissions not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/providerPermissions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providerPermissions` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := p.srv.ProviderPermissions(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], nil) + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.ProviderPermissions(req.Context(), resourceProviderNamespaceUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -274,11 +303,11 @@ func (p *ProvidersServerTransport) dispatchProviderPermissions(req *http.Request func (p *ProvidersServerTransport) dispatchRegister(req *http.Request) (*http.Response, error) { if p.srv.Register == nil { - return nil, &nonRetriableError{errors.New("method Register not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Register not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/register" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/register` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -286,13 +315,17 @@ func (p *ProvidersServerTransport) dispatchRegister(req *http.Request) (*http.Re if err != nil { return nil, err } + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } var options *armresources.ProvidersClientRegisterOptions if !reflect.ValueOf(body).IsZero() { options = &armresources.ProvidersClientRegisterOptions{ Properties: &body, } } - respr, errRespr := p.srv.Register(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], options) + respr, errRespr := p.srv.Register(req.Context(), resourceProviderNamespaceUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -309,15 +342,23 @@ func (p *ProvidersServerTransport) dispatchRegister(req *http.Request) (*http.Re func (p *ProvidersServerTransport) dispatchRegisterAtManagementGroupScope(req *http.Request) (*http.Response, error) { if p.srv.RegisterAtManagementGroupScope == nil { - return nil, &nonRetriableError{errors.New("method RegisterAtManagementGroupScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method RegisterAtManagementGroupScope not implemented")} } - const regexStr = "/providers/Microsoft.Management/managementGroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/register" + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/register` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := p.srv.RegisterAtManagementGroupScope(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("groupId")], nil) + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.RegisterAtManagementGroupScope(req.Context(), resourceProviderNamespaceUnescaped, groupIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -334,15 +375,19 @@ func (p *ProvidersServerTransport) dispatchRegisterAtManagementGroupScope(req *h func (p *ProvidersServerTransport) dispatchUnregister(req *http.Request) (*http.Response, error) { if p.srv.Unregister == nil { - return nil, &nonRetriableError{errors.New("method Unregister not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Unregister not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/unregister" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/unregister` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := p.srv.Unregister(req.Context(), matches[regex.SubexpIndex("resourceProviderNamespace")], nil) + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Unregister(req.Context(), resourceProviderNamespaceUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go b/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go index efe6293085c1..7d72d380446e 100644 --- a/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go @@ -18,6 +18,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "regexp" "strconv" ) @@ -108,15 +109,19 @@ func (r *ResourceGroupsServerTransport) Do(req *http.Request) (*http.Response, e func (r *ResourceGroupsServerTransport) dispatchCheckExistence(req *http.Request) (*http.Response, error) { if r.srv.CheckExistence == nil { - return nil, &nonRetriableError{errors.New("method CheckExistence not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistence not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := r.srv.CheckExistence(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CheckExistence(req.Context(), resourceGroupNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,11 +138,11 @@ func (r *ResourceGroupsServerTransport) dispatchCheckExistence(req *http.Request func (r *ResourceGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { if r.srv.CreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method CreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -145,7 +150,11 @@ func (r *ResourceGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request if err != nil { return nil, err } - respr, errRespr := r.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -162,24 +171,32 @@ func (r *ResourceGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request func (r *ResourceGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if r.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if r.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - forceDeletionTypesParam := getOptional(qp.Get("forceDeletionTypes")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + forceDeletionTypesUnescaped, err := url.QueryUnescape(qp.Get("forceDeletionTypes")) + if err != nil { + return nil, err + } + forceDeletionTypesParam := getOptional(forceDeletionTypesUnescaped) var options *armresources.ResourceGroupsClientBeginDeleteOptions if forceDeletionTypesParam != nil { options = &armresources.ResourceGroupsClientBeginDeleteOptions{ ForceDeletionTypes: forceDeletionTypesParam, } } - respr, errRespr := r.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], options) + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -203,12 +220,12 @@ func (r *ResourceGroupsServerTransport) dispatchBeginDelete(req *http.Request) ( func (r *ResourceGroupsServerTransport) dispatchBeginExportTemplate(req *http.Request) (*http.Response, error) { if r.srv.BeginExportTemplate == nil { - return nil, &nonRetriableError{errors.New("method BeginExportTemplate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginExportTemplate not implemented")} } if r.beginExportTemplate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/exportTemplate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -216,7 +233,11 @@ func (r *ResourceGroupsServerTransport) dispatchBeginExportTemplate(req *http.Re if err != nil { return nil, err } - respr, errRespr := r.srv.BeginExportTemplate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginExportTemplate(req.Context(), resourceGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -240,15 +261,19 @@ func (r *ResourceGroupsServerTransport) dispatchBeginExportTemplate(req *http.Re func (r *ResourceGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if r.srv.Get == nil { - return nil, &nonRetriableError{errors.New("method Get not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := r.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -265,18 +290,26 @@ func (r *ResourceGroupsServerTransport) dispatchGet(req *http.Request) (*http.Re func (r *ResourceGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if r.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if r.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -314,11 +347,11 @@ func (r *ResourceGroupsServerTransport) dispatchNewListPager(req *http.Request) func (r *ResourceGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { if r.srv.Update == nil { - return nil, &nonRetriableError{errors.New("method Update not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -326,7 +359,11 @@ func (r *ResourceGroupsServerTransport) dispatchUpdate(req *http.Request) (*http if err != nil { return nil, err } - respr, errRespr := r.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Update(req.Context(), resourceGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/server.go b/sdk/resourcemanager/resources/armresources/fake/server.go index 6def4ade1ab5..b6905a00244a 100644 --- a/sdk/resourcemanager/resources/armresources/fake/server.go +++ b/sdk/resourcemanager/resources/armresources/fake/server.go @@ -18,6 +18,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "regexp" "strconv" ) @@ -157,16 +158,40 @@ func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { func (s *ServerTransport) dispatchCheckExistence(req *http.Request) (*http.Response, error) { if s.srv.CheckExistence == nil { - return nil, &nonRetriableError{errors.New("method CheckExistence not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistence not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 6 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - respr, errRespr := s.srv.CheckExistence(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CheckExistence(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -183,16 +208,24 @@ func (s *ServerTransport) dispatchCheckExistence(req *http.Request) (*http.Respo func (s *ServerTransport) dispatchCheckExistenceByID(req *http.Request) (*http.Response, error) { if s.srv.CheckExistenceByID == nil { - return nil, &nonRetriableError{errors.New("method CheckExistenceByID not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CheckExistenceByID not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - respr, errRespr := s.srv.CheckExistenceByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), nil) + resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CheckExistenceByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -209,12 +242,12 @@ func (s *ServerTransport) dispatchCheckExistenceByID(req *http.Request) (*http.R func (s *ServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if s.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if s.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 6 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -223,7 +256,31 @@ func (s *ServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http. if err != nil { return nil, err } - respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -247,12 +304,12 @@ func (s *ServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http. func (s *ServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*http.Response, error) { if s.srv.BeginCreateOrUpdateByID == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdateByID not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateByID not implemented")} } if s.beginCreateOrUpdateByID == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -261,7 +318,15 @@ func (s *ServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*h if err != nil { return nil, err } - respr, errRespr := s.srv.BeginCreateOrUpdateByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), body, nil) + resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdateByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -285,17 +350,41 @@ func (s *ServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*h func (s *ServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if s.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if s.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 6 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - respr, errRespr := s.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -319,17 +408,25 @@ func (s *ServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response func (s *ServerTransport) dispatchBeginDeleteByID(req *http.Request) (*http.Response, error) { if s.srv.BeginDeleteByID == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteByID not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteByID not implemented")} } if s.beginDeleteByID == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - respr, errRespr := s.srv.BeginDeleteByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), nil) + resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDeleteByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -353,16 +450,40 @@ func (s *ServerTransport) dispatchBeginDeleteByID(req *http.Request) (*http.Resp func (s *ServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if s.srv.Get == nil { - return nil, &nonRetriableError{errors.New("method Get not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 6 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - respr, errRespr := s.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -379,16 +500,24 @@ func (s *ServerTransport) dispatchGet(req *http.Request) (*http.Response, error) func (s *ServerTransport) dispatchGetByID(req *http.Request) (*http.Response, error) { if s.srv.GetByID == nil { - return nil, &nonRetriableError{errors.New("method GetByID not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetByID not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - respr, errRespr := s.srv.GetByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), nil) + resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -405,19 +534,31 @@ func (s *ServerTransport) dispatchGetByID(req *http.Request) (*http.Response, er func (s *ServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if s.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if s.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resources" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resources` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - expandParam := getOptional(qp.Get("$expand")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -456,19 +597,35 @@ func (s *ServerTransport) dispatchNewListPager(req *http.Request) (*http.Respons func (s *ServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if s.srv.NewListByResourceGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } if s.newListByResourceGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/resources" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resources` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - expandParam := getOptional(qp.Get("$expand")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -486,7 +643,7 @@ func (s *ServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) Top: topParam, } } - resp := s.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], options) + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, options) s.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armresources.ClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -507,12 +664,12 @@ func (s *ServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) func (s *ServerTransport) dispatchBeginMoveResources(req *http.Request) (*http.Response, error) { if s.srv.BeginMoveResources == nil { - return nil, &nonRetriableError{errors.New("method BeginMoveResources not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginMoveResources not implemented")} } if s.beginMoveResources == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/moveResources" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/moveResources` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -520,7 +677,11 @@ func (s *ServerTransport) dispatchBeginMoveResources(req *http.Request) (*http.R if err != nil { return nil, err } - respr, errRespr := s.srv.BeginMoveResources(req.Context(), matches[regex.SubexpIndex("sourceResourceGroupName")], body, nil) + sourceResourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sourceResourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginMoveResources(req.Context(), sourceResourceGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -544,12 +705,12 @@ func (s *ServerTransport) dispatchBeginMoveResources(req *http.Request) (*http.R func (s *ServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if s.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if s.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourcegroups/(?P[a-zA-Z0-9-_]+)/providers/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 6 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -558,7 +719,31 @@ func (s *ServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response if err != nil { return nil, err } - respr, errRespr := s.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("resourceProviderNamespace")], matches[regex.SubexpIndex("parentResourcePath")], matches[regex.SubexpIndex("resourceType")], matches[regex.SubexpIndex("resourceName")], qp.Get("api-version"), body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -582,12 +767,12 @@ func (s *ServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response func (s *ServerTransport) dispatchBeginUpdateByID(req *http.Request) (*http.Response, error) { if s.srv.BeginUpdateByID == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdateByID not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateByID not implemented")} } if s.beginUpdateByID == nil { - const regexStr = "/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -596,7 +781,15 @@ func (s *ServerTransport) dispatchBeginUpdateByID(req *http.Request) (*http.Resp if err != nil { return nil, err } - respr, errRespr := s.srv.BeginUpdateByID(req.Context(), matches[regex.SubexpIndex("resourceId")], qp.Get("api-version"), body, nil) + resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + if err != nil { + return nil, err + } + apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdateByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -620,12 +813,12 @@ func (s *ServerTransport) dispatchBeginUpdateByID(req *http.Request) (*http.Resp func (s *ServerTransport) dispatchBeginValidateMoveResources(req *http.Request) (*http.Response, error) { if s.srv.BeginValidateMoveResources == nil { - return nil, &nonRetriableError{errors.New("method BeginValidateMoveResources not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginValidateMoveResources not implemented")} } if s.beginValidateMoveResources == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/validateMoveResources" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validateMoveResources` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -633,7 +826,11 @@ func (s *ServerTransport) dispatchBeginValidateMoveResources(req *http.Request) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginValidateMoveResources(req.Context(), matches[regex.SubexpIndex("sourceResourceGroupName")], body, nil) + sourceResourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sourceResourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginValidateMoveResources(req.Context(), sourceResourceGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/tags_server.go b/sdk/resourcemanager/resources/armresources/fake/tags_server.go index 9350f016692b..e32765315f4b 100644 --- a/sdk/resourcemanager/resources/armresources/fake/tags_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/tags_server.go @@ -18,6 +18,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "net/http" + "net/url" "regexp" ) @@ -117,15 +118,19 @@ func (t *TagsServerTransport) Do(req *http.Request) (*http.Response, error) { func (t *TagsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { if t.srv.CreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method CreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagNames/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := t.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("tagName")], nil) + tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.CreateOrUpdate(req.Context(), tagNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -142,11 +147,11 @@ func (t *TagsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.R func (t *TagsServerTransport) dispatchCreateOrUpdateAtScope(req *http.Request) (*http.Response, error) { if t.srv.CreateOrUpdateAtScope == nil { - return nil, &nonRetriableError{errors.New("method CreateOrUpdateAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -154,7 +159,11 @@ func (t *TagsServerTransport) dispatchCreateOrUpdateAtScope(req *http.Request) ( if err != nil { return nil, err } - respr, errRespr := t.srv.CreateOrUpdateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], body, nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.CreateOrUpdateAtScope(req.Context(), scopeUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -171,15 +180,23 @@ func (t *TagsServerTransport) dispatchCreateOrUpdateAtScope(req *http.Request) ( func (t *TagsServerTransport) dispatchCreateOrUpdateValue(req *http.Request) (*http.Response, error) { if t.srv.CreateOrUpdateValue == nil { - return nil, &nonRetriableError{errors.New("method CreateOrUpdateValue not implemented")} + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateValue not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)/tagValues/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagNames/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagValues/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := t.srv.CreateOrUpdateValue(req.Context(), matches[regex.SubexpIndex("tagName")], matches[regex.SubexpIndex("tagValue")], nil) + tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + if err != nil { + return nil, err + } + tagValueUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagValue")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.CreateOrUpdateValue(req.Context(), tagNameUnescaped, tagValueUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -196,15 +213,19 @@ func (t *TagsServerTransport) dispatchCreateOrUpdateValue(req *http.Request) (*h func (t *TagsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { if t.srv.Delete == nil { - return nil, &nonRetriableError{errors.New("method Delete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagNames/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := t.srv.Delete(req.Context(), matches[regex.SubexpIndex("tagName")], nil) + tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.Delete(req.Context(), tagNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -221,15 +242,19 @@ func (t *TagsServerTransport) dispatchDelete(req *http.Request) (*http.Response, func (t *TagsServerTransport) dispatchDeleteAtScope(req *http.Request) (*http.Response, error) { if t.srv.DeleteAtScope == nil { - return nil, &nonRetriableError{errors.New("method DeleteAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method DeleteAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := t.srv.DeleteAtScope(req.Context(), matches[regex.SubexpIndex("scope")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.DeleteAtScope(req.Context(), scopeUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -246,15 +271,23 @@ func (t *TagsServerTransport) dispatchDeleteAtScope(req *http.Request) (*http.Re func (t *TagsServerTransport) dispatchDeleteValue(req *http.Request) (*http.Response, error) { if t.srv.DeleteValue == nil { - return nil, &nonRetriableError{errors.New("method DeleteValue not implemented")} + return nil, &nonRetriableError{errors.New("fake for method DeleteValue not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames/(?P[a-zA-Z0-9-_]+)/tagValues/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagNames/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagValues/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := t.srv.DeleteValue(req.Context(), matches[regex.SubexpIndex("tagName")], matches[regex.SubexpIndex("tagValue")], nil) + tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + if err != nil { + return nil, err + } + tagValueUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagValue")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.DeleteValue(req.Context(), tagNameUnescaped, tagValueUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -271,15 +304,19 @@ func (t *TagsServerTransport) dispatchDeleteValue(req *http.Request) (*http.Resp func (t *TagsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) { if t.srv.GetAtScope == nil { - return nil, &nonRetriableError{errors.New("method GetAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := t.srv.GetAtScope(req.Context(), matches[regex.SubexpIndex("scope")], nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.GetAtScope(req.Context(), scopeUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -296,12 +333,12 @@ func (t *TagsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Respo func (t *TagsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if t.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if t.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/tagNames" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tagNames` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -326,11 +363,11 @@ func (t *TagsServerTransport) dispatchNewListPager(req *http.Request) (*http.Res func (t *TagsServerTransport) dispatchUpdateAtScope(req *http.Request) (*http.Response, error) { if t.srv.UpdateAtScope == nil { - return nil, &nonRetriableError{errors.New("method UpdateAtScope not implemented")} + return nil, &nonRetriableError{errors.New("fake for method UpdateAtScope not implemented")} } - const regexStr = "/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Resources/tags/default" + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -338,7 +375,11 @@ func (t *TagsServerTransport) dispatchUpdateAtScope(req *http.Request) (*http.Re if err != nil { return nil, err } - respr, errRespr := t.srv.UpdateAtScope(req.Context(), matches[regex.SubexpIndex("scope")], body, nil) + scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.UpdateAtScope(req.Context(), scopeUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake_example_test.go b/sdk/resourcemanager/resources/armresources/fake_example_test.go new file mode 100644 index 000000000000..9c4d23e95339 --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake_example_test.go @@ -0,0 +1,74 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package armresources_test + +import ( + "context" + "fmt" + "log" + "net/http" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources/fake" +) + +func ExampleServer() { + // first, create an instance of the fake server for the client you wish to test. + // the type name of the server will be similar to the corresponding client, with + // the suffix "Server" instead of "Client". + fakeServer := fake.Server{ + + // next, provide implementations for the APIs you wish to fake. + // this fake corresponds to the Client.CheckExistence() API. + CheckExistence: func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *armresources.ClientCheckExistenceOptions) (resp azfake.Responder[armresources.ClientCheckExistenceResponse], errResp azfake.ErrorResponder) { + // the values of ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion, and options come from the API call. + + // the named return values resp and errResp are used to construct the response + // and are meant to be mutually exclusive. if both responses have been constructed, + // the error response is selected. + + // use resp to set the desired response + resp.SetResponse(http.StatusNoContent, armresources.ClientCheckExistenceResponse{Success: true}, nil) + + // to simulate the failure case, use errResp + //errResp.SetResponseError(http.StatusBadRequest, "ThisIsASimulatedError") + + return + }, + } + + // now create the corresponding client, connecting the fake server via the client options + client, err := armresources.NewClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewServerTransport(&fakeServer), + }, + }) + if err != nil { + log.Fatal(err) + } + + // call the API. the provided values will be passed to the fake's implementation. + // the response or error values returned by the API call are from the fake. + resp, err := client.CheckExistence(context.TODO(), "fakeResourceGroup", "fakeProvider", "fakeParent", "fakeType", "fakeResource", "fakeAPIVersion", nil) + if err != nil { + log.Fatal(err) + } + + fmt.Println(resp.Success) + + // APIs that haven't been faked will return an error + _, err = client.Get(context.TODO(), "fakeResourceGroup", "fakeProvider", "fakeParent", "fakeType", "fakeResource", "fakeAPIVersion", nil) + + fmt.Println(err.Error()) + + // Output: + // true + // fake for method Get not implemented +}