From 35eea44fd258e87577bbd901a7bd65f15d438e8e Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 8 Jun 2023 08:16:29 -0700 Subject: [PATCH 1/4] armcompute 5.1.0-beta.1 release Includes updated codegen for fakes and trace spans. --- .../compute/armcompute/CHANGELOG.md | 6 + .../compute/armcompute/README.md | 34 + .../compute/armcompute/autorest.md | 7 +- .../armcompute/availabilitysets_client.go | 76 +- .../compute/armcompute/build.go | 2 +- .../capacityreservationgroups_client.go | 74 +- .../armcompute/capacityreservations_client.go | 81 +- .../compute/armcompute/client_factory.go | 3 +- .../cloudserviceoperatingsystems_client.go | 37 +- .../cloudserviceroleinstances_client.go | 117 +- .../armcompute/cloudserviceroles_client.go | 20 +- .../armcompute/cloudservices_client.go | 220 +++- .../cloudservicesupdatedomain_client.go | 42 +- .../armcompute/communitygalleries_client.go | 18 +- .../communitygalleryimages_client.go | 20 +- .../communitygalleryimageversions_client.go | 20 +- .../compute/armcompute/constants.go | 61 +- .../armcompute/dedicatedhostgroups_client.go | 74 +- .../armcompute/dedicatedhosts_client.go | 100 +- .../compute/armcompute/diskaccesses_client.go | 154 ++- .../armcompute/diskencryptionsets_client.go | 85 +- .../armcompute/diskrestorepoint_client.go | 59 +- .../compute/armcompute/disks_client.go | 122 +- .../fake/availabilitysets_server.go | 309 +++++ .../fake/capacityreservationgroups_server.go | 291 +++++ .../fake/capacityreservations_server.go | 265 ++++ .../cloudserviceoperatingsystems_server.go | 197 +++ .../fake/cloudserviceroleinstances_server.go | 370 ++++++ .../fake/cloudserviceroles_server.go | 129 ++ .../armcompute/fake/cloudservices_server.go | 606 +++++++++ .../fake/cloudservicesupdatedomain_server.go | 194 +++ .../fake/communitygalleries_server.go | 91 ++ .../fake/communitygalleryimages_server.go | 129 ++ .../communitygalleryimageversions_server.go | 129 ++ .../fake/dedicatedhostgroups_server.go | 275 ++++ .../armcompute/fake/dedicatedhosts_server.go | 339 +++++ .../armcompute/fake/diskaccesses_server.go | 477 +++++++ .../fake/diskencryptionsets_server.go | 331 +++++ .../fake/diskrestorepoint_server.go | 213 +++ .../compute/armcompute/fake/disks_server.go | 378 ++++++ .../armcompute/fake/galleries_server.go | 304 +++++ .../fake/galleryapplications_server.go | 257 ++++ .../fake/galleryapplicationversions_server.go | 265 ++++ .../armcompute/fake/galleryimages_server.go | 257 ++++ .../fake/galleryimageversions_server.go | 265 ++++ .../fake/gallerysharingprofile_server.go | 104 ++ .../compute/armcompute/fake/images_server.go | 302 +++++ .../compute/armcompute/fake/internal.go | 78 ++ .../armcompute/fake/loganalytics_server.go | 148 +++ .../armcompute/fake/operations_server.go | 86 ++ .../fake/proximityplacementgroups_server.go | 275 ++++ .../armcompute/fake/resourceskus_server.go | 107 ++ .../fake/restorepointcollections_server.go | 284 ++++ .../armcompute/fake/restorepoints_server.go | 183 +++ .../armcompute/fake/sharedgalleries_server.go | 137 ++ .../fake/sharedgalleryimages_server.go | 137 ++ .../fake/sharedgalleryimageversions_server.go | 137 ++ .../armcompute/fake/snapshots_server.go | 378 ++++++ .../armcompute/fake/sshpublickeys_server.go | 298 +++++ .../compute/armcompute/fake/time_rfc3339.go | 86 ++ .../compute/armcompute/fake/usage_server.go | 97 ++ .../virtualmachineextensionimages_server.go | 175 +++ .../fake/virtualmachineextensions_server.go | 266 ++++ .../fake/virtualmachineimages_server.go | 268 ++++ .../virtualmachineimagesedgezone_server.go | 237 ++++ .../fake/virtualmachineruncommands_server.go | 341 +++++ .../armcompute/fake/virtualmachines_server.go | 1113 ++++++++++++++++ ...virtualmachinescalesetextensions_server.go | 265 ++++ ...almachinescalesetrollingupgrades_server.go | 211 +++ .../fake/virtualmachinescalesets_server.go | 1138 +++++++++++++++++ ...rtualmachinescalesetvmextensions_server.go | 266 ++++ ...tualmachinescalesetvmruncommands_server.go | 273 ++++ .../fake/virtualmachinescalesetvms_server.go | 741 +++++++++++ .../fake/virtualmachinesizes_server.go | 93 ++ .../compute/armcompute/galleries_client.go | 83 +- .../armcompute/galleryapplications_client.go | 81 +- .../galleryapplicationversions_client.go | 81 +- .../armcompute/galleryimages_client.go | 81 +- .../armcompute/galleryimageversions_client.go | 81 +- .../gallerysharingprofile_client.go | 25 +- sdk/resourcemanager/compute/armcompute/go.mod | 10 +- sdk/resourcemanager/compute/armcompute/go.sum | 20 +- .../compute/armcompute/images_client.go | 83 +- .../compute/armcompute/loganalytics_client.go | 47 +- .../compute/armcompute/models.go | 3 +- .../compute/armcompute/models_serde.go | 3 +- .../compute/armcompute/operations_client.go | 5 +- .../proximityplacementgroups_client.go | 74 +- .../compute/armcompute/resourceskus_client.go | 5 +- .../compute/armcompute/response_types.go | 3 +- .../restorepointcollections_client.go | 79 +- .../armcompute/restorepoints_client.go | 57 +- .../armcompute/sharedgalleries_client.go | 20 +- .../armcompute/sharedgalleryimages_client.go | 20 +- .../sharedgalleryimageversions_client.go | 20 +- .../compute/armcompute/snapshots_client.go | 122 +- .../armcompute/sshpublickeys_client.go | 89 +- .../compute/armcompute/time_rfc3339.go | 3 +- .../compute/armcompute/usage_client.go | 5 +- .../virtualmachineextensionimages_client.go | 48 +- .../virtualmachineextensions_client.go | 94 +- .../armcompute/virtualmachineimages_client.go | 93 +- .../virtualmachineimagesedgezone_client.go | 78 +- .../virtualmachineruncommands_client.go | 98 +- .../armcompute/virtualmachines_client.go | 382 ++++-- ...virtualmachinescalesetextensions_client.go | 81 +- ...almachinescalesetrollingupgrades_client.go | 69 +- .../virtualmachinescalesets_client.go | 395 ++++-- ...rtualmachinescalesetvmextensions_client.go | 94 +- ...tualmachinescalesetvmruncommands_client.go | 81 +- .../virtualmachinescalesetvms_client.go | 264 ++-- .../armcompute/virtualmachinesizes_client.go | 5 +- 112 files changed, 17388 insertions(+), 1221 deletions(-) create mode 100644 sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/disks_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/galleries_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/images_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/internal.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/loganalytics_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/operations_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/proximityplacementgroups_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/usage_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go create mode 100644 sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go diff --git a/sdk/resourcemanager/compute/armcompute/CHANGELOG.md b/sdk/resourcemanager/compute/armcompute/CHANGELOG.md index fe4dc2d06414..a2f0160a36b1 100644 --- a/sdk/resourcemanager/compute/armcompute/CHANGELOG.md +++ b/sdk/resourcemanager/compute/armcompute/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 5.1.0-beta.1 (2023-06-08) + +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + ## 5.0.0 (2023-05-26) ### Breaking Changes diff --git a/sdk/resourcemanager/compute/armcompute/README.md b/sdk/resourcemanager/compute/armcompute/README.md index 39f86b0b9987..c2d2b8a83c58 100644 --- a/sdk/resourcemanager/compute/armcompute/README.md +++ b/sdk/resourcemanager/compute/armcompute/README.md @@ -60,6 +60,40 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewLogAnalyticsClient() ``` +## 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 +myFakeAvailabilitySetsServer := fake.AvailabilitySetsServer{} +``` + +Next, provide func implementations for the methods you wish to fake. +The named return variables can be used to simplify return value construction. + +```go +myFakeAvailabilitySetsServer.Get = func(ctx context.Context, resourceGroupName string, availabilitySetName string, options *armcompute.AvailabilitySetsClientGetOptions) (resp azfake.Responder[armcompute.AvailabilitySetsClientGetResponse], err azfake.ErrorResponder) { + // TODO: resp.SetResponse(/* your fake AvailabilitySetsClientGetResponse 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 := armcompute.NewAvailabilitySetsClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewAvailabilitySetsServerTransport(&myFakeAvailabilitySetsServer), + }, +}) +``` + ## More sample code - [Availability Set](https://aka.ms/azsdk/go/mgmt/samples?path=sdk/resourcemanager/compute/availabilityset) diff --git a/sdk/resourcemanager/compute/armcompute/autorest.md b/sdk/resourcemanager/compute/armcompute/autorest.md index fbff785e9a4d..7968ec9e4fa5 100644 --- a/sdk/resourcemanager/compute/armcompute/autorest.md +++ b/sdk/resourcemanager/compute/armcompute/autorest.md @@ -8,6 +8,9 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/5d2adf9b7fda669b4a2538c65e937ee74fe3f966/specification/compute/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/5d2adf9b7fda669b4a2538c65e937ee74fe3f966/specification/compute/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 5.0.0 +module-version: 5.1.0-beta.1 tag: package-2023-03-01 -``` \ No newline at end of file +azcore-version: 1.7.0-beta.2 +generate-fakes: true +inject-spans: true +``` diff --git a/sdk/resourcemanager/compute/armcompute/availabilitysets_client.go b/sdk/resourcemanager/compute/armcompute/availabilitysets_client.go index a6d6d2e44a95..ec501cdba333 100644 --- a/sdk/resourcemanager/compute/armcompute/availabilitysets_client.go +++ b/sdk/resourcemanager/compute/armcompute/availabilitysets_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 armcompute @@ -55,18 +54,25 @@ func NewAvailabilitySetsClient(subscriptionID string, credential azcore.TokenCre // - options - AvailabilitySetsClientCreateOrUpdateOptions contains the optional parameters for the AvailabilitySetsClient.CreateOrUpdate // method. func (client *AvailabilitySetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters AvailabilitySet, options *AvailabilitySetsClientCreateOrUpdateOptions) (AvailabilitySetsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "AvailabilitySetsClient.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, availabilitySetName, parameters, options) if err != nil { return AvailabilitySetsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AvailabilitySetsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AvailabilitySetsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return AvailabilitySetsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -92,7 +98,10 @@ func (client *AvailabilitySetsClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2023-03-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. @@ -112,16 +121,22 @@ func (client *AvailabilitySetsClient) createOrUpdateHandleResponse(resp *http.Re // - availabilitySetName - The name of the availability set. // - options - AvailabilitySetsClientDeleteOptions contains the optional parameters for the AvailabilitySetsClient.Delete method. func (client *AvailabilitySetsClient) Delete(ctx context.Context, resourceGroupName string, availabilitySetName string, options *AvailabilitySetsClientDeleteOptions) (AvailabilitySetsClientDeleteResponse, error) { + var err error + const operationName = "AvailabilitySetsClient.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, resourceGroupName, availabilitySetName, options) if err != nil { return AvailabilitySetsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AvailabilitySetsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return AvailabilitySetsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return AvailabilitySetsClientDeleteResponse{}, err } return AvailabilitySetsClientDeleteResponse{}, nil } @@ -160,18 +175,25 @@ func (client *AvailabilitySetsClient) deleteCreateRequest(ctx context.Context, r // - availabilitySetName - The name of the availability set. // - options - AvailabilitySetsClientGetOptions contains the optional parameters for the AvailabilitySetsClient.Get method. func (client *AvailabilitySetsClient) Get(ctx context.Context, resourceGroupName string, availabilitySetName string, options *AvailabilitySetsClientGetOptions) (AvailabilitySetsClientGetResponse, error) { + var err error + const operationName = "AvailabilitySetsClient.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, availabilitySetName, options) if err != nil { return AvailabilitySetsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AvailabilitySetsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AvailabilitySetsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return AvailabilitySetsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -221,6 +243,7 @@ func (client *AvailabilitySetsClient) NewListPager(resourceGroupName string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailabilitySetsClientListResponse) (AvailabilitySetsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailabilitySetsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -240,6 +263,7 @@ func (client *AvailabilitySetsClient) NewListPager(resourceGroupName string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -288,6 +312,7 @@ func (client *AvailabilitySetsClient) NewListAvailableSizesPager(resourceGroupNa return false }, Fetcher: func(ctx context.Context, page *AvailabilitySetsClientListAvailableSizesResponse) (AvailabilitySetsClientListAvailableSizesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailabilitySetsClient.NewListAvailableSizesPager") req, err := client.listAvailableSizesCreateRequest(ctx, resourceGroupName, availabilitySetName, options) if err != nil { return AvailabilitySetsClientListAvailableSizesResponse{}, err @@ -301,6 +326,7 @@ func (client *AvailabilitySetsClient) NewListAvailableSizesPager(resourceGroupNa } return client.listAvailableSizesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -350,6 +376,7 @@ func (client *AvailabilitySetsClient) NewListBySubscriptionPager(options *Availa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailabilitySetsClientListBySubscriptionResponse) (AvailabilitySetsClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailabilitySetsClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -369,6 +396,7 @@ func (client *AvailabilitySetsClient) NewListBySubscriptionPager(options *Availa } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -411,18 +439,25 @@ func (client *AvailabilitySetsClient) listBySubscriptionHandleResponse(resp *htt // - parameters - Parameters supplied to the Update Availability Set operation. // - options - AvailabilitySetsClientUpdateOptions contains the optional parameters for the AvailabilitySetsClient.Update method. func (client *AvailabilitySetsClient) Update(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters AvailabilitySetUpdate, options *AvailabilitySetsClientUpdateOptions) (AvailabilitySetsClientUpdateResponse, error) { + var err error + const operationName = "AvailabilitySetsClient.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, availabilitySetName, parameters, options) if err != nil { return AvailabilitySetsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AvailabilitySetsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AvailabilitySetsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return AvailabilitySetsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -448,7 +483,10 @@ func (client *AvailabilitySetsClient) updateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2023-03-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/compute/armcompute/build.go b/sdk/resourcemanager/compute/armcompute/build.go index f88d006f4fbb..6dea5eecf48f 100644 --- a/sdk/resourcemanager/compute/armcompute/build.go +++ b/sdk/resourcemanager/compute/armcompute/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 -alwaysSetBodyParamRequired resourcemanager/compute/armcompute +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.50" -skipBuild -cleanGenerated -format -tidy -generate -alwaysSetBodyParamRequired resourcemanager/compute/armcompute package armcompute diff --git a/sdk/resourcemanager/compute/armcompute/capacityreservationgroups_client.go b/sdk/resourcemanager/compute/armcompute/capacityreservationgroups_client.go index 858a01cb4c2e..490b8735b782 100644 --- a/sdk/resourcemanager/compute/armcompute/capacityreservationgroups_client.go +++ b/sdk/resourcemanager/compute/armcompute/capacityreservationgroups_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 armcompute @@ -57,18 +56,25 @@ func NewCapacityReservationGroupsClient(subscriptionID string, credential azcore // - options - CapacityReservationGroupsClientCreateOrUpdateOptions contains the optional parameters for the CapacityReservationGroupsClient.CreateOrUpdate // method. func (client *CapacityReservationGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, parameters CapacityReservationGroup, options *CapacityReservationGroupsClientCreateOrUpdateOptions) (CapacityReservationGroupsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "CapacityReservationGroupsClient.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, capacityReservationGroupName, parameters, options) if err != nil { return CapacityReservationGroupsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CapacityReservationGroupsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return CapacityReservationGroupsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return CapacityReservationGroupsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -94,7 +100,10 @@ func (client *CapacityReservationGroupsClient) createOrUpdateCreateRequest(ctx c reqQP.Set("api-version", "2023-03-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. @@ -117,16 +126,22 @@ func (client *CapacityReservationGroupsClient) createOrUpdateHandleResponse(resp // - options - CapacityReservationGroupsClientDeleteOptions contains the optional parameters for the CapacityReservationGroupsClient.Delete // method. func (client *CapacityReservationGroupsClient) Delete(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, options *CapacityReservationGroupsClientDeleteOptions) (CapacityReservationGroupsClientDeleteResponse, error) { + var err error + const operationName = "CapacityReservationGroupsClient.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, resourceGroupName, capacityReservationGroupName, options) if err != nil { return CapacityReservationGroupsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CapacityReservationGroupsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return CapacityReservationGroupsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return CapacityReservationGroupsClientDeleteResponse{}, err } return CapacityReservationGroupsClientDeleteResponse{}, nil } @@ -166,18 +181,25 @@ func (client *CapacityReservationGroupsClient) deleteCreateRequest(ctx context.C // - options - CapacityReservationGroupsClientGetOptions contains the optional parameters for the CapacityReservationGroupsClient.Get // method. func (client *CapacityReservationGroupsClient) Get(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, options *CapacityReservationGroupsClientGetOptions) (CapacityReservationGroupsClientGetResponse, error) { + var err error + const operationName = "CapacityReservationGroupsClient.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, capacityReservationGroupName, options) if err != nil { return CapacityReservationGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CapacityReservationGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CapacityReservationGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CapacityReservationGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -231,6 +253,7 @@ func (client *CapacityReservationGroupsClient) NewListByResourceGroupPager(resou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CapacityReservationGroupsClientListByResourceGroupResponse) (CapacityReservationGroupsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CapacityReservationGroupsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -250,6 +273,7 @@ func (client *CapacityReservationGroupsClient) NewListByResourceGroupPager(resou } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -299,6 +323,7 @@ func (client *CapacityReservationGroupsClient) NewListBySubscriptionPager(option return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CapacityReservationGroupsClientListBySubscriptionResponse) (CapacityReservationGroupsClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CapacityReservationGroupsClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -318,6 +343,7 @@ func (client *CapacityReservationGroupsClient) NewListBySubscriptionPager(option } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -362,18 +388,25 @@ func (client *CapacityReservationGroupsClient) listBySubscriptionHandleResponse( // - options - CapacityReservationGroupsClientUpdateOptions contains the optional parameters for the CapacityReservationGroupsClient.Update // method. func (client *CapacityReservationGroupsClient) Update(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, parameters CapacityReservationGroupUpdate, options *CapacityReservationGroupsClientUpdateOptions) (CapacityReservationGroupsClientUpdateResponse, error) { + var err error + const operationName = "CapacityReservationGroupsClient.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, capacityReservationGroupName, parameters, options) if err != nil { return CapacityReservationGroupsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CapacityReservationGroupsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CapacityReservationGroupsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CapacityReservationGroupsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -399,7 +432,10 @@ func (client *CapacityReservationGroupsClient) updateCreateRequest(ctx context.C reqQP.Set("api-version", "2023-03-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/compute/armcompute/capacityreservations_client.go b/sdk/resourcemanager/compute/armcompute/capacityreservations_client.go index d814ac925d86..66ce229c7084 100644 --- a/sdk/resourcemanager/compute/armcompute/capacityreservations_client.go +++ b/sdk/resourcemanager/compute/armcompute/capacityreservations_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 armcompute @@ -63,7 +62,8 @@ func (client *CapacityReservationsClient) BeginCreateOrUpdate(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller[CapacityReservationsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CapacityReservationsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CapacityReservationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -76,18 +76,24 @@ func (client *CapacityReservationsClient) BeginCreateOrUpdate(ctx context.Contex // // Generated from API version 2023-03-01 func (client *CapacityReservationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, parameters CapacityReservation, options *CapacityReservationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "CapacityReservationsClient.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, capacityReservationGroupName, capacityReservationName, 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. @@ -117,7 +123,10 @@ func (client *CapacityReservationsClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2023-03-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 - The operation to delete a capacity reservation. This operation is allowed only when all the associated resources @@ -137,7 +146,8 @@ func (client *CapacityReservationsClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller[CapacityReservationsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CapacityReservationsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CapacityReservationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -150,18 +160,24 @@ func (client *CapacityReservationsClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2023-03-01 func (client *CapacityReservationsClient) deleteOperation(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, options *CapacityReservationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "CapacityReservationsClient.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, capacityReservationGroupName, capacityReservationName, 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. @@ -204,18 +220,25 @@ func (client *CapacityReservationsClient) deleteCreateRequest(ctx context.Contex // - options - CapacityReservationsClientGetOptions contains the optional parameters for the CapacityReservationsClient.Get // method. func (client *CapacityReservationsClient) Get(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, options *CapacityReservationsClientGetOptions) (CapacityReservationsClientGetResponse, error) { + var err error + const operationName = "CapacityReservationsClient.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, capacityReservationGroupName, capacityReservationName, options) if err != nil { return CapacityReservationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CapacityReservationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CapacityReservationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CapacityReservationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -274,6 +297,7 @@ func (client *CapacityReservationsClient) NewListByCapacityReservationGroupPager return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CapacityReservationsClientListByCapacityReservationGroupResponse) (CapacityReservationsClientListByCapacityReservationGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CapacityReservationsClient.NewListByCapacityReservationGroupPager") var req *policy.Request var err error if page == nil { @@ -293,6 +317,7 @@ func (client *CapacityReservationsClient) NewListByCapacityReservationGroupPager } return client.listByCapacityReservationGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -347,7 +372,8 @@ func (client *CapacityReservationsClient) BeginUpdate(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller[CapacityReservationsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CapacityReservationsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CapacityReservationsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -358,18 +384,24 @@ func (client *CapacityReservationsClient) BeginUpdate(ctx context.Context, resou // // Generated from API version 2023-03-01 func (client *CapacityReservationsClient) update(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, parameters CapacityReservationUpdate, options *CapacityReservationsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "CapacityReservationsClient.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, capacityReservationGroupName, capacityReservationName, 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. @@ -399,5 +431,8 @@ func (client *CapacityReservationsClient) updateCreateRequest(ctx context.Contex reqQP.Set("api-version", "2023-03-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/compute/armcompute/client_factory.go b/sdk/resourcemanager/compute/armcompute/client_factory.go index 3942d46fca2a..adad45461335 100644 --- a/sdk/resourcemanager/compute/armcompute/client_factory.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute diff --git a/sdk/resourcemanager/compute/armcompute/cloudserviceoperatingsystems_client.go b/sdk/resourcemanager/compute/armcompute/cloudserviceoperatingsystems_client.go index 6f3f88dae2d7..f8f69c96b9f7 100644 --- a/sdk/resourcemanager/compute/armcompute/cloudserviceoperatingsystems_client.go +++ b/sdk/resourcemanager/compute/armcompute/cloudserviceoperatingsystems_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 armcompute @@ -55,18 +54,25 @@ func NewCloudServiceOperatingSystemsClient(subscriptionID string, credential azc // - options - CloudServiceOperatingSystemsClientGetOSFamilyOptions contains the optional parameters for the CloudServiceOperatingSystemsClient.GetOSFamily // method. func (client *CloudServiceOperatingSystemsClient) GetOSFamily(ctx context.Context, location string, osFamilyName string, options *CloudServiceOperatingSystemsClientGetOSFamilyOptions) (CloudServiceOperatingSystemsClientGetOSFamilyResponse, error) { + var err error + const operationName = "CloudServiceOperatingSystemsClient.GetOSFamily" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getOSFamilyCreateRequest(ctx, location, osFamilyName, options) if err != nil { return CloudServiceOperatingSystemsClientGetOSFamilyResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServiceOperatingSystemsClientGetOSFamilyResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServiceOperatingSystemsClientGetOSFamilyResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServiceOperatingSystemsClientGetOSFamilyResponse{}, err } - return client.getOSFamilyHandleResponse(resp) + resp, err := client.getOSFamilyHandleResponse(httpResp) + return resp, err } // getOSFamilyCreateRequest creates the GetOSFamily request. @@ -114,18 +120,25 @@ func (client *CloudServiceOperatingSystemsClient) getOSFamilyHandleResponse(resp // - options - CloudServiceOperatingSystemsClientGetOSVersionOptions contains the optional parameters for the CloudServiceOperatingSystemsClient.GetOSVersion // method. func (client *CloudServiceOperatingSystemsClient) GetOSVersion(ctx context.Context, location string, osVersionName string, options *CloudServiceOperatingSystemsClientGetOSVersionOptions) (CloudServiceOperatingSystemsClientGetOSVersionResponse, error) { + var err error + const operationName = "CloudServiceOperatingSystemsClient.GetOSVersion" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getOSVersionCreateRequest(ctx, location, osVersionName, options) if err != nil { return CloudServiceOperatingSystemsClientGetOSVersionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServiceOperatingSystemsClientGetOSVersionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServiceOperatingSystemsClientGetOSVersionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServiceOperatingSystemsClientGetOSVersionResponse{}, err } - return client.getOSVersionHandleResponse(resp) + resp, err := client.getOSVersionHandleResponse(httpResp) + return resp, err } // getOSVersionCreateRequest creates the GetOSVersion request. @@ -177,6 +190,7 @@ func (client *CloudServiceOperatingSystemsClient) NewListOSFamiliesPager(locatio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServiceOperatingSystemsClientListOSFamiliesResponse) (CloudServiceOperatingSystemsClientListOSFamiliesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServiceOperatingSystemsClient.NewListOSFamiliesPager") var req *policy.Request var err error if page == nil { @@ -196,6 +210,7 @@ func (client *CloudServiceOperatingSystemsClient) NewListOSFamiliesPager(locatio } return client.listOSFamiliesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -244,6 +259,7 @@ func (client *CloudServiceOperatingSystemsClient) NewListOSVersionsPager(locatio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServiceOperatingSystemsClientListOSVersionsResponse) (CloudServiceOperatingSystemsClientListOSVersionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServiceOperatingSystemsClient.NewListOSVersionsPager") var req *policy.Request var err error if page == nil { @@ -263,6 +279,7 @@ func (client *CloudServiceOperatingSystemsClient) NewListOSVersionsPager(locatio } return client.listOSVersionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/cloudserviceroleinstances_client.go b/sdk/resourcemanager/compute/armcompute/cloudserviceroleinstances_client.go index 603191776b15..f368b3a9843e 100644 --- a/sdk/resourcemanager/compute/armcompute/cloudserviceroleinstances_client.go +++ b/sdk/resourcemanager/compute/armcompute/cloudserviceroleinstances_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 armcompute @@ -60,7 +59,8 @@ func (client *CloudServiceRoleInstancesClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[CloudServiceRoleInstancesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServiceRoleInstancesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServiceRoleInstancesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -71,18 +71,24 @@ func (client *CloudServiceRoleInstancesClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-09-04 func (client *CloudServiceRoleInstancesClient) deleteOperation(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.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, roleInstanceName, resourceGroupName, cloudServiceName, 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. @@ -125,18 +131,25 @@ func (client *CloudServiceRoleInstancesClient) deleteCreateRequest(ctx context.C // - options - CloudServiceRoleInstancesClientGetOptions contains the optional parameters for the CloudServiceRoleInstancesClient.Get // method. func (client *CloudServiceRoleInstancesClient) Get(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientGetOptions) (CloudServiceRoleInstancesClientGetResponse, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.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, roleInstanceName, resourceGroupName, cloudServiceName, options) if err != nil { return CloudServiceRoleInstancesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServiceRoleInstancesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServiceRoleInstancesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServiceRoleInstancesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -191,18 +204,25 @@ func (client *CloudServiceRoleInstancesClient) getHandleResponse(resp *http.Resp // - options - CloudServiceRoleInstancesClientGetInstanceViewOptions contains the optional parameters for the CloudServiceRoleInstancesClient.GetInstanceView // method. func (client *CloudServiceRoleInstancesClient) GetInstanceView(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientGetInstanceViewOptions) (CloudServiceRoleInstancesClientGetInstanceViewResponse, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.GetInstanceView" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getInstanceViewCreateRequest(ctx, roleInstanceName, resourceGroupName, cloudServiceName, options) if err != nil { return CloudServiceRoleInstancesClientGetInstanceViewResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServiceRoleInstancesClientGetInstanceViewResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServiceRoleInstancesClientGetInstanceViewResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServiceRoleInstancesClientGetInstanceViewResponse{}, err } - return client.getInstanceViewHandleResponse(resp) + resp, err := client.getInstanceViewHandleResponse(httpResp) + return resp, err } // getInstanceViewCreateRequest creates the GetInstanceView request. @@ -254,18 +274,24 @@ func (client *CloudServiceRoleInstancesClient) getInstanceViewHandleResponse(res // - options - CloudServiceRoleInstancesClientGetRemoteDesktopFileOptions contains the optional parameters for the CloudServiceRoleInstancesClient.GetRemoteDesktopFile // method. func (client *CloudServiceRoleInstancesClient) GetRemoteDesktopFile(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientGetRemoteDesktopFileOptions) (CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.GetRemoteDesktopFile" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getRemoteDesktopFileCreateRequest(ctx, roleInstanceName, resourceGroupName, cloudServiceName, options) if err != nil { return CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse{}, err } - return CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse{Body: resp.Body}, nil + return CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse{Body: httpResp.Body}, nil } // getRemoteDesktopFileCreateRequest creates the GetRemoteDesktopFile request. @@ -313,6 +339,7 @@ func (client *CloudServiceRoleInstancesClient) NewListPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServiceRoleInstancesClientListResponse) (CloudServiceRoleInstancesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServiceRoleInstancesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -332,6 +359,7 @@ func (client *CloudServiceRoleInstancesClient) NewListPager(resourceGroupName st } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -390,7 +418,8 @@ func (client *CloudServiceRoleInstancesClient) BeginRebuild(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[CloudServiceRoleInstancesClientRebuildResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServiceRoleInstancesClientRebuildResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServiceRoleInstancesClientRebuildResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -403,18 +432,24 @@ func (client *CloudServiceRoleInstancesClient) BeginRebuild(ctx context.Context, // // Generated from API version 2022-09-04 func (client *CloudServiceRoleInstancesClient) rebuild(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientBeginRebuildOptions) (*http.Response, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.BeginRebuild" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.rebuildCreateRequest(ctx, roleInstanceName, resourceGroupName, cloudServiceName, 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 } // rebuildCreateRequest creates the Rebuild request. @@ -463,7 +498,8 @@ func (client *CloudServiceRoleInstancesClient) BeginReimage(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[CloudServiceRoleInstancesClientReimageResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServiceRoleInstancesClientReimageResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServiceRoleInstancesClientReimageResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -475,18 +511,24 @@ func (client *CloudServiceRoleInstancesClient) BeginReimage(ctx context.Context, // // Generated from API version 2022-09-04 func (client *CloudServiceRoleInstancesClient) reimage(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientBeginReimageOptions) (*http.Response, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.BeginReimage" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageCreateRequest(ctx, roleInstanceName, resourceGroupName, cloudServiceName, 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 } // reimageCreateRequest creates the Reimage request. @@ -534,7 +576,8 @@ func (client *CloudServiceRoleInstancesClient) BeginRestart(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[CloudServiceRoleInstancesClientRestartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServiceRoleInstancesClientRestartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServiceRoleInstancesClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -545,18 +588,24 @@ func (client *CloudServiceRoleInstancesClient) BeginRestart(ctx context.Context, // // Generated from API version 2022-09-04 func (client *CloudServiceRoleInstancesClient) restart(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRoleInstancesClientBeginRestartOptions) (*http.Response, error) { + var err error + const operationName = "CloudServiceRoleInstancesClient.BeginRestart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.restartCreateRequest(ctx, roleInstanceName, resourceGroupName, cloudServiceName, 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 } // restartCreateRequest creates the Restart request. diff --git a/sdk/resourcemanager/compute/armcompute/cloudserviceroles_client.go b/sdk/resourcemanager/compute/armcompute/cloudserviceroles_client.go index 926dd8d21b2b..79bd318495c8 100644 --- a/sdk/resourcemanager/compute/armcompute/cloudserviceroles_client.go +++ b/sdk/resourcemanager/compute/armcompute/cloudserviceroles_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 armcompute @@ -54,18 +53,25 @@ func NewCloudServiceRolesClient(subscriptionID string, credential azcore.TokenCr // - cloudServiceName - Name of the cloud service. // - options - CloudServiceRolesClientGetOptions contains the optional parameters for the CloudServiceRolesClient.Get method. func (client *CloudServiceRolesClient) Get(ctx context.Context, roleName string, resourceGroupName string, cloudServiceName string, options *CloudServiceRolesClientGetOptions) (CloudServiceRolesClientGetResponse, error) { + var err error + const operationName = "CloudServiceRolesClient.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, roleName, resourceGroupName, cloudServiceName, options) if err != nil { return CloudServiceRolesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServiceRolesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServiceRolesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServiceRolesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *CloudServiceRolesClient) NewListPager(resourceGroupName string, cl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServiceRolesClientListResponse) (CloudServiceRolesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServiceRolesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *CloudServiceRolesClient) NewListPager(resourceGroupName string, cl } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/cloudservices_client.go b/sdk/resourcemanager/compute/armcompute/cloudservices_client.go index 656d8112aceb..51df0e700a33 100644 --- a/sdk/resourcemanager/compute/armcompute/cloudservices_client.go +++ b/sdk/resourcemanager/compute/armcompute/cloudservices_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 armcompute @@ -61,7 +60,8 @@ func (client *CloudServicesClient) BeginCreateOrUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *CloudServicesClient) BeginCreateOrUpdate(ctx context.Context, reso // // Generated from API version 2022-09-04 func (client *CloudServicesClient) createOrUpdate(ctx context.Context, resourceGroupName string, cloudServiceName string, parameters CloudService, options *CloudServicesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.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, cloudServiceName, 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. @@ -109,7 +115,10 @@ func (client *CloudServicesClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-09-04") 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 cloud service. @@ -126,7 +135,8 @@ func (client *CloudServicesClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -137,18 +147,24 @@ func (client *CloudServicesClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2022-09-04 func (client *CloudServicesClient) deleteOperation(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.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, cloudServiceName, 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. @@ -191,7 +207,8 @@ func (client *CloudServicesClient) BeginDeleteInstances(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientDeleteInstancesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientDeleteInstancesResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientDeleteInstancesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -202,18 +219,24 @@ func (client *CloudServicesClient) BeginDeleteInstances(ctx context.Context, res // // Generated from API version 2022-09-04 func (client *CloudServicesClient) deleteInstances(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginDeleteInstancesOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.BeginDeleteInstances" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteInstancesCreateRequest(ctx, resourceGroupName, cloudServiceName, 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 } // deleteInstancesCreateRequest creates the DeleteInstances request. @@ -240,7 +263,10 @@ func (client *CloudServicesClient) deleteInstancesCreateRequest(ctx context.Cont req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -253,18 +279,25 @@ func (client *CloudServicesClient) deleteInstancesCreateRequest(ctx context.Cont // - cloudServiceName - Name of the cloud service. // - options - CloudServicesClientGetOptions contains the optional parameters for the CloudServicesClient.Get method. func (client *CloudServicesClient) Get(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientGetOptions) (CloudServicesClientGetResponse, error) { + var err error + const operationName = "CloudServicesClient.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, cloudServiceName, options) if err != nil { return CloudServicesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServicesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServicesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServicesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -311,18 +344,25 @@ func (client *CloudServicesClient) getHandleResponse(resp *http.Response) (Cloud // - options - CloudServicesClientGetInstanceViewOptions contains the optional parameters for the CloudServicesClient.GetInstanceView // method. func (client *CloudServicesClient) GetInstanceView(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientGetInstanceViewOptions) (CloudServicesClientGetInstanceViewResponse, error) { + var err error + const operationName = "CloudServicesClient.GetInstanceView" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getInstanceViewCreateRequest(ctx, resourceGroupName, cloudServiceName, options) if err != nil { return CloudServicesClientGetInstanceViewResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServicesClientGetInstanceViewResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServicesClientGetInstanceViewResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServicesClientGetInstanceViewResponse{}, err } - return client.getInstanceViewHandleResponse(resp) + resp, err := client.getInstanceViewHandleResponse(httpResp) + return resp, err } // getInstanceViewCreateRequest creates the GetInstanceView request. @@ -372,6 +412,7 @@ func (client *CloudServicesClient) NewListPager(resourceGroupName string, option return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServicesClientListResponse) (CloudServicesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServicesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -391,6 +432,7 @@ func (client *CloudServicesClient) NewListPager(resourceGroupName string, option } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -438,6 +480,7 @@ func (client *CloudServicesClient) NewListAllPager(options *CloudServicesClientL return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServicesClientListAllResponse) (CloudServicesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServicesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -457,6 +500,7 @@ func (client *CloudServicesClient) NewListAllPager(options *CloudServicesClientL } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -502,7 +546,8 @@ func (client *CloudServicesClient) BeginPowerOff(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientPowerOffResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -513,18 +558,24 @@ func (client *CloudServicesClient) BeginPowerOff(ctx context.Context, resourceGr // // Generated from API version 2022-09-04 func (client *CloudServicesClient) powerOff(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginPowerOffOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.BeginPowerOff" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.powerOffCreateRequest(ctx, resourceGroupName, cloudServiceName, 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 } // powerOffCreateRequest creates the PowerOff request. @@ -569,7 +620,8 @@ func (client *CloudServicesClient) BeginRebuild(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientRebuildResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientRebuildResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientRebuildResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -582,18 +634,24 @@ func (client *CloudServicesClient) BeginRebuild(ctx context.Context, resourceGro // // Generated from API version 2022-09-04 func (client *CloudServicesClient) rebuild(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginRebuildOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.BeginRebuild" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.rebuildCreateRequest(ctx, resourceGroupName, cloudServiceName, 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 } // rebuildCreateRequest creates the Rebuild request. @@ -620,7 +678,10 @@ func (client *CloudServicesClient) rebuildCreateRequest(ctx context.Context, res req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -639,7 +700,8 @@ func (client *CloudServicesClient) BeginReimage(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientReimageResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientReimageResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientReimageResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -650,18 +712,24 @@ func (client *CloudServicesClient) BeginReimage(ctx context.Context, resourceGro // // Generated from API version 2022-09-04 func (client *CloudServicesClient) reimage(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginReimageOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.BeginReimage" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageCreateRequest(ctx, resourceGroupName, cloudServiceName, 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 } // reimageCreateRequest creates the Reimage request. @@ -688,7 +756,10 @@ func (client *CloudServicesClient) reimageCreateRequest(ctx context.Context, res req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -707,7 +778,8 @@ func (client *CloudServicesClient) BeginRestart(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientRestartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientRestartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -718,18 +790,24 @@ func (client *CloudServicesClient) BeginRestart(ctx context.Context, resourceGro // // Generated from API version 2022-09-04 func (client *CloudServicesClient) restart(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginRestartOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.BeginRestart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.restartCreateRequest(ctx, resourceGroupName, cloudServiceName, 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 } // restartCreateRequest creates the Restart request. @@ -756,7 +834,10 @@ func (client *CloudServicesClient) restartCreateRequest(ctx context.Context, res req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -775,7 +856,8 @@ func (client *CloudServicesClient) BeginStart(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientStartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientStartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -786,18 +868,24 @@ func (client *CloudServicesClient) BeginStart(ctx context.Context, resourceGroup // // Generated from API version 2022-09-04 func (client *CloudServicesClient) start(ctx context.Context, resourceGroupName string, cloudServiceName string, options *CloudServicesClientBeginStartOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.BeginStart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startCreateRequest(ctx, resourceGroupName, cloudServiceName, 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 } // startCreateRequest creates the Start request. @@ -841,7 +929,8 @@ func (client *CloudServicesClient) BeginUpdate(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -852,18 +941,24 @@ func (client *CloudServicesClient) BeginUpdate(ctx context.Context, resourceGrou // // Generated from API version 2022-09-04 func (client *CloudServicesClient) update(ctx context.Context, resourceGroupName string, cloudServiceName string, parameters CloudServiceUpdate, options *CloudServicesClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesClient.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, cloudServiceName, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -889,5 +984,8 @@ func (client *CloudServicesClient) updateCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2022-09-04") 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/compute/armcompute/cloudservicesupdatedomain_client.go b/sdk/resourcemanager/compute/armcompute/cloudservicesupdatedomain_client.go index 32f10ba85fdd..f32be89d414f 100644 --- a/sdk/resourcemanager/compute/armcompute/cloudservicesupdatedomain_client.go +++ b/sdk/resourcemanager/compute/armcompute/cloudservicesupdatedomain_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 armcompute @@ -58,18 +57,25 @@ func NewCloudServicesUpdateDomainClient(subscriptionID string, credential azcore // - options - CloudServicesUpdateDomainClientGetUpdateDomainOptions contains the optional parameters for the CloudServicesUpdateDomainClient.GetUpdateDomain // method. func (client *CloudServicesUpdateDomainClient) GetUpdateDomain(ctx context.Context, resourceGroupName string, cloudServiceName string, updateDomain int32, options *CloudServicesUpdateDomainClientGetUpdateDomainOptions) (CloudServicesUpdateDomainClientGetUpdateDomainResponse, error) { + var err error + const operationName = "CloudServicesUpdateDomainClient.GetUpdateDomain" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getUpdateDomainCreateRequest(ctx, resourceGroupName, cloudServiceName, updateDomain, options) if err != nil { return CloudServicesUpdateDomainClientGetUpdateDomainResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CloudServicesUpdateDomainClientGetUpdateDomainResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CloudServicesUpdateDomainClientGetUpdateDomainResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CloudServicesUpdateDomainClientGetUpdateDomainResponse{}, err } - return client.getUpdateDomainHandleResponse(resp) + resp, err := client.getUpdateDomainHandleResponse(httpResp) + return resp, err } // getUpdateDomainCreateRequest creates the GetUpdateDomain request. @@ -121,6 +127,7 @@ func (client *CloudServicesUpdateDomainClient) NewListUpdateDomainsPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CloudServicesUpdateDomainClientListUpdateDomainsResponse) (CloudServicesUpdateDomainClientListUpdateDomainsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CloudServicesUpdateDomainClient.NewListUpdateDomainsPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *CloudServicesUpdateDomainClient) NewListUpdateDomainsPager(resourc } return client.listUpdateDomainsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -195,7 +203,8 @@ func (client *CloudServicesUpdateDomainClient) BeginWalkUpdateDomain(ctx context if err != nil { return nil, err } - return runtime.NewPoller[CloudServicesUpdateDomainClientWalkUpdateDomainResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[CloudServicesUpdateDomainClientWalkUpdateDomainResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[CloudServicesUpdateDomainClientWalkUpdateDomainResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -206,18 +215,24 @@ func (client *CloudServicesUpdateDomainClient) BeginWalkUpdateDomain(ctx context // // Generated from API version 2022-09-04 func (client *CloudServicesUpdateDomainClient) walkUpdateDomain(ctx context.Context, resourceGroupName string, cloudServiceName string, updateDomain int32, parameters UpdateDomain, options *CloudServicesUpdateDomainClientBeginWalkUpdateDomainOptions) (*http.Response, error) { + var err error + const operationName = "CloudServicesUpdateDomainClient.BeginWalkUpdateDomain" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.walkUpdateDomainCreateRequest(ctx, resourceGroupName, cloudServiceName, updateDomain, 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 } // walkUpdateDomainCreateRequest creates the WalkUpdateDomain request. @@ -244,5 +259,8 @@ func (client *CloudServicesUpdateDomainClient) walkUpdateDomainCreateRequest(ctx reqQP.Set("api-version", "2022-09-04") 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/compute/armcompute/communitygalleries_client.go b/sdk/resourcemanager/compute/armcompute/communitygalleries_client.go index 4c0a55f739bb..f9de1dae3eb3 100644 --- a/sdk/resourcemanager/compute/armcompute/communitygalleries_client.go +++ b/sdk/resourcemanager/compute/armcompute/communitygalleries_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 armcompute @@ -53,18 +52,25 @@ func NewCommunityGalleriesClient(subscriptionID string, credential azcore.TokenC // - publicGalleryName - The public name of the community gallery. // - options - CommunityGalleriesClientGetOptions contains the optional parameters for the CommunityGalleriesClient.Get method. func (client *CommunityGalleriesClient) Get(ctx context.Context, location string, publicGalleryName string, options *CommunityGalleriesClientGetOptions) (CommunityGalleriesClientGetResponse, error) { + var err error + const operationName = "CommunityGalleriesClient.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, location, publicGalleryName, options) if err != nil { return CommunityGalleriesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CommunityGalleriesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CommunityGalleriesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CommunityGalleriesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. diff --git a/sdk/resourcemanager/compute/armcompute/communitygalleryimages_client.go b/sdk/resourcemanager/compute/armcompute/communitygalleryimages_client.go index 23b341df2089..bc74a08b7f24 100644 --- a/sdk/resourcemanager/compute/armcompute/communitygalleryimages_client.go +++ b/sdk/resourcemanager/compute/armcompute/communitygalleryimages_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 armcompute @@ -55,18 +54,25 @@ func NewCommunityGalleryImagesClient(subscriptionID string, credential azcore.To // - options - CommunityGalleryImagesClientGetOptions contains the optional parameters for the CommunityGalleryImagesClient.Get // method. func (client *CommunityGalleryImagesClient) Get(ctx context.Context, location string, publicGalleryName string, galleryImageName string, options *CommunityGalleryImagesClientGetOptions) (CommunityGalleryImagesClientGetResponse, error) { + var err error + const operationName = "CommunityGalleryImagesClient.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, location, publicGalleryName, galleryImageName, options) if err != nil { return CommunityGalleryImagesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CommunityGalleryImagesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CommunityGalleryImagesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CommunityGalleryImagesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *CommunityGalleryImagesClient) NewListPager(location string, public return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CommunityGalleryImagesClientListResponse) (CommunityGalleryImagesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CommunityGalleryImagesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *CommunityGalleryImagesClient) NewListPager(location string, public } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/communitygalleryimageversions_client.go b/sdk/resourcemanager/compute/armcompute/communitygalleryimageversions_client.go index a05c5d729ce0..04a2c6b69713 100644 --- a/sdk/resourcemanager/compute/armcompute/communitygalleryimageversions_client.go +++ b/sdk/resourcemanager/compute/armcompute/communitygalleryimageversions_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 armcompute @@ -58,18 +57,25 @@ func NewCommunityGalleryImageVersionsClient(subscriptionID string, credential az // - options - CommunityGalleryImageVersionsClientGetOptions contains the optional parameters for the CommunityGalleryImageVersionsClient.Get // method. func (client *CommunityGalleryImageVersionsClient) Get(ctx context.Context, location string, publicGalleryName string, galleryImageName string, galleryImageVersionName string, options *CommunityGalleryImageVersionsClientGetOptions) (CommunityGalleryImageVersionsClientGetResponse, error) { + var err error + const operationName = "CommunityGalleryImageVersionsClient.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, location, publicGalleryName, galleryImageName, galleryImageVersionName, options) if err != nil { return CommunityGalleryImageVersionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CommunityGalleryImageVersionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CommunityGalleryImageVersionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CommunityGalleryImageVersionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -129,6 +135,7 @@ func (client *CommunityGalleryImageVersionsClient) NewListPager(location string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CommunityGalleryImageVersionsClientListResponse) (CommunityGalleryImageVersionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CommunityGalleryImageVersionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -148,6 +155,7 @@ func (client *CommunityGalleryImageVersionsClient) NewListPager(location string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/constants.go b/sdk/resourcemanager/compute/armcompute/constants.go index 8ec4af18fa39..a513a8a2efdf 100644 --- a/sdk/resourcemanager/compute/armcompute/constants.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute const ( moduleName = "armcompute" - moduleVersion = "v5.0.0" + moduleVersion = "v5.1.0-beta.1" ) type AccessLevel string @@ -790,17 +789,17 @@ func PossibleExtendedLocationTypesValues() []ExtendedLocationTypes { type GalleryApplicationCustomActionParameterType string const ( - GalleryApplicationCustomActionParameterTypeString GalleryApplicationCustomActionParameterType = "String" GalleryApplicationCustomActionParameterTypeConfigurationDataBlob GalleryApplicationCustomActionParameterType = "ConfigurationDataBlob" GalleryApplicationCustomActionParameterTypeLogOutputBlob GalleryApplicationCustomActionParameterType = "LogOutputBlob" + GalleryApplicationCustomActionParameterTypeString GalleryApplicationCustomActionParameterType = "String" ) // PossibleGalleryApplicationCustomActionParameterTypeValues returns the possible values for the GalleryApplicationCustomActionParameterType const type. func PossibleGalleryApplicationCustomActionParameterTypeValues() []GalleryApplicationCustomActionParameterType { return []GalleryApplicationCustomActionParameterType{ - GalleryApplicationCustomActionParameterTypeString, GalleryApplicationCustomActionParameterTypeConfigurationDataBlob, GalleryApplicationCustomActionParameterTypeLogOutputBlob, + GalleryApplicationCustomActionParameterTypeString, } } @@ -1016,19 +1015,19 @@ func PossibleInstanceViewTypesValues() []InstanceViewTypes { type IntervalInMins string const ( - IntervalInMinsThreeMins IntervalInMins = "ThreeMins" IntervalInMinsFiveMins IntervalInMins = "FiveMins" - IntervalInMinsThirtyMins IntervalInMins = "ThirtyMins" IntervalInMinsSixtyMins IntervalInMins = "SixtyMins" + IntervalInMinsThirtyMins IntervalInMins = "ThirtyMins" + IntervalInMinsThreeMins IntervalInMins = "ThreeMins" ) // PossibleIntervalInMinsValues returns the possible values for the IntervalInMins const type. func PossibleIntervalInMinsValues() []IntervalInMins { return []IntervalInMins{ - IntervalInMinsThreeMins, IntervalInMinsFiveMins, - IntervalInMinsThirtyMins, IntervalInMinsSixtyMins, + IntervalInMinsThirtyMins, + IntervalInMinsThreeMins, } } @@ -1097,19 +1096,19 @@ func PossibleLinuxVMGuestPatchModeValues() []LinuxVMGuestPatchMode { type MaintenanceOperationResultCodeTypes string const ( - MaintenanceOperationResultCodeTypesNone MaintenanceOperationResultCodeTypes = "None" - MaintenanceOperationResultCodeTypesRetryLater MaintenanceOperationResultCodeTypes = "RetryLater" MaintenanceOperationResultCodeTypesMaintenanceAborted MaintenanceOperationResultCodeTypes = "MaintenanceAborted" MaintenanceOperationResultCodeTypesMaintenanceCompleted MaintenanceOperationResultCodeTypes = "MaintenanceCompleted" + MaintenanceOperationResultCodeTypesNone MaintenanceOperationResultCodeTypes = "None" + MaintenanceOperationResultCodeTypesRetryLater MaintenanceOperationResultCodeTypes = "RetryLater" ) // PossibleMaintenanceOperationResultCodeTypesValues returns the possible values for the MaintenanceOperationResultCodeTypes const type. func PossibleMaintenanceOperationResultCodeTypesValues() []MaintenanceOperationResultCodeTypes { return []MaintenanceOperationResultCodeTypes{ - MaintenanceOperationResultCodeTypesNone, - MaintenanceOperationResultCodeTypesRetryLater, MaintenanceOperationResultCodeTypesMaintenanceAborted, MaintenanceOperationResultCodeTypesMaintenanceCompleted, + MaintenanceOperationResultCodeTypesNone, + MaintenanceOperationResultCodeTypesRetryLater, } } @@ -1189,15 +1188,15 @@ func PossibleOperatingSystemTypeValues() []OperatingSystemType { type OperatingSystemTypes string const ( - OperatingSystemTypesWindows OperatingSystemTypes = "Windows" OperatingSystemTypesLinux OperatingSystemTypes = "Linux" + OperatingSystemTypesWindows OperatingSystemTypes = "Windows" ) // PossibleOperatingSystemTypesValues returns the possible values for the OperatingSystemTypes const type. func PossibleOperatingSystemTypesValues() []OperatingSystemTypes { return []OperatingSystemTypes{ - OperatingSystemTypesWindows, OperatingSystemTypesLinux, + OperatingSystemTypesWindows, } } @@ -1564,19 +1563,19 @@ func PossibleReplicationStatusTypesValues() []ReplicationStatusTypes { 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, } } @@ -1602,15 +1601,15 @@ func PossibleResourceSKUCapacityScaleTypeValues() []ResourceSKUCapacityScaleType type ResourceSKURestrictionsReasonCode string const ( - ResourceSKURestrictionsReasonCodeQuotaID ResourceSKURestrictionsReasonCode = "QuotaId" ResourceSKURestrictionsReasonCodeNotAvailableForSubscription ResourceSKURestrictionsReasonCode = "NotAvailableForSubscription" + ResourceSKURestrictionsReasonCodeQuotaID ResourceSKURestrictionsReasonCode = "QuotaId" ) // PossibleResourceSKURestrictionsReasonCodeValues returns the possible values for the ResourceSKURestrictionsReasonCode const type. func PossibleResourceSKURestrictionsReasonCodeValues() []ResourceSKURestrictionsReasonCode { return []ResourceSKURestrictionsReasonCode{ - ResourceSKURestrictionsReasonCodeQuotaID, ResourceSKURestrictionsReasonCodeNotAvailableForSubscription, + ResourceSKURestrictionsReasonCodeQuotaID, } } @@ -1684,15 +1683,15 @@ func PossibleRestorePointExpandOptionsValues() []RestorePointExpandOptions { type RollingUpgradeActionType string const ( - RollingUpgradeActionTypeStart RollingUpgradeActionType = "Start" RollingUpgradeActionTypeCancel RollingUpgradeActionType = "Cancel" + RollingUpgradeActionTypeStart RollingUpgradeActionType = "Start" ) // PossibleRollingUpgradeActionTypeValues returns the possible values for the RollingUpgradeActionType const type. func PossibleRollingUpgradeActionTypeValues() []RollingUpgradeActionType { return []RollingUpgradeActionType{ - RollingUpgradeActionTypeStart, RollingUpgradeActionTypeCancel, + RollingUpgradeActionTypeStart, } } @@ -1700,19 +1699,19 @@ func PossibleRollingUpgradeActionTypeValues() []RollingUpgradeActionType { type RollingUpgradeStatusCode string const ( - RollingUpgradeStatusCodeRollingForward RollingUpgradeStatusCode = "RollingForward" RollingUpgradeStatusCodeCancelled RollingUpgradeStatusCode = "Cancelled" RollingUpgradeStatusCodeCompleted RollingUpgradeStatusCode = "Completed" RollingUpgradeStatusCodeFaulted RollingUpgradeStatusCode = "Faulted" + RollingUpgradeStatusCodeRollingForward RollingUpgradeStatusCode = "RollingForward" ) // PossibleRollingUpgradeStatusCodeValues returns the possible values for the RollingUpgradeStatusCode const type. func PossibleRollingUpgradeStatusCodeValues() []RollingUpgradeStatusCode { return []RollingUpgradeStatusCode{ - RollingUpgradeStatusCodeRollingForward, RollingUpgradeStatusCodeCancelled, RollingUpgradeStatusCodeCompleted, RollingUpgradeStatusCodeFaulted, + RollingUpgradeStatusCodeRollingForward, } } @@ -1901,17 +1900,17 @@ func PossibleSnapshotStorageAccountTypesValues() []SnapshotStorageAccountTypes { type StatusLevelTypes string const ( + StatusLevelTypesError StatusLevelTypes = "Error" StatusLevelTypesInfo StatusLevelTypes = "Info" StatusLevelTypesWarning StatusLevelTypes = "Warning" - StatusLevelTypesError StatusLevelTypes = "Error" ) // PossibleStatusLevelTypesValues returns the possible values for the StatusLevelTypes const type. func PossibleStatusLevelTypesValues() []StatusLevelTypes { return []StatusLevelTypes{ + StatusLevelTypesError, StatusLevelTypesInfo, StatusLevelTypesWarning, - StatusLevelTypesError, } } @@ -1991,17 +1990,17 @@ func PossibleUpgradeModeValues() []UpgradeMode { type UpgradeOperationInvoker string const ( + UpgradeOperationInvokerPlatform UpgradeOperationInvoker = "Platform" UpgradeOperationInvokerUnknown UpgradeOperationInvoker = "Unknown" UpgradeOperationInvokerUser UpgradeOperationInvoker = "User" - UpgradeOperationInvokerPlatform UpgradeOperationInvoker = "Platform" ) // PossibleUpgradeOperationInvokerValues returns the possible values for the UpgradeOperationInvoker const type. func PossibleUpgradeOperationInvokerValues() []UpgradeOperationInvoker { return []UpgradeOperationInvoker{ + UpgradeOperationInvokerPlatform, UpgradeOperationInvokerUnknown, UpgradeOperationInvokerUser, - UpgradeOperationInvokerPlatform, } } @@ -2009,19 +2008,19 @@ func PossibleUpgradeOperationInvokerValues() []UpgradeOperationInvoker { type UpgradeState string const ( - UpgradeStateRollingForward UpgradeState = "RollingForward" UpgradeStateCancelled UpgradeState = "Cancelled" UpgradeStateCompleted UpgradeState = "Completed" UpgradeStateFaulted UpgradeState = "Faulted" + UpgradeStateRollingForward UpgradeState = "RollingForward" ) // PossibleUpgradeStateValues returns the possible values for the UpgradeState const type. func PossibleUpgradeStateValues() []UpgradeState { return []UpgradeState{ - UpgradeStateRollingForward, UpgradeStateCancelled, UpgradeStateCompleted, UpgradeStateFaulted, + UpgradeStateRollingForward, } } diff --git a/sdk/resourcemanager/compute/armcompute/dedicatedhostgroups_client.go b/sdk/resourcemanager/compute/armcompute/dedicatedhostgroups_client.go index 5c239087b6bd..c1c4ba7d1460 100644 --- a/sdk/resourcemanager/compute/armcompute/dedicatedhostgroups_client.go +++ b/sdk/resourcemanager/compute/armcompute/dedicatedhostgroups_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 armcompute @@ -56,18 +55,25 @@ func NewDedicatedHostGroupsClient(subscriptionID string, credential azcore.Token // - options - DedicatedHostGroupsClientCreateOrUpdateOptions contains the optional parameters for the DedicatedHostGroupsClient.CreateOrUpdate // method. func (client *DedicatedHostGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, hostGroupName string, parameters DedicatedHostGroup, options *DedicatedHostGroupsClientCreateOrUpdateOptions) (DedicatedHostGroupsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "DedicatedHostGroupsClient.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, hostGroupName, parameters, options) if err != nil { return DedicatedHostGroupsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DedicatedHostGroupsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return DedicatedHostGroupsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return DedicatedHostGroupsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -93,7 +99,10 @@ func (client *DedicatedHostGroupsClient) createOrUpdateCreateRequest(ctx context reqQP.Set("api-version", "2023-03-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. @@ -114,16 +123,22 @@ func (client *DedicatedHostGroupsClient) createOrUpdateHandleResponse(resp *http // - options - DedicatedHostGroupsClientDeleteOptions contains the optional parameters for the DedicatedHostGroupsClient.Delete // method. func (client *DedicatedHostGroupsClient) Delete(ctx context.Context, resourceGroupName string, hostGroupName string, options *DedicatedHostGroupsClientDeleteOptions) (DedicatedHostGroupsClientDeleteResponse, error) { + var err error + const operationName = "DedicatedHostGroupsClient.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, resourceGroupName, hostGroupName, options) if err != nil { return DedicatedHostGroupsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DedicatedHostGroupsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return DedicatedHostGroupsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DedicatedHostGroupsClientDeleteResponse{}, err } return DedicatedHostGroupsClientDeleteResponse{}, nil } @@ -162,18 +177,25 @@ func (client *DedicatedHostGroupsClient) deleteCreateRequest(ctx context.Context // - hostGroupName - The name of the dedicated host group. // - options - DedicatedHostGroupsClientGetOptions contains the optional parameters for the DedicatedHostGroupsClient.Get method. func (client *DedicatedHostGroupsClient) Get(ctx context.Context, resourceGroupName string, hostGroupName string, options *DedicatedHostGroupsClientGetOptions) (DedicatedHostGroupsClientGetResponse, error) { + var err error + const operationName = "DedicatedHostGroupsClient.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, hostGroupName, options) if err != nil { return DedicatedHostGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DedicatedHostGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DedicatedHostGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DedicatedHostGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -227,6 +249,7 @@ func (client *DedicatedHostGroupsClient) NewListByResourceGroupPager(resourceGro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DedicatedHostGroupsClientListByResourceGroupResponse) (DedicatedHostGroupsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DedicatedHostGroupsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -246,6 +269,7 @@ func (client *DedicatedHostGroupsClient) NewListByResourceGroupPager(resourceGro } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -292,6 +316,7 @@ func (client *DedicatedHostGroupsClient) NewListBySubscriptionPager(options *Ded return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DedicatedHostGroupsClientListBySubscriptionResponse) (DedicatedHostGroupsClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DedicatedHostGroupsClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -311,6 +336,7 @@ func (client *DedicatedHostGroupsClient) NewListBySubscriptionPager(options *Ded } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -351,18 +377,25 @@ func (client *DedicatedHostGroupsClient) listBySubscriptionHandleResponse(resp * // - options - DedicatedHostGroupsClientUpdateOptions contains the optional parameters for the DedicatedHostGroupsClient.Update // method. func (client *DedicatedHostGroupsClient) Update(ctx context.Context, resourceGroupName string, hostGroupName string, parameters DedicatedHostGroupUpdate, options *DedicatedHostGroupsClientUpdateOptions) (DedicatedHostGroupsClientUpdateResponse, error) { + var err error + const operationName = "DedicatedHostGroupsClient.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, hostGroupName, parameters, options) if err != nil { return DedicatedHostGroupsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DedicatedHostGroupsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DedicatedHostGroupsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DedicatedHostGroupsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -388,7 +421,10 @@ func (client *DedicatedHostGroupsClient) updateCreateRequest(ctx context.Context reqQP.Set("api-version", "2023-03-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/compute/armcompute/dedicatedhosts_client.go b/sdk/resourcemanager/compute/armcompute/dedicatedhosts_client.go index 28c8742f37a7..5af8f8e14857 100644 --- a/sdk/resourcemanager/compute/armcompute/dedicatedhosts_client.go +++ b/sdk/resourcemanager/compute/armcompute/dedicatedhosts_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 armcompute @@ -61,7 +60,8 @@ func (client *DedicatedHostsClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller[DedicatedHostsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DedicatedHostsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DedicatedHostsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *DedicatedHostsClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2023-03-01 func (client *DedicatedHostsClient) createOrUpdate(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters DedicatedHost, options *DedicatedHostsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DedicatedHostsClient.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, hostGroupName, hostName, 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. @@ -113,7 +119,10 @@ func (client *DedicatedHostsClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2023-03-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 - Delete a dedicated host. @@ -131,7 +140,8 @@ func (client *DedicatedHostsClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[DedicatedHostsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DedicatedHostsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DedicatedHostsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *DedicatedHostsClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2023-03-01 func (client *DedicatedHostsClient) deleteOperation(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, options *DedicatedHostsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DedicatedHostsClient.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, hostGroupName, hostName, 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. @@ -195,18 +211,25 @@ func (client *DedicatedHostsClient) deleteCreateRequest(ctx context.Context, res // - hostName - The name of the dedicated host. // - options - DedicatedHostsClientGetOptions contains the optional parameters for the DedicatedHostsClient.Get method. func (client *DedicatedHostsClient) Get(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, options *DedicatedHostsClientGetOptions) (DedicatedHostsClientGetResponse, error) { + var err error + const operationName = "DedicatedHostsClient.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, hostGroupName, hostName, options) if err != nil { return DedicatedHostsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DedicatedHostsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DedicatedHostsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DedicatedHostsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *DedicatedHostsClient) NewListAvailableSizesPager(resourceGroupName return false }, Fetcher: func(ctx context.Context, page *DedicatedHostsClientListAvailableSizesResponse) (DedicatedHostsClientListAvailableSizesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DedicatedHostsClient.NewListAvailableSizesPager") req, err := client.listAvailableSizesCreateRequest(ctx, resourceGroupName, hostGroupName, hostName, options) if err != nil { return DedicatedHostsClientListAvailableSizesResponse{}, err @@ -279,6 +303,7 @@ func (client *DedicatedHostsClient) NewListAvailableSizesPager(resourceGroupName } return client.listAvailableSizesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -335,6 +360,7 @@ func (client *DedicatedHostsClient) NewListByHostGroupPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DedicatedHostsClientListByHostGroupResponse) (DedicatedHostsClientListByHostGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DedicatedHostsClient.NewListByHostGroupPager") var req *policy.Request var err error if page == nil { @@ -354,6 +380,7 @@ func (client *DedicatedHostsClient) NewListByHostGroupPager(resourceGroupName st } return client.listByHostGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -410,7 +437,8 @@ func (client *DedicatedHostsClient) BeginRestart(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller[DedicatedHostsClientRestartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DedicatedHostsClientRestartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DedicatedHostsClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -424,18 +452,24 @@ func (client *DedicatedHostsClient) BeginRestart(ctx context.Context, resourceGr // // Generated from API version 2023-03-01 func (client *DedicatedHostsClient) restart(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, options *DedicatedHostsClientBeginRestartOptions) (*http.Response, error) { + var err error + const operationName = "DedicatedHostsClient.BeginRestart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.restartCreateRequest(ctx, resourceGroupName, hostGroupName, hostName, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // restartCreateRequest creates the Restart request. @@ -484,7 +518,8 @@ func (client *DedicatedHostsClient) BeginUpdate(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[DedicatedHostsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DedicatedHostsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DedicatedHostsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -495,18 +530,24 @@ func (client *DedicatedHostsClient) BeginUpdate(ctx context.Context, resourceGro // // Generated from API version 2023-03-01 func (client *DedicatedHostsClient) update(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters DedicatedHostUpdate, options *DedicatedHostsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DedicatedHostsClient.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, hostGroupName, hostName, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -536,5 +577,8 @@ func (client *DedicatedHostsClient) updateCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2023-03-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/compute/armcompute/diskaccesses_client.go b/sdk/resourcemanager/compute/armcompute/diskaccesses_client.go index 4c0e205530eb..d7cdb82b02c6 100644 --- a/sdk/resourcemanager/compute/armcompute/diskaccesses_client.go +++ b/sdk/resourcemanager/compute/armcompute/diskaccesses_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 armcompute @@ -62,7 +61,8 @@ func (client *DiskAccessesClient) BeginCreateOrUpdate(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller[DiskAccessesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskAccessesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskAccessesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *DiskAccessesClient) BeginCreateOrUpdate(ctx context.Context, resou // // Generated from API version 2022-07-02 func (client *DiskAccessesClient) createOrUpdate(ctx context.Context, resourceGroupName string, diskAccessName string, diskAccess DiskAccess, options *DiskAccessesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DiskAccessesClient.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, diskAccessName, diskAccess, 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 } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -110,7 +116,10 @@ func (client *DiskAccessesClient) createOrUpdateCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, diskAccess) + if err := runtime.MarshalAsJSON(req, diskAccess); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a disk access resource. @@ -129,7 +138,8 @@ func (client *DiskAccessesClient) BeginDelete(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller[DiskAccessesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskAccessesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskAccessesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *DiskAccessesClient) BeginDelete(ctx context.Context, resourceGroup // // Generated from API version 2022-07-02 func (client *DiskAccessesClient) deleteOperation(ctx context.Context, resourceGroupName string, diskAccessName string, options *DiskAccessesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DiskAccessesClient.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, diskAccessName, 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. @@ -197,7 +213,8 @@ func (client *DiskAccessesClient) BeginDeleteAPrivateEndpointConnection(ctx cont if err != nil { return nil, err } - return runtime.NewPoller[DiskAccessesClientDeleteAPrivateEndpointConnectionResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskAccessesClientDeleteAPrivateEndpointConnectionResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskAccessesClientDeleteAPrivateEndpointConnectionResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -208,18 +225,24 @@ func (client *DiskAccessesClient) BeginDeleteAPrivateEndpointConnection(ctx cont // // Generated from API version 2022-07-02 func (client *DiskAccessesClient) deleteAPrivateEndpointConnection(ctx context.Context, resourceGroupName string, diskAccessName string, privateEndpointConnectionName string, options *DiskAccessesClientBeginDeleteAPrivateEndpointConnectionOptions) (*http.Response, error) { + var err error + const operationName = "DiskAccessesClient.BeginDeleteAPrivateEndpointConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAPrivateEndpointConnectionCreateRequest(ctx, resourceGroupName, diskAccessName, privateEndpointConnectionName, 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 } // deleteAPrivateEndpointConnectionCreateRequest creates the DeleteAPrivateEndpointConnection request. @@ -262,18 +285,25 @@ func (client *DiskAccessesClient) deleteAPrivateEndpointConnectionCreateRequest( // maximum name length is 80 characters. // - options - DiskAccessesClientGetOptions contains the optional parameters for the DiskAccessesClient.Get method. func (client *DiskAccessesClient) Get(ctx context.Context, resourceGroupName string, diskAccessName string, options *DiskAccessesClientGetOptions) (DiskAccessesClientGetResponse, error) { + var err error + const operationName = "DiskAccessesClient.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, diskAccessName, options) if err != nil { return DiskAccessesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DiskAccessesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DiskAccessesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DiskAccessesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -323,18 +353,25 @@ func (client *DiskAccessesClient) getHandleResponse(resp *http.Response) (DiskAc // - options - DiskAccessesClientGetAPrivateEndpointConnectionOptions contains the optional parameters for the DiskAccessesClient.GetAPrivateEndpointConnection // method. func (client *DiskAccessesClient) GetAPrivateEndpointConnection(ctx context.Context, resourceGroupName string, diskAccessName string, privateEndpointConnectionName string, options *DiskAccessesClientGetAPrivateEndpointConnectionOptions) (DiskAccessesClientGetAPrivateEndpointConnectionResponse, error) { + var err error + const operationName = "DiskAccessesClient.GetAPrivateEndpointConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAPrivateEndpointConnectionCreateRequest(ctx, resourceGroupName, diskAccessName, privateEndpointConnectionName, options) if err != nil { return DiskAccessesClientGetAPrivateEndpointConnectionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DiskAccessesClientGetAPrivateEndpointConnectionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DiskAccessesClientGetAPrivateEndpointConnectionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DiskAccessesClientGetAPrivateEndpointConnectionResponse{}, err } - return client.getAPrivateEndpointConnectionHandleResponse(resp) + resp, err := client.getAPrivateEndpointConnectionHandleResponse(httpResp) + return resp, err } // getAPrivateEndpointConnectionCreateRequest creates the GetAPrivateEndpointConnection request. @@ -387,18 +424,25 @@ func (client *DiskAccessesClient) getAPrivateEndpointConnectionHandleResponse(re // - options - DiskAccessesClientGetPrivateLinkResourcesOptions contains the optional parameters for the DiskAccessesClient.GetPrivateLinkResources // method. func (client *DiskAccessesClient) GetPrivateLinkResources(ctx context.Context, resourceGroupName string, diskAccessName string, options *DiskAccessesClientGetPrivateLinkResourcesOptions) (DiskAccessesClientGetPrivateLinkResourcesResponse, error) { + var err error + const operationName = "DiskAccessesClient.GetPrivateLinkResources" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getPrivateLinkResourcesCreateRequest(ctx, resourceGroupName, diskAccessName, options) if err != nil { return DiskAccessesClientGetPrivateLinkResourcesResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DiskAccessesClientGetPrivateLinkResourcesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DiskAccessesClientGetPrivateLinkResourcesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DiskAccessesClientGetPrivateLinkResourcesResponse{}, err } - return client.getPrivateLinkResourcesHandleResponse(resp) + resp, err := client.getPrivateLinkResourcesHandleResponse(httpResp) + return resp, err } // getPrivateLinkResourcesCreateRequest creates the GetPrivateLinkResources request. @@ -446,6 +490,7 @@ func (client *DiskAccessesClient) NewListPager(options *DiskAccessesClientListOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskAccessesClientListResponse) (DiskAccessesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskAccessesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -465,6 +510,7 @@ func (client *DiskAccessesClient) NewListPager(options *DiskAccessesClientListOp } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -507,6 +553,7 @@ func (client *DiskAccessesClient) NewListByResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskAccessesClientListByResourceGroupResponse) (DiskAccessesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskAccessesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -526,6 +573,7 @@ func (client *DiskAccessesClient) NewListByResourceGroupPager(resourceGroupName } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -575,6 +623,7 @@ func (client *DiskAccessesClient) NewListPrivateEndpointConnectionsPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskAccessesClientListPrivateEndpointConnectionsResponse) (DiskAccessesClientListPrivateEndpointConnectionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskAccessesClient.NewListPrivateEndpointConnectionsPager") var req *policy.Request var err error if page == nil { @@ -594,6 +643,7 @@ func (client *DiskAccessesClient) NewListPrivateEndpointConnectionsPager(resourc } return client.listPrivateEndpointConnectionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -649,7 +699,8 @@ func (client *DiskAccessesClient) BeginUpdate(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller[DiskAccessesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskAccessesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskAccessesClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -660,18 +711,24 @@ func (client *DiskAccessesClient) BeginUpdate(ctx context.Context, resourceGroup // // Generated from API version 2022-07-02 func (client *DiskAccessesClient) update(ctx context.Context, resourceGroupName string, diskAccessName string, diskAccess DiskAccessUpdate, options *DiskAccessesClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DiskAccessesClient.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, diskAccessName, diskAccess, 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. @@ -697,7 +754,10 @@ func (client *DiskAccessesClient) updateCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, diskAccess) + if err := runtime.MarshalAsJSON(req, diskAccess); err != nil { + return nil, err + } + return req, nil } // BeginUpdateAPrivateEndpointConnection - Approve or reject a private endpoint connection under disk access resource, this @@ -720,7 +780,8 @@ func (client *DiskAccessesClient) BeginUpdateAPrivateEndpointConnection(ctx cont if err != nil { return nil, err } - return runtime.NewPoller[DiskAccessesClientUpdateAPrivateEndpointConnectionResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskAccessesClientUpdateAPrivateEndpointConnectionResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskAccessesClientUpdateAPrivateEndpointConnectionResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -732,18 +793,24 @@ func (client *DiskAccessesClient) BeginUpdateAPrivateEndpointConnection(ctx cont // // Generated from API version 2022-07-02 func (client *DiskAccessesClient) updateAPrivateEndpointConnection(ctx context.Context, resourceGroupName string, diskAccessName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection, options *DiskAccessesClientBeginUpdateAPrivateEndpointConnectionOptions) (*http.Response, error) { + var err error + const operationName = "DiskAccessesClient.BeginUpdateAPrivateEndpointConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateAPrivateEndpointConnectionCreateRequest(ctx, resourceGroupName, diskAccessName, privateEndpointConnectionName, privateEndpointConnection, 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 } // updateAPrivateEndpointConnectionCreateRequest creates the UpdateAPrivateEndpointConnection request. @@ -773,5 +840,8 @@ func (client *DiskAccessesClient) updateAPrivateEndpointConnectionCreateRequest( reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, privateEndpointConnection) + if err := runtime.MarshalAsJSON(req, privateEndpointConnection); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/diskencryptionsets_client.go b/sdk/resourcemanager/compute/armcompute/diskencryptionsets_client.go index 05d1c3d1ce46..dc150ff4f4aa 100644 --- a/sdk/resourcemanager/compute/armcompute/diskencryptionsets_client.go +++ b/sdk/resourcemanager/compute/armcompute/diskencryptionsets_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 armcompute @@ -62,7 +61,8 @@ func (client *DiskEncryptionSetsClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[DiskEncryptionSetsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskEncryptionSetsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskEncryptionSetsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *DiskEncryptionSetsClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-07-02 func (client *DiskEncryptionSetsClient) createOrUpdate(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, diskEncryptionSet DiskEncryptionSet, options *DiskEncryptionSetsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DiskEncryptionSetsClient.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, diskEncryptionSetName, diskEncryptionSet, 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 } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -110,7 +116,10 @@ func (client *DiskEncryptionSetsClient) createOrUpdateCreateRequest(ctx context. reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, diskEncryptionSet) + if err := runtime.MarshalAsJSON(req, diskEncryptionSet); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a disk encryption set. @@ -129,7 +138,8 @@ func (client *DiskEncryptionSetsClient) BeginDelete(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller[DiskEncryptionSetsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskEncryptionSetsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskEncryptionSetsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *DiskEncryptionSetsClient) BeginDelete(ctx context.Context, resourc // // Generated from API version 2022-07-02 func (client *DiskEncryptionSetsClient) deleteOperation(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, options *DiskEncryptionSetsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DiskEncryptionSetsClient.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, diskEncryptionSetName, 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. @@ -190,18 +206,25 @@ func (client *DiskEncryptionSetsClient) deleteCreateRequest(ctx context.Context, // name length is 80 characters. // - options - DiskEncryptionSetsClientGetOptions contains the optional parameters for the DiskEncryptionSetsClient.Get method. func (client *DiskEncryptionSetsClient) Get(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, options *DiskEncryptionSetsClientGetOptions) (DiskEncryptionSetsClientGetResponse, error) { + var err error + const operationName = "DiskEncryptionSetsClient.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, diskEncryptionSetName, options) if err != nil { return DiskEncryptionSetsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DiskEncryptionSetsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DiskEncryptionSetsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DiskEncryptionSetsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *DiskEncryptionSetsClient) NewListPager(options *DiskEncryptionSets return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskEncryptionSetsClientListResponse) (DiskEncryptionSetsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskEncryptionSetsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *DiskEncryptionSetsClient) NewListPager(options *DiskEncryptionSets } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -314,6 +339,7 @@ func (client *DiskEncryptionSetsClient) NewListAssociatedResourcesPager(resource return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskEncryptionSetsClientListAssociatedResourcesResponse) (DiskEncryptionSetsClientListAssociatedResourcesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskEncryptionSetsClient.NewListAssociatedResourcesPager") var req *policy.Request var err error if page == nil { @@ -333,6 +359,7 @@ func (client *DiskEncryptionSetsClient) NewListAssociatedResourcesPager(resource } return client.listAssociatedResourcesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -383,6 +410,7 @@ func (client *DiskEncryptionSetsClient) NewListByResourceGroupPager(resourceGrou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskEncryptionSetsClientListByResourceGroupResponse) (DiskEncryptionSetsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskEncryptionSetsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -402,6 +430,7 @@ func (client *DiskEncryptionSetsClient) NewListByResourceGroupPager(resourceGrou } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -453,7 +482,8 @@ func (client *DiskEncryptionSetsClient) BeginUpdate(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller[DiskEncryptionSetsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DiskEncryptionSetsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskEncryptionSetsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -464,18 +494,24 @@ func (client *DiskEncryptionSetsClient) BeginUpdate(ctx context.Context, resourc // // Generated from API version 2022-07-02 func (client *DiskEncryptionSetsClient) update(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, diskEncryptionSet DiskEncryptionSetUpdate, options *DiskEncryptionSetsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DiskEncryptionSetsClient.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, diskEncryptionSetName, diskEncryptionSet, 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. @@ -501,5 +537,8 @@ func (client *DiskEncryptionSetsClient) updateCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, diskEncryptionSet) + if err := runtime.MarshalAsJSON(req, diskEncryptionSet); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/diskrestorepoint_client.go b/sdk/resourcemanager/compute/armcompute/diskrestorepoint_client.go index 73a56d912b0f..7b108567e5dd 100644 --- a/sdk/resourcemanager/compute/armcompute/diskrestorepoint_client.go +++ b/sdk/resourcemanager/compute/armcompute/diskrestorepoint_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 armcompute @@ -55,18 +54,25 @@ func NewDiskRestorePointClient(subscriptionID string, credential azcore.TokenCre // - diskRestorePointName - The name of the disk restore point created. // - options - DiskRestorePointClientGetOptions contains the optional parameters for the DiskRestorePointClient.Get method. func (client *DiskRestorePointClient) Get(ctx context.Context, resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, diskRestorePointName string, options *DiskRestorePointClientGetOptions) (DiskRestorePointClientGetResponse, error) { + var err error + const operationName = "DiskRestorePointClient.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, restorePointCollectionName, vmRestorePointName, diskRestorePointName, options) if err != nil { return DiskRestorePointClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DiskRestorePointClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DiskRestorePointClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DiskRestorePointClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -129,9 +135,10 @@ func (client *DiskRestorePointClient) BeginGrantAccess(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DiskRestorePointClientGrantAccessResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DiskRestorePointClientGrantAccessResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskRestorePointClientGrantAccessResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +149,24 @@ func (client *DiskRestorePointClient) BeginGrantAccess(ctx context.Context, reso // // Generated from API version 2022-07-02 func (client *DiskRestorePointClient) grantAccess(ctx context.Context, resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, diskRestorePointName string, grantAccessData GrantAccessData, options *DiskRestorePointClientBeginGrantAccessOptions) (*http.Response, error) { + var err error + const operationName = "DiskRestorePointClient.BeginGrantAccess" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.grantAccessCreateRequest(ctx, resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, grantAccessData, 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 } // grantAccessCreateRequest creates the GrantAccess request. @@ -187,7 +200,10 @@ func (client *DiskRestorePointClient) grantAccessCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, grantAccessData) + if err := runtime.MarshalAsJSON(req, grantAccessData); err != nil { + return nil, err + } + return req, nil } // NewListByRestorePointPager - Lists diskRestorePoints under a vmRestorePoint. @@ -204,6 +220,7 @@ func (client *DiskRestorePointClient) NewListByRestorePointPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DiskRestorePointClientListByRestorePointResponse) (DiskRestorePointClientListByRestorePointResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DiskRestorePointClient.NewListByRestorePointPager") var req *policy.Request var err error if page == nil { @@ -223,6 +240,7 @@ func (client *DiskRestorePointClient) NewListByRestorePointPager(resourceGroupNa } return client.listByRestorePointHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -281,9 +299,10 @@ func (client *DiskRestorePointClient) BeginRevokeAccess(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DiskRestorePointClientRevokeAccessResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DiskRestorePointClientRevokeAccessResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DiskRestorePointClientRevokeAccessResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -294,18 +313,24 @@ func (client *DiskRestorePointClient) BeginRevokeAccess(ctx context.Context, res // // Generated from API version 2022-07-02 func (client *DiskRestorePointClient) revokeAccess(ctx context.Context, resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, diskRestorePointName string, options *DiskRestorePointClientBeginRevokeAccessOptions) (*http.Response, error) { + var err error + const operationName = "DiskRestorePointClient.BeginRevokeAccess" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.revokeAccessCreateRequest(ctx, resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, 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 } // revokeAccessCreateRequest creates the RevokeAccess request. diff --git a/sdk/resourcemanager/compute/armcompute/disks_client.go b/sdk/resourcemanager/compute/armcompute/disks_client.go index 9bbb442973aa..4aca99353c11 100644 --- a/sdk/resourcemanager/compute/armcompute/disks_client.go +++ b/sdk/resourcemanager/compute/armcompute/disks_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 armcompute @@ -62,7 +61,8 @@ func (client *DisksClient) BeginCreateOrUpdate(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[DisksClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DisksClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DisksClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *DisksClient) BeginCreateOrUpdate(ctx context.Context, resourceGrou // // Generated from API version 2022-07-02 func (client *DisksClient) createOrUpdate(ctx context.Context, resourceGroupName string, diskName string, disk Disk, options *DisksClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DisksClient.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, diskName, disk, 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 } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -110,7 +116,10 @@ func (client *DisksClient) createOrUpdateCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, disk) + if err := runtime.MarshalAsJSON(req, disk); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a disk. @@ -128,7 +137,8 @@ func (client *DisksClient) BeginDelete(ctx context.Context, resourceGroupName st if err != nil { return nil, err } - return runtime.NewPoller[DisksClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DisksClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DisksClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *DisksClient) BeginDelete(ctx context.Context, resourceGroupName st // // Generated from API version 2022-07-02 func (client *DisksClient) deleteOperation(ctx context.Context, resourceGroupName string, diskName string, options *DisksClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DisksClient.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, diskName, 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. @@ -188,18 +204,25 @@ func (client *DisksClient) deleteCreateRequest(ctx context.Context, resourceGrou // characters. // - options - DisksClientGetOptions contains the optional parameters for the DisksClient.Get method. func (client *DisksClient) Get(ctx context.Context, resourceGroupName string, diskName string, options *DisksClientGetOptions) (DisksClientGetResponse, error) { + var err error + const operationName = "DisksClient.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, diskName, options) if err != nil { return DisksClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DisksClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DisksClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DisksClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -253,9 +276,10 @@ func (client *DisksClient) BeginGrantAccess(ctx context.Context, resourceGroupNa if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DisksClientGrantAccessResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DisksClientGrantAccessResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DisksClientGrantAccessResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -266,18 +290,24 @@ func (client *DisksClient) BeginGrantAccess(ctx context.Context, resourceGroupNa // // Generated from API version 2022-07-02 func (client *DisksClient) grantAccess(ctx context.Context, resourceGroupName string, diskName string, grantAccessData GrantAccessData, options *DisksClientBeginGrantAccessOptions) (*http.Response, error) { + var err error + const operationName = "DisksClient.BeginGrantAccess" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.grantAccessCreateRequest(ctx, resourceGroupName, diskName, grantAccessData, 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 } // grantAccessCreateRequest creates the GrantAccess request. @@ -303,7 +333,10 @@ func (client *DisksClient) grantAccessCreateRequest(ctx context.Context, resourc reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, grantAccessData) + if err := runtime.MarshalAsJSON(req, grantAccessData); err != nil { + return nil, err + } + return req, nil } // NewListPager - Lists all the disks under a subscription. @@ -316,6 +349,7 @@ func (client *DisksClient) NewListPager(options *DisksClientListOptions) *runtim return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DisksClientListResponse) (DisksClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DisksClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -335,6 +369,7 @@ func (client *DisksClient) NewListPager(options *DisksClientListOptions) *runtim } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -377,6 +412,7 @@ func (client *DisksClient) NewListByResourceGroupPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DisksClientListByResourceGroupResponse) (DisksClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DisksClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -396,6 +432,7 @@ func (client *DisksClient) NewListByResourceGroupPager(resourceGroupName string, } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -445,9 +482,10 @@ func (client *DisksClient) BeginRevokeAccess(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DisksClientRevokeAccessResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DisksClientRevokeAccessResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DisksClientRevokeAccessResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -458,18 +496,24 @@ func (client *DisksClient) BeginRevokeAccess(ctx context.Context, resourceGroupN // // Generated from API version 2022-07-02 func (client *DisksClient) revokeAccess(ctx context.Context, resourceGroupName string, diskName string, options *DisksClientBeginRevokeAccessOptions) (*http.Response, error) { + var err error + const operationName = "DisksClient.BeginRevokeAccess" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.revokeAccessCreateRequest(ctx, resourceGroupName, diskName, 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 } // revokeAccessCreateRequest creates the RevokeAccess request. @@ -513,7 +557,8 @@ func (client *DisksClient) BeginUpdate(ctx context.Context, resourceGroupName st if err != nil { return nil, err } - return runtime.NewPoller[DisksClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[DisksClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[DisksClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -524,18 +569,24 @@ func (client *DisksClient) BeginUpdate(ctx context.Context, resourceGroupName st // // Generated from API version 2022-07-02 func (client *DisksClient) update(ctx context.Context, resourceGroupName string, diskName string, disk DiskUpdate, options *DisksClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DisksClient.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, diskName, disk, 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. @@ -561,5 +612,8 @@ func (client *DisksClient) updateCreateRequest(ctx context.Context, resourceGrou reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, disk) + if err := runtime.MarshalAsJSON(req, disk); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go b/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go new file mode 100644 index 000000000000..5a39510809ad --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go @@ -0,0 +1,309 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// AvailabilitySetsServer is a fake server for instances of the armcompute.AvailabilitySetsClient type. +type AvailabilitySetsServer struct { + // CreateOrUpdate is the fake for method AvailabilitySetsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK + CreateOrUpdate func(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters armcompute.AvailabilitySet, options *armcompute.AvailabilitySetsClientCreateOrUpdateOptions) (resp azfake.Responder[armcompute.AvailabilitySetsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method AvailabilitySetsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, availabilitySetName string, options *armcompute.AvailabilitySetsClientDeleteOptions) (resp azfake.Responder[armcompute.AvailabilitySetsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AvailabilitySetsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, availabilitySetName string, options *armcompute.AvailabilitySetsClientGetOptions) (resp azfake.Responder[armcompute.AvailabilitySetsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AvailabilitySetsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armcompute.AvailabilitySetsClientListOptions) (resp azfake.PagerResponder[armcompute.AvailabilitySetsClientListResponse]) + + // NewListAvailableSizesPager is the fake for method AvailabilitySetsClient.NewListAvailableSizesPager + // HTTP status codes to indicate success: http.StatusOK + NewListAvailableSizesPager func(resourceGroupName string, availabilitySetName string, options *armcompute.AvailabilitySetsClientListAvailableSizesOptions) (resp azfake.PagerResponder[armcompute.AvailabilitySetsClientListAvailableSizesResponse]) + + // NewListBySubscriptionPager is the fake for method AvailabilitySetsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armcompute.AvailabilitySetsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armcompute.AvailabilitySetsClientListBySubscriptionResponse]) + + // Update is the fake for method AvailabilitySetsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters armcompute.AvailabilitySetUpdate, options *armcompute.AvailabilitySetsClientUpdateOptions) (resp azfake.Responder[armcompute.AvailabilitySetsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewAvailabilitySetsServerTransport creates a new instance of AvailabilitySetsServerTransport with the provided implementation. +// The returned AvailabilitySetsServerTransport instance is connected to an instance of armcompute.AvailabilitySetsClient by way of the +// undefined.Transporter field. +func NewAvailabilitySetsServerTransport(srv *AvailabilitySetsServer) *AvailabilitySetsServerTransport { + return &AvailabilitySetsServerTransport{srv: srv} +} + +// AvailabilitySetsServerTransport connects instances of armcompute.AvailabilitySetsClient to instances of AvailabilitySetsServer. +// Don't use this type directly, use NewAvailabilitySetsServerTransport instead. +type AvailabilitySetsServerTransport struct { + srv *AvailabilitySetsServer + newListPager *azfake.PagerResponder[armcompute.AvailabilitySetsClientListResponse] + newListAvailableSizesPager *azfake.PagerResponder[armcompute.AvailabilitySetsClientListAvailableSizesResponse] + newListBySubscriptionPager *azfake.PagerResponder[armcompute.AvailabilitySetsClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for AvailabilitySetsServerTransport. +func (a *AvailabilitySetsServerTransport) 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 "AvailabilitySetsClient.CreateOrUpdate": + resp, err = a.dispatchCreateOrUpdate(req) + case "AvailabilitySetsClient.Delete": + resp, err = a.dispatchDelete(req) + case "AvailabilitySetsClient.Get": + resp, err = a.dispatchGet(req) + case "AvailabilitySetsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "AvailabilitySetsClient.NewListAvailableSizesPager": + resp, err = a.dispatchNewListAvailableSizesPager(req) + case "AvailabilitySetsClient.NewListBySubscriptionPager": + resp, err = a.dispatchNewListBySubscriptionPager(req) + case "AvailabilitySetsClient.Update": + resp, err = a.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AvailabilitySetsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.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-_]+)/providers/Microsoft.Compute/availabilitySets/(?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[armcompute.AvailabilitySet](req) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], 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).AvailabilitySet, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AvailabilitySetsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if a.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("method Delete not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets/(?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 := a.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], 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 (a *AvailabilitySetsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.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.Compute/availabilitySets/(?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 := a.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], 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).AvailabilitySet, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AvailabilitySetsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if a.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets" + 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) + } + resp := a.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armcompute.AvailabilitySetsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListPager) { + a.newListPager = nil + } + return resp, nil +} + +func (a *AvailabilitySetsServerTransport) dispatchNewListAvailableSizesPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListAvailableSizesPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAvailableSizesPager not implemented")} + } + if a.newListAvailableSizesPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets/(?P[a-zA-Z0-9-_]+)/vmSizes" + 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) + } + resp := a.srv.NewListAvailableSizesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], nil) + a.newListAvailableSizesPager = &resp + } + resp, err := server.PagerResponderNext(a.newListAvailableSizesPager, 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(a.newListAvailableSizesPager) { + a.newListAvailableSizesPager = nil + } + return resp, nil +} + +func (a *AvailabilitySetsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + } + if a.newListBySubscriptionPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets" + 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 *armcompute.AvailabilitySetsClientListBySubscriptionOptions + if expandParam != nil { + options = &armcompute.AvailabilitySetsClientListBySubscriptionOptions{ + Expand: expandParam, + } + } + resp := a.srv.NewListBySubscriptionPager(options) + a.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(a.newListBySubscriptionPager, req, func(page *armcompute.AvailabilitySetsClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.newListBySubscriptionPager, 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(a.newListBySubscriptionPager) { + a.newListBySubscriptionPager = nil + } + return resp, nil +} + +func (a *AvailabilitySetsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if a.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-_]+)/providers/Microsoft.Compute/availabilitySets/(?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[armcompute.AvailabilitySetUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], 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).AvailabilitySet, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go b/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go new file mode 100644 index 000000000000..782aed79e85b --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go @@ -0,0 +1,291 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CapacityReservationGroupsServer is a fake server for instances of the armcompute.CapacityReservationGroupsClient type. +type CapacityReservationGroupsServer struct { + // CreateOrUpdate is the fake for method CapacityReservationGroupsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, parameters armcompute.CapacityReservationGroup, options *armcompute.CapacityReservationGroupsClientCreateOrUpdateOptions) (resp azfake.Responder[armcompute.CapacityReservationGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method CapacityReservationGroupsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, options *armcompute.CapacityReservationGroupsClientDeleteOptions) (resp azfake.Responder[armcompute.CapacityReservationGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method CapacityReservationGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, options *armcompute.CapacityReservationGroupsClientGetOptions) (resp azfake.Responder[armcompute.CapacityReservationGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method CapacityReservationGroupsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.CapacityReservationGroupsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.CapacityReservationGroupsClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method CapacityReservationGroupsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armcompute.CapacityReservationGroupsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armcompute.CapacityReservationGroupsClientListBySubscriptionResponse]) + + // Update is the fake for method CapacityReservationGroupsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, parameters armcompute.CapacityReservationGroupUpdate, options *armcompute.CapacityReservationGroupsClientUpdateOptions) (resp azfake.Responder[armcompute.CapacityReservationGroupsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewCapacityReservationGroupsServerTransport creates a new instance of CapacityReservationGroupsServerTransport with the provided implementation. +// The returned CapacityReservationGroupsServerTransport instance is connected to an instance of armcompute.CapacityReservationGroupsClient by way of the +// undefined.Transporter field. +func NewCapacityReservationGroupsServerTransport(srv *CapacityReservationGroupsServer) *CapacityReservationGroupsServerTransport { + return &CapacityReservationGroupsServerTransport{srv: srv} +} + +// CapacityReservationGroupsServerTransport connects instances of armcompute.CapacityReservationGroupsClient to instances of CapacityReservationGroupsServer. +// Don't use this type directly, use NewCapacityReservationGroupsServerTransport instead. +type CapacityReservationGroupsServerTransport struct { + srv *CapacityReservationGroupsServer + newListByResourceGroupPager *azfake.PagerResponder[armcompute.CapacityReservationGroupsClientListByResourceGroupResponse] + newListBySubscriptionPager *azfake.PagerResponder[armcompute.CapacityReservationGroupsClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for CapacityReservationGroupsServerTransport. +func (c *CapacityReservationGroupsServerTransport) 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 "CapacityReservationGroupsClient.CreateOrUpdate": + resp, err = c.dispatchCreateOrUpdate(req) + case "CapacityReservationGroupsClient.Delete": + resp, err = c.dispatchDelete(req) + case "CapacityReservationGroupsClient.Get": + resp, err = c.dispatchGet(req) + case "CapacityReservationGroupsClient.NewListByResourceGroupPager": + resp, err = c.dispatchNewListByResourceGroupPager(req) + case "CapacityReservationGroupsClient.NewListBySubscriptionPager": + resp, err = c.dispatchNewListBySubscriptionPager(req) + case "CapacityReservationGroupsClient.Update": + resp, err = c.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CapacityReservationGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.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-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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[armcompute.CapacityReservationGroup](req) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], 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).CapacityReservationGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CapacityReservationGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if c.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("method Delete not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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 := c.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], 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 (c *CapacityReservationGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.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.Compute/capacityReservationGroups/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.CapacityReservationGroupInstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.CapacityReservationGroupsClientGetOptions + if expandParam != nil { + options = &armcompute.CapacityReservationGroupsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], 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).CapacityReservationGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CapacityReservationGroupsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + } + if c.newListByResourceGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups" + 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(armcompute.ExpandTypesForGetCapacityReservationGroups(qp.Get("$expand"))) + var options *armcompute.CapacityReservationGroupsClientListByResourceGroupOptions + if expandParam != nil { + options = &armcompute.CapacityReservationGroupsClientListByResourceGroupOptions{ + Expand: expandParam, + } + } + resp := c.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], options) + c.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(c.newListByResourceGroupPager, req, func(page *armcompute.CapacityReservationGroupsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.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(c.newListByResourceGroupPager) { + c.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (c *CapacityReservationGroupsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + } + if c.newListBySubscriptionPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups" + 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(armcompute.ExpandTypesForGetCapacityReservationGroups(qp.Get("$expand"))) + var options *armcompute.CapacityReservationGroupsClientListBySubscriptionOptions + if expandParam != nil { + options = &armcompute.CapacityReservationGroupsClientListBySubscriptionOptions{ + Expand: expandParam, + } + } + resp := c.srv.NewListBySubscriptionPager(options) + c.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(c.newListBySubscriptionPager, req, func(page *armcompute.CapacityReservationGroupsClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListBySubscriptionPager, 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(c.newListBySubscriptionPager) { + c.newListBySubscriptionPager = nil + } + return resp, nil +} + +func (c *CapacityReservationGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if c.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-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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[armcompute.CapacityReservationGroupUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], 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).CapacityReservationGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go b/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go new file mode 100644 index 000000000000..b9fc40370aba --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go @@ -0,0 +1,265 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CapacityReservationsServer is a fake server for instances of the armcompute.CapacityReservationsClient type. +type CapacityReservationsServer struct { + // BeginCreateOrUpdate is the fake for method CapacityReservationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, parameters armcompute.CapacityReservation, options *armcompute.CapacityReservationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.CapacityReservationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method CapacityReservationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, options *armcompute.CapacityReservationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.CapacityReservationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method CapacityReservationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, options *armcompute.CapacityReservationsClientGetOptions) (resp azfake.Responder[armcompute.CapacityReservationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByCapacityReservationGroupPager is the fake for method CapacityReservationsClient.NewListByCapacityReservationGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByCapacityReservationGroupPager func(resourceGroupName string, capacityReservationGroupName string, options *armcompute.CapacityReservationsClientListByCapacityReservationGroupOptions) (resp azfake.PagerResponder[armcompute.CapacityReservationsClientListByCapacityReservationGroupResponse]) + + // BeginUpdate is the fake for method CapacityReservationsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, capacityReservationGroupName string, capacityReservationName string, parameters armcompute.CapacityReservationUpdate, options *armcompute.CapacityReservationsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.CapacityReservationsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewCapacityReservationsServerTransport creates a new instance of CapacityReservationsServerTransport with the provided implementation. +// The returned CapacityReservationsServerTransport instance is connected to an instance of armcompute.CapacityReservationsClient by way of the +// undefined.Transporter field. +func NewCapacityReservationsServerTransport(srv *CapacityReservationsServer) *CapacityReservationsServerTransport { + return &CapacityReservationsServerTransport{srv: srv} +} + +// CapacityReservationsServerTransport connects instances of armcompute.CapacityReservationsClient to instances of CapacityReservationsServer. +// Don't use this type directly, use NewCapacityReservationsServerTransport instead. +type CapacityReservationsServerTransport struct { + srv *CapacityReservationsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.CapacityReservationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.CapacityReservationsClientDeleteResponse] + newListByCapacityReservationGroupPager *azfake.PagerResponder[armcompute.CapacityReservationsClientListByCapacityReservationGroupResponse] + beginUpdate *azfake.PollerResponder[armcompute.CapacityReservationsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for CapacityReservationsServerTransport. +func (c *CapacityReservationsServerTransport) 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 "CapacityReservationsClient.BeginCreateOrUpdate": + resp, err = c.dispatchBeginCreateOrUpdate(req) + case "CapacityReservationsClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "CapacityReservationsClient.Get": + resp, err = c.dispatchGet(req) + case "CapacityReservationsClient.NewListByCapacityReservationGroupPager": + resp, err = c.dispatchNewListByCapacityReservationGroupPager(req) + case "CapacityReservationsClient.BeginUpdate": + resp, err = c.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CapacityReservationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if c.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.CapacityReservation](req) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(c.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(c.beginCreateOrUpdate) { + c.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (c *CapacityReservationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if c.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?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 := c.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(c.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(c.beginDelete) { + c.beginDelete = nil + } + + return resp, nil +} + +func (c *CapacityReservationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.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.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.CapacityReservationInstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.CapacityReservationsClientGetOptions + if expandParam != nil { + options = &armcompute.CapacityReservationsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], 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).CapacityReservation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CapacityReservationsServerTransport) dispatchNewListByCapacityReservationGroupPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListByCapacityReservationGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByCapacityReservationGroupPager not implemented")} + } + if c.newListByCapacityReservationGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations" + 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) + } + resp := c.srv.NewListByCapacityReservationGroupPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], nil) + c.newListByCapacityReservationGroupPager = &resp + server.PagerResponderInjectNextLinks(c.newListByCapacityReservationGroupPager, req, func(page *armcompute.CapacityReservationsClientListByCapacityReservationGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListByCapacityReservationGroupPager, 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(c.newListByCapacityReservationGroupPager) { + c.newListByCapacityReservationGroupPager = nil + } + return resp, nil +} + +func (c *CapacityReservationsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if c.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.CapacityReservationUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(c.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(c.beginUpdate) { + c.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go new file mode 100644 index 000000000000..a45abb6bfc25 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go @@ -0,0 +1,197 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CloudServiceOperatingSystemsServer is a fake server for instances of the armcompute.CloudServiceOperatingSystemsClient type. +type CloudServiceOperatingSystemsServer struct { + // GetOSFamily is the fake for method CloudServiceOperatingSystemsClient.GetOSFamily + // HTTP status codes to indicate success: http.StatusOK + GetOSFamily func(ctx context.Context, location string, osFamilyName string, options *armcompute.CloudServiceOperatingSystemsClientGetOSFamilyOptions) (resp azfake.Responder[armcompute.CloudServiceOperatingSystemsClientGetOSFamilyResponse], errResp azfake.ErrorResponder) + + // GetOSVersion is the fake for method CloudServiceOperatingSystemsClient.GetOSVersion + // HTTP status codes to indicate success: http.StatusOK + GetOSVersion func(ctx context.Context, location string, osVersionName string, options *armcompute.CloudServiceOperatingSystemsClientGetOSVersionOptions) (resp azfake.Responder[armcompute.CloudServiceOperatingSystemsClientGetOSVersionResponse], errResp azfake.ErrorResponder) + + // NewListOSFamiliesPager is the fake for method CloudServiceOperatingSystemsClient.NewListOSFamiliesPager + // HTTP status codes to indicate success: http.StatusOK + NewListOSFamiliesPager func(location string, options *armcompute.CloudServiceOperatingSystemsClientListOSFamiliesOptions) (resp azfake.PagerResponder[armcompute.CloudServiceOperatingSystemsClientListOSFamiliesResponse]) + + // NewListOSVersionsPager is the fake for method CloudServiceOperatingSystemsClient.NewListOSVersionsPager + // HTTP status codes to indicate success: http.StatusOK + NewListOSVersionsPager func(location string, options *armcompute.CloudServiceOperatingSystemsClientListOSVersionsOptions) (resp azfake.PagerResponder[armcompute.CloudServiceOperatingSystemsClientListOSVersionsResponse]) +} + +// NewCloudServiceOperatingSystemsServerTransport creates a new instance of CloudServiceOperatingSystemsServerTransport with the provided implementation. +// The returned CloudServiceOperatingSystemsServerTransport instance is connected to an instance of armcompute.CloudServiceOperatingSystemsClient by way of the +// undefined.Transporter field. +func NewCloudServiceOperatingSystemsServerTransport(srv *CloudServiceOperatingSystemsServer) *CloudServiceOperatingSystemsServerTransport { + return &CloudServiceOperatingSystemsServerTransport{srv: srv} +} + +// CloudServiceOperatingSystemsServerTransport connects instances of armcompute.CloudServiceOperatingSystemsClient to instances of CloudServiceOperatingSystemsServer. +// Don't use this type directly, use NewCloudServiceOperatingSystemsServerTransport instead. +type CloudServiceOperatingSystemsServerTransport struct { + srv *CloudServiceOperatingSystemsServer + newListOSFamiliesPager *azfake.PagerResponder[armcompute.CloudServiceOperatingSystemsClientListOSFamiliesResponse] + newListOSVersionsPager *azfake.PagerResponder[armcompute.CloudServiceOperatingSystemsClientListOSVersionsResponse] +} + +// Do implements the policy.Transporter interface for CloudServiceOperatingSystemsServerTransport. +func (c *CloudServiceOperatingSystemsServerTransport) 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 "CloudServiceOperatingSystemsClient.GetOSFamily": + resp, err = c.dispatchGetOSFamily(req) + case "CloudServiceOperatingSystemsClient.GetOSVersion": + resp, err = c.dispatchGetOSVersion(req) + case "CloudServiceOperatingSystemsClient.NewListOSFamiliesPager": + resp, err = c.dispatchNewListOSFamiliesPager(req) + case "CloudServiceOperatingSystemsClient.NewListOSVersionsPager": + resp, err = c.dispatchNewListOSVersionsPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CloudServiceOperatingSystemsServerTransport) dispatchGetOSFamily(req *http.Request) (*http.Response, error) { + if c.srv.GetOSFamily == nil { + return nil, &nonRetriableError{errors.New("method GetOSFamily not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsFamilies/(?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 := c.srv.GetOSFamily(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("osFamilyName")], 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).OSFamily, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServiceOperatingSystemsServerTransport) dispatchGetOSVersion(req *http.Request) (*http.Response, error) { + if c.srv.GetOSVersion == nil { + return nil, &nonRetriableError{errors.New("method GetOSVersion not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsVersions/(?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 := c.srv.GetOSVersion(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("osVersionName")], 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).OSVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServiceOperatingSystemsServerTransport) dispatchNewListOSFamiliesPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListOSFamiliesPager == nil { + return nil, &nonRetriableError{errors.New("method NewListOSFamiliesPager not implemented")} + } + if c.newListOSFamiliesPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsFamilies" + 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) + } + resp := c.srv.NewListOSFamiliesPager(matches[regex.SubexpIndex("location")], nil) + c.newListOSFamiliesPager = &resp + server.PagerResponderInjectNextLinks(c.newListOSFamiliesPager, req, func(page *armcompute.CloudServiceOperatingSystemsClientListOSFamiliesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListOSFamiliesPager, 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(c.newListOSFamiliesPager) { + c.newListOSFamiliesPager = nil + } + return resp, nil +} + +func (c *CloudServiceOperatingSystemsServerTransport) dispatchNewListOSVersionsPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListOSVersionsPager == nil { + return nil, &nonRetriableError{errors.New("method NewListOSVersionsPager not implemented")} + } + if c.newListOSVersionsPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsVersions" + 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) + } + resp := c.srv.NewListOSVersionsPager(matches[regex.SubexpIndex("location")], nil) + c.newListOSVersionsPager = &resp + server.PagerResponderInjectNextLinks(c.newListOSVersionsPager, req, func(page *armcompute.CloudServiceOperatingSystemsClientListOSVersionsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListOSVersionsPager, 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(c.newListOSVersionsPager) { + c.newListOSVersionsPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go new file mode 100644 index 000000000000..61019ac6d8d6 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go @@ -0,0 +1,370 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CloudServiceRoleInstancesServer is a fake server for instances of the armcompute.CloudServiceRoleInstancesClient type. +type CloudServiceRoleInstancesServer struct { + // BeginDelete is the fake for method CloudServiceRoleInstancesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method CloudServiceRoleInstancesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientGetOptions) (resp azfake.Responder[armcompute.CloudServiceRoleInstancesClientGetResponse], errResp azfake.ErrorResponder) + + // GetInstanceView is the fake for method CloudServiceRoleInstancesClient.GetInstanceView + // HTTP status codes to indicate success: http.StatusOK + GetInstanceView func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientGetInstanceViewOptions) (resp azfake.Responder[armcompute.CloudServiceRoleInstancesClientGetInstanceViewResponse], errResp azfake.ErrorResponder) + + // GetRemoteDesktopFile is the fake for method CloudServiceRoleInstancesClient.GetRemoteDesktopFile + // HTTP status codes to indicate success: http.StatusOK + GetRemoteDesktopFile func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientGetRemoteDesktopFileOptions) (resp azfake.Responder[armcompute.CloudServiceRoleInstancesClientGetRemoteDesktopFileResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method CloudServiceRoleInstancesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientListOptions) (resp azfake.PagerResponder[armcompute.CloudServiceRoleInstancesClientListResponse]) + + // BeginRebuild is the fake for method CloudServiceRoleInstancesClient.BeginRebuild + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRebuild func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientBeginRebuildOptions) (resp azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientRebuildResponse], errResp azfake.ErrorResponder) + + // BeginReimage is the fake for method CloudServiceRoleInstancesClient.BeginReimage + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimage func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientBeginReimageOptions) (resp azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientReimageResponse], errResp azfake.ErrorResponder) + + // BeginRestart is the fake for method CloudServiceRoleInstancesClient.BeginRestart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRestart func(ctx context.Context, roleInstanceName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRoleInstancesClientBeginRestartOptions) (resp azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientRestartResponse], errResp azfake.ErrorResponder) +} + +// NewCloudServiceRoleInstancesServerTransport creates a new instance of CloudServiceRoleInstancesServerTransport with the provided implementation. +// The returned CloudServiceRoleInstancesServerTransport instance is connected to an instance of armcompute.CloudServiceRoleInstancesClient by way of the +// undefined.Transporter field. +func NewCloudServiceRoleInstancesServerTransport(srv *CloudServiceRoleInstancesServer) *CloudServiceRoleInstancesServerTransport { + return &CloudServiceRoleInstancesServerTransport{srv: srv} +} + +// CloudServiceRoleInstancesServerTransport connects instances of armcompute.CloudServiceRoleInstancesClient to instances of CloudServiceRoleInstancesServer. +// Don't use this type directly, use NewCloudServiceRoleInstancesServerTransport instead. +type CloudServiceRoleInstancesServerTransport struct { + srv *CloudServiceRoleInstancesServer + beginDelete *azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.CloudServiceRoleInstancesClientListResponse] + beginRebuild *azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientRebuildResponse] + beginReimage *azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientReimageResponse] + beginRestart *azfake.PollerResponder[armcompute.CloudServiceRoleInstancesClientRestartResponse] +} + +// Do implements the policy.Transporter interface for CloudServiceRoleInstancesServerTransport. +func (c *CloudServiceRoleInstancesServerTransport) 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 "CloudServiceRoleInstancesClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "CloudServiceRoleInstancesClient.Get": + resp, err = c.dispatchGet(req) + case "CloudServiceRoleInstancesClient.GetInstanceView": + resp, err = c.dispatchGetInstanceView(req) + case "CloudServiceRoleInstancesClient.GetRemoteDesktopFile": + resp, err = c.dispatchGetRemoteDesktopFile(req) + case "CloudServiceRoleInstancesClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + case "CloudServiceRoleInstancesClient.BeginRebuild": + resp, err = c.dispatchBeginRebuild(req) + case "CloudServiceRoleInstancesClient.BeginReimage": + resp, err = c.dispatchBeginReimage(req) + case "CloudServiceRoleInstancesClient.BeginRestart": + resp, err = c.dispatchBeginRestart(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if c.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?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 := c.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(c.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(c.beginDelete) { + c.beginDelete = nil + } + + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.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.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.CloudServiceRoleInstancesClientGetOptions + if expandParam != nil { + options = &armcompute.CloudServiceRoleInstancesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], 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).RoleInstance, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { + if c.srv.GetInstanceView == nil { + return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/instanceView" + 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 := c.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], 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).RoleInstanceView, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchGetRemoteDesktopFile(req *http.Request) (*http.Response, error) { + if c.srv.GetRemoteDesktopFile == nil { + return nil, &nonRetriableError{errors.New("method GetRemoteDesktopFile not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/remoteDesktopFile" + 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 := c.srv.GetRemoteDesktopFile(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], 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, &server.ResponseOptions{ + Body: server.GetResponse(respr).Body, + ContentType: "application/octet-stream", + }) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if c.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances" + 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() + expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.CloudServiceRoleInstancesClientListOptions + if expandParam != nil { + options = &armcompute.CloudServiceRoleInstancesClientListOptions{ + Expand: expandParam, + } + } + resp := c.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + c.newListPager = &resp + server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CloudServiceRoleInstancesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.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(c.newListPager) { + c.newListPager = nil + } + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginRebuild(req *http.Request) (*http.Response, error) { + if c.srv.BeginRebuild == nil { + return nil, &nonRetriableError{errors.New("method BeginRebuild not implemented")} + } + if c.beginRebuild == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/rebuild" + 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 := c.srv.BeginRebuild(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginRebuild = &respr + } + + resp, err := server.PollerResponderNext(c.beginRebuild, 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(c.beginRebuild) { + c.beginRebuild = nil + } + + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { + if c.srv.BeginReimage == nil { + return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + } + if c.beginReimage == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/reimage" + 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 := c.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginReimage = &respr + } + + resp, err := server.PollerResponderNext(c.beginReimage, 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(c.beginReimage) { + c.beginReimage = nil + } + + return resp, nil +} + +func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { + if c.srv.BeginRestart == nil { + return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + } + if c.beginRestart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/restart" + 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 := c.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginRestart = &respr + } + + resp, err := server.PollerResponderNext(c.beginRestart, 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(c.beginRestart) { + c.beginRestart = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go new file mode 100644 index 000000000000..ca84dd8464ab --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go @@ -0,0 +1,129 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CloudServiceRolesServer is a fake server for instances of the armcompute.CloudServiceRolesClient type. +type CloudServiceRolesServer struct { + // Get is the fake for method CloudServiceRolesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, roleName string, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRolesClientGetOptions) (resp azfake.Responder[armcompute.CloudServiceRolesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method CloudServiceRolesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, cloudServiceName string, options *armcompute.CloudServiceRolesClientListOptions) (resp azfake.PagerResponder[armcompute.CloudServiceRolesClientListResponse]) +} + +// NewCloudServiceRolesServerTransport creates a new instance of CloudServiceRolesServerTransport with the provided implementation. +// The returned CloudServiceRolesServerTransport instance is connected to an instance of armcompute.CloudServiceRolesClient by way of the +// undefined.Transporter field. +func NewCloudServiceRolesServerTransport(srv *CloudServiceRolesServer) *CloudServiceRolesServerTransport { + return &CloudServiceRolesServerTransport{srv: srv} +} + +// CloudServiceRolesServerTransport connects instances of armcompute.CloudServiceRolesClient to instances of CloudServiceRolesServer. +// Don't use this type directly, use NewCloudServiceRolesServerTransport instead. +type CloudServiceRolesServerTransport struct { + srv *CloudServiceRolesServer + newListPager *azfake.PagerResponder[armcompute.CloudServiceRolesClientListResponse] +} + +// Do implements the policy.Transporter interface for CloudServiceRolesServerTransport. +func (c *CloudServiceRolesServerTransport) 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 "CloudServiceRolesClient.Get": + resp, err = c.dispatchGet(req) + case "CloudServiceRolesClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CloudServiceRolesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.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.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roles/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("roleName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], 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).CloudServiceRole, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServiceRolesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if c.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roles" + 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) + } + resp := c.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + c.newListPager = &resp + server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CloudServiceRolesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.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(c.newListPager) { + c.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go new file mode 100644 index 000000000000..52a539823adb --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go @@ -0,0 +1,606 @@ +//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/compute/armcompute/v5" + "net/http" + "reflect" + "regexp" +) + +// CloudServicesServer is a fake server for instances of the armcompute.CloudServicesClient type. +type CloudServicesServer struct { + // BeginCreateOrUpdate is the fake for method CloudServicesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, cloudServiceName string, parameters armcompute.CloudService, options *armcompute.CloudServicesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method CloudServicesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteInstances is the fake for method CloudServicesClient.BeginDeleteInstances + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDeleteInstances func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginDeleteInstancesOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientDeleteInstancesResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method CloudServicesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientGetOptions) (resp azfake.Responder[armcompute.CloudServicesClientGetResponse], errResp azfake.ErrorResponder) + + // GetInstanceView is the fake for method CloudServicesClient.GetInstanceView + // HTTP status codes to indicate success: http.StatusOK + GetInstanceView func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientGetInstanceViewOptions) (resp azfake.Responder[armcompute.CloudServicesClientGetInstanceViewResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method CloudServicesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armcompute.CloudServicesClientListOptions) (resp azfake.PagerResponder[armcompute.CloudServicesClientListResponse]) + + // NewListAllPager is the fake for method CloudServicesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armcompute.CloudServicesClientListAllOptions) (resp azfake.PagerResponder[armcompute.CloudServicesClientListAllResponse]) + + // BeginPowerOff is the fake for method CloudServicesClient.BeginPowerOff + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPowerOff func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginPowerOffOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientPowerOffResponse], errResp azfake.ErrorResponder) + + // BeginRebuild is the fake for method CloudServicesClient.BeginRebuild + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRebuild func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginRebuildOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientRebuildResponse], errResp azfake.ErrorResponder) + + // BeginReimage is the fake for method CloudServicesClient.BeginReimage + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimage func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginReimageOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientReimageResponse], errResp azfake.ErrorResponder) + + // BeginRestart is the fake for method CloudServicesClient.BeginRestart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRestart func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginRestartOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientRestartResponse], errResp azfake.ErrorResponder) + + // BeginStart is the fake for method CloudServicesClient.BeginStart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStart func(ctx context.Context, resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesClientBeginStartOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientStartResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method CloudServicesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, cloudServiceName string, parameters armcompute.CloudServiceUpdate, options *armcompute.CloudServicesClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.CloudServicesClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewCloudServicesServerTransport creates a new instance of CloudServicesServerTransport with the provided implementation. +// The returned CloudServicesServerTransport instance is connected to an instance of armcompute.CloudServicesClient by way of the +// undefined.Transporter field. +func NewCloudServicesServerTransport(srv *CloudServicesServer) *CloudServicesServerTransport { + return &CloudServicesServerTransport{srv: srv} +} + +// CloudServicesServerTransport connects instances of armcompute.CloudServicesClient to instances of CloudServicesServer. +// Don't use this type directly, use NewCloudServicesServerTransport instead. +type CloudServicesServerTransport struct { + srv *CloudServicesServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.CloudServicesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.CloudServicesClientDeleteResponse] + beginDeleteInstances *azfake.PollerResponder[armcompute.CloudServicesClientDeleteInstancesResponse] + newListPager *azfake.PagerResponder[armcompute.CloudServicesClientListResponse] + newListAllPager *azfake.PagerResponder[armcompute.CloudServicesClientListAllResponse] + beginPowerOff *azfake.PollerResponder[armcompute.CloudServicesClientPowerOffResponse] + beginRebuild *azfake.PollerResponder[armcompute.CloudServicesClientRebuildResponse] + beginReimage *azfake.PollerResponder[armcompute.CloudServicesClientReimageResponse] + beginRestart *azfake.PollerResponder[armcompute.CloudServicesClientRestartResponse] + beginStart *azfake.PollerResponder[armcompute.CloudServicesClientStartResponse] + beginUpdate *azfake.PollerResponder[armcompute.CloudServicesClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for CloudServicesServerTransport. +func (c *CloudServicesServerTransport) 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 "CloudServicesClient.BeginCreateOrUpdate": + resp, err = c.dispatchBeginCreateOrUpdate(req) + case "CloudServicesClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "CloudServicesClient.BeginDeleteInstances": + resp, err = c.dispatchBeginDeleteInstances(req) + case "CloudServicesClient.Get": + resp, err = c.dispatchGet(req) + case "CloudServicesClient.GetInstanceView": + resp, err = c.dispatchGetInstanceView(req) + case "CloudServicesClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + case "CloudServicesClient.NewListAllPager": + resp, err = c.dispatchNewListAllPager(req) + case "CloudServicesClient.BeginPowerOff": + resp, err = c.dispatchBeginPowerOff(req) + case "CloudServicesClient.BeginRebuild": + resp, err = c.dispatchBeginRebuild(req) + case "CloudServicesClient.BeginReimage": + resp, err = c.dispatchBeginReimage(req) + case "CloudServicesClient.BeginRestart": + resp, err = c.dispatchBeginRestart(req) + case "CloudServicesClient.BeginStart": + resp, err = c.dispatchBeginStart(req) + case "CloudServicesClient.BeginUpdate": + resp, err = c.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if c.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?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[armcompute.CloudService](req) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(c.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(c.beginCreateOrUpdate) { + c.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if c.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?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 := c.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(c.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(c.beginDelete) { + c.beginDelete = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginDeleteInstances(req *http.Request) (*http.Response, error) { + if c.srv.BeginDeleteInstances == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteInstances not implemented")} + } + if c.beginDeleteInstances == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/delete" + 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[armcompute.RoleInstances](req) + if err != nil { + return nil, err + } + var options *armcompute.CloudServicesClientBeginDeleteInstancesOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.CloudServicesClientBeginDeleteInstancesOptions{ + Parameters: &body, + } + } + respr, errRespr := c.srv.BeginDeleteInstances(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginDeleteInstances = &respr + } + + resp, err := server.PollerResponderNext(c.beginDeleteInstances, 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(c.beginDeleteInstances) { + c.beginDeleteInstances = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.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.Compute/cloudServices/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], 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).CloudService, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { + if c.srv.GetInstanceView == nil { + return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/instanceView" + 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 := c.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], 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).CloudServiceInstanceView, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if c.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices" + 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) + } + resp := c.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + c.newListPager = &resp + server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CloudServicesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.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(c.newListPager) { + c.newListPager = nil + } + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + } + if c.newListAllPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices" + 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 := c.srv.NewListAllPager(nil) + c.newListAllPager = &resp + server.PagerResponderInjectNextLinks(c.newListAllPager, req, func(page *armcompute.CloudServicesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListAllPager, 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(c.newListAllPager) { + c.newListAllPager = nil + } + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { + if c.srv.BeginPowerOff == nil { + return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + } + if c.beginPowerOff == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/poweroff" + 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 := c.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginPowerOff = &respr + } + + resp, err := server.PollerResponderNext(c.beginPowerOff, 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(c.beginPowerOff) { + c.beginPowerOff = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginRebuild(req *http.Request) (*http.Response, error) { + if c.srv.BeginRebuild == nil { + return nil, &nonRetriableError{errors.New("method BeginRebuild not implemented")} + } + if c.beginRebuild == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/rebuild" + 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[armcompute.RoleInstances](req) + if err != nil { + return nil, err + } + var options *armcompute.CloudServicesClientBeginRebuildOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.CloudServicesClientBeginRebuildOptions{ + Parameters: &body, + } + } + respr, errRespr := c.srv.BeginRebuild(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginRebuild = &respr + } + + resp, err := server.PollerResponderNext(c.beginRebuild, 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(c.beginRebuild) { + c.beginRebuild = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { + if c.srv.BeginReimage == nil { + return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + } + if c.beginReimage == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/reimage" + 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[armcompute.RoleInstances](req) + if err != nil { + return nil, err + } + var options *armcompute.CloudServicesClientBeginReimageOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.CloudServicesClientBeginReimageOptions{ + Parameters: &body, + } + } + respr, errRespr := c.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginReimage = &respr + } + + resp, err := server.PollerResponderNext(c.beginReimage, 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(c.beginReimage) { + c.beginReimage = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { + if c.srv.BeginRestart == nil { + return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + } + if c.beginRestart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/restart" + 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[armcompute.RoleInstances](req) + if err != nil { + return nil, err + } + var options *armcompute.CloudServicesClientBeginRestartOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.CloudServicesClientBeginRestartOptions{ + Parameters: &body, + } + } + respr, errRespr := c.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginRestart = &respr + } + + resp, err := server.PollerResponderNext(c.beginRestart, 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(c.beginRestart) { + c.beginRestart = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { + if c.srv.BeginStart == nil { + return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + } + if c.beginStart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/start" + 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 := c.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginStart = &respr + } + + resp, err := server.PollerResponderNext(c.beginStart, 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(c.beginStart) { + c.beginStart = nil + } + + return resp, nil +} + +func (c *CloudServicesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if c.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?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[armcompute.CloudServiceUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(c.beginUpdate, 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.PollerResponderMore(c.beginUpdate) { + c.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go new file mode 100644 index 000000000000..8db1b276eb87 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go @@ -0,0 +1,194 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" + "strconv" +) + +// CloudServicesUpdateDomainServer is a fake server for instances of the armcompute.CloudServicesUpdateDomainClient type. +type CloudServicesUpdateDomainServer struct { + // GetUpdateDomain is the fake for method CloudServicesUpdateDomainClient.GetUpdateDomain + // HTTP status codes to indicate success: http.StatusOK + GetUpdateDomain func(ctx context.Context, resourceGroupName string, cloudServiceName string, updateDomain int32, options *armcompute.CloudServicesUpdateDomainClientGetUpdateDomainOptions) (resp azfake.Responder[armcompute.CloudServicesUpdateDomainClientGetUpdateDomainResponse], errResp azfake.ErrorResponder) + + // NewListUpdateDomainsPager is the fake for method CloudServicesUpdateDomainClient.NewListUpdateDomainsPager + // HTTP status codes to indicate success: http.StatusOK + NewListUpdateDomainsPager func(resourceGroupName string, cloudServiceName string, options *armcompute.CloudServicesUpdateDomainClientListUpdateDomainsOptions) (resp azfake.PagerResponder[armcompute.CloudServicesUpdateDomainClientListUpdateDomainsResponse]) + + // BeginWalkUpdateDomain is the fake for method CloudServicesUpdateDomainClient.BeginWalkUpdateDomain + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginWalkUpdateDomain func(ctx context.Context, resourceGroupName string, cloudServiceName string, updateDomain int32, parameters armcompute.UpdateDomain, options *armcompute.CloudServicesUpdateDomainClientBeginWalkUpdateDomainOptions) (resp azfake.PollerResponder[armcompute.CloudServicesUpdateDomainClientWalkUpdateDomainResponse], errResp azfake.ErrorResponder) +} + +// NewCloudServicesUpdateDomainServerTransport creates a new instance of CloudServicesUpdateDomainServerTransport with the provided implementation. +// The returned CloudServicesUpdateDomainServerTransport instance is connected to an instance of armcompute.CloudServicesUpdateDomainClient by way of the +// undefined.Transporter field. +func NewCloudServicesUpdateDomainServerTransport(srv *CloudServicesUpdateDomainServer) *CloudServicesUpdateDomainServerTransport { + return &CloudServicesUpdateDomainServerTransport{srv: srv} +} + +// CloudServicesUpdateDomainServerTransport connects instances of armcompute.CloudServicesUpdateDomainClient to instances of CloudServicesUpdateDomainServer. +// Don't use this type directly, use NewCloudServicesUpdateDomainServerTransport instead. +type CloudServicesUpdateDomainServerTransport struct { + srv *CloudServicesUpdateDomainServer + newListUpdateDomainsPager *azfake.PagerResponder[armcompute.CloudServicesUpdateDomainClientListUpdateDomainsResponse] + beginWalkUpdateDomain *azfake.PollerResponder[armcompute.CloudServicesUpdateDomainClientWalkUpdateDomainResponse] +} + +// Do implements the policy.Transporter interface for CloudServicesUpdateDomainServerTransport. +func (c *CloudServicesUpdateDomainServerTransport) 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 "CloudServicesUpdateDomainClient.GetUpdateDomain": + resp, err = c.dispatchGetUpdateDomain(req) + case "CloudServicesUpdateDomainClient.NewListUpdateDomainsPager": + resp, err = c.dispatchNewListUpdateDomainsPager(req) + case "CloudServicesUpdateDomainClient.BeginWalkUpdateDomain": + resp, err = c.dispatchBeginWalkUpdateDomain(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CloudServicesUpdateDomainServerTransport) dispatchGetUpdateDomain(req *http.Request) (*http.Response, error) { + if c.srv.GetUpdateDomain == nil { + return nil, &nonRetriableError{errors.New("method GetUpdateDomain not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/updateDomains/(?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) + } + updateDomainParam, err := parseWithCast(matches[regex.SubexpIndex("updateDomain")], 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 + } + respr, errRespr := c.srv.GetUpdateDomain(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], int32(updateDomainParam), 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).UpdateDomain, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CloudServicesUpdateDomainServerTransport) dispatchNewListUpdateDomainsPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListUpdateDomainsPager == nil { + return nil, &nonRetriableError{errors.New("method NewListUpdateDomainsPager not implemented")} + } + if c.newListUpdateDomainsPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/updateDomains" + 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) + } + resp := c.srv.NewListUpdateDomainsPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + c.newListUpdateDomainsPager = &resp + server.PagerResponderInjectNextLinks(c.newListUpdateDomainsPager, req, func(page *armcompute.CloudServicesUpdateDomainClientListUpdateDomainsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListUpdateDomainsPager, 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(c.newListUpdateDomainsPager) { + c.newListUpdateDomainsPager = nil + } + return resp, nil +} + +func (c *CloudServicesUpdateDomainServerTransport) dispatchBeginWalkUpdateDomain(req *http.Request) (*http.Response, error) { + if c.srv.BeginWalkUpdateDomain == nil { + return nil, &nonRetriableError{errors.New("method BeginWalkUpdateDomain not implemented")} + } + if c.beginWalkUpdateDomain == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/updateDomains/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.UpdateDomain](req) + if err != nil { + return nil, err + } + updateDomainParam, err := parseWithCast(matches[regex.SubexpIndex("updateDomain")], 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 + } + respr, errRespr := c.srv.BeginWalkUpdateDomain(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], int32(updateDomainParam), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginWalkUpdateDomain = &respr + } + + resp, err := server.PollerResponderNext(c.beginWalkUpdateDomain, 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(c.beginWalkUpdateDomain) { + c.beginWalkUpdateDomain = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go b/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go new file mode 100644 index 000000000000..b87f0c904983 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go @@ -0,0 +1,91 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CommunityGalleriesServer is a fake server for instances of the armcompute.CommunityGalleriesClient type. +type CommunityGalleriesServer struct { + // Get is the fake for method CommunityGalleriesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, publicGalleryName string, options *armcompute.CommunityGalleriesClientGetOptions) (resp azfake.Responder[armcompute.CommunityGalleriesClientGetResponse], errResp azfake.ErrorResponder) +} + +// NewCommunityGalleriesServerTransport creates a new instance of CommunityGalleriesServerTransport with the provided implementation. +// The returned CommunityGalleriesServerTransport instance is connected to an instance of armcompute.CommunityGalleriesClient by way of the +// undefined.Transporter field. +func NewCommunityGalleriesServerTransport(srv *CommunityGalleriesServer) *CommunityGalleriesServerTransport { + return &CommunityGalleriesServerTransport{srv: srv} +} + +// CommunityGalleriesServerTransport connects instances of armcompute.CommunityGalleriesClient to instances of CommunityGalleriesServer. +// Don't use this type directly, use NewCommunityGalleriesServerTransport instead. +type CommunityGalleriesServerTransport struct { + srv *CommunityGalleriesServer +} + +// Do implements the policy.Transporter interface for CommunityGalleriesServerTransport. +func (c *CommunityGalleriesServerTransport) 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 "CommunityGalleriesClient.Get": + resp, err = c.dispatchGet(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CommunityGalleriesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], 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).CommunityGallery, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go new file mode 100644 index 000000000000..23a3c4e19b07 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go @@ -0,0 +1,129 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CommunityGalleryImagesServer is a fake server for instances of the armcompute.CommunityGalleryImagesClient type. +type CommunityGalleryImagesServer struct { + // Get is the fake for method CommunityGalleryImagesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, publicGalleryName string, galleryImageName string, options *armcompute.CommunityGalleryImagesClientGetOptions) (resp azfake.Responder[armcompute.CommunityGalleryImagesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method CommunityGalleryImagesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, publicGalleryName string, options *armcompute.CommunityGalleryImagesClientListOptions) (resp azfake.PagerResponder[armcompute.CommunityGalleryImagesClientListResponse]) +} + +// NewCommunityGalleryImagesServerTransport creates a new instance of CommunityGalleryImagesServerTransport with the provided implementation. +// The returned CommunityGalleryImagesServerTransport instance is connected to an instance of armcompute.CommunityGalleryImagesClient by way of the +// undefined.Transporter field. +func NewCommunityGalleryImagesServerTransport(srv *CommunityGalleryImagesServer) *CommunityGalleryImagesServerTransport { + return &CommunityGalleryImagesServerTransport{srv: srv} +} + +// CommunityGalleryImagesServerTransport connects instances of armcompute.CommunityGalleryImagesClient to instances of CommunityGalleryImagesServer. +// Don't use this type directly, use NewCommunityGalleryImagesServerTransport instead. +type CommunityGalleryImagesServerTransport struct { + srv *CommunityGalleryImagesServer + newListPager *azfake.PagerResponder[armcompute.CommunityGalleryImagesClientListResponse] +} + +// Do implements the policy.Transporter interface for CommunityGalleryImagesServerTransport. +func (c *CommunityGalleryImagesServerTransport) 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 "CommunityGalleryImagesClient.Get": + resp, err = c.dispatchGet(req) + case "CommunityGalleryImagesClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CommunityGalleryImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], matches[regex.SubexpIndex("galleryImageName")], 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).CommunityGalleryImage, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CommunityGalleryImagesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if c.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images" + 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) + } + resp := c.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], nil) + c.newListPager = &resp + server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CommunityGalleryImagesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.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(c.newListPager) { + c.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go new file mode 100644 index 000000000000..c7a8627a56fe --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go @@ -0,0 +1,129 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// CommunityGalleryImageVersionsServer is a fake server for instances of the armcompute.CommunityGalleryImageVersionsClient type. +type CommunityGalleryImageVersionsServer struct { + // Get is the fake for method CommunityGalleryImageVersionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, publicGalleryName string, galleryImageName string, galleryImageVersionName string, options *armcompute.CommunityGalleryImageVersionsClientGetOptions) (resp azfake.Responder[armcompute.CommunityGalleryImageVersionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method CommunityGalleryImageVersionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, publicGalleryName string, galleryImageName string, options *armcompute.CommunityGalleryImageVersionsClientListOptions) (resp azfake.PagerResponder[armcompute.CommunityGalleryImageVersionsClientListResponse]) +} + +// NewCommunityGalleryImageVersionsServerTransport creates a new instance of CommunityGalleryImageVersionsServerTransport with the provided implementation. +// The returned CommunityGalleryImageVersionsServerTransport instance is connected to an instance of armcompute.CommunityGalleryImageVersionsClient by way of the +// undefined.Transporter field. +func NewCommunityGalleryImageVersionsServerTransport(srv *CommunityGalleryImageVersionsServer) *CommunityGalleryImageVersionsServerTransport { + return &CommunityGalleryImageVersionsServerTransport{srv: srv} +} + +// CommunityGalleryImageVersionsServerTransport connects instances of armcompute.CommunityGalleryImageVersionsClient to instances of CommunityGalleryImageVersionsServer. +// Don't use this type directly, use NewCommunityGalleryImageVersionsServerTransport instead. +type CommunityGalleryImageVersionsServerTransport struct { + srv *CommunityGalleryImageVersionsServer + newListPager *azfake.PagerResponder[armcompute.CommunityGalleryImageVersionsClientListResponse] +} + +// Do implements the policy.Transporter interface for CommunityGalleryImageVersionsServerTransport. +func (c *CommunityGalleryImageVersionsServerTransport) 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 "CommunityGalleryImageVersionsClient.Get": + resp, err = c.dispatchGet(req) + case "CommunityGalleryImageVersionsClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CommunityGalleryImageVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], 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).CommunityGalleryImageVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CommunityGalleryImageVersionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if c.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions" + 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) + } + resp := c.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + c.newListPager = &resp + server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CommunityGalleryImageVersionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.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(c.newListPager) { + c.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go new file mode 100644 index 000000000000..66f889598d4c --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go @@ -0,0 +1,275 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// DedicatedHostGroupsServer is a fake server for instances of the armcompute.DedicatedHostGroupsClient type. +type DedicatedHostGroupsServer struct { + // CreateOrUpdate is the fake for method DedicatedHostGroupsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, hostGroupName string, parameters armcompute.DedicatedHostGroup, options *armcompute.DedicatedHostGroupsClientCreateOrUpdateOptions) (resp azfake.Responder[armcompute.DedicatedHostGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method DedicatedHostGroupsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, hostGroupName string, options *armcompute.DedicatedHostGroupsClientDeleteOptions) (resp azfake.Responder[armcompute.DedicatedHostGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DedicatedHostGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, hostGroupName string, options *armcompute.DedicatedHostGroupsClientGetOptions) (resp azfake.Responder[armcompute.DedicatedHostGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method DedicatedHostGroupsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.DedicatedHostGroupsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.DedicatedHostGroupsClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method DedicatedHostGroupsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armcompute.DedicatedHostGroupsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armcompute.DedicatedHostGroupsClientListBySubscriptionResponse]) + + // Update is the fake for method DedicatedHostGroupsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, hostGroupName string, parameters armcompute.DedicatedHostGroupUpdate, options *armcompute.DedicatedHostGroupsClientUpdateOptions) (resp azfake.Responder[armcompute.DedicatedHostGroupsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewDedicatedHostGroupsServerTransport creates a new instance of DedicatedHostGroupsServerTransport with the provided implementation. +// The returned DedicatedHostGroupsServerTransport instance is connected to an instance of armcompute.DedicatedHostGroupsClient by way of the +// undefined.Transporter field. +func NewDedicatedHostGroupsServerTransport(srv *DedicatedHostGroupsServer) *DedicatedHostGroupsServerTransport { + return &DedicatedHostGroupsServerTransport{srv: srv} +} + +// DedicatedHostGroupsServerTransport connects instances of armcompute.DedicatedHostGroupsClient to instances of DedicatedHostGroupsServer. +// Don't use this type directly, use NewDedicatedHostGroupsServerTransport instead. +type DedicatedHostGroupsServerTransport struct { + srv *DedicatedHostGroupsServer + newListByResourceGroupPager *azfake.PagerResponder[armcompute.DedicatedHostGroupsClientListByResourceGroupResponse] + newListBySubscriptionPager *azfake.PagerResponder[armcompute.DedicatedHostGroupsClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for DedicatedHostGroupsServerTransport. +func (d *DedicatedHostGroupsServerTransport) 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 "DedicatedHostGroupsClient.CreateOrUpdate": + resp, err = d.dispatchCreateOrUpdate(req) + case "DedicatedHostGroupsClient.Delete": + resp, err = d.dispatchDelete(req) + case "DedicatedHostGroupsClient.Get": + resp, err = d.dispatchGet(req) + case "DedicatedHostGroupsClient.NewListByResourceGroupPager": + resp, err = d.dispatchNewListByResourceGroupPager(req) + case "DedicatedHostGroupsClient.NewListBySubscriptionPager": + resp, err = d.dispatchNewListBySubscriptionPager(req) + case "DedicatedHostGroupsClient.Update": + resp, err = d.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DedicatedHostGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if d.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-_]+)/providers/Microsoft.Compute/hostGroups/(?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[armcompute.DedicatedHostGroup](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], 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).DedicatedHostGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DedicatedHostGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if d.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("method Delete not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?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.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], 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 (d *DedicatedHostGroupsServerTransport) 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.Compute/hostGroups/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.DedicatedHostGroupsClientGetOptions + if expandParam != nil { + options = &armcompute.DedicatedHostGroupsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], 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).DedicatedHostGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DedicatedHostGroupsServerTransport) 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.Compute/hostGroups" + 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) + } + resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + d.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DedicatedHostGroupsClientListByResourceGroupResponse, 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 *DedicatedHostGroupsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + } + if d.newListBySubscriptionPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups" + 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 := d.srv.NewListBySubscriptionPager(nil) + d.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(d.newListBySubscriptionPager, req, func(page *armcompute.DedicatedHostGroupsClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListBySubscriptionPager, 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.newListBySubscriptionPager) { + d.newListBySubscriptionPager = nil + } + return resp, nil +} + +func (d *DedicatedHostGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if d.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-_]+)/providers/Microsoft.Compute/hostGroups/(?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[armcompute.DedicatedHostGroupUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], 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).DedicatedHostGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go new file mode 100644 index 000000000000..c779a3ecd685 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go @@ -0,0 +1,339 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// DedicatedHostsServer is a fake server for instances of the armcompute.DedicatedHostsClient type. +type DedicatedHostsServer struct { + // BeginCreateOrUpdate is the fake for method DedicatedHostsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters armcompute.DedicatedHost, options *armcompute.DedicatedHostsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.DedicatedHostsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DedicatedHostsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, options *armcompute.DedicatedHostsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.DedicatedHostsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DedicatedHostsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, options *armcompute.DedicatedHostsClientGetOptions) (resp azfake.Responder[armcompute.DedicatedHostsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListAvailableSizesPager is the fake for method DedicatedHostsClient.NewListAvailableSizesPager + // HTTP status codes to indicate success: http.StatusOK + NewListAvailableSizesPager func(resourceGroupName string, hostGroupName string, hostName string, options *armcompute.DedicatedHostsClientListAvailableSizesOptions) (resp azfake.PagerResponder[armcompute.DedicatedHostsClientListAvailableSizesResponse]) + + // NewListByHostGroupPager is the fake for method DedicatedHostsClient.NewListByHostGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByHostGroupPager func(resourceGroupName string, hostGroupName string, options *armcompute.DedicatedHostsClientListByHostGroupOptions) (resp azfake.PagerResponder[armcompute.DedicatedHostsClientListByHostGroupResponse]) + + // BeginRestart is the fake for method DedicatedHostsClient.BeginRestart + // HTTP status codes to indicate success: http.StatusOK + BeginRestart func(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, options *armcompute.DedicatedHostsClientBeginRestartOptions) (resp azfake.PollerResponder[armcompute.DedicatedHostsClientRestartResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method DedicatedHostsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters armcompute.DedicatedHostUpdate, options *armcompute.DedicatedHostsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.DedicatedHostsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewDedicatedHostsServerTransport creates a new instance of DedicatedHostsServerTransport with the provided implementation. +// The returned DedicatedHostsServerTransport instance is connected to an instance of armcompute.DedicatedHostsClient by way of the +// undefined.Transporter field. +func NewDedicatedHostsServerTransport(srv *DedicatedHostsServer) *DedicatedHostsServerTransport { + return &DedicatedHostsServerTransport{srv: srv} +} + +// DedicatedHostsServerTransport connects instances of armcompute.DedicatedHostsClient to instances of DedicatedHostsServer. +// Don't use this type directly, use NewDedicatedHostsServerTransport instead. +type DedicatedHostsServerTransport struct { + srv *DedicatedHostsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.DedicatedHostsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.DedicatedHostsClientDeleteResponse] + newListAvailableSizesPager *azfake.PagerResponder[armcompute.DedicatedHostsClientListAvailableSizesResponse] + newListByHostGroupPager *azfake.PagerResponder[armcompute.DedicatedHostsClientListByHostGroupResponse] + beginRestart *azfake.PollerResponder[armcompute.DedicatedHostsClientRestartResponse] + beginUpdate *azfake.PollerResponder[armcompute.DedicatedHostsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for DedicatedHostsServerTransport. +func (d *DedicatedHostsServerTransport) 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 "DedicatedHostsClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DedicatedHostsClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DedicatedHostsClient.Get": + resp, err = d.dispatchGet(req) + case "DedicatedHostsClient.NewListAvailableSizesPager": + resp, err = d.dispatchNewListAvailableSizesPager(req) + case "DedicatedHostsClient.NewListByHostGroupPager": + resp, err = d.dispatchNewListByHostGroupPager(req) + case "DedicatedHostsClient.BeginRestart": + resp, err = d.dispatchBeginRestart(req) + case "DedicatedHostsClient.BeginUpdate": + resp, err = d.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DedicatedHostsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.DedicatedHost](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], 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 *DedicatedHostsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?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.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], 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.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(d.beginDelete) { + d.beginDelete = nil + } + + return resp, nil +} + +func (d *DedicatedHostsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.DedicatedHostsClientGetOptions + if expandParam != nil { + options = &armcompute.DedicatedHostsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], 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).DedicatedHost, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DedicatedHostsServerTransport) dispatchNewListAvailableSizesPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAvailableSizesPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAvailableSizesPager not implemented")} + } + if d.newListAvailableSizesPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)/hostSizes" + 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) + } + resp := d.srv.NewListAvailableSizesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], nil) + d.newListAvailableSizesPager = &resp + } + resp, err := server.PagerResponderNext(d.newListAvailableSizesPager, 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.newListAvailableSizesPager) { + d.newListAvailableSizesPager = nil + } + return resp, nil +} + +func (d *DedicatedHostsServerTransport) dispatchNewListByHostGroupPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListByHostGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByHostGroupPager not implemented")} + } + if d.newListByHostGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts" + 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) + } + resp := d.srv.NewListByHostGroupPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], nil) + d.newListByHostGroupPager = &resp + server.PagerResponderInjectNextLinks(d.newListByHostGroupPager, req, func(page *armcompute.DedicatedHostsClientListByHostGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListByHostGroupPager, 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.newListByHostGroupPager) { + d.newListByHostGroupPager = nil + } + return resp, nil +} + +func (d *DedicatedHostsServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { + if d.srv.BeginRestart == nil { + return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + } + if d.beginRestart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)/restart" + 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.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginRestart = &respr + } + + resp, err := server.PollerResponderNext(d.beginRestart, 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.PollerResponderMore(d.beginRestart) { + d.beginRestart = nil + } + + return resp, nil +} + +func (d *DedicatedHostsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if d.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.DedicatedHostUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(d.beginUpdate, 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.PollerResponderMore(d.beginUpdate) { + d.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go b/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go new file mode 100644 index 000000000000..62a452548b8e --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go @@ -0,0 +1,477 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// DiskAccessesServer is a fake server for instances of the armcompute.DiskAccessesClient type. +type DiskAccessesServer struct { + // BeginCreateOrUpdate is the fake for method DiskAccessesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, diskAccessName string, diskAccess armcompute.DiskAccess, options *armcompute.DiskAccessesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.DiskAccessesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DiskAccessesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, diskAccessName string, options *armcompute.DiskAccessesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.DiskAccessesClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAPrivateEndpointConnection is the fake for method DiskAccessesClient.BeginDeleteAPrivateEndpointConnection + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeleteAPrivateEndpointConnection func(ctx context.Context, resourceGroupName string, diskAccessName string, privateEndpointConnectionName string, options *armcompute.DiskAccessesClientBeginDeleteAPrivateEndpointConnectionOptions) (resp azfake.PollerResponder[armcompute.DiskAccessesClientDeleteAPrivateEndpointConnectionResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DiskAccessesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, diskAccessName string, options *armcompute.DiskAccessesClientGetOptions) (resp azfake.Responder[armcompute.DiskAccessesClientGetResponse], errResp azfake.ErrorResponder) + + // GetAPrivateEndpointConnection is the fake for method DiskAccessesClient.GetAPrivateEndpointConnection + // HTTP status codes to indicate success: http.StatusOK + GetAPrivateEndpointConnection func(ctx context.Context, resourceGroupName string, diskAccessName string, privateEndpointConnectionName string, options *armcompute.DiskAccessesClientGetAPrivateEndpointConnectionOptions) (resp azfake.Responder[armcompute.DiskAccessesClientGetAPrivateEndpointConnectionResponse], errResp azfake.ErrorResponder) + + // GetPrivateLinkResources is the fake for method DiskAccessesClient.GetPrivateLinkResources + // HTTP status codes to indicate success: http.StatusOK + GetPrivateLinkResources func(ctx context.Context, resourceGroupName string, diskAccessName string, options *armcompute.DiskAccessesClientGetPrivateLinkResourcesOptions) (resp azfake.Responder[armcompute.DiskAccessesClientGetPrivateLinkResourcesResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DiskAccessesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.DiskAccessesClientListOptions) (resp azfake.PagerResponder[armcompute.DiskAccessesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method DiskAccessesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.DiskAccessesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.DiskAccessesClientListByResourceGroupResponse]) + + // NewListPrivateEndpointConnectionsPager is the fake for method DiskAccessesClient.NewListPrivateEndpointConnectionsPager + // HTTP status codes to indicate success: http.StatusOK + NewListPrivateEndpointConnectionsPager func(resourceGroupName string, diskAccessName string, options *armcompute.DiskAccessesClientListPrivateEndpointConnectionsOptions) (resp azfake.PagerResponder[armcompute.DiskAccessesClientListPrivateEndpointConnectionsResponse]) + + // BeginUpdate is the fake for method DiskAccessesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, diskAccessName string, diskAccess armcompute.DiskAccessUpdate, options *armcompute.DiskAccessesClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.DiskAccessesClientUpdateResponse], errResp azfake.ErrorResponder) + + // BeginUpdateAPrivateEndpointConnection is the fake for method DiskAccessesClient.BeginUpdateAPrivateEndpointConnection + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateAPrivateEndpointConnection func(ctx context.Context, resourceGroupName string, diskAccessName string, privateEndpointConnectionName string, privateEndpointConnection armcompute.PrivateEndpointConnection, options *armcompute.DiskAccessesClientBeginUpdateAPrivateEndpointConnectionOptions) (resp azfake.PollerResponder[armcompute.DiskAccessesClientUpdateAPrivateEndpointConnectionResponse], errResp azfake.ErrorResponder) +} + +// NewDiskAccessesServerTransport creates a new instance of DiskAccessesServerTransport with the provided implementation. +// The returned DiskAccessesServerTransport instance is connected to an instance of armcompute.DiskAccessesClient by way of the +// undefined.Transporter field. +func NewDiskAccessesServerTransport(srv *DiskAccessesServer) *DiskAccessesServerTransport { + return &DiskAccessesServerTransport{srv: srv} +} + +// DiskAccessesServerTransport connects instances of armcompute.DiskAccessesClient to instances of DiskAccessesServer. +// Don't use this type directly, use NewDiskAccessesServerTransport instead. +type DiskAccessesServerTransport struct { + srv *DiskAccessesServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.DiskAccessesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.DiskAccessesClientDeleteResponse] + beginDeleteAPrivateEndpointConnection *azfake.PollerResponder[armcompute.DiskAccessesClientDeleteAPrivateEndpointConnectionResponse] + newListPager *azfake.PagerResponder[armcompute.DiskAccessesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armcompute.DiskAccessesClientListByResourceGroupResponse] + newListPrivateEndpointConnectionsPager *azfake.PagerResponder[armcompute.DiskAccessesClientListPrivateEndpointConnectionsResponse] + beginUpdate *azfake.PollerResponder[armcompute.DiskAccessesClientUpdateResponse] + beginUpdateAPrivateEndpointConnection *azfake.PollerResponder[armcompute.DiskAccessesClientUpdateAPrivateEndpointConnectionResponse] +} + +// Do implements the policy.Transporter interface for DiskAccessesServerTransport. +func (d *DiskAccessesServerTransport) 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 "DiskAccessesClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DiskAccessesClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DiskAccessesClient.BeginDeleteAPrivateEndpointConnection": + resp, err = d.dispatchBeginDeleteAPrivateEndpointConnection(req) + case "DiskAccessesClient.Get": + resp, err = d.dispatchGet(req) + case "DiskAccessesClient.GetAPrivateEndpointConnection": + resp, err = d.dispatchGetAPrivateEndpointConnection(req) + case "DiskAccessesClient.GetPrivateLinkResources": + resp, err = d.dispatchGetPrivateLinkResources(req) + case "DiskAccessesClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DiskAccessesClient.NewListByResourceGroupPager": + resp, err = d.dispatchNewListByResourceGroupPager(req) + case "DiskAccessesClient.NewListPrivateEndpointConnectionsPager": + resp, err = d.dispatchNewListPrivateEndpointConnectionsPager(req) + case "DiskAccessesClient.BeginUpdate": + resp, err = d.dispatchBeginUpdate(req) + case "DiskAccessesClient.BeginUpdateAPrivateEndpointConnection": + resp, err = d.dispatchBeginUpdateAPrivateEndpointConnection(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses/(?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[armcompute.DiskAccess](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], 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.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.beginCreateOrUpdate) { + d.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses/(?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("diskAccessName")], 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.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(d.beginDelete) { + d.beginDelete = nil + } + + return resp, nil +} + +func (d *DiskAccessesServerTransport) dispatchBeginDeleteAPrivateEndpointConnection(req *http.Request) (*http.Response, error) { + if d.srv.BeginDeleteAPrivateEndpointConnection == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteAPrivateEndpointConnection not implemented")} + } + if d.beginDeleteAPrivateEndpointConnection == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections/(?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.BeginDeleteAPrivateEndpointConnection(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], matches[regex.SubexpIndex("privateEndpointConnectionName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginDeleteAPrivateEndpointConnection = &respr + } + + resp, err := server.PollerResponderNext(d.beginDeleteAPrivateEndpointConnection, 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(d.beginDeleteAPrivateEndpointConnection) { + d.beginDeleteAPrivateEndpointConnection = nil + } + + return resp, nil +} + +func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses/(?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("diskAccessName")], 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).DiskAccess, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DiskAccessesServerTransport) dispatchGetAPrivateEndpointConnection(req *http.Request) (*http.Response, error) { + if d.srv.GetAPrivateEndpointConnection == nil { + return nil, &nonRetriableError{errors.New("method GetAPrivateEndpointConnection not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections/(?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.GetAPrivateEndpointConnection(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], matches[regex.SubexpIndex("privateEndpointConnectionName")], 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).PrivateEndpointConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DiskAccessesServerTransport) dispatchGetPrivateLinkResources(req *http.Request) (*http.Response, error) { + if d.srv.GetPrivateLinkResources == nil { + return nil, &nonRetriableError{errors.New("method GetPrivateLinkResources not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateLinkResources" + 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.GetPrivateLinkResources(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], 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).PrivateLinkResourceListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DiskAccessesServerTransport) 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-_]+)/providers/Microsoft.Compute/diskAccesses" + 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 := d.srv.NewListPager(nil) + d.newListPager = &resp + server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armcompute.DiskAccessesClientListResponse, 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 *DiskAccessesServerTransport) 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.Compute/diskAccesses" + 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) + } + resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + d.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DiskAccessesClientListByResourceGroupResponse, 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 *DiskAccessesServerTransport) dispatchNewListPrivateEndpointConnectionsPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPrivateEndpointConnectionsPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPrivateEndpointConnectionsPager not implemented")} + } + if d.newListPrivateEndpointConnectionsPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections" + 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) + } + resp := d.srv.NewListPrivateEndpointConnectionsPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], nil) + d.newListPrivateEndpointConnectionsPager = &resp + server.PagerResponderInjectNextLinks(d.newListPrivateEndpointConnectionsPager, req, func(page *armcompute.DiskAccessesClientListPrivateEndpointConnectionsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListPrivateEndpointConnectionsPager, 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.newListPrivateEndpointConnectionsPager) { + d.newListPrivateEndpointConnectionsPager = nil + } + return resp, nil +} + +func (d *DiskAccessesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if d.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?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[armcompute.DiskAccessUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(d.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(d.beginUpdate) { + d.beginUpdate = nil + } + + return resp, nil +} + +func (d *DiskAccessesServerTransport) dispatchBeginUpdateAPrivateEndpointConnection(req *http.Request) (*http.Response, error) { + if d.srv.BeginUpdateAPrivateEndpointConnection == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdateAPrivateEndpointConnection not implemented")} + } + if d.beginUpdateAPrivateEndpointConnection == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.PrivateEndpointConnection](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdateAPrivateEndpointConnection(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], matches[regex.SubexpIndex("privateEndpointConnectionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginUpdateAPrivateEndpointConnection = &respr + } + + resp, err := server.PollerResponderNext(d.beginUpdateAPrivateEndpointConnection, 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.beginUpdateAPrivateEndpointConnection) { + d.beginUpdateAPrivateEndpointConnection = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go b/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go new file mode 100644 index 000000000000..5a3ae2e39ac5 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go @@ -0,0 +1,331 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// DiskEncryptionSetsServer is a fake server for instances of the armcompute.DiskEncryptionSetsClient type. +type DiskEncryptionSetsServer struct { + // BeginCreateOrUpdate is the fake for method DiskEncryptionSetsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, diskEncryptionSet armcompute.DiskEncryptionSet, options *armcompute.DiskEncryptionSetsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.DiskEncryptionSetsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DiskEncryptionSetsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, options *armcompute.DiskEncryptionSetsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.DiskEncryptionSetsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DiskEncryptionSetsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, options *armcompute.DiskEncryptionSetsClientGetOptions) (resp azfake.Responder[armcompute.DiskEncryptionSetsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DiskEncryptionSetsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.DiskEncryptionSetsClientListOptions) (resp azfake.PagerResponder[armcompute.DiskEncryptionSetsClientListResponse]) + + // NewListAssociatedResourcesPager is the fake for method DiskEncryptionSetsClient.NewListAssociatedResourcesPager + // HTTP status codes to indicate success: http.StatusOK + NewListAssociatedResourcesPager func(resourceGroupName string, diskEncryptionSetName string, options *armcompute.DiskEncryptionSetsClientListAssociatedResourcesOptions) (resp azfake.PagerResponder[armcompute.DiskEncryptionSetsClientListAssociatedResourcesResponse]) + + // NewListByResourceGroupPager is the fake for method DiskEncryptionSetsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.DiskEncryptionSetsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.DiskEncryptionSetsClientListByResourceGroupResponse]) + + // BeginUpdate is the fake for method DiskEncryptionSetsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, diskEncryptionSetName string, diskEncryptionSet armcompute.DiskEncryptionSetUpdate, options *armcompute.DiskEncryptionSetsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.DiskEncryptionSetsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewDiskEncryptionSetsServerTransport creates a new instance of DiskEncryptionSetsServerTransport with the provided implementation. +// The returned DiskEncryptionSetsServerTransport instance is connected to an instance of armcompute.DiskEncryptionSetsClient by way of the +// undefined.Transporter field. +func NewDiskEncryptionSetsServerTransport(srv *DiskEncryptionSetsServer) *DiskEncryptionSetsServerTransport { + return &DiskEncryptionSetsServerTransport{srv: srv} +} + +// DiskEncryptionSetsServerTransport connects instances of armcompute.DiskEncryptionSetsClient to instances of DiskEncryptionSetsServer. +// Don't use this type directly, use NewDiskEncryptionSetsServerTransport instead. +type DiskEncryptionSetsServerTransport struct { + srv *DiskEncryptionSetsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.DiskEncryptionSetsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.DiskEncryptionSetsClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.DiskEncryptionSetsClientListResponse] + newListAssociatedResourcesPager *azfake.PagerResponder[armcompute.DiskEncryptionSetsClientListAssociatedResourcesResponse] + newListByResourceGroupPager *azfake.PagerResponder[armcompute.DiskEncryptionSetsClientListByResourceGroupResponse] + beginUpdate *azfake.PollerResponder[armcompute.DiskEncryptionSetsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for DiskEncryptionSetsServerTransport. +func (d *DiskEncryptionSetsServerTransport) 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 "DiskEncryptionSetsClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DiskEncryptionSetsClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DiskEncryptionSetsClient.Get": + resp, err = d.dispatchGet(req) + case "DiskEncryptionSetsClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DiskEncryptionSetsClient.NewListAssociatedResourcesPager": + resp, err = d.dispatchNewListAssociatedResourcesPager(req) + case "DiskEncryptionSetsClient.NewListByResourceGroupPager": + resp, err = d.dispatchNewListByResourceGroupPager(req) + case "DiskEncryptionSetsClient.BeginUpdate": + resp, err = d.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets/(?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[armcompute.DiskEncryptionSet](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskEncryptionSetName")], 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.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.beginCreateOrUpdate) { + d.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets/(?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("diskEncryptionSetName")], 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.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(d.beginDelete) { + d.beginDelete = nil + } + + return resp, nil +} + +func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets/(?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("diskEncryptionSetName")], 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).DiskEncryptionSet, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DiskEncryptionSetsServerTransport) 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-_]+)/providers/Microsoft.Compute/diskEncryptionSets" + 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 := d.srv.NewListPager(nil) + d.newListPager = &resp + server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armcompute.DiskEncryptionSetsClientListResponse, 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 *DiskEncryptionSetsServerTransport) dispatchNewListAssociatedResourcesPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAssociatedResourcesPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAssociatedResourcesPager not implemented")} + } + if d.newListAssociatedResourcesPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskEncryptionSets/(?P[a-zA-Z0-9-_]+)/associatedResources" + 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) + } + resp := d.srv.NewListAssociatedResourcesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskEncryptionSetName")], nil) + d.newListAssociatedResourcesPager = &resp + server.PagerResponderInjectNextLinks(d.newListAssociatedResourcesPager, req, func(page *armcompute.DiskEncryptionSetsClientListAssociatedResourcesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListAssociatedResourcesPager, 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.newListAssociatedResourcesPager) { + d.newListAssociatedResourcesPager = nil + } + return resp, nil +} + +func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets" + 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) + } + resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + d.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DiskEncryptionSetsClientListByResourceGroupResponse, 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 *DiskEncryptionSetsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if d.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskEncryptionSets/(?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[armcompute.DiskEncryptionSetUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskEncryptionSetName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(d.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(d.beginUpdate) { + d.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go b/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go new file mode 100644 index 000000000000..f1b0e50e2632 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go @@ -0,0 +1,213 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// DiskRestorePointServer is a fake server for instances of the armcompute.DiskRestorePointClient type. +type DiskRestorePointServer struct { + // Get is the fake for method DiskRestorePointClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, diskRestorePointName string, options *armcompute.DiskRestorePointClientGetOptions) (resp azfake.Responder[armcompute.DiskRestorePointClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGrantAccess is the fake for method DiskRestorePointClient.BeginGrantAccess + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGrantAccess func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, diskRestorePointName string, grantAccessData armcompute.GrantAccessData, options *armcompute.DiskRestorePointClientBeginGrantAccessOptions) (resp azfake.PollerResponder[armcompute.DiskRestorePointClientGrantAccessResponse], errResp azfake.ErrorResponder) + + // NewListByRestorePointPager is the fake for method DiskRestorePointClient.NewListByRestorePointPager + // HTTP status codes to indicate success: http.StatusOK + NewListByRestorePointPager func(resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, options *armcompute.DiskRestorePointClientListByRestorePointOptions) (resp azfake.PagerResponder[armcompute.DiskRestorePointClientListByRestorePointResponse]) + + // BeginRevokeAccess is the fake for method DiskRestorePointClient.BeginRevokeAccess + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRevokeAccess func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, vmRestorePointName string, diskRestorePointName string, options *armcompute.DiskRestorePointClientBeginRevokeAccessOptions) (resp azfake.PollerResponder[armcompute.DiskRestorePointClientRevokeAccessResponse], errResp azfake.ErrorResponder) +} + +// NewDiskRestorePointServerTransport creates a new instance of DiskRestorePointServerTransport with the provided implementation. +// The returned DiskRestorePointServerTransport instance is connected to an instance of armcompute.DiskRestorePointClient by way of the +// undefined.Transporter field. +func NewDiskRestorePointServerTransport(srv *DiskRestorePointServer) *DiskRestorePointServerTransport { + return &DiskRestorePointServerTransport{srv: srv} +} + +// DiskRestorePointServerTransport connects instances of armcompute.DiskRestorePointClient to instances of DiskRestorePointServer. +// Don't use this type directly, use NewDiskRestorePointServerTransport instead. +type DiskRestorePointServerTransport struct { + srv *DiskRestorePointServer + beginGrantAccess *azfake.PollerResponder[armcompute.DiskRestorePointClientGrantAccessResponse] + newListByRestorePointPager *azfake.PagerResponder[armcompute.DiskRestorePointClientListByRestorePointResponse] + beginRevokeAccess *azfake.PollerResponder[armcompute.DiskRestorePointClientRevokeAccessResponse] +} + +// Do implements the policy.Transporter interface for DiskRestorePointServerTransport. +func (d *DiskRestorePointServerTransport) 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 "DiskRestorePointClient.Get": + resp, err = d.dispatchGet(req) + case "DiskRestorePointClient.BeginGrantAccess": + resp, err = d.dispatchBeginGrantAccess(req) + case "DiskRestorePointClient.NewListByRestorePointPager": + resp, err = d.dispatchNewListByRestorePointPager(req) + case "DiskRestorePointClient.BeginRevokeAccess": + resp, err = d.dispatchBeginRevokeAccess(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DiskRestorePointServerTransport) 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.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + 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("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], matches[regex.SubexpIndex("diskRestorePointName")], 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).DiskRestorePoint, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DiskRestorePointServerTransport) dispatchBeginGrantAccess(req *http.Request) (*http.Response, error) { + if d.srv.BeginGrantAccess == nil { + return nil, &nonRetriableError{errors.New("method BeginGrantAccess not implemented")} + } + if d.beginGrantAccess == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints/(?P[a-zA-Z0-9-_]+)/beginGetAccess" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GrantAccessData](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginGrantAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], matches[regex.SubexpIndex("diskRestorePointName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginGrantAccess = &respr + } + + resp, err := server.PollerResponderNext(d.beginGrantAccess, 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.beginGrantAccess) { + d.beginGrantAccess = nil + } + + return resp, nil +} + +func (d *DiskRestorePointServerTransport) dispatchNewListByRestorePointPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListByRestorePointPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByRestorePointPager not implemented")} + } + if d.newListByRestorePointPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints" + 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) + } + resp := d.srv.NewListByRestorePointPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], nil) + d.newListByRestorePointPager = &resp + server.PagerResponderInjectNextLinks(d.newListByRestorePointPager, req, func(page *armcompute.DiskRestorePointClientListByRestorePointResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.newListByRestorePointPager, 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.newListByRestorePointPager) { + d.newListByRestorePointPager = nil + } + return resp, nil +} + +func (d *DiskRestorePointServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*http.Response, error) { + if d.srv.BeginRevokeAccess == nil { + return nil, &nonRetriableError{errors.New("method BeginRevokeAccess not implemented")} + } + if d.beginRevokeAccess == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints/(?P[a-zA-Z0-9-_]+)/endGetAccess" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := d.srv.BeginRevokeAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], matches[regex.SubexpIndex("diskRestorePointName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginRevokeAccess = &respr + } + + resp, err := server.PollerResponderNext(d.beginRevokeAccess, 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.beginRevokeAccess) { + d.beginRevokeAccess = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/disks_server.go b/sdk/resourcemanager/compute/armcompute/fake/disks_server.go new file mode 100644 index 000000000000..9296e520ef52 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/disks_server.go @@ -0,0 +1,378 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// DisksServer is a fake server for instances of the armcompute.DisksClient type. +type DisksServer struct { + // BeginCreateOrUpdate is the fake for method DisksClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, diskName string, disk armcompute.Disk, options *armcompute.DisksClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.DisksClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DisksClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, diskName string, options *armcompute.DisksClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.DisksClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DisksClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, diskName string, options *armcompute.DisksClientGetOptions) (resp azfake.Responder[armcompute.DisksClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGrantAccess is the fake for method DisksClient.BeginGrantAccess + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGrantAccess func(ctx context.Context, resourceGroupName string, diskName string, grantAccessData armcompute.GrantAccessData, options *armcompute.DisksClientBeginGrantAccessOptions) (resp azfake.PollerResponder[armcompute.DisksClientGrantAccessResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DisksClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.DisksClientListOptions) (resp azfake.PagerResponder[armcompute.DisksClientListResponse]) + + // NewListByResourceGroupPager is the fake for method DisksClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.DisksClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.DisksClientListByResourceGroupResponse]) + + // BeginRevokeAccess is the fake for method DisksClient.BeginRevokeAccess + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRevokeAccess func(ctx context.Context, resourceGroupName string, diskName string, options *armcompute.DisksClientBeginRevokeAccessOptions) (resp azfake.PollerResponder[armcompute.DisksClientRevokeAccessResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method DisksClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, diskName string, disk armcompute.DiskUpdate, options *armcompute.DisksClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.DisksClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewDisksServerTransport creates a new instance of DisksServerTransport with the provided implementation. +// The returned DisksServerTransport instance is connected to an instance of armcompute.DisksClient by way of the +// undefined.Transporter field. +func NewDisksServerTransport(srv *DisksServer) *DisksServerTransport { + return &DisksServerTransport{srv: srv} +} + +// DisksServerTransport connects instances of armcompute.DisksClient to instances of DisksServer. +// Don't use this type directly, use NewDisksServerTransport instead. +type DisksServerTransport struct { + srv *DisksServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.DisksClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.DisksClientDeleteResponse] + beginGrantAccess *azfake.PollerResponder[armcompute.DisksClientGrantAccessResponse] + newListPager *azfake.PagerResponder[armcompute.DisksClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armcompute.DisksClientListByResourceGroupResponse] + beginRevokeAccess *azfake.PollerResponder[armcompute.DisksClientRevokeAccessResponse] + beginUpdate *azfake.PollerResponder[armcompute.DisksClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for DisksServerTransport. +func (d *DisksServerTransport) 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 "DisksClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DisksClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DisksClient.Get": + resp, err = d.dispatchGet(req) + case "DisksClient.BeginGrantAccess": + resp, err = d.dispatchBeginGrantAccess(req) + case "DisksClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DisksClient.NewListByResourceGroupPager": + resp, err = d.dispatchNewListByResourceGroupPager(req) + case "DisksClient.BeginRevokeAccess": + resp, err = d.dispatchBeginRevokeAccess(req) + case "DisksClient.BeginUpdate": + resp, err = d.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DisksServerTransport) 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.Compute/disks/(?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[armcompute.Disk](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], 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.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.beginCreateOrUpdate) { + d.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (d *DisksServerTransport) 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.Compute/disks/(?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("diskName")], 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.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(d.beginDelete) { + d.beginDelete = nil + } + + return resp, nil +} + +func (d *DisksServerTransport) 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.Compute/disks/(?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("diskName")], 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).Disk, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DisksServerTransport) dispatchBeginGrantAccess(req *http.Request) (*http.Response, error) { + if d.srv.BeginGrantAccess == nil { + return nil, &nonRetriableError{errors.New("method BeginGrantAccess not implemented")} + } + if d.beginGrantAccess == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/disks/(?P[a-zA-Z0-9-_]+)/beginGetAccess" + 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[armcompute.GrantAccessData](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginGrantAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginGrantAccess = &respr + } + + resp, err := server.PollerResponderNext(d.beginGrantAccess, 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.beginGrantAccess) { + d.beginGrantAccess = nil + } + + return resp, nil +} + +func (d *DisksServerTransport) 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-_]+)/providers/Microsoft.Compute/disks" + 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 := d.srv.NewListPager(nil) + d.newListPager = &resp + server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armcompute.DisksClientListResponse, 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 *DisksServerTransport) 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.Compute/disks" + 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) + } + resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + d.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DisksClientListByResourceGroupResponse, 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 *DisksServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*http.Response, error) { + if d.srv.BeginRevokeAccess == nil { + return nil, &nonRetriableError{errors.New("method BeginRevokeAccess not implemented")} + } + if d.beginRevokeAccess == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/disks/(?P[a-zA-Z0-9-_]+)/endGetAccess" + 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.BeginRevokeAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginRevokeAccess = &respr + } + + resp, err := server.PollerResponderNext(d.beginRevokeAccess, 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.beginRevokeAccess) { + d.beginRevokeAccess = nil + } + + return resp, nil +} + +func (d *DisksServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if d.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/disks/(?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[armcompute.DiskUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + d.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(d.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(d.beginUpdate) { + d.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleries_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleries_server.go new file mode 100644 index 000000000000..0bf85e26152d --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/galleries_server.go @@ -0,0 +1,304 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// GalleriesServer is a fake server for instances of the armcompute.GalleriesClient type. +type GalleriesServer struct { + // BeginCreateOrUpdate is the fake for method GalleriesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, galleryName string, gallery armcompute.Gallery, options *armcompute.GalleriesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleriesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method GalleriesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, galleryName string, options *armcompute.GalleriesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.GalleriesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method GalleriesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, galleryName string, options *armcompute.GalleriesClientGetOptions) (resp azfake.Responder[armcompute.GalleriesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method GalleriesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.GalleriesClientListOptions) (resp azfake.PagerResponder[armcompute.GalleriesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method GalleriesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.GalleriesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.GalleriesClientListByResourceGroupResponse]) + + // BeginUpdate is the fake for method GalleriesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, galleryName string, gallery armcompute.GalleryUpdate, options *armcompute.GalleriesClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleriesClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewGalleriesServerTransport creates a new instance of GalleriesServerTransport with the provided implementation. +// The returned GalleriesServerTransport instance is connected to an instance of armcompute.GalleriesClient by way of the +// undefined.Transporter field. +func NewGalleriesServerTransport(srv *GalleriesServer) *GalleriesServerTransport { + return &GalleriesServerTransport{srv: srv} +} + +// GalleriesServerTransport connects instances of armcompute.GalleriesClient to instances of GalleriesServer. +// Don't use this type directly, use NewGalleriesServerTransport instead. +type GalleriesServerTransport struct { + srv *GalleriesServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.GalleriesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.GalleriesClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.GalleriesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armcompute.GalleriesClientListByResourceGroupResponse] + beginUpdate *azfake.PollerResponder[armcompute.GalleriesClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for GalleriesServerTransport. +func (g *GalleriesServerTransport) 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 "GalleriesClient.BeginCreateOrUpdate": + resp, err = g.dispatchBeginCreateOrUpdate(req) + case "GalleriesClient.BeginDelete": + resp, err = g.dispatchBeginDelete(req) + case "GalleriesClient.Get": + resp, err = g.dispatchGet(req) + case "GalleriesClient.NewListPager": + resp, err = g.dispatchNewListPager(req) + case "GalleriesClient.NewListByResourceGroupPager": + resp, err = g.dispatchNewListByResourceGroupPager(req) + case "GalleriesClient.BeginUpdate": + resp, err = g.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GalleriesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if g.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?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[armcompute.Gallery](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginCreateOrUpdate) { + g.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (g *GalleriesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if g.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if g.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?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 := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginDelete) { + g.beginDelete = nil + } + + return resp, nil +} + +func (g *GalleriesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if g.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.Compute/galleries/(?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) + } + qp := req.URL.Query() + selectParam := getOptional(armcompute.SelectPermissions(qp.Get("$select"))) + expandParam := getOptional(armcompute.GalleryExpandParams(qp.Get("$expand"))) + var options *armcompute.GalleriesClientGetOptions + if selectParam != nil || expandParam != nil { + options = &armcompute.GalleriesClientGetOptions{ + Select: selectParam, + Expand: expandParam, + } + } + respr, errRespr := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], 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).Gallery, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (g *GalleriesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if g.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if g.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries" + 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 := g.srv.NewListPager(nil) + g.newListPager = &resp + server.PagerResponderInjectNextLinks(g.newListPager, req, func(page *armcompute.GalleriesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(g.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(g.newListPager) { + g.newListPager = nil + } + return resp, nil +} + +func (g *GalleriesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if g.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + } + if g.newListByResourceGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries" + 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) + } + resp := g.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + g.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(g.newListByResourceGroupPager, req, func(page *armcompute.GalleriesClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(g.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(g.newListByResourceGroupPager) { + g.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (g *GalleriesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if g.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?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[armcompute.GalleryUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.beginUpdate, 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.PollerResponderMore(g.beginUpdate) { + g.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go new file mode 100644 index 000000000000..d4b01209314a --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go @@ -0,0 +1,257 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// GalleryApplicationsServer is a fake server for instances of the armcompute.GalleryApplicationsClient type. +type GalleryApplicationsServer struct { + // BeginCreateOrUpdate is the fake for method GalleryApplicationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplication armcompute.GalleryApplication, options *armcompute.GalleryApplicationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryApplicationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method GalleryApplicationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, options *armcompute.GalleryApplicationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.GalleryApplicationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method GalleryApplicationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, options *armcompute.GalleryApplicationsClientGetOptions) (resp azfake.Responder[armcompute.GalleryApplicationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByGalleryPager is the fake for method GalleryApplicationsClient.NewListByGalleryPager + // HTTP status codes to indicate success: http.StatusOK + NewListByGalleryPager func(resourceGroupName string, galleryName string, options *armcompute.GalleryApplicationsClientListByGalleryOptions) (resp azfake.PagerResponder[armcompute.GalleryApplicationsClientListByGalleryResponse]) + + // BeginUpdate is the fake for method GalleryApplicationsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplication armcompute.GalleryApplicationUpdate, options *armcompute.GalleryApplicationsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryApplicationsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewGalleryApplicationsServerTransport creates a new instance of GalleryApplicationsServerTransport with the provided implementation. +// The returned GalleryApplicationsServerTransport instance is connected to an instance of armcompute.GalleryApplicationsClient by way of the +// undefined.Transporter field. +func NewGalleryApplicationsServerTransport(srv *GalleryApplicationsServer) *GalleryApplicationsServerTransport { + return &GalleryApplicationsServerTransport{srv: srv} +} + +// GalleryApplicationsServerTransport connects instances of armcompute.GalleryApplicationsClient to instances of GalleryApplicationsServer. +// Don't use this type directly, use NewGalleryApplicationsServerTransport instead. +type GalleryApplicationsServerTransport struct { + srv *GalleryApplicationsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.GalleryApplicationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.GalleryApplicationsClientDeleteResponse] + newListByGalleryPager *azfake.PagerResponder[armcompute.GalleryApplicationsClientListByGalleryResponse] + beginUpdate *azfake.PollerResponder[armcompute.GalleryApplicationsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for GalleryApplicationsServerTransport. +func (g *GalleryApplicationsServerTransport) 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 "GalleryApplicationsClient.BeginCreateOrUpdate": + resp, err = g.dispatchBeginCreateOrUpdate(req) + case "GalleryApplicationsClient.BeginDelete": + resp, err = g.dispatchBeginDelete(req) + case "GalleryApplicationsClient.Get": + resp, err = g.dispatchGet(req) + case "GalleryApplicationsClient.NewListByGalleryPager": + resp, err = g.dispatchNewListByGalleryPager(req) + case "GalleryApplicationsClient.BeginUpdate": + resp, err = g.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GalleryApplicationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if g.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryApplication](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginCreateOrUpdate) { + g.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (g *GalleryApplicationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if g.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if g.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?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 := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginDelete) { + g.beginDelete = nil + } + + return resp, nil +} + +func (g *GalleryApplicationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?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 := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], 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).GalleryApplication, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (g *GalleryApplicationsServerTransport) dispatchNewListByGalleryPager(req *http.Request) (*http.Response, error) { + if g.srv.NewListByGalleryPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByGalleryPager not implemented")} + } + if g.newListByGalleryPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications" + 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) + } + resp := g.srv.NewListByGalleryPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], nil) + g.newListByGalleryPager = &resp + server.PagerResponderInjectNextLinks(g.newListByGalleryPager, req, func(page *armcompute.GalleryApplicationsClientListByGalleryResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(g.newListByGalleryPager, 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(g.newListByGalleryPager) { + g.newListByGalleryPager = nil + } + return resp, nil +} + +func (g *GalleryApplicationsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if g.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryApplicationUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.beginUpdate, 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.PollerResponderMore(g.beginUpdate) { + g.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go new file mode 100644 index 000000000000..119ba9fc16e6 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go @@ -0,0 +1,265 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// GalleryApplicationVersionsServer is a fake server for instances of the armcompute.GalleryApplicationVersionsClient type. +type GalleryApplicationVersionsServer struct { + // BeginCreateOrUpdate is the fake for method GalleryApplicationVersionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, galleryApplicationVersion armcompute.GalleryApplicationVersion, options *armcompute.GalleryApplicationVersionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryApplicationVersionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method GalleryApplicationVersionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, options *armcompute.GalleryApplicationVersionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.GalleryApplicationVersionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method GalleryApplicationVersionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, options *armcompute.GalleryApplicationVersionsClientGetOptions) (resp azfake.Responder[armcompute.GalleryApplicationVersionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByGalleryApplicationPager is the fake for method GalleryApplicationVersionsClient.NewListByGalleryApplicationPager + // HTTP status codes to indicate success: http.StatusOK + NewListByGalleryApplicationPager func(resourceGroupName string, galleryName string, galleryApplicationName string, options *armcompute.GalleryApplicationVersionsClientListByGalleryApplicationOptions) (resp azfake.PagerResponder[armcompute.GalleryApplicationVersionsClientListByGalleryApplicationResponse]) + + // BeginUpdate is the fake for method GalleryApplicationVersionsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, galleryApplicationVersion armcompute.GalleryApplicationVersionUpdate, options *armcompute.GalleryApplicationVersionsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryApplicationVersionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewGalleryApplicationVersionsServerTransport creates a new instance of GalleryApplicationVersionsServerTransport with the provided implementation. +// The returned GalleryApplicationVersionsServerTransport instance is connected to an instance of armcompute.GalleryApplicationVersionsClient by way of the +// undefined.Transporter field. +func NewGalleryApplicationVersionsServerTransport(srv *GalleryApplicationVersionsServer) *GalleryApplicationVersionsServerTransport { + return &GalleryApplicationVersionsServerTransport{srv: srv} +} + +// GalleryApplicationVersionsServerTransport connects instances of armcompute.GalleryApplicationVersionsClient to instances of GalleryApplicationVersionsServer. +// Don't use this type directly, use NewGalleryApplicationVersionsServerTransport instead. +type GalleryApplicationVersionsServerTransport struct { + srv *GalleryApplicationVersionsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.GalleryApplicationVersionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.GalleryApplicationVersionsClientDeleteResponse] + newListByGalleryApplicationPager *azfake.PagerResponder[armcompute.GalleryApplicationVersionsClientListByGalleryApplicationResponse] + beginUpdate *azfake.PollerResponder[armcompute.GalleryApplicationVersionsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for GalleryApplicationVersionsServerTransport. +func (g *GalleryApplicationVersionsServerTransport) 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 "GalleryApplicationVersionsClient.BeginCreateOrUpdate": + resp, err = g.dispatchBeginCreateOrUpdate(req) + case "GalleryApplicationVersionsClient.BeginDelete": + resp, err = g.dispatchBeginDelete(req) + case "GalleryApplicationVersionsClient.Get": + resp, err = g.dispatchGet(req) + case "GalleryApplicationVersionsClient.NewListByGalleryApplicationPager": + resp, err = g.dispatchNewListByGalleryApplicationPager(req) + case "GalleryApplicationVersionsClient.BeginUpdate": + resp, err = g.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GalleryApplicationVersionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if g.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryApplicationVersion](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginCreateOrUpdate) { + g.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (g *GalleryApplicationVersionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if g.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if g.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginDelete) { + g.beginDelete = nil + } + + return resp, nil +} + +func (g *GalleryApplicationVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.ReplicationStatusTypes(qp.Get("$expand"))) + var options *armcompute.GalleryApplicationVersionsClientGetOptions + if expandParam != nil { + options = &armcompute.GalleryApplicationVersionsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], 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).GalleryApplicationVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (g *GalleryApplicationVersionsServerTransport) dispatchNewListByGalleryApplicationPager(req *http.Request) (*http.Response, error) { + if g.srv.NewListByGalleryApplicationPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByGalleryApplicationPager not implemented")} + } + if g.newListByGalleryApplicationPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions" + 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) + } + resp := g.srv.NewListByGalleryApplicationPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], nil) + g.newListByGalleryApplicationPager = &resp + server.PagerResponderInjectNextLinks(g.newListByGalleryApplicationPager, req, func(page *armcompute.GalleryApplicationVersionsClientListByGalleryApplicationResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(g.newListByGalleryApplicationPager, 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(g.newListByGalleryApplicationPager) { + g.newListByGalleryApplicationPager = nil + } + return resp, nil +} + +func (g *GalleryApplicationVersionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if g.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryApplicationVersionUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.beginUpdate, 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.PollerResponderMore(g.beginUpdate) { + g.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go new file mode 100644 index 000000000000..2f21a50e6772 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go @@ -0,0 +1,257 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// GalleryImagesServer is a fake server for instances of the armcompute.GalleryImagesClient type. +type GalleryImagesServer struct { + // BeginCreateOrUpdate is the fake for method GalleryImagesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImage armcompute.GalleryImage, options *armcompute.GalleryImagesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryImagesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method GalleryImagesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, options *armcompute.GalleryImagesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.GalleryImagesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method GalleryImagesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, options *armcompute.GalleryImagesClientGetOptions) (resp azfake.Responder[armcompute.GalleryImagesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByGalleryPager is the fake for method GalleryImagesClient.NewListByGalleryPager + // HTTP status codes to indicate success: http.StatusOK + NewListByGalleryPager func(resourceGroupName string, galleryName string, options *armcompute.GalleryImagesClientListByGalleryOptions) (resp azfake.PagerResponder[armcompute.GalleryImagesClientListByGalleryResponse]) + + // BeginUpdate is the fake for method GalleryImagesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImage armcompute.GalleryImageUpdate, options *armcompute.GalleryImagesClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryImagesClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewGalleryImagesServerTransport creates a new instance of GalleryImagesServerTransport with the provided implementation. +// The returned GalleryImagesServerTransport instance is connected to an instance of armcompute.GalleryImagesClient by way of the +// undefined.Transporter field. +func NewGalleryImagesServerTransport(srv *GalleryImagesServer) *GalleryImagesServerTransport { + return &GalleryImagesServerTransport{srv: srv} +} + +// GalleryImagesServerTransport connects instances of armcompute.GalleryImagesClient to instances of GalleryImagesServer. +// Don't use this type directly, use NewGalleryImagesServerTransport instead. +type GalleryImagesServerTransport struct { + srv *GalleryImagesServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.GalleryImagesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.GalleryImagesClientDeleteResponse] + newListByGalleryPager *azfake.PagerResponder[armcompute.GalleryImagesClientListByGalleryResponse] + beginUpdate *azfake.PollerResponder[armcompute.GalleryImagesClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for GalleryImagesServerTransport. +func (g *GalleryImagesServerTransport) 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 "GalleryImagesClient.BeginCreateOrUpdate": + resp, err = g.dispatchBeginCreateOrUpdate(req) + case "GalleryImagesClient.BeginDelete": + resp, err = g.dispatchBeginDelete(req) + case "GalleryImagesClient.Get": + resp, err = g.dispatchGet(req) + case "GalleryImagesClient.NewListByGalleryPager": + resp, err = g.dispatchNewListByGalleryPager(req) + case "GalleryImagesClient.BeginUpdate": + resp, err = g.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GalleryImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if g.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryImage](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginCreateOrUpdate) { + g.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (g *GalleryImagesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if g.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if g.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?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 := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginDelete) { + g.beginDelete = nil + } + + return resp, nil +} + +func (g *GalleryImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?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 := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], 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).GalleryImage, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (g *GalleryImagesServerTransport) dispatchNewListByGalleryPager(req *http.Request) (*http.Response, error) { + if g.srv.NewListByGalleryPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByGalleryPager not implemented")} + } + if g.newListByGalleryPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images" + 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) + } + resp := g.srv.NewListByGalleryPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], nil) + g.newListByGalleryPager = &resp + server.PagerResponderInjectNextLinks(g.newListByGalleryPager, req, func(page *armcompute.GalleryImagesClientListByGalleryResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(g.newListByGalleryPager, 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(g.newListByGalleryPager) { + g.newListByGalleryPager = nil + } + return resp, nil +} + +func (g *GalleryImagesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if g.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryImageUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.beginUpdate, 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.PollerResponderMore(g.beginUpdate) { + g.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go new file mode 100644 index 000000000000..3f71f9cef802 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go @@ -0,0 +1,265 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// GalleryImageVersionsServer is a fake server for instances of the armcompute.GalleryImageVersionsClient type. +type GalleryImageVersionsServer struct { + // BeginCreateOrUpdate is the fake for method GalleryImageVersionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, galleryImageVersion armcompute.GalleryImageVersion, options *armcompute.GalleryImageVersionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryImageVersionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method GalleryImageVersionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, options *armcompute.GalleryImageVersionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.GalleryImageVersionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method GalleryImageVersionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, options *armcompute.GalleryImageVersionsClientGetOptions) (resp azfake.Responder[armcompute.GalleryImageVersionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByGalleryImagePager is the fake for method GalleryImageVersionsClient.NewListByGalleryImagePager + // HTTP status codes to indicate success: http.StatusOK + NewListByGalleryImagePager func(resourceGroupName string, galleryName string, galleryImageName string, options *armcompute.GalleryImageVersionsClientListByGalleryImageOptions) (resp azfake.PagerResponder[armcompute.GalleryImageVersionsClientListByGalleryImageResponse]) + + // BeginUpdate is the fake for method GalleryImageVersionsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, galleryImageVersion armcompute.GalleryImageVersionUpdate, options *armcompute.GalleryImageVersionsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.GalleryImageVersionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewGalleryImageVersionsServerTransport creates a new instance of GalleryImageVersionsServerTransport with the provided implementation. +// The returned GalleryImageVersionsServerTransport instance is connected to an instance of armcompute.GalleryImageVersionsClient by way of the +// undefined.Transporter field. +func NewGalleryImageVersionsServerTransport(srv *GalleryImageVersionsServer) *GalleryImageVersionsServerTransport { + return &GalleryImageVersionsServerTransport{srv: srv} +} + +// GalleryImageVersionsServerTransport connects instances of armcompute.GalleryImageVersionsClient to instances of GalleryImageVersionsServer. +// Don't use this type directly, use NewGalleryImageVersionsServerTransport instead. +type GalleryImageVersionsServerTransport struct { + srv *GalleryImageVersionsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.GalleryImageVersionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.GalleryImageVersionsClientDeleteResponse] + newListByGalleryImagePager *azfake.PagerResponder[armcompute.GalleryImageVersionsClientListByGalleryImageResponse] + beginUpdate *azfake.PollerResponder[armcompute.GalleryImageVersionsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for GalleryImageVersionsServerTransport. +func (g *GalleryImageVersionsServerTransport) 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 "GalleryImageVersionsClient.BeginCreateOrUpdate": + resp, err = g.dispatchBeginCreateOrUpdate(req) + case "GalleryImageVersionsClient.BeginDelete": + resp, err = g.dispatchBeginDelete(req) + case "GalleryImageVersionsClient.Get": + resp, err = g.dispatchGet(req) + case "GalleryImageVersionsClient.NewListByGalleryImagePager": + resp, err = g.dispatchNewListByGalleryImagePager(req) + case "GalleryImageVersionsClient.BeginUpdate": + resp, err = g.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GalleryImageVersionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if g.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryImageVersion](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginCreateOrUpdate) { + g.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (g *GalleryImageVersionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if g.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if g.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginDelete) { + g.beginDelete = nil + } + + return resp, nil +} + +func (g *GalleryImageVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.ReplicationStatusTypes(qp.Get("$expand"))) + var options *armcompute.GalleryImageVersionsClientGetOptions + if expandParam != nil { + options = &armcompute.GalleryImageVersionsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], 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).GalleryImageVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (g *GalleryImageVersionsServerTransport) dispatchNewListByGalleryImagePager(req *http.Request) (*http.Response, error) { + if g.srv.NewListByGalleryImagePager == nil { + return nil, &nonRetriableError{errors.New("method NewListByGalleryImagePager not implemented")} + } + if g.newListByGalleryImagePager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions" + 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) + } + resp := g.srv.NewListByGalleryImagePager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + g.newListByGalleryImagePager = &resp + server.PagerResponderInjectNextLinks(g.newListByGalleryImagePager, req, func(page *armcompute.GalleryImageVersionsClientListByGalleryImageResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(g.newListByGalleryImagePager, 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(g.newListByGalleryImagePager) { + g.newListByGalleryImagePager = nil + } + return resp, nil +} + +func (g *GalleryImageVersionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if g.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.GalleryImageVersionUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.beginUpdate, 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.PollerResponderMore(g.beginUpdate) { + g.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go b/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go new file mode 100644 index 000000000000..aedf524107fd --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go @@ -0,0 +1,104 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// GallerySharingProfileServer is a fake server for instances of the armcompute.GallerySharingProfileClient type. +type GallerySharingProfileServer struct { + // BeginUpdate is the fake for method GallerySharingProfileClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, galleryName string, sharingUpdate armcompute.SharingUpdate, options *armcompute.GallerySharingProfileClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.GallerySharingProfileClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewGallerySharingProfileServerTransport creates a new instance of GallerySharingProfileServerTransport with the provided implementation. +// The returned GallerySharingProfileServerTransport instance is connected to an instance of armcompute.GallerySharingProfileClient by way of the +// undefined.Transporter field. +func NewGallerySharingProfileServerTransport(srv *GallerySharingProfileServer) *GallerySharingProfileServerTransport { + return &GallerySharingProfileServerTransport{srv: srv} +} + +// GallerySharingProfileServerTransport connects instances of armcompute.GallerySharingProfileClient to instances of GallerySharingProfileServer. +// Don't use this type directly, use NewGallerySharingProfileServerTransport instead. +type GallerySharingProfileServerTransport struct { + srv *GallerySharingProfileServer + beginUpdate *azfake.PollerResponder[armcompute.GallerySharingProfileClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for GallerySharingProfileServerTransport. +func (g *GallerySharingProfileServerTransport) 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 "GallerySharingProfileClient.BeginUpdate": + resp, err = g.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GallerySharingProfileServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if g.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if g.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/share" + 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[armcompute.SharingUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + g.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(g.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(g.beginUpdate) { + g.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/images_server.go b/sdk/resourcemanager/compute/armcompute/fake/images_server.go new file mode 100644 index 000000000000..170d33911c14 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/images_server.go @@ -0,0 +1,302 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// ImagesServer is a fake server for instances of the armcompute.ImagesClient type. +type ImagesServer struct { + // BeginCreateOrUpdate is the fake for method ImagesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, imageName string, parameters armcompute.Image, options *armcompute.ImagesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.ImagesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ImagesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, imageName string, options *armcompute.ImagesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.ImagesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ImagesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, imageName string, options *armcompute.ImagesClientGetOptions) (resp azfake.Responder[armcompute.ImagesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ImagesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.ImagesClientListOptions) (resp azfake.PagerResponder[armcompute.ImagesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method ImagesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.ImagesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.ImagesClientListByResourceGroupResponse]) + + // BeginUpdate is the fake for method ImagesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginUpdate func(ctx context.Context, resourceGroupName string, imageName string, parameters armcompute.ImageUpdate, options *armcompute.ImagesClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.ImagesClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewImagesServerTransport creates a new instance of ImagesServerTransport with the provided implementation. +// The returned ImagesServerTransport instance is connected to an instance of armcompute.ImagesClient by way of the +// undefined.Transporter field. +func NewImagesServerTransport(srv *ImagesServer) *ImagesServerTransport { + return &ImagesServerTransport{srv: srv} +} + +// ImagesServerTransport connects instances of armcompute.ImagesClient to instances of ImagesServer. +// Don't use this type directly, use NewImagesServerTransport instead. +type ImagesServerTransport struct { + srv *ImagesServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.ImagesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.ImagesClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.ImagesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armcompute.ImagesClientListByResourceGroupResponse] + beginUpdate *azfake.PollerResponder[armcompute.ImagesClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for ImagesServerTransport. +func (i *ImagesServerTransport) 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 "ImagesClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + case "ImagesClient.BeginDelete": + resp, err = i.dispatchBeginDelete(req) + case "ImagesClient.Get": + resp, err = i.dispatchGet(req) + case "ImagesClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + case "ImagesClient.NewListByResourceGroupPager": + resp, err = i.dispatchNewListByResourceGroupPager(req) + case "ImagesClient.BeginUpdate": + resp, err = i.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *ImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if i.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images/(?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[armcompute.Image](req) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + i.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(i.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(i.beginCreateOrUpdate) { + i.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (i *ImagesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if i.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if i.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images/(?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 := i.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + i.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(i.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(i.beginDelete) { + i.beginDelete = nil + } + + return resp, nil +} + +func (i *ImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.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.Compute/images/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.ImagesClientGetOptions + if expandParam != nil { + options = &armcompute.ImagesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], 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).Image, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *ImagesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if i.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images" + 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 := i.srv.NewListPager(nil) + i.newListPager = &resp + server.PagerResponderInjectNextLinks(i.newListPager, req, func(page *armcompute.ImagesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.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(i.newListPager) { + i.newListPager = nil + } + return resp, nil +} + +func (i *ImagesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + } + if i.newListByResourceGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images" + 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) + } + resp := i.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + i.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(i.newListByResourceGroupPager, req, func(page *armcompute.ImagesClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.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(i.newListByResourceGroupPager) { + i.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (i *ImagesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if i.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images/(?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[armcompute.ImageUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + i.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(i.beginUpdate, 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(i.beginUpdate) { + i.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/internal.go b/sdk/resourcemanager/compute/armcompute/fake/internal.go new file mode 100644 index 000000000000..e9c8222f2199 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/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/compute/armcompute/fake/loganalytics_server.go b/sdk/resourcemanager/compute/armcompute/fake/loganalytics_server.go new file mode 100644 index 000000000000..ab3e6ce3f519 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/loganalytics_server.go @@ -0,0 +1,148 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// LogAnalyticsServer is a fake server for instances of the armcompute.LogAnalyticsClient type. +type LogAnalyticsServer struct { + // BeginExportRequestRateByInterval is the fake for method LogAnalyticsClient.BeginExportRequestRateByInterval + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginExportRequestRateByInterval func(ctx context.Context, location string, parameters armcompute.RequestRateByIntervalInput, options *armcompute.LogAnalyticsClientBeginExportRequestRateByIntervalOptions) (resp azfake.PollerResponder[armcompute.LogAnalyticsClientExportRequestRateByIntervalResponse], errResp azfake.ErrorResponder) + + // BeginExportThrottledRequests is the fake for method LogAnalyticsClient.BeginExportThrottledRequests + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginExportThrottledRequests func(ctx context.Context, location string, parameters armcompute.ThrottledRequestsInput, options *armcompute.LogAnalyticsClientBeginExportThrottledRequestsOptions) (resp azfake.PollerResponder[armcompute.LogAnalyticsClientExportThrottledRequestsResponse], errResp azfake.ErrorResponder) +} + +// NewLogAnalyticsServerTransport creates a new instance of LogAnalyticsServerTransport with the provided implementation. +// The returned LogAnalyticsServerTransport instance is connected to an instance of armcompute.LogAnalyticsClient by way of the +// undefined.Transporter field. +func NewLogAnalyticsServerTransport(srv *LogAnalyticsServer) *LogAnalyticsServerTransport { + return &LogAnalyticsServerTransport{srv: srv} +} + +// LogAnalyticsServerTransport connects instances of armcompute.LogAnalyticsClient to instances of LogAnalyticsServer. +// Don't use this type directly, use NewLogAnalyticsServerTransport instead. +type LogAnalyticsServerTransport struct { + srv *LogAnalyticsServer + beginExportRequestRateByInterval *azfake.PollerResponder[armcompute.LogAnalyticsClientExportRequestRateByIntervalResponse] + beginExportThrottledRequests *azfake.PollerResponder[armcompute.LogAnalyticsClientExportThrottledRequestsResponse] +} + +// Do implements the policy.Transporter interface for LogAnalyticsServerTransport. +func (l *LogAnalyticsServerTransport) 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 "LogAnalyticsClient.BeginExportRequestRateByInterval": + resp, err = l.dispatchBeginExportRequestRateByInterval(req) + case "LogAnalyticsClient.BeginExportThrottledRequests": + resp, err = l.dispatchBeginExportThrottledRequests(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LogAnalyticsServerTransport) dispatchBeginExportRequestRateByInterval(req *http.Request) (*http.Response, error) { + if l.srv.BeginExportRequestRateByInterval == nil { + return nil, &nonRetriableError{errors.New("method BeginExportRequestRateByInterval not implemented")} + } + if l.beginExportRequestRateByInterval == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/logAnalytics/apiAccess/getRequestRateByInterval" + 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[armcompute.RequestRateByIntervalInput](req) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginExportRequestRateByInterval(req.Context(), matches[regex.SubexpIndex("location")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginExportRequestRateByInterval = &respr + } + + resp, err := server.PollerResponderNext(l.beginExportRequestRateByInterval, 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(l.beginExportRequestRateByInterval) { + l.beginExportRequestRateByInterval = nil + } + + return resp, nil +} + +func (l *LogAnalyticsServerTransport) dispatchBeginExportThrottledRequests(req *http.Request) (*http.Response, error) { + if l.srv.BeginExportThrottledRequests == nil { + return nil, &nonRetriableError{errors.New("method BeginExportThrottledRequests not implemented")} + } + if l.beginExportThrottledRequests == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/logAnalytics/apiAccess/getThrottledRequests" + 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[armcompute.ThrottledRequestsInput](req) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginExportThrottledRequests(req.Context(), matches[regex.SubexpIndex("location")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginExportThrottledRequests = &respr + } + + resp, err := server.PollerResponderNext(l.beginExportThrottledRequests, 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(l.beginExportThrottledRequests) { + l.beginExportThrottledRequests = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/operations_server.go b/sdk/resourcemanager/compute/armcompute/fake/operations_server.go new file mode 100644 index 000000000000..34ef72d4db85 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/operations_server.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 ( + "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/compute/armcompute/v5" + "net/http" +) + +// OperationsServer is a fake server for instances of the armcompute.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.OperationsClientListOptions) (resp azfake.PagerResponder[armcompute.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armcompute.OperationsClient by way of the +// undefined.Transporter field. +func NewOperationsServerTransport(srv *OperationsServer) *OperationsServerTransport { + return &OperationsServerTransport{srv: srv} +} + +// OperationsServerTransport connects instances of armcompute.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *azfake.PagerResponder[armcompute.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 + } + 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/compute/armcompute/fake/proximityplacementgroups_server.go b/sdk/resourcemanager/compute/armcompute/fake/proximityplacementgroups_server.go new file mode 100644 index 000000000000..eb8904bf214e --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/proximityplacementgroups_server.go @@ -0,0 +1,275 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// ProximityPlacementGroupsServer is a fake server for instances of the armcompute.ProximityPlacementGroupsClient type. +type ProximityPlacementGroupsServer struct { + // CreateOrUpdate is the fake for method ProximityPlacementGroupsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, parameters armcompute.ProximityPlacementGroup, options *armcompute.ProximityPlacementGroupsClientCreateOrUpdateOptions) (resp azfake.Responder[armcompute.ProximityPlacementGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method ProximityPlacementGroupsClient.Delete + // HTTP status codes to indicate success: http.StatusOK + Delete func(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, options *armcompute.ProximityPlacementGroupsClientDeleteOptions) (resp azfake.Responder[armcompute.ProximityPlacementGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ProximityPlacementGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, options *armcompute.ProximityPlacementGroupsClientGetOptions) (resp azfake.Responder[armcompute.ProximityPlacementGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method ProximityPlacementGroupsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.ProximityPlacementGroupsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.ProximityPlacementGroupsClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method ProximityPlacementGroupsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armcompute.ProximityPlacementGroupsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armcompute.ProximityPlacementGroupsClientListBySubscriptionResponse]) + + // Update is the fake for method ProximityPlacementGroupsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, parameters armcompute.ProximityPlacementGroupUpdate, options *armcompute.ProximityPlacementGroupsClientUpdateOptions) (resp azfake.Responder[armcompute.ProximityPlacementGroupsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewProximityPlacementGroupsServerTransport creates a new instance of ProximityPlacementGroupsServerTransport with the provided implementation. +// The returned ProximityPlacementGroupsServerTransport instance is connected to an instance of armcompute.ProximityPlacementGroupsClient by way of the +// undefined.Transporter field. +func NewProximityPlacementGroupsServerTransport(srv *ProximityPlacementGroupsServer) *ProximityPlacementGroupsServerTransport { + return &ProximityPlacementGroupsServerTransport{srv: srv} +} + +// ProximityPlacementGroupsServerTransport connects instances of armcompute.ProximityPlacementGroupsClient to instances of ProximityPlacementGroupsServer. +// Don't use this type directly, use NewProximityPlacementGroupsServerTransport instead. +type ProximityPlacementGroupsServerTransport struct { + srv *ProximityPlacementGroupsServer + newListByResourceGroupPager *azfake.PagerResponder[armcompute.ProximityPlacementGroupsClientListByResourceGroupResponse] + newListBySubscriptionPager *azfake.PagerResponder[armcompute.ProximityPlacementGroupsClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for ProximityPlacementGroupsServerTransport. +func (p *ProximityPlacementGroupsServerTransport) 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 "ProximityPlacementGroupsClient.CreateOrUpdate": + resp, err = p.dispatchCreateOrUpdate(req) + case "ProximityPlacementGroupsClient.Delete": + resp, err = p.dispatchDelete(req) + case "ProximityPlacementGroupsClient.Get": + resp, err = p.dispatchGet(req) + case "ProximityPlacementGroupsClient.NewListByResourceGroupPager": + resp, err = p.dispatchNewListByResourceGroupPager(req) + case "ProximityPlacementGroupsClient.NewListBySubscriptionPager": + resp, err = p.dispatchNewListBySubscriptionPager(req) + case "ProximityPlacementGroupsClient.Update": + resp, err = p.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *ProximityPlacementGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.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-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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[armcompute.ProximityPlacementGroup](req) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], 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).ProximityPlacementGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProximityPlacementGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if p.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("method Delete not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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 := p.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], 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 *ProximityPlacementGroupsServerTransport) 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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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) + } + qp := req.URL.Query() + includeColocationStatusParam := getOptional(qp.Get("includeColocationStatus")) + var options *armcompute.ProximityPlacementGroupsClientGetOptions + if includeColocationStatusParam != nil { + options = &armcompute.ProximityPlacementGroupsClientGetOptions{ + IncludeColocationStatus: includeColocationStatusParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], 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).ProximityPlacementGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProximityPlacementGroupsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + } + if p.newListByResourceGroupPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups" + 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) + } + resp := p.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + p.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(p.newListByResourceGroupPager, req, func(page *armcompute.ProximityPlacementGroupsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.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(p.newListByResourceGroupPager) { + p.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (p *ProximityPlacementGroupsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + } + if p.newListBySubscriptionPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups" + 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 := p.srv.NewListBySubscriptionPager(nil) + p.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(p.newListBySubscriptionPager, req, func(page *armcompute.ProximityPlacementGroupsClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListBySubscriptionPager, 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.newListBySubscriptionPager) { + p.newListBySubscriptionPager = nil + } + return resp, nil +} + +func (p *ProximityPlacementGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if p.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-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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[armcompute.ProximityPlacementGroupUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], 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).ProximityPlacementGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go b/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go new file mode 100644 index 000000000000..0426bbf53c64 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go @@ -0,0 +1,107 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// ResourceSKUsServer is a fake server for instances of the armcompute.ResourceSKUsClient type. +type ResourceSKUsServer struct { + // NewListPager is the fake for method ResourceSKUsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.ResourceSKUsClientListOptions) (resp azfake.PagerResponder[armcompute.ResourceSKUsClientListResponse]) +} + +// NewResourceSKUsServerTransport creates a new instance of ResourceSKUsServerTransport with the provided implementation. +// The returned ResourceSKUsServerTransport instance is connected to an instance of armcompute.ResourceSKUsClient by way of the +// undefined.Transporter field. +func NewResourceSKUsServerTransport(srv *ResourceSKUsServer) *ResourceSKUsServerTransport { + return &ResourceSKUsServerTransport{srv: srv} +} + +// ResourceSKUsServerTransport connects instances of armcompute.ResourceSKUsClient to instances of ResourceSKUsServer. +// Don't use this type directly, use NewResourceSKUsServerTransport instead. +type ResourceSKUsServerTransport struct { + srv *ResourceSKUsServer + newListPager *azfake.PagerResponder[armcompute.ResourceSKUsClientListResponse] +} + +// Do implements the policy.Transporter interface for ResourceSKUsServerTransport. +func (r *ResourceSKUsServerTransport) 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 "ResourceSKUsClient.NewListPager": + resp, err = r.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *ResourceSKUsServerTransport) 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-_]+)/providers/Microsoft.Compute/skus" + 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")) + includeExtendedLocationsParam := getOptional(qp.Get("includeExtendedLocations")) + var options *armcompute.ResourceSKUsClientListOptions + if filterParam != nil || includeExtendedLocationsParam != nil { + options = &armcompute.ResourceSKUsClientListOptions{ + Filter: filterParam, + IncludeExtendedLocations: includeExtendedLocationsParam, + } + } + resp := r.srv.NewListPager(options) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armcompute.ResourceSKUsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go b/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go new file mode 100644 index 000000000000..f518a03afeb9 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go @@ -0,0 +1,284 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// RestorePointCollectionsServer is a fake server for instances of the armcompute.RestorePointCollectionsClient type. +type RestorePointCollectionsServer struct { + // CreateOrUpdate is the fake for method RestorePointCollectionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, parameters armcompute.RestorePointCollection, options *armcompute.RestorePointCollectionsClientCreateOrUpdateOptions) (resp azfake.Responder[armcompute.RestorePointCollectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RestorePointCollectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, options *armcompute.RestorePointCollectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.RestorePointCollectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RestorePointCollectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, options *armcompute.RestorePointCollectionsClientGetOptions) (resp azfake.Responder[armcompute.RestorePointCollectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RestorePointCollectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armcompute.RestorePointCollectionsClientListOptions) (resp azfake.PagerResponder[armcompute.RestorePointCollectionsClientListResponse]) + + // NewListAllPager is the fake for method RestorePointCollectionsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armcompute.RestorePointCollectionsClientListAllOptions) (resp azfake.PagerResponder[armcompute.RestorePointCollectionsClientListAllResponse]) + + // Update is the fake for method RestorePointCollectionsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, parameters armcompute.RestorePointCollectionUpdate, options *armcompute.RestorePointCollectionsClientUpdateOptions) (resp azfake.Responder[armcompute.RestorePointCollectionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewRestorePointCollectionsServerTransport creates a new instance of RestorePointCollectionsServerTransport with the provided implementation. +// The returned RestorePointCollectionsServerTransport instance is connected to an instance of armcompute.RestorePointCollectionsClient by way of the +// undefined.Transporter field. +func NewRestorePointCollectionsServerTransport(srv *RestorePointCollectionsServer) *RestorePointCollectionsServerTransport { + return &RestorePointCollectionsServerTransport{srv: srv} +} + +// RestorePointCollectionsServerTransport connects instances of armcompute.RestorePointCollectionsClient to instances of RestorePointCollectionsServer. +// Don't use this type directly, use NewRestorePointCollectionsServerTransport instead. +type RestorePointCollectionsServerTransport struct { + srv *RestorePointCollectionsServer + beginDelete *azfake.PollerResponder[armcompute.RestorePointCollectionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.RestorePointCollectionsClientListResponse] + newListAllPager *azfake.PagerResponder[armcompute.RestorePointCollectionsClientListAllResponse] +} + +// Do implements the policy.Transporter interface for RestorePointCollectionsServerTransport. +func (r *RestorePointCollectionsServerTransport) 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 "RestorePointCollectionsClient.CreateOrUpdate": + resp, err = r.dispatchCreateOrUpdate(req) + case "RestorePointCollectionsClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RestorePointCollectionsClient.Get": + resp, err = r.dispatchGet(req) + case "RestorePointCollectionsClient.NewListPager": + resp, err = r.dispatchNewListPager(req) + case "RestorePointCollectionsClient.NewListAllPager": + resp, err = r.dispatchNewListAllPager(req) + case "RestorePointCollectionsClient.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 *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?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[armcompute.RestorePointCollection](req) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], 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).RestorePointCollection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?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 := r.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], nil) + 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, 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(r.beginDelete) { + r.beginDelete = nil + } + + return resp, nil +} + +func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.RestorePointCollectionExpandOptions(qp.Get("$expand"))) + var options *armcompute.RestorePointCollectionsClientGetOptions + if expandParam != nil { + options = &armcompute.RestorePointCollectionsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := r.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], 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).RestorePointCollection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RestorePointCollectionsServerTransport) 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/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections" + 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) + } + resp := r.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armcompute.RestorePointCollectionsClientListResponse, 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 *RestorePointCollectionsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + } + if r.newListAllPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections" + 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 := r.srv.NewListAllPager(nil) + r.newListAllPager = &resp + server.PagerResponderInjectNextLinks(r.newListAllPager, req, func(page *armcompute.RestorePointCollectionsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(r.newListAllPager, 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.newListAllPager) { + r.newListAllPager = nil + } + return resp, nil +} + +func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?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[armcompute.RestorePointCollectionUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], 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).RestorePointCollection, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go b/sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go new file mode 100644 index 000000000000..5341e7a91c6e --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go @@ -0,0 +1,183 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// RestorePointsServer is a fake server for instances of the armcompute.RestorePointsClient type. +type RestorePointsServer struct { + // BeginCreate is the fake for method RestorePointsClient.BeginCreate + // HTTP status codes to indicate success: http.StatusCreated + BeginCreate func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, restorePointName string, parameters armcompute.RestorePoint, options *armcompute.RestorePointsClientBeginCreateOptions) (resp azfake.PollerResponder[armcompute.RestorePointsClientCreateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RestorePointsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, restorePointName string, options *armcompute.RestorePointsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.RestorePointsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RestorePointsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, restorePointCollectionName string, restorePointName string, options *armcompute.RestorePointsClientGetOptions) (resp azfake.Responder[armcompute.RestorePointsClientGetResponse], errResp azfake.ErrorResponder) +} + +// NewRestorePointsServerTransport creates a new instance of RestorePointsServerTransport with the provided implementation. +// The returned RestorePointsServerTransport instance is connected to an instance of armcompute.RestorePointsClient by way of the +// undefined.Transporter field. +func NewRestorePointsServerTransport(srv *RestorePointsServer) *RestorePointsServerTransport { + return &RestorePointsServerTransport{srv: srv} +} + +// RestorePointsServerTransport connects instances of armcompute.RestorePointsClient to instances of RestorePointsServer. +// Don't use this type directly, use NewRestorePointsServerTransport instead. +type RestorePointsServerTransport struct { + srv *RestorePointsServer + beginCreate *azfake.PollerResponder[armcompute.RestorePointsClientCreateResponse] + beginDelete *azfake.PollerResponder[armcompute.RestorePointsClientDeleteResponse] +} + +// Do implements the policy.Transporter interface for RestorePointsServerTransport. +func (r *RestorePointsServerTransport) 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 "RestorePointsClient.BeginCreate": + resp, err = r.dispatchBeginCreate(req) + case "RestorePointsClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RestorePointsClient.Get": + resp, err = r.dispatchGet(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *RestorePointsServerTransport) dispatchBeginCreate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreate not implemented")} + } + if r.beginCreate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.RestorePoint](req) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("restorePointName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreate = &respr + } + + resp, err := server.PollerResponderNext(r.beginCreate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(r.beginCreate) { + r.beginCreate = nil + } + + return resp, nil +} + +func (r *RestorePointsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?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 := r.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("restorePointName")], nil) + 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, 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(r.beginDelete) { + r.beginDelete = nil + } + + return resp, nil +} + +func (r *RestorePointsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.RestorePointExpandOptions(qp.Get("$expand"))) + var options *armcompute.RestorePointsClientGetOptions + if expandParam != nil { + options = &armcompute.RestorePointsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := r.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("restorePointName")], 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).RestorePoint, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go new file mode 100644 index 000000000000..2be3c9502524 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go @@ -0,0 +1,137 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// SharedGalleriesServer is a fake server for instances of the armcompute.SharedGalleriesClient type. +type SharedGalleriesServer struct { + // Get is the fake for method SharedGalleriesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, galleryUniqueName string, options *armcompute.SharedGalleriesClientGetOptions) (resp azfake.Responder[armcompute.SharedGalleriesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SharedGalleriesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armcompute.SharedGalleriesClientListOptions) (resp azfake.PagerResponder[armcompute.SharedGalleriesClientListResponse]) +} + +// NewSharedGalleriesServerTransport creates a new instance of SharedGalleriesServerTransport with the provided implementation. +// The returned SharedGalleriesServerTransport instance is connected to an instance of armcompute.SharedGalleriesClient by way of the +// undefined.Transporter field. +func NewSharedGalleriesServerTransport(srv *SharedGalleriesServer) *SharedGalleriesServerTransport { + return &SharedGalleriesServerTransport{srv: srv} +} + +// SharedGalleriesServerTransport connects instances of armcompute.SharedGalleriesClient to instances of SharedGalleriesServer. +// Don't use this type directly, use NewSharedGalleriesServerTransport instead. +type SharedGalleriesServerTransport struct { + srv *SharedGalleriesServer + newListPager *azfake.PagerResponder[armcompute.SharedGalleriesClientListResponse] +} + +// Do implements the policy.Transporter interface for SharedGalleriesServerTransport. +func (s *SharedGalleriesServerTransport) 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 "SharedGalleriesClient.Get": + resp, err = s.dispatchGet(req) + case "SharedGalleriesClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SharedGalleriesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], 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).SharedGallery, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SharedGalleriesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries" + 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() + sharedToParam := getOptional(armcompute.SharedToValues(qp.Get("sharedTo"))) + var options *armcompute.SharedGalleriesClientListOptions + if sharedToParam != nil { + options = &armcompute.SharedGalleriesClientListOptions{ + SharedTo: sharedToParam, + } + } + resp := s.srv.NewListPager(matches[regex.SubexpIndex("location")], options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SharedGalleriesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go new file mode 100644 index 000000000000..b4aa2130aec4 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go @@ -0,0 +1,137 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// SharedGalleryImagesServer is a fake server for instances of the armcompute.SharedGalleryImagesClient type. +type SharedGalleryImagesServer struct { + // Get is the fake for method SharedGalleryImagesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, options *armcompute.SharedGalleryImagesClientGetOptions) (resp azfake.Responder[armcompute.SharedGalleryImagesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SharedGalleryImagesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, galleryUniqueName string, options *armcompute.SharedGalleryImagesClientListOptions) (resp azfake.PagerResponder[armcompute.SharedGalleryImagesClientListResponse]) +} + +// NewSharedGalleryImagesServerTransport creates a new instance of SharedGalleryImagesServerTransport with the provided implementation. +// The returned SharedGalleryImagesServerTransport instance is connected to an instance of armcompute.SharedGalleryImagesClient by way of the +// undefined.Transporter field. +func NewSharedGalleryImagesServerTransport(srv *SharedGalleryImagesServer) *SharedGalleryImagesServerTransport { + return &SharedGalleryImagesServerTransport{srv: srv} +} + +// SharedGalleryImagesServerTransport connects instances of armcompute.SharedGalleryImagesClient to instances of SharedGalleryImagesServer. +// Don't use this type directly, use NewSharedGalleryImagesServerTransport instead. +type SharedGalleryImagesServerTransport struct { + srv *SharedGalleryImagesServer + newListPager *azfake.PagerResponder[armcompute.SharedGalleryImagesClientListResponse] +} + +// Do implements the policy.Transporter interface for SharedGalleryImagesServerTransport. +func (s *SharedGalleryImagesServerTransport) 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 "SharedGalleryImagesClient.Get": + resp, err = s.dispatchGet(req) + case "SharedGalleryImagesClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SharedGalleryImagesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], matches[regex.SubexpIndex("galleryImageName")], 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).SharedGalleryImage, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SharedGalleryImagesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images" + 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() + sharedToParam := getOptional(armcompute.SharedToValues(qp.Get("sharedTo"))) + var options *armcompute.SharedGalleryImagesClientListOptions + if sharedToParam != nil { + options = &armcompute.SharedGalleryImagesClientListOptions{ + SharedTo: sharedToParam, + } + } + resp := s.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SharedGalleryImagesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go new file mode 100644 index 000000000000..59224deba273 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go @@ -0,0 +1,137 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// SharedGalleryImageVersionsServer is a fake server for instances of the armcompute.SharedGalleryImageVersionsClient type. +type SharedGalleryImageVersionsServer struct { + // Get is the fake for method SharedGalleryImageVersionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, galleryImageVersionName string, options *armcompute.SharedGalleryImageVersionsClientGetOptions) (resp azfake.Responder[armcompute.SharedGalleryImageVersionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SharedGalleryImageVersionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, galleryUniqueName string, galleryImageName string, options *armcompute.SharedGalleryImageVersionsClientListOptions) (resp azfake.PagerResponder[armcompute.SharedGalleryImageVersionsClientListResponse]) +} + +// NewSharedGalleryImageVersionsServerTransport creates a new instance of SharedGalleryImageVersionsServerTransport with the provided implementation. +// The returned SharedGalleryImageVersionsServerTransport instance is connected to an instance of armcompute.SharedGalleryImageVersionsClient by way of the +// undefined.Transporter field. +func NewSharedGalleryImageVersionsServerTransport(srv *SharedGalleryImageVersionsServer) *SharedGalleryImageVersionsServerTransport { + return &SharedGalleryImageVersionsServerTransport{srv: srv} +} + +// SharedGalleryImageVersionsServerTransport connects instances of armcompute.SharedGalleryImageVersionsClient to instances of SharedGalleryImageVersionsServer. +// Don't use this type directly, use NewSharedGalleryImageVersionsServerTransport instead. +type SharedGalleryImageVersionsServerTransport struct { + srv *SharedGalleryImageVersionsServer + newListPager *azfake.PagerResponder[armcompute.SharedGalleryImageVersionsClientListResponse] +} + +// Do implements the policy.Transporter interface for SharedGalleryImageVersionsServerTransport. +func (s *SharedGalleryImageVersionsServerTransport) 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 "SharedGalleryImageVersionsClient.Get": + resp, err = s.dispatchGet(req) + case "SharedGalleryImageVersionsClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SharedGalleryImageVersionsServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := s.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], 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).SharedGalleryImageVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SharedGalleryImageVersionsServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions" + 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) + } + qp := req.URL.Query() + sharedToParam := getOptional(armcompute.SharedToValues(qp.Get("sharedTo"))) + var options *armcompute.SharedGalleryImageVersionsClientListOptions + if sharedToParam != nil { + options = &armcompute.SharedGalleryImageVersionsClientListOptions{ + SharedTo: sharedToParam, + } + } + resp := s.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], matches[regex.SubexpIndex("galleryImageName")], options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SharedGalleryImageVersionsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go b/sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go new file mode 100644 index 000000000000..87f9c79eba20 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go @@ -0,0 +1,378 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// SnapshotsServer is a fake server for instances of the armcompute.SnapshotsClient type. +type SnapshotsServer struct { + // BeginCreateOrUpdate is the fake for method SnapshotsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, snapshotName string, snapshot armcompute.Snapshot, options *armcompute.SnapshotsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.SnapshotsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SnapshotsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, snapshotName string, options *armcompute.SnapshotsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.SnapshotsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SnapshotsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, snapshotName string, options *armcompute.SnapshotsClientGetOptions) (resp azfake.Responder[armcompute.SnapshotsClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGrantAccess is the fake for method SnapshotsClient.BeginGrantAccess + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGrantAccess func(ctx context.Context, resourceGroupName string, snapshotName string, grantAccessData armcompute.GrantAccessData, options *armcompute.SnapshotsClientBeginGrantAccessOptions) (resp azfake.PollerResponder[armcompute.SnapshotsClientGrantAccessResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SnapshotsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armcompute.SnapshotsClientListOptions) (resp azfake.PagerResponder[armcompute.SnapshotsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method SnapshotsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.SnapshotsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.SnapshotsClientListByResourceGroupResponse]) + + // BeginRevokeAccess is the fake for method SnapshotsClient.BeginRevokeAccess + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRevokeAccess func(ctx context.Context, resourceGroupName string, snapshotName string, options *armcompute.SnapshotsClientBeginRevokeAccessOptions) (resp azfake.PollerResponder[armcompute.SnapshotsClientRevokeAccessResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method SnapshotsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, snapshotName string, snapshot armcompute.SnapshotUpdate, options *armcompute.SnapshotsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.SnapshotsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewSnapshotsServerTransport creates a new instance of SnapshotsServerTransport with the provided implementation. +// The returned SnapshotsServerTransport instance is connected to an instance of armcompute.SnapshotsClient by way of the +// undefined.Transporter field. +func NewSnapshotsServerTransport(srv *SnapshotsServer) *SnapshotsServerTransport { + return &SnapshotsServerTransport{srv: srv} +} + +// SnapshotsServerTransport connects instances of armcompute.SnapshotsClient to instances of SnapshotsServer. +// Don't use this type directly, use NewSnapshotsServerTransport instead. +type SnapshotsServerTransport struct { + srv *SnapshotsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.SnapshotsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.SnapshotsClientDeleteResponse] + beginGrantAccess *azfake.PollerResponder[armcompute.SnapshotsClientGrantAccessResponse] + newListPager *azfake.PagerResponder[armcompute.SnapshotsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armcompute.SnapshotsClientListByResourceGroupResponse] + beginRevokeAccess *azfake.PollerResponder[armcompute.SnapshotsClientRevokeAccessResponse] + beginUpdate *azfake.PollerResponder[armcompute.SnapshotsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for SnapshotsServerTransport. +func (s *SnapshotsServerTransport) 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 "SnapshotsClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "SnapshotsClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "SnapshotsClient.Get": + resp, err = s.dispatchGet(req) + case "SnapshotsClient.BeginGrantAccess": + resp, err = s.dispatchBeginGrantAccess(req) + case "SnapshotsClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "SnapshotsClient.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "SnapshotsClient.BeginRevokeAccess": + resp, err = s.dispatchBeginRevokeAccess(req) + case "SnapshotsClient.BeginUpdate": + resp, err = s.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?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[armcompute.Snapshot](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], 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.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.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?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 := s.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], 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 *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], 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).Snapshot, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SnapshotsServerTransport) dispatchBeginGrantAccess(req *http.Request) (*http.Response, error) { + if s.srv.BeginGrantAccess == nil { + return nil, &nonRetriableError{errors.New("method BeginGrantAccess not implemented")} + } + if s.beginGrantAccess == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)/beginGetAccess" + 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[armcompute.GrantAccessData](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginGrantAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginGrantAccess = &respr + } + + resp, err := server.PollerResponderNext(s.beginGrantAccess, 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.beginGrantAccess) { + s.beginGrantAccess = nil + } + + return resp, nil +} + +func (s *SnapshotsServerTransport) 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-_]+)/providers/Microsoft.Compute/snapshots" + 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 := s.srv.NewListPager(nil) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SnapshotsClientListResponse, 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 *SnapshotsServerTransport) 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-_]+)/providers/Microsoft.Compute/snapshots" + 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) + } + resp := s.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + s.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armcompute.SnapshotsClientListByResourceGroupResponse, 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 *SnapshotsServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*http.Response, error) { + if s.srv.BeginRevokeAccess == nil { + return nil, &nonRetriableError{errors.New("method BeginRevokeAccess not implemented")} + } + if s.beginRevokeAccess == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)/endGetAccess" + 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 := s.srv.BeginRevokeAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginRevokeAccess = &respr + } + + resp, err := server.PollerResponderNext(s.beginRevokeAccess, 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.beginRevokeAccess) { + s.beginRevokeAccess = nil + } + + return resp, nil +} + +func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?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[armcompute.SnapshotUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], 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 +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go b/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go new file mode 100644 index 000000000000..970987158ddb --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go @@ -0,0 +1,298 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// SSHPublicKeysServer is a fake server for instances of the armcompute.SSHPublicKeysClient type. +type SSHPublicKeysServer struct { + // Create is the fake for method SSHPublicKeysClient.Create + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + Create func(ctx context.Context, resourceGroupName string, sshPublicKeyName string, parameters armcompute.SSHPublicKeyResource, options *armcompute.SSHPublicKeysClientCreateOptions) (resp azfake.Responder[armcompute.SSHPublicKeysClientCreateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method SSHPublicKeysClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, sshPublicKeyName string, options *armcompute.SSHPublicKeysClientDeleteOptions) (resp azfake.Responder[armcompute.SSHPublicKeysClientDeleteResponse], errResp azfake.ErrorResponder) + + // GenerateKeyPair is the fake for method SSHPublicKeysClient.GenerateKeyPair + // HTTP status codes to indicate success: http.StatusOK + GenerateKeyPair func(ctx context.Context, resourceGroupName string, sshPublicKeyName string, options *armcompute.SSHPublicKeysClientGenerateKeyPairOptions) (resp azfake.Responder[armcompute.SSHPublicKeysClientGenerateKeyPairResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SSHPublicKeysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, sshPublicKeyName string, options *armcompute.SSHPublicKeysClientGetOptions) (resp azfake.Responder[armcompute.SSHPublicKeysClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method SSHPublicKeysClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armcompute.SSHPublicKeysClientListByResourceGroupOptions) (resp azfake.PagerResponder[armcompute.SSHPublicKeysClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method SSHPublicKeysClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armcompute.SSHPublicKeysClientListBySubscriptionOptions) (resp azfake.PagerResponder[armcompute.SSHPublicKeysClientListBySubscriptionResponse]) + + // Update is the fake for method SSHPublicKeysClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, sshPublicKeyName string, parameters armcompute.SSHPublicKeyUpdateResource, options *armcompute.SSHPublicKeysClientUpdateOptions) (resp azfake.Responder[armcompute.SSHPublicKeysClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewSSHPublicKeysServerTransport creates a new instance of SSHPublicKeysServerTransport with the provided implementation. +// The returned SSHPublicKeysServerTransport instance is connected to an instance of armcompute.SSHPublicKeysClient by way of the +// undefined.Transporter field. +func NewSSHPublicKeysServerTransport(srv *SSHPublicKeysServer) *SSHPublicKeysServerTransport { + return &SSHPublicKeysServerTransport{srv: srv} +} + +// SSHPublicKeysServerTransport connects instances of armcompute.SSHPublicKeysClient to instances of SSHPublicKeysServer. +// Don't use this type directly, use NewSSHPublicKeysServerTransport instead. +type SSHPublicKeysServerTransport struct { + srv *SSHPublicKeysServer + newListByResourceGroupPager *azfake.PagerResponder[armcompute.SSHPublicKeysClientListByResourceGroupResponse] + newListBySubscriptionPager *azfake.PagerResponder[armcompute.SSHPublicKeysClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for SSHPublicKeysServerTransport. +func (s *SSHPublicKeysServerTransport) 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 "SSHPublicKeysClient.Create": + resp, err = s.dispatchCreate(req) + case "SSHPublicKeysClient.Delete": + resp, err = s.dispatchDelete(req) + case "SSHPublicKeysClient.GenerateKeyPair": + resp, err = s.dispatchGenerateKeyPair(req) + case "SSHPublicKeysClient.Get": + resp, err = s.dispatchGet(req) + case "SSHPublicKeysClient.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "SSHPublicKeysClient.NewListBySubscriptionPager": + resp, err = s.dispatchNewListBySubscriptionPager(req) + case "SSHPublicKeysClient.Update": + resp, err = s.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SSHPublicKeysServerTransport) dispatchCreate(req *http.Request) (*http.Response, error) { + if s.srv.Create == nil { + return nil, &nonRetriableError{errors.New("method Create not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?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[armcompute.SSHPublicKeyResource](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Create(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], 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).SSHPublicKeyResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SSHPublicKeysServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("method Delete not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?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 := s.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], 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 (s *SSHPublicKeysServerTransport) dispatchGenerateKeyPair(req *http.Request) (*http.Response, error) { + if s.srv.GenerateKeyPair == nil { + return nil, &nonRetriableError{errors.New("method GenerateKeyPair not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?P[a-zA-Z0-9-_]+)/generateKeyPair" + 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 := s.srv.GenerateKeyPair(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], 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).SSHPublicKeyGenerateKeyPairResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SSHPublicKeysServerTransport) 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/Microsoft.Compute/sshPublicKeys/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], 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).SSHPublicKeyResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SSHPublicKeysServerTransport) 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-_]+)/providers/Microsoft.Compute/sshPublicKeys" + 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) + } + resp := s.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + s.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armcompute.SSHPublicKeysClientListByResourceGroupResponse, 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 *SSHPublicKeysServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + } + if s.newListBySubscriptionPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys" + 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 := s.srv.NewListBySubscriptionPager(nil) + s.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(s.newListBySubscriptionPager, req, func(page *armcompute.SSHPublicKeysClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(s.newListBySubscriptionPager, 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.newListBySubscriptionPager) { + s.newListBySubscriptionPager = nil + } + return resp, nil +} + +func (s *SSHPublicKeysServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if s.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-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?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[armcompute.SSHPublicKeyUpdateResource](req) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], 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).SSHPublicKeyResource, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/time_rfc3339.go b/sdk/resourcemanager/compute/armcompute/fake/time_rfc3339.go new file mode 100644 index 000000000000..45fe10cbc6df --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/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/compute/armcompute/fake/usage_server.go b/sdk/resourcemanager/compute/armcompute/fake/usage_server.go new file mode 100644 index 000000000000..6fbd4b9416fc --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/usage_server.go @@ -0,0 +1,97 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// UsageServer is a fake server for instances of the armcompute.UsageClient type. +type UsageServer struct { + // NewListPager is the fake for method UsageClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armcompute.UsageClientListOptions) (resp azfake.PagerResponder[armcompute.UsageClientListResponse]) +} + +// NewUsageServerTransport creates a new instance of UsageServerTransport with the provided implementation. +// The returned UsageServerTransport instance is connected to an instance of armcompute.UsageClient by way of the +// undefined.Transporter field. +func NewUsageServerTransport(srv *UsageServer) *UsageServerTransport { + return &UsageServerTransport{srv: srv} +} + +// UsageServerTransport connects instances of armcompute.UsageClient to instances of UsageServer. +// Don't use this type directly, use NewUsageServerTransport instead. +type UsageServerTransport struct { + srv *UsageServer + newListPager *azfake.PagerResponder[armcompute.UsageClientListResponse] +} + +// Do implements the policy.Transporter interface for UsageServerTransport. +func (u *UsageServerTransport) 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 "UsageClient.NewListPager": + resp, err = u.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (u *UsageServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if u.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if u.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/usages" + 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) + } + resp := u.srv.NewListPager(matches[regex.SubexpIndex("location")], nil) + u.newListPager = &resp + server.PagerResponderInjectNextLinks(u.newListPager, req, func(page *armcompute.UsageClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(u.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(u.newListPager) { + u.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go new file mode 100644 index 000000000000..9456dd39f9c4 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go @@ -0,0 +1,175 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" + "strconv" +) + +// VirtualMachineExtensionImagesServer is a fake server for instances of the armcompute.VirtualMachineExtensionImagesClient type. +type VirtualMachineExtensionImagesServer struct { + // Get is the fake for method VirtualMachineExtensionImagesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, publisherName string, typeParam string, version string, options *armcompute.VirtualMachineExtensionImagesClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineExtensionImagesClientGetResponse], errResp azfake.ErrorResponder) + + // ListTypes is the fake for method VirtualMachineExtensionImagesClient.ListTypes + // HTTP status codes to indicate success: http.StatusOK + ListTypes func(ctx context.Context, location string, publisherName string, options *armcompute.VirtualMachineExtensionImagesClientListTypesOptions) (resp azfake.Responder[armcompute.VirtualMachineExtensionImagesClientListTypesResponse], errResp azfake.ErrorResponder) + + // ListVersions is the fake for method VirtualMachineExtensionImagesClient.ListVersions + // HTTP status codes to indicate success: http.StatusOK + ListVersions func(ctx context.Context, location string, publisherName string, typeParam string, options *armcompute.VirtualMachineExtensionImagesClientListVersionsOptions) (resp azfake.Responder[armcompute.VirtualMachineExtensionImagesClientListVersionsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineExtensionImagesServerTransport creates a new instance of VirtualMachineExtensionImagesServerTransport with the provided implementation. +// The returned VirtualMachineExtensionImagesServerTransport instance is connected to an instance of armcompute.VirtualMachineExtensionImagesClient by way of the +// undefined.Transporter field. +func NewVirtualMachineExtensionImagesServerTransport(srv *VirtualMachineExtensionImagesServer) *VirtualMachineExtensionImagesServerTransport { + return &VirtualMachineExtensionImagesServerTransport{srv: srv} +} + +// VirtualMachineExtensionImagesServerTransport connects instances of armcompute.VirtualMachineExtensionImagesClient to instances of VirtualMachineExtensionImagesServer. +// Don't use this type directly, use NewVirtualMachineExtensionImagesServerTransport instead. +type VirtualMachineExtensionImagesServerTransport struct { + srv *VirtualMachineExtensionImagesServer +} + +// Do implements the policy.Transporter interface for VirtualMachineExtensionImagesServerTransport. +func (v *VirtualMachineExtensionImagesServerTransport) 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 "VirtualMachineExtensionImagesClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineExtensionImagesClient.ListTypes": + resp, err = v.dispatchListTypes(req) + case "VirtualMachineExtensionImagesClient.ListVersions": + resp, err = v.dispatchListVersions(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineExtensionImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmextension/types/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("type")], matches[regex.SubexpIndex("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).VirtualMachineExtensionImage, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineExtensionImagesServerTransport) dispatchListTypes(req *http.Request) (*http.Response, error) { + if v.srv.ListTypes == nil { + return nil, &nonRetriableError{errors.New("method ListTypes not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmextension/types" + 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 := v.srv.ListTypes(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], 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).VirtualMachineExtensionImageArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineExtensionImagesServerTransport) dispatchListVersions(req *http.Request) (*http.Response, error) { + if v.srv.ListVersions == nil { + return nil, &nonRetriableError{errors.New("method ListVersions not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmextension/types/(?P[a-zA-Z0-9-_]+)/versions" + 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) + } + 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 + } + orderbyParam := getOptional(qp.Get("$orderby")) + var options *armcompute.VirtualMachineExtensionImagesClientListVersionsOptions + if filterParam != nil || topParam != nil || orderbyParam != nil { + options = &armcompute.VirtualMachineExtensionImagesClientListVersionsOptions{ + Filter: filterParam, + Top: topParam, + Orderby: orderbyParam, + } + } + respr, errRespr := v.srv.ListVersions(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("type")], 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).VirtualMachineExtensionImageArray, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go new file mode 100644 index 000000000000..cb30df6a9ebc --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go @@ -0,0 +1,266 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineExtensionsServer is a fake server for instances of the armcompute.VirtualMachineExtensionsClient type. +type VirtualMachineExtensionsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualMachineExtensionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, extensionParameters armcompute.VirtualMachineExtension, options *armcompute.VirtualMachineExtensionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineExtensionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineExtensionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, options *armcompute.VirtualMachineExtensionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineExtensionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineExtensionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, options *armcompute.VirtualMachineExtensionsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineExtensionsClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method VirtualMachineExtensionsClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachineExtensionsClientListOptions) (resp azfake.Responder[armcompute.VirtualMachineExtensionsClientListResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method VirtualMachineExtensionsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, extensionParameters armcompute.VirtualMachineExtensionUpdate, options *armcompute.VirtualMachineExtensionsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineExtensionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineExtensionsServerTransport creates a new instance of VirtualMachineExtensionsServerTransport with the provided implementation. +// The returned VirtualMachineExtensionsServerTransport instance is connected to an instance of armcompute.VirtualMachineExtensionsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineExtensionsServerTransport(srv *VirtualMachineExtensionsServer) *VirtualMachineExtensionsServerTransport { + return &VirtualMachineExtensionsServerTransport{srv: srv} +} + +// VirtualMachineExtensionsServerTransport connects instances of armcompute.VirtualMachineExtensionsClient to instances of VirtualMachineExtensionsServer. +// Don't use this type directly, use NewVirtualMachineExtensionsServerTransport instead. +type VirtualMachineExtensionsServerTransport struct { + srv *VirtualMachineExtensionsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachineExtensionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineExtensionsClientDeleteResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineExtensionsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineExtensionsServerTransport. +func (v *VirtualMachineExtensionsServerTransport) 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 "VirtualMachineExtensionsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachineExtensionsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineExtensionsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineExtensionsClient.List": + resp, err = v.dispatchList(req) + case "VirtualMachineExtensionsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineExtensionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineExtension](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineExtensionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?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 := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineExtensionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineExtensionsClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachineExtensionsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], 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).VirtualMachineExtension, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineExtensionsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if v.srv.List == nil { + return nil, &nonRetriableError{errors.New("method List not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions" + 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() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineExtensionsClientListOptions + if expandParam != nil { + options = &armcompute.VirtualMachineExtensionsClientListOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], 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).VirtualMachineExtensionsListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineExtensionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineExtensionUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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.PollerResponderMore(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go new file mode 100644 index 000000000000..89d7276ba954 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go @@ -0,0 +1,268 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" + "strconv" +) + +// VirtualMachineImagesServer is a fake server for instances of the armcompute.VirtualMachineImagesClient type. +type VirtualMachineImagesServer struct { + // Get is the fake for method VirtualMachineImagesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, publisherName string, offer string, skus string, version string, options *armcompute.VirtualMachineImagesClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method VirtualMachineImagesClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, location string, publisherName string, offer string, skus string, options *armcompute.VirtualMachineImagesClientListOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesClientListResponse], errResp azfake.ErrorResponder) + + // ListByEdgeZone is the fake for method VirtualMachineImagesClient.ListByEdgeZone + // HTTP status codes to indicate success: http.StatusOK + ListByEdgeZone func(ctx context.Context, location string, edgeZone string, options *armcompute.VirtualMachineImagesClientListByEdgeZoneOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesClientListByEdgeZoneResponse], errResp azfake.ErrorResponder) + + // ListOffers is the fake for method VirtualMachineImagesClient.ListOffers + // HTTP status codes to indicate success: http.StatusOK + ListOffers func(ctx context.Context, location string, publisherName string, options *armcompute.VirtualMachineImagesClientListOffersOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesClientListOffersResponse], errResp azfake.ErrorResponder) + + // ListPublishers is the fake for method VirtualMachineImagesClient.ListPublishers + // HTTP status codes to indicate success: http.StatusOK + ListPublishers func(ctx context.Context, location string, options *armcompute.VirtualMachineImagesClientListPublishersOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesClientListPublishersResponse], errResp azfake.ErrorResponder) + + // ListSKUs is the fake for method VirtualMachineImagesClient.ListSKUs + // HTTP status codes to indicate success: http.StatusOK + ListSKUs func(ctx context.Context, location string, publisherName string, offer string, options *armcompute.VirtualMachineImagesClientListSKUsOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesClientListSKUsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineImagesServerTransport creates a new instance of VirtualMachineImagesServerTransport with the provided implementation. +// The returned VirtualMachineImagesServerTransport instance is connected to an instance of armcompute.VirtualMachineImagesClient by way of the +// undefined.Transporter field. +func NewVirtualMachineImagesServerTransport(srv *VirtualMachineImagesServer) *VirtualMachineImagesServerTransport { + return &VirtualMachineImagesServerTransport{srv: srv} +} + +// VirtualMachineImagesServerTransport connects instances of armcompute.VirtualMachineImagesClient to instances of VirtualMachineImagesServer. +// Don't use this type directly, use NewVirtualMachineImagesServerTransport instead. +type VirtualMachineImagesServerTransport struct { + srv *VirtualMachineImagesServer +} + +// Do implements the policy.Transporter interface for VirtualMachineImagesServerTransport. +func (v *VirtualMachineImagesServerTransport) 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 "VirtualMachineImagesClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineImagesClient.List": + resp, err = v.dispatchList(req) + case "VirtualMachineImagesClient.ListByEdgeZone": + resp, err = v.dispatchListByEdgeZone(req) + case "VirtualMachineImagesClient.ListOffers": + resp, err = v.dispatchListOffers(req) + case "VirtualMachineImagesClient.ListPublishers": + resp, err = v.dispatchListPublishers(req) + case "VirtualMachineImagesClient.ListSKUs": + resp, err = v.dispatchListSKUs(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions/(?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) + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], matches[regex.SubexpIndex("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).VirtualMachineImage, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if v.srv.List == nil { + return nil, &nonRetriableError{errors.New("method List not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + 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 + } + orderbyParam := getOptional(qp.Get("$orderby")) + var options *armcompute.VirtualMachineImagesClientListOptions + if expandParam != nil || topParam != nil || orderbyParam != nil { + options = &armcompute.VirtualMachineImagesClientListOptions{ + Expand: expandParam, + Top: topParam, + Orderby: orderbyParam, + } + } + respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesServerTransport) dispatchListByEdgeZone(req *http.Request) (*http.Response, error) { + if v.srv.ListByEdgeZone == nil { + return nil, &nonRetriableError{errors.New("method ListByEdgeZone not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/vmimages" + 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 := v.srv.ListByEdgeZone(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], 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).VMImagesInEdgeZoneListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesServerTransport) dispatchListOffers(req *http.Request) (*http.Response, error) { + if v.srv.ListOffers == nil { + return nil, &nonRetriableError{errors.New("method ListOffers not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers" + 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 := v.srv.ListOffers(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesServerTransport) dispatchListPublishers(req *http.Request) (*http.Response, error) { + if v.srv.ListPublishers == nil { + return nil, &nonRetriableError{errors.New("method ListPublishers not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers" + 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 := v.srv.ListPublishers(req.Context(), matches[regex.SubexpIndex("location")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesServerTransport) dispatchListSKUs(req *http.Request) (*http.Response, error) { + if v.srv.ListSKUs == nil { + return nil, &nonRetriableError{errors.New("method ListSKUs not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus" + 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 := v.srv.ListSKUs(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go new file mode 100644 index 000000000000..e82926b00339 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go @@ -0,0 +1,237 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" + "strconv" +) + +// VirtualMachineImagesEdgeZoneServer is a fake server for instances of the armcompute.VirtualMachineImagesEdgeZoneClient type. +type VirtualMachineImagesEdgeZoneServer struct { + // Get is the fake for method VirtualMachineImagesEdgeZoneClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, edgeZone string, publisherName string, offer string, skus string, version string, options *armcompute.VirtualMachineImagesEdgeZoneClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesEdgeZoneClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method VirtualMachineImagesEdgeZoneClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, location string, edgeZone string, publisherName string, offer string, skus string, options *armcompute.VirtualMachineImagesEdgeZoneClientListOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesEdgeZoneClientListResponse], errResp azfake.ErrorResponder) + + // ListOffers is the fake for method VirtualMachineImagesEdgeZoneClient.ListOffers + // HTTP status codes to indicate success: http.StatusOK + ListOffers func(ctx context.Context, location string, edgeZone string, publisherName string, options *armcompute.VirtualMachineImagesEdgeZoneClientListOffersOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesEdgeZoneClientListOffersResponse], errResp azfake.ErrorResponder) + + // ListPublishers is the fake for method VirtualMachineImagesEdgeZoneClient.ListPublishers + // HTTP status codes to indicate success: http.StatusOK + ListPublishers func(ctx context.Context, location string, edgeZone string, options *armcompute.VirtualMachineImagesEdgeZoneClientListPublishersOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesEdgeZoneClientListPublishersResponse], errResp azfake.ErrorResponder) + + // ListSKUs is the fake for method VirtualMachineImagesEdgeZoneClient.ListSKUs + // HTTP status codes to indicate success: http.StatusOK + ListSKUs func(ctx context.Context, location string, edgeZone string, publisherName string, offer string, options *armcompute.VirtualMachineImagesEdgeZoneClientListSKUsOptions) (resp azfake.Responder[armcompute.VirtualMachineImagesEdgeZoneClientListSKUsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineImagesEdgeZoneServerTransport creates a new instance of VirtualMachineImagesEdgeZoneServerTransport with the provided implementation. +// The returned VirtualMachineImagesEdgeZoneServerTransport instance is connected to an instance of armcompute.VirtualMachineImagesEdgeZoneClient by way of the +// undefined.Transporter field. +func NewVirtualMachineImagesEdgeZoneServerTransport(srv *VirtualMachineImagesEdgeZoneServer) *VirtualMachineImagesEdgeZoneServerTransport { + return &VirtualMachineImagesEdgeZoneServerTransport{srv: srv} +} + +// VirtualMachineImagesEdgeZoneServerTransport connects instances of armcompute.VirtualMachineImagesEdgeZoneClient to instances of VirtualMachineImagesEdgeZoneServer. +// Don't use this type directly, use NewVirtualMachineImagesEdgeZoneServerTransport instead. +type VirtualMachineImagesEdgeZoneServerTransport struct { + srv *VirtualMachineImagesEdgeZoneServer +} + +// Do implements the policy.Transporter interface for VirtualMachineImagesEdgeZoneServerTransport. +func (v *VirtualMachineImagesEdgeZoneServerTransport) 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 "VirtualMachineImagesEdgeZoneClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineImagesEdgeZoneClient.List": + resp, err = v.dispatchList(req) + case "VirtualMachineImagesEdgeZoneClient.ListOffers": + resp, err = v.dispatchListOffers(req) + case "VirtualMachineImagesEdgeZoneClient.ListPublishers": + resp, err = v.dispatchListPublishers(req) + case "VirtualMachineImagesEdgeZoneClient.ListSKUs": + resp, err = v.dispatchListSKUs(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 7 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], matches[regex.SubexpIndex("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).VirtualMachineImage, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if v.srv.List == nil { + return nil, &nonRetriableError{errors.New("method List not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions" + 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() + 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 + } + orderbyParam := getOptional(qp.Get("$orderby")) + var options *armcompute.VirtualMachineImagesEdgeZoneClientListOptions + if expandParam != nil || topParam != nil || orderbyParam != nil { + options = &armcompute.VirtualMachineImagesEdgeZoneClientListOptions{ + Expand: expandParam, + Top: topParam, + Orderby: orderbyParam, + } + } + respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListOffers(req *http.Request) (*http.Response, error) { + if v.srv.ListOffers == nil { + return nil, &nonRetriableError{errors.New("method ListOffers not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers" + 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 := v.srv.ListOffers(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListPublishers(req *http.Request) (*http.Response, error) { + if v.srv.ListPublishers == nil { + return nil, &nonRetriableError{errors.New("method ListPublishers not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers" + 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 := v.srv.ListPublishers(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListSKUs(req *http.Request) (*http.Response, error) { + if v.srv.ListSKUs == nil { + return nil, &nonRetriableError{errors.New("method ListSKUs not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := v.srv.ListSKUs(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], 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).VirtualMachineImageResourceArray, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go new file mode 100644 index 000000000000..3d4208f4e215 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go @@ -0,0 +1,341 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineRunCommandsServer is a fake server for instances of the armcompute.VirtualMachineRunCommandsClient type. +type VirtualMachineRunCommandsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualMachineRunCommandsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, runCommand armcompute.VirtualMachineRunCommand, options *armcompute.VirtualMachineRunCommandsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineRunCommandsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineRunCommandsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, options *armcompute.VirtualMachineRunCommandsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineRunCommandsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineRunCommandsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, commandID string, options *armcompute.VirtualMachineRunCommandsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineRunCommandsClientGetResponse], errResp azfake.ErrorResponder) + + // GetByVirtualMachine is the fake for method VirtualMachineRunCommandsClient.GetByVirtualMachine + // HTTP status codes to indicate success: http.StatusOK + GetByVirtualMachine func(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, options *armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineOptions) (resp azfake.Responder[armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualMachineRunCommandsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armcompute.VirtualMachineRunCommandsClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineRunCommandsClientListResponse]) + + // NewListByVirtualMachinePager is the fake for method VirtualMachineRunCommandsClient.NewListByVirtualMachinePager + // HTTP status codes to indicate success: http.StatusOK + NewListByVirtualMachinePager func(resourceGroupName string, vmName string, options *armcompute.VirtualMachineRunCommandsClientListByVirtualMachineOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineRunCommandsClientListByVirtualMachineResponse]) + + // BeginUpdate is the fake for method VirtualMachineRunCommandsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, runCommand armcompute.VirtualMachineRunCommandUpdate, options *armcompute.VirtualMachineRunCommandsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineRunCommandsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineRunCommandsServerTransport creates a new instance of VirtualMachineRunCommandsServerTransport with the provided implementation. +// The returned VirtualMachineRunCommandsServerTransport instance is connected to an instance of armcompute.VirtualMachineRunCommandsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineRunCommandsServerTransport(srv *VirtualMachineRunCommandsServer) *VirtualMachineRunCommandsServerTransport { + return &VirtualMachineRunCommandsServerTransport{srv: srv} +} + +// VirtualMachineRunCommandsServerTransport connects instances of armcompute.VirtualMachineRunCommandsClient to instances of VirtualMachineRunCommandsServer. +// Don't use this type directly, use NewVirtualMachineRunCommandsServerTransport instead. +type VirtualMachineRunCommandsServerTransport struct { + srv *VirtualMachineRunCommandsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachineRunCommandsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineRunCommandsClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.VirtualMachineRunCommandsClientListResponse] + newListByVirtualMachinePager *azfake.PagerResponder[armcompute.VirtualMachineRunCommandsClientListByVirtualMachineResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineRunCommandsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineRunCommandsServerTransport. +func (v *VirtualMachineRunCommandsServerTransport) 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 "VirtualMachineRunCommandsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachineRunCommandsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineRunCommandsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineRunCommandsClient.GetByVirtualMachine": + resp, err = v.dispatchGetByVirtualMachine(req) + case "VirtualMachineRunCommandsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualMachineRunCommandsClient.NewListByVirtualMachinePager": + resp, err = v.dispatchNewListByVirtualMachinePager(req) + case "VirtualMachineRunCommandsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineRunCommand](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?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 := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("method Get not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/runCommands/(?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 := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("commandId")], 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).RunCommandDocument, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchGetByVirtualMachine(req *http.Request) (*http.Response, error) { + if v.srv.GetByVirtualMachine == nil { + return nil, &nonRetriableError{errors.New("method GetByVirtualMachine not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineOptions + if expandParam != nil { + options = &armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.GetByVirtualMachine(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], 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).VirtualMachineRunCommand, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/runCommands" + 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) + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("location")], nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineRunCommandsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchNewListByVirtualMachinePager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByVirtualMachinePager == nil { + return nil, &nonRetriableError{errors.New("method NewListByVirtualMachinePager not implemented")} + } + if v.newListByVirtualMachinePager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands" + 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() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineRunCommandsClientListByVirtualMachineOptions + if expandParam != nil { + options = &armcompute.VirtualMachineRunCommandsClientListByVirtualMachineOptions{ + Expand: expandParam, + } + } + resp := v.srv.NewListByVirtualMachinePager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + v.newListByVirtualMachinePager = &resp + server.PagerResponderInjectNextLinks(v.newListByVirtualMachinePager, req, func(page *armcompute.VirtualMachineRunCommandsClientListByVirtualMachineResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByVirtualMachinePager, 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(v.newListByVirtualMachinePager) { + v.newListByVirtualMachinePager = nil + } + return resp, nil +} + +func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineRunCommandUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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.PollerResponderMore(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go new file mode 100644 index 000000000000..13321082acba --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go @@ -0,0 +1,1113 @@ +//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/compute/armcompute/v5" + "net/http" + "reflect" + "regexp" + "strconv" +) + +// VirtualMachinesServer is a fake server for instances of the armcompute.VirtualMachinesClient type. +type VirtualMachinesServer struct { + // BeginAssessPatches is the fake for method VirtualMachinesClient.BeginAssessPatches + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginAssessPatches func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginAssessPatchesOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientAssessPatchesResponse], errResp azfake.ErrorResponder) + + // BeginCapture is the fake for method VirtualMachinesClient.BeginCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCapture func(ctx context.Context, resourceGroupName string, vmName string, parameters armcompute.VirtualMachineCaptureParameters, options *armcompute.VirtualMachinesClientBeginCaptureOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientCaptureResponse], errResp azfake.ErrorResponder) + + // BeginConvertToManagedDisks is the fake for method VirtualMachinesClient.BeginConvertToManagedDisks + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginConvertToManagedDisks func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginConvertToManagedDisksOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientConvertToManagedDisksResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method VirtualMachinesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmName string, parameters armcompute.VirtualMachine, options *armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDeallocate is the fake for method VirtualMachinesClient.BeginDeallocate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDeallocate func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginDeallocateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientDeallocateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachinesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Generalize is the fake for method VirtualMachinesClient.Generalize + // HTTP status codes to indicate success: http.StatusOK + Generalize func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientGeneralizeOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientGeneralizeResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachinesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientGetResponse], errResp azfake.ErrorResponder) + + // BeginInstallPatches is the fake for method VirtualMachinesClient.BeginInstallPatches + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginInstallPatches func(ctx context.Context, resourceGroupName string, vmName string, installPatchesInput armcompute.VirtualMachineInstallPatchesParameters, options *armcompute.VirtualMachinesClientBeginInstallPatchesOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientInstallPatchesResponse], errResp azfake.ErrorResponder) + + // InstanceView is the fake for method VirtualMachinesClient.InstanceView + // HTTP status codes to indicate success: http.StatusOK + InstanceView func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientInstanceViewOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientInstanceViewResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualMachinesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armcompute.VirtualMachinesClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachinesClientListResponse]) + + // NewListAllPager is the fake for method VirtualMachinesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armcompute.VirtualMachinesClientListAllOptions) (resp azfake.PagerResponder[armcompute.VirtualMachinesClientListAllResponse]) + + // NewListAvailableSizesPager is the fake for method VirtualMachinesClient.NewListAvailableSizesPager + // HTTP status codes to indicate success: http.StatusOK + NewListAvailableSizesPager func(resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientListAvailableSizesOptions) (resp azfake.PagerResponder[armcompute.VirtualMachinesClientListAvailableSizesResponse]) + + // NewListByLocationPager is the fake for method VirtualMachinesClient.NewListByLocationPager + // HTTP status codes to indicate success: http.StatusOK + NewListByLocationPager func(location string, options *armcompute.VirtualMachinesClientListByLocationOptions) (resp azfake.PagerResponder[armcompute.VirtualMachinesClientListByLocationResponse]) + + // BeginPerformMaintenance is the fake for method VirtualMachinesClient.BeginPerformMaintenance + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPerformMaintenance func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginPerformMaintenanceOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientPerformMaintenanceResponse], errResp azfake.ErrorResponder) + + // BeginPowerOff is the fake for method VirtualMachinesClient.BeginPowerOff + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPowerOff func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginPowerOffOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientPowerOffResponse], errResp azfake.ErrorResponder) + + // BeginReapply is the fake for method VirtualMachinesClient.BeginReapply + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReapply func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginReapplyOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientReapplyResponse], errResp azfake.ErrorResponder) + + // BeginRedeploy is the fake for method VirtualMachinesClient.BeginRedeploy + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRedeploy func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginRedeployOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientRedeployResponse], errResp azfake.ErrorResponder) + + // BeginReimage is the fake for method VirtualMachinesClient.BeginReimage + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimage func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginReimageOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientReimageResponse], errResp azfake.ErrorResponder) + + // BeginRestart is the fake for method VirtualMachinesClient.BeginRestart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRestart func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginRestartOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientRestartResponse], errResp azfake.ErrorResponder) + + // RetrieveBootDiagnosticsData is the fake for method VirtualMachinesClient.RetrieveBootDiagnosticsData + // HTTP status codes to indicate success: http.StatusOK + RetrieveBootDiagnosticsData func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataResponse], errResp azfake.ErrorResponder) + + // BeginRunCommand is the fake for method VirtualMachinesClient.BeginRunCommand + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRunCommand func(ctx context.Context, resourceGroupName string, vmName string, parameters armcompute.RunCommandInput, options *armcompute.VirtualMachinesClientBeginRunCommandOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientRunCommandResponse], errResp azfake.ErrorResponder) + + // SimulateEviction is the fake for method VirtualMachinesClient.SimulateEviction + // HTTP status codes to indicate success: http.StatusNoContent + SimulateEviction func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientSimulateEvictionOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientSimulateEvictionResponse], errResp azfake.ErrorResponder) + + // BeginStart is the fake for method VirtualMachinesClient.BeginStart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStart func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientBeginStartOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientStartResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method VirtualMachinesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, vmName string, parameters armcompute.VirtualMachineUpdate, options *armcompute.VirtualMachinesClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachinesClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachinesServerTransport creates a new instance of VirtualMachinesServerTransport with the provided implementation. +// The returned VirtualMachinesServerTransport instance is connected to an instance of armcompute.VirtualMachinesClient by way of the +// undefined.Transporter field. +func NewVirtualMachinesServerTransport(srv *VirtualMachinesServer) *VirtualMachinesServerTransport { + return &VirtualMachinesServerTransport{srv: srv} +} + +// VirtualMachinesServerTransport connects instances of armcompute.VirtualMachinesClient to instances of VirtualMachinesServer. +// Don't use this type directly, use NewVirtualMachinesServerTransport instead. +type VirtualMachinesServerTransport struct { + srv *VirtualMachinesServer + beginAssessPatches *azfake.PollerResponder[armcompute.VirtualMachinesClientAssessPatchesResponse] + beginCapture *azfake.PollerResponder[armcompute.VirtualMachinesClientCaptureResponse] + beginConvertToManagedDisks *azfake.PollerResponder[armcompute.VirtualMachinesClientConvertToManagedDisksResponse] + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachinesClientCreateOrUpdateResponse] + beginDeallocate *azfake.PollerResponder[armcompute.VirtualMachinesClientDeallocateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachinesClientDeleteResponse] + beginInstallPatches *azfake.PollerResponder[armcompute.VirtualMachinesClientInstallPatchesResponse] + newListPager *azfake.PagerResponder[armcompute.VirtualMachinesClientListResponse] + newListAllPager *azfake.PagerResponder[armcompute.VirtualMachinesClientListAllResponse] + newListAvailableSizesPager *azfake.PagerResponder[armcompute.VirtualMachinesClientListAvailableSizesResponse] + newListByLocationPager *azfake.PagerResponder[armcompute.VirtualMachinesClientListByLocationResponse] + beginPerformMaintenance *azfake.PollerResponder[armcompute.VirtualMachinesClientPerformMaintenanceResponse] + beginPowerOff *azfake.PollerResponder[armcompute.VirtualMachinesClientPowerOffResponse] + beginReapply *azfake.PollerResponder[armcompute.VirtualMachinesClientReapplyResponse] + beginRedeploy *azfake.PollerResponder[armcompute.VirtualMachinesClientRedeployResponse] + beginReimage *azfake.PollerResponder[armcompute.VirtualMachinesClientReimageResponse] + beginRestart *azfake.PollerResponder[armcompute.VirtualMachinesClientRestartResponse] + beginRunCommand *azfake.PollerResponder[armcompute.VirtualMachinesClientRunCommandResponse] + beginStart *azfake.PollerResponder[armcompute.VirtualMachinesClientStartResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachinesClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachinesServerTransport. +func (v *VirtualMachinesServerTransport) 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 "VirtualMachinesClient.BeginAssessPatches": + resp, err = v.dispatchBeginAssessPatches(req) + case "VirtualMachinesClient.BeginCapture": + resp, err = v.dispatchBeginCapture(req) + case "VirtualMachinesClient.BeginConvertToManagedDisks": + resp, err = v.dispatchBeginConvertToManagedDisks(req) + case "VirtualMachinesClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachinesClient.BeginDeallocate": + resp, err = v.dispatchBeginDeallocate(req) + case "VirtualMachinesClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachinesClient.Generalize": + resp, err = v.dispatchGeneralize(req) + case "VirtualMachinesClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachinesClient.BeginInstallPatches": + resp, err = v.dispatchBeginInstallPatches(req) + case "VirtualMachinesClient.InstanceView": + resp, err = v.dispatchInstanceView(req) + case "VirtualMachinesClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualMachinesClient.NewListAllPager": + resp, err = v.dispatchNewListAllPager(req) + case "VirtualMachinesClient.NewListAvailableSizesPager": + resp, err = v.dispatchNewListAvailableSizesPager(req) + case "VirtualMachinesClient.NewListByLocationPager": + resp, err = v.dispatchNewListByLocationPager(req) + case "VirtualMachinesClient.BeginPerformMaintenance": + resp, err = v.dispatchBeginPerformMaintenance(req) + case "VirtualMachinesClient.BeginPowerOff": + resp, err = v.dispatchBeginPowerOff(req) + case "VirtualMachinesClient.BeginReapply": + resp, err = v.dispatchBeginReapply(req) + case "VirtualMachinesClient.BeginRedeploy": + resp, err = v.dispatchBeginRedeploy(req) + case "VirtualMachinesClient.BeginReimage": + resp, err = v.dispatchBeginReimage(req) + case "VirtualMachinesClient.BeginRestart": + resp, err = v.dispatchBeginRestart(req) + case "VirtualMachinesClient.RetrieveBootDiagnosticsData": + resp, err = v.dispatchRetrieveBootDiagnosticsData(req) + case "VirtualMachinesClient.BeginRunCommand": + resp, err = v.dispatchBeginRunCommand(req) + case "VirtualMachinesClient.SimulateEviction": + resp, err = v.dispatchSimulateEviction(req) + case "VirtualMachinesClient.BeginStart": + resp, err = v.dispatchBeginStart(req) + case "VirtualMachinesClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginAssessPatches(req *http.Request) (*http.Response, error) { + if v.srv.BeginAssessPatches == nil { + return nil, &nonRetriableError{errors.New("method BeginAssessPatches not implemented")} + } + if v.beginAssessPatches == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/assessPatches" + 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 := v.srv.BeginAssessPatches(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginAssessPatches = &respr + } + + resp, err := server.PollerResponderNext(v.beginAssessPatches, 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(v.beginAssessPatches) { + v.beginAssessPatches = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginCapture == nil { + return nil, &nonRetriableError{errors.New("method BeginCapture not implemented")} + } + if v.beginCapture == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/capture" + 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[armcompute.VirtualMachineCaptureParameters](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCapture(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginCapture, 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(v.beginCapture) { + v.beginCapture = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginConvertToManagedDisks(req *http.Request) (*http.Response, error) { + if v.srv.BeginConvertToManagedDisks == nil { + return nil, &nonRetriableError{errors.New("method BeginConvertToManagedDisks not implemented")} + } + if v.beginConvertToManagedDisks == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/convertToManagedDisks" + 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 := v.srv.BeginConvertToManagedDisks(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginConvertToManagedDisks = &respr + } + + resp, err := server.PollerResponderNext(v.beginConvertToManagedDisks, 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(v.beginConvertToManagedDisks) { + v.beginConvertToManagedDisks = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?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[armcompute.VirtualMachine](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginDeallocate(req *http.Request) (*http.Response, error) { + if v.srv.BeginDeallocate == nil { + return nil, &nonRetriableError{errors.New("method BeginDeallocate not implemented")} + } + if v.beginDeallocate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/deallocate" + 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() + hibernateParam, err := parseOptional(qp.Get("hibernate"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachinesClientBeginDeallocateOptions + if hibernateParam != nil { + options = &armcompute.VirtualMachinesClientBeginDeallocateOptions{ + Hibernate: hibernateParam, + } + } + respr, errRespr := v.srv.BeginDeallocate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDeallocate = &respr + } + + resp, err := server.PollerResponderNext(v.beginDeallocate, 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(v.beginDeallocate) { + v.beginDeallocate = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?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) + } + qp := req.URL.Query() + forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachinesClientBeginDeleteOptions + if forceDeletionParam != nil { + options = &armcompute.VirtualMachinesClientBeginDeleteOptions{ + ForceDeletion: forceDeletionParam, + } + } + respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchGeneralize(req *http.Request) (*http.Response, error) { + if v.srv.Generalize == nil { + return nil, &nonRetriableError{errors.New("method Generalize not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/generalize" + 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 := v.srv.Generalize(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], 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 (v *VirtualMachinesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachines/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.VirtualMachinesClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachinesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], 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).VirtualMachine, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginInstallPatches(req *http.Request) (*http.Response, error) { + if v.srv.BeginInstallPatches == nil { + return nil, &nonRetriableError{errors.New("method BeginInstallPatches not implemented")} + } + if v.beginInstallPatches == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/installPatches" + 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[armcompute.VirtualMachineInstallPatchesParameters](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginInstallPatches(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginInstallPatches = &respr + } + + resp, err := server.PollerResponderNext(v.beginInstallPatches, 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(v.beginInstallPatches) { + v.beginInstallPatches = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchInstanceView(req *http.Request) (*http.Response, error) { + if v.srv.InstanceView == nil { + return nil, &nonRetriableError{errors.New("method InstanceView not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/instanceView" + 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 := v.srv.InstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], 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).VirtualMachineInstanceView, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines" + 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(armcompute.ExpandTypeForListVMs(qp.Get("$expand"))) + var options *armcompute.VirtualMachinesClientListOptions + if filterParam != nil || expandParam != nil { + options = &armcompute.VirtualMachinesClientListOptions{ + Filter: filterParam, + Expand: expandParam, + } + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], options) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachinesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + } + if v.newListAllPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines" + 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() + statusOnlyParam := getOptional(qp.Get("statusOnly")) + filterParam := getOptional(qp.Get("$filter")) + expandParam := getOptional(armcompute.ExpandTypesForListVMs(qp.Get("$expand"))) + var options *armcompute.VirtualMachinesClientListAllOptions + if statusOnlyParam != nil || filterParam != nil || expandParam != nil { + options = &armcompute.VirtualMachinesClientListAllOptions{ + StatusOnly: statusOnlyParam, + Filter: filterParam, + Expand: expandParam, + } + } + resp := v.srv.NewListAllPager(options) + v.newListAllPager = &resp + server.PagerResponderInjectNextLinks(v.newListAllPager, req, func(page *armcompute.VirtualMachinesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListAllPager, 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(v.newListAllPager) { + v.newListAllPager = nil + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchNewListAvailableSizesPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListAvailableSizesPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAvailableSizesPager not implemented")} + } + if v.newListAvailableSizesPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/vmSizes" + 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) + } + resp := v.srv.NewListAvailableSizesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + v.newListAvailableSizesPager = &resp + } + resp, err := server.PagerResponderNext(v.newListAvailableSizesPager, 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(v.newListAvailableSizesPager) { + v.newListAvailableSizesPager = nil + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchNewListByLocationPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByLocationPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByLocationPager not implemented")} + } + if v.newListByLocationPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/virtualMachines" + 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) + } + resp := v.srv.NewListByLocationPager(matches[regex.SubexpIndex("location")], nil) + v.newListByLocationPager = &resp + server.PagerResponderInjectNextLinks(v.newListByLocationPager, req, func(page *armcompute.VirtualMachinesClientListByLocationResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByLocationPager, 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(v.newListByLocationPager) { + v.newListByLocationPager = nil + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginPerformMaintenance(req *http.Request) (*http.Response, error) { + if v.srv.BeginPerformMaintenance == nil { + return nil, &nonRetriableError{errors.New("method BeginPerformMaintenance not implemented")} + } + if v.beginPerformMaintenance == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/performMaintenance" + 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 := v.srv.BeginPerformMaintenance(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginPerformMaintenance = &respr + } + + resp, err := server.PollerResponderNext(v.beginPerformMaintenance, 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(v.beginPerformMaintenance) { + v.beginPerformMaintenance = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { + if v.srv.BeginPowerOff == nil { + return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + } + if v.beginPowerOff == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/powerOff" + 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() + skipShutdownParam, err := parseOptional(qp.Get("skipShutdown"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachinesClientBeginPowerOffOptions + if skipShutdownParam != nil { + options = &armcompute.VirtualMachinesClientBeginPowerOffOptions{ + SkipShutdown: skipShutdownParam, + } + } + respr, errRespr := v.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginPowerOff = &respr + } + + resp, err := server.PollerResponderNext(v.beginPowerOff, 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(v.beginPowerOff) { + v.beginPowerOff = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginReapply(req *http.Request) (*http.Response, error) { + if v.srv.BeginReapply == nil { + return nil, &nonRetriableError{errors.New("method BeginReapply not implemented")} + } + if v.beginReapply == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/reapply" + 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 := v.srv.BeginReapply(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReapply = &respr + } + + resp, err := server.PollerResponderNext(v.beginReapply, 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(v.beginReapply) { + v.beginReapply = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginRedeploy(req *http.Request) (*http.Response, error) { + if v.srv.BeginRedeploy == nil { + return nil, &nonRetriableError{errors.New("method BeginRedeploy not implemented")} + } + if v.beginRedeploy == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/redeploy" + 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 := v.srv.BeginRedeploy(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRedeploy = &respr + } + + resp, err := server.PollerResponderNext(v.beginRedeploy, 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(v.beginRedeploy) { + v.beginRedeploy = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { + if v.srv.BeginReimage == nil { + return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + } + if v.beginReimage == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/reimage" + 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[armcompute.VirtualMachineReimageParameters](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachinesClientBeginReimageOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachinesClientBeginReimageOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReimage = &respr + } + + resp, err := server.PollerResponderNext(v.beginReimage, 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(v.beginReimage) { + v.beginReimage = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { + if v.srv.BeginRestart == nil { + return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + } + if v.beginRestart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/restart" + 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 := v.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRestart = &respr + } + + resp, err := server.PollerResponderNext(v.beginRestart, 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(v.beginRestart) { + v.beginRestart = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchRetrieveBootDiagnosticsData(req *http.Request) (*http.Response, error) { + if v.srv.RetrieveBootDiagnosticsData == nil { + return nil, &nonRetriableError{errors.New("method RetrieveBootDiagnosticsData not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/retrieveBootDiagnosticsData" + 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() + sasURIExpirationTimeInMinutesParam, err := parseOptional(qp.Get("sasUriExpirationTimeInMinutes"), 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 *armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataOptions + if sasURIExpirationTimeInMinutesParam != nil { + options = &armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataOptions{ + SasURIExpirationTimeInMinutes: sasURIExpirationTimeInMinutesParam, + } + } + respr, errRespr := v.srv.RetrieveBootDiagnosticsData(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], 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).RetrieveBootDiagnosticsDataResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginRunCommand(req *http.Request) (*http.Response, error) { + if v.srv.BeginRunCommand == nil { + return nil, &nonRetriableError{errors.New("method BeginRunCommand not implemented")} + } + if v.beginRunCommand == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommand" + 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[armcompute.RunCommandInput](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRunCommand(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRunCommand = &respr + } + + resp, err := server.PollerResponderNext(v.beginRunCommand, 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(v.beginRunCommand) { + v.beginRunCommand = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchSimulateEviction(req *http.Request) (*http.Response, error) { + if v.srv.SimulateEviction == nil { + return nil, &nonRetriableError{errors.New("method SimulateEviction not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/simulateEviction" + 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 := v.srv.SimulateEviction(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], 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 (v *VirtualMachinesServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { + if v.srv.BeginStart == nil { + return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + } + if v.beginStart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/start" + 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 := v.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStart = &respr + } + + resp, err := server.PollerResponderNext(v.beginStart, 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(v.beginStart) { + v.beginStart = nil + } + + return resp, nil +} + +func (v *VirtualMachinesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?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[armcompute.VirtualMachineUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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.PollerResponderMore(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go new file mode 100644 index 000000000000..86f87a9858dd --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go @@ -0,0 +1,265 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineScaleSetExtensionsServer is a fake server for instances of the armcompute.VirtualMachineScaleSetExtensionsClient type. +type VirtualMachineScaleSetExtensionsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualMachineScaleSetExtensionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, extensionParameters armcompute.VirtualMachineScaleSetExtension, options *armcompute.VirtualMachineScaleSetExtensionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetExtensionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineScaleSetExtensionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, options *armcompute.VirtualMachineScaleSetExtensionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetExtensionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineScaleSetExtensionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, options *armcompute.VirtualMachineScaleSetExtensionsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetExtensionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualMachineScaleSetExtensionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetExtensionsClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetExtensionsClientListResponse]) + + // BeginUpdate is the fake for method VirtualMachineScaleSetExtensionsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, extensionParameters armcompute.VirtualMachineScaleSetExtensionUpdate, options *armcompute.VirtualMachineScaleSetExtensionsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetExtensionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineScaleSetExtensionsServerTransport creates a new instance of VirtualMachineScaleSetExtensionsServerTransport with the provided implementation. +// The returned VirtualMachineScaleSetExtensionsServerTransport instance is connected to an instance of armcompute.VirtualMachineScaleSetExtensionsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineScaleSetExtensionsServerTransport(srv *VirtualMachineScaleSetExtensionsServer) *VirtualMachineScaleSetExtensionsServerTransport { + return &VirtualMachineScaleSetExtensionsServerTransport{srv: srv} +} + +// VirtualMachineScaleSetExtensionsServerTransport connects instances of armcompute.VirtualMachineScaleSetExtensionsClient to instances of VirtualMachineScaleSetExtensionsServer. +// Don't use this type directly, use NewVirtualMachineScaleSetExtensionsServerTransport instead. +type VirtualMachineScaleSetExtensionsServerTransport struct { + srv *VirtualMachineScaleSetExtensionsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetExtensionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineScaleSetExtensionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetExtensionsClientListResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetExtensionsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineScaleSetExtensionsServerTransport. +func (v *VirtualMachineScaleSetExtensionsServerTransport) 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 "VirtualMachineScaleSetExtensionsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachineScaleSetExtensionsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineScaleSetExtensionsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineScaleSetExtensionsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualMachineScaleSetExtensionsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetExtension](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?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 := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineScaleSetExtensionsClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetExtensionsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], 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).VirtualMachineScaleSetExtension, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions" + 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) + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetExtensionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetExtensionUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go new file mode 100644 index 000000000000..5e602b509caa --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go @@ -0,0 +1,211 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineScaleSetRollingUpgradesServer is a fake server for instances of the armcompute.VirtualMachineScaleSetRollingUpgradesClient type. +type VirtualMachineScaleSetRollingUpgradesServer struct { + // BeginCancel is the fake for method VirtualMachineScaleSetRollingUpgradesClient.BeginCancel + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCancel func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetRollingUpgradesClientBeginCancelOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetRollingUpgradesClientCancelResponse], errResp azfake.ErrorResponder) + + // GetLatest is the fake for method VirtualMachineScaleSetRollingUpgradesClient.GetLatest + // HTTP status codes to indicate success: http.StatusOK + GetLatest func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetRollingUpgradesClientGetLatestOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetRollingUpgradesClientGetLatestResponse], errResp azfake.ErrorResponder) + + // BeginStartExtensionUpgrade is the fake for method VirtualMachineScaleSetRollingUpgradesClient.BeginStartExtensionUpgrade + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStartExtensionUpgrade func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetRollingUpgradesClientBeginStartExtensionUpgradeOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetRollingUpgradesClientStartExtensionUpgradeResponse], errResp azfake.ErrorResponder) + + // BeginStartOSUpgrade is the fake for method VirtualMachineScaleSetRollingUpgradesClient.BeginStartOSUpgrade + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStartOSUpgrade func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetRollingUpgradesClientBeginStartOSUpgradeOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetRollingUpgradesClientStartOSUpgradeResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineScaleSetRollingUpgradesServerTransport creates a new instance of VirtualMachineScaleSetRollingUpgradesServerTransport with the provided implementation. +// The returned VirtualMachineScaleSetRollingUpgradesServerTransport instance is connected to an instance of armcompute.VirtualMachineScaleSetRollingUpgradesClient by way of the +// undefined.Transporter field. +func NewVirtualMachineScaleSetRollingUpgradesServerTransport(srv *VirtualMachineScaleSetRollingUpgradesServer) *VirtualMachineScaleSetRollingUpgradesServerTransport { + return &VirtualMachineScaleSetRollingUpgradesServerTransport{srv: srv} +} + +// VirtualMachineScaleSetRollingUpgradesServerTransport connects instances of armcompute.VirtualMachineScaleSetRollingUpgradesClient to instances of VirtualMachineScaleSetRollingUpgradesServer. +// Don't use this type directly, use NewVirtualMachineScaleSetRollingUpgradesServerTransport instead. +type VirtualMachineScaleSetRollingUpgradesServerTransport struct { + srv *VirtualMachineScaleSetRollingUpgradesServer + beginCancel *azfake.PollerResponder[armcompute.VirtualMachineScaleSetRollingUpgradesClientCancelResponse] + beginStartExtensionUpgrade *azfake.PollerResponder[armcompute.VirtualMachineScaleSetRollingUpgradesClientStartExtensionUpgradeResponse] + beginStartOSUpgrade *azfake.PollerResponder[armcompute.VirtualMachineScaleSetRollingUpgradesClientStartOSUpgradeResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineScaleSetRollingUpgradesServerTransport. +func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) 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 "VirtualMachineScaleSetRollingUpgradesClient.BeginCancel": + resp, err = v.dispatchBeginCancel(req) + case "VirtualMachineScaleSetRollingUpgradesClient.GetLatest": + resp, err = v.dispatchGetLatest(req) + case "VirtualMachineScaleSetRollingUpgradesClient.BeginStartExtensionUpgrade": + resp, err = v.dispatchBeginStartExtensionUpgrade(req) + case "VirtualMachineScaleSetRollingUpgradesClient.BeginStartOSUpgrade": + resp, err = v.dispatchBeginStartOSUpgrade(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginCancel(req *http.Request) (*http.Response, error) { + if v.srv.BeginCancel == nil { + return nil, &nonRetriableError{errors.New("method BeginCancel not implemented")} + } + if v.beginCancel == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/rollingUpgrades/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 := v.srv.BeginCancel(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCancel = &respr + } + + resp, err := server.PollerResponderNext(v.beginCancel, 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(v.beginCancel) { + v.beginCancel = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchGetLatest(req *http.Request) (*http.Response, error) { + if v.srv.GetLatest == nil { + return nil, &nonRetriableError{errors.New("method GetLatest not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/rollingUpgrades/latest" + 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 := v.srv.GetLatest(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], 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).RollingUpgradeStatusInfo, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginStartExtensionUpgrade(req *http.Request) (*http.Response, error) { + if v.srv.BeginStartExtensionUpgrade == nil { + return nil, &nonRetriableError{errors.New("method BeginStartExtensionUpgrade not implemented")} + } + if v.beginStartExtensionUpgrade == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensionRollingUpgrade" + 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 := v.srv.BeginStartExtensionUpgrade(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStartExtensionUpgrade = &respr + } + + resp, err := server.PollerResponderNext(v.beginStartExtensionUpgrade, 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(v.beginStartExtensionUpgrade) { + v.beginStartExtensionUpgrade = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginStartOSUpgrade(req *http.Request) (*http.Response, error) { + if v.srv.BeginStartOSUpgrade == nil { + return nil, &nonRetriableError{errors.New("method BeginStartOSUpgrade not implemented")} + } + if v.beginStartOSUpgrade == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/osRollingUpgrade" + 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 := v.srv.BeginStartOSUpgrade(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStartOSUpgrade = &respr + } + + resp, err := server.PollerResponderNext(v.beginStartOSUpgrade, 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(v.beginStartOSUpgrade) { + v.beginStartOSUpgrade = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go new file mode 100644 index 000000000000..50d464251c3f --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go @@ -0,0 +1,1138 @@ +//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/compute/armcompute/v5" + "net/http" + "reflect" + "regexp" + "strconv" +) + +// VirtualMachineScaleSetsServer is a fake server for instances of the armcompute.VirtualMachineScaleSetsClient type. +type VirtualMachineScaleSetsServer struct { + // ConvertToSinglePlacementGroup is the fake for method VirtualMachineScaleSetsClient.ConvertToSinglePlacementGroup + // HTTP status codes to indicate success: http.StatusOK + ConvertToSinglePlacementGroup func(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters armcompute.VMScaleSetConvertToSinglePlacementGroupInput, options *armcompute.VirtualMachineScaleSetsClientConvertToSinglePlacementGroupOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method VirtualMachineScaleSetsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters armcompute.VirtualMachineScaleSet, options *armcompute.VirtualMachineScaleSetsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDeallocate is the fake for method VirtualMachineScaleSetsClient.BeginDeallocate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDeallocate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginDeallocateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientDeallocateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineScaleSetsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteInstances is the fake for method VirtualMachineScaleSetsClient.BeginDeleteInstances + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDeleteInstances func(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmInstanceIDs armcompute.VirtualMachineScaleSetVMInstanceRequiredIDs, options *armcompute.VirtualMachineScaleSetsClientBeginDeleteInstancesOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientDeleteInstancesResponse], errResp azfake.ErrorResponder) + + // ForceRecoveryServiceFabricPlatformUpdateDomainWalk is the fake for method VirtualMachineScaleSetsClient.ForceRecoveryServiceFabricPlatformUpdateDomainWalk + // HTTP status codes to indicate success: http.StatusOK + ForceRecoveryServiceFabricPlatformUpdateDomainWalk func(ctx context.Context, resourceGroupName string, vmScaleSetName string, platformUpdateDomain int32, options *armcompute.VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineScaleSetsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetsClientGetResponse], errResp azfake.ErrorResponder) + + // GetInstanceView is the fake for method VirtualMachineScaleSetsClient.GetInstanceView + // HTTP status codes to indicate success: http.StatusOK + GetInstanceView func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientGetInstanceViewOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetsClientGetInstanceViewResponse], errResp azfake.ErrorResponder) + + // NewGetOSUpgradeHistoryPager is the fake for method VirtualMachineScaleSetsClient.NewGetOSUpgradeHistoryPager + // HTTP status codes to indicate success: http.StatusOK + NewGetOSUpgradeHistoryPager func(resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientGetOSUpgradeHistoryOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientGetOSUpgradeHistoryResponse]) + + // NewListPager is the fake for method VirtualMachineScaleSetsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armcompute.VirtualMachineScaleSetsClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListResponse]) + + // NewListAllPager is the fake for method VirtualMachineScaleSetsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armcompute.VirtualMachineScaleSetsClientListAllOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListAllResponse]) + + // NewListByLocationPager is the fake for method VirtualMachineScaleSetsClient.NewListByLocationPager + // HTTP status codes to indicate success: http.StatusOK + NewListByLocationPager func(location string, options *armcompute.VirtualMachineScaleSetsClientListByLocationOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListByLocationResponse]) + + // NewListSKUsPager is the fake for method VirtualMachineScaleSetsClient.NewListSKUsPager + // HTTP status codes to indicate success: http.StatusOK + NewListSKUsPager func(resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientListSKUsOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListSKUsResponse]) + + // BeginPerformMaintenance is the fake for method VirtualMachineScaleSetsClient.BeginPerformMaintenance + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPerformMaintenance func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginPerformMaintenanceOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientPerformMaintenanceResponse], errResp azfake.ErrorResponder) + + // BeginPowerOff is the fake for method VirtualMachineScaleSetsClient.BeginPowerOff + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPowerOff func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginPowerOffOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientPowerOffResponse], errResp azfake.ErrorResponder) + + // BeginReapply is the fake for method VirtualMachineScaleSetsClient.BeginReapply + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReapply func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginReapplyOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientReapplyResponse], errResp azfake.ErrorResponder) + + // BeginRedeploy is the fake for method VirtualMachineScaleSetsClient.BeginRedeploy + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRedeploy func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginRedeployOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientRedeployResponse], errResp azfake.ErrorResponder) + + // BeginReimage is the fake for method VirtualMachineScaleSetsClient.BeginReimage + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimage func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginReimageOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientReimageResponse], errResp azfake.ErrorResponder) + + // BeginReimageAll is the fake for method VirtualMachineScaleSetsClient.BeginReimageAll + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimageAll func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginReimageAllOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientReimageAllResponse], errResp azfake.ErrorResponder) + + // BeginRestart is the fake for method VirtualMachineScaleSetsClient.BeginRestart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRestart func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginRestartOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientRestartResponse], errResp azfake.ErrorResponder) + + // BeginSetOrchestrationServiceState is the fake for method VirtualMachineScaleSetsClient.BeginSetOrchestrationServiceState + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginSetOrchestrationServiceState func(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters armcompute.OrchestrationServiceStateInput, options *armcompute.VirtualMachineScaleSetsClientBeginSetOrchestrationServiceStateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientSetOrchestrationServiceStateResponse], errResp azfake.ErrorResponder) + + // BeginStart is the fake for method VirtualMachineScaleSetsClient.BeginStart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStart func(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *armcompute.VirtualMachineScaleSetsClientBeginStartOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientStartResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method VirtualMachineScaleSetsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters armcompute.VirtualMachineScaleSetUpdate, options *armcompute.VirtualMachineScaleSetsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientUpdateResponse], errResp azfake.ErrorResponder) + + // BeginUpdateInstances is the fake for method VirtualMachineScaleSetsClient.BeginUpdateInstances + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateInstances func(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmInstanceIDs armcompute.VirtualMachineScaleSetVMInstanceRequiredIDs, options *armcompute.VirtualMachineScaleSetsClientBeginUpdateInstancesOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientUpdateInstancesResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineScaleSetsServerTransport creates a new instance of VirtualMachineScaleSetsServerTransport with the provided implementation. +// The returned VirtualMachineScaleSetsServerTransport instance is connected to an instance of armcompute.VirtualMachineScaleSetsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineScaleSetsServerTransport(srv *VirtualMachineScaleSetsServer) *VirtualMachineScaleSetsServerTransport { + return &VirtualMachineScaleSetsServerTransport{srv: srv} +} + +// VirtualMachineScaleSetsServerTransport connects instances of armcompute.VirtualMachineScaleSetsClient to instances of VirtualMachineScaleSetsServer. +// Don't use this type directly, use NewVirtualMachineScaleSetsServerTransport instead. +type VirtualMachineScaleSetsServerTransport struct { + srv *VirtualMachineScaleSetsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientCreateOrUpdateResponse] + beginDeallocate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientDeallocateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientDeleteResponse] + beginDeleteInstances *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientDeleteInstancesResponse] + newGetOSUpgradeHistoryPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientGetOSUpgradeHistoryResponse] + newListPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListResponse] + newListAllPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListAllResponse] + newListByLocationPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListByLocationResponse] + newListSKUsPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetsClientListSKUsResponse] + beginPerformMaintenance *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientPerformMaintenanceResponse] + beginPowerOff *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientPowerOffResponse] + beginReapply *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientReapplyResponse] + beginRedeploy *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientRedeployResponse] + beginReimage *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientReimageResponse] + beginReimageAll *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientReimageAllResponse] + beginRestart *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientRestartResponse] + beginSetOrchestrationServiceState *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientSetOrchestrationServiceStateResponse] + beginStart *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientStartResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientUpdateResponse] + beginUpdateInstances *azfake.PollerResponder[armcompute.VirtualMachineScaleSetsClientUpdateInstancesResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineScaleSetsServerTransport. +func (v *VirtualMachineScaleSetsServerTransport) 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 "VirtualMachineScaleSetsClient.ConvertToSinglePlacementGroup": + resp, err = v.dispatchConvertToSinglePlacementGroup(req) + case "VirtualMachineScaleSetsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachineScaleSetsClient.BeginDeallocate": + resp, err = v.dispatchBeginDeallocate(req) + case "VirtualMachineScaleSetsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineScaleSetsClient.BeginDeleteInstances": + resp, err = v.dispatchBeginDeleteInstances(req) + case "VirtualMachineScaleSetsClient.ForceRecoveryServiceFabricPlatformUpdateDomainWalk": + resp, err = v.dispatchForceRecoveryServiceFabricPlatformUpdateDomainWalk(req) + case "VirtualMachineScaleSetsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineScaleSetsClient.GetInstanceView": + resp, err = v.dispatchGetInstanceView(req) + case "VirtualMachineScaleSetsClient.NewGetOSUpgradeHistoryPager": + resp, err = v.dispatchNewGetOSUpgradeHistoryPager(req) + case "VirtualMachineScaleSetsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualMachineScaleSetsClient.NewListAllPager": + resp, err = v.dispatchNewListAllPager(req) + case "VirtualMachineScaleSetsClient.NewListByLocationPager": + resp, err = v.dispatchNewListByLocationPager(req) + case "VirtualMachineScaleSetsClient.NewListSKUsPager": + resp, err = v.dispatchNewListSKUsPager(req) + case "VirtualMachineScaleSetsClient.BeginPerformMaintenance": + resp, err = v.dispatchBeginPerformMaintenance(req) + case "VirtualMachineScaleSetsClient.BeginPowerOff": + resp, err = v.dispatchBeginPowerOff(req) + case "VirtualMachineScaleSetsClient.BeginReapply": + resp, err = v.dispatchBeginReapply(req) + case "VirtualMachineScaleSetsClient.BeginRedeploy": + resp, err = v.dispatchBeginRedeploy(req) + case "VirtualMachineScaleSetsClient.BeginReimage": + resp, err = v.dispatchBeginReimage(req) + case "VirtualMachineScaleSetsClient.BeginReimageAll": + resp, err = v.dispatchBeginReimageAll(req) + case "VirtualMachineScaleSetsClient.BeginRestart": + resp, err = v.dispatchBeginRestart(req) + case "VirtualMachineScaleSetsClient.BeginSetOrchestrationServiceState": + resp, err = v.dispatchBeginSetOrchestrationServiceState(req) + case "VirtualMachineScaleSetsClient.BeginStart": + resp, err = v.dispatchBeginStart(req) + case "VirtualMachineScaleSetsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + case "VirtualMachineScaleSetsClient.BeginUpdateInstances": + resp, err = v.dispatchBeginUpdateInstances(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchConvertToSinglePlacementGroup(req *http.Request) (*http.Response, error) { + if v.srv.ConvertToSinglePlacementGroup == nil { + return nil, &nonRetriableError{errors.New("method ConvertToSinglePlacementGroup not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/convertToSinglePlacementGroup" + 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[armcompute.VMScaleSetConvertToSinglePlacementGroupInput](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ConvertToSinglePlacementGroup(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], 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.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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[armcompute.VirtualMachineScaleSet](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeallocate(req *http.Request) (*http.Response, error) { + if v.srv.BeginDeallocate == nil { + return nil, &nonRetriableError{errors.New("method BeginDeallocate not implemented")} + } + if v.beginDeallocate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/deallocate" + 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() + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + hibernateParam, err := parseOptional(qp.Get("hibernate"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginDeallocateOptions + if hibernateParam != nil || !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginDeallocateOptions{ + Hibernate: hibernateParam, + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginDeallocate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDeallocate = &respr + } + + resp, err := server.PollerResponderNext(v.beginDeallocate, 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(v.beginDeallocate) { + v.beginDeallocate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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) + } + qp := req.URL.Query() + forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginDeleteOptions + if forceDeletionParam != nil { + options = &armcompute.VirtualMachineScaleSetsClientBeginDeleteOptions{ + ForceDeletion: forceDeletionParam, + } + } + respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeleteInstances(req *http.Request) (*http.Response, error) { + if v.srv.BeginDeleteInstances == nil { + return nil, &nonRetriableError{errors.New("method BeginDeleteInstances not implemented")} + } + if v.beginDeleteInstances == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/delete" + 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() + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVMInstanceRequiredIDs](req) + if err != nil { + return nil, err + } + forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginDeleteInstancesOptions + if forceDeletionParam != nil { + options = &armcompute.VirtualMachineScaleSetsClientBeginDeleteInstancesOptions{ + ForceDeletion: forceDeletionParam, + } + } + respr, errRespr := v.srv.BeginDeleteInstances(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDeleteInstances = &respr + } + + resp, err := server.PollerResponderNext(v.beginDeleteInstances, 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(v.beginDeleteInstances) { + v.beginDeleteInstances = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchForceRecoveryServiceFabricPlatformUpdateDomainWalk(req *http.Request) (*http.Response, error) { + if v.srv.ForceRecoveryServiceFabricPlatformUpdateDomainWalk == nil { + return nil, &nonRetriableError{errors.New("method ForceRecoveryServiceFabricPlatformUpdateDomainWalk not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/forceRecoveryServiceFabricPlatformUpdateDomainWalk" + 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() + platformUpdateDomainParam, err := parseWithCast(qp.Get("platformUpdateDomain"), 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 + } + zoneParam := getOptional(qp.Get("zone")) + placementGroupIDParam := getOptional(qp.Get("placementGroupId")) + var options *armcompute.VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions + if zoneParam != nil || placementGroupIDParam != nil { + options = &armcompute.VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions{ + Zone: zoneParam, + PlacementGroupID: placementGroupIDParam, + } + } + respr, errRespr := v.srv.ForceRecoveryServiceFabricPlatformUpdateDomainWalk(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], int32(platformUpdateDomainParam), 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).RecoveryWalkResponse, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachineScaleSets/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.ExpandTypesForGetVMScaleSets(qp.Get("$expand"))) + var options *armcompute.VirtualMachineScaleSetsClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], 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).VirtualMachineScaleSet, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { + if v.srv.GetInstanceView == nil { + return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/instanceView" + 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 := v.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], 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).VirtualMachineScaleSetInstanceView, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchNewGetOSUpgradeHistoryPager(req *http.Request) (*http.Response, error) { + if v.srv.NewGetOSUpgradeHistoryPager == nil { + return nil, &nonRetriableError{errors.New("method NewGetOSUpgradeHistoryPager not implemented")} + } + if v.newGetOSUpgradeHistoryPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/osUpgradeHistory" + 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) + } + resp := v.srv.NewGetOSUpgradeHistoryPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + v.newGetOSUpgradeHistoryPager = &resp + server.PagerResponderInjectNextLinks(v.newGetOSUpgradeHistoryPager, req, func(page *armcompute.VirtualMachineScaleSetsClientGetOSUpgradeHistoryResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newGetOSUpgradeHistoryPager, 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(v.newGetOSUpgradeHistoryPager) { + v.newGetOSUpgradeHistoryPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets" + 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) + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + } + if v.newListAllPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets" + 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 := v.srv.NewListAllPager(nil) + v.newListAllPager = &resp + server.PagerResponderInjectNextLinks(v.newListAllPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListAllPager, 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(v.newListAllPager) { + v.newListAllPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListByLocationPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByLocationPager == nil { + return nil, &nonRetriableError{errors.New("method NewListByLocationPager not implemented")} + } + if v.newListByLocationPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/virtualMachineScaleSets" + 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) + } + resp := v.srv.NewListByLocationPager(matches[regex.SubexpIndex("location")], nil) + v.newListByLocationPager = &resp + server.PagerResponderInjectNextLinks(v.newListByLocationPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListByLocationResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByLocationPager, 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(v.newListByLocationPager) { + v.newListByLocationPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListSKUsPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListSKUsPager == nil { + return nil, &nonRetriableError{errors.New("method NewListSKUsPager not implemented")} + } + if v.newListSKUsPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/skus" + 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) + } + resp := v.srv.NewListSKUsPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + v.newListSKUsPager = &resp + server.PagerResponderInjectNextLinks(v.newListSKUsPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListSKUsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListSKUsPager, 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(v.newListSKUsPager) { + v.newListSKUsPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPerformMaintenance(req *http.Request) (*http.Response, error) { + if v.srv.BeginPerformMaintenance == nil { + return nil, &nonRetriableError{errors.New("method BeginPerformMaintenance not implemented")} + } + if v.beginPerformMaintenance == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/performMaintenance" + 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[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginPerformMaintenanceOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginPerformMaintenanceOptions{ + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginPerformMaintenance(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginPerformMaintenance = &respr + } + + resp, err := server.PollerResponderNext(v.beginPerformMaintenance, 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(v.beginPerformMaintenance) { + v.beginPerformMaintenance = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { + if v.srv.BeginPowerOff == nil { + return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + } + if v.beginPowerOff == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/poweroff" + 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() + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + skipShutdownParam, err := parseOptional(qp.Get("skipShutdown"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginPowerOffOptions + if skipShutdownParam != nil || !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginPowerOffOptions{ + SkipShutdown: skipShutdownParam, + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginPowerOff = &respr + } + + resp, err := server.PollerResponderNext(v.beginPowerOff, 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(v.beginPowerOff) { + v.beginPowerOff = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReapply(req *http.Request) (*http.Response, error) { + if v.srv.BeginReapply == nil { + return nil, &nonRetriableError{errors.New("method BeginReapply not implemented")} + } + if v.beginReapply == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/reapply" + 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 := v.srv.BeginReapply(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReapply = &respr + } + + resp, err := server.PollerResponderNext(v.beginReapply, 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(v.beginReapply) { + v.beginReapply = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRedeploy(req *http.Request) (*http.Response, error) { + if v.srv.BeginRedeploy == nil { + return nil, &nonRetriableError{errors.New("method BeginRedeploy not implemented")} + } + if v.beginRedeploy == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/redeploy" + 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[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginRedeployOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginRedeployOptions{ + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginRedeploy(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRedeploy = &respr + } + + resp, err := server.PollerResponderNext(v.beginRedeploy, 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(v.beginRedeploy) { + v.beginRedeploy = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { + if v.srv.BeginReimage == nil { + return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + } + if v.beginReimage == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/reimage" + 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[armcompute.VirtualMachineScaleSetReimageParameters](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginReimageOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginReimageOptions{ + VMScaleSetReimageInput: &body, + } + } + respr, errRespr := v.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReimage = &respr + } + + resp, err := server.PollerResponderNext(v.beginReimage, 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(v.beginReimage) { + v.beginReimage = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimageAll(req *http.Request) (*http.Response, error) { + if v.srv.BeginReimageAll == nil { + return nil, &nonRetriableError{errors.New("method BeginReimageAll not implemented")} + } + if v.beginReimageAll == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/reimageall" + 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[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginReimageAllOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginReimageAllOptions{ + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginReimageAll(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReimageAll = &respr + } + + resp, err := server.PollerResponderNext(v.beginReimageAll, 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(v.beginReimageAll) { + v.beginReimageAll = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { + if v.srv.BeginRestart == nil { + return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + } + if v.beginRestart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/restart" + 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[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginRestartOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginRestartOptions{ + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRestart = &respr + } + + resp, err := server.PollerResponderNext(v.beginRestart, 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(v.beginRestart) { + v.beginRestart = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginSetOrchestrationServiceState(req *http.Request) (*http.Response, error) { + if v.srv.BeginSetOrchestrationServiceState == nil { + return nil, &nonRetriableError{errors.New("method BeginSetOrchestrationServiceState not implemented")} + } + if v.beginSetOrchestrationServiceState == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/setOrchestrationServiceState" + 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[armcompute.OrchestrationServiceStateInput](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginSetOrchestrationServiceState(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginSetOrchestrationServiceState = &respr + } + + resp, err := server.PollerResponderNext(v.beginSetOrchestrationServiceState, 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(v.beginSetOrchestrationServiceState) { + v.beginSetOrchestrationServiceState = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { + if v.srv.BeginStart == nil { + return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + } + if v.beginStart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/start" + 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[armcompute.VirtualMachineScaleSetVMInstanceIDs](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetsClientBeginStartOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetsClientBeginStartOptions{ + VMInstanceIDs: &body, + } + } + respr, errRespr := v.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStart = &respr + } + + resp, err := server.PollerResponderNext(v.beginStart, 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(v.beginStart) { + v.beginStart = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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[armcompute.VirtualMachineScaleSetUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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.PollerResponderMore(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdateInstances(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdateInstances == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdateInstances not implemented")} + } + if v.beginUpdateInstances == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/manualupgrade" + 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[armcompute.VirtualMachineScaleSetVMInstanceRequiredIDs](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdateInstances(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdateInstances = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdateInstances, 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(v.beginUpdateInstances) { + v.beginUpdateInstances = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go new file mode 100644 index 000000000000..752a89648a64 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go @@ -0,0 +1,266 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineScaleSetVMExtensionsServer is a fake server for instances of the armcompute.VirtualMachineScaleSetVMExtensionsClient type. +type VirtualMachineScaleSetVMExtensionsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualMachineScaleSetVMExtensionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, extensionParameters armcompute.VirtualMachineScaleSetVMExtension, options *armcompute.VirtualMachineScaleSetVMExtensionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMExtensionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineScaleSetVMExtensionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, options *armcompute.VirtualMachineScaleSetVMExtensionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMExtensionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineScaleSetVMExtensionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, options *armcompute.VirtualMachineScaleSetVMExtensionsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMExtensionsClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method VirtualMachineScaleSetVMExtensionsClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMExtensionsClientListOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMExtensionsClientListResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method VirtualMachineScaleSetVMExtensionsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, extensionParameters armcompute.VirtualMachineScaleSetVMExtensionUpdate, options *armcompute.VirtualMachineScaleSetVMExtensionsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMExtensionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineScaleSetVMExtensionsServerTransport creates a new instance of VirtualMachineScaleSetVMExtensionsServerTransport with the provided implementation. +// The returned VirtualMachineScaleSetVMExtensionsServerTransport instance is connected to an instance of armcompute.VirtualMachineScaleSetVMExtensionsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineScaleSetVMExtensionsServerTransport(srv *VirtualMachineScaleSetVMExtensionsServer) *VirtualMachineScaleSetVMExtensionsServerTransport { + return &VirtualMachineScaleSetVMExtensionsServerTransport{srv: srv} +} + +// VirtualMachineScaleSetVMExtensionsServerTransport connects instances of armcompute.VirtualMachineScaleSetVMExtensionsClient to instances of VirtualMachineScaleSetVMExtensionsServer. +// Don't use this type directly, use NewVirtualMachineScaleSetVMExtensionsServerTransport instead. +type VirtualMachineScaleSetVMExtensionsServerTransport struct { + srv *VirtualMachineScaleSetVMExtensionsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMExtensionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMExtensionsClientDeleteResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMExtensionsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineScaleSetVMExtensionsServerTransport. +func (v *VirtualMachineScaleSetVMExtensionsServerTransport) 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 "VirtualMachineScaleSetVMExtensionsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachineScaleSetVMExtensionsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineScaleSetVMExtensionsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineScaleSetVMExtensionsClient.List": + resp, err = v.dispatchList(req) + case "VirtualMachineScaleSetVMExtensionsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVMExtension](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineScaleSetVMExtensionsClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetVMExtensionsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], 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).VirtualMachineScaleSetVMExtension, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if v.srv.List == nil { + return nil, &nonRetriableError{errors.New("method List not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions" + 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) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineScaleSetVMExtensionsClientListOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetVMExtensionsClientListOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], 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).VirtualMachineScaleSetVMExtensionsListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVMExtensionUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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.PollerResponderMore(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go new file mode 100644 index 000000000000..db3a03c01606 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go @@ -0,0 +1,273 @@ +//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/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineScaleSetVMRunCommandsServer is a fake server for instances of the armcompute.VirtualMachineScaleSetVMRunCommandsClient type. +type VirtualMachineScaleSetVMRunCommandsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualMachineScaleSetVMRunCommandsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, runCommand armcompute.VirtualMachineRunCommand, options *armcompute.VirtualMachineScaleSetVMRunCommandsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineScaleSetVMRunCommandsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, options *armcompute.VirtualMachineScaleSetVMRunCommandsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineScaleSetVMRunCommandsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, options *armcompute.VirtualMachineScaleSetVMRunCommandsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMRunCommandsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualMachineScaleSetVMRunCommandsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMRunCommandsClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientListResponse]) + + // BeginUpdate is the fake for method VirtualMachineScaleSetVMRunCommandsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, runCommand armcompute.VirtualMachineRunCommandUpdate, options *armcompute.VirtualMachineScaleSetVMRunCommandsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineScaleSetVMRunCommandsServerTransport creates a new instance of VirtualMachineScaleSetVMRunCommandsServerTransport with the provided implementation. +// The returned VirtualMachineScaleSetVMRunCommandsServerTransport instance is connected to an instance of armcompute.VirtualMachineScaleSetVMRunCommandsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineScaleSetVMRunCommandsServerTransport(srv *VirtualMachineScaleSetVMRunCommandsServer) *VirtualMachineScaleSetVMRunCommandsServerTransport { + return &VirtualMachineScaleSetVMRunCommandsServerTransport{srv: srv} +} + +// VirtualMachineScaleSetVMRunCommandsServerTransport connects instances of armcompute.VirtualMachineScaleSetVMRunCommandsClient to instances of VirtualMachineScaleSetVMRunCommandsServer. +// Don't use this type directly, use NewVirtualMachineScaleSetVMRunCommandsServerTransport instead. +type VirtualMachineScaleSetVMRunCommandsServerTransport struct { + srv *VirtualMachineScaleSetVMRunCommandsServer + beginCreateOrUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientListResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMRunCommandsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineScaleSetVMRunCommandsServerTransport. +func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) 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 "VirtualMachineScaleSetVMRunCommandsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualMachineScaleSetVMRunCommandsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineScaleSetVMRunCommandsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineScaleSetVMRunCommandsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualMachineScaleSetVMRunCommandsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + } + if v.beginCreateOrUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineRunCommand](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginCreateOrUpdate) { + v.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineScaleSetVMRunCommandsClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetVMRunCommandsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], 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).VirtualMachineRunCommand, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands" + 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) + } + qp := req.URL.Query() + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineScaleSetVMRunCommandsClientListOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetVMRunCommandsClientListOptions{ + Expand: expandParam, + } + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetVMRunCommandsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.Path) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineRunCommandUpdate](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdate, 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.PollerResponderMore(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go new file mode 100644 index 000000000000..9de5415b2ab8 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go @@ -0,0 +1,741 @@ +//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/compute/armcompute/v5" + "net/http" + "reflect" + "regexp" + "strconv" +) + +// VirtualMachineScaleSetVMsServer is a fake server for instances of the armcompute.VirtualMachineScaleSetVMsClient type. +type VirtualMachineScaleSetVMsServer struct { + // BeginDeallocate is the fake for method VirtualMachineScaleSetVMsClient.BeginDeallocate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDeallocate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginDeallocateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientDeallocateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualMachineScaleSetVMsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginDeleteOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualMachineScaleSetVMsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMsClientGetResponse], errResp azfake.ErrorResponder) + + // GetInstanceView is the fake for method VirtualMachineScaleSetVMsClient.GetInstanceView + // HTTP status codes to indicate success: http.StatusOK + GetInstanceView func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientGetInstanceViewOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMsClientGetInstanceViewResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualMachineScaleSetVMsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualMachineScaleSetName string, options *armcompute.VirtualMachineScaleSetVMsClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineScaleSetVMsClientListResponse]) + + // BeginPerformMaintenance is the fake for method VirtualMachineScaleSetVMsClient.BeginPerformMaintenance + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPerformMaintenance func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginPerformMaintenanceOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientPerformMaintenanceResponse], errResp azfake.ErrorResponder) + + // BeginPowerOff is the fake for method VirtualMachineScaleSetVMsClient.BeginPowerOff + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPowerOff func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginPowerOffOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientPowerOffResponse], errResp azfake.ErrorResponder) + + // BeginRedeploy is the fake for method VirtualMachineScaleSetVMsClient.BeginRedeploy + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRedeploy func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginRedeployOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientRedeployResponse], errResp azfake.ErrorResponder) + + // BeginReimage is the fake for method VirtualMachineScaleSetVMsClient.BeginReimage + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimage func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginReimageOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientReimageResponse], errResp azfake.ErrorResponder) + + // BeginReimageAll is the fake for method VirtualMachineScaleSetVMsClient.BeginReimageAll + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReimageAll func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginReimageAllOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientReimageAllResponse], errResp azfake.ErrorResponder) + + // BeginRestart is the fake for method VirtualMachineScaleSetVMsClient.BeginRestart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRestart func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginRestartOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientRestartResponse], errResp azfake.ErrorResponder) + + // RetrieveBootDiagnosticsData is the fake for method VirtualMachineScaleSetVMsClient.RetrieveBootDiagnosticsData + // HTTP status codes to indicate success: http.StatusOK + RetrieveBootDiagnosticsData func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataResponse], errResp azfake.ErrorResponder) + + // BeginRunCommand is the fake for method VirtualMachineScaleSetVMsClient.BeginRunCommand + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRunCommand func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, parameters armcompute.RunCommandInput, options *armcompute.VirtualMachineScaleSetVMsClientBeginRunCommandOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientRunCommandResponse], errResp azfake.ErrorResponder) + + // SimulateEviction is the fake for method VirtualMachineScaleSetVMsClient.SimulateEviction + // HTTP status codes to indicate success: http.StatusNoContent + SimulateEviction func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientSimulateEvictionOptions) (resp azfake.Responder[armcompute.VirtualMachineScaleSetVMsClientSimulateEvictionResponse], errResp azfake.ErrorResponder) + + // BeginStart is the fake for method VirtualMachineScaleSetVMsClient.BeginStart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStart func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcompute.VirtualMachineScaleSetVMsClientBeginStartOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientStartResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method VirtualMachineScaleSetVMsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, parameters armcompute.VirtualMachineScaleSetVM, options *armcompute.VirtualMachineScaleSetVMsClientBeginUpdateOptions) (resp azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualMachineScaleSetVMsServerTransport creates a new instance of VirtualMachineScaleSetVMsServerTransport with the provided implementation. +// The returned VirtualMachineScaleSetVMsServerTransport instance is connected to an instance of armcompute.VirtualMachineScaleSetVMsClient by way of the +// undefined.Transporter field. +func NewVirtualMachineScaleSetVMsServerTransport(srv *VirtualMachineScaleSetVMsServer) *VirtualMachineScaleSetVMsServerTransport { + return &VirtualMachineScaleSetVMsServerTransport{srv: srv} +} + +// VirtualMachineScaleSetVMsServerTransport connects instances of armcompute.VirtualMachineScaleSetVMsClient to instances of VirtualMachineScaleSetVMsServer. +// Don't use this type directly, use NewVirtualMachineScaleSetVMsServerTransport instead. +type VirtualMachineScaleSetVMsServerTransport struct { + srv *VirtualMachineScaleSetVMsServer + beginDeallocate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientDeallocateResponse] + beginDelete *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientDeleteResponse] + newListPager *azfake.PagerResponder[armcompute.VirtualMachineScaleSetVMsClientListResponse] + beginPerformMaintenance *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientPerformMaintenanceResponse] + beginPowerOff *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientPowerOffResponse] + beginRedeploy *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientRedeployResponse] + beginReimage *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientReimageResponse] + beginReimageAll *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientReimageAllResponse] + beginRestart *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientRestartResponse] + beginRunCommand *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientRunCommandResponse] + beginStart *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientStartResponse] + beginUpdate *azfake.PollerResponder[armcompute.VirtualMachineScaleSetVMsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineScaleSetVMsServerTransport. +func (v *VirtualMachineScaleSetVMsServerTransport) 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 "VirtualMachineScaleSetVMsClient.BeginDeallocate": + resp, err = v.dispatchBeginDeallocate(req) + case "VirtualMachineScaleSetVMsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualMachineScaleSetVMsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualMachineScaleSetVMsClient.GetInstanceView": + resp, err = v.dispatchGetInstanceView(req) + case "VirtualMachineScaleSetVMsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualMachineScaleSetVMsClient.BeginPerformMaintenance": + resp, err = v.dispatchBeginPerformMaintenance(req) + case "VirtualMachineScaleSetVMsClient.BeginPowerOff": + resp, err = v.dispatchBeginPowerOff(req) + case "VirtualMachineScaleSetVMsClient.BeginRedeploy": + resp, err = v.dispatchBeginRedeploy(req) + case "VirtualMachineScaleSetVMsClient.BeginReimage": + resp, err = v.dispatchBeginReimage(req) + case "VirtualMachineScaleSetVMsClient.BeginReimageAll": + resp, err = v.dispatchBeginReimageAll(req) + case "VirtualMachineScaleSetVMsClient.BeginRestart": + resp, err = v.dispatchBeginRestart(req) + case "VirtualMachineScaleSetVMsClient.RetrieveBootDiagnosticsData": + resp, err = v.dispatchRetrieveBootDiagnosticsData(req) + case "VirtualMachineScaleSetVMsClient.BeginRunCommand": + resp, err = v.dispatchBeginRunCommand(req) + case "VirtualMachineScaleSetVMsClient.SimulateEviction": + resp, err = v.dispatchSimulateEviction(req) + case "VirtualMachineScaleSetVMsClient.BeginStart": + resp, err = v.dispatchBeginStart(req) + case "VirtualMachineScaleSetVMsClient.BeginUpdate": + resp, err = v.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDeallocate(req *http.Request) (*http.Response, error) { + if v.srv.BeginDeallocate == nil { + return nil, &nonRetriableError{errors.New("method BeginDeallocate not implemented")} + } + if v.beginDeallocate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/deallocate" + 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 := v.srv.BeginDeallocate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDeallocate = &respr + } + + resp, err := server.PollerResponderNext(v.beginDeallocate, 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(v.beginDeallocate) { + v.beginDeallocate = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + } + if v.beginDelete == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?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) + } + qp := req.URL.Query() + forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetVMsClientBeginDeleteOptions + if forceDeletionParam != nil { + options = &armcompute.VirtualMachineScaleSetVMsClientBeginDeleteOptions{ + ForceDeletion: forceDeletionParam, + } + } + respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginDelete) { + v.beginDelete = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?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) + } + qp := req.URL.Query() + expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + var options *armcompute.VirtualMachineScaleSetVMsClientGetOptions + if expandParam != nil { + options = &armcompute.VirtualMachineScaleSetVMsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], 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).VirtualMachineScaleSetVM, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { + if v.srv.GetInstanceView == nil { + return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/instanceView" + 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 := v.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], 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).VirtualMachineScaleSetVMInstanceView, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines" + 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() + filterParam := getOptional(qp.Get("$filter")) + selectParam := getOptional(qp.Get("$select")) + expandParam := getOptional(qp.Get("$expand")) + var options *armcompute.VirtualMachineScaleSetVMsClientListOptions + if filterParam != nil || selectParam != nil || expandParam != nil { + options = &armcompute.VirtualMachineScaleSetVMsClientListOptions{ + Filter: filterParam, + Select: selectParam, + Expand: expandParam, + } + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("virtualMachineScaleSetName")], options) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetVMsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPerformMaintenance(req *http.Request) (*http.Response, error) { + if v.srv.BeginPerformMaintenance == nil { + return nil, &nonRetriableError{errors.New("method BeginPerformMaintenance not implemented")} + } + if v.beginPerformMaintenance == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/performMaintenance" + 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 := v.srv.BeginPerformMaintenance(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginPerformMaintenance = &respr + } + + resp, err := server.PollerResponderNext(v.beginPerformMaintenance, 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(v.beginPerformMaintenance) { + v.beginPerformMaintenance = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { + if v.srv.BeginPowerOff == nil { + return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + } + if v.beginPowerOff == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/poweroff" + 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) + } + qp := req.URL.Query() + skipShutdownParam, err := parseOptional(qp.Get("skipShutdown"), strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetVMsClientBeginPowerOffOptions + if skipShutdownParam != nil { + options = &armcompute.VirtualMachineScaleSetVMsClientBeginPowerOffOptions{ + SkipShutdown: skipShutdownParam, + } + } + respr, errRespr := v.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginPowerOff = &respr + } + + resp, err := server.PollerResponderNext(v.beginPowerOff, 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(v.beginPowerOff) { + v.beginPowerOff = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRedeploy(req *http.Request) (*http.Response, error) { + if v.srv.BeginRedeploy == nil { + return nil, &nonRetriableError{errors.New("method BeginRedeploy not implemented")} + } + if v.beginRedeploy == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/redeploy" + 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 := v.srv.BeginRedeploy(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRedeploy = &respr + } + + resp, err := server.PollerResponderNext(v.beginRedeploy, 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(v.beginRedeploy) { + v.beginRedeploy = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { + if v.srv.BeginReimage == nil { + return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + } + if v.beginReimage == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/reimage" + 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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVMReimageParameters](req) + if err != nil { + return nil, err + } + var options *armcompute.VirtualMachineScaleSetVMsClientBeginReimageOptions + if !reflect.ValueOf(body).IsZero() { + options = &armcompute.VirtualMachineScaleSetVMsClientBeginReimageOptions{ + VMScaleSetVMReimageInput: &body, + } + } + respr, errRespr := v.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReimage = &respr + } + + resp, err := server.PollerResponderNext(v.beginReimage, 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(v.beginReimage) { + v.beginReimage = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimageAll(req *http.Request) (*http.Response, error) { + if v.srv.BeginReimageAll == nil { + return nil, &nonRetriableError{errors.New("method BeginReimageAll not implemented")} + } + if v.beginReimageAll == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/reimageall" + 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 := v.srv.BeginReimageAll(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReimageAll = &respr + } + + resp, err := server.PollerResponderNext(v.beginReimageAll, 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(v.beginReimageAll) { + v.beginReimageAll = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { + if v.srv.BeginRestart == nil { + return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + } + if v.beginRestart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/restart" + 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 := v.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRestart = &respr + } + + resp, err := server.PollerResponderNext(v.beginRestart, 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(v.beginRestart) { + v.beginRestart = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchRetrieveBootDiagnosticsData(req *http.Request) (*http.Response, error) { + if v.srv.RetrieveBootDiagnosticsData == nil { + return nil, &nonRetriableError{errors.New("method RetrieveBootDiagnosticsData not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/retrieveBootDiagnosticsData" + 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) + } + qp := req.URL.Query() + sasURIExpirationTimeInMinutesParam, err := parseOptional(qp.Get("sasUriExpirationTimeInMinutes"), 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 *armcompute.VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataOptions + if sasURIExpirationTimeInMinutesParam != nil { + options = &armcompute.VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataOptions{ + SasURIExpirationTimeInMinutes: sasURIExpirationTimeInMinutesParam, + } + } + respr, errRespr := v.srv.RetrieveBootDiagnosticsData(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], 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).RetrieveBootDiagnosticsDataResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRunCommand(req *http.Request) (*http.Response, error) { + if v.srv.BeginRunCommand == nil { + return nil, &nonRetriableError{errors.New("method BeginRunCommand not implemented")} + } + if v.beginRunCommand == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/runCommand" + 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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.RunCommandInput](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRunCommand(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginRunCommand = &respr + } + + resp, err := server.PollerResponderNext(v.beginRunCommand, 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(v.beginRunCommand) { + v.beginRunCommand = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchSimulateEviction(req *http.Request) (*http.Response, error) { + if v.srv.SimulateEviction == nil { + return nil, &nonRetriableError{errors.New("method SimulateEviction not implemented")} + } + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/simulateEviction" + 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 := v.srv.SimulateEviction(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], 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 (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { + if v.srv.BeginStart == nil { + return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + } + if v.beginStart == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/start" + 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 := v.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStart = &respr + } + + resp, err := server.PollerResponderNext(v.beginStart, 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(v.beginStart) { + v.beginStart = nil + } + + return resp, nil +} + +func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + } + if v.beginUpdate == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?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) + } + body, err := server.UnmarshalRequestAsJSON[armcompute.VirtualMachineScaleSetVM](req) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(v.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(v.beginUpdate) { + v.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go new file mode 100644 index 000000000000..7a72bffb7a1d --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go @@ -0,0 +1,93 @@ +//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/resourcemanager/compute/armcompute/v5" + "net/http" + "regexp" +) + +// VirtualMachineSizesServer is a fake server for instances of the armcompute.VirtualMachineSizesClient type. +type VirtualMachineSizesServer struct { + // NewListPager is the fake for method VirtualMachineSizesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armcompute.VirtualMachineSizesClientListOptions) (resp azfake.PagerResponder[armcompute.VirtualMachineSizesClientListResponse]) +} + +// NewVirtualMachineSizesServerTransport creates a new instance of VirtualMachineSizesServerTransport with the provided implementation. +// The returned VirtualMachineSizesServerTransport instance is connected to an instance of armcompute.VirtualMachineSizesClient by way of the +// undefined.Transporter field. +func NewVirtualMachineSizesServerTransport(srv *VirtualMachineSizesServer) *VirtualMachineSizesServerTransport { + return &VirtualMachineSizesServerTransport{srv: srv} +} + +// VirtualMachineSizesServerTransport connects instances of armcompute.VirtualMachineSizesClient to instances of VirtualMachineSizesServer. +// Don't use this type directly, use NewVirtualMachineSizesServerTransport instead. +type VirtualMachineSizesServerTransport struct { + srv *VirtualMachineSizesServer + newListPager *azfake.PagerResponder[armcompute.VirtualMachineSizesClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualMachineSizesServerTransport. +func (v *VirtualMachineSizesServerTransport) 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 "VirtualMachineSizesClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualMachineSizesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + } + if v.newListPager == nil { + const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/vmSizes" + 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) + } + resp := v.srv.NewListPager(matches[regex.SubexpIndex("location")], nil) + v.newListPager = &resp + } + resp, err := server.PagerResponderNext(v.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(v.newListPager) { + v.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/compute/armcompute/galleries_client.go b/sdk/resourcemanager/compute/armcompute/galleries_client.go index 1faff1f6cd33..f4c266f03092 100644 --- a/sdk/resourcemanager/compute/armcompute/galleries_client.go +++ b/sdk/resourcemanager/compute/armcompute/galleries_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 armcompute @@ -61,7 +60,8 @@ func (client *GalleriesClient) BeginCreateOrUpdate(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller[GalleriesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleriesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleriesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *GalleriesClient) BeginCreateOrUpdate(ctx context.Context, resource // // Generated from API version 2022-03-03 func (client *GalleriesClient) createOrUpdate(ctx context.Context, resourceGroupName string, galleryName string, gallery Gallery, options *GalleriesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleriesClient.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, galleryName, gallery, 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. @@ -109,7 +115,10 @@ func (client *GalleriesClient) createOrUpdateCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, gallery) + if err := runtime.MarshalAsJSON(req, gallery); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Delete a Shared Image Gallery. @@ -125,7 +134,8 @@ func (client *GalleriesClient) BeginDelete(ctx context.Context, resourceGroupNam if err != nil { return nil, err } - return runtime.NewPoller[GalleriesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleriesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleriesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -136,18 +146,24 @@ func (client *GalleriesClient) BeginDelete(ctx context.Context, resourceGroupNam // // Generated from API version 2022-03-03 func (client *GalleriesClient) deleteOperation(ctx context.Context, resourceGroupName string, galleryName string, options *GalleriesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "GalleriesClient.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, galleryName, 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. @@ -184,18 +200,25 @@ func (client *GalleriesClient) deleteCreateRequest(ctx context.Context, resource // - galleryName - The name of the Shared Image Gallery. // - options - GalleriesClientGetOptions contains the optional parameters for the GalleriesClient.Get method. func (client *GalleriesClient) Get(ctx context.Context, resourceGroupName string, galleryName string, options *GalleriesClientGetOptions) (GalleriesClientGetResponse, error) { + var err error + const operationName = "GalleriesClient.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, galleryName, options) if err != nil { return GalleriesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GalleriesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return GalleriesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return GalleriesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -249,6 +272,7 @@ func (client *GalleriesClient) NewListPager(options *GalleriesClientListOptions) return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GalleriesClientListResponse) (GalleriesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GalleriesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -268,6 +292,7 @@ func (client *GalleriesClient) NewListPager(options *GalleriesClientListOptions) } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -310,6 +335,7 @@ func (client *GalleriesClient) NewListByResourceGroupPager(resourceGroupName str return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GalleriesClientListByResourceGroupResponse) (GalleriesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GalleriesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -329,6 +355,7 @@ func (client *GalleriesClient) NewListByResourceGroupPager(resourceGroupName str } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -378,7 +405,8 @@ func (client *GalleriesClient) BeginUpdate(ctx context.Context, resourceGroupNam if err != nil { return nil, err } - return runtime.NewPoller[GalleriesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleriesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleriesClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -389,18 +417,24 @@ func (client *GalleriesClient) BeginUpdate(ctx context.Context, resourceGroupNam // // Generated from API version 2022-03-03 func (client *GalleriesClient) update(ctx context.Context, resourceGroupName string, galleryName string, gallery GalleryUpdate, options *GalleriesClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleriesClient.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, galleryName, gallery, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -426,5 +460,8 @@ func (client *GalleriesClient) updateCreateRequest(ctx context.Context, resource reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, gallery) + if err := runtime.MarshalAsJSON(req, gallery); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/galleryapplications_client.go b/sdk/resourcemanager/compute/armcompute/galleryapplications_client.go index 36ae2d7d969b..459ab1120072 100644 --- a/sdk/resourcemanager/compute/armcompute/galleryapplications_client.go +++ b/sdk/resourcemanager/compute/armcompute/galleryapplications_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 armcompute @@ -63,7 +62,8 @@ func (client *GalleryApplicationsClient) BeginCreateOrUpdate(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller[GalleryApplicationsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryApplicationsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryApplicationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *GalleryApplicationsClient) BeginCreateOrUpdate(ctx context.Context // // Generated from API version 2022-03-03 func (client *GalleryApplicationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplication GalleryApplication, options *GalleryApplicationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryApplicationsClient.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, galleryName, galleryApplicationName, galleryApplication, 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. @@ -115,7 +121,10 @@ func (client *GalleryApplicationsClient) createOrUpdateCreateRequest(ctx context reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryApplication) + if err := runtime.MarshalAsJSON(req, galleryApplication); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Delete a gallery Application. @@ -133,7 +142,8 @@ func (client *GalleryApplicationsClient) BeginDelete(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller[GalleryApplicationsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryApplicationsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryApplicationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -144,18 +154,24 @@ func (client *GalleryApplicationsClient) BeginDelete(ctx context.Context, resour // // Generated from API version 2022-03-03 func (client *GalleryApplicationsClient) deleteOperation(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, options *GalleryApplicationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "GalleryApplicationsClient.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, galleryName, galleryApplicationName, 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. @@ -197,18 +213,25 @@ func (client *GalleryApplicationsClient) deleteCreateRequest(ctx context.Context // - galleryApplicationName - The name of the gallery Application Definition to be retrieved. // - options - GalleryApplicationsClientGetOptions contains the optional parameters for the GalleryApplicationsClient.Get method. func (client *GalleryApplicationsClient) Get(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, options *GalleryApplicationsClientGetOptions) (GalleryApplicationsClientGetResponse, error) { + var err error + const operationName = "GalleryApplicationsClient.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, galleryName, galleryApplicationName, options) if err != nil { return GalleryApplicationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GalleryApplicationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return GalleryApplicationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return GalleryApplicationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -263,6 +286,7 @@ func (client *GalleryApplicationsClient) NewListByGalleryPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GalleryApplicationsClientListByGalleryResponse) (GalleryApplicationsClientListByGalleryResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GalleryApplicationsClient.NewListByGalleryPager") var req *policy.Request var err error if page == nil { @@ -282,6 +306,7 @@ func (client *GalleryApplicationsClient) NewListByGalleryPager(resourceGroupName } return client.listByGalleryHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -338,7 +363,8 @@ func (client *GalleryApplicationsClient) BeginUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller[GalleryApplicationsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryApplicationsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryApplicationsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -349,18 +375,24 @@ func (client *GalleryApplicationsClient) BeginUpdate(ctx context.Context, resour // // Generated from API version 2022-03-03 func (client *GalleryApplicationsClient) update(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplication GalleryApplicationUpdate, options *GalleryApplicationsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryApplicationsClient.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, galleryName, galleryApplicationName, galleryApplication, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -390,5 +422,8 @@ func (client *GalleryApplicationsClient) updateCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryApplication) + if err := runtime.MarshalAsJSON(req, galleryApplication); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/galleryapplicationversions_client.go b/sdk/resourcemanager/compute/armcompute/galleryapplicationversions_client.go index c9f3f47191d8..22b5593086d6 100644 --- a/sdk/resourcemanager/compute/armcompute/galleryapplicationversions_client.go +++ b/sdk/resourcemanager/compute/armcompute/galleryapplicationversions_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 armcompute @@ -64,7 +63,8 @@ func (client *GalleryApplicationVersionsClient) BeginCreateOrUpdate(ctx context. if err != nil { return nil, err } - return runtime.NewPoller[GalleryApplicationVersionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryApplicationVersionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryApplicationVersionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -75,18 +75,24 @@ func (client *GalleryApplicationVersionsClient) BeginCreateOrUpdate(ctx context. // // Generated from API version 2022-03-03 func (client *GalleryApplicationVersionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, galleryApplicationVersion GalleryApplicationVersion, options *GalleryApplicationVersionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryApplicationVersionsClient.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, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion, 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. @@ -120,7 +126,10 @@ func (client *GalleryApplicationVersionsClient) createOrUpdateCreateRequest(ctx reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryApplicationVersion) + if err := runtime.MarshalAsJSON(req, galleryApplicationVersion); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Delete a gallery Application Version. @@ -139,7 +148,8 @@ func (client *GalleryApplicationVersionsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[GalleryApplicationVersionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryApplicationVersionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryApplicationVersionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -150,18 +160,24 @@ func (client *GalleryApplicationVersionsClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-03-03 func (client *GalleryApplicationVersionsClient) deleteOperation(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, options *GalleryApplicationVersionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "GalleryApplicationVersionsClient.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, galleryName, galleryApplicationName, galleryApplicationVersionName, 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. @@ -209,18 +225,25 @@ func (client *GalleryApplicationVersionsClient) deleteCreateRequest(ctx context. // - options - GalleryApplicationVersionsClientGetOptions contains the optional parameters for the GalleryApplicationVersionsClient.Get // method. func (client *GalleryApplicationVersionsClient) Get(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, options *GalleryApplicationVersionsClientGetOptions) (GalleryApplicationVersionsClientGetResponse, error) { + var err error + const operationName = "GalleryApplicationVersionsClient.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, galleryName, galleryApplicationName, galleryApplicationVersionName, options) if err != nil { return GalleryApplicationVersionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GalleryApplicationVersionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return GalleryApplicationVersionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return GalleryApplicationVersionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -284,6 +307,7 @@ func (client *GalleryApplicationVersionsClient) NewListByGalleryApplicationPager return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GalleryApplicationVersionsClientListByGalleryApplicationResponse) (GalleryApplicationVersionsClientListByGalleryApplicationResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GalleryApplicationVersionsClient.NewListByGalleryApplicationPager") var req *policy.Request var err error if page == nil { @@ -303,6 +327,7 @@ func (client *GalleryApplicationVersionsClient) NewListByGalleryApplicationPager } return client.listByGalleryApplicationHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -364,7 +389,8 @@ func (client *GalleryApplicationVersionsClient) BeginUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[GalleryApplicationVersionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryApplicationVersionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryApplicationVersionsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -375,18 +401,24 @@ func (client *GalleryApplicationVersionsClient) BeginUpdate(ctx context.Context, // // Generated from API version 2022-03-03 func (client *GalleryApplicationVersionsClient) update(ctx context.Context, resourceGroupName string, galleryName string, galleryApplicationName string, galleryApplicationVersionName string, galleryApplicationVersion GalleryApplicationVersionUpdate, options *GalleryApplicationVersionsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryApplicationVersionsClient.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, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -420,5 +452,8 @@ func (client *GalleryApplicationVersionsClient) updateCreateRequest(ctx context. reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryApplicationVersion) + if err := runtime.MarshalAsJSON(req, galleryApplicationVersion); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/galleryimages_client.go b/sdk/resourcemanager/compute/armcompute/galleryimages_client.go index bf4387227575..4c0a132a0b2f 100644 --- a/sdk/resourcemanager/compute/armcompute/galleryimages_client.go +++ b/sdk/resourcemanager/compute/armcompute/galleryimages_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 armcompute @@ -63,7 +62,8 @@ func (client *GalleryImagesClient) BeginCreateOrUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller[GalleryImagesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryImagesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryImagesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *GalleryImagesClient) BeginCreateOrUpdate(ctx context.Context, reso // // Generated from API version 2022-03-03 func (client *GalleryImagesClient) createOrUpdate(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImage GalleryImage, options *GalleryImagesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryImagesClient.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, galleryName, galleryImageName, galleryImage, 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. @@ -115,7 +121,10 @@ func (client *GalleryImagesClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryImage) + if err := runtime.MarshalAsJSON(req, galleryImage); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Delete a gallery image. @@ -133,7 +142,8 @@ func (client *GalleryImagesClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[GalleryImagesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryImagesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryImagesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -144,18 +154,24 @@ func (client *GalleryImagesClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2022-03-03 func (client *GalleryImagesClient) deleteOperation(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, options *GalleryImagesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "GalleryImagesClient.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, galleryName, galleryImageName, 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. @@ -197,18 +213,25 @@ func (client *GalleryImagesClient) deleteCreateRequest(ctx context.Context, reso // - galleryImageName - The name of the gallery image definition to be retrieved. // - options - GalleryImagesClientGetOptions contains the optional parameters for the GalleryImagesClient.Get method. func (client *GalleryImagesClient) Get(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, options *GalleryImagesClientGetOptions) (GalleryImagesClientGetResponse, error) { + var err error + const operationName = "GalleryImagesClient.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, galleryName, galleryImageName, options) if err != nil { return GalleryImagesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GalleryImagesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return GalleryImagesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return GalleryImagesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -263,6 +286,7 @@ func (client *GalleryImagesClient) NewListByGalleryPager(resourceGroupName strin return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GalleryImagesClientListByGalleryResponse) (GalleryImagesClientListByGalleryResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GalleryImagesClient.NewListByGalleryPager") var req *policy.Request var err error if page == nil { @@ -282,6 +306,7 @@ func (client *GalleryImagesClient) NewListByGalleryPager(resourceGroupName strin } return client.listByGalleryHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -337,7 +362,8 @@ func (client *GalleryImagesClient) BeginUpdate(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[GalleryImagesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryImagesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryImagesClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -348,18 +374,24 @@ func (client *GalleryImagesClient) BeginUpdate(ctx context.Context, resourceGrou // // Generated from API version 2022-03-03 func (client *GalleryImagesClient) update(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImage GalleryImageUpdate, options *GalleryImagesClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryImagesClient.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, galleryName, galleryImageName, galleryImage, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -389,5 +421,8 @@ func (client *GalleryImagesClient) updateCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryImage) + if err := runtime.MarshalAsJSON(req, galleryImage); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/galleryimageversions_client.go b/sdk/resourcemanager/compute/armcompute/galleryimageversions_client.go index 5854c87eebe0..90975af499d3 100644 --- a/sdk/resourcemanager/compute/armcompute/galleryimageversions_client.go +++ b/sdk/resourcemanager/compute/armcompute/galleryimageversions_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 armcompute @@ -64,7 +63,8 @@ func (client *GalleryImageVersionsClient) BeginCreateOrUpdate(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller[GalleryImageVersionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryImageVersionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryImageVersionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -75,18 +75,24 @@ func (client *GalleryImageVersionsClient) BeginCreateOrUpdate(ctx context.Contex // // Generated from API version 2022-03-03 func (client *GalleryImageVersionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, galleryImageVersion GalleryImageVersion, options *GalleryImageVersionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryImageVersionsClient.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, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion, 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. @@ -120,7 +126,10 @@ func (client *GalleryImageVersionsClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryImageVersion) + if err := runtime.MarshalAsJSON(req, galleryImageVersion); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Delete a gallery image version. @@ -139,7 +148,8 @@ func (client *GalleryImageVersionsClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller[GalleryImageVersionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryImageVersionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryImageVersionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -150,18 +160,24 @@ func (client *GalleryImageVersionsClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2022-03-03 func (client *GalleryImageVersionsClient) deleteOperation(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, options *GalleryImageVersionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "GalleryImageVersionsClient.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, galleryName, galleryImageName, galleryImageVersionName, 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. @@ -209,18 +225,25 @@ func (client *GalleryImageVersionsClient) deleteCreateRequest(ctx context.Contex // - options - GalleryImageVersionsClientGetOptions contains the optional parameters for the GalleryImageVersionsClient.Get // method. func (client *GalleryImageVersionsClient) Get(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, options *GalleryImageVersionsClientGetOptions) (GalleryImageVersionsClientGetResponse, error) { + var err error + const operationName = "GalleryImageVersionsClient.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, galleryName, galleryImageName, galleryImageVersionName, options) if err != nil { return GalleryImageVersionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GalleryImageVersionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return GalleryImageVersionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return GalleryImageVersionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -283,6 +306,7 @@ func (client *GalleryImageVersionsClient) NewListByGalleryImagePager(resourceGro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GalleryImageVersionsClientListByGalleryImageResponse) (GalleryImageVersionsClientListByGalleryImageResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GalleryImageVersionsClient.NewListByGalleryImagePager") var req *policy.Request var err error if page == nil { @@ -302,6 +326,7 @@ func (client *GalleryImageVersionsClient) NewListByGalleryImagePager(resourceGro } return client.listByGalleryImageHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -363,7 +388,8 @@ func (client *GalleryImageVersionsClient) BeginUpdate(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller[GalleryImageVersionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GalleryImageVersionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GalleryImageVersionsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -374,18 +400,24 @@ func (client *GalleryImageVersionsClient) BeginUpdate(ctx context.Context, resou // // Generated from API version 2022-03-03 func (client *GalleryImageVersionsClient) update(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, galleryImageVersion GalleryImageVersionUpdate, options *GalleryImageVersionsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GalleryImageVersionsClient.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, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -419,5 +451,8 @@ func (client *GalleryImageVersionsClient) updateCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, galleryImageVersion) + if err := runtime.MarshalAsJSON(req, galleryImageVersion); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/gallerysharingprofile_client.go b/sdk/resourcemanager/compute/armcompute/gallerysharingprofile_client.go index 1e6b646054a5..59e8777e9109 100644 --- a/sdk/resourcemanager/compute/armcompute/gallerysharingprofile_client.go +++ b/sdk/resourcemanager/compute/armcompute/gallerysharingprofile_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 armcompute @@ -60,7 +59,8 @@ func (client *GallerySharingProfileClient) BeginUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller[GallerySharingProfileClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[GallerySharingProfileClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[GallerySharingProfileClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -71,18 +71,24 @@ func (client *GallerySharingProfileClient) BeginUpdate(ctx context.Context, reso // // Generated from API version 2022-03-03 func (client *GallerySharingProfileClient) update(ctx context.Context, resourceGroupName string, galleryName string, sharingUpdate SharingUpdate, options *GallerySharingProfileClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "GallerySharingProfileClient.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, galleryName, sharingUpdate, 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. @@ -108,5 +114,8 @@ func (client *GallerySharingProfileClient) updateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-03-03") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, sharingUpdate) + if err := runtime.MarshalAsJSON(req, sharingUpdate); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/go.mod b/sdk/resourcemanager/compute/armcompute/go.mod index 7bf6f8fc204a..8965d86f88d8 100644 --- a/sdk/resourcemanager/compute/armcompute/go.mod +++ b/sdk/resourcemanager/compute/armcompute/go.mod @@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/ 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.2 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 @@ -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.9.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-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/crypto v0.6.0 // 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/compute/armcompute/go.sum b/sdk/resourcemanager/compute/armcompute/go.sum index 9e67f59f4a17..b8e59261b2da 100644 --- a/sdk/resourcemanager/compute/armcompute/go.sum +++ b/sdk/resourcemanager/compute/armcompute/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.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= -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= @@ -32,13 +32,13 @@ 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.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -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/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -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/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/compute/armcompute/images_client.go b/sdk/resourcemanager/compute/armcompute/images_client.go index f9235e2abc60..cd474b8d4399 100644 --- a/sdk/resourcemanager/compute/armcompute/images_client.go +++ b/sdk/resourcemanager/compute/armcompute/images_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 armcompute @@ -60,7 +59,8 @@ func (client *ImagesClient) BeginCreateOrUpdate(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[ImagesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ImagesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ImagesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -71,18 +71,24 @@ func (client *ImagesClient) BeginCreateOrUpdate(ctx context.Context, resourceGro // // Generated from API version 2023-03-01 func (client *ImagesClient) createOrUpdate(ctx context.Context, resourceGroupName string, imageName string, parameters Image, options *ImagesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ImagesClient.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, imageName, 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. @@ -108,7 +114,10 @@ func (client *ImagesClient) createOrUpdateCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2023-03-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 - Deletes an Image. @@ -124,7 +133,8 @@ func (client *ImagesClient) BeginDelete(ctx context.Context, resourceGroupName s if err != nil { return nil, err } - return runtime.NewPoller[ImagesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ImagesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ImagesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -135,18 +145,24 @@ func (client *ImagesClient) BeginDelete(ctx context.Context, resourceGroupName s // // Generated from API version 2023-03-01 func (client *ImagesClient) deleteOperation(ctx context.Context, resourceGroupName string, imageName string, options *ImagesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ImagesClient.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, imageName, 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. @@ -183,18 +199,25 @@ func (client *ImagesClient) deleteCreateRequest(ctx context.Context, resourceGro // - imageName - The name of the image. // - options - ImagesClientGetOptions contains the optional parameters for the ImagesClient.Get method. func (client *ImagesClient) Get(ctx context.Context, resourceGroupName string, imageName string, options *ImagesClientGetOptions) (ImagesClientGetResponse, error) { + var err error + const operationName = "ImagesClient.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, imageName, options) if err != nil { return ImagesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ImagesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ImagesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ImagesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -246,6 +269,7 @@ func (client *ImagesClient) NewListPager(options *ImagesClientListOptions) *runt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ImagesClientListResponse) (ImagesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ImagesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -265,6 +289,7 @@ func (client *ImagesClient) NewListPager(options *ImagesClientListOptions) *runt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -307,6 +332,7 @@ func (client *ImagesClient) NewListByResourceGroupPager(resourceGroupName string return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ImagesClientListByResourceGroupResponse) (ImagesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ImagesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -326,6 +352,7 @@ func (client *ImagesClient) NewListByResourceGroupPager(resourceGroupName string } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -374,7 +401,8 @@ func (client *ImagesClient) BeginUpdate(ctx context.Context, resourceGroupName s if err != nil { return nil, err } - return runtime.NewPoller[ImagesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[ImagesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[ImagesClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -385,18 +413,24 @@ func (client *ImagesClient) BeginUpdate(ctx context.Context, resourceGroupName s // // Generated from API version 2023-03-01 func (client *ImagesClient) update(ctx context.Context, resourceGroupName string, imageName string, parameters ImageUpdate, options *ImagesClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ImagesClient.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, imageName, 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 } // updateCreateRequest creates the Update request. @@ -422,5 +456,8 @@ func (client *ImagesClient) updateCreateRequest(ctx context.Context, resourceGro reqQP.Set("api-version", "2023-03-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/compute/armcompute/loganalytics_client.go b/sdk/resourcemanager/compute/armcompute/loganalytics_client.go index b19f3a632fb8..71d3e09da8f2 100644 --- a/sdk/resourcemanager/compute/armcompute/loganalytics_client.go +++ b/sdk/resourcemanager/compute/armcompute/loganalytics_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 armcompute @@ -60,9 +59,10 @@ func (client *LogAnalyticsClient) BeginExportRequestRateByInterval(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LogAnalyticsClientExportRequestRateByIntervalResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LogAnalyticsClientExportRequestRateByIntervalResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LogAnalyticsClientExportRequestRateByIntervalResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *LogAnalyticsClient) BeginExportRequestRateByInterval(ctx context.C // // Generated from API version 2023-03-01 func (client *LogAnalyticsClient) exportRequestRateByInterval(ctx context.Context, location string, parameters RequestRateByIntervalInput, options *LogAnalyticsClientBeginExportRequestRateByIntervalOptions) (*http.Response, error) { + var err error + const operationName = "LogAnalyticsClient.BeginExportRequestRateByInterval" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportRequestRateByIntervalCreateRequest(ctx, location, 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 } // exportRequestRateByIntervalCreateRequest creates the ExportRequestRateByInterval request. @@ -107,7 +113,10 @@ func (client *LogAnalyticsClient) exportRequestRateByIntervalCreateRequest(ctx c reqQP.Set("api-version", "2023-03-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 } // BeginExportThrottledRequests - Export logs that show total throttled Api requests for this subscription in the given time @@ -125,9 +134,10 @@ func (client *LogAnalyticsClient) BeginExportThrottledRequests(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LogAnalyticsClientExportThrottledRequestsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LogAnalyticsClientExportThrottledRequestsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LogAnalyticsClientExportThrottledRequestsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -138,18 +148,24 @@ func (client *LogAnalyticsClient) BeginExportThrottledRequests(ctx context.Conte // // Generated from API version 2023-03-01 func (client *LogAnalyticsClient) exportThrottledRequests(ctx context.Context, location string, parameters ThrottledRequestsInput, options *LogAnalyticsClientBeginExportThrottledRequestsOptions) (*http.Response, error) { + var err error + const operationName = "LogAnalyticsClient.BeginExportThrottledRequests" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportThrottledRequestsCreateRequest(ctx, location, 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 } // exportThrottledRequestsCreateRequest creates the ExportThrottledRequests request. @@ -171,5 +187,8 @@ func (client *LogAnalyticsClient) exportThrottledRequestsCreateRequest(ctx conte reqQP.Set("api-version", "2023-03-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/compute/armcompute/models.go b/sdk/resourcemanager/compute/armcompute/models.go index d85b30765b47..1d75062e2e24 100644 --- a/sdk/resourcemanager/compute/armcompute/models.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute diff --git a/sdk/resourcemanager/compute/armcompute/models_serde.go b/sdk/resourcemanager/compute/armcompute/models_serde.go index c9add9b77031..689814f93305 100644 --- a/sdk/resourcemanager/compute/armcompute/models_serde.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute diff --git a/sdk/resourcemanager/compute/armcompute/operations_client.go b/sdk/resourcemanager/compute/armcompute/operations_client.go index 92dde75d6d7d..14a574e17f5a 100644 --- a/sdk/resourcemanager/compute/armcompute/operations_client.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute @@ -48,6 +47,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption return false }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") req, err := client.listCreateRequest(ctx, options) if err != nil { return OperationsClientListResponse{}, err @@ -61,6 +61,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/proximityplacementgroups_client.go b/sdk/resourcemanager/compute/armcompute/proximityplacementgroups_client.go index 7d12d0f07f2d..c32df0927483 100644 --- a/sdk/resourcemanager/compute/armcompute/proximityplacementgroups_client.go +++ b/sdk/resourcemanager/compute/armcompute/proximityplacementgroups_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 armcompute @@ -55,18 +54,25 @@ func NewProximityPlacementGroupsClient(subscriptionID string, credential azcore. // - options - ProximityPlacementGroupsClientCreateOrUpdateOptions contains the optional parameters for the ProximityPlacementGroupsClient.CreateOrUpdate // method. func (client *ProximityPlacementGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, parameters ProximityPlacementGroup, options *ProximityPlacementGroupsClientCreateOrUpdateOptions) (ProximityPlacementGroupsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ProximityPlacementGroupsClient.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, proximityPlacementGroupName, parameters, options) if err != nil { return ProximityPlacementGroupsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProximityPlacementGroupsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ProximityPlacementGroupsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ProximityPlacementGroupsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -92,7 +98,10 @@ func (client *ProximityPlacementGroupsClient) createOrUpdateCreateRequest(ctx co reqQP.Set("api-version", "2023-03-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. @@ -113,16 +122,22 @@ func (client *ProximityPlacementGroupsClient) createOrUpdateHandleResponse(resp // - options - ProximityPlacementGroupsClientDeleteOptions contains the optional parameters for the ProximityPlacementGroupsClient.Delete // method. func (client *ProximityPlacementGroupsClient) Delete(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, options *ProximityPlacementGroupsClientDeleteOptions) (ProximityPlacementGroupsClientDeleteResponse, error) { + var err error + const operationName = "ProximityPlacementGroupsClient.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, resourceGroupName, proximityPlacementGroupName, options) if err != nil { return ProximityPlacementGroupsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProximityPlacementGroupsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProximityPlacementGroupsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProximityPlacementGroupsClientDeleteResponse{}, err } return ProximityPlacementGroupsClientDeleteResponse{}, nil } @@ -162,18 +177,25 @@ func (client *ProximityPlacementGroupsClient) deleteCreateRequest(ctx context.Co // - options - ProximityPlacementGroupsClientGetOptions contains the optional parameters for the ProximityPlacementGroupsClient.Get // method. func (client *ProximityPlacementGroupsClient) Get(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, options *ProximityPlacementGroupsClientGetOptions) (ProximityPlacementGroupsClientGetResponse, error) { + var err error + const operationName = "ProximityPlacementGroupsClient.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, proximityPlacementGroupName, options) if err != nil { return ProximityPlacementGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProximityPlacementGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProximityPlacementGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProximityPlacementGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -226,6 +248,7 @@ func (client *ProximityPlacementGroupsClient) NewListByResourceGroupPager(resour return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ProximityPlacementGroupsClientListByResourceGroupResponse) (ProximityPlacementGroupsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProximityPlacementGroupsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -245,6 +268,7 @@ func (client *ProximityPlacementGroupsClient) NewListByResourceGroupPager(resour } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -290,6 +314,7 @@ func (client *ProximityPlacementGroupsClient) NewListBySubscriptionPager(options return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ProximityPlacementGroupsClientListBySubscriptionResponse) (ProximityPlacementGroupsClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProximityPlacementGroupsClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -309,6 +334,7 @@ func (client *ProximityPlacementGroupsClient) NewListBySubscriptionPager(options } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -349,18 +375,25 @@ func (client *ProximityPlacementGroupsClient) listBySubscriptionHandleResponse(r // - options - ProximityPlacementGroupsClientUpdateOptions contains the optional parameters for the ProximityPlacementGroupsClient.Update // method. func (client *ProximityPlacementGroupsClient) Update(ctx context.Context, resourceGroupName string, proximityPlacementGroupName string, parameters ProximityPlacementGroupUpdate, options *ProximityPlacementGroupsClientUpdateOptions) (ProximityPlacementGroupsClientUpdateResponse, error) { + var err error + const operationName = "ProximityPlacementGroupsClient.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, proximityPlacementGroupName, parameters, options) if err != nil { return ProximityPlacementGroupsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProximityPlacementGroupsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProximityPlacementGroupsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProximityPlacementGroupsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -386,7 +419,10 @@ func (client *ProximityPlacementGroupsClient) updateCreateRequest(ctx context.Co reqQP.Set("api-version", "2023-03-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/compute/armcompute/resourceskus_client.go b/sdk/resourcemanager/compute/armcompute/resourceskus_client.go index 55799292b6bf..695431acbec8 100644 --- a/sdk/resourcemanager/compute/armcompute/resourceskus_client.go +++ b/sdk/resourcemanager/compute/armcompute/resourceskus_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 armcompute @@ -55,6 +54,7 @@ func (client *ResourceSKUsClient) NewListPager(options *ResourceSKUsClientListOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceSKUsClientListResponse) (ResourceSKUsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceSKUsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -74,6 +74,7 @@ func (client *ResourceSKUsClient) NewListPager(options *ResourceSKUsClientListOp } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/response_types.go b/sdk/resourcemanager/compute/armcompute/response_types.go index 2a77733c9f28..3f23308e7e9e 100644 --- a/sdk/resourcemanager/compute/armcompute/response_types.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute diff --git a/sdk/resourcemanager/compute/armcompute/restorepointcollections_client.go b/sdk/resourcemanager/compute/armcompute/restorepointcollections_client.go index 85ac1df0b150..039c2019116b 100644 --- a/sdk/resourcemanager/compute/armcompute/restorepointcollections_client.go +++ b/sdk/resourcemanager/compute/armcompute/restorepointcollections_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 armcompute @@ -56,18 +55,25 @@ func NewRestorePointCollectionsClient(subscriptionID string, credential azcore.T // - options - RestorePointCollectionsClientCreateOrUpdateOptions contains the optional parameters for the RestorePointCollectionsClient.CreateOrUpdate // method. func (client *RestorePointCollectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, restorePointCollectionName string, parameters RestorePointCollection, options *RestorePointCollectionsClientCreateOrUpdateOptions) (RestorePointCollectionsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "RestorePointCollectionsClient.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, restorePointCollectionName, parameters, options) if err != nil { return RestorePointCollectionsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RestorePointCollectionsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return RestorePointCollectionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return RestorePointCollectionsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -93,7 +99,10 @@ func (client *RestorePointCollectionsClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2023-03-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. @@ -120,7 +129,8 @@ func (client *RestorePointCollectionsClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller[RestorePointCollectionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[RestorePointCollectionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[RestorePointCollectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -132,18 +142,24 @@ func (client *RestorePointCollectionsClient) BeginDelete(ctx context.Context, re // // Generated from API version 2023-03-01 func (client *RestorePointCollectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, restorePointCollectionName string, options *RestorePointCollectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RestorePointCollectionsClient.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, restorePointCollectionName, 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. @@ -181,18 +197,25 @@ func (client *RestorePointCollectionsClient) deleteCreateRequest(ctx context.Con // - options - RestorePointCollectionsClientGetOptions contains the optional parameters for the RestorePointCollectionsClient.Get // method. func (client *RestorePointCollectionsClient) Get(ctx context.Context, resourceGroupName string, restorePointCollectionName string, options *RestorePointCollectionsClientGetOptions) (RestorePointCollectionsClientGetResponse, error) { + var err error + const operationName = "RestorePointCollectionsClient.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, restorePointCollectionName, options) if err != nil { return RestorePointCollectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RestorePointCollectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RestorePointCollectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RestorePointCollectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -245,6 +268,7 @@ func (client *RestorePointCollectionsClient) NewListPager(resourceGroupName stri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RestorePointCollectionsClientListResponse) (RestorePointCollectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RestorePointCollectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -264,6 +288,7 @@ func (client *RestorePointCollectionsClient) NewListPager(resourceGroupName stri } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -311,6 +336,7 @@ func (client *RestorePointCollectionsClient) NewListAllPager(options *RestorePoi return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RestorePointCollectionsClientListAllResponse) (RestorePointCollectionsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RestorePointCollectionsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -330,6 +356,7 @@ func (client *RestorePointCollectionsClient) NewListAllPager(options *RestorePoi } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -370,18 +397,25 @@ func (client *RestorePointCollectionsClient) listAllHandleResponse(resp *http.Re // - options - RestorePointCollectionsClientUpdateOptions contains the optional parameters for the RestorePointCollectionsClient.Update // method. func (client *RestorePointCollectionsClient) Update(ctx context.Context, resourceGroupName string, restorePointCollectionName string, parameters RestorePointCollectionUpdate, options *RestorePointCollectionsClientUpdateOptions) (RestorePointCollectionsClientUpdateResponse, error) { + var err error + const operationName = "RestorePointCollectionsClient.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, restorePointCollectionName, parameters, options) if err != nil { return RestorePointCollectionsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RestorePointCollectionsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RestorePointCollectionsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RestorePointCollectionsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -407,7 +441,10 @@ func (client *RestorePointCollectionsClient) updateCreateRequest(ctx context.Con reqQP.Set("api-version", "2023-03-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/compute/armcompute/restorepoints_client.go b/sdk/resourcemanager/compute/armcompute/restorepoints_client.go index dc3b1da6e128..6c9b115bb9ee 100644 --- a/sdk/resourcemanager/compute/armcompute/restorepoints_client.go +++ b/sdk/resourcemanager/compute/armcompute/restorepoints_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 armcompute @@ -61,7 +60,8 @@ func (client *RestorePointsClient) BeginCreate(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[RestorePointsClientCreateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[RestorePointsClientCreateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[RestorePointsClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *RestorePointsClient) BeginCreate(ctx context.Context, resourceGrou // // Generated from API version 2023-03-01 func (client *RestorePointsClient) create(ctx context.Context, resourceGroupName string, restorePointCollectionName string, restorePointName string, parameters RestorePoint, options *RestorePointsClientBeginCreateOptions) (*http.Response, error) { + var err error + const operationName = "RestorePointsClient.BeginCreate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createCreateRequest(ctx, resourceGroupName, restorePointCollectionName, restorePointName, 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.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createCreateRequest creates the Create request. @@ -113,7 +119,10 @@ func (client *RestorePointsClient) createCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2023-03-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 - The operation to delete the restore point. @@ -131,7 +140,8 @@ func (client *RestorePointsClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller[RestorePointsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[RestorePointsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[RestorePointsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *RestorePointsClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2023-03-01 func (client *RestorePointsClient) deleteOperation(ctx context.Context, resourceGroupName string, restorePointCollectionName string, restorePointName string, options *RestorePointsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RestorePointsClient.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, restorePointCollectionName, restorePointName, 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. @@ -195,18 +211,25 @@ func (client *RestorePointsClient) deleteCreateRequest(ctx context.Context, reso // - restorePointName - The name of the restore point. // - options - RestorePointsClientGetOptions contains the optional parameters for the RestorePointsClient.Get method. func (client *RestorePointsClient) Get(ctx context.Context, resourceGroupName string, restorePointCollectionName string, restorePointName string, options *RestorePointsClientGetOptions) (RestorePointsClientGetResponse, error) { + var err error + const operationName = "RestorePointsClient.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, restorePointCollectionName, restorePointName, options) if err != nil { return RestorePointsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RestorePointsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RestorePointsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RestorePointsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. diff --git a/sdk/resourcemanager/compute/armcompute/sharedgalleries_client.go b/sdk/resourcemanager/compute/armcompute/sharedgalleries_client.go index b9a9467e6f4b..06f87bf38612 100644 --- a/sdk/resourcemanager/compute/armcompute/sharedgalleries_client.go +++ b/sdk/resourcemanager/compute/armcompute/sharedgalleries_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 armcompute @@ -53,18 +52,25 @@ func NewSharedGalleriesClient(subscriptionID string, credential azcore.TokenCred // - galleryUniqueName - The unique name of the Shared Gallery. // - options - SharedGalleriesClientGetOptions contains the optional parameters for the SharedGalleriesClient.Get method. func (client *SharedGalleriesClient) Get(ctx context.Context, location string, galleryUniqueName string, options *SharedGalleriesClientGetOptions) (SharedGalleriesClientGetResponse, error) { + var err error + const operationName = "SharedGalleriesClient.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, location, galleryUniqueName, options) if err != nil { return SharedGalleriesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SharedGalleriesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SharedGalleriesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SharedGalleriesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -114,6 +120,7 @@ func (client *SharedGalleriesClient) NewListPager(location string, options *Shar return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SharedGalleriesClientListResponse) (SharedGalleriesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SharedGalleriesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -133,6 +140,7 @@ func (client *SharedGalleriesClient) NewListPager(location string, options *Shar } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/sharedgalleryimages_client.go b/sdk/resourcemanager/compute/armcompute/sharedgalleryimages_client.go index 0f6618d263fc..9d1e8833551b 100644 --- a/sdk/resourcemanager/compute/armcompute/sharedgalleryimages_client.go +++ b/sdk/resourcemanager/compute/armcompute/sharedgalleryimages_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 armcompute @@ -54,18 +53,25 @@ func NewSharedGalleryImagesClient(subscriptionID string, credential azcore.Token // - galleryImageName - The name of the Shared Gallery Image Definition from which the Image Versions are to be listed. // - options - SharedGalleryImagesClientGetOptions contains the optional parameters for the SharedGalleryImagesClient.Get method. func (client *SharedGalleryImagesClient) Get(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, options *SharedGalleryImagesClientGetOptions) (SharedGalleryImagesClientGetResponse, error) { + var err error + const operationName = "SharedGalleryImagesClient.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, location, galleryUniqueName, galleryImageName, options) if err != nil { return SharedGalleryImagesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SharedGalleryImagesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SharedGalleryImagesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SharedGalleryImagesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -120,6 +126,7 @@ func (client *SharedGalleryImagesClient) NewListPager(location string, galleryUn return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SharedGalleryImagesClientListResponse) (SharedGalleryImagesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SharedGalleryImagesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -139,6 +146,7 @@ func (client *SharedGalleryImagesClient) NewListPager(location string, galleryUn } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/sharedgalleryimageversions_client.go b/sdk/resourcemanager/compute/armcompute/sharedgalleryimageversions_client.go index a688c3cbfcdd..ca6aeb9a4e16 100644 --- a/sdk/resourcemanager/compute/armcompute/sharedgalleryimageversions_client.go +++ b/sdk/resourcemanager/compute/armcompute/sharedgalleryimageversions_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 armcompute @@ -58,18 +57,25 @@ func NewSharedGalleryImageVersionsClient(subscriptionID string, credential azcor // - options - SharedGalleryImageVersionsClientGetOptions contains the optional parameters for the SharedGalleryImageVersionsClient.Get // method. func (client *SharedGalleryImageVersionsClient) Get(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, galleryImageVersionName string, options *SharedGalleryImageVersionsClientGetOptions) (SharedGalleryImageVersionsClientGetResponse, error) { + var err error + const operationName = "SharedGalleryImageVersionsClient.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, location, galleryUniqueName, galleryImageName, galleryImageVersionName, options) if err != nil { return SharedGalleryImageVersionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SharedGalleryImageVersionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SharedGalleryImageVersionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SharedGalleryImageVersionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -129,6 +135,7 @@ func (client *SharedGalleryImageVersionsClient) NewListPager(location string, ga return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SharedGalleryImageVersionsClientListResponse) (SharedGalleryImageVersionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SharedGalleryImageVersionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -148,6 +155,7 @@ func (client *SharedGalleryImageVersionsClient) NewListPager(location string, ga } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/snapshots_client.go b/sdk/resourcemanager/compute/armcompute/snapshots_client.go index 169c5aadea16..9112f007548a 100644 --- a/sdk/resourcemanager/compute/armcompute/snapshots_client.go +++ b/sdk/resourcemanager/compute/armcompute/snapshots_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 armcompute @@ -62,7 +61,8 @@ func (client *SnapshotsClient) BeginCreateOrUpdate(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller[SnapshotsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[SnapshotsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[SnapshotsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *SnapshotsClient) BeginCreateOrUpdate(ctx context.Context, resource // // Generated from API version 2022-07-02 func (client *SnapshotsClient) createOrUpdate(ctx context.Context, resourceGroupName string, snapshotName string, snapshot Snapshot, options *SnapshotsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SnapshotsClient.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, snapshotName, snapshot, 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 } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -110,7 +116,10 @@ func (client *SnapshotsClient) createOrUpdateCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, snapshot) + if err := runtime.MarshalAsJSON(req, snapshot); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a snapshot. @@ -128,7 +137,8 @@ func (client *SnapshotsClient) BeginDelete(ctx context.Context, resourceGroupNam if err != nil { return nil, err } - return runtime.NewPoller[SnapshotsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[SnapshotsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[SnapshotsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *SnapshotsClient) BeginDelete(ctx context.Context, resourceGroupNam // // Generated from API version 2022-07-02 func (client *SnapshotsClient) deleteOperation(ctx context.Context, resourceGroupName string, snapshotName string, options *SnapshotsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SnapshotsClient.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, snapshotName, 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. @@ -188,18 +204,25 @@ func (client *SnapshotsClient) deleteCreateRequest(ctx context.Context, resource // characters. // - options - SnapshotsClientGetOptions contains the optional parameters for the SnapshotsClient.Get method. func (client *SnapshotsClient) Get(ctx context.Context, resourceGroupName string, snapshotName string, options *SnapshotsClientGetOptions) (SnapshotsClientGetResponse, error) { + var err error + const operationName = "SnapshotsClient.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, snapshotName, options) if err != nil { return SnapshotsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SnapshotsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SnapshotsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SnapshotsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -254,9 +277,10 @@ func (client *SnapshotsClient) BeginGrantAccess(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SnapshotsClientGrantAccessResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SnapshotsClientGrantAccessResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SnapshotsClientGrantAccessResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -267,18 +291,24 @@ func (client *SnapshotsClient) BeginGrantAccess(ctx context.Context, resourceGro // // Generated from API version 2022-07-02 func (client *SnapshotsClient) grantAccess(ctx context.Context, resourceGroupName string, snapshotName string, grantAccessData GrantAccessData, options *SnapshotsClientBeginGrantAccessOptions) (*http.Response, error) { + var err error + const operationName = "SnapshotsClient.BeginGrantAccess" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.grantAccessCreateRequest(ctx, resourceGroupName, snapshotName, grantAccessData, 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 } // grantAccessCreateRequest creates the GrantAccess request. @@ -304,7 +334,10 @@ func (client *SnapshotsClient) grantAccessCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, grantAccessData) + if err := runtime.MarshalAsJSON(req, grantAccessData); err != nil { + return nil, err + } + return req, nil } // NewListPager - Lists snapshots under a subscription. @@ -317,6 +350,7 @@ func (client *SnapshotsClient) NewListPager(options *SnapshotsClientListOptions) return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SnapshotsClientListResponse) (SnapshotsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SnapshotsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -336,6 +370,7 @@ func (client *SnapshotsClient) NewListPager(options *SnapshotsClientListOptions) } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -378,6 +413,7 @@ func (client *SnapshotsClient) NewListByResourceGroupPager(resourceGroupName str return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SnapshotsClientListByResourceGroupResponse) (SnapshotsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SnapshotsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -397,6 +433,7 @@ func (client *SnapshotsClient) NewListByResourceGroupPager(resourceGroupName str } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -447,9 +484,10 @@ func (client *SnapshotsClient) BeginRevokeAccess(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SnapshotsClientRevokeAccessResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SnapshotsClientRevokeAccessResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SnapshotsClientRevokeAccessResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -460,18 +498,24 @@ func (client *SnapshotsClient) BeginRevokeAccess(ctx context.Context, resourceGr // // Generated from API version 2022-07-02 func (client *SnapshotsClient) revokeAccess(ctx context.Context, resourceGroupName string, snapshotName string, options *SnapshotsClientBeginRevokeAccessOptions) (*http.Response, error) { + var err error + const operationName = "SnapshotsClient.BeginRevokeAccess" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.revokeAccessCreateRequest(ctx, resourceGroupName, snapshotName, 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 } // revokeAccessCreateRequest creates the RevokeAccess request. @@ -515,7 +559,8 @@ func (client *SnapshotsClient) BeginUpdate(ctx context.Context, resourceGroupNam if err != nil { return nil, err } - return runtime.NewPoller[SnapshotsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[SnapshotsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[SnapshotsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -526,18 +571,24 @@ func (client *SnapshotsClient) BeginUpdate(ctx context.Context, resourceGroupNam // // Generated from API version 2022-07-02 func (client *SnapshotsClient) update(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate, options *SnapshotsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SnapshotsClient.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, snapshotName, snapshot, 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. @@ -563,5 +614,8 @@ func (client *SnapshotsClient) updateCreateRequest(ctx context.Context, resource reqQP.Set("api-version", "2022-07-02") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, snapshot) + if err := runtime.MarshalAsJSON(req, snapshot); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/sshpublickeys_client.go b/sdk/resourcemanager/compute/armcompute/sshpublickeys_client.go index 5bf5f7690f31..3944da9a1f32 100644 --- a/sdk/resourcemanager/compute/armcompute/sshpublickeys_client.go +++ b/sdk/resourcemanager/compute/armcompute/sshpublickeys_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 armcompute @@ -54,18 +53,25 @@ func NewSSHPublicKeysClient(subscriptionID string, credential azcore.TokenCreden // - parameters - Parameters supplied to create the SSH public key. // - options - SSHPublicKeysClientCreateOptions contains the optional parameters for the SSHPublicKeysClient.Create method. func (client *SSHPublicKeysClient) Create(ctx context.Context, resourceGroupName string, sshPublicKeyName string, parameters SSHPublicKeyResource, options *SSHPublicKeysClientCreateOptions) (SSHPublicKeysClientCreateResponse, error) { + var err error + const operationName = "SSHPublicKeysClient.Create" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createCreateRequest(ctx, resourceGroupName, sshPublicKeyName, parameters, options) if err != nil { return SSHPublicKeysClientCreateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SSHPublicKeysClientCreateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return SSHPublicKeysClientCreateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return SSHPublicKeysClientCreateResponse{}, err } - return client.createHandleResponse(resp) + resp, err := client.createHandleResponse(httpResp) + return resp, err } // createCreateRequest creates the Create request. @@ -91,7 +97,10 @@ func (client *SSHPublicKeysClient) createCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2023-03-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 } // createHandleResponse handles the Create response. @@ -111,16 +120,22 @@ func (client *SSHPublicKeysClient) createHandleResponse(resp *http.Response) (SS // - sshPublicKeyName - The name of the SSH public key. // - options - SSHPublicKeysClientDeleteOptions contains the optional parameters for the SSHPublicKeysClient.Delete method. func (client *SSHPublicKeysClient) Delete(ctx context.Context, resourceGroupName string, sshPublicKeyName string, options *SSHPublicKeysClientDeleteOptions) (SSHPublicKeysClientDeleteResponse, error) { + var err error + const operationName = "SSHPublicKeysClient.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, resourceGroupName, sshPublicKeyName, options) if err != nil { return SSHPublicKeysClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SSHPublicKeysClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return SSHPublicKeysClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return SSHPublicKeysClientDeleteResponse{}, err } return SSHPublicKeysClientDeleteResponse{}, nil } @@ -162,18 +177,25 @@ func (client *SSHPublicKeysClient) deleteCreateRequest(ctx context.Context, reso // - options - SSHPublicKeysClientGenerateKeyPairOptions contains the optional parameters for the SSHPublicKeysClient.GenerateKeyPair // method. func (client *SSHPublicKeysClient) GenerateKeyPair(ctx context.Context, resourceGroupName string, sshPublicKeyName string, options *SSHPublicKeysClientGenerateKeyPairOptions) (SSHPublicKeysClientGenerateKeyPairResponse, error) { + var err error + const operationName = "SSHPublicKeysClient.GenerateKeyPair" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generateKeyPairCreateRequest(ctx, resourceGroupName, sshPublicKeyName, options) if err != nil { return SSHPublicKeysClientGenerateKeyPairResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SSHPublicKeysClientGenerateKeyPairResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SSHPublicKeysClientGenerateKeyPairResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SSHPublicKeysClientGenerateKeyPairResponse{}, err } - return client.generateKeyPairHandleResponse(resp) + resp, err := client.generateKeyPairHandleResponse(httpResp) + return resp, err } // generateKeyPairCreateRequest creates the GenerateKeyPair request. @@ -219,18 +241,25 @@ func (client *SSHPublicKeysClient) generateKeyPairHandleResponse(resp *http.Resp // - sshPublicKeyName - The name of the SSH public key. // - options - SSHPublicKeysClientGetOptions contains the optional parameters for the SSHPublicKeysClient.Get method. func (client *SSHPublicKeysClient) Get(ctx context.Context, resourceGroupName string, sshPublicKeyName string, options *SSHPublicKeysClientGetOptions) (SSHPublicKeysClientGetResponse, error) { + var err error + const operationName = "SSHPublicKeysClient.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, sshPublicKeyName, options) if err != nil { return SSHPublicKeysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SSHPublicKeysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SSHPublicKeysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SSHPublicKeysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -281,6 +310,7 @@ func (client *SSHPublicKeysClient) NewListByResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SSHPublicKeysClientListByResourceGroupResponse) (SSHPublicKeysClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SSHPublicKeysClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -300,6 +330,7 @@ func (client *SSHPublicKeysClient) NewListByResourceGroupPager(resourceGroupName } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -346,6 +377,7 @@ func (client *SSHPublicKeysClient) NewListBySubscriptionPager(options *SSHPublic return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SSHPublicKeysClientListBySubscriptionResponse) (SSHPublicKeysClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SSHPublicKeysClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -365,6 +397,7 @@ func (client *SSHPublicKeysClient) NewListBySubscriptionPager(options *SSHPublic } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -404,18 +437,25 @@ func (client *SSHPublicKeysClient) listBySubscriptionHandleResponse(resp *http.R // - parameters - Parameters supplied to update the SSH public key. // - options - SSHPublicKeysClientUpdateOptions contains the optional parameters for the SSHPublicKeysClient.Update method. func (client *SSHPublicKeysClient) Update(ctx context.Context, resourceGroupName string, sshPublicKeyName string, parameters SSHPublicKeyUpdateResource, options *SSHPublicKeysClientUpdateOptions) (SSHPublicKeysClientUpdateResponse, error) { + var err error + const operationName = "SSHPublicKeysClient.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, sshPublicKeyName, parameters, options) if err != nil { return SSHPublicKeysClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SSHPublicKeysClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SSHPublicKeysClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SSHPublicKeysClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -441,7 +481,10 @@ func (client *SSHPublicKeysClient) updateCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2023-03-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/compute/armcompute/time_rfc3339.go b/sdk/resourcemanager/compute/armcompute/time_rfc3339.go index 9181b3d076ff..558de99cb879 100644 --- a/sdk/resourcemanager/compute/armcompute/time_rfc3339.go +++ b/sdk/resourcemanager/compute/armcompute/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 armcompute diff --git a/sdk/resourcemanager/compute/armcompute/usage_client.go b/sdk/resourcemanager/compute/armcompute/usage_client.go index 2a9ea794d3bd..261174509bc5 100644 --- a/sdk/resourcemanager/compute/armcompute/usage_client.go +++ b/sdk/resourcemanager/compute/armcompute/usage_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 armcompute @@ -57,6 +56,7 @@ func (client *UsageClient) NewListPager(location string, options *UsageClientLis return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *UsageClientListResponse) (UsageClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "UsageClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -76,6 +76,7 @@ func (client *UsageClient) NewListPager(location string, options *UsageClientLis } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimages_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimages_client.go index a235a419a45e..f5cda3b63ef8 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimages_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimages_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 armcompute @@ -54,18 +53,25 @@ func NewVirtualMachineExtensionImagesClient(subscriptionID string, credential az // - options - VirtualMachineExtensionImagesClientGetOptions contains the optional parameters for the VirtualMachineExtensionImagesClient.Get // method. func (client *VirtualMachineExtensionImagesClient) Get(ctx context.Context, location string, publisherName string, typeParam string, version string, options *VirtualMachineExtensionImagesClientGetOptions) (VirtualMachineExtensionImagesClientGetResponse, error) { + var err error + const operationName = "VirtualMachineExtensionImagesClient.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, location, publisherName, typeParam, version, options) if err != nil { return VirtualMachineExtensionImagesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineExtensionImagesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineExtensionImagesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineExtensionImagesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -119,18 +125,25 @@ func (client *VirtualMachineExtensionImagesClient) getHandleResponse(resp *http. // - options - VirtualMachineExtensionImagesClientListTypesOptions contains the optional parameters for the VirtualMachineExtensionImagesClient.ListTypes // method. func (client *VirtualMachineExtensionImagesClient) ListTypes(ctx context.Context, location string, publisherName string, options *VirtualMachineExtensionImagesClientListTypesOptions) (VirtualMachineExtensionImagesClientListTypesResponse, error) { + var err error + const operationName = "VirtualMachineExtensionImagesClient.ListTypes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listTypesCreateRequest(ctx, location, publisherName, options) if err != nil { return VirtualMachineExtensionImagesClientListTypesResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineExtensionImagesClientListTypesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineExtensionImagesClientListTypesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineExtensionImagesClientListTypesResponse{}, err } - return client.listTypesHandleResponse(resp) + resp, err := client.listTypesHandleResponse(httpResp) + return resp, err } // listTypesCreateRequest creates the ListTypes request. @@ -176,18 +189,25 @@ func (client *VirtualMachineExtensionImagesClient) listTypesHandleResponse(resp // - options - VirtualMachineExtensionImagesClientListVersionsOptions contains the optional parameters for the VirtualMachineExtensionImagesClient.ListVersions // method. func (client *VirtualMachineExtensionImagesClient) ListVersions(ctx context.Context, location string, publisherName string, typeParam string, options *VirtualMachineExtensionImagesClientListVersionsOptions) (VirtualMachineExtensionImagesClientListVersionsResponse, error) { + var err error + const operationName = "VirtualMachineExtensionImagesClient.ListVersions" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listVersionsCreateRequest(ctx, location, publisherName, typeParam, options) if err != nil { return VirtualMachineExtensionImagesClientListVersionsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineExtensionImagesClientListVersionsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineExtensionImagesClientListVersionsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineExtensionImagesClientListVersionsResponse{}, err } - return client.listVersionsHandleResponse(resp) + resp, err := client.listVersionsHandleResponse(httpResp) + return resp, err } // listVersionsCreateRequest creates the ListVersions request. diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineextensions_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachineextensions_client.go index c14cbf8e5d23..ab76f34e2723 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachineextensions_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineextensions_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 armcompute @@ -61,7 +60,8 @@ func (client *VirtualMachineExtensionsClient) BeginCreateOrUpdate(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineExtensionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineExtensionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineExtensionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *VirtualMachineExtensionsClient) BeginCreateOrUpdate(ctx context.Co // // Generated from API version 2023-03-01 func (client *VirtualMachineExtensionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, extensionParameters VirtualMachineExtension, options *VirtualMachineExtensionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineExtensionsClient.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, vmName, vmExtensionName, extensionParameters, 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. @@ -113,7 +119,10 @@ func (client *VirtualMachineExtensionsClient) createOrUpdateCreateRequest(ctx co reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, extensionParameters) + if err := runtime.MarshalAsJSON(req, extensionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - The operation to delete the extension. @@ -131,7 +140,8 @@ func (client *VirtualMachineExtensionsClient) BeginDelete(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineExtensionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineExtensionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineExtensionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *VirtualMachineExtensionsClient) BeginDelete(ctx context.Context, r // // Generated from API version 2023-03-01 func (client *VirtualMachineExtensionsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, options *VirtualMachineExtensionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineExtensionsClient.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, vmName, vmExtensionName, 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. @@ -196,18 +212,25 @@ func (client *VirtualMachineExtensionsClient) deleteCreateRequest(ctx context.Co // - options - VirtualMachineExtensionsClientGetOptions contains the optional parameters for the VirtualMachineExtensionsClient.Get // method. func (client *VirtualMachineExtensionsClient) Get(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, options *VirtualMachineExtensionsClientGetOptions) (VirtualMachineExtensionsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineExtensionsClient.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, vmName, vmExtensionName, options) if err != nil { return VirtualMachineExtensionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineExtensionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineExtensionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineExtensionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -261,18 +284,25 @@ func (client *VirtualMachineExtensionsClient) getHandleResponse(resp *http.Respo // - options - VirtualMachineExtensionsClientListOptions contains the optional parameters for the VirtualMachineExtensionsClient.List // method. func (client *VirtualMachineExtensionsClient) List(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachineExtensionsClientListOptions) (VirtualMachineExtensionsClientListResponse, error) { + var err error + const operationName = "VirtualMachineExtensionsClient.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, resourceGroupName, vmName, options) if err != nil { return VirtualMachineExtensionsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineExtensionsClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineExtensionsClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineExtensionsClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -329,7 +359,8 @@ func (client *VirtualMachineExtensionsClient) BeginUpdate(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineExtensionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineExtensionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineExtensionsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -340,18 +371,24 @@ func (client *VirtualMachineExtensionsClient) BeginUpdate(ctx context.Context, r // // Generated from API version 2023-03-01 func (client *VirtualMachineExtensionsClient) update(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, extensionParameters VirtualMachineExtensionUpdate, options *VirtualMachineExtensionsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineExtensionsClient.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, vmName, vmExtensionName, extensionParameters, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -381,5 +418,8 @@ func (client *VirtualMachineExtensionsClient) updateCreateRequest(ctx context.Co reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, extensionParameters) + if err := runtime.MarshalAsJSON(req, extensionParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineimages_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachineimages_client.go index 0e6c10f160c6..59ae2b64b802 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachineimages_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineimages_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 armcompute @@ -58,18 +57,25 @@ func NewVirtualMachineImagesClient(subscriptionID string, credential azcore.Toke // - options - VirtualMachineImagesClientGetOptions contains the optional parameters for the VirtualMachineImagesClient.Get // method. func (client *VirtualMachineImagesClient) Get(ctx context.Context, location string, publisherName string, offer string, skus string, version string, options *VirtualMachineImagesClientGetOptions) (VirtualMachineImagesClientGetResponse, error) { + var err error + const operationName = "VirtualMachineImagesClient.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, location, publisherName, offer, skus, version, options) if err != nil { return VirtualMachineImagesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -130,18 +136,25 @@ func (client *VirtualMachineImagesClient) getHandleResponse(resp *http.Response) // - options - VirtualMachineImagesClientListOptions contains the optional parameters for the VirtualMachineImagesClient.List // method. func (client *VirtualMachineImagesClient) List(ctx context.Context, location string, publisherName string, offer string, skus string, options *VirtualMachineImagesClientListOptions) (VirtualMachineImagesClientListResponse, error) { + var err error + const operationName = "VirtualMachineImagesClient.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, location, publisherName, offer, skus, options) if err != nil { return VirtualMachineImagesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -205,18 +218,25 @@ func (client *VirtualMachineImagesClient) listHandleResponse(resp *http.Response // - options - VirtualMachineImagesClientListByEdgeZoneOptions contains the optional parameters for the VirtualMachineImagesClient.ListByEdgeZone // method. func (client *VirtualMachineImagesClient) ListByEdgeZone(ctx context.Context, location string, edgeZone string, options *VirtualMachineImagesClientListByEdgeZoneOptions) (VirtualMachineImagesClientListByEdgeZoneResponse, error) { + var err error + const operationName = "VirtualMachineImagesClient.ListByEdgeZone" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listByEdgeZoneCreateRequest(ctx, location, edgeZone, options) if err != nil { return VirtualMachineImagesClientListByEdgeZoneResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesClientListByEdgeZoneResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesClientListByEdgeZoneResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesClientListByEdgeZoneResponse{}, err } - return client.listByEdgeZoneHandleResponse(resp) + resp, err := client.listByEdgeZoneHandleResponse(httpResp) + return resp, err } // listByEdgeZoneCreateRequest creates the ListByEdgeZone request. @@ -263,18 +283,25 @@ func (client *VirtualMachineImagesClient) listByEdgeZoneHandleResponse(resp *htt // - options - VirtualMachineImagesClientListOffersOptions contains the optional parameters for the VirtualMachineImagesClient.ListOffers // method. func (client *VirtualMachineImagesClient) ListOffers(ctx context.Context, location string, publisherName string, options *VirtualMachineImagesClientListOffersOptions) (VirtualMachineImagesClientListOffersResponse, error) { + var err error + const operationName = "VirtualMachineImagesClient.ListOffers" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listOffersCreateRequest(ctx, location, publisherName, options) if err != nil { return VirtualMachineImagesClientListOffersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesClientListOffersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesClientListOffersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesClientListOffersResponse{}, err } - return client.listOffersHandleResponse(resp) + resp, err := client.listOffersHandleResponse(httpResp) + return resp, err } // listOffersCreateRequest creates the ListOffers request. @@ -320,18 +347,25 @@ func (client *VirtualMachineImagesClient) listOffersHandleResponse(resp *http.Re // - options - VirtualMachineImagesClientListPublishersOptions contains the optional parameters for the VirtualMachineImagesClient.ListPublishers // method. func (client *VirtualMachineImagesClient) ListPublishers(ctx context.Context, location string, options *VirtualMachineImagesClientListPublishersOptions) (VirtualMachineImagesClientListPublishersResponse, error) { + var err error + const operationName = "VirtualMachineImagesClient.ListPublishers" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listPublishersCreateRequest(ctx, location, options) if err != nil { return VirtualMachineImagesClientListPublishersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesClientListPublishersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesClientListPublishersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesClientListPublishersResponse{}, err } - return client.listPublishersHandleResponse(resp) + resp, err := client.listPublishersHandleResponse(httpResp) + return resp, err } // listPublishersCreateRequest creates the ListPublishers request. @@ -375,18 +409,25 @@ func (client *VirtualMachineImagesClient) listPublishersHandleResponse(resp *htt // - options - VirtualMachineImagesClientListSKUsOptions contains the optional parameters for the VirtualMachineImagesClient.ListSKUs // method. func (client *VirtualMachineImagesClient) ListSKUs(ctx context.Context, location string, publisherName string, offer string, options *VirtualMachineImagesClientListSKUsOptions) (VirtualMachineImagesClientListSKUsResponse, error) { + var err error + const operationName = "VirtualMachineImagesClient.ListSKUs" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listSKUsCreateRequest(ctx, location, publisherName, offer, options) if err != nil { return VirtualMachineImagesClientListSKUsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesClientListSKUsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesClientListSKUsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesClientListSKUsResponse{}, err } - return client.listSKUsHandleResponse(resp) + resp, err := client.listSKUsHandleResponse(httpResp) + return resp, err } // listSKUsCreateRequest creates the ListSKUs request. diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineimagesedgezone_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachineimagesedgezone_client.go index d3db9bd044cc..cdbbc3abea1f 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachineimagesedgezone_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineimagesedgezone_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 armcompute @@ -59,18 +58,25 @@ func NewVirtualMachineImagesEdgeZoneClient(subscriptionID string, credential azc // - options - VirtualMachineImagesEdgeZoneClientGetOptions contains the optional parameters for the VirtualMachineImagesEdgeZoneClient.Get // method. func (client *VirtualMachineImagesEdgeZoneClient) Get(ctx context.Context, location string, edgeZone string, publisherName string, offer string, skus string, version string, options *VirtualMachineImagesEdgeZoneClientGetOptions) (VirtualMachineImagesEdgeZoneClientGetResponse, error) { + var err error + const operationName = "VirtualMachineImagesEdgeZoneClient.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, location, edgeZone, publisherName, offer, skus, version, options) if err != nil { return VirtualMachineImagesEdgeZoneClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesEdgeZoneClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesEdgeZoneClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesEdgeZoneClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -136,18 +142,25 @@ func (client *VirtualMachineImagesEdgeZoneClient) getHandleResponse(resp *http.R // - options - VirtualMachineImagesEdgeZoneClientListOptions contains the optional parameters for the VirtualMachineImagesEdgeZoneClient.List // method. func (client *VirtualMachineImagesEdgeZoneClient) List(ctx context.Context, location string, edgeZone string, publisherName string, offer string, skus string, options *VirtualMachineImagesEdgeZoneClientListOptions) (VirtualMachineImagesEdgeZoneClientListResponse, error) { + var err error + const operationName = "VirtualMachineImagesEdgeZoneClient.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, location, edgeZone, publisherName, offer, skus, options) if err != nil { return VirtualMachineImagesEdgeZoneClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesEdgeZoneClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesEdgeZoneClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesEdgeZoneClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -216,18 +229,25 @@ func (client *VirtualMachineImagesEdgeZoneClient) listHandleResponse(resp *http. // - options - VirtualMachineImagesEdgeZoneClientListOffersOptions contains the optional parameters for the VirtualMachineImagesEdgeZoneClient.ListOffers // method. func (client *VirtualMachineImagesEdgeZoneClient) ListOffers(ctx context.Context, location string, edgeZone string, publisherName string, options *VirtualMachineImagesEdgeZoneClientListOffersOptions) (VirtualMachineImagesEdgeZoneClientListOffersResponse, error) { + var err error + const operationName = "VirtualMachineImagesEdgeZoneClient.ListOffers" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listOffersCreateRequest(ctx, location, edgeZone, publisherName, options) if err != nil { return VirtualMachineImagesEdgeZoneClientListOffersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesEdgeZoneClientListOffersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesEdgeZoneClientListOffersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesEdgeZoneClientListOffersResponse{}, err } - return client.listOffersHandleResponse(resp) + resp, err := client.listOffersHandleResponse(httpResp) + return resp, err } // listOffersCreateRequest creates the ListOffers request. @@ -278,18 +298,25 @@ func (client *VirtualMachineImagesEdgeZoneClient) listOffersHandleResponse(resp // - options - VirtualMachineImagesEdgeZoneClientListPublishersOptions contains the optional parameters for the VirtualMachineImagesEdgeZoneClient.ListPublishers // method. func (client *VirtualMachineImagesEdgeZoneClient) ListPublishers(ctx context.Context, location string, edgeZone string, options *VirtualMachineImagesEdgeZoneClientListPublishersOptions) (VirtualMachineImagesEdgeZoneClientListPublishersResponse, error) { + var err error + const operationName = "VirtualMachineImagesEdgeZoneClient.ListPublishers" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listPublishersCreateRequest(ctx, location, edgeZone, options) if err != nil { return VirtualMachineImagesEdgeZoneClientListPublishersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesEdgeZoneClientListPublishersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesEdgeZoneClientListPublishersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesEdgeZoneClientListPublishersResponse{}, err } - return client.listPublishersHandleResponse(resp) + resp, err := client.listPublishersHandleResponse(httpResp) + return resp, err } // listPublishersCreateRequest creates the ListPublishers request. @@ -338,18 +365,25 @@ func (client *VirtualMachineImagesEdgeZoneClient) listPublishersHandleResponse(r // - options - VirtualMachineImagesEdgeZoneClientListSKUsOptions contains the optional parameters for the VirtualMachineImagesEdgeZoneClient.ListSKUs // method. func (client *VirtualMachineImagesEdgeZoneClient) ListSKUs(ctx context.Context, location string, edgeZone string, publisherName string, offer string, options *VirtualMachineImagesEdgeZoneClientListSKUsOptions) (VirtualMachineImagesEdgeZoneClientListSKUsResponse, error) { + var err error + const operationName = "VirtualMachineImagesEdgeZoneClient.ListSKUs" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listSKUsCreateRequest(ctx, location, edgeZone, publisherName, offer, options) if err != nil { return VirtualMachineImagesEdgeZoneClientListSKUsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineImagesEdgeZoneClientListSKUsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineImagesEdgeZoneClientListSKUsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineImagesEdgeZoneClientListSKUsResponse{}, err } - return client.listSKUsHandleResponse(resp) + resp, err := client.listSKUsHandleResponse(httpResp) + return resp, err } // listSKUsCreateRequest creates the ListSKUs request. diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineruncommands_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachineruncommands_client.go index 1e1c9e9172d2..7b205149ec36 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachineruncommands_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineruncommands_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 armcompute @@ -61,7 +60,8 @@ func (client *VirtualMachineRunCommandsClient) BeginCreateOrUpdate(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineRunCommandsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineRunCommandsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineRunCommandsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *VirtualMachineRunCommandsClient) BeginCreateOrUpdate(ctx context.C // // Generated from API version 2023-03-01 func (client *VirtualMachineRunCommandsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, runCommand VirtualMachineRunCommand, options *VirtualMachineRunCommandsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineRunCommandsClient.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, vmName, runCommandName, runCommand, 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. @@ -113,7 +119,10 @@ func (client *VirtualMachineRunCommandsClient) createOrUpdateCreateRequest(ctx c reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json, text/json"} - return req, runtime.MarshalAsJSON(req, runCommand) + if err := runtime.MarshalAsJSON(req, runCommand); err != nil { + return nil, err + } + return req, nil } // BeginDelete - The operation to delete the run command. @@ -131,7 +140,8 @@ func (client *VirtualMachineRunCommandsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineRunCommandsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineRunCommandsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineRunCommandsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *VirtualMachineRunCommandsClient) BeginDelete(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineRunCommandsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, options *VirtualMachineRunCommandsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineRunCommandsClient.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, vmName, runCommandName, 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. @@ -195,18 +211,25 @@ func (client *VirtualMachineRunCommandsClient) deleteCreateRequest(ctx context.C // - options - VirtualMachineRunCommandsClientGetOptions contains the optional parameters for the VirtualMachineRunCommandsClient.Get // method. func (client *VirtualMachineRunCommandsClient) Get(ctx context.Context, location string, commandID string, options *VirtualMachineRunCommandsClientGetOptions) (VirtualMachineRunCommandsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineRunCommandsClient.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, location, commandID, options) if err != nil { return VirtualMachineRunCommandsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineRunCommandsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineRunCommandsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineRunCommandsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -254,18 +277,25 @@ func (client *VirtualMachineRunCommandsClient) getHandleResponse(resp *http.Resp // - options - VirtualMachineRunCommandsClientGetByVirtualMachineOptions contains the optional parameters for the VirtualMachineRunCommandsClient.GetByVirtualMachine // method. func (client *VirtualMachineRunCommandsClient) GetByVirtualMachine(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, options *VirtualMachineRunCommandsClientGetByVirtualMachineOptions) (VirtualMachineRunCommandsClientGetByVirtualMachineResponse, error) { + var err error + const operationName = "VirtualMachineRunCommandsClient.GetByVirtualMachine" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByVirtualMachineCreateRequest(ctx, resourceGroupName, vmName, runCommandName, options) if err != nil { return VirtualMachineRunCommandsClientGetByVirtualMachineResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineRunCommandsClientGetByVirtualMachineResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineRunCommandsClientGetByVirtualMachineResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineRunCommandsClientGetByVirtualMachineResponse{}, err } - return client.getByVirtualMachineHandleResponse(resp) + resp, err := client.getByVirtualMachineHandleResponse(httpResp) + return resp, err } // getByVirtualMachineCreateRequest creates the GetByVirtualMachine request. @@ -322,6 +352,7 @@ func (client *VirtualMachineRunCommandsClient) NewListPager(location string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineRunCommandsClientListResponse) (VirtualMachineRunCommandsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineRunCommandsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -341,6 +372,7 @@ func (client *VirtualMachineRunCommandsClient) NewListPager(location string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -388,6 +420,7 @@ func (client *VirtualMachineRunCommandsClient) NewListByVirtualMachinePager(reso return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineRunCommandsClientListByVirtualMachineResponse) (VirtualMachineRunCommandsClientListByVirtualMachineResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineRunCommandsClient.NewListByVirtualMachinePager") var req *policy.Request var err error if page == nil { @@ -407,6 +440,7 @@ func (client *VirtualMachineRunCommandsClient) NewListByVirtualMachinePager(reso } return client.listByVirtualMachineHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -464,7 +498,8 @@ func (client *VirtualMachineRunCommandsClient) BeginUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineRunCommandsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineRunCommandsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineRunCommandsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -475,18 +510,24 @@ func (client *VirtualMachineRunCommandsClient) BeginUpdate(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineRunCommandsClient) update(ctx context.Context, resourceGroupName string, vmName string, runCommandName string, runCommand VirtualMachineRunCommandUpdate, options *VirtualMachineRunCommandsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineRunCommandsClient.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, vmName, runCommandName, runCommand, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -516,5 +557,8 @@ func (client *VirtualMachineRunCommandsClient) updateCreateRequest(ctx context.C reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json, text/json"} - return req, runtime.MarshalAsJSON(req, runCommand) + if err := runtime.MarshalAsJSON(req, runCommand); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachines_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachines_client.go index ee8f928570c3..f085731997cf 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachines_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachines_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 armcompute @@ -60,9 +59,10 @@ func (client *VirtualMachinesClient) BeginAssessPatches(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientAssessPatchesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientAssessPatchesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientAssessPatchesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualMachinesClient) BeginAssessPatches(ctx context.Context, res // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) assessPatches(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginAssessPatchesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginAssessPatches" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.assessPatchesCreateRequest(ctx, resourceGroupName, vmName, 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 } // assessPatchesCreateRequest creates the AssessPatches request. @@ -129,9 +135,10 @@ func (client *VirtualMachinesClient) BeginCapture(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -143,18 +150,24 @@ func (client *VirtualMachinesClient) BeginCapture(ctx context.Context, resourceG // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) capture(ctx context.Context, resourceGroupName string, vmName string, parameters VirtualMachineCaptureParameters, options *VirtualMachinesClientBeginCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.captureCreateRequest(ctx, resourceGroupName, vmName, 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 } // captureCreateRequest creates the Capture request. @@ -180,7 +193,10 @@ func (client *VirtualMachinesClient) captureCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2023-03-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 } // BeginConvertToManagedDisks - Converts virtual machine disks from blob-based to managed disks. Virtual machine must be stop-deallocated @@ -198,7 +214,8 @@ func (client *VirtualMachinesClient) BeginConvertToManagedDisks(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientConvertToManagedDisksResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientConvertToManagedDisksResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientConvertToManagedDisksResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -210,18 +227,24 @@ func (client *VirtualMachinesClient) BeginConvertToManagedDisks(ctx context.Cont // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) convertToManagedDisks(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginConvertToManagedDisksOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginConvertToManagedDisks" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.convertToManagedDisksCreateRequest(ctx, resourceGroupName, vmName, 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 } // convertToManagedDisksCreateRequest creates the ConvertToManagedDisks request. @@ -266,7 +289,8 @@ func (client *VirtualMachinesClient) BeginCreateOrUpdate(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -278,18 +302,24 @@ func (client *VirtualMachinesClient) BeginCreateOrUpdate(ctx context.Context, re // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmName string, parameters VirtualMachine, options *VirtualMachinesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.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, vmName, 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. @@ -315,7 +345,10 @@ func (client *VirtualMachinesClient) createOrUpdateCreateRequest(ctx context.Con reqQP.Set("api-version", "2023-03-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 } // BeginDeallocate - Shuts down the virtual machine and releases the compute resources. You are not billed for the compute @@ -333,7 +366,8 @@ func (client *VirtualMachinesClient) BeginDeallocate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientDeallocateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientDeallocateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientDeallocateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -345,18 +379,24 @@ func (client *VirtualMachinesClient) BeginDeallocate(ctx context.Context, resour // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) deallocate(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginDeallocateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginDeallocate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deallocateCreateRequest(ctx, resourceGroupName, vmName, 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 } // deallocateCreateRequest creates the Deallocate request. @@ -402,7 +442,8 @@ func (client *VirtualMachinesClient) BeginDelete(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -413,18 +454,24 @@ func (client *VirtualMachinesClient) BeginDelete(ctx context.Context, resourceGr // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) deleteOperation(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.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, vmName, 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. @@ -469,16 +516,22 @@ func (client *VirtualMachinesClient) deleteCreateRequest(ctx context.Context, re // - options - VirtualMachinesClientGeneralizeOptions contains the optional parameters for the VirtualMachinesClient.Generalize // method. func (client *VirtualMachinesClient) Generalize(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientGeneralizeOptions) (VirtualMachinesClientGeneralizeResponse, error) { + var err error + const operationName = "VirtualMachinesClient.Generalize" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generalizeCreateRequest(ctx, resourceGroupName, vmName, options) if err != nil { return VirtualMachinesClientGeneralizeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachinesClientGeneralizeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachinesClientGeneralizeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachinesClientGeneralizeResponse{}, err } return VirtualMachinesClientGeneralizeResponse{}, nil } @@ -517,18 +570,25 @@ func (client *VirtualMachinesClient) generalizeCreateRequest(ctx context.Context // - vmName - The name of the virtual machine. // - options - VirtualMachinesClientGetOptions contains the optional parameters for the VirtualMachinesClient.Get method. func (client *VirtualMachinesClient) Get(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientGetOptions) (VirtualMachinesClientGetResponse, error) { + var err error + const operationName = "VirtualMachinesClient.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, vmName, options) if err != nil { return VirtualMachinesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachinesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachinesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachinesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -584,9 +644,10 @@ func (client *VirtualMachinesClient) BeginInstallPatches(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientInstallPatchesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientInstallPatchesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientInstallPatchesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -597,18 +658,24 @@ func (client *VirtualMachinesClient) BeginInstallPatches(ctx context.Context, re // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) installPatches(ctx context.Context, resourceGroupName string, vmName string, installPatchesInput VirtualMachineInstallPatchesParameters, options *VirtualMachinesClientBeginInstallPatchesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginInstallPatches" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.installPatchesCreateRequest(ctx, resourceGroupName, vmName, installPatchesInput, 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 } // installPatchesCreateRequest creates the InstallPatches request. @@ -634,7 +701,10 @@ func (client *VirtualMachinesClient) installPatchesCreateRequest(ctx context.Con reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, installPatchesInput) + if err := runtime.MarshalAsJSON(req, installPatchesInput); err != nil { + return nil, err + } + return req, nil } // InstanceView - Retrieves information about the run-time state of a virtual machine. @@ -646,18 +716,25 @@ func (client *VirtualMachinesClient) installPatchesCreateRequest(ctx context.Con // - options - VirtualMachinesClientInstanceViewOptions contains the optional parameters for the VirtualMachinesClient.InstanceView // method. func (client *VirtualMachinesClient) InstanceView(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientInstanceViewOptions) (VirtualMachinesClientInstanceViewResponse, error) { + var err error + const operationName = "VirtualMachinesClient.InstanceView" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.instanceViewCreateRequest(ctx, resourceGroupName, vmName, options) if err != nil { return VirtualMachinesClientInstanceViewResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachinesClientInstanceViewResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachinesClientInstanceViewResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachinesClientInstanceViewResponse{}, err } - return client.instanceViewHandleResponse(resp) + resp, err := client.instanceViewHandleResponse(httpResp) + return resp, err } // instanceViewCreateRequest creates the InstanceView request. @@ -708,6 +785,7 @@ func (client *VirtualMachinesClient) NewListPager(resourceGroupName string, opti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachinesClientListResponse) (VirtualMachinesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachinesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -727,6 +805,7 @@ func (client *VirtualMachinesClient) NewListPager(resourceGroupName string, opti } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -779,6 +858,7 @@ func (client *VirtualMachinesClient) NewListAllPager(options *VirtualMachinesCli return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachinesClientListAllResponse) (VirtualMachinesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachinesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -798,6 +878,7 @@ func (client *VirtualMachinesClient) NewListAllPager(options *VirtualMachinesCli } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -850,6 +931,7 @@ func (client *VirtualMachinesClient) NewListAvailableSizesPager(resourceGroupNam return false }, Fetcher: func(ctx context.Context, page *VirtualMachinesClientListAvailableSizesResponse) (VirtualMachinesClientListAvailableSizesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachinesClient.NewListAvailableSizesPager") req, err := client.listAvailableSizesCreateRequest(ctx, resourceGroupName, vmName, options) if err != nil { return VirtualMachinesClientListAvailableSizesResponse{}, err @@ -863,6 +945,7 @@ func (client *VirtualMachinesClient) NewListAvailableSizesPager(resourceGroupNam } return client.listAvailableSizesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -913,6 +996,7 @@ func (client *VirtualMachinesClient) NewListByLocationPager(location string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachinesClientListByLocationResponse) (VirtualMachinesClientListByLocationResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachinesClient.NewListByLocationPager") var req *policy.Request var err error if page == nil { @@ -932,6 +1016,7 @@ func (client *VirtualMachinesClient) NewListByLocationPager(location string, opt } return client.listByLocationHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -980,7 +1065,8 @@ func (client *VirtualMachinesClient) BeginPerformMaintenance(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientPerformMaintenanceResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientPerformMaintenanceResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientPerformMaintenanceResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -991,18 +1077,24 @@ func (client *VirtualMachinesClient) BeginPerformMaintenance(ctx context.Context // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) performMaintenance(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginPerformMaintenanceOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginPerformMaintenance" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.performMaintenanceCreateRequest(ctx, resourceGroupName, vmName, 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 } // performMaintenanceCreateRequest creates the PerformMaintenance request. @@ -1046,7 +1138,8 @@ func (client *VirtualMachinesClient) BeginPowerOff(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientPowerOffResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1058,18 +1151,24 @@ func (client *VirtualMachinesClient) BeginPowerOff(ctx context.Context, resource // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) powerOff(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginPowerOffOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginPowerOff" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.powerOffCreateRequest(ctx, resourceGroupName, vmName, 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 } // powerOffCreateRequest creates the PowerOff request. @@ -1115,7 +1214,8 @@ func (client *VirtualMachinesClient) BeginReapply(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientReapplyResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientReapplyResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientReapplyResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1126,18 +1226,24 @@ func (client *VirtualMachinesClient) BeginReapply(ctx context.Context, resourceG // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) reapply(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginReapplyOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginReapply" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reapplyCreateRequest(ctx, resourceGroupName, vmName, 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 } // reapplyCreateRequest creates the Reapply request. @@ -1180,7 +1286,8 @@ func (client *VirtualMachinesClient) BeginRedeploy(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientRedeployResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientRedeployResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientRedeployResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1191,18 +1298,24 @@ func (client *VirtualMachinesClient) BeginRedeploy(ctx context.Context, resource // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) redeploy(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginRedeployOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginRedeploy" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.redeployCreateRequest(ctx, resourceGroupName, vmName, 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 } // redeployCreateRequest creates the Redeploy request. @@ -1249,7 +1362,8 @@ func (client *VirtualMachinesClient) BeginReimage(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientReimageResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientReimageResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientReimageResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1264,18 +1378,24 @@ func (client *VirtualMachinesClient) BeginReimage(ctx context.Context, resourceG // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) reimage(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginReimageOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginReimage" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageCreateRequest(ctx, resourceGroupName, vmName, 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 } // reimageCreateRequest creates the Reimage request. @@ -1302,7 +1422,10 @@ func (client *VirtualMachinesClient) reimageCreateRequest(ctx context.Context, r req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1321,7 +1444,8 @@ func (client *VirtualMachinesClient) BeginRestart(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientRestartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientRestartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1332,18 +1456,24 @@ func (client *VirtualMachinesClient) BeginRestart(ctx context.Context, resourceG // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) restart(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginRestartOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginRestart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.restartCreateRequest(ctx, resourceGroupName, vmName, 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 } // restartCreateRequest creates the Restart request. @@ -1381,18 +1511,25 @@ func (client *VirtualMachinesClient) restartCreateRequest(ctx context.Context, r // - options - VirtualMachinesClientRetrieveBootDiagnosticsDataOptions contains the optional parameters for the VirtualMachinesClient.RetrieveBootDiagnosticsData // method. func (client *VirtualMachinesClient) RetrieveBootDiagnosticsData(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientRetrieveBootDiagnosticsDataOptions) (VirtualMachinesClientRetrieveBootDiagnosticsDataResponse, error) { + var err error + const operationName = "VirtualMachinesClient.RetrieveBootDiagnosticsData" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.retrieveBootDiagnosticsDataCreateRequest(ctx, resourceGroupName, vmName, options) if err != nil { return VirtualMachinesClientRetrieveBootDiagnosticsDataResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachinesClientRetrieveBootDiagnosticsDataResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachinesClientRetrieveBootDiagnosticsDataResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachinesClientRetrieveBootDiagnosticsDataResponse{}, err } - return client.retrieveBootDiagnosticsDataHandleResponse(resp) + resp, err := client.retrieveBootDiagnosticsDataHandleResponse(httpResp) + return resp, err } // retrieveBootDiagnosticsDataCreateRequest creates the RetrieveBootDiagnosticsData request. @@ -1448,9 +1585,10 @@ func (client *VirtualMachinesClient) BeginRunCommand(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientRunCommandResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachinesClientRunCommandResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientRunCommandResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1461,18 +1599,24 @@ func (client *VirtualMachinesClient) BeginRunCommand(ctx context.Context, resour // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) runCommand(ctx context.Context, resourceGroupName string, vmName string, parameters RunCommandInput, options *VirtualMachinesClientBeginRunCommandOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginRunCommand" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.runCommandCreateRequest(ctx, resourceGroupName, vmName, 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 } // runCommandCreateRequest creates the RunCommand request. @@ -1498,7 +1642,10 @@ func (client *VirtualMachinesClient) runCommandCreateRequest(ctx context.Context reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json, text/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // SimulateEviction - The operation to simulate the eviction of spot virtual machine. @@ -1510,16 +1657,22 @@ func (client *VirtualMachinesClient) runCommandCreateRequest(ctx context.Context // - options - VirtualMachinesClientSimulateEvictionOptions contains the optional parameters for the VirtualMachinesClient.SimulateEviction // method. func (client *VirtualMachinesClient) SimulateEviction(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientSimulateEvictionOptions) (VirtualMachinesClientSimulateEvictionResponse, error) { + var err error + const operationName = "VirtualMachinesClient.SimulateEviction" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.simulateEvictionCreateRequest(ctx, resourceGroupName, vmName, options) if err != nil { return VirtualMachinesClientSimulateEvictionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachinesClientSimulateEvictionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return VirtualMachinesClientSimulateEvictionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return VirtualMachinesClientSimulateEvictionResponse{}, err } return VirtualMachinesClientSimulateEvictionResponse{}, nil } @@ -1564,7 +1717,8 @@ func (client *VirtualMachinesClient) BeginStart(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientStartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientStartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1575,18 +1729,24 @@ func (client *VirtualMachinesClient) BeginStart(ctx context.Context, resourceGro // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) start(ctx context.Context, resourceGroupName string, vmName string, options *VirtualMachinesClientBeginStartOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.BeginStart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startCreateRequest(ctx, resourceGroupName, vmName, 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 } // startCreateRequest creates the Start request. @@ -1630,7 +1790,8 @@ func (client *VirtualMachinesClient) BeginUpdate(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachinesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachinesClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachinesClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1641,18 +1802,24 @@ func (client *VirtualMachinesClient) BeginUpdate(ctx context.Context, resourceGr // // Generated from API version 2023-03-01 func (client *VirtualMachinesClient) update(ctx context.Context, resourceGroupName string, vmName string, parameters VirtualMachineUpdate, options *VirtualMachinesClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachinesClient.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, vmName, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -1678,5 +1845,8 @@ func (client *VirtualMachinesClient) updateCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2023-03-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/compute/armcompute/virtualmachinescalesetextensions_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetextensions_client.go index 53149b8ee22f..8923d16a6bfe 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetextensions_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetextensions_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 armcompute @@ -61,7 +60,8 @@ func (client *VirtualMachineScaleSetExtensionsClient) BeginCreateOrUpdate(ctx co if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetExtensionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetExtensionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetExtensionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *VirtualMachineScaleSetExtensionsClient) BeginCreateOrUpdate(ctx co // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetExtensionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, extensionParameters VirtualMachineScaleSetExtension, options *VirtualMachineScaleSetExtensionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetExtensionsClient.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, vmScaleSetName, vmssExtensionName, extensionParameters, 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. @@ -113,7 +119,10 @@ func (client *VirtualMachineScaleSetExtensionsClient) createOrUpdateCreateReques reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, extensionParameters) + if err := runtime.MarshalAsJSON(req, extensionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - The operation to delete the extension. @@ -131,7 +140,8 @@ func (client *VirtualMachineScaleSetExtensionsClient) BeginDelete(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetExtensionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetExtensionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetExtensionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *VirtualMachineScaleSetExtensionsClient) BeginDelete(ctx context.Co // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetExtensionsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, options *VirtualMachineScaleSetExtensionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetExtensionsClient.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, vmScaleSetName, vmssExtensionName, 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. @@ -196,18 +212,25 @@ func (client *VirtualMachineScaleSetExtensionsClient) deleteCreateRequest(ctx co // - options - VirtualMachineScaleSetExtensionsClientGetOptions contains the optional parameters for the VirtualMachineScaleSetExtensionsClient.Get // method. func (client *VirtualMachineScaleSetExtensionsClient) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, options *VirtualMachineScaleSetExtensionsClientGetOptions) (VirtualMachineScaleSetExtensionsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetExtensionsClient.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, vmScaleSetName, vmssExtensionName, options) if err != nil { return VirtualMachineScaleSetExtensionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetExtensionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetExtensionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetExtensionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -265,6 +288,7 @@ func (client *VirtualMachineScaleSetExtensionsClient) NewListPager(resourceGroup return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetExtensionsClientListResponse) (VirtualMachineScaleSetExtensionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetExtensionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -284,6 +308,7 @@ func (client *VirtualMachineScaleSetExtensionsClient) NewListPager(resourceGroup } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -338,7 +363,8 @@ func (client *VirtualMachineScaleSetExtensionsClient) BeginUpdate(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetExtensionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetExtensionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetExtensionsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -349,18 +375,24 @@ func (client *VirtualMachineScaleSetExtensionsClient) BeginUpdate(ctx context.Co // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetExtensionsClient) update(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmssExtensionName string, extensionParameters VirtualMachineScaleSetExtensionUpdate, options *VirtualMachineScaleSetExtensionsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetExtensionsClient.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, vmScaleSetName, vmssExtensionName, extensionParameters, 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 } // updateCreateRequest creates the Update request. @@ -390,5 +422,8 @@ func (client *VirtualMachineScaleSetExtensionsClient) updateCreateRequest(ctx co reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, extensionParameters) + if err := runtime.MarshalAsJSON(req, extensionParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetrollingupgrades_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetrollingupgrades_client.go index b8ff0d8acc4d..e9d6cb4d1edc 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetrollingupgrades_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetrollingupgrades_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 armcompute @@ -59,7 +58,8 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) BeginCancel(ctx conte if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetRollingUpgradesClientCancelResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetRollingUpgradesClientCancelResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetRollingUpgradesClientCancelResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -70,18 +70,24 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) BeginCancel(ctx conte // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetRollingUpgradesClient) cancel(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetRollingUpgradesClientBeginCancelOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetRollingUpgradesClient.BeginCancel" + 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, vmScaleSetName, 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 } // cancelCreateRequest creates the Cancel request. @@ -119,18 +125,25 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) cancelCreateRequest(c // - options - VirtualMachineScaleSetRollingUpgradesClientGetLatestOptions contains the optional parameters for the VirtualMachineScaleSetRollingUpgradesClient.GetLatest // method. func (client *VirtualMachineScaleSetRollingUpgradesClient) GetLatest(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetRollingUpgradesClientGetLatestOptions) (VirtualMachineScaleSetRollingUpgradesClientGetLatestResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetRollingUpgradesClient.GetLatest" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getLatestCreateRequest(ctx, resourceGroupName, vmScaleSetName, options) if err != nil { return VirtualMachineScaleSetRollingUpgradesClientGetLatestResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetRollingUpgradesClientGetLatestResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetRollingUpgradesClientGetLatestResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetRollingUpgradesClientGetLatestResponse{}, err } - return client.getLatestHandleResponse(resp) + resp, err := client.getLatestHandleResponse(httpResp) + return resp, err } // getLatestCreateRequest creates the GetLatest request. @@ -184,7 +197,8 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) BeginStartExtensionUp if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetRollingUpgradesClientStartExtensionUpgradeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetRollingUpgradesClientStartExtensionUpgradeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetRollingUpgradesClientStartExtensionUpgradeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -197,18 +211,24 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) BeginStartExtensionUp // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetRollingUpgradesClient) startExtensionUpgrade(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetRollingUpgradesClientBeginStartExtensionUpgradeOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetRollingUpgradesClient.BeginStartExtensionUpgrade" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startExtensionUpgradeCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // startExtensionUpgradeCreateRequest creates the StartExtensionUpgrade request. @@ -253,7 +273,8 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) BeginStartOSUpgrade(c if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetRollingUpgradesClientStartOSUpgradeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetRollingUpgradesClientStartOSUpgradeResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetRollingUpgradesClientStartOSUpgradeResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -266,18 +287,24 @@ func (client *VirtualMachineScaleSetRollingUpgradesClient) BeginStartOSUpgrade(c // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetRollingUpgradesClient) startOSUpgrade(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetRollingUpgradesClientBeginStartOSUpgradeOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetRollingUpgradesClient.BeginStartOSUpgrade" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startOSUpgradeCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // startOSUpgradeCreateRequest creates the StartOSUpgrade request. diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client.go index f42db6472d32..2d99c86bf93b 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_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 armcompute @@ -56,16 +55,22 @@ func NewVirtualMachineScaleSetsClient(subscriptionID string, credential azcore.T // - options - VirtualMachineScaleSetsClientConvertToSinglePlacementGroupOptions contains the optional parameters for the VirtualMachineScaleSetsClient.ConvertToSinglePlacementGroup // method. func (client *VirtualMachineScaleSetsClient) ConvertToSinglePlacementGroup(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters VMScaleSetConvertToSinglePlacementGroupInput, options *VirtualMachineScaleSetsClientConvertToSinglePlacementGroupOptions) (VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.ConvertToSinglePlacementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.convertToSinglePlacementGroupCreateRequest(ctx, resourceGroupName, vmScaleSetName, parameters, options) if err != nil { return VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse{}, err } return VirtualMachineScaleSetsClientConvertToSinglePlacementGroupResponse{}, nil } @@ -93,7 +98,10 @@ func (client *VirtualMachineScaleSetsClient) convertToSinglePlacementGroupCreate reqQP.Set("api-version", "2023-03-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 } // BeginCreateOrUpdate - Create or update a VM scale set. @@ -111,7 +119,8 @@ func (client *VirtualMachineScaleSetsClient) BeginCreateOrUpdate(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -122,18 +131,24 @@ func (client *VirtualMachineScaleSetsClient) BeginCreateOrUpdate(ctx context.Con // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters VirtualMachineScaleSet, options *VirtualMachineScaleSetsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.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, vmScaleSetName, 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. @@ -159,7 +174,10 @@ func (client *VirtualMachineScaleSetsClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2023-03-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 } // BeginDeallocate - Deallocates specific virtual machines in a VM scale set. Shuts down the virtual machines and releases @@ -178,7 +196,8 @@ func (client *VirtualMachineScaleSetsClient) BeginDeallocate(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientDeallocateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientDeallocateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientDeallocateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -191,18 +210,24 @@ func (client *VirtualMachineScaleSetsClient) BeginDeallocate(ctx context.Context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) deallocate(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginDeallocateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginDeallocate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deallocateCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // deallocateCreateRequest creates the Deallocate request. @@ -232,7 +257,10 @@ func (client *VirtualMachineScaleSetsClient) deallocateCreateRequest(ctx context req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -251,7 +279,8 @@ func (client *VirtualMachineScaleSetsClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -262,18 +291,24 @@ func (client *VirtualMachineScaleSetsClient) BeginDelete(ctx context.Context, re // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.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, vmScaleSetName, 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. @@ -320,7 +355,8 @@ func (client *VirtualMachineScaleSetsClient) BeginDeleteInstances(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientDeleteInstancesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientDeleteInstancesResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientDeleteInstancesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -331,18 +367,24 @@ func (client *VirtualMachineScaleSetsClient) BeginDeleteInstances(ctx context.Co // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) deleteInstances(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmInstanceIDs VirtualMachineScaleSetVMInstanceRequiredIDs, options *VirtualMachineScaleSetsClientBeginDeleteInstancesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginDeleteInstances" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteInstancesCreateRequest(ctx, resourceGroupName, vmScaleSetName, vmInstanceIDs, 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 } // deleteInstancesCreateRequest creates the DeleteInstances request. @@ -371,7 +413,10 @@ func (client *VirtualMachineScaleSetsClient) deleteInstancesCreateRequest(ctx co reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vmInstanceIDs) + if err := runtime.MarshalAsJSON(req, vmInstanceIDs); err != nil { + return nil, err + } + return req, nil } // ForceRecoveryServiceFabricPlatformUpdateDomainWalk - Manual platform update domain walk to update virtual machines in a @@ -385,18 +430,25 @@ func (client *VirtualMachineScaleSetsClient) deleteInstancesCreateRequest(ctx co // - options - VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions contains the optional // parameters for the VirtualMachineScaleSetsClient.ForceRecoveryServiceFabricPlatformUpdateDomainWalk method. func (client *VirtualMachineScaleSetsClient) ForceRecoveryServiceFabricPlatformUpdateDomainWalk(ctx context.Context, resourceGroupName string, vmScaleSetName string, platformUpdateDomain int32, options *VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions) (VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.ForceRecoveryServiceFabricPlatformUpdateDomainWalk" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.forceRecoveryServiceFabricPlatformUpdateDomainWalkCreateRequest(ctx, resourceGroupName, vmScaleSetName, platformUpdateDomain, options) if err != nil { return VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkResponse{}, err } - return client.forceRecoveryServiceFabricPlatformUpdateDomainWalkHandleResponse(resp) + resp, err := client.forceRecoveryServiceFabricPlatformUpdateDomainWalkHandleResponse(httpResp) + return resp, err } // forceRecoveryServiceFabricPlatformUpdateDomainWalkCreateRequest creates the ForceRecoveryServiceFabricPlatformUpdateDomainWalk request. @@ -450,18 +502,25 @@ func (client *VirtualMachineScaleSetsClient) forceRecoveryServiceFabricPlatformU // - options - VirtualMachineScaleSetsClientGetOptions contains the optional parameters for the VirtualMachineScaleSetsClient.Get // method. func (client *VirtualMachineScaleSetsClient) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientGetOptions) (VirtualMachineScaleSetsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.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, vmScaleSetName, options) if err != nil { return VirtualMachineScaleSetsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -511,18 +570,25 @@ func (client *VirtualMachineScaleSetsClient) getHandleResponse(resp *http.Respon // - options - VirtualMachineScaleSetsClientGetInstanceViewOptions contains the optional parameters for the VirtualMachineScaleSetsClient.GetInstanceView // method. func (client *VirtualMachineScaleSetsClient) GetInstanceView(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientGetInstanceViewOptions) (VirtualMachineScaleSetsClientGetInstanceViewResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.GetInstanceView" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getInstanceViewCreateRequest(ctx, resourceGroupName, vmScaleSetName, options) if err != nil { return VirtualMachineScaleSetsClientGetInstanceViewResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetsClientGetInstanceViewResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetsClientGetInstanceViewResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetsClientGetInstanceViewResponse{}, err } - return client.getInstanceViewHandleResponse(resp) + resp, err := client.getInstanceViewHandleResponse(httpResp) + return resp, err } // getInstanceViewCreateRequest creates the GetInstanceView request. @@ -573,6 +639,7 @@ func (client *VirtualMachineScaleSetsClient) NewGetOSUpgradeHistoryPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetsClientGetOSUpgradeHistoryResponse) (VirtualMachineScaleSetsClientGetOSUpgradeHistoryResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetsClient.NewGetOSUpgradeHistoryPager") var req *policy.Request var err error if page == nil { @@ -592,6 +659,7 @@ func (client *VirtualMachineScaleSetsClient) NewGetOSUpgradeHistoryPager(resourc } return client.getOSUpgradeHistoryHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -642,6 +710,7 @@ func (client *VirtualMachineScaleSetsClient) NewListPager(resourceGroupName stri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetsClientListResponse) (VirtualMachineScaleSetsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -661,6 +730,7 @@ func (client *VirtualMachineScaleSetsClient) NewListPager(resourceGroupName stri } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -708,6 +778,7 @@ func (client *VirtualMachineScaleSetsClient) NewListAllPager(options *VirtualMac return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetsClientListAllResponse) (VirtualMachineScaleSetsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -727,6 +798,7 @@ func (client *VirtualMachineScaleSetsClient) NewListAllPager(options *VirtualMac } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -769,6 +841,7 @@ func (client *VirtualMachineScaleSetsClient) NewListByLocationPager(location str return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetsClientListByLocationResponse) (VirtualMachineScaleSetsClientListByLocationResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetsClient.NewListByLocationPager") var req *policy.Request var err error if page == nil { @@ -788,6 +861,7 @@ func (client *VirtualMachineScaleSetsClient) NewListByLocationPager(location str } return client.listByLocationHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -836,6 +910,7 @@ func (client *VirtualMachineScaleSetsClient) NewListSKUsPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetsClientListSKUsResponse) (VirtualMachineScaleSetsClientListSKUsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetsClient.NewListSKUsPager") var req *policy.Request var err error if page == nil { @@ -855,6 +930,7 @@ func (client *VirtualMachineScaleSetsClient) NewListSKUsPager(resourceGroupName } return client.listSKUsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -909,7 +985,8 @@ func (client *VirtualMachineScaleSetsClient) BeginPerformMaintenance(ctx context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientPerformMaintenanceResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientPerformMaintenanceResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientPerformMaintenanceResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -922,18 +999,24 @@ func (client *VirtualMachineScaleSetsClient) BeginPerformMaintenance(ctx context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) performMaintenance(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginPerformMaintenanceOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginPerformMaintenance" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.performMaintenanceCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // performMaintenanceCreateRequest creates the PerformMaintenance request. @@ -960,7 +1043,10 @@ func (client *VirtualMachineScaleSetsClient) performMaintenanceCreateRequest(ctx req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -981,7 +1067,8 @@ func (client *VirtualMachineScaleSetsClient) BeginPowerOff(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientPowerOffResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -994,18 +1081,24 @@ func (client *VirtualMachineScaleSetsClient) BeginPowerOff(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) powerOff(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginPowerOffOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginPowerOff" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.powerOffCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // powerOffCreateRequest creates the PowerOff request. @@ -1035,7 +1128,10 @@ func (client *VirtualMachineScaleSetsClient) powerOffCreateRequest(ctx context.C req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1054,9 +1150,10 @@ func (client *VirtualMachineScaleSetsClient) BeginReapply(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachineScaleSetsClientReapplyResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachineScaleSetsClientReapplyResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientReapplyResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1067,18 +1164,24 @@ func (client *VirtualMachineScaleSetsClient) BeginReapply(ctx context.Context, r // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) reapply(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginReapplyOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginReapply" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reapplyCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // reapplyCreateRequest creates the Reapply request. @@ -1122,7 +1225,8 @@ func (client *VirtualMachineScaleSetsClient) BeginRedeploy(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientRedeployResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientRedeployResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientRedeployResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1134,18 +1238,24 @@ func (client *VirtualMachineScaleSetsClient) BeginRedeploy(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) redeploy(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginRedeployOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginRedeploy" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.redeployCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // redeployCreateRequest creates the Redeploy request. @@ -1172,7 +1282,10 @@ func (client *VirtualMachineScaleSetsClient) redeployCreateRequest(ctx context.C req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1193,7 +1306,8 @@ func (client *VirtualMachineScaleSetsClient) BeginReimage(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientReimageResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientReimageResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientReimageResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1206,18 +1320,24 @@ func (client *VirtualMachineScaleSetsClient) BeginReimage(ctx context.Context, r // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) reimage(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginReimageOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginReimage" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // reimageCreateRequest creates the Reimage request. @@ -1244,7 +1364,10 @@ func (client *VirtualMachineScaleSetsClient) reimageCreateRequest(ctx context.Co req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMScaleSetReimageInput != nil { - return req, runtime.MarshalAsJSON(req, *options.VMScaleSetReimageInput) + if err := runtime.MarshalAsJSON(req, *options.VMScaleSetReimageInput); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1264,7 +1387,8 @@ func (client *VirtualMachineScaleSetsClient) BeginReimageAll(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientReimageAllResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientReimageAllResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientReimageAllResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1276,18 +1400,24 @@ func (client *VirtualMachineScaleSetsClient) BeginReimageAll(ctx context.Context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) reimageAll(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginReimageAllOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginReimageAll" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageAllCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // reimageAllCreateRequest creates the ReimageAll request. @@ -1314,7 +1444,10 @@ func (client *VirtualMachineScaleSetsClient) reimageAllCreateRequest(ctx context req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1333,7 +1466,8 @@ func (client *VirtualMachineScaleSetsClient) BeginRestart(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientRestartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientRestartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1344,18 +1478,24 @@ func (client *VirtualMachineScaleSetsClient) BeginRestart(ctx context.Context, r // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) restart(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginRestartOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginRestart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.restartCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // restartCreateRequest creates the Restart request. @@ -1382,7 +1522,10 @@ func (client *VirtualMachineScaleSetsClient) restartCreateRequest(ctx context.Co req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1402,7 +1545,8 @@ func (client *VirtualMachineScaleSetsClient) BeginSetOrchestrationServiceState(c if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientSetOrchestrationServiceStateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientSetOrchestrationServiceStateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientSetOrchestrationServiceStateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1413,18 +1557,24 @@ func (client *VirtualMachineScaleSetsClient) BeginSetOrchestrationServiceState(c // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) setOrchestrationServiceState(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters OrchestrationServiceStateInput, options *VirtualMachineScaleSetsClientBeginSetOrchestrationServiceStateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginSetOrchestrationServiceState" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.setOrchestrationServiceStateCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // setOrchestrationServiceStateCreateRequest creates the SetOrchestrationServiceState request. @@ -1450,7 +1600,10 @@ func (client *VirtualMachineScaleSetsClient) setOrchestrationServiceStateCreateR reqQP.Set("api-version", "2023-03-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 } // BeginStart - Starts one or more virtual machines in a VM scale set. @@ -1467,7 +1620,8 @@ func (client *VirtualMachineScaleSetsClient) BeginStart(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientStartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientStartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1478,18 +1632,24 @@ func (client *VirtualMachineScaleSetsClient) BeginStart(ctx context.Context, res // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) start(ctx context.Context, resourceGroupName string, vmScaleSetName string, options *VirtualMachineScaleSetsClientBeginStartOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginStart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startCreateRequest(ctx, resourceGroupName, vmScaleSetName, 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 } // startCreateRequest creates the Start request. @@ -1516,7 +1676,10 @@ func (client *VirtualMachineScaleSetsClient) startCreateRequest(ctx context.Cont req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMInstanceIDs != nil { - return req, runtime.MarshalAsJSON(req, *options.VMInstanceIDs) + if err := runtime.MarshalAsJSON(req, *options.VMInstanceIDs); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -1536,7 +1699,8 @@ func (client *VirtualMachineScaleSetsClient) BeginUpdate(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1547,18 +1711,24 @@ func (client *VirtualMachineScaleSetsClient) BeginUpdate(ctx context.Context, re // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) update(ctx context.Context, resourceGroupName string, vmScaleSetName string, parameters VirtualMachineScaleSetUpdate, options *VirtualMachineScaleSetsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.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, vmScaleSetName, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -1584,7 +1754,10 @@ func (client *VirtualMachineScaleSetsClient) updateCreateRequest(ctx context.Con reqQP.Set("api-version", "2023-03-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 } // BeginUpdateInstances - Upgrades one or more virtual machines to the latest SKU set in the VM scale set model. @@ -1602,7 +1775,8 @@ func (client *VirtualMachineScaleSetsClient) BeginUpdateInstances(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetsClientUpdateInstancesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetsClientUpdateInstancesResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetsClientUpdateInstancesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1613,18 +1787,24 @@ func (client *VirtualMachineScaleSetsClient) BeginUpdateInstances(ctx context.Co // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetsClient) updateInstances(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmInstanceIDs VirtualMachineScaleSetVMInstanceRequiredIDs, options *VirtualMachineScaleSetsClientBeginUpdateInstancesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetsClient.BeginUpdateInstances" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateInstancesCreateRequest(ctx, resourceGroupName, vmScaleSetName, vmInstanceIDs, 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 } // updateInstancesCreateRequest creates the UpdateInstances request. @@ -1650,5 +1830,8 @@ func (client *VirtualMachineScaleSetsClient) updateInstancesCreateRequest(ctx co reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vmInstanceIDs) + if err := runtime.MarshalAsJSON(req, vmInstanceIDs); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmextensions_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmextensions_client.go index ef2df765f66b..cbe63ad370bc 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmextensions_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmextensions_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 armcompute @@ -62,7 +61,8 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) BeginCreateOrUpdate(ctx if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMExtensionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMExtensionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMExtensionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) BeginCreateOrUpdate(ctx // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMExtensionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, extensionParameters VirtualMachineScaleSetVMExtension, options *VirtualMachineScaleSetVMExtensionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMExtensionsClient.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, vmScaleSetName, instanceID, vmExtensionName, extensionParameters, 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. @@ -118,7 +124,10 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) createOrUpdateCreateRequ reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, extensionParameters) + if err := runtime.MarshalAsJSON(req, extensionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - The operation to delete the VMSS VM extension. @@ -137,7 +146,8 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) BeginDelete(ctx context. if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMExtensionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMExtensionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMExtensionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -148,18 +158,24 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) BeginDelete(ctx context. // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMExtensionsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, options *VirtualMachineScaleSetVMExtensionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMExtensionsClient.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, vmScaleSetName, instanceID, vmExtensionName, 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. @@ -207,18 +223,25 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) deleteCreateRequest(ctx // - options - VirtualMachineScaleSetVMExtensionsClientGetOptions contains the optional parameters for the VirtualMachineScaleSetVMExtensionsClient.Get // method. func (client *VirtualMachineScaleSetVMExtensionsClient) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, options *VirtualMachineScaleSetVMExtensionsClientGetOptions) (VirtualMachineScaleSetVMExtensionsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMExtensionsClient.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, vmScaleSetName, instanceID, vmExtensionName, options) if err != nil { return VirtualMachineScaleSetVMExtensionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMExtensionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetVMExtensionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMExtensionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -277,18 +300,25 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) getHandleResponse(resp * // - options - VirtualMachineScaleSetVMExtensionsClientListOptions contains the optional parameters for the VirtualMachineScaleSetVMExtensionsClient.List // method. func (client *VirtualMachineScaleSetVMExtensionsClient) List(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMExtensionsClientListOptions) (VirtualMachineScaleSetVMExtensionsClientListResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMExtensionsClient.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, resourceGroupName, vmScaleSetName, instanceID, options) if err != nil { return VirtualMachineScaleSetVMExtensionsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMExtensionsClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetVMExtensionsClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMExtensionsClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -350,7 +380,8 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) BeginUpdate(ctx context. if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMExtensionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMExtensionsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMExtensionsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -361,18 +392,24 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) BeginUpdate(ctx context. // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMExtensionsClient) update(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, vmExtensionName string, extensionParameters VirtualMachineScaleSetVMExtensionUpdate, options *VirtualMachineScaleSetVMExtensionsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMExtensionsClient.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, vmScaleSetName, instanceID, vmExtensionName, extensionParameters, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -406,5 +443,8 @@ func (client *VirtualMachineScaleSetVMExtensionsClient) updateCreateRequest(ctx reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, extensionParameters) + if err := runtime.MarshalAsJSON(req, extensionParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmruncommands_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmruncommands_client.go index afc01746974e..ed7bf167b590 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmruncommands_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvmruncommands_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 armcompute @@ -62,7 +61,8 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) BeginCreateOrUpdate(ctx if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) BeginCreateOrUpdate(ctx // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMRunCommandsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, runCommand VirtualMachineRunCommand, options *VirtualMachineScaleSetVMRunCommandsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMRunCommandsClient.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, vmScaleSetName, instanceID, runCommandName, runCommand, 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. @@ -118,7 +124,10 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) createOrUpdateCreateReq reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json, text/json"} - return req, runtime.MarshalAsJSON(req, runCommand) + if err := runtime.MarshalAsJSON(req, runCommand); err != nil { + return nil, err + } + return req, nil } // BeginDelete - The operation to delete the VMSS VM run command. @@ -137,7 +146,8 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) BeginDelete(ctx context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMRunCommandsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMRunCommandsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMRunCommandsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -148,18 +158,24 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) BeginDelete(ctx context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMRunCommandsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, options *VirtualMachineScaleSetVMRunCommandsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMRunCommandsClient.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, vmScaleSetName, instanceID, runCommandName, 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. @@ -207,18 +223,25 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) deleteCreateRequest(ctx // - options - VirtualMachineScaleSetVMRunCommandsClientGetOptions contains the optional parameters for the VirtualMachineScaleSetVMRunCommandsClient.Get // method. func (client *VirtualMachineScaleSetVMRunCommandsClient) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, options *VirtualMachineScaleSetVMRunCommandsClientGetOptions) (VirtualMachineScaleSetVMRunCommandsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMRunCommandsClient.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, vmScaleSetName, instanceID, runCommandName, options) if err != nil { return VirtualMachineScaleSetVMRunCommandsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMRunCommandsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetVMRunCommandsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMRunCommandsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -281,6 +304,7 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) NewListPager(resourceGr return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetVMRunCommandsClientListResponse) (VirtualMachineScaleSetVMRunCommandsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetVMRunCommandsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -300,6 +324,7 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) NewListPager(resourceGr } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -362,7 +387,8 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) BeginUpdate(ctx context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMRunCommandsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMRunCommandsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMRunCommandsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -373,18 +399,24 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) BeginUpdate(ctx context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMRunCommandsClient) update(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, runCommandName string, runCommand VirtualMachineRunCommandUpdate, options *VirtualMachineScaleSetVMRunCommandsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMRunCommandsClient.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, vmScaleSetName, instanceID, runCommandName, runCommand, 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) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // updateCreateRequest creates the Update request. @@ -418,5 +450,8 @@ func (client *VirtualMachineScaleSetVMRunCommandsClient) updateCreateRequest(ctx reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json, text/json"} - return req, runtime.MarshalAsJSON(req, runCommand) + if err := runtime.MarshalAsJSON(req, runCommand); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvms_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvms_client.go index 5518ed54c676..a0fe09681f36 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvms_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesetvms_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 armcompute @@ -63,7 +62,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginDeallocate(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientDeallocateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientDeallocateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientDeallocateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -76,18 +76,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginDeallocate(ctx context.Conte // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) deallocate(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginDeallocateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginDeallocate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deallocateCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // deallocateCreateRequest creates the Deallocate request. @@ -135,7 +141,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +153,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginDelete(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) deleteOperation(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.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, vmScaleSetName, instanceID, 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. @@ -203,18 +216,25 @@ func (client *VirtualMachineScaleSetVMsClient) deleteCreateRequest(ctx context.C // - options - VirtualMachineScaleSetVMsClientGetOptions contains the optional parameters for the VirtualMachineScaleSetVMsClient.Get // method. func (client *VirtualMachineScaleSetVMsClient) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientGetOptions) (VirtualMachineScaleSetVMsClientGetResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.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, vmScaleSetName, instanceID, options) if err != nil { return VirtualMachineScaleSetVMsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetVMsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -269,18 +289,25 @@ func (client *VirtualMachineScaleSetVMsClient) getHandleResponse(resp *http.Resp // - options - VirtualMachineScaleSetVMsClientGetInstanceViewOptions contains the optional parameters for the VirtualMachineScaleSetVMsClient.GetInstanceView // method. func (client *VirtualMachineScaleSetVMsClient) GetInstanceView(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientGetInstanceViewOptions) (VirtualMachineScaleSetVMsClientGetInstanceViewResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.GetInstanceView" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getInstanceViewCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, options) if err != nil { return VirtualMachineScaleSetVMsClientGetInstanceViewResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMsClientGetInstanceViewResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetVMsClientGetInstanceViewResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMsClientGetInstanceViewResponse{}, err } - return client.getInstanceViewHandleResponse(resp) + resp, err := client.getInstanceViewHandleResponse(httpResp) + return resp, err } // getInstanceViewCreateRequest creates the GetInstanceView request. @@ -335,6 +362,7 @@ func (client *VirtualMachineScaleSetVMsClient) NewListPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualMachineScaleSetVMsClientListResponse) (VirtualMachineScaleSetVMsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineScaleSetVMsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -354,6 +382,7 @@ func (client *VirtualMachineScaleSetVMsClient) NewListPager(resourceGroupName st } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -416,7 +445,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginPerformMaintenance(ctx conte if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientPerformMaintenanceResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientPerformMaintenanceResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientPerformMaintenanceResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -427,18 +457,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginPerformMaintenance(ctx conte // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) performMaintenance(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginPerformMaintenanceOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginPerformMaintenance" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.performMaintenanceCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // performMaintenanceCreateRequest creates the PerformMaintenance request. @@ -488,7 +524,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginPowerOff(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientPowerOffResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientPowerOffResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -501,18 +538,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginPowerOff(ctx context.Context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) powerOff(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginPowerOffOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginPowerOff" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.powerOffCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // powerOffCreateRequest creates the PowerOff request. @@ -564,7 +607,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginRedeploy(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientRedeployResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientRedeployResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientRedeployResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -576,18 +620,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginRedeploy(ctx context.Context // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) redeploy(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginRedeployOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginRedeploy" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.redeployCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // redeployCreateRequest creates the Redeploy request. @@ -635,7 +685,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginReimage(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientReimageResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientReimageResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientReimageResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -646,18 +697,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginReimage(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) reimage(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginReimageOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginReimage" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // reimageCreateRequest creates the Reimage request. @@ -688,7 +745,10 @@ func (client *VirtualMachineScaleSetVMsClient) reimageCreateRequest(ctx context. req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.VMScaleSetVMReimageInput != nil { - return req, runtime.MarshalAsJSON(req, *options.VMScaleSetVMReimageInput) + if err := runtime.MarshalAsJSON(req, *options.VMScaleSetVMReimageInput); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -709,7 +769,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginReimageAll(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientReimageAllResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientReimageAllResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientReimageAllResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -721,18 +782,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginReimageAll(ctx context.Conte // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) reimageAll(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginReimageAllOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginReimageAll" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.reimageAllCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // reimageAllCreateRequest creates the ReimageAll request. @@ -780,7 +847,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginRestart(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientRestartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientRestartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -791,18 +859,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginRestart(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) restart(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginRestartOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginRestart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.restartCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // restartCreateRequest creates the Restart request. @@ -846,18 +920,25 @@ func (client *VirtualMachineScaleSetVMsClient) restartCreateRequest(ctx context. // - options - VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataOptions contains the optional parameters for the VirtualMachineScaleSetVMsClient.RetrieveBootDiagnosticsData // method. func (client *VirtualMachineScaleSetVMsClient) RetrieveBootDiagnosticsData(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataOptions) (VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.RetrieveBootDiagnosticsData" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.retrieveBootDiagnosticsDataCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, options) if err != nil { return VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMsClientRetrieveBootDiagnosticsDataResponse{}, err } - return client.retrieveBootDiagnosticsDataHandleResponse(resp) + resp, err := client.retrieveBootDiagnosticsDataHandleResponse(httpResp) + return resp, err } // retrieveBootDiagnosticsDataCreateRequest creates the RetrieveBootDiagnosticsData request. @@ -918,9 +999,10 @@ func (client *VirtualMachineScaleSetVMsClient) BeginRunCommand(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachineScaleSetVMsClientRunCommandResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualMachineScaleSetVMsClientRunCommandResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientRunCommandResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -931,18 +1013,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginRunCommand(ctx context.Conte // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) runCommand(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, parameters RunCommandInput, options *VirtualMachineScaleSetVMsClientBeginRunCommandOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginRunCommand" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.runCommandCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // runCommandCreateRequest creates the RunCommand request. @@ -972,7 +1060,10 @@ func (client *VirtualMachineScaleSetVMsClient) runCommandCreateRequest(ctx conte reqQP.Set("api-version", "2023-03-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json, text/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // SimulateEviction - The operation to simulate the eviction of spot virtual machine in a VM scale set. @@ -985,16 +1076,22 @@ func (client *VirtualMachineScaleSetVMsClient) runCommandCreateRequest(ctx conte // - options - VirtualMachineScaleSetVMsClientSimulateEvictionOptions contains the optional parameters for the VirtualMachineScaleSetVMsClient.SimulateEviction // method. func (client *VirtualMachineScaleSetVMsClient) SimulateEviction(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientSimulateEvictionOptions) (VirtualMachineScaleSetVMsClientSimulateEvictionResponse, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.SimulateEviction" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.simulateEvictionCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, options) if err != nil { return VirtualMachineScaleSetVMsClientSimulateEvictionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualMachineScaleSetVMsClientSimulateEvictionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return VirtualMachineScaleSetVMsClientSimulateEvictionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return VirtualMachineScaleSetVMsClientSimulateEvictionResponse{}, err } return VirtualMachineScaleSetVMsClientSimulateEvictionResponse{}, nil } @@ -1044,7 +1141,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginStart(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientStartResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientStartResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1055,18 +1153,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginStart(ctx context.Context, r // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) start(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *VirtualMachineScaleSetVMsClientBeginStartOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.BeginStart" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startCreateRequest(ctx, resourceGroupName, vmScaleSetName, instanceID, 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 } // startCreateRequest creates the Start request. @@ -1115,7 +1219,8 @@ func (client *VirtualMachineScaleSetVMsClient) BeginUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[VirtualMachineScaleSetVMsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VirtualMachineScaleSetVMsClientUpdateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualMachineScaleSetVMsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1126,18 +1231,24 @@ func (client *VirtualMachineScaleSetVMsClient) BeginUpdate(ctx context.Context, // // Generated from API version 2023-03-01 func (client *VirtualMachineScaleSetVMsClient) update(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, parameters VirtualMachineScaleSetVM, options *VirtualMachineScaleSetVMsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualMachineScaleSetVMsClient.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, vmScaleSetName, instanceID, 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. @@ -1167,5 +1278,8 @@ func (client *VirtualMachineScaleSetVMsClient) updateCreateRequest(ctx context.C reqQP.Set("api-version", "2023-03-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/compute/armcompute/virtualmachinesizes_client.go b/sdk/resourcemanager/compute/armcompute/virtualmachinesizes_client.go index 1d05512ed17d..2235d57f087b 100644 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinesizes_client.go +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinesizes_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 armcompute @@ -57,6 +56,7 @@ func (client *VirtualMachineSizesClient) NewListPager(location string, options * return false }, Fetcher: func(ctx context.Context, page *VirtualMachineSizesClientListResponse) (VirtualMachineSizesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualMachineSizesClient.NewListPager") req, err := client.listCreateRequest(ctx, location, options) if err != nil { return VirtualMachineSizesClientListResponse{}, err @@ -70,6 +70,7 @@ func (client *VirtualMachineSizesClient) NewListPager(location string, options * } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } From 65f9ba0204abb0da6c8eb4b668158e3fc93a98fa Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 8 Jun 2023 09:48:11 -0700 Subject: [PATCH 2/4] add module settinig to config file update build script to recursively clean files --- eng/scripts/build.ps1 | 2 +- sdk/resourcemanager/compute/armcompute/autorest.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/scripts/build.ps1 b/eng/scripts/build.ps1 index 98ebe8614e72..b5e6e7a6e02d 100644 --- a/eng/scripts/build.ps1 +++ b/eng/scripts/build.ps1 @@ -32,7 +32,7 @@ function Process-Sdk () if ($cleanGenerated) { Write-Host "##[command]Cleaning auto-generated files in" $currentDirectory - (Get-ChildItem "*.go" | Where-Object { $_.Name -notlike '*_test.go' } | Select-String -Pattern "Code generated by Microsoft" | Select-Object -ExpandProperty path) | Remove-Item -Force + (Get-ChildItem -recurse "*.go" | Where-Object { $_.Name -notlike '*_test.go' } | Select-String -Pattern "Code generated by Microsoft" | Select-Object -ExpandProperty path) | Remove-Item -Force } if ($generate) diff --git a/sdk/resourcemanager/compute/armcompute/autorest.md b/sdk/resourcemanager/compute/armcompute/autorest.md index 7968ec9e4fa5..ceb9fdd5b293 100644 --- a/sdk/resourcemanager/compute/armcompute/autorest.md +++ b/sdk/resourcemanager/compute/armcompute/autorest.md @@ -8,6 +8,7 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/5d2adf9b7fda669b4a2538c65e937ee74fe3f966/specification/compute/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/5d2adf9b7fda669b4a2538c65e937ee74fe3f966/specification/compute/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION +module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 module-version: 5.1.0-beta.1 tag: package-2023-03-01 azcore-version: 1.7.0-beta.2 From 74175e80d08021f6c1cc7098ff773304a4595994 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Fri, 9 Jun 2023 14:02:56 -0700 Subject: [PATCH 3/4] update to latest code generator add fake testable example --- .../compute/armcompute/README.md | 10 +- .../compute/armcompute/build.go | 2 +- .../fake/availabilitysets_server.go | 105 +++-- .../fake/capacityreservationgroups_server.go | 101 +++- .../fake/capacityreservations_server.go | 103 +++- .../cloudserviceoperatingsystems_server.go | 57 ++- .../fake/cloudserviceroleinstances_server.go | 169 +++++-- .../fake/cloudserviceroles_server.go | 37 +- .../armcompute/fake/cloudservices_server.go | 195 ++++++-- .../fake/cloudservicesupdatedomain_server.go | 61 ++- .../fake/communitygalleries_server.go | 17 +- .../fake/communitygalleryimages_server.go | 37 +- .../communitygalleryimageversions_server.go | 45 +- .../fake/dedicatedhostgroups_server.go | 89 +++- .../armcompute/fake/dedicatedhosts_server.go | 143 ++++-- .../armcompute/fake/diskaccesses_server.go | 175 +++++-- .../fake/diskencryptionsets_server.go | 99 ++-- .../fake/diskrestorepoint_server.go | 93 +++- .../compute/armcompute/fake/disks_server.go | 115 +++-- .../armcompute/fake/galleries_server.go | 95 +++- .../fake/galleryapplications_server.go | 97 +++- .../fake/galleryapplicationversions_server.go | 123 ++++- .../armcompute/fake/galleryimages_server.go | 97 +++- .../fake/galleryimageversions_server.go | 123 ++++- .../fake/gallerysharingprofile_server.go | 17 +- .../compute/armcompute/fake/images_server.go | 89 +++- .../armcompute/fake/loganalytics_server.go | 25 +- .../armcompute/fake/operations_server.go | 2 +- .../fake/proximityplacementgroups_server.go | 89 +++- .../armcompute/fake/resourceskus_server.go | 19 +- .../fake/restorepointcollections_server.go | 89 +++- .../armcompute/fake/restorepoints_server.go | 67 ++- .../armcompute/fake/sharedgalleries_server.go | 35 +- .../fake/sharedgalleryimages_server.go | 43 +- .../fake/sharedgalleryimageversions_server.go | 51 +- .../armcompute/fake/snapshots_server.go | 115 +++-- .../armcompute/fake/sshpublickeys_server.go | 99 ++-- .../compute/armcompute/fake/usage_server.go | 13 +- .../virtualmachineextensionimages_server.go | 79 +++- .../fake/virtualmachineextensions_server.go | 109 ++++- .../fake/virtualmachineimages_server.go | 135 ++++-- .../virtualmachineimagesedgezone_server.go | 139 +++++- .../fake/virtualmachineruncommands_server.go | 137 ++++-- .../armcompute/fake/virtualmachines_server.go | 443 +++++++++++++----- ...virtualmachinescalesetextensions_server.go | 103 +++- ...almachinescalesetrollingupgrades_server.go | 65 ++- .../fake/virtualmachinescalesets_server.go | 415 ++++++++++++---- ...rtualmachinescalesetvmextensions_server.go | 129 ++++- ...tualmachinescalesetvmruncommands_server.go | 129 ++++- .../fake/virtualmachinescalesetvms_server.go | 359 +++++++++++--- .../fake/virtualmachinesizes_server.go | 13 +- .../compute/armcompute/fake_example_test.go | 79 ++++ 52 files changed, 4097 insertions(+), 1178 deletions(-) create mode 100644 sdk/resourcemanager/compute/armcompute/fake_example_test.go diff --git a/sdk/resourcemanager/compute/armcompute/README.md b/sdk/resourcemanager/compute/armcompute/README.md index c2d2b8a83c58..bfc1b4975678 100644 --- a/sdk/resourcemanager/compute/armcompute/README.md +++ b/sdk/resourcemanager/compute/armcompute/README.md @@ -67,15 +67,15 @@ The `fake` package provides implementations for fake servers that can be used fo To create a fake server, declare an instance of the required fake server type(s). ```go -myFakeAvailabilitySetsServer := fake.AvailabilitySetsServer{} +myFakeVirtualMachinesServer := fake.VirtualMachinesServer{} ``` Next, provide func implementations for the methods you wish to fake. The named return variables can be used to simplify return value construction. ```go -myFakeAvailabilitySetsServer.Get = func(ctx context.Context, resourceGroupName string, availabilitySetName string, options *armcompute.AvailabilitySetsClientGetOptions) (resp azfake.Responder[armcompute.AvailabilitySetsClientGetResponse], err azfake.ErrorResponder) { - // TODO: resp.SetResponse(/* your fake AvailabilitySetsClientGetResponse response */) +myFakeVirtualMachinesServer.Get = func(ctx context.Context, resourceGroupName string, vmName string, options *armcompute.VirtualMachinesClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientGetResponse], errResp azfake.ErrorResponder) { + // TODO: resp.SetResponse(/* your fake armcompute.VirtualMachinesClientGetResponse response */) return } ``` @@ -87,9 +87,9 @@ 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 := armcompute.NewAvailabilitySetsClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ +client, err := armcompute.VirtualMachinesClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ ClientOptions: azcore.ClientOptions{ - Transport: fake.NewAvailabilitySetsServerTransport(&myFakeAvailabilitySetsServer), + Transport: fake.NewVirtualMachinesServerTransport(&myFakeVirtualMachinesServer), }, }) ``` diff --git a/sdk/resourcemanager/compute/armcompute/build.go b/sdk/resourcemanager/compute/armcompute/build.go index 6dea5eecf48f..d301bc6e5b9f 100644 --- a/sdk/resourcemanager/compute/armcompute/build.go +++ b/sdk/resourcemanager/compute/armcompute/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 -alwaysSetBodyParamRequired resourcemanager/compute/armcompute +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.51" -skipBuild -cleanGenerated -format -tidy -generate -alwaysSetBodyParamRequired resourcemanager/compute/armcompute package armcompute diff --git a/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go b/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go index 5a39510809ad..4bd37fd81ed7 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/availabilitysets_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -107,11 +108,11 @@ func (a *AvailabilitySetsServerTransport) Do(req *http.Request) (*http.Response, func (a *AvailabilitySetsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { if a.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-_]+)/providers/Microsoft.Compute/availabilitySets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets/(?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) } @@ -119,7 +120,15 @@ func (a *AvailabilitySetsServerTransport) dispatchCreateOrUpdate(req *http.Reque if err != nil { return nil, err } - respr, errRespr := a.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + availabilitySetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("availabilitySetName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, availabilitySetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -136,15 +145,23 @@ func (a *AvailabilitySetsServerTransport) dispatchCreateOrUpdate(req *http.Reque func (a *AvailabilitySetsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { if a.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets/(?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 := a.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + availabilitySetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("availabilitySetName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Delete(req.Context(), resourceGroupNameUnescaped, availabilitySetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -161,15 +178,23 @@ func (a *AvailabilitySetsServerTransport) dispatchDelete(req *http.Request) (*ht func (a *AvailabilitySetsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if a.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.Compute/availabilitySets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets/(?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 := a.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + availabilitySetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("availabilitySetName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, availabilitySetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -186,16 +211,20 @@ func (a *AvailabilitySetsServerTransport) dispatchGet(req *http.Request) (*http. func (a *AvailabilitySetsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if a.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if a.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets` 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) } - resp := a.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(resourceGroupNameUnescaped, nil) a.newListPager = &resp server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armcompute.AvailabilitySetsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -216,16 +245,24 @@ func (a *AvailabilitySetsServerTransport) dispatchNewListPager(req *http.Request func (a *AvailabilitySetsServerTransport) dispatchNewListAvailableSizesPager(req *http.Request) (*http.Response, error) { if a.srv.NewListAvailableSizesPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAvailableSizesPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAvailableSizesPager not implemented")} } if a.newListAvailableSizesPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets/(?P[a-zA-Z0-9-_]+)/vmSizes" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vmSizes` 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) } - resp := a.srv.NewListAvailableSizesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + availabilitySetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("availabilitySetName")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListAvailableSizesPager(resourceGroupNameUnescaped, availabilitySetNameUnescaped, nil) a.newListAvailableSizesPager = &resp } resp, err := server.PagerResponderNext(a.newListAvailableSizesPager, req) @@ -243,17 +280,21 @@ func (a *AvailabilitySetsServerTransport) dispatchNewListAvailableSizesPager(req func (a *AvailabilitySetsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { if a.srv.NewListBySubscriptionPager == nil { - return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} } if a.newListBySubscriptionPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/availabilitySets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets` 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 *armcompute.AvailabilitySetsClientListBySubscriptionOptions if expandParam != nil { options = &armcompute.AvailabilitySetsClientListBySubscriptionOptions{ @@ -281,11 +322,11 @@ func (a *AvailabilitySetsServerTransport) dispatchNewListBySubscriptionPager(req func (a *AvailabilitySetsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { if a.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-_]+)/providers/Microsoft.Compute/availabilitySets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/availabilitySets/(?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) } @@ -293,7 +334,15 @@ func (a *AvailabilitySetsServerTransport) dispatchUpdate(req *http.Request) (*ht if err != nil { return nil, err } - respr, errRespr := a.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("availabilitySetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + availabilitySetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("availabilitySetName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Update(req.Context(), resourceGroupNameUnescaped, availabilitySetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go b/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go index 782aed79e85b..fff2c8f5dc9a 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/capacityreservationgroups_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -100,11 +101,11 @@ func (c *CapacityReservationGroupsServerTransport) Do(req *http.Request) (*http. func (c *CapacityReservationGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { if c.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-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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) } @@ -112,7 +113,15 @@ func (c *CapacityReservationGroupsServerTransport) dispatchCreateOrUpdate(req *h if err != nil { return nil, err } - respr, errRespr := c.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -129,15 +138,23 @@ func (c *CapacityReservationGroupsServerTransport) dispatchCreateOrUpdate(req *h func (c *CapacityReservationGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { if c.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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 := c.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Delete(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -154,23 +171,35 @@ func (c *CapacityReservationGroupsServerTransport) dispatchDelete(req *http.Requ func (c *CapacityReservationGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.CapacityReservationGroupInstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.CapacityReservationGroupInstanceViewTypes(expandUnescaped)) var options *armcompute.CapacityReservationGroupsClientGetOptions if expandParam != nil { options = &armcompute.CapacityReservationGroupsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], options) + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -187,24 +216,32 @@ func (c *CapacityReservationGroupsServerTransport) dispatchGet(req *http.Request func (c *CapacityReservationGroupsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if c.srv.NewListByResourceGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } if c.newListByResourceGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups` 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(armcompute.ExpandTypesForGetCapacityReservationGroups(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.ExpandTypesForGetCapacityReservationGroups(expandUnescaped)) var options *armcompute.CapacityReservationGroupsClientListByResourceGroupOptions if expandParam != nil { options = &armcompute.CapacityReservationGroupsClientListByResourceGroupOptions{ Expand: expandParam, } } - resp := c.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], options) + resp := c.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, options) c.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(c.newListByResourceGroupPager, req, func(page *armcompute.CapacityReservationGroupsClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -225,17 +262,21 @@ func (c *CapacityReservationGroupsServerTransport) dispatchNewListByResourceGrou func (c *CapacityReservationGroupsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { if c.srv.NewListBySubscriptionPager == nil { - return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} } if c.newListBySubscriptionPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups` 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(armcompute.ExpandTypesForGetCapacityReservationGroups(qp.Get("$expand"))) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.ExpandTypesForGetCapacityReservationGroups(expandUnescaped)) var options *armcompute.CapacityReservationGroupsClientListBySubscriptionOptions if expandParam != nil { options = &armcompute.CapacityReservationGroupsClientListBySubscriptionOptions{ @@ -263,11 +304,11 @@ func (c *CapacityReservationGroupsServerTransport) dispatchNewListBySubscription func (c *CapacityReservationGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { if c.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-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?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) } @@ -275,7 +316,15 @@ func (c *CapacityReservationGroupsServerTransport) dispatchUpdate(req *http.Requ if err != nil { return nil, err } - respr, errRespr := c.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Update(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go b/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go index b9fc40370aba..3b5272a6cbad 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/capacityreservations_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (c *CapacityReservationsServerTransport) Do(req *http.Request) (*http.Respo func (c *CapacityReservationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if c.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if c.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/capacityReservations/(?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) } @@ -109,7 +110,19 @@ func (c *CapacityReservationsServerTransport) dispatchBeginCreateOrUpdate(req *h if err != nil { return nil, err } - respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + capacityReservationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, capacityReservationNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +146,28 @@ func (c *CapacityReservationsServerTransport) dispatchBeginCreateOrUpdate(req *h func (c *CapacityReservationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if c.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if c.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/capacityReservations/(?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 := c.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + capacityReservationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, capacityReservationNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,23 +191,39 @@ func (c *CapacityReservationsServerTransport) dispatchBeginDelete(req *http.Requ func (c *CapacityReservationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/capacityReservations/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.CapacityReservationInstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + capacityReservationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.CapacityReservationInstanceViewTypes(expandUnescaped)) var options *armcompute.CapacityReservationsClientGetOptions if expandParam != nil { options = &armcompute.CapacityReservationsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], options) + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, capacityReservationNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -199,16 +240,24 @@ func (c *CapacityReservationsServerTransport) dispatchGet(req *http.Request) (*h func (c *CapacityReservationsServerTransport) dispatchNewListByCapacityReservationGroupPager(req *http.Request) (*http.Response, error) { if c.srv.NewListByCapacityReservationGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByCapacityReservationGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByCapacityReservationGroupPager not implemented")} } if c.newListByCapacityReservationGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/capacityReservations` 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) } - resp := c.srv.NewListByCapacityReservationGroupPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListByCapacityReservationGroupPager(resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, nil) c.newListByCapacityReservationGroupPager = &resp server.PagerResponderInjectNextLinks(c.newListByCapacityReservationGroupPager, req, func(page *armcompute.CapacityReservationsClientListByCapacityReservationGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -229,12 +278,12 @@ func (c *CapacityReservationsServerTransport) dispatchNewListByCapacityReservati func (c *CapacityReservationsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if c.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if c.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[a-zA-Z0-9-_]+)/capacityReservations/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/capacityReservationGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/capacityReservations/(?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) } @@ -242,7 +291,19 @@ func (c *CapacityReservationsServerTransport) dispatchBeginUpdate(req *http.Requ if err != nil { return nil, err } - respr, errRespr := c.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("capacityReservationGroupName")], matches[regex.SubexpIndex("capacityReservationName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + capacityReservationGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationGroupName")]) + if err != nil { + return nil, err + } + capacityReservationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("capacityReservationName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, capacityReservationGroupNameUnescaped, capacityReservationNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go index a45abb6bfc25..5d9f96f6f65f 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceoperatingsystems_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -88,15 +89,23 @@ func (c *CloudServiceOperatingSystemsServerTransport) Do(req *http.Request) (*ht func (c *CloudServiceOperatingSystemsServerTransport) dispatchGetOSFamily(req *http.Request) (*http.Response, error) { if c.srv.GetOSFamily == nil { - return nil, &nonRetriableError{errors.New("method GetOSFamily not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetOSFamily not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsFamilies/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cloudServiceOsFamilies/(?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 := c.srv.GetOSFamily(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("osFamilyName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + osFamilyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("osFamilyName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.GetOSFamily(req.Context(), locationUnescaped, osFamilyNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -113,15 +122,23 @@ func (c *CloudServiceOperatingSystemsServerTransport) dispatchGetOSFamily(req *h func (c *CloudServiceOperatingSystemsServerTransport) dispatchGetOSVersion(req *http.Request) (*http.Response, error) { if c.srv.GetOSVersion == nil { - return nil, &nonRetriableError{errors.New("method GetOSVersion not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetOSVersion not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsVersions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cloudServiceOsVersions/(?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 := c.srv.GetOSVersion(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("osVersionName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + osVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("osVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.GetOSVersion(req.Context(), locationUnescaped, osVersionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -138,16 +155,20 @@ func (c *CloudServiceOperatingSystemsServerTransport) dispatchGetOSVersion(req * func (c *CloudServiceOperatingSystemsServerTransport) dispatchNewListOSFamiliesPager(req *http.Request) (*http.Response, error) { if c.srv.NewListOSFamiliesPager == nil { - return nil, &nonRetriableError{errors.New("method NewListOSFamiliesPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListOSFamiliesPager not implemented")} } if c.newListOSFamiliesPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsFamilies" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cloudServiceOsFamilies` 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) } - resp := c.srv.NewListOSFamiliesPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListOSFamiliesPager(locationUnescaped, nil) c.newListOSFamiliesPager = &resp server.PagerResponderInjectNextLinks(c.newListOSFamiliesPager, req, func(page *armcompute.CloudServiceOperatingSystemsClientListOSFamiliesResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -168,16 +189,20 @@ func (c *CloudServiceOperatingSystemsServerTransport) dispatchNewListOSFamiliesP func (c *CloudServiceOperatingSystemsServerTransport) dispatchNewListOSVersionsPager(req *http.Request) (*http.Response, error) { if c.srv.NewListOSVersionsPager == nil { - return nil, &nonRetriableError{errors.New("method NewListOSVersionsPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListOSVersionsPager not implemented")} } if c.newListOSVersionsPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/cloudServiceOsVersions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cloudServiceOsVersions` 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) } - resp := c.srv.NewListOSVersionsPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListOSVersionsPager(locationUnescaped, nil) c.newListOSVersionsPager = &resp server.PagerResponderInjectNextLinks(c.newListOSVersionsPager, req, func(page *armcompute.CloudServiceOperatingSystemsClientListOSVersionsResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go index 61019ac6d8d6..ef8b4ad375ca 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroleinstances_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -115,16 +116,28 @@ func (c *CloudServiceRoleInstancesServerTransport) Do(req *http.Request) (*http. func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if c.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if c.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?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 := c.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginDelete(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -148,23 +161,39 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginDelete(req *http func (c *CloudServiceRoleInstancesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.InstanceViewTypes(expandUnescaped)) var options *armcompute.CloudServiceRoleInstancesClientGetOptions if expandParam != nil { options = &armcompute.CloudServiceRoleInstancesClientGetOptions{ Expand: expandParam, } } - respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + respr, errRespr := c.srv.Get(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -181,15 +210,27 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchGet(req *http.Request func (c *CloudServiceRoleInstancesServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { if c.srv.GetInstanceView == nil { - return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetInstanceView not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/instanceView" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/instanceView` 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 := c.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.GetInstanceView(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -206,15 +247,27 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchGetInstanceView(req * func (c *CloudServiceRoleInstancesServerTransport) dispatchGetRemoteDesktopFile(req *http.Request) (*http.Response, error) { if c.srv.GetRemoteDesktopFile == nil { - return nil, &nonRetriableError{errors.New("method GetRemoteDesktopFile not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetRemoteDesktopFile not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/remoteDesktopFile" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/remoteDesktopFile` 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 := c.srv.GetRemoteDesktopFile(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.GetRemoteDesktopFile(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -234,24 +287,36 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchGetRemoteDesktopFile( func (c *CloudServiceRoleInstancesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if c.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if c.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances` 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() - expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.InstanceViewTypes(expandUnescaped)) var options *armcompute.CloudServiceRoleInstancesClientListOptions if expandParam != nil { options = &armcompute.CloudServiceRoleInstancesClientListOptions{ Expand: expandParam, } } - resp := c.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + resp := c.srv.NewListPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, options) c.newListPager = &resp server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CloudServiceRoleInstancesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -272,16 +337,28 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchNewListPager(req *htt func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginRebuild(req *http.Request) (*http.Response, error) { if c.srv.BeginRebuild == nil { - return nil, &nonRetriableError{errors.New("method BeginRebuild not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRebuild not implemented")} } if c.beginRebuild == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/rebuild" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rebuild` 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 := c.srv.BeginRebuild(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginRebuild(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -305,16 +382,28 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginRebuild(req *htt func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { if c.srv.BeginReimage == nil { - return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimage not implemented")} } if c.beginReimage == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/reimage" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimage` 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 := c.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginReimage(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -338,16 +427,28 @@ func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginReimage(req *htt func (c *CloudServiceRoleInstancesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { if c.srv.BeginRestart == nil { - return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} } if c.beginRestart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roleInstances/(?P[a-zA-Z0-9-_]+)/restart" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roleInstances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 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 := c.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("roleInstanceName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginRestart(req.Context(), roleInstanceNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go index ca84dd8464ab..1131cc2f2a8c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudserviceroles_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,15 +76,27 @@ func (c *CloudServiceRolesServerTransport) Do(req *http.Request) (*http.Response func (c *CloudServiceRolesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roles/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roles/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("roleName")], matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + roleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), roleNameUnescaped, resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -100,16 +113,24 @@ func (c *CloudServiceRolesServerTransport) dispatchGet(req *http.Request) (*http func (c *CloudServiceRolesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if c.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if c.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/roles" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/roles` 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) } - resp := c.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) c.newListPager = &resp server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CloudServiceRolesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go index 52a539823adb..ecb57b62a74a 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/cloudservices_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudservices_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/compute/armcompute/v5" "net/http" + "net/url" "reflect" "regexp" ) @@ -152,12 +153,12 @@ func (c *CloudServicesServerTransport) Do(req *http.Request) (*http.Response, er func (c *CloudServicesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if c.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if c.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?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) } @@ -165,7 +166,15 @@ func (c *CloudServicesServerTransport) dispatchBeginCreateOrUpdate(req *http.Req if err != nil { return nil, err } - respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -189,16 +198,24 @@ func (c *CloudServicesServerTransport) dispatchBeginCreateOrUpdate(req *http.Req func (c *CloudServicesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if c.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if c.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?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 := c.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -222,12 +239,12 @@ func (c *CloudServicesServerTransport) dispatchBeginDelete(req *http.Request) (* func (c *CloudServicesServerTransport) dispatchBeginDeleteInstances(req *http.Request) (*http.Response, error) { if c.srv.BeginDeleteInstances == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteInstances not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteInstances not implemented")} } if c.beginDeleteInstances == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/delete" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/delete` 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) } @@ -235,13 +252,21 @@ func (c *CloudServicesServerTransport) dispatchBeginDeleteInstances(req *http.Re if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } var options *armcompute.CloudServicesClientBeginDeleteInstancesOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.CloudServicesClientBeginDeleteInstancesOptions{ Parameters: &body, } } - respr, errRespr := c.srv.BeginDeleteInstances(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + respr, errRespr := c.srv.BeginDeleteInstances(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -265,15 +290,23 @@ func (c *CloudServicesServerTransport) dispatchBeginDeleteInstances(req *http.Re func (c *CloudServicesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -290,15 +323,23 @@ func (c *CloudServicesServerTransport) dispatchGet(req *http.Request) (*http.Res func (c *CloudServicesServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { if c.srv.GetInstanceView == nil { - return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetInstanceView not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/instanceView" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/instanceView` 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 := c.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.GetInstanceView(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -315,16 +356,20 @@ func (c *CloudServicesServerTransport) dispatchGetInstanceView(req *http.Request func (c *CloudServicesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if c.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if c.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices` 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) } - resp := c.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListPager(resourceGroupNameUnescaped, nil) c.newListPager = &resp server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CloudServicesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -345,12 +390,12 @@ func (c *CloudServicesServerTransport) dispatchNewListPager(req *http.Request) ( func (c *CloudServicesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { if c.srv.NewListAllPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} } if c.newListAllPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices` 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) } @@ -375,16 +420,24 @@ func (c *CloudServicesServerTransport) dispatchNewListAllPager(req *http.Request func (c *CloudServicesServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { if c.srv.BeginPowerOff == nil { - return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPowerOff not implemented")} } if c.beginPowerOff == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/poweroff" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/poweroff` 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 := c.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginPowerOff(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -408,12 +461,12 @@ func (c *CloudServicesServerTransport) dispatchBeginPowerOff(req *http.Request) func (c *CloudServicesServerTransport) dispatchBeginRebuild(req *http.Request) (*http.Response, error) { if c.srv.BeginRebuild == nil { - return nil, &nonRetriableError{errors.New("method BeginRebuild not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRebuild not implemented")} } if c.beginRebuild == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/rebuild" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rebuild` 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) } @@ -421,13 +474,21 @@ func (c *CloudServicesServerTransport) dispatchBeginRebuild(req *http.Request) ( if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } var options *armcompute.CloudServicesClientBeginRebuildOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.CloudServicesClientBeginRebuildOptions{ Parameters: &body, } } - respr, errRespr := c.srv.BeginRebuild(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + respr, errRespr := c.srv.BeginRebuild(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -451,12 +512,12 @@ func (c *CloudServicesServerTransport) dispatchBeginRebuild(req *http.Request) ( func (c *CloudServicesServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { if c.srv.BeginReimage == nil { - return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimage not implemented")} } if c.beginReimage == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/reimage" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimage` 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) } @@ -464,13 +525,21 @@ func (c *CloudServicesServerTransport) dispatchBeginReimage(req *http.Request) ( if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } var options *armcompute.CloudServicesClientBeginReimageOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.CloudServicesClientBeginReimageOptions{ Parameters: &body, } } - respr, errRespr := c.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + respr, errRespr := c.srv.BeginReimage(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -494,12 +563,12 @@ func (c *CloudServicesServerTransport) dispatchBeginReimage(req *http.Request) ( func (c *CloudServicesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { if c.srv.BeginRestart == nil { - return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} } if c.beginRestart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/restart" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 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) } @@ -507,13 +576,21 @@ func (c *CloudServicesServerTransport) dispatchBeginRestart(req *http.Request) ( if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } var options *armcompute.CloudServicesClientBeginRestartOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.CloudServicesClientBeginRestartOptions{ Parameters: &body, } } - respr, errRespr := c.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], options) + respr, errRespr := c.srv.BeginRestart(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -537,16 +614,24 @@ func (c *CloudServicesServerTransport) dispatchBeginRestart(req *http.Request) ( func (c *CloudServicesServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { if c.srv.BeginStart == nil { - return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginStart not implemented")} } if c.beginStart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/start" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/start` 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 := c.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginStart(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -570,12 +655,12 @@ func (c *CloudServicesServerTransport) dispatchBeginStart(req *http.Request) (*h func (c *CloudServicesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if c.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if c.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?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) } @@ -583,7 +668,15 @@ func (c *CloudServicesServerTransport) dispatchBeginUpdate(req *http.Request) (* if err != nil { return nil, err } - respr, errRespr := c.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go b/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go index 8db1b276eb87..19337782c379 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/cloudservicesupdatedomain_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" "strconv" ) @@ -83,15 +84,27 @@ func (c *CloudServicesUpdateDomainServerTransport) Do(req *http.Request) (*http. func (c *CloudServicesUpdateDomainServerTransport) dispatchGetUpdateDomain(req *http.Request) (*http.Response, error) { if c.srv.GetUpdateDomain == nil { - return nil, &nonRetriableError{errors.New("method GetUpdateDomain not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetUpdateDomain not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/updateDomains/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/updateDomains/(?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) } - updateDomainParam, err := parseWithCast(matches[regex.SubexpIndex("updateDomain")], func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + updateDomainUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("updateDomain")]) + if err != nil { + return nil, err + } + updateDomainParam, err := parseWithCast(updateDomainUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -101,7 +114,7 @@ func (c *CloudServicesUpdateDomainServerTransport) dispatchGetUpdateDomain(req * if err != nil { return nil, err } - respr, errRespr := c.srv.GetUpdateDomain(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], int32(updateDomainParam), nil) + respr, errRespr := c.srv.GetUpdateDomain(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, int32(updateDomainParam), nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -118,16 +131,24 @@ func (c *CloudServicesUpdateDomainServerTransport) dispatchGetUpdateDomain(req * func (c *CloudServicesUpdateDomainServerTransport) dispatchNewListUpdateDomainsPager(req *http.Request) (*http.Response, error) { if c.srv.NewListUpdateDomainsPager == nil { - return nil, &nonRetriableError{errors.New("method NewListUpdateDomainsPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListUpdateDomainsPager not implemented")} } if c.newListUpdateDomainsPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/updateDomains" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/updateDomains` 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) } - resp := c.srv.NewListUpdateDomainsPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListUpdateDomainsPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) c.newListUpdateDomainsPager = &resp server.PagerResponderInjectNextLinks(c.newListUpdateDomainsPager, req, func(page *armcompute.CloudServicesUpdateDomainClientListUpdateDomainsResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -148,12 +169,12 @@ func (c *CloudServicesUpdateDomainServerTransport) dispatchNewListUpdateDomainsP func (c *CloudServicesUpdateDomainServerTransport) dispatchBeginWalkUpdateDomain(req *http.Request) (*http.Response, error) { if c.srv.BeginWalkUpdateDomain == nil { - return nil, &nonRetriableError{errors.New("method BeginWalkUpdateDomain not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginWalkUpdateDomain not implemented")} } if c.beginWalkUpdateDomain == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/cloudServices/(?P[a-zA-Z0-9-_]+)/updateDomains/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/updateDomains/(?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) } @@ -161,7 +182,19 @@ func (c *CloudServicesUpdateDomainServerTransport) dispatchBeginWalkUpdateDomain if err != nil { return nil, err } - updateDomainParam, err := parseWithCast(matches[regex.SubexpIndex("updateDomain")], func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + cloudServiceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("cloudServiceName")]) + if err != nil { + return nil, err + } + updateDomainUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("updateDomain")]) + if err != nil { + return nil, err + } + updateDomainParam, err := parseWithCast(updateDomainUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -171,7 +204,7 @@ func (c *CloudServicesUpdateDomainServerTransport) dispatchBeginWalkUpdateDomain if err != nil { return nil, err } - respr, errRespr := c.srv.BeginWalkUpdateDomain(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("cloudServiceName")], int32(updateDomainParam), body, nil) + respr, errRespr := c.srv.BeginWalkUpdateDomain(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, int32(updateDomainParam), body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go b/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go index b87f0c904983..10a00daa9a77 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/communitygalleries_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -67,15 +68,23 @@ func (c *CommunityGalleriesServerTransport) Do(req *http.Request) (*http.Respons func (c *CommunityGalleriesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/communityGalleries/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publicGalleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicGalleryName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), locationUnescaped, publicGalleryNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go index 23a3c4e19b07..6a13283915e4 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimages_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,15 +76,27 @@ func (c *CommunityGalleryImagesServerTransport) Do(req *http.Request) (*http.Res func (c *CommunityGalleryImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/communityGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?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 := c.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publicGalleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicGalleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), locationUnescaped, publicGalleryNameUnescaped, galleryImageNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -100,16 +113,24 @@ func (c *CommunityGalleryImagesServerTransport) dispatchGet(req *http.Request) ( func (c *CommunityGalleryImagesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if c.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if c.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/communityGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images` 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) } - resp := c.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publicGalleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicGalleryName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListPager(locationUnescaped, publicGalleryNameUnescaped, nil) c.newListPager = &resp server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CommunityGalleryImagesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go index c7a8627a56fe..81a3c0f42dc1 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/communitygalleryimageversions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,15 +76,31 @@ func (c *CommunityGalleryImageVersionsServerTransport) Do(req *http.Request) (*h func (c *CommunityGalleryImageVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if c.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/communityGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := c.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publicGalleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicGalleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + galleryImageVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), locationUnescaped, publicGalleryNameUnescaped, galleryImageNameUnescaped, galleryImageVersionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -100,16 +117,28 @@ func (c *CommunityGalleryImageVersionsServerTransport) dispatchGet(req *http.Req func (c *CommunityGalleryImageVersionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if c.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if c.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/communityGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/communityGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` 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) } - resp := c.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publicGalleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publicGalleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicGalleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListPager(locationUnescaped, publicGalleryNameUnescaped, galleryImageNameUnescaped, nil) c.newListPager = &resp server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armcompute.CommunityGalleryImageVersionsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go index 66f889598d4c..895cb2ab8686 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhostgroups_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -100,11 +101,11 @@ func (d *DedicatedHostGroupsServerTransport) Do(req *http.Request) (*http.Respon func (d *DedicatedHostGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { if d.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-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?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) } @@ -112,7 +113,15 @@ func (d *DedicatedHostGroupsServerTransport) dispatchCreateOrUpdate(req *http.Re if err != nil { return nil, err } - respr, errRespr := d.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -129,15 +138,23 @@ func (d *DedicatedHostGroupsServerTransport) dispatchCreateOrUpdate(req *http.Re func (d *DedicatedHostGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { if d.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?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.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Delete(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -154,23 +171,35 @@ func (d *DedicatedHostGroupsServerTransport) dispatchDelete(req *http.Request) ( func (d *DedicatedHostGroupsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.InstanceViewTypes(expandUnescaped)) var options *armcompute.DedicatedHostGroupsClientGetOptions if expandParam != nil { options = &armcompute.DedicatedHostGroupsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], options) + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -187,16 +216,20 @@ func (d *DedicatedHostGroupsServerTransport) dispatchGet(req *http.Request) (*ht func (d *DedicatedHostGroupsServerTransport) 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.Compute/hostGroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups` 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) } - resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) d.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DedicatedHostGroupsClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -217,12 +250,12 @@ func (d *DedicatedHostGroupsServerTransport) dispatchNewListByResourceGroupPager func (d *DedicatedHostGroupsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { if d.srv.NewListBySubscriptionPager == nil { - return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} } if d.newListBySubscriptionPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups` 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) } @@ -247,11 +280,11 @@ func (d *DedicatedHostGroupsServerTransport) dispatchNewListBySubscriptionPager( func (d *DedicatedHostGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { if d.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-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?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) } @@ -259,7 +292,15 @@ func (d *DedicatedHostGroupsServerTransport) dispatchUpdate(req *http.Request) ( if err != nil { return nil, err } - respr, errRespr := d.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Update(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go index c779a3ecd685..a7f6d5390ba5 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/dedicatedhosts_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -110,12 +111,12 @@ func (d *DedicatedHostsServerTransport) Do(req *http.Request) (*http.Response, e func (d *DedicatedHostsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts/(?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) } @@ -123,7 +124,19 @@ func (d *DedicatedHostsServerTransport) dispatchBeginCreateOrUpdate(req *http.Re if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + hostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, hostNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -147,16 +160,28 @@ func (d *DedicatedHostsServerTransport) dispatchBeginCreateOrUpdate(req *http.Re func (d *DedicatedHostsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts/(?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.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + hostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, hostNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -180,23 +205,39 @@ func (d *DedicatedHostsServerTransport) dispatchBeginDelete(req *http.Request) ( func (d *DedicatedHostsServerTransport) 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.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + hostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.InstanceViewTypes(expandUnescaped)) var options *armcompute.DedicatedHostsClientGetOptions if expandParam != nil { options = &armcompute.DedicatedHostsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := d.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], options) + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, hostNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -213,16 +254,28 @@ func (d *DedicatedHostsServerTransport) dispatchGet(req *http.Request) (*http.Re func (d *DedicatedHostsServerTransport) dispatchNewListAvailableSizesPager(req *http.Request) (*http.Response, error) { if d.srv.NewListAvailableSizesPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAvailableSizesPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAvailableSizesPager not implemented")} } if d.newListAvailableSizesPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)/hostSizes" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hostSizes` 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) } - resp := d.srv.NewListAvailableSizesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + hostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListAvailableSizesPager(resourceGroupNameUnescaped, hostGroupNameUnescaped, hostNameUnescaped, nil) d.newListAvailableSizesPager = &resp } resp, err := server.PagerResponderNext(d.newListAvailableSizesPager, req) @@ -240,16 +293,24 @@ func (d *DedicatedHostsServerTransport) dispatchNewListAvailableSizesPager(req * func (d *DedicatedHostsServerTransport) dispatchNewListByHostGroupPager(req *http.Request) (*http.Response, error) { if d.srv.NewListByHostGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByHostGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByHostGroupPager not implemented")} } if d.newListByHostGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts` 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) } - resp := d.srv.NewListByHostGroupPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListByHostGroupPager(resourceGroupNameUnescaped, hostGroupNameUnescaped, nil) d.newListByHostGroupPager = &resp server.PagerResponderInjectNextLinks(d.newListByHostGroupPager, req, func(page *armcompute.DedicatedHostsClientListByHostGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -270,16 +331,28 @@ func (d *DedicatedHostsServerTransport) dispatchNewListByHostGroupPager(req *htt func (d *DedicatedHostsServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { if d.srv.BeginRestart == nil { - return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} } if d.beginRestart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)/restart" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 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.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + hostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginRestart(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, hostNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -303,12 +376,12 @@ func (d *DedicatedHostsServerTransport) dispatchBeginRestart(req *http.Request) func (d *DedicatedHostsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if d.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if d.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/hostGroups/(?P[a-zA-Z0-9-_]+)/hosts/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/hostGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hosts/(?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) } @@ -316,7 +389,19 @@ func (d *DedicatedHostsServerTransport) dispatchBeginUpdate(req *http.Request) ( if err != nil { return nil, err } - respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("hostGroupName")], matches[regex.SubexpIndex("hostName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hostGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostGroupName")]) + if err != nil { + return nil, err + } + hostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hostName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, hostGroupNameUnescaped, hostNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go b/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go index 62a452548b8e..6e46387e0691 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/diskaccesses_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -136,12 +137,12 @@ func (d *DiskAccessesServerTransport) Do(req *http.Request) (*http.Response, err func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?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) } @@ -149,7 +150,15 @@ func (d *DiskAccessesServerTransport) dispatchBeginCreateOrUpdate(req *http.Requ if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -173,16 +182,24 @@ func (d *DiskAccessesServerTransport) dispatchBeginCreateOrUpdate(req *http.Requ func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?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("diskAccessName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -206,16 +223,28 @@ func (d *DiskAccessesServerTransport) dispatchBeginDelete(req *http.Request) (*h func (d *DiskAccessesServerTransport) dispatchBeginDeleteAPrivateEndpointConnection(req *http.Request) (*http.Response, error) { if d.srv.BeginDeleteAPrivateEndpointConnection == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteAPrivateEndpointConnection not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAPrivateEndpointConnection not implemented")} } if d.beginDeleteAPrivateEndpointConnection == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?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.BeginDeleteAPrivateEndpointConnection(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], matches[regex.SubexpIndex("privateEndpointConnectionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + privateEndpointConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDeleteAPrivateEndpointConnection(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, privateEndpointConnectionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -239,15 +268,23 @@ func (d *DiskAccessesServerTransport) dispatchBeginDeleteAPrivateEndpointConnect func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?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("diskAccessName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -264,15 +301,27 @@ func (d *DiskAccessesServerTransport) dispatchGet(req *http.Request) (*http.Resp func (d *DiskAccessesServerTransport) dispatchGetAPrivateEndpointConnection(req *http.Request) (*http.Response, error) { if d.srv.GetAPrivateEndpointConnection == nil { - return nil, &nonRetriableError{errors.New("method GetAPrivateEndpointConnection not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetAPrivateEndpointConnection not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?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.GetAPrivateEndpointConnection(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], matches[regex.SubexpIndex("privateEndpointConnectionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + privateEndpointConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAPrivateEndpointConnection(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, privateEndpointConnectionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -289,15 +338,23 @@ func (d *DiskAccessesServerTransport) dispatchGetAPrivateEndpointConnection(req func (d *DiskAccessesServerTransport) dispatchGetPrivateLinkResources(req *http.Request) (*http.Response, error) { if d.srv.GetPrivateLinkResources == nil { - return nil, &nonRetriableError{errors.New("method GetPrivateLinkResources not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetPrivateLinkResources not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateLinkResources" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateLinkResources` 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.GetPrivateLinkResources(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetPrivateLinkResources(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -314,12 +371,12 @@ func (d *DiskAccessesServerTransport) dispatchGetPrivateLinkResources(req *http. func (d *DiskAccessesServerTransport) 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-_]+)/providers/Microsoft.Compute/diskAccesses" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses` 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) } @@ -344,16 +401,20 @@ func (d *DiskAccessesServerTransport) dispatchNewListPager(req *http.Request) (* func (d *DiskAccessesServerTransport) 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.Compute/diskAccesses" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses` 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) } - resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) d.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DiskAccessesClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -374,16 +435,24 @@ func (d *DiskAccessesServerTransport) dispatchNewListByResourceGroupPager(req *h func (d *DiskAccessesServerTransport) dispatchNewListPrivateEndpointConnectionsPager(req *http.Request) (*http.Response, error) { if d.srv.NewListPrivateEndpointConnectionsPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPrivateEndpointConnectionsPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPrivateEndpointConnectionsPager not implemented")} } if d.newListPrivateEndpointConnectionsPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections` 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) } - resp := d.srv.NewListPrivateEndpointConnectionsPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListPrivateEndpointConnectionsPager(resourceGroupNameUnescaped, diskAccessNameUnescaped, nil) d.newListPrivateEndpointConnectionsPager = &resp server.PagerResponderInjectNextLinks(d.newListPrivateEndpointConnectionsPager, req, func(page *armcompute.DiskAccessesClientListPrivateEndpointConnectionsResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -404,12 +473,12 @@ func (d *DiskAccessesServerTransport) dispatchNewListPrivateEndpointConnectionsP func (d *DiskAccessesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if d.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if d.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?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) } @@ -417,7 +486,15 @@ func (d *DiskAccessesServerTransport) dispatchBeginUpdate(req *http.Request) (*h if err != nil { return nil, err } - respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -441,12 +518,12 @@ func (d *DiskAccessesServerTransport) dispatchBeginUpdate(req *http.Request) (*h func (d *DiskAccessesServerTransport) dispatchBeginUpdateAPrivateEndpointConnection(req *http.Request) (*http.Response, error) { if d.srv.BeginUpdateAPrivateEndpointConnection == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdateAPrivateEndpointConnection not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateAPrivateEndpointConnection not implemented")} } if d.beginUpdateAPrivateEndpointConnection == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskAccesses/(?P[a-zA-Z0-9-_]+)/privateEndpointConnections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskAccesses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?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) } @@ -454,7 +531,19 @@ func (d *DiskAccessesServerTransport) dispatchBeginUpdateAPrivateEndpointConnect if err != nil { return nil, err } - respr, errRespr := d.srv.BeginUpdateAPrivateEndpointConnection(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskAccessName")], matches[regex.SubexpIndex("privateEndpointConnectionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskAccessNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskAccessName")]) + if err != nil { + return nil, err + } + privateEndpointConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdateAPrivateEndpointConnection(req.Context(), resourceGroupNameUnescaped, diskAccessNameUnescaped, privateEndpointConnectionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go b/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go index 5a3ae2e39ac5..66f8b5b6113c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/diskencryptionsets_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -110,12 +111,12 @@ func (d *DiskEncryptionSetsServerTransport) Do(req *http.Request) (*http.Respons func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets/(?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) } @@ -123,7 +124,15 @@ func (d *DiskEncryptionSetsServerTransport) dispatchBeginCreateOrUpdate(req *htt if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskEncryptionSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskEncryptionSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskEncryptionSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, diskEncryptionSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -147,16 +156,24 @@ func (d *DiskEncryptionSetsServerTransport) dispatchBeginCreateOrUpdate(req *htt func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets/(?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("diskEncryptionSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskEncryptionSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskEncryptionSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, diskEncryptionSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -180,15 +197,23 @@ func (d *DiskEncryptionSetsServerTransport) dispatchBeginDelete(req *http.Reques func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets/(?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("diskEncryptionSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskEncryptionSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskEncryptionSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, diskEncryptionSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -205,12 +230,12 @@ func (d *DiskEncryptionSetsServerTransport) dispatchGet(req *http.Request) (*htt func (d *DiskEncryptionSetsServerTransport) 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-_]+)/providers/Microsoft.Compute/diskEncryptionSets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets` 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) } @@ -235,16 +260,24 @@ func (d *DiskEncryptionSetsServerTransport) dispatchNewListPager(req *http.Reque func (d *DiskEncryptionSetsServerTransport) dispatchNewListAssociatedResourcesPager(req *http.Request) (*http.Response, error) { if d.srv.NewListAssociatedResourcesPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAssociatedResourcesPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAssociatedResourcesPager not implemented")} } if d.newListAssociatedResourcesPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskEncryptionSets/(?P[a-zA-Z0-9-_]+)/associatedResources" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/associatedResources` 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) } - resp := d.srv.NewListAssociatedResourcesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskEncryptionSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskEncryptionSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskEncryptionSetName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListAssociatedResourcesPager(resourceGroupNameUnescaped, diskEncryptionSetNameUnescaped, nil) d.newListAssociatedResourcesPager = &resp server.PagerResponderInjectNextLinks(d.newListAssociatedResourcesPager, req, func(page *armcompute.DiskEncryptionSetsClientListAssociatedResourcesResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -265,16 +298,20 @@ func (d *DiskEncryptionSetsServerTransport) dispatchNewListAssociatedResourcesPa func (d *DiskEncryptionSetsServerTransport) 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.Compute/diskEncryptionSets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets` 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) } - resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) d.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DiskEncryptionSetsClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -295,12 +332,12 @@ func (d *DiskEncryptionSetsServerTransport) dispatchNewListByResourceGroupPager( func (d *DiskEncryptionSetsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if d.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if d.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/diskEncryptionSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/diskEncryptionSets/(?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) } @@ -308,7 +345,15 @@ func (d *DiskEncryptionSetsServerTransport) dispatchBeginUpdate(req *http.Reques if err != nil { return nil, err } - respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskEncryptionSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskEncryptionSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskEncryptionSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, diskEncryptionSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go b/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go index f1b0e50e2632..d91d690cf622 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/diskrestorepoint_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -89,15 +90,31 @@ func (d *DiskRestorePointServerTransport) Do(req *http.Request) (*http.Response, func (d *DiskRestorePointServerTransport) 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.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/diskRestorePoints/(?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) < 5 { 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("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], matches[regex.SubexpIndex("diskRestorePointName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + vmRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmRestorePointName")]) + if err != nil { + return nil, err + } + diskRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskRestorePointName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, vmRestorePointNameUnescaped, diskRestorePointNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -114,12 +131,12 @@ func (d *DiskRestorePointServerTransport) dispatchGet(req *http.Request) (*http. func (d *DiskRestorePointServerTransport) dispatchBeginGrantAccess(req *http.Request) (*http.Response, error) { if d.srv.BeginGrantAccess == nil { - return nil, &nonRetriableError{errors.New("method BeginGrantAccess not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginGrantAccess not implemented")} } if d.beginGrantAccess == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints/(?P[a-zA-Z0-9-_]+)/beginGetAccess" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/diskRestorePoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/beginGetAccess` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -127,7 +144,23 @@ func (d *DiskRestorePointServerTransport) dispatchBeginGrantAccess(req *http.Req if err != nil { return nil, err } - respr, errRespr := d.srv.BeginGrantAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], matches[regex.SubexpIndex("diskRestorePointName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + vmRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmRestorePointName")]) + if err != nil { + return nil, err + } + diskRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskRestorePointName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginGrantAccess(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, vmRestorePointNameUnescaped, diskRestorePointNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -151,16 +184,28 @@ func (d *DiskRestorePointServerTransport) dispatchBeginGrantAccess(req *http.Req func (d *DiskRestorePointServerTransport) dispatchNewListByRestorePointPager(req *http.Request) (*http.Response, error) { if d.srv.NewListByRestorePointPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByRestorePointPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByRestorePointPager not implemented")} } if d.newListByRestorePointPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/diskRestorePoints` 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) } - resp := d.srv.NewListByRestorePointPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + vmRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmRestorePointName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListByRestorePointPager(resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, vmRestorePointNameUnescaped, nil) d.newListByRestorePointPager = &resp server.PagerResponderInjectNextLinks(d.newListByRestorePointPager, req, func(page *armcompute.DiskRestorePointClientListByRestorePointResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -181,16 +226,32 @@ func (d *DiskRestorePointServerTransport) dispatchNewListByRestorePointPager(req func (d *DiskRestorePointServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*http.Response, error) { if d.srv.BeginRevokeAccess == nil { - return nil, &nonRetriableError{errors.New("method BeginRevokeAccess not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRevokeAccess not implemented")} } if d.beginRevokeAccess == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)/diskRestorePoints/(?P[a-zA-Z0-9-_]+)/endGetAccess" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/diskRestorePoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/endGetAccess` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := d.srv.BeginRevokeAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("vmRestorePointName")], matches[regex.SubexpIndex("diskRestorePointName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + vmRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmRestorePointName")]) + if err != nil { + return nil, err + } + diskRestorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskRestorePointName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginRevokeAccess(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, vmRestorePointNameUnescaped, diskRestorePointNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/disks_server.go b/sdk/resourcemanager/compute/armcompute/fake/disks_server.go index 9296e520ef52..b190cd1c3129 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/disks_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/disks_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -117,12 +118,12 @@ func (d *DisksServerTransport) Do(req *http.Request) (*http.Response, error) { func (d *DisksServerTransport) 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.Compute/disks/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks/(?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) } @@ -130,7 +131,15 @@ func (d *DisksServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (* if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, diskNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -154,16 +163,24 @@ func (d *DisksServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (* func (d *DisksServerTransport) 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.Compute/disks/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks/(?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("diskName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, diskNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -187,15 +204,23 @@ func (d *DisksServerTransport) dispatchBeginDelete(req *http.Request) (*http.Res func (d *DisksServerTransport) 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.Compute/disks/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks/(?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("diskName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, diskNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -212,12 +237,12 @@ func (d *DisksServerTransport) dispatchGet(req *http.Request) (*http.Response, e func (d *DisksServerTransport) dispatchBeginGrantAccess(req *http.Request) (*http.Response, error) { if d.srv.BeginGrantAccess == nil { - return nil, &nonRetriableError{errors.New("method BeginGrantAccess not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginGrantAccess not implemented")} } if d.beginGrantAccess == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/disks/(?P[a-zA-Z0-9-_]+)/beginGetAccess" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/beginGetAccess` 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) } @@ -225,7 +250,15 @@ func (d *DisksServerTransport) dispatchBeginGrantAccess(req *http.Request) (*htt if err != nil { return nil, err } - respr, errRespr := d.srv.BeginGrantAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginGrantAccess(req.Context(), resourceGroupNameUnescaped, diskNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -249,12 +282,12 @@ func (d *DisksServerTransport) dispatchBeginGrantAccess(req *http.Request) (*htt func (d *DisksServerTransport) 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-_]+)/providers/Microsoft.Compute/disks" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks` 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) } @@ -279,16 +312,20 @@ func (d *DisksServerTransport) dispatchNewListPager(req *http.Request) (*http.Re func (d *DisksServerTransport) 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.Compute/disks" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks` 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) } - resp := d.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) d.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(d.newListByResourceGroupPager, req, func(page *armcompute.DisksClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -309,16 +346,24 @@ func (d *DisksServerTransport) dispatchNewListByResourceGroupPager(req *http.Req func (d *DisksServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*http.Response, error) { if d.srv.BeginRevokeAccess == nil { - return nil, &nonRetriableError{errors.New("method BeginRevokeAccess not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRevokeAccess not implemented")} } if d.beginRevokeAccess == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/disks/(?P[a-zA-Z0-9-_]+)/endGetAccess" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/endGetAccess` 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.BeginRevokeAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginRevokeAccess(req.Context(), resourceGroupNameUnescaped, diskNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -342,12 +387,12 @@ func (d *DisksServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*ht func (d *DisksServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if d.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if d.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/disks/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/disks/(?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) } @@ -355,7 +400,15 @@ func (d *DisksServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Res if err != nil { return nil, err } - respr, errRespr := d.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("diskName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + diskNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("diskName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, diskNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleries_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleries_server.go index 0bf85e26152d..c86071662757 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/galleries_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/galleries_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -103,12 +104,12 @@ func (g *GalleriesServerTransport) Do(req *http.Request) (*http.Response, error) func (g *GalleriesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if g.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?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) } @@ -116,7 +117,15 @@ func (g *GalleriesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request if err != nil { return nil, err } - respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -140,16 +149,24 @@ func (g *GalleriesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request func (g *GalleriesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if g.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if g.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?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 := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -173,17 +190,33 @@ func (g *GalleriesServerTransport) dispatchBeginDelete(req *http.Request) (*http func (g *GalleriesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?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) } qp := req.URL.Query() - selectParam := getOptional(armcompute.SelectPermissions(qp.Get("$select"))) - expandParam := getOptional(armcompute.GalleryExpandParams(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + selectUnescaped, err := url.QueryUnescape(qp.Get("$select")) + if err != nil { + return nil, err + } + selectParam := getOptional(armcompute.SelectPermissions(selectUnescaped)) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.GalleryExpandParams(expandUnescaped)) var options *armcompute.GalleriesClientGetOptions if selectParam != nil || expandParam != nil { options = &armcompute.GalleriesClientGetOptions{ @@ -191,7 +224,7 @@ func (g *GalleriesServerTransport) dispatchGet(req *http.Request) (*http.Respons Expand: expandParam, } } - respr, errRespr := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], options) + respr, errRespr := g.srv.Get(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -208,12 +241,12 @@ func (g *GalleriesServerTransport) dispatchGet(req *http.Request) (*http.Respons func (g *GalleriesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if g.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if g.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries` 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) } @@ -238,16 +271,20 @@ func (g *GalleriesServerTransport) dispatchNewListPager(req *http.Request) (*htt func (g *GalleriesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if g.srv.NewListByResourceGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } if g.newListByResourceGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries` 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) } - resp := g.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := g.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) g.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(g.newListByResourceGroupPager, req, func(page *armcompute.GalleriesClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -268,12 +305,12 @@ func (g *GalleriesServerTransport) dispatchNewListByResourceGroupPager(req *http func (g *GalleriesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if g.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?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) } @@ -281,7 +318,15 @@ func (g *GalleriesServerTransport) dispatchBeginUpdate(req *http.Request) (*http if err != nil { return nil, err } - respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go index d4b01209314a..ec505359bbea 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryapplications_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (g *GalleryApplicationsServerTransport) Do(req *http.Request) (*http.Respon func (g *GalleryApplicationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if g.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?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) } @@ -109,7 +110,19 @@ func (g *GalleryApplicationsServerTransport) dispatchBeginCreateOrUpdate(req *ht if err != nil { return nil, err } - respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +146,28 @@ func (g *GalleryApplicationsServerTransport) dispatchBeginCreateOrUpdate(req *ht func (g *GalleryApplicationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if g.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if g.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?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 := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,15 +191,27 @@ func (g *GalleryApplicationsServerTransport) dispatchBeginDelete(req *http.Reque func (g *GalleryApplicationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?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 := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.Get(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -191,16 +228,24 @@ func (g *GalleryApplicationsServerTransport) dispatchGet(req *http.Request) (*ht func (g *GalleryApplicationsServerTransport) dispatchNewListByGalleryPager(req *http.Request) (*http.Response, error) { if g.srv.NewListByGalleryPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByGalleryPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByGalleryPager not implemented")} } if g.newListByGalleryPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications` 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) } - resp := g.srv.NewListByGalleryPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + resp := g.srv.NewListByGalleryPager(resourceGroupNameUnescaped, galleryNameUnescaped, nil) g.newListByGalleryPager = &resp server.PagerResponderInjectNextLinks(g.newListByGalleryPager, req, func(page *armcompute.GalleryApplicationsClientListByGalleryResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -221,12 +266,12 @@ func (g *GalleryApplicationsServerTransport) dispatchNewListByGalleryPager(req * func (g *GalleryApplicationsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if g.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?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) } @@ -234,7 +279,19 @@ func (g *GalleryApplicationsServerTransport) dispatchBeginUpdate(req *http.Reque if err != nil { return nil, err } - respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go index 119ba9fc16e6..ccf4b614129c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryapplicationversions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (g *GalleryApplicationVersionsServerTransport) Do(req *http.Request) (*http func (g *GalleryApplicationVersionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if g.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -109,7 +110,23 @@ func (g *GalleryApplicationVersionsServerTransport) dispatchBeginCreateOrUpdate( if err != nil { return nil, err } - respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + galleryApplicationVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, galleryApplicationVersionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +150,32 @@ func (g *GalleryApplicationVersionsServerTransport) dispatchBeginCreateOrUpdate( func (g *GalleryApplicationVersionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if g.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if g.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + galleryApplicationVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, galleryApplicationVersionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,23 +199,43 @@ func (g *GalleryApplicationVersionsServerTransport) dispatchBeginDelete(req *htt func (g *GalleryApplicationVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(armcompute.ReplicationStatusTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + galleryApplicationVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationVersionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.ReplicationStatusTypes(expandUnescaped)) var options *armcompute.GalleryApplicationVersionsClientGetOptions if expandParam != nil { options = &armcompute.GalleryApplicationVersionsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], options) + respr, errRespr := g.srv.Get(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, galleryApplicationVersionNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -199,16 +252,28 @@ func (g *GalleryApplicationVersionsServerTransport) dispatchGet(req *http.Reques func (g *GalleryApplicationVersionsServerTransport) dispatchNewListByGalleryApplicationPager(req *http.Request) (*http.Response, error) { if g.srv.NewListByGalleryApplicationPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByGalleryApplicationPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByGalleryApplicationPager not implemented")} } if g.newListByGalleryApplicationPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` 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) } - resp := g.srv.NewListByGalleryApplicationPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + resp := g.srv.NewListByGalleryApplicationPager(resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, nil) g.newListByGalleryApplicationPager = &resp server.PagerResponderInjectNextLinks(g.newListByGalleryApplicationPager, req, func(page *armcompute.GalleryApplicationVersionsClientListByGalleryApplicationResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -229,12 +294,12 @@ func (g *GalleryApplicationVersionsServerTransport) dispatchNewListByGalleryAppl func (g *GalleryApplicationVersionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if g.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/applications/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applications/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -242,7 +307,23 @@ func (g *GalleryApplicationVersionsServerTransport) dispatchBeginUpdate(req *htt if err != nil { return nil, err } - respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryApplicationName")], matches[regex.SubexpIndex("galleryApplicationVersionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryApplicationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationName")]) + if err != nil { + return nil, err + } + galleryApplicationVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryApplicationVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryApplicationNameUnescaped, galleryApplicationVersionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go index 2f21a50e6772..9fe025c69acf 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/galleryimages_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryimages_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (g *GalleryImagesServerTransport) Do(req *http.Request) (*http.Response, er func (g *GalleryImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if g.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?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) } @@ -109,7 +110,19 @@ func (g *GalleryImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Req if err != nil { return nil, err } - respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +146,28 @@ func (g *GalleryImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Req func (g *GalleryImagesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if g.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if g.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?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 := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,15 +191,27 @@ func (g *GalleryImagesServerTransport) dispatchBeginDelete(req *http.Request) (* func (g *GalleryImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?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 := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.Get(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -191,16 +228,24 @@ func (g *GalleryImagesServerTransport) dispatchGet(req *http.Request) (*http.Res func (g *GalleryImagesServerTransport) dispatchNewListByGalleryPager(req *http.Request) (*http.Response, error) { if g.srv.NewListByGalleryPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByGalleryPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByGalleryPager not implemented")} } if g.newListByGalleryPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images` 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) } - resp := g.srv.NewListByGalleryPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + resp := g.srv.NewListByGalleryPager(resourceGroupNameUnescaped, galleryNameUnescaped, nil) g.newListByGalleryPager = &resp server.PagerResponderInjectNextLinks(g.newListByGalleryPager, req, func(page *armcompute.GalleryImagesClientListByGalleryResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -221,12 +266,12 @@ func (g *GalleryImagesServerTransport) dispatchNewListByGalleryPager(req *http.R func (g *GalleryImagesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if g.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?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) } @@ -234,7 +279,19 @@ func (g *GalleryImagesServerTransport) dispatchBeginUpdate(req *http.Request) (* if err != nil { return nil, err } - respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go index 3f71f9cef802..2add4cd73d91 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/galleryimageversions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (g *GalleryImageVersionsServerTransport) Do(req *http.Request) (*http.Respo func (g *GalleryImageVersionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if g.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -109,7 +110,23 @@ func (g *GalleryImageVersionsServerTransport) dispatchBeginCreateOrUpdate(req *h if err != nil { return nil, err } - respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + galleryImageVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, galleryImageVersionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +150,32 @@ func (g *GalleryImageVersionsServerTransport) dispatchBeginCreateOrUpdate(req *h func (g *GalleryImageVersionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if g.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if g.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := g.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + galleryImageVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, galleryImageVersionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,23 +199,43 @@ func (g *GalleryImageVersionsServerTransport) dispatchBeginDelete(req *http.Requ func (g *GalleryImageVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if g.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.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(armcompute.ReplicationStatusTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + galleryImageVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageVersionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.ReplicationStatusTypes(expandUnescaped)) var options *armcompute.GalleryImageVersionsClientGetOptions if expandParam != nil { options = &armcompute.GalleryImageVersionsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := g.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], options) + respr, errRespr := g.srv.Get(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, galleryImageVersionNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -199,16 +252,28 @@ func (g *GalleryImageVersionsServerTransport) dispatchGet(req *http.Request) (*h func (g *GalleryImageVersionsServerTransport) dispatchNewListByGalleryImagePager(req *http.Request) (*http.Response, error) { if g.srv.NewListByGalleryImagePager == nil { - return nil, &nonRetriableError{errors.New("method NewListByGalleryImagePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByGalleryImagePager not implemented")} } if g.newListByGalleryImagePager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` 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) } - resp := g.srv.NewListByGalleryImagePager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + resp := g.srv.NewListByGalleryImagePager(resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, nil) g.newListByGalleryImagePager = &resp server.PagerResponderInjectNextLinks(g.newListByGalleryImagePager, req, func(page *armcompute.GalleryImageVersionsClientListByGalleryImageResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -229,12 +294,12 @@ func (g *GalleryImageVersionsServerTransport) dispatchNewListByGalleryImagePager func (g *GalleryImageVersionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if g.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -242,7 +307,23 @@ func (g *GalleryImageVersionsServerTransport) dispatchBeginUpdate(req *http.Requ if err != nil { return nil, err } - respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + galleryImageVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, galleryImageNameUnescaped, galleryImageVersionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go b/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go index aedf524107fd..d8157d5f0d6c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/gallerysharingprofile_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -68,12 +69,12 @@ func (g *GallerySharingProfileServerTransport) Do(req *http.Request) (*http.Resp func (g *GallerySharingProfileServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if g.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if g.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/galleries/(?P[a-zA-Z0-9-_]+)/share" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/galleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/share` 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) } @@ -81,7 +82,15 @@ func (g *GallerySharingProfileServerTransport) dispatchBeginUpdate(req *http.Req if err != nil { return nil, err } - respr, errRespr := g.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("galleryName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + galleryNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, galleryNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/images_server.go b/sdk/resourcemanager/compute/armcompute/fake/images_server.go index 170d33911c14..da04f379118c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/images_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/images_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -103,12 +104,12 @@ func (i *ImagesServerTransport) Do(req *http.Request) (*http.Response, error) { func (i *ImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if i.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if i.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/images/(?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) } @@ -116,7 +117,15 @@ func (i *ImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) ( if err != nil { return nil, err } - respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + imageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("imageName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, imageNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -140,16 +149,24 @@ func (i *ImagesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) ( func (i *ImagesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if i.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if i.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/images/(?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 := i.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + imageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("imageName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, imageNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -173,23 +190,35 @@ func (i *ImagesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Re func (i *ImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if i.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.Compute/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/images/(?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) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + imageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("imageName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.ImagesClientGetOptions if expandParam != nil { options = &armcompute.ImagesClientGetOptions{ Expand: expandParam, } } - respr, errRespr := i.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], options) + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, imageNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -206,12 +235,12 @@ func (i *ImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, func (i *ImagesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if i.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if i.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/images` 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) } @@ -236,16 +265,20 @@ func (i *ImagesServerTransport) dispatchNewListPager(req *http.Request) (*http.R func (i *ImagesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if i.srv.NewListByResourceGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } if i.newListByResourceGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/images` 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) } - resp := i.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) i.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(i.newListByResourceGroupPager, req, func(page *armcompute.ImagesClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -266,12 +299,12 @@ func (i *ImagesServerTransport) dispatchNewListByResourceGroupPager(req *http.Re func (i *ImagesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if i.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if i.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/images/(?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) } @@ -279,7 +312,15 @@ func (i *ImagesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Re if err != nil { return nil, err } - respr, errRespr := i.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("imageName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + imageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("imageName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, imageNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/loganalytics_server.go b/sdk/resourcemanager/compute/armcompute/fake/loganalytics_server.go index ab3e6ce3f519..8c2a7b5ebc75 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/loganalytics_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/loganalytics_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,12 +76,12 @@ func (l *LogAnalyticsServerTransport) Do(req *http.Request) (*http.Response, err func (l *LogAnalyticsServerTransport) dispatchBeginExportRequestRateByInterval(req *http.Request) (*http.Response, error) { if l.srv.BeginExportRequestRateByInterval == nil { - return nil, &nonRetriableError{errors.New("method BeginExportRequestRateByInterval not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginExportRequestRateByInterval not implemented")} } if l.beginExportRequestRateByInterval == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/logAnalytics/apiAccess/getRequestRateByInterval" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/logAnalytics/apiAccess/getRequestRateByInterval` 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) } @@ -88,7 +89,11 @@ func (l *LogAnalyticsServerTransport) dispatchBeginExportRequestRateByInterval(r if err != nil { return nil, err } - respr, errRespr := l.srv.BeginExportRequestRateByInterval(req.Context(), matches[regex.SubexpIndex("location")], body, nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginExportRequestRateByInterval(req.Context(), locationUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -112,12 +117,12 @@ func (l *LogAnalyticsServerTransport) dispatchBeginExportRequestRateByInterval(r func (l *LogAnalyticsServerTransport) dispatchBeginExportThrottledRequests(req *http.Request) (*http.Response, error) { if l.srv.BeginExportThrottledRequests == nil { - return nil, &nonRetriableError{errors.New("method BeginExportThrottledRequests not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginExportThrottledRequests not implemented")} } if l.beginExportThrottledRequests == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/logAnalytics/apiAccess/getThrottledRequests" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/logAnalytics/apiAccess/getThrottledRequests` 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) } @@ -125,7 +130,11 @@ func (l *LogAnalyticsServerTransport) dispatchBeginExportThrottledRequests(req * if err != nil { return nil, err } - respr, errRespr := l.srv.BeginExportThrottledRequests(req.Context(), matches[regex.SubexpIndex("location")], body, nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginExportThrottledRequests(req.Context(), locationUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/operations_server.go b/sdk/resourcemanager/compute/armcompute/fake/operations_server.go index 34ef72d4db85..cd6fa60a9598 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/operations_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/operations_server.go @@ -66,7 +66,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/compute/armcompute/fake/proximityplacementgroups_server.go b/sdk/resourcemanager/compute/armcompute/fake/proximityplacementgroups_server.go index eb8904bf214e..b067d0d6790a 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/proximityplacementgroups_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/proximityplacementgroups_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -100,11 +101,11 @@ func (p *ProximityPlacementGroupsServerTransport) Do(req *http.Request) (*http.R func (p *ProximityPlacementGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { if p.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-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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) } @@ -112,7 +113,15 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchCreateOrUpdate(req *ht if err != nil { return nil, err } - respr, errRespr := p.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + proximityPlacementGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("proximityPlacementGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, proximityPlacementGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -129,15 +138,23 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchCreateOrUpdate(req *ht func (p *ProximityPlacementGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { if p.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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 := p.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + proximityPlacementGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("proximityPlacementGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Delete(req.Context(), resourceGroupNameUnescaped, proximityPlacementGroupNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -154,23 +171,35 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchDelete(req *http.Reque func (p *ProximityPlacementGroupsServerTransport) 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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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) } qp := req.URL.Query() - includeColocationStatusParam := getOptional(qp.Get("includeColocationStatus")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + proximityPlacementGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("proximityPlacementGroupName")]) + if err != nil { + return nil, err + } + includeColocationStatusUnescaped, err := url.QueryUnescape(qp.Get("includeColocationStatus")) + if err != nil { + return nil, err + } + includeColocationStatusParam := getOptional(includeColocationStatusUnescaped) var options *armcompute.ProximityPlacementGroupsClientGetOptions if includeColocationStatusParam != nil { options = &armcompute.ProximityPlacementGroupsClientGetOptions{ IncludeColocationStatus: includeColocationStatusParam, } } - respr, errRespr := p.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], options) + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, proximityPlacementGroupNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -187,16 +216,20 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchGet(req *http.Request) func (p *ProximityPlacementGroupsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if p.srv.NewListByResourceGroupPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByResourceGroupPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } if p.newListByResourceGroupPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/proximityPlacementGroups` 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) } - resp := p.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) p.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(p.newListByResourceGroupPager, req, func(page *armcompute.ProximityPlacementGroupsClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -217,12 +250,12 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchNewListByResourceGroup func (p *ProximityPlacementGroupsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { if p.srv.NewListBySubscriptionPager == nil { - return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} } if p.newListBySubscriptionPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/proximityPlacementGroups" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/proximityPlacementGroups` 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) } @@ -247,11 +280,11 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchNewListBySubscriptionP func (p *ProximityPlacementGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { if p.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-_]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/proximityPlacementGroups/(?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) } @@ -259,7 +292,15 @@ func (p *ProximityPlacementGroupsServerTransport) dispatchUpdate(req *http.Reque if err != nil { return nil, err } - respr, errRespr := p.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("proximityPlacementGroupName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + proximityPlacementGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("proximityPlacementGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Update(req.Context(), resourceGroupNameUnescaped, proximityPlacementGroupNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go b/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go index 0426bbf53c64..de5cf390f23f 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/resourceskus_server.go @@ -17,6 +17,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -68,18 +69,26 @@ func (r *ResourceSKUsServerTransport) Do(req *http.Request) (*http.Response, err func (r *ResourceSKUsServerTransport) 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-_]+)/providers/Microsoft.Compute/skus" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/skus` 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")) - includeExtendedLocationsParam := getOptional(qp.Get("includeExtendedLocations")) + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + includeExtendedLocationsUnescaped, err := url.QueryUnescape(qp.Get("includeExtendedLocations")) + if err != nil { + return nil, err + } + includeExtendedLocationsParam := getOptional(includeExtendedLocationsUnescaped) var options *armcompute.ResourceSKUsClientListOptions if filterParam != nil || includeExtendedLocationsParam != nil { options = &armcompute.ResourceSKUsClientListOptions{ diff --git a/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go b/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go index f518a03afeb9..dddd84e2a922 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/restorepointcollections_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -101,11 +102,11 @@ func (r *RestorePointCollectionsServerTransport) Do(req *http.Request) (*http.Re func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?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) } @@ -113,7 +114,15 @@ func (r *RestorePointCollectionsServerTransport) dispatchCreateOrUpdate(req *htt if err != nil { return nil, err } - respr, errRespr := r.srv.CreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -130,16 +139,24 @@ func (r *RestorePointCollectionsServerTransport) dispatchCreateOrUpdate(req *htt func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?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 := r.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -163,23 +180,35 @@ func (r *RestorePointCollectionsServerTransport) dispatchBeginDelete(req *http.R func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.RestorePointCollectionExpandOptions(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.RestorePointCollectionExpandOptions(expandUnescaped)) var options *armcompute.RestorePointCollectionsClientGetOptions if expandParam != nil { options = &armcompute.RestorePointCollectionsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := r.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], options) + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -196,16 +225,20 @@ func (r *RestorePointCollectionsServerTransport) dispatchGet(req *http.Request) func (r *RestorePointCollectionsServerTransport) 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/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections` 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) } - resp := r.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := r.srv.NewListPager(resourceGroupNameUnescaped, nil) r.newListPager = &resp server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armcompute.RestorePointCollectionsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -226,12 +259,12 @@ func (r *RestorePointCollectionsServerTransport) dispatchNewListPager(req *http. func (r *RestorePointCollectionsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { if r.srv.NewListAllPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} } if r.newListAllPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections` 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) } @@ -256,11 +289,11 @@ func (r *RestorePointCollectionsServerTransport) dispatchNewListAllPager(req *ht func (r *RestorePointCollectionsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?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) } @@ -268,7 +301,15 @@ func (r *RestorePointCollectionsServerTransport) dispatchUpdate(req *http.Reques if err != nil { return nil, err } - respr, errRespr := r.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Update(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go b/sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go index 5341e7a91c6e..0bff9e9d74a0 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/restorepoints_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/restorepoints_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -81,12 +82,12 @@ func (r *RestorePointsServerTransport) Do(req *http.Request) (*http.Response, er func (r *RestorePointsServerTransport) dispatchBeginCreate(req *http.Request) (*http.Response, error) { if r.srv.BeginCreate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreate not implemented")} } if r.beginCreate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?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) } @@ -94,7 +95,19 @@ func (r *RestorePointsServerTransport) dispatchBeginCreate(req *http.Request) (* if err != nil { return nil, err } - respr, errRespr := r.srv.BeginCreate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("restorePointName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + restorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreate(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, restorePointNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -118,16 +131,28 @@ func (r *RestorePointsServerTransport) dispatchBeginCreate(req *http.Request) (* func (r *RestorePointsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?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 := r.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("restorePointName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + restorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, restorePointNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -151,23 +176,39 @@ func (r *RestorePointsServerTransport) dispatchBeginDelete(req *http.Request) (* func (r *RestorePointsServerTransport) 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-_]+)/providers/Microsoft.Compute/restorePointCollections/(?P[a-zA-Z0-9-_]+)/restorePoints/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/restorePointCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restorePoints/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.RestorePointExpandOptions(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + restorePointCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointCollectionName")]) + if err != nil { + return nil, err + } + restorePointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("restorePointName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.RestorePointExpandOptions(expandUnescaped)) var options *armcompute.RestorePointsClientGetOptions if expandParam != nil { options = &armcompute.RestorePointsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := r.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("restorePointCollectionName")], matches[regex.SubexpIndex("restorePointName")], options) + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, restorePointCollectionNameUnescaped, restorePointNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go index 2be3c9502524..3189fb7ecce6 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleries_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,15 +76,23 @@ func (s *SharedGalleriesServerTransport) Do(req *http.Request) (*http.Response, func (s *SharedGalleriesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedGalleries/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + galleryUniqueNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryUniqueName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), locationUnescaped, galleryUniqueNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -100,24 +109,32 @@ func (s *SharedGalleriesServerTransport) dispatchGet(req *http.Request) (*http.R func (s *SharedGalleriesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedGalleries` 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() - sharedToParam := getOptional(armcompute.SharedToValues(qp.Get("sharedTo"))) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + sharedToUnescaped, err := url.QueryUnescape(qp.Get("sharedTo")) + if err != nil { + return nil, err + } + sharedToParam := getOptional(armcompute.SharedToValues(sharedToUnescaped)) var options *armcompute.SharedGalleriesClientListOptions if sharedToParam != nil { options = &armcompute.SharedGalleriesClientListOptions{ SharedTo: sharedToParam, } } - resp := s.srv.NewListPager(matches[regex.SubexpIndex("location")], options) + resp := s.srv.NewListPager(locationUnescaped, options) s.newListPager = &resp server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SharedGalleriesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go index b4aa2130aec4..449941ca06e1 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimages_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,15 +76,27 @@ func (s *SharedGalleryImagesServerTransport) Do(req *http.Request) (*http.Respon func (s *SharedGalleryImagesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], matches[regex.SubexpIndex("galleryImageName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + galleryUniqueNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryUniqueName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), locationUnescaped, galleryUniqueNameUnescaped, galleryImageNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -100,24 +113,36 @@ func (s *SharedGalleryImagesServerTransport) dispatchGet(req *http.Request) (*ht func (s *SharedGalleryImagesServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images` 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() - sharedToParam := getOptional(armcompute.SharedToValues(qp.Get("sharedTo"))) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + galleryUniqueNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryUniqueName")]) + if err != nil { + return nil, err + } + sharedToUnescaped, err := url.QueryUnescape(qp.Get("sharedTo")) + if err != nil { + return nil, err + } + sharedToParam := getOptional(armcompute.SharedToValues(sharedToUnescaped)) var options *armcompute.SharedGalleryImagesClientListOptions if sharedToParam != nil { options = &armcompute.SharedGalleryImagesClientListOptions{ SharedTo: sharedToParam, } } - resp := s.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], options) + resp := s.srv.NewListPager(locationUnescaped, galleryUniqueNameUnescaped, options) s.newListPager = &resp server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SharedGalleryImagesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go index 59224deba273..1ad694e2faa0 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/sharedgalleryimageversions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -75,15 +76,31 @@ func (s *SharedGalleryImageVersionsServerTransport) Do(req *http.Request) (*http func (s *SharedGalleryImageVersionsServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := s.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], matches[regex.SubexpIndex("galleryImageName")], matches[regex.SubexpIndex("galleryImageVersionName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + galleryUniqueNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryUniqueName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + galleryImageVersionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), locationUnescaped, galleryUniqueNameUnescaped, galleryImageNameUnescaped, galleryImageVersionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -100,24 +117,40 @@ func (s *SharedGalleryImageVersionsServerTransport) dispatchGet(req *http.Reques func (s *SharedGalleryImageVersionsServerTransport) 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-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/sharedGalleries/(?P[a-zA-Z0-9-_]+)/images/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedGalleries/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/images/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` 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) } qp := req.URL.Query() - sharedToParam := getOptional(armcompute.SharedToValues(qp.Get("sharedTo"))) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + galleryUniqueNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryUniqueName")]) + if err != nil { + return nil, err + } + galleryImageNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("galleryImageName")]) + if err != nil { + return nil, err + } + sharedToUnescaped, err := url.QueryUnescape(qp.Get("sharedTo")) + if err != nil { + return nil, err + } + sharedToParam := getOptional(armcompute.SharedToValues(sharedToUnescaped)) var options *armcompute.SharedGalleryImageVersionsClientListOptions if sharedToParam != nil { options = &armcompute.SharedGalleryImageVersionsClientListOptions{ SharedTo: sharedToParam, } } - resp := s.srv.NewListPager(matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("galleryUniqueName")], matches[regex.SubexpIndex("galleryImageName")], options) + resp := s.srv.NewListPager(locationUnescaped, galleryUniqueNameUnescaped, galleryImageNameUnescaped, options) s.newListPager = &resp server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armcompute.SharedGalleryImageVersionsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go b/sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go index 87f9c79eba20..bf457c5a3919 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/snapshots_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/snapshots_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -117,12 +118,12 @@ func (s *SnapshotsServerTransport) Do(req *http.Request) (*http.Response, error) func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots/(?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) } @@ -130,7 +131,15 @@ func (s *SnapshotsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request if err != nil { return nil, err } - respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + snapshotNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("snapshotName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, snapshotNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -154,16 +163,24 @@ func (s *SnapshotsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots/(?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 := s.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + snapshotNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("snapshotName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, snapshotNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -187,15 +204,23 @@ func (s *SnapshotsServerTransport) dispatchBeginDelete(req *http.Request) (*http func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + snapshotNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("snapshotName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, snapshotNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -212,12 +237,12 @@ func (s *SnapshotsServerTransport) dispatchGet(req *http.Request) (*http.Respons func (s *SnapshotsServerTransport) dispatchBeginGrantAccess(req *http.Request) (*http.Response, error) { if s.srv.BeginGrantAccess == nil { - return nil, &nonRetriableError{errors.New("method BeginGrantAccess not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginGrantAccess not implemented")} } if s.beginGrantAccess == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)/beginGetAccess" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/beginGetAccess` 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) } @@ -225,7 +250,15 @@ func (s *SnapshotsServerTransport) dispatchBeginGrantAccess(req *http.Request) ( if err != nil { return nil, err } - respr, errRespr := s.srv.BeginGrantAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + snapshotNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("snapshotName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginGrantAccess(req.Context(), resourceGroupNameUnescaped, snapshotNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -249,12 +282,12 @@ func (s *SnapshotsServerTransport) dispatchBeginGrantAccess(req *http.Request) ( func (s *SnapshotsServerTransport) 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-_]+)/providers/Microsoft.Compute/snapshots" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots` 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) } @@ -279,16 +312,20 @@ func (s *SnapshotsServerTransport) dispatchNewListPager(req *http.Request) (*htt func (s *SnapshotsServerTransport) 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-_]+)/providers/Microsoft.Compute/snapshots" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots` 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) } - resp := s.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) s.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armcompute.SnapshotsClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -309,16 +346,24 @@ func (s *SnapshotsServerTransport) dispatchNewListByResourceGroupPager(req *http func (s *SnapshotsServerTransport) dispatchBeginRevokeAccess(req *http.Request) (*http.Response, error) { if s.srv.BeginRevokeAccess == nil { - return nil, &nonRetriableError{errors.New("method BeginRevokeAccess not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRevokeAccess not implemented")} } if s.beginRevokeAccess == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)/endGetAccess" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/endGetAccess` 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 := s.srv.BeginRevokeAccess(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + snapshotNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("snapshotName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginRevokeAccess(req.Context(), resourceGroupNameUnescaped, snapshotNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -342,12 +387,12 @@ func (s *SnapshotsServerTransport) dispatchBeginRevokeAccess(req *http.Request) func (s *SnapshotsServerTransport) 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/Microsoft.Compute/snapshots/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/snapshots/(?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) } @@ -355,7 +400,15 @@ func (s *SnapshotsServerTransport) dispatchBeginUpdate(req *http.Request) (*http if err != nil { return nil, err } - respr, errRespr := s.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("snapshotName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + snapshotNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("snapshotName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, snapshotNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go b/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go index 970987158ddb..ac70080a158c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/sshpublickeys_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -106,11 +107,11 @@ func (s *SSHPublicKeysServerTransport) Do(req *http.Request) (*http.Response, er func (s *SSHPublicKeysServerTransport) dispatchCreate(req *http.Request) (*http.Response, error) { if s.srv.Create == nil { - return nil, &nonRetriableError{errors.New("method Create not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Create not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys/(?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) } @@ -118,7 +119,15 @@ func (s *SSHPublicKeysServerTransport) dispatchCreate(req *http.Request) (*http. if err != nil { return nil, err } - respr, errRespr := s.srv.Create(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + sshPublicKeyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sshPublicKeyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Create(req.Context(), resourceGroupNameUnescaped, sshPublicKeyNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -135,15 +144,23 @@ func (s *SSHPublicKeysServerTransport) dispatchCreate(req *http.Request) (*http. func (s *SSHPublicKeysServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { if s.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys/(?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 := s.srv.Delete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + sshPublicKeyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sshPublicKeyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), resourceGroupNameUnescaped, sshPublicKeyNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -160,15 +177,23 @@ func (s *SSHPublicKeysServerTransport) dispatchDelete(req *http.Request) (*http. func (s *SSHPublicKeysServerTransport) dispatchGenerateKeyPair(req *http.Request) (*http.Response, error) { if s.srv.GenerateKeyPair == nil { - return nil, &nonRetriableError{errors.New("method GenerateKeyPair not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GenerateKeyPair not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?P[a-zA-Z0-9-_]+)/generateKeyPair" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generateKeyPair` 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 := s.srv.GenerateKeyPair(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + sshPublicKeyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sshPublicKeyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GenerateKeyPair(req.Context(), resourceGroupNameUnescaped, sshPublicKeyNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -185,15 +210,23 @@ func (s *SSHPublicKeysServerTransport) dispatchGenerateKeyPair(req *http.Request func (s *SSHPublicKeysServerTransport) 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/Microsoft.Compute/sshPublicKeys/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys/(?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 := s.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + sshPublicKeyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sshPublicKeyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, sshPublicKeyNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -210,16 +243,20 @@ func (s *SSHPublicKeysServerTransport) dispatchGet(req *http.Request) (*http.Res func (s *SSHPublicKeysServerTransport) 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-_]+)/providers/Microsoft.Compute/sshPublicKeys" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys` 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) } - resp := s.srv.NewListByResourceGroupPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) s.newListByResourceGroupPager = &resp server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armcompute.SSHPublicKeysClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -240,12 +277,12 @@ func (s *SSHPublicKeysServerTransport) dispatchNewListByResourceGroupPager(req * func (s *SSHPublicKeysServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { if s.srv.NewListBySubscriptionPager == nil { - return nil, &nonRetriableError{errors.New("method NewListBySubscriptionPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} } if s.newListBySubscriptionPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/sshPublicKeys" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys` 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) } @@ -270,11 +307,11 @@ func (s *SSHPublicKeysServerTransport) dispatchNewListBySubscriptionPager(req *h func (s *SSHPublicKeysServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { if s.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-_]+)/providers/Microsoft.Compute/sshPublicKeys/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/sshPublicKeys/(?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) } @@ -282,7 +319,15 @@ func (s *SSHPublicKeysServerTransport) dispatchUpdate(req *http.Request) (*http. if err != nil { return nil, err } - respr, errRespr := s.srv.Update(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("sshPublicKeyName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + sshPublicKeyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sshPublicKeyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Update(req.Context(), resourceGroupNameUnescaped, sshPublicKeyNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/usage_server.go b/sdk/resourcemanager/compute/armcompute/fake/usage_server.go index 6fbd4b9416fc..cef7a65a9ff8 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/usage_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/usage_server.go @@ -17,6 +17,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -68,16 +69,20 @@ func (u *UsageServerTransport) Do(req *http.Request) (*http.Response, error) { func (u *UsageServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if u.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if u.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/usages" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/usages` 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) } - resp := u.srv.NewListPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := u.srv.NewListPager(locationUnescaped, nil) u.newListPager = &resp server.PagerResponderInjectNextLinks(u.newListPager, req, func(page *armcompute.UsageClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go index 9456dd39f9c4..86068a3ead9f 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensionimages_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" "strconv" ) @@ -80,15 +81,31 @@ func (v *VirtualMachineExtensionImagesServerTransport) Do(req *http.Request) (*h func (v *VirtualMachineExtensionImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmextension/types/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmextension/types/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("type")], matches[regex.SubexpIndex("version")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + typeParamUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("type")]) + if err != nil { + return nil, err + } + versionUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("version")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), locationUnescaped, publisherNameUnescaped, typeParamUnescaped, versionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -105,15 +122,23 @@ func (v *VirtualMachineExtensionImagesServerTransport) dispatchGet(req *http.Req func (v *VirtualMachineExtensionImagesServerTransport) dispatchListTypes(req *http.Request) (*http.Response, error) { if v.srv.ListTypes == nil { - return nil, &nonRetriableError{errors.New("method ListTypes not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListTypes not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmextension/types" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmextension/types` 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 := v.srv.ListTypes(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListTypes(req.Context(), locationUnescaped, publisherNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -130,17 +155,37 @@ func (v *VirtualMachineExtensionImagesServerTransport) dispatchListTypes(req *ht func (v *VirtualMachineExtensionImagesServerTransport) dispatchListVersions(req *http.Request) (*http.Response, error) { if v.srv.ListVersions == nil { - return nil, &nonRetriableError{errors.New("method ListVersions not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListVersions not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmextension/types/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmextension/types/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` 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) } qp := req.URL.Query() - filterParam := getOptional(qp.Get("$filter")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + typeParamUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("type")]) + 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 @@ -150,7 +195,11 @@ func (v *VirtualMachineExtensionImagesServerTransport) dispatchListVersions(req if err != nil { return nil, err } - orderbyParam := getOptional(qp.Get("$orderby")) + orderbyUnescaped, err := url.QueryUnescape(qp.Get("$orderby")) + if err != nil { + return nil, err + } + orderbyParam := getOptional(orderbyUnescaped) var options *armcompute.VirtualMachineExtensionImagesClientListVersionsOptions if filterParam != nil || topParam != nil || orderbyParam != nil { options = &armcompute.VirtualMachineExtensionImagesClientListVersionsOptions{ @@ -159,7 +208,7 @@ func (v *VirtualMachineExtensionImagesServerTransport) dispatchListVersions(req Orderby: orderbyParam, } } - respr, errRespr := v.srv.ListVersions(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("type")], options) + respr, errRespr := v.srv.ListVersions(req.Context(), locationUnescaped, publisherNameUnescaped, typeParamUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go index cb30df6a9ebc..4971818b3b98 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineextensions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -94,12 +95,12 @@ func (v *VirtualMachineExtensionsServerTransport) Do(req *http.Request) (*http.R func (v *VirtualMachineExtensionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) } @@ -107,7 +108,19 @@ func (v *VirtualMachineExtensionsServerTransport) dispatchBeginCreateOrUpdate(re if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, vmExtensionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -131,16 +144,28 @@ func (v *VirtualMachineExtensionsServerTransport) dispatchBeginCreateOrUpdate(re func (v *VirtualMachineExtensionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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 := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, vmExtensionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -164,23 +189,39 @@ func (v *VirtualMachineExtensionsServerTransport) dispatchBeginDelete(req *http. func (v *VirtualMachineExtensionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineExtensionsClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachineExtensionsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, vmExtensionNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -197,23 +238,35 @@ func (v *VirtualMachineExtensionsServerTransport) dispatchGet(req *http.Request) func (v *VirtualMachineExtensionsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { if v.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions` 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() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineExtensionsClientListOptions if expandParam != nil { options = &armcompute.VirtualMachineExtensionsClientListOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.List(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -230,12 +283,12 @@ func (v *VirtualMachineExtensionsServerTransport) dispatchList(req *http.Request func (v *VirtualMachineExtensionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) } @@ -243,7 +296,19 @@ func (v *VirtualMachineExtensionsServerTransport) dispatchBeginUpdate(req *http. if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, vmExtensionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go index 89d7276ba954..2aaec473eb8c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimages_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" "strconv" ) @@ -98,15 +99,35 @@ func (v *VirtualMachineImagesServerTransport) Do(req *http.Request) (*http.Respo func (v *VirtualMachineImagesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], matches[regex.SubexpIndex("version")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + offerUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offer")]) + if err != nil { + return nil, err + } + skusUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("skus")]) + if err != nil { + return nil, err + } + versionUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("version")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), locationUnescaped, publisherNameUnescaped, offerUnescaped, skusUnescaped, versionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -123,17 +144,41 @@ func (v *VirtualMachineImagesServerTransport) dispatchGet(req *http.Request) (*h func (v *VirtualMachineImagesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { if v.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + offerUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offer")]) + if err != nil { + return nil, err + } + skusUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("skus")]) + if err != nil { + return nil, err + } + 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 @@ -143,7 +188,11 @@ func (v *VirtualMachineImagesServerTransport) dispatchList(req *http.Request) (* if err != nil { return nil, err } - orderbyParam := getOptional(qp.Get("$orderby")) + orderbyUnescaped, err := url.QueryUnescape(qp.Get("$orderby")) + if err != nil { + return nil, err + } + orderbyParam := getOptional(orderbyUnescaped) var options *armcompute.VirtualMachineImagesClientListOptions if expandParam != nil || topParam != nil || orderbyParam != nil { options = &armcompute.VirtualMachineImagesClientListOptions{ @@ -152,7 +201,7 @@ func (v *VirtualMachineImagesServerTransport) dispatchList(req *http.Request) (* Orderby: orderbyParam, } } - respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], options) + respr, errRespr := v.srv.List(req.Context(), locationUnescaped, publisherNameUnescaped, offerUnescaped, skusUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -169,15 +218,23 @@ func (v *VirtualMachineImagesServerTransport) dispatchList(req *http.Request) (* func (v *VirtualMachineImagesServerTransport) dispatchListByEdgeZone(req *http.Request) (*http.Response, error) { if v.srv.ListByEdgeZone == nil { - return nil, &nonRetriableError{errors.New("method ListByEdgeZone not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListByEdgeZone not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/vmimages" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/edgeZones/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vmimages` 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 := v.srv.ListByEdgeZone(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + edgeZoneUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("edgeZone")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListByEdgeZone(req.Context(), locationUnescaped, edgeZoneUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -194,15 +251,23 @@ func (v *VirtualMachineImagesServerTransport) dispatchListByEdgeZone(req *http.R func (v *VirtualMachineImagesServerTransport) dispatchListOffers(req *http.Request) (*http.Response, error) { if v.srv.ListOffers == nil { - return nil, &nonRetriableError{errors.New("method ListOffers not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListOffers not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers` 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 := v.srv.ListOffers(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListOffers(req.Context(), locationUnescaped, publisherNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -219,15 +284,19 @@ func (v *VirtualMachineImagesServerTransport) dispatchListOffers(req *http.Reque func (v *VirtualMachineImagesServerTransport) dispatchListPublishers(req *http.Request) (*http.Response, error) { if v.srv.ListPublishers == nil { - return nil, &nonRetriableError{errors.New("method ListPublishers not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListPublishers not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers` 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 := v.srv.ListPublishers(req.Context(), matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListPublishers(req.Context(), locationUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -244,15 +313,27 @@ func (v *VirtualMachineImagesServerTransport) dispatchListPublishers(req *http.R func (v *VirtualMachineImagesServerTransport) dispatchListSKUs(req *http.Request) (*http.Response, error) { if v.srv.ListSKUs == nil { - return nil, &nonRetriableError{errors.New("method ListSKUs not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListSKUs not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus` 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 := v.srv.ListSKUs(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + offerUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offer")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListSKUs(req.Context(), locationUnescaped, publisherNameUnescaped, offerUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go index e82926b00339..a24715fcce9c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineimagesedgezone_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" "strconv" ) @@ -92,15 +93,39 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) Do(req *http.Request) (*ht func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/edgeZones/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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) < 7 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], matches[regex.SubexpIndex("version")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + edgeZoneUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("edgeZone")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + offerUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offer")]) + if err != nil { + return nil, err + } + skusUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("skus")]) + if err != nil { + return nil, err + } + versionUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("version")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), locationUnescaped, edgeZoneUnescaped, publisherNameUnescaped, offerUnescaped, skusUnescaped, versionUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -117,17 +142,45 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchGet(req *http.Requ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchList(req *http.Request) (*http.Response, error) { if v.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus/(?P[a-zA-Z0-9-_]+)/versions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/edgeZones/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` 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() - expandParam := getOptional(qp.Get("$expand")) - topParam, err := parseOptional(qp.Get("$top"), func(v string) (int32, error) { + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + edgeZoneUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("edgeZone")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + offerUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offer")]) + if err != nil { + return nil, err + } + skusUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("skus")]) + if err != nil { + return nil, err + } + 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 @@ -137,7 +190,11 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchList(req *http.Req if err != nil { return nil, err } - orderbyParam := getOptional(qp.Get("$orderby")) + orderbyUnescaped, err := url.QueryUnescape(qp.Get("$orderby")) + if err != nil { + return nil, err + } + orderbyParam := getOptional(orderbyUnescaped) var options *armcompute.VirtualMachineImagesEdgeZoneClientListOptions if expandParam != nil || topParam != nil || orderbyParam != nil { options = &armcompute.VirtualMachineImagesEdgeZoneClientListOptions{ @@ -146,7 +203,7 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchList(req *http.Req Orderby: orderbyParam, } } - respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], matches[regex.SubexpIndex("skus")], options) + respr, errRespr := v.srv.List(req.Context(), locationUnescaped, edgeZoneUnescaped, publisherNameUnescaped, offerUnescaped, skusUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -163,15 +220,27 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchList(req *http.Req func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListOffers(req *http.Request) (*http.Response, error) { if v.srv.ListOffers == nil { - return nil, &nonRetriableError{errors.New("method ListOffers not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListOffers not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/edgeZones/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers` 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 := v.srv.ListOffers(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + edgeZoneUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("edgeZone")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListOffers(req.Context(), locationUnescaped, edgeZoneUnescaped, publisherNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -188,15 +257,23 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListOffers(req *ht func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListPublishers(req *http.Request) (*http.Response, error) { if v.srv.ListPublishers == nil { - return nil, &nonRetriableError{errors.New("method ListPublishers not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListPublishers not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/edgeZones/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers` 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 := v.srv.ListPublishers(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + edgeZoneUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("edgeZone")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListPublishers(req.Context(), locationUnescaped, edgeZoneUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -213,15 +290,31 @@ func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListPublishers(req func (v *VirtualMachineImagesEdgeZoneServerTransport) dispatchListSKUs(req *http.Request) (*http.Response, error) { if v.srv.ListSKUs == nil { - return nil, &nonRetriableError{errors.New("method ListSKUs not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ListSKUs not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/edgeZones/(?P[a-zA-Z0-9-_]+)/publishers/(?P[a-zA-Z0-9-_]+)/artifacttypes/vmimage/offers/(?P[a-zA-Z0-9-_]+)/skus" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/edgeZones/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/artifacttypes/vmimage/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus` regex := regexp.MustCompile(regexStr) - matches := regex.FindStringSubmatch(req.URL.Path) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := v.srv.ListSKUs(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("edgeZone")], matches[regex.SubexpIndex("publisherName")], matches[regex.SubexpIndex("offer")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + edgeZoneUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("edgeZone")]) + if err != nil { + return nil, err + } + publisherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + offerUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offer")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ListSKUs(req.Context(), locationUnescaped, edgeZoneUnescaped, publisherNameUnescaped, offerUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go index 3d4208f4e215..32fe4bc31be8 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachineruncommands_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -109,12 +110,12 @@ func (v *VirtualMachineRunCommandsServerTransport) Do(req *http.Request) (*http. func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) } @@ -122,7 +123,19 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginCreateOrUpdate(r if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, runCommandNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -146,16 +159,28 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginCreateOrUpdate(r func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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 := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, runCommandNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -179,15 +204,23 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginDelete(req *http func (v *VirtualMachineRunCommandsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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 := v.srv.Get(req.Context(), matches[regex.SubexpIndex("location")], matches[regex.SubexpIndex("commandId")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + commandIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("commandId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), locationUnescaped, commandIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -204,23 +237,39 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchGet(req *http.Request func (v *VirtualMachineRunCommandsServerTransport) dispatchGetByVirtualMachine(req *http.Request) (*http.Response, error) { if v.srv.GetByVirtualMachine == nil { - return nil, &nonRetriableError{errors.New("method GetByVirtualMachine not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetByVirtualMachine not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineOptions if expandParam != nil { options = &armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.GetByVirtualMachine(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], options) + respr, errRespr := v.srv.GetByVirtualMachine(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, runCommandNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -237,16 +286,20 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchGetByVirtualMachine(r func (v *VirtualMachineRunCommandsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/runCommands" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands` 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) } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(locationUnescaped, nil) v.newListPager = &resp server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineRunCommandsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -267,24 +320,36 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchNewListPager(req *htt func (v *VirtualMachineRunCommandsServerTransport) dispatchNewListByVirtualMachinePager(req *http.Request) (*http.Response, error) { if v.srv.NewListByVirtualMachinePager == nil { - return nil, &nonRetriableError{errors.New("method NewListByVirtualMachinePager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByVirtualMachinePager not implemented")} } if v.newListByVirtualMachinePager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands` 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() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineRunCommandsClientListByVirtualMachineOptions if expandParam != nil { options = &armcompute.VirtualMachineRunCommandsClientListByVirtualMachineOptions{ Expand: expandParam, } } - resp := v.srv.NewListByVirtualMachinePager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + resp := v.srv.NewListByVirtualMachinePager(resourceGroupNameUnescaped, vmNameUnescaped, options) v.newListByVirtualMachinePager = &resp server.PagerResponderInjectNextLinks(v.newListByVirtualMachinePager, req, func(page *armcompute.VirtualMachineRunCommandsClientListByVirtualMachineResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -305,12 +370,12 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchNewListByVirtualMachi func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) } @@ -318,7 +383,19 @@ func (v *VirtualMachineRunCommandsServerTransport) dispatchBeginUpdate(req *http if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], matches[regex.SubexpIndex("runCommandName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, runCommandNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go index 13321082acba..81cffcb9d03c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachines_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/compute/armcompute/v5" "net/http" + "net/url" "reflect" "regexp" "strconv" @@ -234,16 +235,24 @@ func (v *VirtualMachinesServerTransport) Do(req *http.Request) (*http.Response, func (v *VirtualMachinesServerTransport) dispatchBeginAssessPatches(req *http.Request) (*http.Response, error) { if v.srv.BeginAssessPatches == nil { - return nil, &nonRetriableError{errors.New("method BeginAssessPatches not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginAssessPatches not implemented")} } if v.beginAssessPatches == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/assessPatches" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/assessPatches` 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 := v.srv.BeginAssessPatches(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginAssessPatches(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -267,12 +276,12 @@ func (v *VirtualMachinesServerTransport) dispatchBeginAssessPatches(req *http.Re func (v *VirtualMachinesServerTransport) dispatchBeginCapture(req *http.Request) (*http.Response, error) { if v.srv.BeginCapture == nil { - return nil, &nonRetriableError{errors.New("method BeginCapture not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCapture not implemented")} } if v.beginCapture == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/capture" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/capture` 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) } @@ -280,7 +289,15 @@ func (v *VirtualMachinesServerTransport) dispatchBeginCapture(req *http.Request) if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCapture(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCapture(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -304,16 +321,24 @@ func (v *VirtualMachinesServerTransport) dispatchBeginCapture(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchBeginConvertToManagedDisks(req *http.Request) (*http.Response, error) { if v.srv.BeginConvertToManagedDisks == nil { - return nil, &nonRetriableError{errors.New("method BeginConvertToManagedDisks not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginConvertToManagedDisks not implemented")} } if v.beginConvertToManagedDisks == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/convertToManagedDisks" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/convertToManagedDisks` 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 := v.srv.BeginConvertToManagedDisks(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginConvertToManagedDisks(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -337,12 +362,12 @@ func (v *VirtualMachinesServerTransport) dispatchBeginConvertToManagedDisks(req func (v *VirtualMachinesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?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) } @@ -350,7 +375,15 @@ func (v *VirtualMachinesServerTransport) dispatchBeginCreateOrUpdate(req *http.R if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -374,17 +407,29 @@ func (v *VirtualMachinesServerTransport) dispatchBeginCreateOrUpdate(req *http.R func (v *VirtualMachinesServerTransport) dispatchBeginDeallocate(req *http.Request) (*http.Response, error) { if v.srv.BeginDeallocate == nil { - return nil, &nonRetriableError{errors.New("method BeginDeallocate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeallocate not implemented")} } if v.beginDeallocate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/deallocate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deallocate` 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() - hibernateParam, err := parseOptional(qp.Get("hibernate"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + hibernateUnescaped, err := url.QueryUnescape(qp.Get("hibernate")) + if err != nil { + return nil, err + } + hibernateParam, err := parseOptional(hibernateUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -394,7 +439,7 @@ func (v *VirtualMachinesServerTransport) dispatchBeginDeallocate(req *http.Reque Hibernate: hibernateParam, } } - respr, errRespr := v.srv.BeginDeallocate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.BeginDeallocate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -418,17 +463,29 @@ func (v *VirtualMachinesServerTransport) dispatchBeginDeallocate(req *http.Reque func (v *VirtualMachinesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?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) } qp := req.URL.Query() - forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + forceDeletionUnescaped, err := url.QueryUnescape(qp.Get("forceDeletion")) + if err != nil { + return nil, err + } + forceDeletionParam, err := parseOptional(forceDeletionUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -438,7 +495,7 @@ func (v *VirtualMachinesServerTransport) dispatchBeginDelete(req *http.Request) ForceDeletion: forceDeletionParam, } } - respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -462,15 +519,23 @@ func (v *VirtualMachinesServerTransport) dispatchBeginDelete(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchGeneralize(req *http.Request) (*http.Response, error) { if v.srv.Generalize == nil { - return nil, &nonRetriableError{errors.New("method Generalize not implemented")} + return nil, &nonRetriableError{errors.New("fake for method Generalize not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/generalize" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generalize` 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 := v.srv.Generalize(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Generalize(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -487,23 +552,35 @@ func (v *VirtualMachinesServerTransport) dispatchGeneralize(req *http.Request) ( func (v *VirtualMachinesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.InstanceViewTypes(expandUnescaped)) var options *armcompute.VirtualMachinesClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachinesClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -520,12 +597,12 @@ func (v *VirtualMachinesServerTransport) dispatchGet(req *http.Request) (*http.R func (v *VirtualMachinesServerTransport) dispatchBeginInstallPatches(req *http.Request) (*http.Response, error) { if v.srv.BeginInstallPatches == nil { - return nil, &nonRetriableError{errors.New("method BeginInstallPatches not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginInstallPatches not implemented")} } if v.beginInstallPatches == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/installPatches" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/installPatches` 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) } @@ -533,7 +610,15 @@ func (v *VirtualMachinesServerTransport) dispatchBeginInstallPatches(req *http.R if err != nil { return nil, err } - respr, errRespr := v.srv.BeginInstallPatches(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginInstallPatches(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -557,15 +642,23 @@ func (v *VirtualMachinesServerTransport) dispatchBeginInstallPatches(req *http.R func (v *VirtualMachinesServerTransport) dispatchInstanceView(req *http.Request) (*http.Response, error) { if v.srv.InstanceView == nil { - return nil, &nonRetriableError{errors.New("method InstanceView not implemented")} + return nil, &nonRetriableError{errors.New("fake for method InstanceView not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/instanceView" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/instanceView` 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 := v.srv.InstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.InstanceView(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -582,18 +675,30 @@ func (v *VirtualMachinesServerTransport) dispatchInstanceView(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines` 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(armcompute.ExpandTypeForListVMs(qp.Get("$expand"))) + 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(armcompute.ExpandTypeForListVMs(expandUnescaped)) var options *armcompute.VirtualMachinesClientListOptions if filterParam != nil || expandParam != nil { options = &armcompute.VirtualMachinesClientListOptions{ @@ -601,7 +706,7 @@ func (v *VirtualMachinesServerTransport) dispatchNewListPager(req *http.Request) Expand: expandParam, } } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], options) + resp := v.srv.NewListPager(resourceGroupNameUnescaped, options) v.newListPager = &resp server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachinesClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -622,19 +727,31 @@ func (v *VirtualMachinesServerTransport) dispatchNewListPager(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { if v.srv.NewListAllPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} } if v.newListAllPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines` 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() - statusOnlyParam := getOptional(qp.Get("statusOnly")) - filterParam := getOptional(qp.Get("$filter")) - expandParam := getOptional(armcompute.ExpandTypesForListVMs(qp.Get("$expand"))) + statusOnlyUnescaped, err := url.QueryUnescape(qp.Get("statusOnly")) + if err != nil { + return nil, err + } + statusOnlyParam := getOptional(statusOnlyUnescaped) + 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(armcompute.ExpandTypesForListVMs(expandUnescaped)) var options *armcompute.VirtualMachinesClientListAllOptions if statusOnlyParam != nil || filterParam != nil || expandParam != nil { options = &armcompute.VirtualMachinesClientListAllOptions{ @@ -664,16 +781,24 @@ func (v *VirtualMachinesServerTransport) dispatchNewListAllPager(req *http.Reque func (v *VirtualMachinesServerTransport) dispatchNewListAvailableSizesPager(req *http.Request) (*http.Response, error) { if v.srv.NewListAvailableSizesPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAvailableSizesPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAvailableSizesPager not implemented")} } if v.newListAvailableSizesPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/vmSizes" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vmSizes` 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) } - resp := v.srv.NewListAvailableSizesPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListAvailableSizesPager(resourceGroupNameUnescaped, vmNameUnescaped, nil) v.newListAvailableSizesPager = &resp } resp, err := server.PagerResponderNext(v.newListAvailableSizesPager, req) @@ -691,16 +816,20 @@ func (v *VirtualMachinesServerTransport) dispatchNewListAvailableSizesPager(req func (v *VirtualMachinesServerTransport) dispatchNewListByLocationPager(req *http.Request) (*http.Response, error) { if v.srv.NewListByLocationPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByLocationPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByLocationPager not implemented")} } if v.newListByLocationPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/virtualMachines" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines` 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) } - resp := v.srv.NewListByLocationPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByLocationPager(locationUnescaped, nil) v.newListByLocationPager = &resp server.PagerResponderInjectNextLinks(v.newListByLocationPager, req, func(page *armcompute.VirtualMachinesClientListByLocationResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -721,16 +850,24 @@ func (v *VirtualMachinesServerTransport) dispatchNewListByLocationPager(req *htt func (v *VirtualMachinesServerTransport) dispatchBeginPerformMaintenance(req *http.Request) (*http.Response, error) { if v.srv.BeginPerformMaintenance == nil { - return nil, &nonRetriableError{errors.New("method BeginPerformMaintenance not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPerformMaintenance not implemented")} } if v.beginPerformMaintenance == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/performMaintenance" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/performMaintenance` 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 := v.srv.BeginPerformMaintenance(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginPerformMaintenance(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -754,17 +891,29 @@ func (v *VirtualMachinesServerTransport) dispatchBeginPerformMaintenance(req *ht func (v *VirtualMachinesServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { if v.srv.BeginPowerOff == nil { - return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPowerOff not implemented")} } if v.beginPowerOff == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/powerOff" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/powerOff` 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() - skipShutdownParam, err := parseOptional(qp.Get("skipShutdown"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + skipShutdownUnescaped, err := url.QueryUnescape(qp.Get("skipShutdown")) + if err != nil { + return nil, err + } + skipShutdownParam, err := parseOptional(skipShutdownUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -774,7 +923,7 @@ func (v *VirtualMachinesServerTransport) dispatchBeginPowerOff(req *http.Request SkipShutdown: skipShutdownParam, } } - respr, errRespr := v.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.BeginPowerOff(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -798,16 +947,24 @@ func (v *VirtualMachinesServerTransport) dispatchBeginPowerOff(req *http.Request func (v *VirtualMachinesServerTransport) dispatchBeginReapply(req *http.Request) (*http.Response, error) { if v.srv.BeginReapply == nil { - return nil, &nonRetriableError{errors.New("method BeginReapply not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReapply not implemented")} } if v.beginReapply == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/reapply" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reapply` 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 := v.srv.BeginReapply(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginReapply(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -831,16 +988,24 @@ func (v *VirtualMachinesServerTransport) dispatchBeginReapply(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchBeginRedeploy(req *http.Request) (*http.Response, error) { if v.srv.BeginRedeploy == nil { - return nil, &nonRetriableError{errors.New("method BeginRedeploy not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRedeploy not implemented")} } if v.beginRedeploy == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/redeploy" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/redeploy` 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 := v.srv.BeginRedeploy(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRedeploy(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -864,12 +1029,12 @@ func (v *VirtualMachinesServerTransport) dispatchBeginRedeploy(req *http.Request func (v *VirtualMachinesServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { if v.srv.BeginReimage == nil { - return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimage not implemented")} } if v.beginReimage == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/reimage" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimage` 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) } @@ -877,13 +1042,21 @@ func (v *VirtualMachinesServerTransport) dispatchBeginReimage(req *http.Request) if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachinesClientBeginReimageOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachinesClientBeginReimageOptions{ Parameters: &body, } } - respr, errRespr := v.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.BeginReimage(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -907,16 +1080,24 @@ func (v *VirtualMachinesServerTransport) dispatchBeginReimage(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { if v.srv.BeginRestart == nil { - return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} } if v.beginRestart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/restart" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 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 := v.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRestart(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -940,16 +1121,28 @@ func (v *VirtualMachinesServerTransport) dispatchBeginRestart(req *http.Request) func (v *VirtualMachinesServerTransport) dispatchRetrieveBootDiagnosticsData(req *http.Request) (*http.Response, error) { if v.srv.RetrieveBootDiagnosticsData == nil { - return nil, &nonRetriableError{errors.New("method RetrieveBootDiagnosticsData not implemented")} + return nil, &nonRetriableError{errors.New("fake for method RetrieveBootDiagnosticsData not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/retrieveBootDiagnosticsData" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/retrieveBootDiagnosticsData` 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() - sasURIExpirationTimeInMinutesParam, err := parseOptional(qp.Get("sasUriExpirationTimeInMinutes"), func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + sasURIExpirationTimeInMinutesUnescaped, err := url.QueryUnescape(qp.Get("sasUriExpirationTimeInMinutes")) + if err != nil { + return nil, err + } + sasURIExpirationTimeInMinutesParam, err := parseOptional(sasURIExpirationTimeInMinutesUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -965,7 +1158,7 @@ func (v *VirtualMachinesServerTransport) dispatchRetrieveBootDiagnosticsData(req SasURIExpirationTimeInMinutes: sasURIExpirationTimeInMinutesParam, } } - respr, errRespr := v.srv.RetrieveBootDiagnosticsData(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], options) + respr, errRespr := v.srv.RetrieveBootDiagnosticsData(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -982,12 +1175,12 @@ func (v *VirtualMachinesServerTransport) dispatchRetrieveBootDiagnosticsData(req func (v *VirtualMachinesServerTransport) dispatchBeginRunCommand(req *http.Request) (*http.Response, error) { if v.srv.BeginRunCommand == nil { - return nil, &nonRetriableError{errors.New("method BeginRunCommand not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRunCommand not implemented")} } if v.beginRunCommand == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommand" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommand` 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) } @@ -995,7 +1188,15 @@ func (v *VirtualMachinesServerTransport) dispatchBeginRunCommand(req *http.Reque if err != nil { return nil, err } - respr, errRespr := v.srv.BeginRunCommand(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRunCommand(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1019,15 +1220,23 @@ func (v *VirtualMachinesServerTransport) dispatchBeginRunCommand(req *http.Reque func (v *VirtualMachinesServerTransport) dispatchSimulateEviction(req *http.Request) (*http.Response, error) { if v.srv.SimulateEviction == nil { - return nil, &nonRetriableError{errors.New("method SimulateEviction not implemented")} + return nil, &nonRetriableError{errors.New("fake for method SimulateEviction not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/simulateEviction" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/simulateEviction` 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 := v.srv.SimulateEviction(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.SimulateEviction(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1044,16 +1253,24 @@ func (v *VirtualMachinesServerTransport) dispatchSimulateEviction(req *http.Requ func (v *VirtualMachinesServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { if v.srv.BeginStart == nil { - return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginStart not implemented")} } if v.beginStart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)/start" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/start` 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 := v.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginStart(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1077,12 +1294,12 @@ func (v *VirtualMachinesServerTransport) dispatchBeginStart(req *http.Request) ( func (v *VirtualMachinesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachines/(?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) } @@ -1090,7 +1307,15 @@ func (v *VirtualMachinesServerTransport) dispatchBeginUpdate(req *http.Request) if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go index 86f87a9858dd..f6517aa38d2e 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetextensions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) Do(req *http.Request) func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) } @@ -109,7 +110,19 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginCreateOrU if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + vmssExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmssExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, vmssExtensionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +146,28 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginCreateOrU func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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 := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + vmssExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmssExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, vmssExtensionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,23 +191,39 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginDelete(re func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + vmssExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmssExtensionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineScaleSetExtensionsClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetExtensionsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, vmssExtensionNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -199,16 +240,24 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchGet(req *http. func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions` 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) } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) v.newListPager = &resp server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetExtensionsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -229,12 +278,12 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchNewListPager(r func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) } @@ -242,7 +291,19 @@ func (v *VirtualMachineScaleSetExtensionsServerTransport) dispatchBeginUpdate(re if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("vmssExtensionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + vmssExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmssExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, vmssExtensionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go index 5e602b509caa..5f7a6f845bad 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetrollingupgrades_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -88,16 +89,24 @@ func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) Do(req *http.Requ func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginCancel(req *http.Request) (*http.Response, error) { if v.srv.BeginCancel == nil { - return nil, &nonRetriableError{errors.New("method BeginCancel not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCancel not implemented")} } if v.beginCancel == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/rollingUpgrades/cancel" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rollingUpgrades/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 := v.srv.BeginCancel(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCancel(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -121,15 +130,23 @@ func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginCanc func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchGetLatest(req *http.Request) (*http.Response, error) { if v.srv.GetLatest == nil { - return nil, &nonRetriableError{errors.New("method GetLatest not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetLatest not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/rollingUpgrades/latest" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rollingUpgrades/latest` 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 := v.srv.GetLatest(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.GetLatest(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -146,16 +163,24 @@ func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchGetLatest func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginStartExtensionUpgrade(req *http.Request) (*http.Response, error) { if v.srv.BeginStartExtensionUpgrade == nil { - return nil, &nonRetriableError{errors.New("method BeginStartExtensionUpgrade not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginStartExtensionUpgrade not implemented")} } if v.beginStartExtensionUpgrade == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/extensionRollingUpgrade" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensionRollingUpgrade` 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 := v.srv.BeginStartExtensionUpgrade(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginStartExtensionUpgrade(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -179,16 +204,24 @@ func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginStar func (v *VirtualMachineScaleSetRollingUpgradesServerTransport) dispatchBeginStartOSUpgrade(req *http.Request) (*http.Response, error) { if v.srv.BeginStartOSUpgrade == nil { - return nil, &nonRetriableError{errors.New("method BeginStartOSUpgrade not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginStartOSUpgrade not implemented")} } if v.beginStartOSUpgrade == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/osRollingUpgrade" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/osRollingUpgrade` 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 := v.srv.BeginStartOSUpgrade(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginStartOSUpgrade(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go index 50d464251c3f..6e12c1870c2f 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesets_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/compute/armcompute/v5" "net/http" + "net/url" "reflect" "regexp" "strconv" @@ -228,11 +229,11 @@ func (v *VirtualMachineScaleSetsServerTransport) Do(req *http.Request) (*http.Re func (v *VirtualMachineScaleSetsServerTransport) dispatchConvertToSinglePlacementGroup(req *http.Request) (*http.Response, error) { if v.srv.ConvertToSinglePlacementGroup == nil { - return nil, &nonRetriableError{errors.New("method ConvertToSinglePlacementGroup not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ConvertToSinglePlacementGroup not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/convertToSinglePlacementGroup" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/convertToSinglePlacementGroup` 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) } @@ -240,7 +241,15 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchConvertToSinglePlacemen if err != nil { return nil, err } - respr, errRespr := v.srv.ConvertToSinglePlacementGroup(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.ConvertToSinglePlacementGroup(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -257,12 +266,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchConvertToSinglePlacemen func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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) } @@ -270,7 +279,15 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginCreateOrUpdate(req if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -294,12 +311,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginCreateOrUpdate(req func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeallocate(req *http.Request) (*http.Response, error) { if v.srv.BeginDeallocate == nil { - return nil, &nonRetriableError{errors.New("method BeginDeallocate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeallocate not implemented")} } if v.beginDeallocate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/deallocate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deallocate` 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) } @@ -308,7 +325,19 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeallocate(req *ht if err != nil { return nil, err } - hibernateParam, err := parseOptional(qp.Get("hibernate"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + hibernateUnescaped, err := url.QueryUnescape(qp.Get("hibernate")) + if err != nil { + return nil, err + } + hibernateParam, err := parseOptional(hibernateUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -319,7 +348,7 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeallocate(req *ht VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginDeallocate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginDeallocate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -343,17 +372,29 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeallocate(req *ht func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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) } qp := req.URL.Query() - forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + forceDeletionUnescaped, err := url.QueryUnescape(qp.Get("forceDeletion")) + if err != nil { + return nil, err + } + forceDeletionParam, err := parseOptional(forceDeletionUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -363,7 +404,7 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDelete(req *http.R ForceDeletion: forceDeletionParam, } } - respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -387,12 +428,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDelete(req *http.R func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeleteInstances(req *http.Request) (*http.Response, error) { if v.srv.BeginDeleteInstances == nil { - return nil, &nonRetriableError{errors.New("method BeginDeleteInstances not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteInstances not implemented")} } if v.beginDeleteInstances == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/delete" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/delete` 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) } @@ -401,7 +442,19 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeleteInstances(re if err != nil { return nil, err } - forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + forceDeletionUnescaped, err := url.QueryUnescape(qp.Get("forceDeletion")) + if err != nil { + return nil, err + } + forceDeletionParam, err := parseOptional(forceDeletionUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -411,7 +464,7 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeleteInstances(re ForceDeletion: forceDeletionParam, } } - respr, errRespr := v.srv.BeginDeleteInstances(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, options) + respr, errRespr := v.srv.BeginDeleteInstances(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, body, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -435,16 +488,28 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginDeleteInstances(re func (v *VirtualMachineScaleSetsServerTransport) dispatchForceRecoveryServiceFabricPlatformUpdateDomainWalk(req *http.Request) (*http.Response, error) { if v.srv.ForceRecoveryServiceFabricPlatformUpdateDomainWalk == nil { - return nil, &nonRetriableError{errors.New("method ForceRecoveryServiceFabricPlatformUpdateDomainWalk not implemented")} + return nil, &nonRetriableError{errors.New("fake for method ForceRecoveryServiceFabricPlatformUpdateDomainWalk not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/forceRecoveryServiceFabricPlatformUpdateDomainWalk" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/forceRecoveryServiceFabricPlatformUpdateDomainWalk` 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() - platformUpdateDomainParam, err := parseWithCast(qp.Get("platformUpdateDomain"), func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + platformUpdateDomainUnescaped, err := url.QueryUnescape(qp.Get("platformUpdateDomain")) + if err != nil { + return nil, err + } + platformUpdateDomainParam, err := parseWithCast(platformUpdateDomainUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -454,8 +519,16 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchForceRecoveryServiceFab if err != nil { return nil, err } - zoneParam := getOptional(qp.Get("zone")) - placementGroupIDParam := getOptional(qp.Get("placementGroupId")) + zoneUnescaped, err := url.QueryUnescape(qp.Get("zone")) + if err != nil { + return nil, err + } + zoneParam := getOptional(zoneUnescaped) + placementGroupIDUnescaped, err := url.QueryUnescape(qp.Get("placementGroupId")) + if err != nil { + return nil, err + } + placementGroupIDParam := getOptional(placementGroupIDUnescaped) var options *armcompute.VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions if zoneParam != nil || placementGroupIDParam != nil { options = &armcompute.VirtualMachineScaleSetsClientForceRecoveryServiceFabricPlatformUpdateDomainWalkOptions{ @@ -463,7 +536,7 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchForceRecoveryServiceFab PlacementGroupID: placementGroupIDParam, } } - respr, errRespr := v.srv.ForceRecoveryServiceFabricPlatformUpdateDomainWalk(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], int32(platformUpdateDomainParam), options) + respr, errRespr := v.srv.ForceRecoveryServiceFabricPlatformUpdateDomainWalk(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, int32(platformUpdateDomainParam), options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -480,23 +553,35 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchForceRecoveryServiceFab func (v *VirtualMachineScaleSetsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.ExpandTypesForGetVMScaleSets(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.ExpandTypesForGetVMScaleSets(expandUnescaped)) var options *armcompute.VirtualMachineScaleSetsClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -513,15 +598,23 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchGet(req *http.Request) func (v *VirtualMachineScaleSetsServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { if v.srv.GetInstanceView == nil { - return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetInstanceView not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/instanceView" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/instanceView` 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 := v.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.GetInstanceView(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -538,16 +631,24 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchGetInstanceView(req *ht func (v *VirtualMachineScaleSetsServerTransport) dispatchNewGetOSUpgradeHistoryPager(req *http.Request) (*http.Response, error) { if v.srv.NewGetOSUpgradeHistoryPager == nil { - return nil, &nonRetriableError{errors.New("method NewGetOSUpgradeHistoryPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewGetOSUpgradeHistoryPager not implemented")} } if v.newGetOSUpgradeHistoryPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/osUpgradeHistory" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/osUpgradeHistory` 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) } - resp := v.srv.NewGetOSUpgradeHistoryPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewGetOSUpgradeHistoryPager(resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) v.newGetOSUpgradeHistoryPager = &resp server.PagerResponderInjectNextLinks(v.newGetOSUpgradeHistoryPager, req, func(page *armcompute.VirtualMachineScaleSetsClientGetOSUpgradeHistoryResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -568,16 +669,20 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchNewGetOSUpgradeHistoryP func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets` 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) } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, nil) v.newListPager = &resp server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -598,12 +703,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListPager(req *http. func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { if v.srv.NewListAllPager == nil { - return nil, &nonRetriableError{errors.New("method NewListAllPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} } if v.newListAllPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets` 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) } @@ -628,16 +733,20 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListAllPager(req *ht func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListByLocationPager(req *http.Request) (*http.Response, error) { if v.srv.NewListByLocationPager == nil { - return nil, &nonRetriableError{errors.New("method NewListByLocationPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListByLocationPager not implemented")} } if v.newListByLocationPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/virtualMachineScaleSets" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachineScaleSets` 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) } - resp := v.srv.NewListByLocationPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByLocationPager(locationUnescaped, nil) v.newListByLocationPager = &resp server.PagerResponderInjectNextLinks(v.newListByLocationPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListByLocationResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -658,16 +767,24 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListByLocationPager( func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListSKUsPager(req *http.Request) (*http.Response, error) { if v.srv.NewListSKUsPager == nil { - return nil, &nonRetriableError{errors.New("method NewListSKUsPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListSKUsPager not implemented")} } if v.newListSKUsPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/skus" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/skus` 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) } - resp := v.srv.NewListSKUsPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListSKUsPager(resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) v.newListSKUsPager = &resp server.PagerResponderInjectNextLinks(v.newListSKUsPager, req, func(page *armcompute.VirtualMachineScaleSetsClientListSKUsResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -688,12 +805,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchNewListSKUsPager(req *h func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPerformMaintenance(req *http.Request) (*http.Response, error) { if v.srv.BeginPerformMaintenance == nil { - return nil, &nonRetriableError{errors.New("method BeginPerformMaintenance not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPerformMaintenance not implemented")} } if v.beginPerformMaintenance == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/performMaintenance" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/performMaintenance` 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) } @@ -701,13 +818,21 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPerformMaintenance if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetsClientBeginPerformMaintenanceOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetsClientBeginPerformMaintenanceOptions{ VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginPerformMaintenance(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginPerformMaintenance(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -731,12 +856,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPerformMaintenance func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { if v.srv.BeginPowerOff == nil { - return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPowerOff not implemented")} } if v.beginPowerOff == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/poweroff" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/poweroff` 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) } @@ -745,7 +870,19 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPowerOff(req *http if err != nil { return nil, err } - skipShutdownParam, err := parseOptional(qp.Get("skipShutdown"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + skipShutdownUnescaped, err := url.QueryUnescape(qp.Get("skipShutdown")) + if err != nil { + return nil, err + } + skipShutdownParam, err := parseOptional(skipShutdownUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -756,7 +893,7 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPowerOff(req *http VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginPowerOff(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -780,16 +917,24 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginPowerOff(req *http func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReapply(req *http.Request) (*http.Response, error) { if v.srv.BeginReapply == nil { - return nil, &nonRetriableError{errors.New("method BeginReapply not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReapply not implemented")} } if v.beginReapply == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/reapply" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reapply` 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 := v.srv.BeginReapply(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginReapply(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -813,12 +958,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReapply(req *http. func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRedeploy(req *http.Request) (*http.Response, error) { if v.srv.BeginRedeploy == nil { - return nil, &nonRetriableError{errors.New("method BeginRedeploy not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRedeploy not implemented")} } if v.beginRedeploy == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/redeploy" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/redeploy` 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) } @@ -826,13 +971,21 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRedeploy(req *http if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetsClientBeginRedeployOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetsClientBeginRedeployOptions{ VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginRedeploy(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginRedeploy(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -856,12 +1009,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRedeploy(req *http func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { if v.srv.BeginReimage == nil { - return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimage not implemented")} } if v.beginReimage == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/reimage" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimage` 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) } @@ -869,13 +1022,21 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimage(req *http. if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetsClientBeginReimageOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetsClientBeginReimageOptions{ VMScaleSetReimageInput: &body, } } - respr, errRespr := v.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginReimage(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -899,12 +1060,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimage(req *http. func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimageAll(req *http.Request) (*http.Response, error) { if v.srv.BeginReimageAll == nil { - return nil, &nonRetriableError{errors.New("method BeginReimageAll not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimageAll not implemented")} } if v.beginReimageAll == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/reimageall" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimageall` 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) } @@ -912,13 +1073,21 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimageAll(req *ht if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetsClientBeginReimageAllOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetsClientBeginReimageAllOptions{ VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginReimageAll(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginReimageAll(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -942,12 +1111,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginReimageAll(req *ht func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { if v.srv.BeginRestart == nil { - return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} } if v.beginRestart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/restart" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 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) } @@ -955,13 +1124,21 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRestart(req *http. if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetsClientBeginRestartOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetsClientBeginRestartOptions{ VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginRestart(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -985,12 +1162,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginRestart(req *http. func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginSetOrchestrationServiceState(req *http.Request) (*http.Response, error) { if v.srv.BeginSetOrchestrationServiceState == nil { - return nil, &nonRetriableError{errors.New("method BeginSetOrchestrationServiceState not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginSetOrchestrationServiceState not implemented")} } if v.beginSetOrchestrationServiceState == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/setOrchestrationServiceState" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/setOrchestrationServiceState` 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) } @@ -998,7 +1175,15 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginSetOrchestrationSe if err != nil { return nil, err } - respr, errRespr := v.srv.BeginSetOrchestrationServiceState(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginSetOrchestrationServiceState(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1022,12 +1207,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginSetOrchestrationSe func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { if v.srv.BeginStart == nil { - return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginStart not implemented")} } if v.beginStart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/start" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/start` 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) } @@ -1035,13 +1220,21 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginStart(req *http.Re if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetsClientBeginStartOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetsClientBeginStartOptions{ VMInstanceIDs: &body, } } - respr, errRespr := v.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], options) + respr, errRespr := v.srv.BeginStart(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1065,12 +1258,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginStart(req *http.Re func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?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) } @@ -1078,7 +1271,15 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdate(req *http.R if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1102,12 +1303,12 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdate(req *http.R func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdateInstances(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdateInstances == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdateInstances not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateInstances not implemented")} } if v.beginUpdateInstances == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/manualupgrade" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/manualupgrade` 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) } @@ -1115,7 +1316,15 @@ func (v *VirtualMachineScaleSetsServerTransport) dispatchBeginUpdateInstances(re if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdateInstances(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdateInstances(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go index 752a89648a64..295091f705e1 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmextensions_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -94,12 +95,12 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) Do(req *http.Request func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -107,7 +108,23 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginCreateO if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, vmExtensionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -131,16 +148,32 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginCreateO func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, vmExtensionNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -164,23 +197,43 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginDelete( func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineScaleSetVMExtensionsClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetVMExtensionsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, vmExtensionNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -197,23 +250,39 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchGet(req *htt func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { if v.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-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions` 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) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineScaleSetVMExtensionsClientListOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetVMExtensionsClientListOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.List(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + respr, errRespr := v.srv.List(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -230,12 +299,12 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchList(req *ht func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/extensions/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensions/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -243,7 +312,23 @@ func (v *VirtualMachineScaleSetVMExtensionsServerTransport) dispatchBeginUpdate( if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("vmExtensionName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + vmExtensionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmExtensionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, vmExtensionNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go index db3a03c01606..4d55bab1340c 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvmruncommands_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/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -96,12 +97,12 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) Do(req *http.Reques func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginCreateOrUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginCreateOrUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} } if v.beginCreateOrUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -109,7 +110,23 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginCreate if err != nil { return nil, err } - respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, runCommandNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -133,16 +150,32 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginCreate func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, runCommandNameUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -166,23 +199,43 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginDelete func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineScaleSetVMRunCommandsClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetVMRunCommandsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, runCommandNameUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -199,24 +252,40 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchGet(req *ht func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands` 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) } qp := req.URL.Query() - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineScaleSetVMRunCommandsClientListOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetVMRunCommandsClientListOptions{ Expand: expandParam, } } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + resp := v.srv.NewListPager(resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) v.newListPager = &resp server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetVMRunCommandsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -237,12 +306,12 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchNewListPage func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/runCommands/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommands/(?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) < 5 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } @@ -250,7 +319,23 @@ func (v *VirtualMachineScaleSetVMRunCommandsServerTransport) dispatchBeginUpdate if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], matches[regex.SubexpIndex("runCommandName")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + runCommandNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("runCommandName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, runCommandNameUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go index 9de5415b2ab8..d2ce35064507 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinescalesetvms_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/compute/armcompute/v5" "net/http" + "net/url" "reflect" "regexp" "strconv" @@ -172,16 +173,28 @@ func (v *VirtualMachineScaleSetVMsServerTransport) Do(req *http.Request) (*http. func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDeallocate(req *http.Request) (*http.Response, error) { if v.srv.BeginDeallocate == nil { - return nil, &nonRetriableError{errors.New("method BeginDeallocate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDeallocate not implemented")} } if v.beginDeallocate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/deallocate" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deallocate` 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 := v.srv.BeginDeallocate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDeallocate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -205,17 +218,33 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDeallocate(req * func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if v.srv.BeginDelete == nil { - return nil, &nonRetriableError{errors.New("method BeginDelete not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } if v.beginDelete == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?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) } qp := req.URL.Query() - forceDeletionParam, err := parseOptional(qp.Get("forceDeletion"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + forceDeletionUnescaped, err := url.QueryUnescape(qp.Get("forceDeletion")) + if err != nil { + return nil, err + } + forceDeletionParam, err := parseOptional(forceDeletionUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -225,7 +254,7 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDelete(req *http ForceDeletion: forceDeletionParam, } } - respr, errRespr := v.srv.BeginDelete(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -249,23 +278,39 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginDelete(req *http func (v *VirtualMachineScaleSetVMsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if v.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.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?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) } qp := req.URL.Query() - expandParam := getOptional(armcompute.InstanceViewTypes(qp.Get("$expand"))) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armcompute.InstanceViewTypes(expandUnescaped)) var options *armcompute.VirtualMachineScaleSetVMsClientGetOptions if expandParam != nil { options = &armcompute.VirtualMachineScaleSetVMsClientGetOptions{ Expand: expandParam, } } - respr, errRespr := v.srv.Get(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -282,15 +327,27 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchGet(req *http.Request func (v *VirtualMachineScaleSetVMsServerTransport) dispatchGetInstanceView(req *http.Request) (*http.Response, error) { if v.srv.GetInstanceView == nil { - return nil, &nonRetriableError{errors.New("method GetInstanceView not implemented")} + return nil, &nonRetriableError{errors.New("fake for method GetInstanceView not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/instanceView" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/instanceView` 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 := v.srv.GetInstanceView(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.GetInstanceView(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -307,19 +364,39 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchGetInstanceView(req * func (v *VirtualMachineScaleSetVMsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines` 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() - filterParam := getOptional(qp.Get("$filter")) - selectParam := getOptional(qp.Get("$select")) - expandParam := getOptional(qp.Get("$expand")) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualMachineScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualMachineScaleSetName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + selectUnescaped, err := url.QueryUnescape(qp.Get("$select")) + if err != nil { + return nil, err + } + selectParam := getOptional(selectUnescaped) + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) var options *armcompute.VirtualMachineScaleSetVMsClientListOptions if filterParam != nil || selectParam != nil || expandParam != nil { options = &armcompute.VirtualMachineScaleSetVMsClientListOptions{ @@ -328,7 +405,7 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchNewListPager(req *htt Expand: expandParam, } } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("virtualMachineScaleSetName")], options) + resp := v.srv.NewListPager(resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, options) v.newListPager = &resp server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armcompute.VirtualMachineScaleSetVMsClientListResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) @@ -349,16 +426,28 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchNewListPager(req *htt func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPerformMaintenance(req *http.Request) (*http.Response, error) { if v.srv.BeginPerformMaintenance == nil { - return nil, &nonRetriableError{errors.New("method BeginPerformMaintenance not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPerformMaintenance not implemented")} } if v.beginPerformMaintenance == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/performMaintenance" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/performMaintenance` 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 := v.srv.BeginPerformMaintenance(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginPerformMaintenance(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -382,17 +471,33 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPerformMaintenan func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPowerOff(req *http.Request) (*http.Response, error) { if v.srv.BeginPowerOff == nil { - return nil, &nonRetriableError{errors.New("method BeginPowerOff not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginPowerOff not implemented")} } if v.beginPowerOff == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/poweroff" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/poweroff` 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) } qp := req.URL.Query() - skipShutdownParam, err := parseOptional(qp.Get("skipShutdown"), strconv.ParseBool) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + skipShutdownUnescaped, err := url.QueryUnescape(qp.Get("skipShutdown")) + if err != nil { + return nil, err + } + skipShutdownParam, err := parseOptional(skipShutdownUnescaped, strconv.ParseBool) if err != nil { return nil, err } @@ -402,7 +507,7 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPowerOff(req *ht SkipShutdown: skipShutdownParam, } } - respr, errRespr := v.srv.BeginPowerOff(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + respr, errRespr := v.srv.BeginPowerOff(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -426,16 +531,28 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginPowerOff(req *ht func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRedeploy(req *http.Request) (*http.Response, error) { if v.srv.BeginRedeploy == nil { - return nil, &nonRetriableError{errors.New("method BeginRedeploy not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRedeploy not implemented")} } if v.beginRedeploy == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/redeploy" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/redeploy` 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 := v.srv.BeginRedeploy(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRedeploy(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -459,12 +576,12 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRedeploy(req *ht func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimage(req *http.Request) (*http.Response, error) { if v.srv.BeginReimage == nil { - return nil, &nonRetriableError{errors.New("method BeginReimage not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimage not implemented")} } if v.beginReimage == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/reimage" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimage` 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) } @@ -472,13 +589,25 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimage(req *htt if err != nil { return nil, err } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } var options *armcompute.VirtualMachineScaleSetVMsClientBeginReimageOptions if !reflect.ValueOf(body).IsZero() { options = &armcompute.VirtualMachineScaleSetVMsClientBeginReimageOptions{ VMScaleSetVMReimageInput: &body, } } - respr, errRespr := v.srv.BeginReimage(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + respr, errRespr := v.srv.BeginReimage(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -502,16 +631,28 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimage(req *htt func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimageAll(req *http.Request) (*http.Response, error) { if v.srv.BeginReimageAll == nil { - return nil, &nonRetriableError{errors.New("method BeginReimageAll not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginReimageAll not implemented")} } if v.beginReimageAll == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/reimageall" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reimageall` 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 := v.srv.BeginReimageAll(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginReimageAll(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -535,16 +676,28 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginReimageAll(req * func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { if v.srv.BeginRestart == nil { - return nil, &nonRetriableError{errors.New("method BeginRestart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} } if v.beginRestart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/restart" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 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 := v.srv.BeginRestart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRestart(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -568,16 +721,32 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRestart(req *htt func (v *VirtualMachineScaleSetVMsServerTransport) dispatchRetrieveBootDiagnosticsData(req *http.Request) (*http.Response, error) { if v.srv.RetrieveBootDiagnosticsData == nil { - return nil, &nonRetriableError{errors.New("method RetrieveBootDiagnosticsData not implemented")} + return nil, &nonRetriableError{errors.New("fake for method RetrieveBootDiagnosticsData not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/retrieveBootDiagnosticsData" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/retrieveBootDiagnosticsData` 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) } qp := req.URL.Query() - sasURIExpirationTimeInMinutesParam, err := parseOptional(qp.Get("sasUriExpirationTimeInMinutes"), func(v string) (int32, error) { + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + sasURIExpirationTimeInMinutesUnescaped, err := url.QueryUnescape(qp.Get("sasUriExpirationTimeInMinutes")) + if err != nil { + return nil, err + } + sasURIExpirationTimeInMinutesParam, err := parseOptional(sasURIExpirationTimeInMinutesUnescaped, func(v string) (int32, error) { p, parseErr := strconv.ParseInt(v, 10, 32) if parseErr != nil { return 0, parseErr @@ -593,7 +762,7 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchRetrieveBootDiagnosti SasURIExpirationTimeInMinutes: sasURIExpirationTimeInMinutesParam, } } - respr, errRespr := v.srv.RetrieveBootDiagnosticsData(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], options) + respr, errRespr := v.srv.RetrieveBootDiagnosticsData(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -610,12 +779,12 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchRetrieveBootDiagnosti func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRunCommand(req *http.Request) (*http.Response, error) { if v.srv.BeginRunCommand == nil { - return nil, &nonRetriableError{errors.New("method BeginRunCommand not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginRunCommand not implemented")} } if v.beginRunCommand == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/runCommand" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/runCommand` 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) } @@ -623,7 +792,19 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRunCommand(req * if err != nil { return nil, err } - respr, errRespr := v.srv.BeginRunCommand(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginRunCommand(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -647,15 +828,27 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginRunCommand(req * func (v *VirtualMachineScaleSetVMsServerTransport) dispatchSimulateEviction(req *http.Request) (*http.Response, error) { if v.srv.SimulateEviction == nil { - return nil, &nonRetriableError{errors.New("method SimulateEviction not implemented")} + return nil, &nonRetriableError{errors.New("fake for method SimulateEviction not implemented")} } - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)/simulateEviction" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/simulateEviction` 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 := v.srv.SimulateEviction(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.SimulateEviction(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -672,16 +865,28 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchSimulateEviction(req func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { if v.srv.BeginStart == nil { - return nil, &nonRetriableError{errors.New("method BeginStart not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginStart not implemented")} } if v.beginStart == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualmachines/(?P[a-zA-Z0-9-_]+)/start" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualmachines/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/start` 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 := v.srv.BeginStart(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginStart(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -705,12 +910,12 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginStart(req *http. func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if v.srv.BeginUpdate == nil { - return nil, &nonRetriableError{errors.New("method BeginUpdate not implemented")} + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } if v.beginUpdate == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/resourceGroups/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[a-zA-Z0-9-_]+)/virtualMachines/(?P[a-zA-Z0-9-_]+)" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualMachines/(?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) } @@ -718,7 +923,19 @@ func (v *VirtualMachineScaleSetVMsServerTransport) dispatchBeginUpdate(req *http if err != nil { return nil, err } - respr, errRespr := v.srv.BeginUpdate(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], matches[regex.SubexpIndex("vmScaleSetName")], matches[regex.SubexpIndex("instanceId")], body, nil) + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vmScaleSetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vmScaleSetName")]) + if err != nil { + return nil, err + } + instanceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("instanceId")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, vmScaleSetNameUnescaped, instanceIDUnescaped, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go index 7a72bffb7a1d..47e098f47c8d 100644 --- a/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go +++ b/sdk/resourcemanager/compute/armcompute/fake/virtualmachinesizes_server.go @@ -16,6 +16,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "net/http" + "net/url" "regexp" ) @@ -67,16 +68,20 @@ func (v *VirtualMachineSizesServerTransport) Do(req *http.Request) (*http.Respon func (v *VirtualMachineSizesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { if v.srv.NewListPager == nil { - return nil, &nonRetriableError{errors.New("method NewListPager not implemented")} + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } if v.newListPager == nil { - const regexStr = "/subscriptions/(?P[a-zA-Z0-9-_]+)/providers/Microsoft.Compute/locations/(?P[a-zA-Z0-9-_]+)/vmSizes" + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vmSizes` 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) } - resp := v.srv.NewListPager(matches[regex.SubexpIndex("location")], nil) + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(locationUnescaped, nil) v.newListPager = &resp } resp, err := server.PagerResponderNext(v.newListPager, req) diff --git a/sdk/resourcemanager/compute/armcompute/fake_example_test.go b/sdk/resourcemanager/compute/armcompute/fake_example_test.go new file mode 100644 index 000000000000..731f1c7d672e --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/fake_example_test.go @@ -0,0 +1,79 @@ +//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 armcompute_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/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5/fake" +) + +func ExampleVirtualMachinesServer() { + // 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". + fakeVirtualMachinesServer := fake.VirtualMachinesServer{ + + // next, provide implementations for the APIs you wish to fake. + // this fake corresponds to the VirtualMachinesClient.Get() API. + Get: func(ctx context.Context, resourceGroupName, vmName string, options *armcompute.VirtualMachinesClientGetOptions) (resp azfake.Responder[armcompute.VirtualMachinesClientGetResponse], errResp azfake.ErrorResponder) { + // the values of ctx, resourceGroupName, vmName, 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. + + // construct the response type, populating fields as required + vmResp := armcompute.VirtualMachinesClientGetResponse{} + vmResp.ID = to.Ptr("/fake/resource/id") + + // use resp to set the desired response + resp.SetResponse(http.StatusOK, vmResp, 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 := armcompute.NewVirtualMachinesClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewVirtualMachinesServerTransport(&fakeVirtualMachinesServer), + }, + }) + 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.Get(context.TODO(), "fakeResourceGroup", "fakeVM", nil) + if err != nil { + log.Fatal(err) + } + + fmt.Println(*resp.ID) + + // APIs that haven't been faked will return an error + _, err = client.BeginDeallocate(context.TODO(), "fakeResourceGroup", "fakeVM", nil) + + fmt.Println(err.Error()) + + // Output: + // /fake/resource/id + // fake for method BeginDeallocate not implemented +} From 7c8fb5304bd9cc0a47a9de0fd76612f53a4e6090 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Fri, 9 Jun 2023 15:14:28 -0700 Subject: [PATCH 4/4] update release date --- sdk/resourcemanager/compute/armcompute/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/compute/armcompute/CHANGELOG.md b/sdk/resourcemanager/compute/armcompute/CHANGELOG.md index a2f0160a36b1..380d89339ea6 100644 --- a/sdk/resourcemanager/compute/armcompute/CHANGELOG.md +++ b/sdk/resourcemanager/compute/armcompute/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 5.1.0-beta.1 (2023-06-08) +## 5.1.0-beta.1 (2023-06-12) ### Features Added