diff --git a/sdk/resourcemanager/network/armnetwork/CHANGELOG.md b/sdk/resourcemanager/network/armnetwork/CHANGELOG.md index fc91b5076f2d..e93e7ccf6665 100644 --- a/sdk/resourcemanager/network/armnetwork/CHANGELOG.md +++ b/sdk/resourcemanager/network/armnetwork/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 3.1.0-beta.1 (2023-06-12) + +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + ## 3.0.0 (2023-05-26) ### Breaking Changes diff --git a/sdk/resourcemanager/network/armnetwork/README.md b/sdk/resourcemanager/network/armnetwork/README.md index 8ffb5332b453..2e79077928b0 100644 --- a/sdk/resourcemanager/network/armnetwork/README.md +++ b/sdk/resourcemanager/network/armnetwork/README.md @@ -60,6 +60,31 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewVirtualHubBgpConnectionsClient() ``` +## 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 +myFakeInterfacesServer := fake.InterfacesServer{} +``` +Next, provide func implementations for the methods you wish to fake. +The named return variables can be used to simplify return value construction. +```go +myFakeInterfacesServer.Get = func(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfacesClientGetOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetResponse], errResp azfake.ErrorResponder) { + // TODO: resp.SetResponse(/* your fake InterfacesClientGetResponse 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 := armnetwork.NewInterfacesClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewInterfacesServerTransport(&myFakeInterfacesServer), + }, +}) +``` + ## More sample code - [IP Address](https://aka.ms/azsdk/go/mgmt/samples?path=sdk/resourcemanager/network/ipaddress) diff --git a/sdk/resourcemanager/network/armnetwork/adminrulecollections_client.go b/sdk/resourcemanager/network/armnetwork/adminrulecollections_client.go index 4b87518f6459..b3ac8e5306ca 100644 --- a/sdk/resourcemanager/network/armnetwork/adminrulecollections_client.go +++ b/sdk/resourcemanager/network/armnetwork/adminrulecollections_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 armnetwork @@ -58,18 +57,25 @@ func NewAdminRuleCollectionsClient(subscriptionID string, credential azcore.Toke // - options - AdminRuleCollectionsClientCreateOrUpdateOptions contains the optional parameters for the AdminRuleCollectionsClient.CreateOrUpdate // method. func (client *AdminRuleCollectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleCollection AdminRuleCollection, options *AdminRuleCollectionsClientCreateOrUpdateOptions) (AdminRuleCollectionsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "AdminRuleCollectionsClient.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, networkManagerName, configurationName, ruleCollectionName, ruleCollection, options) if err != nil { return AdminRuleCollectionsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AdminRuleCollectionsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return AdminRuleCollectionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return AdminRuleCollectionsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -103,7 +109,10 @@ func (client *AdminRuleCollectionsClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, ruleCollection) + if err := runtime.MarshalAsJSON(req, ruleCollection); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -131,9 +140,10 @@ func (client *AdminRuleCollectionsClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AdminRuleCollectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AdminRuleCollectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AdminRuleCollectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -144,18 +154,24 @@ func (client *AdminRuleCollectionsClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *AdminRuleCollectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *AdminRuleCollectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "AdminRuleCollectionsClient.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, networkManagerName, configurationName, ruleCollectionName, 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. @@ -206,18 +222,25 @@ func (client *AdminRuleCollectionsClient) deleteCreateRequest(ctx context.Contex // - options - AdminRuleCollectionsClientGetOptions contains the optional parameters for the AdminRuleCollectionsClient.Get // method. func (client *AdminRuleCollectionsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *AdminRuleCollectionsClientGetOptions) (AdminRuleCollectionsClientGetResponse, error) { + var err error + const operationName = "AdminRuleCollectionsClient.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, networkManagerName, configurationName, ruleCollectionName, options) if err != nil { return AdminRuleCollectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AdminRuleCollectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AdminRuleCollectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return AdminRuleCollectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -277,6 +300,7 @@ func (client *AdminRuleCollectionsClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AdminRuleCollectionsClientListResponse) (AdminRuleCollectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AdminRuleCollectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -296,6 +320,7 @@ func (client *AdminRuleCollectionsClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/adminrules_client.go b/sdk/resourcemanager/network/armnetwork/adminrules_client.go index 9ab4fe2dc772..de14e6298d96 100644 --- a/sdk/resourcemanager/network/armnetwork/adminrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/adminrules_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 armnetwork @@ -59,18 +58,25 @@ func NewAdminRulesClient(subscriptionID string, credential azcore.TokenCredentia // - options - AdminRulesClientCreateOrUpdateOptions contains the optional parameters for the AdminRulesClient.CreateOrUpdate // method. func (client *AdminRulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, adminRule BaseAdminRuleClassification, options *AdminRulesClientCreateOrUpdateOptions) (AdminRulesClientCreateOrUpdateResponse, error) { + var err error + const operationName = "AdminRulesClient.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, networkManagerName, configurationName, ruleCollectionName, ruleName, adminRule, options) if err != nil { return AdminRulesClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AdminRulesClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return AdminRulesClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return AdminRulesClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -108,7 +114,10 @@ func (client *AdminRulesClient) createOrUpdateCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, adminRule) + if err := runtime.MarshalAsJSON(req, adminRule); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -136,9 +145,10 @@ func (client *AdminRulesClient) BeginDelete(ctx context.Context, resourceGroupNa if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AdminRulesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AdminRulesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AdminRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -149,18 +159,24 @@ func (client *AdminRulesClient) BeginDelete(ctx context.Context, resourceGroupNa // // Generated from API version 2022-11-01 func (client *AdminRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *AdminRulesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "AdminRulesClient.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, networkManagerName, configurationName, ruleCollectionName, ruleName, 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. @@ -215,18 +231,25 @@ func (client *AdminRulesClient) deleteCreateRequest(ctx context.Context, resourc // - ruleName - The name of the rule. // - options - AdminRulesClientGetOptions contains the optional parameters for the AdminRulesClient.Get method. func (client *AdminRulesClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *AdminRulesClientGetOptions) (AdminRulesClientGetResponse, error) { + var err error + const operationName = "AdminRulesClient.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, networkManagerName, configurationName, ruleCollectionName, ruleName, options) if err != nil { return AdminRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AdminRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AdminRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return AdminRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -290,6 +313,7 @@ func (client *AdminRulesClient) NewListPager(resourceGroupName string, networkMa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AdminRulesClientListResponse) (AdminRulesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AdminRulesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -309,6 +333,7 @@ func (client *AdminRulesClient) NewListPager(resourceGroupName string, networkMa } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/applicationgatewayprivateendpointconnections_client.go b/sdk/resourcemanager/network/armnetwork/applicationgatewayprivateendpointconnections_client.go index 329872812c16..1e2b86bdcf6e 100644 --- a/sdk/resourcemanager/network/armnetwork/applicationgatewayprivateendpointconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/applicationgatewayprivateendpointconnections_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 armnetwork @@ -60,9 +59,10 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) BeginDelete(ct if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) BeginDelete(ct // // Generated from API version 2022-11-01 func (client *ApplicationGatewayPrivateEndpointConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewayPrivateEndpointConnectionsClient.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, applicationGatewayName, connectionName, 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. @@ -127,18 +133,25 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) deleteCreateRe // - options - ApplicationGatewayPrivateEndpointConnectionsClientGetOptions contains the optional parameters for the ApplicationGatewayPrivateEndpointConnectionsClient.Get // method. func (client *ApplicationGatewayPrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientGetOptions) (ApplicationGatewayPrivateEndpointConnectionsClientGetResponse, error) { + var err error + const operationName = "ApplicationGatewayPrivateEndpointConnectionsClient.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, applicationGatewayName, connectionName, options) if err != nil { return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -193,6 +206,7 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) NewListPager(r return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationGatewayPrivateEndpointConnectionsClientListResponse) (ApplicationGatewayPrivateEndpointConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewayPrivateEndpointConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -212,6 +226,7 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) NewListPager(r } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -266,9 +281,10 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) BeginUpdate(ct if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -279,18 +295,24 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) BeginUpdate(ct // // Generated from API version 2022-11-01 func (client *ApplicationGatewayPrivateEndpointConnectionsClient) update(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, parameters ApplicationGatewayPrivateEndpointConnection, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewayPrivateEndpointConnectionsClient.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, applicationGatewayName, connectionName, 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. @@ -320,5 +342,8 @@ func (client *ApplicationGatewayPrivateEndpointConnectionsClient) updateCreateRe reqQP.Set("api-version", "2022-11-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/network/armnetwork/applicationgatewayprivatelinkresources_client.go b/sdk/resourcemanager/network/armnetwork/applicationgatewayprivatelinkresources_client.go index f66b4773c717..a832f039664f 100644 --- a/sdk/resourcemanager/network/armnetwork/applicationgatewayprivatelinkresources_client.go +++ b/sdk/resourcemanager/network/armnetwork/applicationgatewayprivatelinkresources_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 armnetwork @@ -58,6 +57,7 @@ func (client *ApplicationGatewayPrivateLinkResourcesClient) NewListPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationGatewayPrivateLinkResourcesClientListResponse) (ApplicationGatewayPrivateLinkResourcesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewayPrivateLinkResourcesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -77,6 +77,7 @@ func (client *ApplicationGatewayPrivateLinkResourcesClient) NewListPager(resourc } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/applicationgateways_client.go b/sdk/resourcemanager/network/armnetwork/applicationgateways_client.go index 597c8b16d6a0..a0a8d7c5f427 100644 --- a/sdk/resourcemanager/network/armnetwork/applicationgateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/applicationgateways_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 armnetwork @@ -59,9 +58,10 @@ func (client *ApplicationGatewaysClient) BeginBackendHealth(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientBackendHealthResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientBackendHealthResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewaysClientBackendHealthResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *ApplicationGatewaysClient) BeginBackendHealth(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ApplicationGatewaysClient) backendHealth(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysClientBeginBackendHealthOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewaysClient.BeginBackendHealth" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.backendHealthCreateRequest(ctx, resourceGroupName, applicationGatewayName, 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 } // backendHealthCreateRequest creates the BackendHealth request. @@ -131,9 +137,10 @@ func (client *ApplicationGatewaysClient) BeginBackendHealthOnDemand(ctx context. if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientBackendHealthOnDemandResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientBackendHealthOnDemandResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewaysClientBackendHealthOnDemandResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -145,18 +152,24 @@ func (client *ApplicationGatewaysClient) BeginBackendHealthOnDemand(ctx context. // // Generated from API version 2022-11-01 func (client *ApplicationGatewaysClient) backendHealthOnDemand(ctx context.Context, resourceGroupName string, applicationGatewayName string, probeRequest ApplicationGatewayOnDemandProbe, options *ApplicationGatewaysClientBeginBackendHealthOnDemandOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewaysClient.BeginBackendHealthOnDemand" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.backendHealthOnDemandCreateRequest(ctx, resourceGroupName, applicationGatewayName, probeRequest, 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 } // backendHealthOnDemandCreateRequest creates the BackendHealthOnDemand request. @@ -185,7 +198,10 @@ func (client *ApplicationGatewaysClient) backendHealthOnDemandCreateRequest(ctx } req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, probeRequest) + if err := runtime.MarshalAsJSON(req, probeRequest); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdate - Creates or updates the specified application gateway. @@ -203,9 +219,10 @@ func (client *ApplicationGatewaysClient) BeginCreateOrUpdate(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -216,18 +233,24 @@ func (client *ApplicationGatewaysClient) BeginCreateOrUpdate(ctx context.Context // // Generated from API version 2022-11-01 func (client *ApplicationGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters ApplicationGateway, options *ApplicationGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewaysClient.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, applicationGatewayName, 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. @@ -253,7 +276,10 @@ func (client *ApplicationGatewaysClient) createOrUpdateCreateRequest(ctx context reqQP.Set("api-version", "2022-11-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 the specified application gateway. @@ -270,9 +296,10 @@ func (client *ApplicationGatewaysClient) BeginDelete(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -283,18 +310,24 @@ func (client *ApplicationGatewaysClient) BeginDelete(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *ApplicationGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewaysClient.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, applicationGatewayName, 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. @@ -331,18 +364,25 @@ func (client *ApplicationGatewaysClient) deleteCreateRequest(ctx context.Context // - applicationGatewayName - The name of the application gateway. // - options - ApplicationGatewaysClientGetOptions contains the optional parameters for the ApplicationGatewaysClient.Get method. func (client *ApplicationGatewaysClient) Get(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysClientGetOptions) (ApplicationGatewaysClientGetResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.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, applicationGatewayName, options) if err != nil { return ApplicationGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -388,18 +428,25 @@ func (client *ApplicationGatewaysClient) getHandleResponse(resp *http.Response) // - options - ApplicationGatewaysClientGetSSLPredefinedPolicyOptions contains the optional parameters for the ApplicationGatewaysClient.GetSSLPredefinedPolicy // method. func (client *ApplicationGatewaysClient) GetSSLPredefinedPolicy(ctx context.Context, predefinedPolicyName string, options *ApplicationGatewaysClientGetSSLPredefinedPolicyOptions) (ApplicationGatewaysClientGetSSLPredefinedPolicyResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.GetSSLPredefinedPolicy" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getSSLPredefinedPolicyCreateRequest(ctx, predefinedPolicyName, options) if err != nil { return ApplicationGatewaysClientGetSSLPredefinedPolicyResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientGetSSLPredefinedPolicyResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientGetSSLPredefinedPolicyResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientGetSSLPredefinedPolicyResponse{}, err } - return client.getSSLPredefinedPolicyHandleResponse(resp) + resp, err := client.getSSLPredefinedPolicyHandleResponse(httpResp) + return resp, err } // getSSLPredefinedPolicyCreateRequest creates the GetSSLPredefinedPolicy request. @@ -445,6 +492,7 @@ func (client *ApplicationGatewaysClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationGatewaysClientListResponse) (ApplicationGatewaysClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewaysClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -464,6 +512,7 @@ func (client *ApplicationGatewaysClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -509,6 +558,7 @@ func (client *ApplicationGatewaysClient) NewListAllPager(options *ApplicationGat return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationGatewaysClientListAllResponse) (ApplicationGatewaysClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewaysClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -528,6 +578,7 @@ func (client *ApplicationGatewaysClient) NewListAllPager(options *ApplicationGat } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -565,18 +616,25 @@ func (client *ApplicationGatewaysClient) listAllHandleResponse(resp *http.Respon // - options - ApplicationGatewaysClientListAvailableRequestHeadersOptions contains the optional parameters for the ApplicationGatewaysClient.ListAvailableRequestHeaders // method. func (client *ApplicationGatewaysClient) ListAvailableRequestHeaders(ctx context.Context, options *ApplicationGatewaysClientListAvailableRequestHeadersOptions) (ApplicationGatewaysClientListAvailableRequestHeadersResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.ListAvailableRequestHeaders" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAvailableRequestHeadersCreateRequest(ctx, options) if err != nil { return ApplicationGatewaysClientListAvailableRequestHeadersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientListAvailableRequestHeadersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientListAvailableRequestHeadersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientListAvailableRequestHeadersResponse{}, err } - return client.listAvailableRequestHeadersHandleResponse(resp) + resp, err := client.listAvailableRequestHeadersHandleResponse(httpResp) + return resp, err } // listAvailableRequestHeadersCreateRequest creates the ListAvailableRequestHeaders request. @@ -613,18 +671,25 @@ func (client *ApplicationGatewaysClient) listAvailableRequestHeadersHandleRespon // - options - ApplicationGatewaysClientListAvailableResponseHeadersOptions contains the optional parameters for the ApplicationGatewaysClient.ListAvailableResponseHeaders // method. func (client *ApplicationGatewaysClient) ListAvailableResponseHeaders(ctx context.Context, options *ApplicationGatewaysClientListAvailableResponseHeadersOptions) (ApplicationGatewaysClientListAvailableResponseHeadersResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.ListAvailableResponseHeaders" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAvailableResponseHeadersCreateRequest(ctx, options) if err != nil { return ApplicationGatewaysClientListAvailableResponseHeadersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientListAvailableResponseHeadersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientListAvailableResponseHeadersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientListAvailableResponseHeadersResponse{}, err } - return client.listAvailableResponseHeadersHandleResponse(resp) + resp, err := client.listAvailableResponseHeadersHandleResponse(httpResp) + return resp, err } // listAvailableResponseHeadersCreateRequest creates the ListAvailableResponseHeaders request. @@ -661,18 +726,25 @@ func (client *ApplicationGatewaysClient) listAvailableResponseHeadersHandleRespo // - options - ApplicationGatewaysClientListAvailableSSLOptionsOptions contains the optional parameters for the ApplicationGatewaysClient.ListAvailableSSLOptions // method. func (client *ApplicationGatewaysClient) ListAvailableSSLOptions(ctx context.Context, options *ApplicationGatewaysClientListAvailableSSLOptionsOptions) (ApplicationGatewaysClientListAvailableSSLOptionsResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.ListAvailableSSLOptions" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAvailableSSLOptionsCreateRequest(ctx, options) if err != nil { return ApplicationGatewaysClientListAvailableSSLOptionsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientListAvailableSSLOptionsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientListAvailableSSLOptionsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientListAvailableSSLOptionsResponse{}, err } - return client.listAvailableSSLOptionsHandleResponse(resp) + resp, err := client.listAvailableSSLOptionsHandleResponse(httpResp) + return resp, err } // listAvailableSSLOptionsCreateRequest creates the ListAvailableSSLOptions request. @@ -713,6 +785,7 @@ func (client *ApplicationGatewaysClient) NewListAvailableSSLPredefinedPoliciesPa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationGatewaysClientListAvailableSSLPredefinedPoliciesResponse) (ApplicationGatewaysClientListAvailableSSLPredefinedPoliciesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewaysClient.NewListAvailableSSLPredefinedPoliciesPager") var req *policy.Request var err error if page == nil { @@ -732,6 +805,7 @@ func (client *ApplicationGatewaysClient) NewListAvailableSSLPredefinedPoliciesPa } return client.listAvailableSSLPredefinedPoliciesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -769,18 +843,25 @@ func (client *ApplicationGatewaysClient) listAvailableSSLPredefinedPoliciesHandl // - options - ApplicationGatewaysClientListAvailableServerVariablesOptions contains the optional parameters for the ApplicationGatewaysClient.ListAvailableServerVariables // method. func (client *ApplicationGatewaysClient) ListAvailableServerVariables(ctx context.Context, options *ApplicationGatewaysClientListAvailableServerVariablesOptions) (ApplicationGatewaysClientListAvailableServerVariablesResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.ListAvailableServerVariables" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAvailableServerVariablesCreateRequest(ctx, options) if err != nil { return ApplicationGatewaysClientListAvailableServerVariablesResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientListAvailableServerVariablesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientListAvailableServerVariablesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientListAvailableServerVariablesResponse{}, err } - return client.listAvailableServerVariablesHandleResponse(resp) + resp, err := client.listAvailableServerVariablesHandleResponse(httpResp) + return resp, err } // listAvailableServerVariablesCreateRequest creates the ListAvailableServerVariables request. @@ -817,18 +898,25 @@ func (client *ApplicationGatewaysClient) listAvailableServerVariablesHandleRespo // - options - ApplicationGatewaysClientListAvailableWafRuleSetsOptions contains the optional parameters for the ApplicationGatewaysClient.ListAvailableWafRuleSets // method. func (client *ApplicationGatewaysClient) ListAvailableWafRuleSets(ctx context.Context, options *ApplicationGatewaysClientListAvailableWafRuleSetsOptions) (ApplicationGatewaysClientListAvailableWafRuleSetsResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.ListAvailableWafRuleSets" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAvailableWafRuleSetsCreateRequest(ctx, options) if err != nil { return ApplicationGatewaysClientListAvailableWafRuleSetsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientListAvailableWafRuleSetsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientListAvailableWafRuleSetsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientListAvailableWafRuleSetsResponse{}, err } - return client.listAvailableWafRuleSetsHandleResponse(resp) + resp, err := client.listAvailableWafRuleSetsHandleResponse(httpResp) + return resp, err } // listAvailableWafRuleSetsCreateRequest creates the ListAvailableWafRuleSets request. @@ -872,9 +960,10 @@ func (client *ApplicationGatewaysClient) BeginStart(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientStartResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientStartResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewaysClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -885,18 +974,24 @@ func (client *ApplicationGatewaysClient) BeginStart(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *ApplicationGatewaysClient) start(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysClientBeginStartOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewaysClient.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, applicationGatewayName, 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. @@ -939,9 +1034,10 @@ func (client *ApplicationGatewaysClient) BeginStop(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientStopResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewaysClientStopResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationGatewaysClientStopResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -952,18 +1048,24 @@ func (client *ApplicationGatewaysClient) BeginStop(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *ApplicationGatewaysClient) stop(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysClientBeginStopOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationGatewaysClient.BeginStop" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopCreateRequest(ctx, resourceGroupName, applicationGatewayName, 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 } // stopCreateRequest creates the Stop request. @@ -1002,18 +1104,25 @@ func (client *ApplicationGatewaysClient) stopCreateRequest(ctx context.Context, // - options - ApplicationGatewaysClientUpdateTagsOptions contains the optional parameters for the ApplicationGatewaysClient.UpdateTags // method. func (client *ApplicationGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters TagsObject, options *ApplicationGatewaysClientUpdateTagsOptions) (ApplicationGatewaysClientUpdateTagsResponse, error) { + var err error + const operationName = "ApplicationGatewaysClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, applicationGatewayName, parameters, options) if err != nil { return ApplicationGatewaysClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewaysClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewaysClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewaysClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -1039,7 +1148,10 @@ func (client *ApplicationGatewaysClient) updateTagsCreateRequest(ctx context.Con reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifests_client.go b/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifests_client.go index 740dd2fd02dd..fbf25dd48022 100644 --- a/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifests_client.go +++ b/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifests_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 armnetwork @@ -57,6 +56,7 @@ func (client *ApplicationGatewayWafDynamicManifestsClient) NewGetPager(location return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationGatewayWafDynamicManifestsClientGetResponse) (ApplicationGatewayWafDynamicManifestsClientGetResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewayWafDynamicManifestsClient.NewGetPager") var req *policy.Request var err error if page == nil { @@ -76,6 +76,7 @@ func (client *ApplicationGatewayWafDynamicManifestsClient) NewGetPager(location } return client.getHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifestsdefault_client.go b/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifestsdefault_client.go index ce0539dbfd63..86bcece24af6 100644 --- a/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifestsdefault_client.go +++ b/sdk/resourcemanager/network/armnetwork/applicationgatewaywafdynamicmanifestsdefault_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 armnetwork @@ -53,18 +52,25 @@ func NewApplicationGatewayWafDynamicManifestsDefaultClient(subscriptionID string // - options - ApplicationGatewayWafDynamicManifestsDefaultClientGetOptions contains the optional parameters for the ApplicationGatewayWafDynamicManifestsDefaultClient.Get // method. func (client *ApplicationGatewayWafDynamicManifestsDefaultClient) Get(ctx context.Context, location string, options *ApplicationGatewayWafDynamicManifestsDefaultClientGetOptions) (ApplicationGatewayWafDynamicManifestsDefaultClientGetResponse, error) { + var err error + const operationName = "ApplicationGatewayWafDynamicManifestsDefaultClient.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, options) if err != nil { return ApplicationGatewayWafDynamicManifestsDefaultClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationGatewayWafDynamicManifestsDefaultClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationGatewayWafDynamicManifestsDefaultClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationGatewayWafDynamicManifestsDefaultClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. diff --git a/sdk/resourcemanager/network/armnetwork/applicationsecuritygroups_client.go b/sdk/resourcemanager/network/armnetwork/applicationsecuritygroups_client.go index 3093ffc1339f..ca8da50ae544 100644 --- a/sdk/resourcemanager/network/armnetwork/applicationsecuritygroups_client.go +++ b/sdk/resourcemanager/network/armnetwork/applicationsecuritygroups_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 armnetwork @@ -60,9 +59,10 @@ func (client *ApplicationSecurityGroupsClient) BeginCreateOrUpdate(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationSecurityGroupsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationSecurityGroupsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationSecurityGroupsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ApplicationSecurityGroupsClient) BeginCreateOrUpdate(ctx context.C // // Generated from API version 2022-11-01 func (client *ApplicationSecurityGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, parameters ApplicationSecurityGroup, options *ApplicationSecurityGroupsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationSecurityGroupsClient.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, applicationSecurityGroupName, 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. @@ -110,7 +116,10 @@ func (client *ApplicationSecurityGroupsClient) createOrUpdateCreateRequest(ctx c reqQP.Set("api-version", "2022-11-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 the specified application security group. @@ -127,9 +136,10 @@ func (client *ApplicationSecurityGroupsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationSecurityGroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationSecurityGroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ApplicationSecurityGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *ApplicationSecurityGroupsClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ApplicationSecurityGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, options *ApplicationSecurityGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationSecurityGroupsClient.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, applicationSecurityGroupName, 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. @@ -189,18 +205,25 @@ func (client *ApplicationSecurityGroupsClient) deleteCreateRequest(ctx context.C // - options - ApplicationSecurityGroupsClientGetOptions contains the optional parameters for the ApplicationSecurityGroupsClient.Get // method. func (client *ApplicationSecurityGroupsClient) Get(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, options *ApplicationSecurityGroupsClientGetOptions) (ApplicationSecurityGroupsClientGetResponse, error) { + var err error + const operationName = "ApplicationSecurityGroupsClient.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, applicationSecurityGroupName, options) if err != nil { return ApplicationSecurityGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationSecurityGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationSecurityGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationSecurityGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *ApplicationSecurityGroupsClient) NewListPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationSecurityGroupsClientListResponse) (ApplicationSecurityGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationSecurityGroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *ApplicationSecurityGroupsClient) NewListPager(resourceGroupName st } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -314,6 +339,7 @@ func (client *ApplicationSecurityGroupsClient) NewListAllPager(options *Applicat return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationSecurityGroupsClientListAllResponse) (ApplicationSecurityGroupsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationSecurityGroupsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -333,6 +359,7 @@ func (client *ApplicationSecurityGroupsClient) NewListAllPager(options *Applicat } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -373,18 +400,25 @@ func (client *ApplicationSecurityGroupsClient) listAllHandleResponse(resp *http. // - options - ApplicationSecurityGroupsClientUpdateTagsOptions contains the optional parameters for the ApplicationSecurityGroupsClient.UpdateTags // method. func (client *ApplicationSecurityGroupsClient) UpdateTags(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, parameters TagsObject, options *ApplicationSecurityGroupsClientUpdateTagsOptions) (ApplicationSecurityGroupsClientUpdateTagsResponse, error) { + var err error + const operationName = "ApplicationSecurityGroupsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, applicationSecurityGroupName, parameters, options) if err != nil { return ApplicationSecurityGroupsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationSecurityGroupsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationSecurityGroupsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationSecurityGroupsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -410,7 +444,10 @@ func (client *ApplicationSecurityGroupsClient) updateTagsCreateRequest(ctx conte reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/autorest.md b/sdk/resourcemanager/network/armnetwork/autorest.md index 3851fc0937c5..e65a72b35b87 100644 --- a/sdk/resourcemanager/network/armnetwork/autorest.md +++ b/sdk/resourcemanager/network/armnetwork/autorest.md @@ -8,6 +8,10 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/17aa6a1314de5aafef059d9aa2229901df506e75/specification/network/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/17aa6a1314de5aafef059d9aa2229901df506e75/specification/network/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 3.0.0 +module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3 +module-version: 3.1.0-beta.1 tag: package-2022-11 -``` \ No newline at end of file +azcore-version: 1.7.0-beta.2 +generate-fakes: true +inject-spans: true +``` diff --git a/sdk/resourcemanager/network/armnetwork/availabledelegations_client.go b/sdk/resourcemanager/network/armnetwork/availabledelegations_client.go index 6f49382cffd6..bf561fd7fdf5 100644 --- a/sdk/resourcemanager/network/armnetwork/availabledelegations_client.go +++ b/sdk/resourcemanager/network/armnetwork/availabledelegations_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 armnetwork @@ -57,6 +56,7 @@ func (client *AvailableDelegationsClient) NewListPager(location string, options return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailableDelegationsClientListResponse) (AvailableDelegationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableDelegationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -76,6 +76,7 @@ func (client *AvailableDelegationsClient) NewListPager(location string, options } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/availableendpointservices_client.go b/sdk/resourcemanager/network/armnetwork/availableendpointservices_client.go index 01af595ba1af..3957353d80c7 100644 --- a/sdk/resourcemanager/network/armnetwork/availableendpointservices_client.go +++ b/sdk/resourcemanager/network/armnetwork/availableendpointservices_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 armnetwork @@ -57,6 +56,7 @@ func (client *AvailableEndpointServicesClient) NewListPager(location string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailableEndpointServicesClientListResponse) (AvailableEndpointServicesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableEndpointServicesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -76,6 +76,7 @@ func (client *AvailableEndpointServicesClient) NewListPager(location string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/availableprivateendpointtypes_client.go b/sdk/resourcemanager/network/armnetwork/availableprivateendpointtypes_client.go index c3891dd5481c..7cbdbd4e7158 100644 --- a/sdk/resourcemanager/network/armnetwork/availableprivateendpointtypes_client.go +++ b/sdk/resourcemanager/network/armnetwork/availableprivateendpointtypes_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 armnetwork @@ -58,6 +57,7 @@ func (client *AvailablePrivateEndpointTypesClient) NewListPager(location string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailablePrivateEndpointTypesClientListResponse) (AvailablePrivateEndpointTypesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailablePrivateEndpointTypesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -77,6 +77,7 @@ func (client *AvailablePrivateEndpointTypesClient) NewListPager(location string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -125,6 +126,7 @@ func (client *AvailablePrivateEndpointTypesClient) NewListByResourceGroupPager(l return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailablePrivateEndpointTypesClientListByResourceGroupResponse) (AvailablePrivateEndpointTypesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailablePrivateEndpointTypesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -144,6 +146,7 @@ func (client *AvailablePrivateEndpointTypesClient) NewListByResourceGroupPager(l } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/availableresourcegroupdelegations_client.go b/sdk/resourcemanager/network/armnetwork/availableresourcegroupdelegations_client.go index 88f35e9b0080..88b6a0bd4ee3 100644 --- a/sdk/resourcemanager/network/armnetwork/availableresourcegroupdelegations_client.go +++ b/sdk/resourcemanager/network/armnetwork/availableresourcegroupdelegations_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 armnetwork @@ -58,6 +57,7 @@ func (client *AvailableResourceGroupDelegationsClient) NewListPager(location str return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailableResourceGroupDelegationsClientListResponse) (AvailableResourceGroupDelegationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableResourceGroupDelegationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -77,6 +77,7 @@ func (client *AvailableResourceGroupDelegationsClient) NewListPager(location str } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/availableservicealiases_client.go b/sdk/resourcemanager/network/armnetwork/availableservicealiases_client.go index c303db2b391f..21a94b4c0892 100644 --- a/sdk/resourcemanager/network/armnetwork/availableservicealiases_client.go +++ b/sdk/resourcemanager/network/armnetwork/availableservicealiases_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 armnetwork @@ -57,6 +56,7 @@ func (client *AvailableServiceAliasesClient) NewListPager(location string, optio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailableServiceAliasesClientListResponse) (AvailableServiceAliasesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableServiceAliasesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -76,6 +76,7 @@ func (client *AvailableServiceAliasesClient) NewListPager(location string, optio } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -123,6 +124,7 @@ func (client *AvailableServiceAliasesClient) NewListByResourceGroupPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AvailableServiceAliasesClientListByResourceGroupResponse) (AvailableServiceAliasesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableServiceAliasesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -142,6 +144,7 @@ func (client *AvailableServiceAliasesClient) NewListByResourceGroupPager(resourc } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/azurefirewallfqdntags_client.go b/sdk/resourcemanager/network/armnetwork/azurefirewallfqdntags_client.go index 947ea8e07d0d..adb021f92743 100644 --- a/sdk/resourcemanager/network/armnetwork/azurefirewallfqdntags_client.go +++ b/sdk/resourcemanager/network/armnetwork/azurefirewallfqdntags_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 armnetwork @@ -56,6 +55,7 @@ func (client *AzureFirewallFqdnTagsClient) NewListAllPager(options *AzureFirewal return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AzureFirewallFqdnTagsClientListAllResponse) (AzureFirewallFqdnTagsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AzureFirewallFqdnTagsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -75,6 +75,7 @@ func (client *AzureFirewallFqdnTagsClient) NewListAllPager(options *AzureFirewal } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/azurefirewalls_client.go b/sdk/resourcemanager/network/armnetwork/azurefirewalls_client.go index c0de9312bda1..5a26bef36365 100644 --- a/sdk/resourcemanager/network/armnetwork/azurefirewalls_client.go +++ b/sdk/resourcemanager/network/armnetwork/azurefirewalls_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 armnetwork @@ -60,9 +59,10 @@ func (client *AzureFirewallsClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AzureFirewallsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *AzureFirewallsClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *AzureFirewallsClient) createOrUpdate(ctx context.Context, resourceGroupName string, azureFirewallName string, parameters AzureFirewall, options *AzureFirewallsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "AzureFirewallsClient.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, azureFirewallName, 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. @@ -110,7 +116,10 @@ func (client *AzureFirewallsClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-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 the specified Azure Firewall. @@ -127,9 +136,10 @@ func (client *AzureFirewallsClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AzureFirewallsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *AzureFirewallsClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *AzureFirewallsClient) deleteOperation(ctx context.Context, resourceGroupName string, azureFirewallName string, options *AzureFirewallsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "AzureFirewallsClient.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, azureFirewallName, 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 *AzureFirewallsClient) deleteCreateRequest(ctx context.Context, res // - azureFirewallName - The name of the Azure Firewall. // - options - AzureFirewallsClientGetOptions contains the optional parameters for the AzureFirewallsClient.Get method. func (client *AzureFirewallsClient) Get(ctx context.Context, resourceGroupName string, azureFirewallName string, options *AzureFirewallsClientGetOptions) (AzureFirewallsClientGetResponse, error) { + var err error + const operationName = "AzureFirewallsClient.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, azureFirewallName, options) if err != nil { return AzureFirewallsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return AzureFirewallsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AzureFirewallsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return AzureFirewallsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -248,6 +271,7 @@ func (client *AzureFirewallsClient) NewListPager(resourceGroupName string, optio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AzureFirewallsClientListResponse) (AzureFirewallsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AzureFirewallsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -267,6 +291,7 @@ func (client *AzureFirewallsClient) NewListPager(resourceGroupName string, optio } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -312,6 +337,7 @@ func (client *AzureFirewallsClient) NewListAllPager(options *AzureFirewallsClien return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AzureFirewallsClientListAllResponse) (AzureFirewallsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AzureFirewallsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -331,6 +357,7 @@ func (client *AzureFirewallsClient) NewListAllPager(options *AzureFirewallsClien } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -375,9 +402,10 @@ func (client *AzureFirewallsClient) BeginListLearnedPrefixes(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientListLearnedPrefixesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientListLearnedPrefixesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AzureFirewallsClientListLearnedPrefixesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -388,18 +416,24 @@ func (client *AzureFirewallsClient) BeginListLearnedPrefixes(ctx context.Context // // Generated from API version 2022-11-01 func (client *AzureFirewallsClient) listLearnedPrefixes(ctx context.Context, resourceGroupName string, azureFirewallName string, options *AzureFirewallsClientBeginListLearnedPrefixesOptions) (*http.Response, error) { + var err error + const operationName = "AzureFirewallsClient.BeginListLearnedPrefixes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listLearnedPrefixesCreateRequest(ctx, resourceGroupName, azureFirewallName, 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 } // listLearnedPrefixesCreateRequest creates the ListLearnedPrefixes request. @@ -443,9 +477,10 @@ func (client *AzureFirewallsClient) BeginPacketCapture(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AzureFirewallsClientPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -456,18 +491,24 @@ func (client *AzureFirewallsClient) BeginPacketCapture(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *AzureFirewallsClient) packetCapture(ctx context.Context, resourceGroupName string, azureFirewallName string, parameters FirewallPacketCaptureParameters, options *AzureFirewallsClientBeginPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "AzureFirewallsClient.BeginPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.packetCaptureCreateRequest(ctx, resourceGroupName, azureFirewallName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // packetCaptureCreateRequest creates the PacketCapture request. @@ -493,7 +534,10 @@ func (client *AzureFirewallsClient) packetCaptureCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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 } // BeginUpdateTags - Updates tags of an Azure Firewall resource. @@ -511,9 +555,10 @@ func (client *AzureFirewallsClient) BeginUpdateTags(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AzureFirewallsClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[AzureFirewallsClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -524,18 +569,24 @@ func (client *AzureFirewallsClient) BeginUpdateTags(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *AzureFirewallsClient) updateTags(ctx context.Context, resourceGroupName string, azureFirewallName string, parameters TagsObject, options *AzureFirewallsClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "AzureFirewallsClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, azureFirewallName, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -561,5 +612,8 @@ func (client *AzureFirewallsClient) updateTagsCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-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/network/armnetwork/bastionhosts_client.go b/sdk/resourcemanager/network/armnetwork/bastionhosts_client.go index cbd9e84d8f76..45bc2c1f15e0 100644 --- a/sdk/resourcemanager/network/armnetwork/bastionhosts_client.go +++ b/sdk/resourcemanager/network/armnetwork/bastionhosts_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 armnetwork @@ -60,9 +59,10 @@ func (client *BastionHostsClient) BeginCreateOrUpdate(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[BastionHostsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[BastionHostsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[BastionHostsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *BastionHostsClient) BeginCreateOrUpdate(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *BastionHostsClient) createOrUpdate(ctx context.Context, resourceGroupName string, bastionHostName string, parameters BastionHost, options *BastionHostsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "BastionHostsClient.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, bastionHostName, 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. @@ -110,7 +116,10 @@ func (client *BastionHostsClient) createOrUpdateCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-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 the specified Bastion Host. @@ -127,9 +136,10 @@ func (client *BastionHostsClient) BeginDelete(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[BastionHostsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[BastionHostsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[BastionHostsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *BastionHostsClient) BeginDelete(ctx context.Context, resourceGroup // // Generated from API version 2022-11-01 func (client *BastionHostsClient) deleteOperation(ctx context.Context, resourceGroupName string, bastionHostName string, options *BastionHostsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "BastionHostsClient.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, bastionHostName, 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 *BastionHostsClient) deleteCreateRequest(ctx context.Context, resou // - bastionHostName - The name of the Bastion Host. // - options - BastionHostsClientGetOptions contains the optional parameters for the BastionHostsClient.Get method. func (client *BastionHostsClient) Get(ctx context.Context, resourceGroupName string, bastionHostName string, options *BastionHostsClientGetOptions) (BastionHostsClientGetResponse, error) { + var err error + const operationName = "BastionHostsClient.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, bastionHostName, options) if err != nil { return BastionHostsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return BastionHostsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return BastionHostsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return BastionHostsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -247,6 +270,7 @@ func (client *BastionHostsClient) NewListPager(options *BastionHostsClientListOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *BastionHostsClientListResponse) (BastionHostsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "BastionHostsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -266,6 +290,7 @@ func (client *BastionHostsClient) NewListPager(options *BastionHostsClientListOp } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -308,6 +333,7 @@ func (client *BastionHostsClient) NewListByResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *BastionHostsClientListByResourceGroupResponse) (BastionHostsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "BastionHostsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -327,6 +353,7 @@ func (client *BastionHostsClient) NewListByResourceGroupPager(resourceGroupName } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -376,9 +403,10 @@ func (client *BastionHostsClient) BeginUpdateTags(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[BastionHostsClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[BastionHostsClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[BastionHostsClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -389,18 +417,24 @@ func (client *BastionHostsClient) BeginUpdateTags(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *BastionHostsClient) updateTags(ctx context.Context, resourceGroupName string, bastionHostName string, parameters TagsObject, options *BastionHostsClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "BastionHostsClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, bastionHostName, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -426,5 +460,8 @@ func (client *BastionHostsClient) updateTagsCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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/network/armnetwork/bgpservicecommunities_client.go b/sdk/resourcemanager/network/armnetwork/bgpservicecommunities_client.go index fa6fd0123437..1f63cae0b837 100644 --- a/sdk/resourcemanager/network/armnetwork/bgpservicecommunities_client.go +++ b/sdk/resourcemanager/network/armnetwork/bgpservicecommunities_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 armnetwork @@ -56,6 +55,7 @@ func (client *BgpServiceCommunitiesClient) NewListPager(options *BgpServiceCommu return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *BgpServiceCommunitiesClientListResponse) (BgpServiceCommunitiesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "BgpServiceCommunitiesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -75,6 +75,7 @@ func (client *BgpServiceCommunitiesClient) NewListPager(options *BgpServiceCommu } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/build.go b/sdk/resourcemanager/network/armnetwork/build.go index a22250100257..8396f2f2a30f 100644 --- a/sdk/resourcemanager/network/armnetwork/build.go +++ b/sdk/resourcemanager/network/armnetwork/build.go @@ -2,6 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // This file enables 'go generate' to regenerate this specific SDK -//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/network/armnetwork +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.51" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/network/armnetwork package armnetwork diff --git a/sdk/resourcemanager/network/armnetwork/client_factory.go b/sdk/resourcemanager/network/armnetwork/client_factory.go index b604bf2620c5..66e7298c2850 100644 --- a/sdk/resourcemanager/network/armnetwork/client_factory.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork diff --git a/sdk/resourcemanager/network/armnetwork/configurationpolicygroups_client.go b/sdk/resourcemanager/network/armnetwork/configurationpolicygroups_client.go index eb2e01313304..1cd53376f1c0 100644 --- a/sdk/resourcemanager/network/armnetwork/configurationpolicygroups_client.go +++ b/sdk/resourcemanager/network/armnetwork/configurationpolicygroups_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 armnetwork @@ -61,9 +60,10 @@ func (client *ConfigurationPolicyGroupsClient) BeginCreateOrUpdate(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConfigurationPolicyGroupsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConfigurationPolicyGroupsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConfigurationPolicyGroupsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ConfigurationPolicyGroupsClient) BeginCreateOrUpdate(ctx context.C // // Generated from API version 2022-11-01 func (client *ConfigurationPolicyGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, vpnServerConfigurationPolicyGroupParameters VPNServerConfigurationPolicyGroup, options *ConfigurationPolicyGroupsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ConfigurationPolicyGroupsClient.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, vpnServerConfigurationName, configurationPolicyGroupName, vpnServerConfigurationPolicyGroupParameters, 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. @@ -115,7 +121,10 @@ func (client *ConfigurationPolicyGroupsClient) createOrUpdateCreateRequest(ctx c reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnServerConfigurationPolicyGroupParameters) + if err := runtime.MarshalAsJSON(req, vpnServerConfigurationPolicyGroupParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a ConfigurationPolicyGroup. @@ -133,9 +142,10 @@ func (client *ConfigurationPolicyGroupsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConfigurationPolicyGroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConfigurationPolicyGroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConfigurationPolicyGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ConfigurationPolicyGroupsClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ConfigurationPolicyGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, options *ConfigurationPolicyGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ConfigurationPolicyGroupsClient.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, vpnServerConfigurationName, configurationPolicyGroupName, 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. @@ -200,18 +216,25 @@ func (client *ConfigurationPolicyGroupsClient) deleteCreateRequest(ctx context.C // - options - ConfigurationPolicyGroupsClientGetOptions contains the optional parameters for the ConfigurationPolicyGroupsClient.Get // method. func (client *ConfigurationPolicyGroupsClient) Get(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, options *ConfigurationPolicyGroupsClientGetOptions) (ConfigurationPolicyGroupsClientGetResponse, error) { + var err error + const operationName = "ConfigurationPolicyGroupsClient.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, vpnServerConfigurationName, configurationPolicyGroupName, options) if err != nil { return ConfigurationPolicyGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ConfigurationPolicyGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ConfigurationPolicyGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ConfigurationPolicyGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *ConfigurationPolicyGroupsClient) NewListByVPNServerConfigurationPa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ConfigurationPolicyGroupsClientListByVPNServerConfigurationResponse) (ConfigurationPolicyGroupsClientListByVPNServerConfigurationResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ConfigurationPolicyGroupsClient.NewListByVPNServerConfigurationPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *ConfigurationPolicyGroupsClient) NewListByVPNServerConfigurationPa } return client.listByVPNServerConfigurationHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/connectionmonitors_client.go b/sdk/resourcemanager/network/armnetwork/connectionmonitors_client.go index eb6a1145c98e..ed89553c3c0e 100644 --- a/sdk/resourcemanager/network/armnetwork/connectionmonitors_client.go +++ b/sdk/resourcemanager/network/armnetwork/connectionmonitors_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 armnetwork @@ -61,9 +60,10 @@ func (client *ConnectionMonitorsClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConnectionMonitorsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ConnectionMonitorsClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ConnectionMonitorsClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters ConnectionMonitor, options *ConnectionMonitorsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ConnectionMonitorsClient.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, networkWatcherName, connectionMonitorName, 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. @@ -118,7 +124,10 @@ func (client *ConnectionMonitorsClient) createOrUpdateCreateRequest(ctx context. } 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 the specified connection monitor. @@ -136,9 +145,10 @@ func (client *ConnectionMonitorsClient) BeginDelete(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConnectionMonitorsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -149,18 +159,24 @@ func (client *ConnectionMonitorsClient) BeginDelete(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *ConnectionMonitorsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ConnectionMonitorsClient.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, networkWatcherName, connectionMonitorName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -202,18 +218,25 @@ func (client *ConnectionMonitorsClient) deleteCreateRequest(ctx context.Context, // - connectionMonitorName - The name of the connection monitor. // - options - ConnectionMonitorsClientGetOptions contains the optional parameters for the ConnectionMonitorsClient.Get method. func (client *ConnectionMonitorsClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientGetOptions) (ConnectionMonitorsClientGetResponse, error) { + var err error + const operationName = "ConnectionMonitorsClient.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, networkWatcherName, connectionMonitorName, options) if err != nil { return ConnectionMonitorsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ConnectionMonitorsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ConnectionMonitorsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ConnectionMonitorsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -268,6 +291,7 @@ func (client *ConnectionMonitorsClient) NewListPager(resourceGroupName string, n return false }, Fetcher: func(ctx context.Context, page *ConnectionMonitorsClientListResponse) (ConnectionMonitorsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ConnectionMonitorsClient.NewListPager") req, err := client.listCreateRequest(ctx, resourceGroupName, networkWatcherName, options) if err != nil { return ConnectionMonitorsClientListResponse{}, err @@ -281,6 +305,7 @@ func (client *ConnectionMonitorsClient) NewListPager(resourceGroupName string, n } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -334,9 +359,10 @@ func (client *ConnectionMonitorsClient) BeginQuery(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientQueryResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientQueryResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConnectionMonitorsClientQueryResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -347,18 +373,24 @@ func (client *ConnectionMonitorsClient) BeginQuery(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *ConnectionMonitorsClient) query(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginQueryOptions) (*http.Response, error) { + var err error + const operationName = "ConnectionMonitorsClient.BeginQuery" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.queryCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, 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 } // queryCreateRequest creates the Query request. @@ -406,9 +438,10 @@ func (client *ConnectionMonitorsClient) BeginStart(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientStartResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientStartResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConnectionMonitorsClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -419,18 +452,24 @@ func (client *ConnectionMonitorsClient) BeginStart(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *ConnectionMonitorsClient) start(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStartOptions) (*http.Response, error) { + var err error + const operationName = "ConnectionMonitorsClient.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, networkWatcherName, connectionMonitorName, 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. @@ -478,9 +517,10 @@ func (client *ConnectionMonitorsClient) BeginStop(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientStopResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectionMonitorsClientStopResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConnectionMonitorsClientStopResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -491,18 +531,24 @@ func (client *ConnectionMonitorsClient) BeginStop(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *ConnectionMonitorsClient) stop(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *ConnectionMonitorsClientBeginStopOptions) (*http.Response, error) { + var err error + const operationName = "ConnectionMonitorsClient.BeginStop" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, 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 } // stopCreateRequest creates the Stop request. @@ -546,18 +592,25 @@ func (client *ConnectionMonitorsClient) stopCreateRequest(ctx context.Context, r // - options - ConnectionMonitorsClientUpdateTagsOptions contains the optional parameters for the ConnectionMonitorsClient.UpdateTags // method. func (client *ConnectionMonitorsClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters TagsObject, options *ConnectionMonitorsClientUpdateTagsOptions) (ConnectionMonitorsClientUpdateTagsResponse, error) { + var err error + const operationName = "ConnectionMonitorsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, parameters, options) if err != nil { return ConnectionMonitorsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ConnectionMonitorsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ConnectionMonitorsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ConnectionMonitorsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -587,7 +640,10 @@ func (client *ConnectionMonitorsClient) updateTagsCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/connectivityconfigurations_client.go b/sdk/resourcemanager/network/armnetwork/connectivityconfigurations_client.go index 466646324b34..e848088ba3d3 100644 --- a/sdk/resourcemanager/network/armnetwork/connectivityconfigurations_client.go +++ b/sdk/resourcemanager/network/armnetwork/connectivityconfigurations_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 armnetwork @@ -57,18 +56,25 @@ func NewConnectivityConfigurationsClient(subscriptionID string, credential azcor // - options - ConnectivityConfigurationsClientCreateOrUpdateOptions contains the optional parameters for the ConnectivityConfigurationsClient.CreateOrUpdate // method. func (client *ConnectivityConfigurationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, connectivityConfiguration ConnectivityConfiguration, options *ConnectivityConfigurationsClientCreateOrUpdateOptions) (ConnectivityConfigurationsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ConnectivityConfigurationsClient.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, networkManagerName, configurationName, connectivityConfiguration, options) if err != nil { return ConnectivityConfigurationsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ConnectivityConfigurationsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ConnectivityConfigurationsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ConnectivityConfigurationsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -98,7 +104,10 @@ func (client *ConnectivityConfigurationsClient) createOrUpdateCreateRequest(ctx reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, connectivityConfiguration) + if err := runtime.MarshalAsJSON(req, connectivityConfiguration); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -126,9 +135,10 @@ func (client *ConnectivityConfigurationsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectivityConfigurationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConnectivityConfigurationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ConnectivityConfigurationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *ConnectivityConfigurationsClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ConnectivityConfigurationsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *ConnectivityConfigurationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ConnectivityConfigurationsClient.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, networkManagerName, configurationName, 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. @@ -198,18 +214,25 @@ func (client *ConnectivityConfigurationsClient) deleteCreateRequest(ctx context. // - options - ConnectivityConfigurationsClientGetOptions contains the optional parameters for the ConnectivityConfigurationsClient.Get // method. func (client *ConnectivityConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *ConnectivityConfigurationsClientGetOptions) (ConnectivityConfigurationsClientGetResponse, error) { + var err error + const operationName = "ConnectivityConfigurationsClient.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, networkManagerName, configurationName, options) if err != nil { return ConnectivityConfigurationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ConnectivityConfigurationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ConnectivityConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ConnectivityConfigurationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -264,6 +287,7 @@ func (client *ConnectivityConfigurationsClient) NewListPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ConnectivityConfigurationsClientListResponse) (ConnectivityConfigurationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ConnectivityConfigurationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -283,6 +307,7 @@ func (client *ConnectivityConfigurationsClient) NewListPager(resourceGroupName s } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/constants.go b/sdk/resourcemanager/network/armnetwork/constants.go index 4ea4aa1ac191..581ba61f0357 100644 --- a/sdk/resourcemanager/network/armnetwork/constants.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork const ( moduleName = "armnetwork" - moduleVersion = "v3.0.0" + moduleVersion = "v3.1.0-beta.1" ) // Access - Access to be allowed or denied. @@ -1606,17 +1605,17 @@ func PossibleFirewallPolicyIDPSQuerySortOrderValues() []FirewallPolicyIDPSQueryS type FirewallPolicyIDPSSignatureDirection int32 const ( - FirewallPolicyIDPSSignatureDirectionZero FirewallPolicyIDPSSignatureDirection = 0 FirewallPolicyIDPSSignatureDirectionOne FirewallPolicyIDPSSignatureDirection = 1 FirewallPolicyIDPSSignatureDirectionTwo FirewallPolicyIDPSSignatureDirection = 2 + FirewallPolicyIDPSSignatureDirectionZero FirewallPolicyIDPSSignatureDirection = 0 ) // PossibleFirewallPolicyIDPSSignatureDirectionValues returns the possible values for the FirewallPolicyIDPSSignatureDirection const type. func PossibleFirewallPolicyIDPSSignatureDirectionValues() []FirewallPolicyIDPSSignatureDirection { return []FirewallPolicyIDPSSignatureDirection{ - FirewallPolicyIDPSSignatureDirectionZero, FirewallPolicyIDPSSignatureDirectionOne, FirewallPolicyIDPSSignatureDirectionTwo, + FirewallPolicyIDPSSignatureDirectionZero, } } @@ -1624,17 +1623,17 @@ func PossibleFirewallPolicyIDPSSignatureDirectionValues() []FirewallPolicyIDPSSi type FirewallPolicyIDPSSignatureMode int32 const ( - FirewallPolicyIDPSSignatureModeZero FirewallPolicyIDPSSignatureMode = 0 FirewallPolicyIDPSSignatureModeOne FirewallPolicyIDPSSignatureMode = 1 FirewallPolicyIDPSSignatureModeTwo FirewallPolicyIDPSSignatureMode = 2 + FirewallPolicyIDPSSignatureModeZero FirewallPolicyIDPSSignatureMode = 0 ) // PossibleFirewallPolicyIDPSSignatureModeValues returns the possible values for the FirewallPolicyIDPSSignatureMode const type. func PossibleFirewallPolicyIDPSSignatureModeValues() []FirewallPolicyIDPSSignatureMode { return []FirewallPolicyIDPSSignatureMode{ - FirewallPolicyIDPSSignatureModeZero, FirewallPolicyIDPSSignatureModeOne, FirewallPolicyIDPSSignatureModeTwo, + FirewallPolicyIDPSSignatureModeZero, } } @@ -1643,16 +1642,16 @@ type FirewallPolicyIDPSSignatureSeverity int32 const ( FirewallPolicyIDPSSignatureSeverityOne FirewallPolicyIDPSSignatureSeverity = 1 - FirewallPolicyIDPSSignatureSeverityTwo FirewallPolicyIDPSSignatureSeverity = 2 FirewallPolicyIDPSSignatureSeverityThree FirewallPolicyIDPSSignatureSeverity = 3 + FirewallPolicyIDPSSignatureSeverityTwo FirewallPolicyIDPSSignatureSeverity = 2 ) // PossibleFirewallPolicyIDPSSignatureSeverityValues returns the possible values for the FirewallPolicyIDPSSignatureSeverity const type. func PossibleFirewallPolicyIDPSSignatureSeverityValues() []FirewallPolicyIDPSSignatureSeverity { return []FirewallPolicyIDPSSignatureSeverity{ FirewallPolicyIDPSSignatureSeverityOne, - FirewallPolicyIDPSSignatureSeverityTwo, FirewallPolicyIDPSSignatureSeverityThree, + FirewallPolicyIDPSSignatureSeverityTwo, } } @@ -2863,19 +2862,19 @@ func PossibleProvisioningStateValues() []ProvisioningState { type PublicIPAddressDNSSettingsDomainNameLabelScope string const ( - PublicIPAddressDNSSettingsDomainNameLabelScopeTenantReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "TenantReuse" - PublicIPAddressDNSSettingsDomainNameLabelScopeSubscriptionReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "SubscriptionReuse" - PublicIPAddressDNSSettingsDomainNameLabelScopeResourceGroupReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "ResourceGroupReuse" PublicIPAddressDNSSettingsDomainNameLabelScopeNoReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "NoReuse" + PublicIPAddressDNSSettingsDomainNameLabelScopeResourceGroupReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "ResourceGroupReuse" + PublicIPAddressDNSSettingsDomainNameLabelScopeSubscriptionReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "SubscriptionReuse" + PublicIPAddressDNSSettingsDomainNameLabelScopeTenantReuse PublicIPAddressDNSSettingsDomainNameLabelScope = "TenantReuse" ) // PossiblePublicIPAddressDNSSettingsDomainNameLabelScopeValues returns the possible values for the PublicIPAddressDNSSettingsDomainNameLabelScope const type. func PossiblePublicIPAddressDNSSettingsDomainNameLabelScopeValues() []PublicIPAddressDNSSettingsDomainNameLabelScope { return []PublicIPAddressDNSSettingsDomainNameLabelScope{ - PublicIPAddressDNSSettingsDomainNameLabelScopeTenantReuse, - PublicIPAddressDNSSettingsDomainNameLabelScopeSubscriptionReuse, - PublicIPAddressDNSSettingsDomainNameLabelScopeResourceGroupReuse, PublicIPAddressDNSSettingsDomainNameLabelScopeNoReuse, + PublicIPAddressDNSSettingsDomainNameLabelScopeResourceGroupReuse, + PublicIPAddressDNSSettingsDomainNameLabelScopeSubscriptionReuse, + PublicIPAddressDNSSettingsDomainNameLabelScopeTenantReuse, } } @@ -2969,19 +2968,19 @@ func PossiblePublicIPPrefixSKUTierValues() []PublicIPPrefixSKUTier { 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, } } diff --git a/sdk/resourcemanager/network/armnetwork/customipprefixes_client.go b/sdk/resourcemanager/network/armnetwork/customipprefixes_client.go index c2d6da1efbee..6da5bb9266ef 100644 --- a/sdk/resourcemanager/network/armnetwork/customipprefixes_client.go +++ b/sdk/resourcemanager/network/armnetwork/customipprefixes_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 armnetwork @@ -60,9 +59,10 @@ func (client *CustomIPPrefixesClient) BeginCreateOrUpdate(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CustomIPPrefixesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CustomIPPrefixesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[CustomIPPrefixesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *CustomIPPrefixesClient) BeginCreateOrUpdate(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *CustomIPPrefixesClient) createOrUpdate(ctx context.Context, resourceGroupName string, customIPPrefixName string, parameters CustomIPPrefix, options *CustomIPPrefixesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "CustomIPPrefixesClient.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, customIPPrefixName, 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. @@ -110,7 +116,10 @@ func (client *CustomIPPrefixesClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 the specified custom IP prefix. @@ -127,9 +136,10 @@ func (client *CustomIPPrefixesClient) BeginDelete(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CustomIPPrefixesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CustomIPPrefixesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[CustomIPPrefixesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *CustomIPPrefixesClient) BeginDelete(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *CustomIPPrefixesClient) deleteOperation(ctx context.Context, resourceGroupName string, customIPPrefixName string, options *CustomIPPrefixesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "CustomIPPrefixesClient.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, customIPPrefixName, 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 *CustomIPPrefixesClient) deleteCreateRequest(ctx context.Context, r // - customIPPrefixName - The name of the custom IP prefix. // - options - CustomIPPrefixesClientGetOptions contains the optional parameters for the CustomIPPrefixesClient.Get method. func (client *CustomIPPrefixesClient) Get(ctx context.Context, resourceGroupName string, customIPPrefixName string, options *CustomIPPrefixesClientGetOptions) (CustomIPPrefixesClientGetResponse, error) { + var err error + const operationName = "CustomIPPrefixesClient.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, customIPPrefixName, options) if err != nil { return CustomIPPrefixesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CustomIPPrefixesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CustomIPPrefixesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CustomIPPrefixesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -252,6 +275,7 @@ func (client *CustomIPPrefixesClient) NewListPager(resourceGroupName string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CustomIPPrefixesClientListResponse) (CustomIPPrefixesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CustomIPPrefixesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -271,6 +295,7 @@ func (client *CustomIPPrefixesClient) NewListPager(resourceGroupName string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -316,6 +341,7 @@ func (client *CustomIPPrefixesClient) NewListAllPager(options *CustomIPPrefixesC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *CustomIPPrefixesClientListAllResponse) (CustomIPPrefixesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CustomIPPrefixesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -335,6 +361,7 @@ func (client *CustomIPPrefixesClient) NewListAllPager(options *CustomIPPrefixesC } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -375,18 +402,25 @@ func (client *CustomIPPrefixesClient) listAllHandleResponse(resp *http.Response) // - options - CustomIPPrefixesClientUpdateTagsOptions contains the optional parameters for the CustomIPPrefixesClient.UpdateTags // method. func (client *CustomIPPrefixesClient) UpdateTags(ctx context.Context, resourceGroupName string, customIPPrefixName string, parameters TagsObject, options *CustomIPPrefixesClientUpdateTagsOptions) (CustomIPPrefixesClientUpdateTagsResponse, error) { + var err error + const operationName = "CustomIPPrefixesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, customIPPrefixName, parameters, options) if err != nil { return CustomIPPrefixesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return CustomIPPrefixesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return CustomIPPrefixesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return CustomIPPrefixesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -412,7 +446,10 @@ func (client *CustomIPPrefixesClient) updateTagsCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/ddoscustompolicies_client.go b/sdk/resourcemanager/network/armnetwork/ddoscustompolicies_client.go index d6300350bc1b..e8f11aa200ac 100644 --- a/sdk/resourcemanager/network/armnetwork/ddoscustompolicies_client.go +++ b/sdk/resourcemanager/network/armnetwork/ddoscustompolicies_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 armnetwork @@ -60,9 +59,10 @@ func (client *DdosCustomPoliciesClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosCustomPoliciesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosCustomPoliciesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DdosCustomPoliciesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *DdosCustomPoliciesClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *DdosCustomPoliciesClient) createOrUpdate(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters DdosCustomPolicy, options *DdosCustomPoliciesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DdosCustomPoliciesClient.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, ddosCustomPolicyName, 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. @@ -110,7 +116,10 @@ func (client *DdosCustomPoliciesClient) createOrUpdateCreateRequest(ctx context. reqQP.Set("api-version", "2022-11-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 the specified DDoS custom policy. @@ -127,9 +136,10 @@ func (client *DdosCustomPoliciesClient) BeginDelete(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosCustomPoliciesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosCustomPoliciesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DdosCustomPoliciesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *DdosCustomPoliciesClient) BeginDelete(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *DdosCustomPoliciesClient) deleteOperation(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, options *DdosCustomPoliciesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DdosCustomPoliciesClient.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, ddosCustomPolicyName, 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 *DdosCustomPoliciesClient) deleteCreateRequest(ctx context.Context, // - ddosCustomPolicyName - The name of the DDoS custom policy. // - options - DdosCustomPoliciesClientGetOptions contains the optional parameters for the DdosCustomPoliciesClient.Get method. func (client *DdosCustomPoliciesClient) Get(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, options *DdosCustomPoliciesClientGetOptions) (DdosCustomPoliciesClientGetResponse, error) { + var err error + const operationName = "DdosCustomPoliciesClient.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, ddosCustomPolicyName, options) if err != nil { return DdosCustomPoliciesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DdosCustomPoliciesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DdosCustomPoliciesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DdosCustomPoliciesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -247,18 +270,25 @@ func (client *DdosCustomPoliciesClient) getHandleResponse(resp *http.Response) ( // - options - DdosCustomPoliciesClientUpdateTagsOptions contains the optional parameters for the DdosCustomPoliciesClient.UpdateTags // method. func (client *DdosCustomPoliciesClient) UpdateTags(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters TagsObject, options *DdosCustomPoliciesClientUpdateTagsOptions) (DdosCustomPoliciesClientUpdateTagsResponse, error) { + var err error + const operationName = "DdosCustomPoliciesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, ddosCustomPolicyName, parameters, options) if err != nil { return DdosCustomPoliciesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DdosCustomPoliciesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DdosCustomPoliciesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DdosCustomPoliciesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -284,7 +314,10 @@ func (client *DdosCustomPoliciesClient) updateTagsCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/ddosprotectionplans_client.go b/sdk/resourcemanager/network/armnetwork/ddosprotectionplans_client.go index 8b90bf667bd3..9de94d197204 100644 --- a/sdk/resourcemanager/network/armnetwork/ddosprotectionplans_client.go +++ b/sdk/resourcemanager/network/armnetwork/ddosprotectionplans_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 armnetwork @@ -60,9 +59,10 @@ func (client *DdosProtectionPlansClient) BeginCreateOrUpdate(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosProtectionPlansClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosProtectionPlansClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DdosProtectionPlansClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *DdosProtectionPlansClient) BeginCreateOrUpdate(ctx context.Context // // Generated from API version 2022-11-01 func (client *DdosProtectionPlansClient) createOrUpdate(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, parameters DdosProtectionPlan, options *DdosProtectionPlansClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DdosProtectionPlansClient.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, ddosProtectionPlanName, 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. @@ -110,7 +116,10 @@ func (client *DdosProtectionPlansClient) createOrUpdateCreateRequest(ctx context reqQP.Set("api-version", "2022-11-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 the specified DDoS protection plan. @@ -127,9 +136,10 @@ func (client *DdosProtectionPlansClient) BeginDelete(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosProtectionPlansClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DdosProtectionPlansClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DdosProtectionPlansClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *DdosProtectionPlansClient) BeginDelete(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *DdosProtectionPlansClient) deleteOperation(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, options *DdosProtectionPlansClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DdosProtectionPlansClient.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, ddosProtectionPlanName, 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 *DdosProtectionPlansClient) deleteCreateRequest(ctx context.Context // - ddosProtectionPlanName - The name of the DDoS protection plan. // - options - DdosProtectionPlansClientGetOptions contains the optional parameters for the DdosProtectionPlansClient.Get method. func (client *DdosProtectionPlansClient) Get(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, options *DdosProtectionPlansClientGetOptions) (DdosProtectionPlansClientGetResponse, error) { + var err error + const operationName = "DdosProtectionPlansClient.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, ddosProtectionPlanName, options) if err != nil { return DdosProtectionPlansClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DdosProtectionPlansClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DdosProtectionPlansClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DdosProtectionPlansClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -248,6 +271,7 @@ func (client *DdosProtectionPlansClient) NewListPager(options *DdosProtectionPla return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DdosProtectionPlansClientListResponse) (DdosProtectionPlansClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DdosProtectionPlansClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -267,6 +291,7 @@ func (client *DdosProtectionPlansClient) NewListPager(options *DdosProtectionPla } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -309,6 +334,7 @@ func (client *DdosProtectionPlansClient) NewListByResourceGroupPager(resourceGro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DdosProtectionPlansClientListByResourceGroupResponse) (DdosProtectionPlansClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DdosProtectionPlansClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -328,6 +354,7 @@ func (client *DdosProtectionPlansClient) NewListByResourceGroupPager(resourceGro } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -372,18 +399,25 @@ func (client *DdosProtectionPlansClient) listByResourceGroupHandleResponse(resp // - options - DdosProtectionPlansClientUpdateTagsOptions contains the optional parameters for the DdosProtectionPlansClient.UpdateTags // method. func (client *DdosProtectionPlansClient) UpdateTags(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, parameters TagsObject, options *DdosProtectionPlansClientUpdateTagsOptions) (DdosProtectionPlansClientUpdateTagsResponse, error) { + var err error + const operationName = "DdosProtectionPlansClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, ddosProtectionPlanName, parameters, options) if err != nil { return DdosProtectionPlansClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DdosProtectionPlansClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DdosProtectionPlansClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DdosProtectionPlansClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -409,7 +443,10 @@ func (client *DdosProtectionPlansClient) updateTagsCreateRequest(ctx context.Con reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/defaultsecurityrules_client.go b/sdk/resourcemanager/network/armnetwork/defaultsecurityrules_client.go index 62c4886c04e7..5af449fdb71a 100644 --- a/sdk/resourcemanager/network/armnetwork/defaultsecurityrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/defaultsecurityrules_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 armnetwork @@ -55,18 +54,25 @@ func NewDefaultSecurityRulesClient(subscriptionID string, credential azcore.Toke // - options - DefaultSecurityRulesClientGetOptions contains the optional parameters for the DefaultSecurityRulesClient.Get // method. func (client *DefaultSecurityRulesClient) Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, defaultSecurityRuleName string, options *DefaultSecurityRulesClientGetOptions) (DefaultSecurityRulesClientGetResponse, error) { + var err error + const operationName = "DefaultSecurityRulesClient.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, networkSecurityGroupName, defaultSecurityRuleName, options) if err != nil { return DefaultSecurityRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DefaultSecurityRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DefaultSecurityRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DefaultSecurityRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *DefaultSecurityRulesClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DefaultSecurityRulesClientListResponse) (DefaultSecurityRulesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefaultSecurityRulesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *DefaultSecurityRulesClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/dscpconfiguration_client.go b/sdk/resourcemanager/network/armnetwork/dscpconfiguration_client.go index 6ae358cf9b96..042cd75a21f4 100644 --- a/sdk/resourcemanager/network/armnetwork/dscpconfiguration_client.go +++ b/sdk/resourcemanager/network/armnetwork/dscpconfiguration_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 armnetwork @@ -60,9 +59,10 @@ func (client *DscpConfigurationClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DscpConfigurationClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DscpConfigurationClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DscpConfigurationClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *DscpConfigurationClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *DscpConfigurationClient) createOrUpdate(ctx context.Context, resourceGroupName string, dscpConfigurationName string, parameters DscpConfiguration, options *DscpConfigurationClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "DscpConfigurationClient.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, dscpConfigurationName, 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. @@ -110,7 +116,10 @@ func (client *DscpConfigurationClient) createOrUpdateCreateRequest(ctx context.C reqQP.Set("api-version", "2022-11-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 a DSCP Configuration. @@ -127,9 +136,10 @@ func (client *DscpConfigurationClient) BeginDelete(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DscpConfigurationClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DscpConfigurationClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[DscpConfigurationClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *DscpConfigurationClient) BeginDelete(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *DscpConfigurationClient) deleteOperation(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "DscpConfigurationClient.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, dscpConfigurationName, 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 *DscpConfigurationClient) deleteCreateRequest(ctx context.Context, // - dscpConfigurationName - The name of the resource. // - options - DscpConfigurationClientGetOptions contains the optional parameters for the DscpConfigurationClient.Get method. func (client *DscpConfigurationClient) Get(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientGetOptions) (DscpConfigurationClientGetResponse, error) { + var err error + const operationName = "DscpConfigurationClient.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, dscpConfigurationName, options) if err != nil { return DscpConfigurationClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return DscpConfigurationClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DscpConfigurationClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DscpConfigurationClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -249,6 +272,7 @@ func (client *DscpConfigurationClient) NewListPager(resourceGroupName string, op return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DscpConfigurationClientListResponse) (DscpConfigurationClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DscpConfigurationClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -268,6 +292,7 @@ func (client *DscpConfigurationClient) NewListPager(resourceGroupName string, op } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -313,6 +338,7 @@ func (client *DscpConfigurationClient) NewListAllPager(options *DscpConfiguratio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DscpConfigurationClientListAllResponse) (DscpConfigurationClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DscpConfigurationClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -332,6 +358,7 @@ func (client *DscpConfigurationClient) NewListAllPager(options *DscpConfiguratio } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressroutecircuitauthorizations_client.go b/sdk/resourcemanager/network/armnetwork/expressroutecircuitauthorizations_client.go index 3de057f94d0b..335812f10849 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutecircuitauthorizations_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutecircuitauthorizations_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 armnetwork @@ -61,9 +60,10 @@ func (client *ExpressRouteCircuitAuthorizationsClient) BeginCreateOrUpdate(ctx c if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitAuthorizationsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitAuthorizationsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitAuthorizationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ExpressRouteCircuitAuthorizationsClient) BeginCreateOrUpdate(ctx c // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitAuthorizationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, authorizationParameters ExpressRouteCircuitAuthorization, options *ExpressRouteCircuitAuthorizationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitAuthorizationsClient.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, circuitName, authorizationName, authorizationParameters, 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. @@ -115,7 +121,10 @@ func (client *ExpressRouteCircuitAuthorizationsClient) createOrUpdateCreateReque reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, authorizationParameters) + if err := runtime.MarshalAsJSON(req, authorizationParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified authorization from the specified express route circuit. @@ -133,9 +142,10 @@ func (client *ExpressRouteCircuitAuthorizationsClient) BeginDelete(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitAuthorizationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitAuthorizationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitAuthorizationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ExpressRouteCircuitAuthorizationsClient) BeginDelete(ctx context.C // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitAuthorizationsClient) deleteOperation(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, options *ExpressRouteCircuitAuthorizationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitAuthorizationsClient.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, circuitName, authorizationName, 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. @@ -200,18 +216,25 @@ func (client *ExpressRouteCircuitAuthorizationsClient) deleteCreateRequest(ctx c // - options - ExpressRouteCircuitAuthorizationsClientGetOptions contains the optional parameters for the ExpressRouteCircuitAuthorizationsClient.Get // method. func (client *ExpressRouteCircuitAuthorizationsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, options *ExpressRouteCircuitAuthorizationsClientGetOptions) (ExpressRouteCircuitAuthorizationsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteCircuitAuthorizationsClient.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, circuitName, authorizationName, options) if err != nil { return ExpressRouteCircuitAuthorizationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitAuthorizationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitAuthorizationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitAuthorizationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *ExpressRouteCircuitAuthorizationsClient) NewListPager(resourceGrou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCircuitAuthorizationsClientListResponse) (ExpressRouteCircuitAuthorizationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCircuitAuthorizationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *ExpressRouteCircuitAuthorizationsClient) NewListPager(resourceGrou } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressroutecircuitconnections_client.go b/sdk/resourcemanager/network/armnetwork/expressroutecircuitconnections_client.go index 1d224463cc69..8584fcb4efc6 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutecircuitconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutecircuitconnections_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 armnetwork @@ -63,9 +62,10 @@ func (client *ExpressRouteCircuitConnectionsClient) BeginCreateOrUpdate(ctx cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -76,18 +76,24 @@ func (client *ExpressRouteCircuitConnectionsClient) BeginCreateOrUpdate(ctx cont // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters ExpressRouteCircuitConnection, options *ExpressRouteCircuitConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitConnectionsClient.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, circuitName, peeringName, connectionName, expressRouteCircuitConnectionParameters, 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. @@ -121,7 +127,10 @@ func (client *ExpressRouteCircuitConnectionsClient) createOrUpdateCreateRequest( reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, expressRouteCircuitConnectionParameters) + if err := runtime.MarshalAsJSON(req, expressRouteCircuitConnectionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified Express Route Circuit Connection from the specified express route circuit. @@ -140,9 +149,10 @@ func (client *ExpressRouteCircuitConnectionsClient) BeginDelete(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -153,18 +163,24 @@ func (client *ExpressRouteCircuitConnectionsClient) BeginDelete(ctx context.Cont // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitConnectionsClient.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, circuitName, peeringName, connectionName, 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. @@ -212,18 +228,25 @@ func (client *ExpressRouteCircuitConnectionsClient) deleteCreateRequest(ctx cont // - options - ExpressRouteCircuitConnectionsClientGetOptions contains the optional parameters for the ExpressRouteCircuitConnectionsClient.Get // method. func (client *ExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *ExpressRouteCircuitConnectionsClientGetOptions) (ExpressRouteCircuitConnectionsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteCircuitConnectionsClient.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, circuitName, peeringName, connectionName, options) if err != nil { return ExpressRouteCircuitConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -283,6 +306,7 @@ func (client *ExpressRouteCircuitConnectionsClient) NewListPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCircuitConnectionsClientListResponse) (ExpressRouteCircuitConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCircuitConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -302,6 +326,7 @@ func (client *ExpressRouteCircuitConnectionsClient) NewListPager(resourceGroupNa } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressroutecircuitpeerings_client.go b/sdk/resourcemanager/network/armnetwork/expressroutecircuitpeerings_client.go index 7d7d03483110..42ca81dd278c 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutecircuitpeerings_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutecircuitpeerings_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 armnetwork @@ -61,9 +60,10 @@ func (client *ExpressRouteCircuitPeeringsClient) BeginCreateOrUpdate(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitPeeringsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitPeeringsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitPeeringsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ExpressRouteCircuitPeeringsClient) BeginCreateOrUpdate(ctx context // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitPeeringsClient) createOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, peeringParameters ExpressRouteCircuitPeering, options *ExpressRouteCircuitPeeringsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitPeeringsClient.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, circuitName, peeringName, peeringParameters, 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. @@ -115,7 +121,10 @@ func (client *ExpressRouteCircuitPeeringsClient) createOrUpdateCreateRequest(ctx reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, peeringParameters) + if err := runtime.MarshalAsJSON(req, peeringParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified peering from the specified express route circuit. @@ -133,9 +142,10 @@ func (client *ExpressRouteCircuitPeeringsClient) BeginDelete(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitPeeringsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitPeeringsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitPeeringsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ExpressRouteCircuitPeeringsClient) BeginDelete(ctx context.Context // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitPeeringsClient) deleteOperation(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *ExpressRouteCircuitPeeringsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitPeeringsClient.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, circuitName, peeringName, 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. @@ -200,18 +216,25 @@ func (client *ExpressRouteCircuitPeeringsClient) deleteCreateRequest(ctx context // - options - ExpressRouteCircuitPeeringsClientGetOptions contains the optional parameters for the ExpressRouteCircuitPeeringsClient.Get // method. func (client *ExpressRouteCircuitPeeringsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *ExpressRouteCircuitPeeringsClientGetOptions) (ExpressRouteCircuitPeeringsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteCircuitPeeringsClient.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, circuitName, peeringName, options) if err != nil { return ExpressRouteCircuitPeeringsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitPeeringsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitPeeringsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitPeeringsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *ExpressRouteCircuitPeeringsClient) NewListPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCircuitPeeringsClientListResponse) (ExpressRouteCircuitPeeringsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCircuitPeeringsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *ExpressRouteCircuitPeeringsClient) NewListPager(resourceGroupName } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressroutecircuits_client.go b/sdk/resourcemanager/network/armnetwork/expressroutecircuits_client.go index 1a54a49238c6..7e4435348d6d 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutecircuits_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutecircuits_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 armnetwork @@ -60,9 +59,10 @@ func (client *ExpressRouteCircuitsClient) BeginCreateOrUpdate(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ExpressRouteCircuitsClient) BeginCreateOrUpdate(ctx context.Contex // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitsClient) createOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, parameters ExpressRouteCircuit, options *ExpressRouteCircuitsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.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, circuitName, 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. @@ -110,7 +116,10 @@ func (client *ExpressRouteCircuitsClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-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 the specified express route circuit. @@ -127,9 +136,10 @@ func (client *ExpressRouteCircuitsClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *ExpressRouteCircuitsClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitsClient) deleteOperation(ctx context.Context, resourceGroupName string, circuitName string, options *ExpressRouteCircuitsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.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, circuitName, 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. @@ -189,18 +205,25 @@ func (client *ExpressRouteCircuitsClient) deleteCreateRequest(ctx context.Contex // - options - ExpressRouteCircuitsClientGetOptions contains the optional parameters for the ExpressRouteCircuitsClient.Get // method. func (client *ExpressRouteCircuitsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, options *ExpressRouteCircuitsClientGetOptions) (ExpressRouteCircuitsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.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, circuitName, options) if err != nil { return ExpressRouteCircuitsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -248,18 +271,25 @@ func (client *ExpressRouteCircuitsClient) getHandleResponse(resp *http.Response) // - options - ExpressRouteCircuitsClientGetPeeringStatsOptions contains the optional parameters for the ExpressRouteCircuitsClient.GetPeeringStats // method. func (client *ExpressRouteCircuitsClient) GetPeeringStats(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *ExpressRouteCircuitsClientGetPeeringStatsOptions) (ExpressRouteCircuitsClientGetPeeringStatsResponse, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.GetPeeringStats" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getPeeringStatsCreateRequest(ctx, resourceGroupName, circuitName, peeringName, options) if err != nil { return ExpressRouteCircuitsClientGetPeeringStatsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitsClientGetPeeringStatsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitsClientGetPeeringStatsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitsClientGetPeeringStatsResponse{}, err } - return client.getPeeringStatsHandleResponse(resp) + resp, err := client.getPeeringStatsHandleResponse(httpResp) + return resp, err } // getPeeringStatsCreateRequest creates the GetPeeringStats request. @@ -310,18 +340,25 @@ func (client *ExpressRouteCircuitsClient) getPeeringStatsHandleResponse(resp *ht // - options - ExpressRouteCircuitsClientGetStatsOptions contains the optional parameters for the ExpressRouteCircuitsClient.GetStats // method. func (client *ExpressRouteCircuitsClient) GetStats(ctx context.Context, resourceGroupName string, circuitName string, options *ExpressRouteCircuitsClientGetStatsOptions) (ExpressRouteCircuitsClientGetStatsResponse, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.GetStats" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getStatsCreateRequest(ctx, resourceGroupName, circuitName, options) if err != nil { return ExpressRouteCircuitsClientGetStatsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitsClientGetStatsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitsClientGetStatsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitsClientGetStatsResponse{}, err } - return client.getStatsHandleResponse(resp) + resp, err := client.getStatsHandleResponse(httpResp) + return resp, err } // getStatsCreateRequest creates the GetStats request. @@ -371,6 +408,7 @@ func (client *ExpressRouteCircuitsClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCircuitsClientListResponse) (ExpressRouteCircuitsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCircuitsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -390,6 +428,7 @@ func (client *ExpressRouteCircuitsClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -435,6 +474,7 @@ func (client *ExpressRouteCircuitsClient) NewListAllPager(options *ExpressRouteC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCircuitsClientListAllResponse) (ExpressRouteCircuitsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCircuitsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -454,6 +494,7 @@ func (client *ExpressRouteCircuitsClient) NewListAllPager(options *ExpressRouteC } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -500,9 +541,10 @@ func (client *ExpressRouteCircuitsClient) BeginListArpTable(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientListArpTableResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientListArpTableResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitsClientListArpTableResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -513,18 +555,24 @@ func (client *ExpressRouteCircuitsClient) BeginListArpTable(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitsClient) listArpTable(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, devicePath string, options *ExpressRouteCircuitsClientBeginListArpTableOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.BeginListArpTable" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listArpTableCreateRequest(ctx, resourceGroupName, circuitName, peeringName, devicePath, 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 } // listArpTableCreateRequest creates the ListArpTable request. @@ -578,9 +626,10 @@ func (client *ExpressRouteCircuitsClient) BeginListRoutesTable(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientListRoutesTableResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientListRoutesTableResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitsClientListRoutesTableResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -591,18 +640,24 @@ func (client *ExpressRouteCircuitsClient) BeginListRoutesTable(ctx context.Conte // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitsClient) listRoutesTable(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, devicePath string, options *ExpressRouteCircuitsClientBeginListRoutesTableOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.BeginListRoutesTable" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listRoutesTableCreateRequest(ctx, resourceGroupName, circuitName, peeringName, devicePath, 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 } // listRoutesTableCreateRequest creates the ListRoutesTable request. @@ -656,9 +711,10 @@ func (client *ExpressRouteCircuitsClient) BeginListRoutesTableSummary(ctx contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientListRoutesTableSummaryResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCircuitsClientListRoutesTableSummaryResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCircuitsClientListRoutesTableSummaryResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -670,18 +726,24 @@ func (client *ExpressRouteCircuitsClient) BeginListRoutesTableSummary(ctx contex // // Generated from API version 2022-11-01 func (client *ExpressRouteCircuitsClient) listRoutesTableSummary(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, devicePath string, options *ExpressRouteCircuitsClientBeginListRoutesTableSummaryOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.BeginListRoutesTableSummary" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listRoutesTableSummaryCreateRequest(ctx, resourceGroupName, circuitName, peeringName, devicePath, 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 } // listRoutesTableSummaryCreateRequest creates the ListRoutesTableSummary request. @@ -728,18 +790,25 @@ func (client *ExpressRouteCircuitsClient) listRoutesTableSummaryCreateRequest(ct // - options - ExpressRouteCircuitsClientUpdateTagsOptions contains the optional parameters for the ExpressRouteCircuitsClient.UpdateTags // method. func (client *ExpressRouteCircuitsClient) UpdateTags(ctx context.Context, resourceGroupName string, circuitName string, parameters TagsObject, options *ExpressRouteCircuitsClientUpdateTagsOptions) (ExpressRouteCircuitsClientUpdateTagsResponse, error) { + var err error + const operationName = "ExpressRouteCircuitsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, circuitName, parameters, options) if err != nil { return ExpressRouteCircuitsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCircuitsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCircuitsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCircuitsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -765,7 +834,10 @@ func (client *ExpressRouteCircuitsClient) updateTagsCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/expressrouteconnections_client.go b/sdk/resourcemanager/network/armnetwork/expressrouteconnections_client.go index 061bd8135d9c..acbc810a170b 100644 --- a/sdk/resourcemanager/network/armnetwork/expressrouteconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressrouteconnections_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 armnetwork @@ -61,9 +60,10 @@ func (client *ExpressRouteConnectionsClient) BeginCreateOrUpdate(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ExpressRouteConnectionsClient) BeginCreateOrUpdate(ctx context.Con // // Generated from API version 2022-11-01 func (client *ExpressRouteConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection, options *ExpressRouteConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteConnectionsClient.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, expressRouteGatewayName, connectionName, putExpressRouteConnectionParameters, 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. @@ -115,7 +121,10 @@ func (client *ExpressRouteConnectionsClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, putExpressRouteConnectionParameters) + if err := runtime.MarshalAsJSON(req, putExpressRouteConnectionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a connection to a ExpressRoute circuit. @@ -133,9 +142,10 @@ func (client *ExpressRouteConnectionsClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ExpressRouteConnectionsClient) BeginDelete(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *ExpressRouteConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteConnectionsClient.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, expressRouteGatewayName, connectionName, 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. @@ -200,18 +216,25 @@ func (client *ExpressRouteConnectionsClient) deleteCreateRequest(ctx context.Con // - options - ExpressRouteConnectionsClientGetOptions contains the optional parameters for the ExpressRouteConnectionsClient.Get // method. func (client *ExpressRouteConnectionsClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientGetOptions) (ExpressRouteConnectionsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteConnectionsClient.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, expressRouteGatewayName, connectionName, options) if err != nil { return ExpressRouteConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -262,18 +285,25 @@ func (client *ExpressRouteConnectionsClient) getHandleResponse(resp *http.Respon // - options - ExpressRouteConnectionsClientListOptions contains the optional parameters for the ExpressRouteConnectionsClient.List // method. func (client *ExpressRouteConnectionsClient) List(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *ExpressRouteConnectionsClientListOptions) (ExpressRouteConnectionsClientListResponse, error) { + var err error + const operationName = "ExpressRouteConnectionsClient.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, expressRouteGatewayName, options) if err != nil { return ExpressRouteConnectionsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteConnectionsClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteConnectionsClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteConnectionsClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/expressroutecrossconnectionpeerings_client.go b/sdk/resourcemanager/network/armnetwork/expressroutecrossconnectionpeerings_client.go index e030157d4ebb..3f026030a1ed 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutecrossconnectionpeerings_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutecrossconnectionpeerings_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 armnetwork @@ -61,9 +60,10 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) BeginCreateOrUpdate(ctx if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionPeeringsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionPeeringsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCrossConnectionPeeringsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) BeginCreateOrUpdate(ctx // // Generated from API version 2022-11-01 func (client *ExpressRouteCrossConnectionPeeringsClient) createOrUpdate(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, peeringParameters ExpressRouteCrossConnectionPeering, options *ExpressRouteCrossConnectionPeeringsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCrossConnectionPeeringsClient.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, crossConnectionName, peeringName, peeringParameters, 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. @@ -115,7 +121,10 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) createOrUpdateCreateReq reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, peeringParameters) + if err := runtime.MarshalAsJSON(req, peeringParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified peering from the ExpressRouteCrossConnection. @@ -133,9 +142,10 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) BeginDelete(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionPeeringsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionPeeringsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCrossConnectionPeeringsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) BeginDelete(ctx context // // Generated from API version 2022-11-01 func (client *ExpressRouteCrossConnectionPeeringsClient) deleteOperation(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, options *ExpressRouteCrossConnectionPeeringsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCrossConnectionPeeringsClient.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, crossConnectionName, peeringName, 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. @@ -200,18 +216,25 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) deleteCreateRequest(ctx // - options - ExpressRouteCrossConnectionPeeringsClientGetOptions contains the optional parameters for the ExpressRouteCrossConnectionPeeringsClient.Get // method. func (client *ExpressRouteCrossConnectionPeeringsClient) Get(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, options *ExpressRouteCrossConnectionPeeringsClientGetOptions) (ExpressRouteCrossConnectionPeeringsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteCrossConnectionPeeringsClient.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, crossConnectionName, peeringName, options) if err != nil { return ExpressRouteCrossConnectionPeeringsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCrossConnectionPeeringsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCrossConnectionPeeringsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCrossConnectionPeeringsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) NewListPager(resourceGr return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCrossConnectionPeeringsClientListResponse) (ExpressRouteCrossConnectionPeeringsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCrossConnectionPeeringsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *ExpressRouteCrossConnectionPeeringsClient) NewListPager(resourceGr } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressroutecrossconnections_client.go b/sdk/resourcemanager/network/armnetwork/expressroutecrossconnections_client.go index e0aaf7c67900..0062b4311d9c 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutecrossconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutecrossconnections_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 armnetwork @@ -60,9 +59,10 @@ func (client *ExpressRouteCrossConnectionsClient) BeginCreateOrUpdate(ctx contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCrossConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ExpressRouteCrossConnectionsClient) BeginCreateOrUpdate(ctx contex // // Generated from API version 2022-11-01 func (client *ExpressRouteCrossConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, crossConnectionName string, parameters ExpressRouteCrossConnection, options *ExpressRouteCrossConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCrossConnectionsClient.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, crossConnectionName, 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 } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -110,7 +116,10 @@ func (client *ExpressRouteCrossConnectionsClient) createOrUpdateCreateRequest(ct reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // Get - Gets details about the specified ExpressRouteCrossConnection. @@ -122,18 +131,25 @@ func (client *ExpressRouteCrossConnectionsClient) createOrUpdateCreateRequest(ct // - options - ExpressRouteCrossConnectionsClientGetOptions contains the optional parameters for the ExpressRouteCrossConnectionsClient.Get // method. func (client *ExpressRouteCrossConnectionsClient) Get(ctx context.Context, resourceGroupName string, crossConnectionName string, options *ExpressRouteCrossConnectionsClientGetOptions) (ExpressRouteCrossConnectionsClientGetResponse, error) { + var err error + const operationName = "ExpressRouteCrossConnectionsClient.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, crossConnectionName, options) if err != nil { return ExpressRouteCrossConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCrossConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCrossConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCrossConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -182,6 +198,7 @@ func (client *ExpressRouteCrossConnectionsClient) NewListPager(options *ExpressR return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCrossConnectionsClientListResponse) (ExpressRouteCrossConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCrossConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -201,6 +218,7 @@ func (client *ExpressRouteCrossConnectionsClient) NewListPager(options *ExpressR } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -248,9 +266,10 @@ func (client *ExpressRouteCrossConnectionsClient) BeginListArpTable(ctx context. if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientListArpTableResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientListArpTableResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCrossConnectionsClientListArpTableResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -262,18 +281,24 @@ func (client *ExpressRouteCrossConnectionsClient) BeginListArpTable(ctx context. // // Generated from API version 2022-11-01 func (client *ExpressRouteCrossConnectionsClient) listArpTable(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, devicePath string, options *ExpressRouteCrossConnectionsClientBeginListArpTableOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCrossConnectionsClient.BeginListArpTable" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listArpTableCreateRequest(ctx, resourceGroupName, crossConnectionName, peeringName, devicePath, 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 } // listArpTableCreateRequest creates the ListArpTable request. @@ -322,6 +347,7 @@ func (client *ExpressRouteCrossConnectionsClient) NewListByResourceGroupPager(re return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteCrossConnectionsClientListByResourceGroupResponse) (ExpressRouteCrossConnectionsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteCrossConnectionsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -341,6 +367,7 @@ func (client *ExpressRouteCrossConnectionsClient) NewListByResourceGroupPager(re } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -392,9 +419,10 @@ func (client *ExpressRouteCrossConnectionsClient) BeginListRoutesTable(ctx conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientListRoutesTableResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientListRoutesTableResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCrossConnectionsClientListRoutesTableResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -406,18 +434,24 @@ func (client *ExpressRouteCrossConnectionsClient) BeginListRoutesTable(ctx conte // // Generated from API version 2022-11-01 func (client *ExpressRouteCrossConnectionsClient) listRoutesTable(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, devicePath string, options *ExpressRouteCrossConnectionsClientBeginListRoutesTableOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCrossConnectionsClient.BeginListRoutesTable" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listRoutesTableCreateRequest(ctx, resourceGroupName, crossConnectionName, peeringName, devicePath, 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 } // listRoutesTableCreateRequest creates the ListRoutesTable request. @@ -471,9 +505,10 @@ func (client *ExpressRouteCrossConnectionsClient) BeginListRoutesTableSummary(ct if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientListRoutesTableSummaryResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteCrossConnectionsClientListRoutesTableSummaryResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteCrossConnectionsClientListRoutesTableSummaryResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -485,18 +520,24 @@ func (client *ExpressRouteCrossConnectionsClient) BeginListRoutesTableSummary(ct // // Generated from API version 2022-11-01 func (client *ExpressRouteCrossConnectionsClient) listRoutesTableSummary(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, devicePath string, options *ExpressRouteCrossConnectionsClientBeginListRoutesTableSummaryOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteCrossConnectionsClient.BeginListRoutesTableSummary" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listRoutesTableSummaryCreateRequest(ctx, resourceGroupName, crossConnectionName, peeringName, devicePath, 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 } // listRoutesTableSummaryCreateRequest creates the ListRoutesTableSummary request. @@ -543,18 +584,25 @@ func (client *ExpressRouteCrossConnectionsClient) listRoutesTableSummaryCreateRe // - options - ExpressRouteCrossConnectionsClientUpdateTagsOptions contains the optional parameters for the ExpressRouteCrossConnectionsClient.UpdateTags // method. func (client *ExpressRouteCrossConnectionsClient) UpdateTags(ctx context.Context, resourceGroupName string, crossConnectionName string, crossConnectionParameters TagsObject, options *ExpressRouteCrossConnectionsClientUpdateTagsOptions) (ExpressRouteCrossConnectionsClientUpdateTagsResponse, error) { + var err error + const operationName = "ExpressRouteCrossConnectionsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, crossConnectionName, crossConnectionParameters, options) if err != nil { return ExpressRouteCrossConnectionsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteCrossConnectionsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteCrossConnectionsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteCrossConnectionsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -580,7 +628,10 @@ func (client *ExpressRouteCrossConnectionsClient) updateTagsCreateRequest(ctx co reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, crossConnectionParameters) + if err := runtime.MarshalAsJSON(req, crossConnectionParameters); err != nil { + return nil, err + } + return req, nil } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/expressroutegateways_client.go b/sdk/resourcemanager/network/armnetwork/expressroutegateways_client.go index 4378d55afe2f..4525f006b6bf 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutegateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutegateways_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 armnetwork @@ -60,9 +59,10 @@ func (client *ExpressRouteGatewaysClient) BeginCreateOrUpdate(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ExpressRouteGatewaysClient) BeginCreateOrUpdate(ctx context.Contex // // Generated from API version 2022-11-01 func (client *ExpressRouteGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway, options *ExpressRouteGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteGatewaysClient.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, expressRouteGatewayName, putExpressRouteGatewayParameters, 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. @@ -110,7 +116,10 @@ func (client *ExpressRouteGatewaysClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, putExpressRouteGatewayParameters) + if err := runtime.MarshalAsJSON(req, putExpressRouteGatewayParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified ExpressRoute gateway in a resource group. An ExpressRoute gateway resource can only @@ -128,9 +137,10 @@ func (client *ExpressRouteGatewaysClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *ExpressRouteGatewaysClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *ExpressRouteGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *ExpressRouteGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteGatewaysClient.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, expressRouteGatewayName, 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,18 +207,25 @@ func (client *ExpressRouteGatewaysClient) deleteCreateRequest(ctx context.Contex // - options - ExpressRouteGatewaysClientGetOptions contains the optional parameters for the ExpressRouteGatewaysClient.Get // method. func (client *ExpressRouteGatewaysClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *ExpressRouteGatewaysClientGetOptions) (ExpressRouteGatewaysClientGetResponse, error) { + var err error + const operationName = "ExpressRouteGatewaysClient.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, expressRouteGatewayName, options) if err != nil { return ExpressRouteGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -248,18 +271,25 @@ func (client *ExpressRouteGatewaysClient) getHandleResponse(resp *http.Response) // - options - ExpressRouteGatewaysClientListByResourceGroupOptions contains the optional parameters for the ExpressRouteGatewaysClient.ListByResourceGroup // method. func (client *ExpressRouteGatewaysClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, options *ExpressRouteGatewaysClientListByResourceGroupOptions) (ExpressRouteGatewaysClientListByResourceGroupResponse, error) { + var err error + const operationName = "ExpressRouteGatewaysClient.ListByResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) if err != nil { return ExpressRouteGatewaysClientListByResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteGatewaysClientListByResourceGroupResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteGatewaysClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteGatewaysClientListByResourceGroupResponse{}, err } - return client.listByResourceGroupHandleResponse(resp) + resp, err := client.listByResourceGroupHandleResponse(httpResp) + return resp, err } // listByResourceGroupCreateRequest creates the ListByResourceGroup request. @@ -300,18 +330,25 @@ func (client *ExpressRouteGatewaysClient) listByResourceGroupHandleResponse(resp // - options - ExpressRouteGatewaysClientListBySubscriptionOptions contains the optional parameters for the ExpressRouteGatewaysClient.ListBySubscription // method. func (client *ExpressRouteGatewaysClient) ListBySubscription(ctx context.Context, options *ExpressRouteGatewaysClientListBySubscriptionOptions) (ExpressRouteGatewaysClientListBySubscriptionResponse, error) { + var err error + const operationName = "ExpressRouteGatewaysClient.ListBySubscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listBySubscriptionCreateRequest(ctx, options) if err != nil { return ExpressRouteGatewaysClientListBySubscriptionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteGatewaysClientListBySubscriptionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteGatewaysClientListBySubscriptionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteGatewaysClientListBySubscriptionResponse{}, err } - return client.listBySubscriptionHandleResponse(resp) + resp, err := client.listBySubscriptionHandleResponse(httpResp) + return resp, err } // listBySubscriptionCreateRequest creates the ListBySubscription request. @@ -356,9 +393,10 @@ func (client *ExpressRouteGatewaysClient) BeginUpdateTags(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteGatewaysClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteGatewaysClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRouteGatewaysClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -369,18 +407,24 @@ func (client *ExpressRouteGatewaysClient) BeginUpdateTags(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *ExpressRouteGatewaysClient) updateTags(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, expressRouteGatewayParameters TagsObject, options *ExpressRouteGatewaysClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRouteGatewaysClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, expressRouteGatewayName, expressRouteGatewayParameters, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -406,5 +450,8 @@ func (client *ExpressRouteGatewaysClient) updateTagsCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, expressRouteGatewayParameters) + if err := runtime.MarshalAsJSON(req, expressRouteGatewayParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/network/armnetwork/expressroutelinks_client.go b/sdk/resourcemanager/network/armnetwork/expressroutelinks_client.go index f766d05801e0..13d0a249845d 100644 --- a/sdk/resourcemanager/network/armnetwork/expressroutelinks_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressroutelinks_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 armnetwork @@ -54,18 +53,25 @@ func NewExpressRouteLinksClient(subscriptionID string, credential azcore.TokenCr // - linkName - The name of the ExpressRouteLink resource. // - options - ExpressRouteLinksClientGetOptions contains the optional parameters for the ExpressRouteLinksClient.Get method. func (client *ExpressRouteLinksClient) Get(ctx context.Context, resourceGroupName string, expressRoutePortName string, linkName string, options *ExpressRouteLinksClientGetOptions) (ExpressRouteLinksClientGetResponse, error) { + var err error + const operationName = "ExpressRouteLinksClient.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, expressRoutePortName, linkName, options) if err != nil { return ExpressRouteLinksClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteLinksClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteLinksClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteLinksClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -120,6 +126,7 @@ func (client *ExpressRouteLinksClient) NewListPager(resourceGroupName string, ex return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteLinksClientListResponse) (ExpressRouteLinksClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteLinksClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -139,6 +146,7 @@ func (client *ExpressRouteLinksClient) NewListPager(resourceGroupName string, ex } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressrouteportauthorizations_client.go b/sdk/resourcemanager/network/armnetwork/expressrouteportauthorizations_client.go index 5176e94e6a35..210679112faa 100644 --- a/sdk/resourcemanager/network/armnetwork/expressrouteportauthorizations_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressrouteportauthorizations_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 armnetwork @@ -61,9 +60,10 @@ func (client *ExpressRoutePortAuthorizationsClient) BeginCreateOrUpdate(ctx cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortAuthorizationsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortAuthorizationsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRoutePortAuthorizationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ExpressRoutePortAuthorizationsClient) BeginCreateOrUpdate(ctx cont // // Generated from API version 2022-11-01 func (client *ExpressRoutePortAuthorizationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, expressRoutePortName string, authorizationName string, authorizationParameters ExpressRoutePortAuthorization, options *ExpressRoutePortAuthorizationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRoutePortAuthorizationsClient.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, expressRoutePortName, authorizationName, authorizationParameters, 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. @@ -115,7 +121,10 @@ func (client *ExpressRoutePortAuthorizationsClient) createOrUpdateCreateRequest( reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, authorizationParameters) + if err := runtime.MarshalAsJSON(req, authorizationParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified authorization from the specified express route port. @@ -133,9 +142,10 @@ func (client *ExpressRoutePortAuthorizationsClient) BeginDelete(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortAuthorizationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortAuthorizationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRoutePortAuthorizationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ExpressRoutePortAuthorizationsClient) BeginDelete(ctx context.Cont // // Generated from API version 2022-11-01 func (client *ExpressRoutePortAuthorizationsClient) deleteOperation(ctx context.Context, resourceGroupName string, expressRoutePortName string, authorizationName string, options *ExpressRoutePortAuthorizationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRoutePortAuthorizationsClient.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, expressRoutePortName, authorizationName, 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. @@ -200,18 +216,25 @@ func (client *ExpressRoutePortAuthorizationsClient) deleteCreateRequest(ctx cont // - options - ExpressRoutePortAuthorizationsClientGetOptions contains the optional parameters for the ExpressRoutePortAuthorizationsClient.Get // method. func (client *ExpressRoutePortAuthorizationsClient) Get(ctx context.Context, resourceGroupName string, expressRoutePortName string, authorizationName string, options *ExpressRoutePortAuthorizationsClientGetOptions) (ExpressRoutePortAuthorizationsClientGetResponse, error) { + var err error + const operationName = "ExpressRoutePortAuthorizationsClient.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, expressRoutePortName, authorizationName, options) if err != nil { return ExpressRoutePortAuthorizationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRoutePortAuthorizationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRoutePortAuthorizationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRoutePortAuthorizationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *ExpressRoutePortAuthorizationsClient) NewListPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRoutePortAuthorizationsClientListResponse) (ExpressRoutePortAuthorizationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRoutePortAuthorizationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *ExpressRoutePortAuthorizationsClient) NewListPager(resourceGroupNa } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressrouteports_client.go b/sdk/resourcemanager/network/armnetwork/expressrouteports_client.go index 5ce9f50c9a66..6549f5e83675 100644 --- a/sdk/resourcemanager/network/armnetwork/expressrouteports_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressrouteports_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 armnetwork @@ -60,9 +59,10 @@ func (client *ExpressRoutePortsClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRoutePortsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ExpressRoutePortsClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *ExpressRoutePortsClient) createOrUpdate(ctx context.Context, resourceGroupName string, expressRoutePortName string, parameters ExpressRoutePort, options *ExpressRoutePortsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRoutePortsClient.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, expressRoutePortName, 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. @@ -110,7 +116,10 @@ func (client *ExpressRoutePortsClient) createOrUpdateCreateRequest(ctx context.C reqQP.Set("api-version", "2022-11-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 the specified ExpressRoutePort resource. @@ -127,9 +136,10 @@ func (client *ExpressRoutePortsClient) BeginDelete(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRoutePortsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ExpressRoutePortsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *ExpressRoutePortsClient) BeginDelete(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *ExpressRoutePortsClient) deleteOperation(ctx context.Context, resourceGroupName string, expressRoutePortName string, options *ExpressRoutePortsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExpressRoutePortsClient.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, expressRoutePortName, 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 *ExpressRoutePortsClient) deleteCreateRequest(ctx context.Context, // - options - ExpressRoutePortsClientGenerateLOAOptions contains the optional parameters for the ExpressRoutePortsClient.GenerateLOA // method. func (client *ExpressRoutePortsClient) GenerateLOA(ctx context.Context, resourceGroupName string, expressRoutePortName string, request GenerateExpressRoutePortsLOARequest, options *ExpressRoutePortsClientGenerateLOAOptions) (ExpressRoutePortsClientGenerateLOAResponse, error) { + var err error + const operationName = "ExpressRoutePortsClient.GenerateLOA" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generateLOACreateRequest(ctx, resourceGroupName, expressRoutePortName, request, options) if err != nil { return ExpressRoutePortsClientGenerateLOAResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRoutePortsClientGenerateLOAResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRoutePortsClientGenerateLOAResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRoutePortsClientGenerateLOAResponse{}, err } - return client.generateLOAHandleResponse(resp) + resp, err := client.generateLOAHandleResponse(httpResp) + return resp, err } // generateLOACreateRequest creates the GenerateLOA request. @@ -227,7 +250,10 @@ func (client *ExpressRoutePortsClient) generateLOACreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, request) + if err := runtime.MarshalAsJSON(req, request); err != nil { + return nil, err + } + return req, nil } // generateLOAHandleResponse handles the GenerateLOA response. @@ -247,18 +273,25 @@ func (client *ExpressRoutePortsClient) generateLOAHandleResponse(resp *http.Resp // - expressRoutePortName - The name of ExpressRoutePort. // - options - ExpressRoutePortsClientGetOptions contains the optional parameters for the ExpressRoutePortsClient.Get method. func (client *ExpressRoutePortsClient) Get(ctx context.Context, resourceGroupName string, expressRoutePortName string, options *ExpressRoutePortsClientGetOptions) (ExpressRoutePortsClientGetResponse, error) { + var err error + const operationName = "ExpressRoutePortsClient.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, expressRoutePortName, options) if err != nil { return ExpressRoutePortsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRoutePortsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRoutePortsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRoutePortsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -307,6 +340,7 @@ func (client *ExpressRoutePortsClient) NewListPager(options *ExpressRoutePortsCl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRoutePortsClientListResponse) (ExpressRoutePortsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRoutePortsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -326,6 +360,7 @@ func (client *ExpressRoutePortsClient) NewListPager(options *ExpressRoutePortsCl } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -368,6 +403,7 @@ func (client *ExpressRoutePortsClient) NewListByResourceGroupPager(resourceGroup return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRoutePortsClientListByResourceGroupResponse) (ExpressRoutePortsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRoutePortsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -387,6 +423,7 @@ func (client *ExpressRoutePortsClient) NewListByResourceGroupPager(resourceGroup } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -431,18 +468,25 @@ func (client *ExpressRoutePortsClient) listByResourceGroupHandleResponse(resp *h // - options - ExpressRoutePortsClientUpdateTagsOptions contains the optional parameters for the ExpressRoutePortsClient.UpdateTags // method. func (client *ExpressRoutePortsClient) UpdateTags(ctx context.Context, resourceGroupName string, expressRoutePortName string, parameters TagsObject, options *ExpressRoutePortsClientUpdateTagsOptions) (ExpressRoutePortsClientUpdateTagsResponse, error) { + var err error + const operationName = "ExpressRoutePortsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, expressRoutePortName, parameters, options) if err != nil { return ExpressRoutePortsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRoutePortsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRoutePortsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRoutePortsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -468,7 +512,10 @@ func (client *ExpressRoutePortsClient) updateTagsCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/expressrouteportslocations_client.go b/sdk/resourcemanager/network/armnetwork/expressrouteportslocations_client.go index f9acf3f10c18..385eb6cdebb1 100644 --- a/sdk/resourcemanager/network/armnetwork/expressrouteportslocations_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressrouteportslocations_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 armnetwork @@ -54,18 +53,25 @@ func NewExpressRoutePortsLocationsClient(subscriptionID string, credential azcor // - options - ExpressRoutePortsLocationsClientGetOptions contains the optional parameters for the ExpressRoutePortsLocationsClient.Get // method. func (client *ExpressRoutePortsLocationsClient) Get(ctx context.Context, locationName string, options *ExpressRoutePortsLocationsClientGetOptions) (ExpressRoutePortsLocationsClientGetResponse, error) { + var err error + const operationName = "ExpressRoutePortsLocationsClient.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, locationName, options) if err != nil { return ExpressRoutePortsLocationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRoutePortsLocationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRoutePortsLocationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRoutePortsLocationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -111,6 +117,7 @@ func (client *ExpressRoutePortsLocationsClient) NewListPager(options *ExpressRou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRoutePortsLocationsClientListResponse) (ExpressRoutePortsLocationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRoutePortsLocationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -130,6 +137,7 @@ func (client *ExpressRoutePortsLocationsClient) NewListPager(options *ExpressRou } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/expressrouteproviderportslocation_client.go b/sdk/resourcemanager/network/armnetwork/expressrouteproviderportslocation_client.go index 05063da44352..344c84df85a6 100644 --- a/sdk/resourcemanager/network/armnetwork/expressrouteproviderportslocation_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressrouteproviderportslocation_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 armnetwork @@ -52,18 +51,25 @@ func NewExpressRouteProviderPortsLocationClient(subscriptionID string, credentia // - options - ExpressRouteProviderPortsLocationClientListOptions contains the optional parameters for the ExpressRouteProviderPortsLocationClient.List // method. func (client *ExpressRouteProviderPortsLocationClient) List(ctx context.Context, options *ExpressRouteProviderPortsLocationClientListOptions) (ExpressRouteProviderPortsLocationClientListResponse, error) { + var err error + const operationName = "ExpressRouteProviderPortsLocationClient.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, options) if err != nil { return ExpressRouteProviderPortsLocationClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ExpressRouteProviderPortsLocationClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExpressRouteProviderPortsLocationClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExpressRouteProviderPortsLocationClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/expressrouteserviceproviders_client.go b/sdk/resourcemanager/network/armnetwork/expressrouteserviceproviders_client.go index d9c186132418..6daedf661d0e 100644 --- a/sdk/resourcemanager/network/armnetwork/expressrouteserviceproviders_client.go +++ b/sdk/resourcemanager/network/armnetwork/expressrouteserviceproviders_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 armnetwork @@ -56,6 +55,7 @@ func (client *ExpressRouteServiceProvidersClient) NewListPager(options *ExpressR return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExpressRouteServiceProvidersClientListResponse) (ExpressRouteServiceProvidersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteServiceProvidersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -75,6 +75,7 @@ func (client *ExpressRouteServiceProvidersClient) NewListPager(options *ExpressR } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/fake/adminrulecollections_server.go b/sdk/resourcemanager/network/armnetwork/fake/adminrulecollections_server.go new file mode 100644 index 000000000000..844ca9e0e25a --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/adminrulecollections_server.go @@ -0,0 +1,308 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// AdminRuleCollectionsServer is a fake server for instances of the armnetwork.AdminRuleCollectionsClient type. +type AdminRuleCollectionsServer struct { + // CreateOrUpdate is the fake for method AdminRuleCollectionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleCollection armnetwork.AdminRuleCollection, options *armnetwork.AdminRuleCollectionsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.AdminRuleCollectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method AdminRuleCollectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *armnetwork.AdminRuleCollectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.AdminRuleCollectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AdminRuleCollectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *armnetwork.AdminRuleCollectionsClientGetOptions) (resp azfake.Responder[armnetwork.AdminRuleCollectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AdminRuleCollectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, configurationName string, options *armnetwork.AdminRuleCollectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.AdminRuleCollectionsClientListResponse]) +} + +// NewAdminRuleCollectionsServerTransport creates a new instance of AdminRuleCollectionsServerTransport with the provided implementation. +// The returned AdminRuleCollectionsServerTransport instance is connected to an instance of armnetwork.AdminRuleCollectionsClient by way of the +// undefined.Transporter field. +func NewAdminRuleCollectionsServerTransport(srv *AdminRuleCollectionsServer) *AdminRuleCollectionsServerTransport { + return &AdminRuleCollectionsServerTransport{srv: srv} +} + +// AdminRuleCollectionsServerTransport connects instances of armnetwork.AdminRuleCollectionsClient to instances of AdminRuleCollectionsServer. +// Don't use this type directly, use NewAdminRuleCollectionsServerTransport instead. +type AdminRuleCollectionsServerTransport struct { + srv *AdminRuleCollectionsServer + beginDelete *azfake.PollerResponder[armnetwork.AdminRuleCollectionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.AdminRuleCollectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for AdminRuleCollectionsServerTransport. +func (a *AdminRuleCollectionsServerTransport) 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 "AdminRuleCollectionsClient.CreateOrUpdate": + resp, err = a.dispatchCreateOrUpdate(req) + case "AdminRuleCollectionsClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "AdminRuleCollectionsClient.Get": + resp, err = a.dispatchGet(req) + case "AdminRuleCollectionsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AdminRuleCollectionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.AdminRuleCollection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, 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).AdminRuleCollection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AdminRuleCollectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if a.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + forceUnescaped, err := url.QueryUnescape(qp.Get("force")) + if err != nil { + return nil, err + } + forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armnetwork.AdminRuleCollectionsClientBeginDeleteOptions + if forceParam != nil { + options = &armnetwork.AdminRuleCollectionsClientBeginDeleteOptions{ + Force: forceParam, + } + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginDelete) { + a.beginDelete = nil + } + + return resp, nil +} + +func (a *AdminRuleCollectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, 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).AdminRuleCollection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AdminRuleCollectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.AdminRuleCollectionsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.AdminRuleCollectionsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := a.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, options) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AdminRuleCollectionsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/adminrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/adminrules_server.go new file mode 100644 index 000000000000..ffd8609e7db8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/adminrules_server.go @@ -0,0 +1,328 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// AdminRulesServer is a fake server for instances of the armnetwork.AdminRulesClient type. +type AdminRulesServer struct { + // CreateOrUpdate is the fake for method AdminRulesClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, adminRule armnetwork.BaseAdminRuleClassification, options *armnetwork.AdminRulesClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.AdminRulesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method AdminRulesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *armnetwork.AdminRulesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.AdminRulesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AdminRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *armnetwork.AdminRulesClientGetOptions) (resp azfake.Responder[armnetwork.AdminRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AdminRulesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *armnetwork.AdminRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.AdminRulesClientListResponse]) +} + +// NewAdminRulesServerTransport creates a new instance of AdminRulesServerTransport with the provided implementation. +// The returned AdminRulesServerTransport instance is connected to an instance of armnetwork.AdminRulesClient by way of the +// undefined.Transporter field. +func NewAdminRulesServerTransport(srv *AdminRulesServer) *AdminRulesServerTransport { + return &AdminRulesServerTransport{srv: srv} +} + +// AdminRulesServerTransport connects instances of armnetwork.AdminRulesClient to instances of AdminRulesServer. +// Don't use this type directly, use NewAdminRulesServerTransport instead. +type AdminRulesServerTransport struct { + srv *AdminRulesServer + beginDelete *azfake.PollerResponder[armnetwork.AdminRulesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.AdminRulesClientListResponse] +} + +// Do implements the policy.Transporter interface for AdminRulesServerTransport. +func (a *AdminRulesServerTransport) 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 "AdminRulesClient.CreateOrUpdate": + resp, err = a.dispatchCreateOrUpdate(req) + case "AdminRulesClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "AdminRulesClient.Get": + resp, err = a.dispatchGet(req) + case "AdminRulesClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AdminRulesServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + raw, err := readRequestBody(req) + if err != nil { + return nil, err + } + body, err := unmarshalBaseAdminRuleClassification(raw) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + ruleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, ruleNameUnescaped, 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).BaseAdminRuleClassification, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AdminRulesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if a.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + ruleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleName")]) + if err != nil { + return nil, err + } + forceUnescaped, err := url.QueryUnescape(qp.Get("force")) + if err != nil { + return nil, err + } + forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armnetwork.AdminRulesClientBeginDeleteOptions + if forceParam != nil { + options = &armnetwork.AdminRulesClientBeginDeleteOptions{ + Force: forceParam, + } + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, ruleNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginDelete) { + a.beginDelete = nil + } + + return resp, nil +} + +func (a *AdminRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + ruleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, ruleNameUnescaped, 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).BaseAdminRuleClassification, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AdminRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/rules` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.AdminRulesClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.AdminRulesClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := a.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, ruleCollectionNameUnescaped, options) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AdminRulesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/applicationgatewayprivateendpointconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewayprivateendpointconnections_server.go new file mode 100644 index 000000000000..ebd368d85781 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewayprivateendpointconnections_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ApplicationGatewayPrivateEndpointConnectionsServer is a fake server for instances of the armnetwork.ApplicationGatewayPrivateEndpointConnectionsClient type. +type ApplicationGatewayPrivateEndpointConnectionsServer struct { + // BeginDelete is the fake for method ApplicationGatewayPrivateEndpointConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ApplicationGatewayPrivateEndpointConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ApplicationGatewayPrivateEndpointConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientListResponse]) + + // BeginUpdate is the fake for method ApplicationGatewayPrivateEndpointConnectionsClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, parameters armnetwork.ApplicationGatewayPrivateEndpointConnection, options *armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientBeginUpdateOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewApplicationGatewayPrivateEndpointConnectionsServerTransport creates a new instance of ApplicationGatewayPrivateEndpointConnectionsServerTransport with the provided implementation. +// The returned ApplicationGatewayPrivateEndpointConnectionsServerTransport instance is connected to an instance of armnetwork.ApplicationGatewayPrivateEndpointConnectionsClient by way of the +// undefined.Transporter field. +func NewApplicationGatewayPrivateEndpointConnectionsServerTransport(srv *ApplicationGatewayPrivateEndpointConnectionsServer) *ApplicationGatewayPrivateEndpointConnectionsServerTransport { + return &ApplicationGatewayPrivateEndpointConnectionsServerTransport{srv: srv} +} + +// ApplicationGatewayPrivateEndpointConnectionsServerTransport connects instances of armnetwork.ApplicationGatewayPrivateEndpointConnectionsClient to instances of ApplicationGatewayPrivateEndpointConnectionsServer. +// Don't use this type directly, use NewApplicationGatewayPrivateEndpointConnectionsServerTransport instead. +type ApplicationGatewayPrivateEndpointConnectionsServerTransport struct { + srv *ApplicationGatewayPrivateEndpointConnectionsServer + beginDelete *azfake.PollerResponder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientListResponse] + beginUpdate *azfake.PollerResponder[armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse] +} + +// Do implements the policy.Transporter interface for ApplicationGatewayPrivateEndpointConnectionsServerTransport. +func (a *ApplicationGatewayPrivateEndpointConnectionsServerTransport) 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 "ApplicationGatewayPrivateEndpointConnectionsClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "ApplicationGatewayPrivateEndpointConnectionsClient.Get": + resp, err = a.dispatchGet(req) + case "ApplicationGatewayPrivateEndpointConnectionsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "ApplicationGatewayPrivateEndpointConnectionsClient.BeginUpdate": + resp, err = a.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationGatewayPrivateEndpointConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if a.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, connectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginDelete) { + a.beginDelete = nil + } + + return resp, nil +} + +func (a *ApplicationGatewayPrivateEndpointConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + 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.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, connectionNameUnescaped, 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).ApplicationGatewayPrivateEndpointConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewayPrivateEndpointConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(resourceGroupNameUnescaped, applicationGatewayNameUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.ApplicationGatewayPrivateEndpointConnectionsClientListResponse, 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 *ApplicationGatewayPrivateEndpointConnectionsServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} + } + if a.beginUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ApplicationGatewayPrivateEndpointConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, connectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginUpdate = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginUpdate) { + a.beginUpdate = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/applicationgatewayprivatelinkresources_server.go b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewayprivatelinkresources_server.go new file mode 100644 index 000000000000..a75748c3dfd6 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewayprivatelinkresources_server.go @@ -0,0 +1,106 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ApplicationGatewayPrivateLinkResourcesServer is a fake server for instances of the armnetwork.ApplicationGatewayPrivateLinkResourcesClient type. +type ApplicationGatewayPrivateLinkResourcesServer struct { + // NewListPager is the fake for method ApplicationGatewayPrivateLinkResourcesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewayPrivateLinkResourcesClientListOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse]) +} + +// NewApplicationGatewayPrivateLinkResourcesServerTransport creates a new instance of ApplicationGatewayPrivateLinkResourcesServerTransport with the provided implementation. +// The returned ApplicationGatewayPrivateLinkResourcesServerTransport instance is connected to an instance of armnetwork.ApplicationGatewayPrivateLinkResourcesClient by way of the +// undefined.Transporter field. +func NewApplicationGatewayPrivateLinkResourcesServerTransport(srv *ApplicationGatewayPrivateLinkResourcesServer) *ApplicationGatewayPrivateLinkResourcesServerTransport { + return &ApplicationGatewayPrivateLinkResourcesServerTransport{srv: srv} +} + +// ApplicationGatewayPrivateLinkResourcesServerTransport connects instances of armnetwork.ApplicationGatewayPrivateLinkResourcesClient to instances of ApplicationGatewayPrivateLinkResourcesServer. +// Don't use this type directly, use NewApplicationGatewayPrivateLinkResourcesServerTransport instead. +type ApplicationGatewayPrivateLinkResourcesServerTransport struct { + srv *ApplicationGatewayPrivateLinkResourcesServer + newListPager *azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse] +} + +// Do implements the policy.Transporter interface for ApplicationGatewayPrivateLinkResourcesServerTransport. +func (a *ApplicationGatewayPrivateLinkResourcesServerTransport) 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 "ApplicationGatewayPrivateLinkResourcesClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationGatewayPrivateLinkResourcesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateLinkResources` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(resourceGroupNameUnescaped, applicationGatewayNameUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/applicationgateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/applicationgateways_server.go new file mode 100644 index 000000000000..0c2cba7c772e --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/applicationgateways_server.go @@ -0,0 +1,769 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ApplicationGatewaysServer is a fake server for instances of the armnetwork.ApplicationGatewaysClient type. +type ApplicationGatewaysServer struct { + // BeginBackendHealth is the fake for method ApplicationGatewaysClient.BeginBackendHealth + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginBackendHealth func(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewaysClientBeginBackendHealthOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewaysClientBackendHealthResponse], errResp azfake.ErrorResponder) + + // BeginBackendHealthOnDemand is the fake for method ApplicationGatewaysClient.BeginBackendHealthOnDemand + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginBackendHealthOnDemand func(ctx context.Context, resourceGroupName string, applicationGatewayName string, probeRequest armnetwork.ApplicationGatewayOnDemandProbe, options *armnetwork.ApplicationGatewaysClientBeginBackendHealthOnDemandOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewaysClientBackendHealthOnDemandResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method ApplicationGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters armnetwork.ApplicationGateway, options *armnetwork.ApplicationGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ApplicationGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ApplicationGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // GetSSLPredefinedPolicy is the fake for method ApplicationGatewaysClient.GetSSLPredefinedPolicy + // HTTP status codes to indicate success: http.StatusOK + GetSSLPredefinedPolicy func(ctx context.Context, predefinedPolicyName string, options *armnetwork.ApplicationGatewaysClientGetSSLPredefinedPolicyOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientGetSSLPredefinedPolicyResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ApplicationGatewaysClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.ApplicationGatewaysClientListOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewaysClientListResponse]) + + // NewListAllPager is the fake for method ApplicationGatewaysClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.ApplicationGatewaysClientListAllOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewaysClientListAllResponse]) + + // ListAvailableRequestHeaders is the fake for method ApplicationGatewaysClient.ListAvailableRequestHeaders + // HTTP status codes to indicate success: http.StatusOK + ListAvailableRequestHeaders func(ctx context.Context, options *armnetwork.ApplicationGatewaysClientListAvailableRequestHeadersOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientListAvailableRequestHeadersResponse], errResp azfake.ErrorResponder) + + // ListAvailableResponseHeaders is the fake for method ApplicationGatewaysClient.ListAvailableResponseHeaders + // HTTP status codes to indicate success: http.StatusOK + ListAvailableResponseHeaders func(ctx context.Context, options *armnetwork.ApplicationGatewaysClientListAvailableResponseHeadersOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientListAvailableResponseHeadersResponse], errResp azfake.ErrorResponder) + + // ListAvailableSSLOptions is the fake for method ApplicationGatewaysClient.ListAvailableSSLOptions + // HTTP status codes to indicate success: http.StatusOK + ListAvailableSSLOptions func(ctx context.Context, options *armnetwork.ApplicationGatewaysClientListAvailableSSLOptionsOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientListAvailableSSLOptionsResponse], errResp azfake.ErrorResponder) + + // NewListAvailableSSLPredefinedPoliciesPager is the fake for method ApplicationGatewaysClient.NewListAvailableSSLPredefinedPoliciesPager + // HTTP status codes to indicate success: http.StatusOK + NewListAvailableSSLPredefinedPoliciesPager func(options *armnetwork.ApplicationGatewaysClientListAvailableSSLPredefinedPoliciesOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewaysClientListAvailableSSLPredefinedPoliciesResponse]) + + // ListAvailableServerVariables is the fake for method ApplicationGatewaysClient.ListAvailableServerVariables + // HTTP status codes to indicate success: http.StatusOK + ListAvailableServerVariables func(ctx context.Context, options *armnetwork.ApplicationGatewaysClientListAvailableServerVariablesOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientListAvailableServerVariablesResponse], errResp azfake.ErrorResponder) + + // ListAvailableWafRuleSets is the fake for method ApplicationGatewaysClient.ListAvailableWafRuleSets + // HTTP status codes to indicate success: http.StatusOK + ListAvailableWafRuleSets func(ctx context.Context, options *armnetwork.ApplicationGatewaysClientListAvailableWafRuleSetsOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientListAvailableWafRuleSetsResponse], errResp azfake.ErrorResponder) + + // BeginStart is the fake for method ApplicationGatewaysClient.BeginStart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStart func(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewaysClientBeginStartOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewaysClientStartResponse], errResp azfake.ErrorResponder) + + // BeginStop is the fake for method ApplicationGatewaysClient.BeginStop + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStop func(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewaysClientBeginStopOptions) (resp azfake.PollerResponder[armnetwork.ApplicationGatewaysClientStopResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method ApplicationGatewaysClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters armnetwork.TagsObject, options *armnetwork.ApplicationGatewaysClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ApplicationGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewApplicationGatewaysServerTransport creates a new instance of ApplicationGatewaysServerTransport with the provided implementation. +// The returned ApplicationGatewaysServerTransport instance is connected to an instance of armnetwork.ApplicationGatewaysClient by way of the +// undefined.Transporter field. +func NewApplicationGatewaysServerTransport(srv *ApplicationGatewaysServer) *ApplicationGatewaysServerTransport { + return &ApplicationGatewaysServerTransport{srv: srv} +} + +// ApplicationGatewaysServerTransport connects instances of armnetwork.ApplicationGatewaysClient to instances of ApplicationGatewaysServer. +// Don't use this type directly, use NewApplicationGatewaysServerTransport instead. +type ApplicationGatewaysServerTransport struct { + srv *ApplicationGatewaysServer + beginBackendHealth *azfake.PollerResponder[armnetwork.ApplicationGatewaysClientBackendHealthResponse] + beginBackendHealthOnDemand *azfake.PollerResponder[armnetwork.ApplicationGatewaysClientBackendHealthOnDemandResponse] + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ApplicationGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ApplicationGatewaysClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ApplicationGatewaysClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.ApplicationGatewaysClientListAllResponse] + newListAvailableSSLPredefinedPoliciesPager *azfake.PagerResponder[armnetwork.ApplicationGatewaysClientListAvailableSSLPredefinedPoliciesResponse] + beginStart *azfake.PollerResponder[armnetwork.ApplicationGatewaysClientStartResponse] + beginStop *azfake.PollerResponder[armnetwork.ApplicationGatewaysClientStopResponse] +} + +// Do implements the policy.Transporter interface for ApplicationGatewaysServerTransport. +func (a *ApplicationGatewaysServerTransport) 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 "ApplicationGatewaysClient.BeginBackendHealth": + resp, err = a.dispatchBeginBackendHealth(req) + case "ApplicationGatewaysClient.BeginBackendHealthOnDemand": + resp, err = a.dispatchBeginBackendHealthOnDemand(req) + case "ApplicationGatewaysClient.BeginCreateOrUpdate": + resp, err = a.dispatchBeginCreateOrUpdate(req) + case "ApplicationGatewaysClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "ApplicationGatewaysClient.Get": + resp, err = a.dispatchGet(req) + case "ApplicationGatewaysClient.GetSSLPredefinedPolicy": + resp, err = a.dispatchGetSSLPredefinedPolicy(req) + case "ApplicationGatewaysClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "ApplicationGatewaysClient.NewListAllPager": + resp, err = a.dispatchNewListAllPager(req) + case "ApplicationGatewaysClient.ListAvailableRequestHeaders": + resp, err = a.dispatchListAvailableRequestHeaders(req) + case "ApplicationGatewaysClient.ListAvailableResponseHeaders": + resp, err = a.dispatchListAvailableResponseHeaders(req) + case "ApplicationGatewaysClient.ListAvailableSSLOptions": + resp, err = a.dispatchListAvailableSSLOptions(req) + case "ApplicationGatewaysClient.NewListAvailableSSLPredefinedPoliciesPager": + resp, err = a.dispatchNewListAvailableSSLPredefinedPoliciesPager(req) + case "ApplicationGatewaysClient.ListAvailableServerVariables": + resp, err = a.dispatchListAvailableServerVariables(req) + case "ApplicationGatewaysClient.ListAvailableWafRuleSets": + resp, err = a.dispatchListAvailableWafRuleSets(req) + case "ApplicationGatewaysClient.BeginStart": + resp, err = a.dispatchBeginStart(req) + case "ApplicationGatewaysClient.BeginStop": + resp, err = a.dispatchBeginStop(req) + case "ApplicationGatewaysClient.UpdateTags": + resp, err = a.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchBeginBackendHealth(req *http.Request) (*http.Response, error) { + if a.srv.BeginBackendHealth == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginBackendHealth not implemented")} + } + if a.beginBackendHealth == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/backendhealth` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.ApplicationGatewaysClientBeginBackendHealthOptions + if expandParam != nil { + options = &armnetwork.ApplicationGatewaysClientBeginBackendHealthOptions{ + Expand: expandParam, + } + } + respr, errRespr := a.srv.BeginBackendHealth(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginBackendHealth = &respr + } + + resp, err := server.PollerResponderNext(a.beginBackendHealth, 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(a.beginBackendHealth) { + a.beginBackendHealth = nil + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchBeginBackendHealthOnDemand(req *http.Request) (*http.Response, error) { + if a.srv.BeginBackendHealthOnDemand == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginBackendHealthOnDemand not implemented")} + } + if a.beginBackendHealthOnDemand == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getBackendHealthOnDemand` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.ApplicationGatewayOnDemandProbe](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.ApplicationGatewaysClientBeginBackendHealthOnDemandOptions + if expandParam != nil { + options = &armnetwork.ApplicationGatewaysClientBeginBackendHealthOnDemandOptions{ + Expand: expandParam, + } + } + respr, errRespr := a.srv.BeginBackendHealthOnDemand(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, body, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginBackendHealthOnDemand = &respr + } + + resp, err := server.PollerResponderNext(a.beginBackendHealthOnDemand, 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(a.beginBackendHealthOnDemand) { + a.beginBackendHealthOnDemand = nil + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if a.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ApplicationGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginCreateOrUpdate) { + a.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if a.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginDelete) { + a.beginDelete = nil + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + 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.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, 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).ApplicationGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchGetSSLPredefinedPolicy(req *http.Request) (*http.Response, error) { + if a.srv.GetSSLPredefinedPolicy == nil { + return nil, &nonRetriableError{errors.New("fake for method GetSSLPredefinedPolicy not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default/predefinedPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + predefinedPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("predefinedPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.GetSSLPredefinedPolicy(req.Context(), predefinedPolicyNameUnescaped, 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).ApplicationGatewaySSLPredefinedPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/applicationGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.ApplicationGatewaysClientListResponse, 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 *ApplicationGatewaysServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if a.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := a.srv.NewListAllPager(nil) + a.newListAllPager = &resp + server.PagerResponderInjectNextLinks(a.newListAllPager, req, func(page *armnetwork.ApplicationGatewaysClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListAllPager) { + a.newListAllPager = nil + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchListAvailableRequestHeaders(req *http.Request) (*http.Response, error) { + if a.srv.ListAvailableRequestHeaders == nil { + return nil, &nonRetriableError{errors.New("fake for method ListAvailableRequestHeaders not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableRequestHeaders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := a.srv.ListAvailableRequestHeaders(req.Context(), 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).StringArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchListAvailableResponseHeaders(req *http.Request) (*http.Response, error) { + if a.srv.ListAvailableResponseHeaders == nil { + return nil, &nonRetriableError{errors.New("fake for method ListAvailableResponseHeaders not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableResponseHeaders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := a.srv.ListAvailableResponseHeaders(req.Context(), 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).StringArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchListAvailableSSLOptions(req *http.Request) (*http.Response, error) { + if a.srv.ListAvailableSSLOptions == nil { + return nil, &nonRetriableError{errors.New("fake for method ListAvailableSSLOptions not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := a.srv.ListAvailableSSLOptions(req.Context(), 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).ApplicationGatewayAvailableSSLOptions, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchNewListAvailableSSLPredefinedPoliciesPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListAvailableSSLPredefinedPoliciesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAvailableSSLPredefinedPoliciesPager not implemented")} + } + if a.newListAvailableSSLPredefinedPoliciesPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default/predefinedPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := a.srv.NewListAvailableSSLPredefinedPoliciesPager(nil) + a.newListAvailableSSLPredefinedPoliciesPager = &resp + server.PagerResponderInjectNextLinks(a.newListAvailableSSLPredefinedPoliciesPager, req, func(page *armnetwork.ApplicationGatewaysClientListAvailableSSLPredefinedPoliciesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.newListAvailableSSLPredefinedPoliciesPager, 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.newListAvailableSSLPredefinedPoliciesPager) { + a.newListAvailableSSLPredefinedPoliciesPager = nil + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchListAvailableServerVariables(req *http.Request) (*http.Response, error) { + if a.srv.ListAvailableServerVariables == nil { + return nil, &nonRetriableError{errors.New("fake for method ListAvailableServerVariables not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableServerVariables` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := a.srv.ListAvailableServerVariables(req.Context(), 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).StringArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchListAvailableWafRuleSets(req *http.Request) (*http.Response, error) { + if a.srv.ListAvailableWafRuleSets == nil { + return nil, &nonRetriableError{errors.New("fake for method ListAvailableWafRuleSets not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGatewayAvailableWafRuleSets` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := a.srv.ListAvailableWafRuleSets(req.Context(), 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).ApplicationGatewayAvailableWafRuleSetsResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { + if a.srv.BeginStart == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStart not implemented")} + } + if a.beginStart == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/start` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginStart(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginStart = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginStart) { + a.beginStart = nil + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchBeginStop(req *http.Request) (*http.Response, error) { + if a.srv.BeginStop == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStop not implemented")} + } + if a.beginStop == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stop` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginStop(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginStop = &respr + } + + resp, err := server.PollerResponderNext(a.beginStop, 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(a.beginStop) { + a.beginStop = nil + } + + return resp, nil +} + +func (a *ApplicationGatewaysServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if a.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, applicationGatewayNameUnescaped, 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).ApplicationGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/applicationgatewaywafdynamicmanifests_server.go b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewaywafdynamicmanifests_server.go new file mode 100644 index 000000000000..fbcbc3256d06 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewaywafdynamicmanifests_server.go @@ -0,0 +1,102 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ApplicationGatewayWafDynamicManifestsServer is a fake server for instances of the armnetwork.ApplicationGatewayWafDynamicManifestsClient type. +type ApplicationGatewayWafDynamicManifestsServer struct { + // NewGetPager is the fake for method ApplicationGatewayWafDynamicManifestsClient.NewGetPager + // HTTP status codes to indicate success: http.StatusOK + NewGetPager func(location string, options *armnetwork.ApplicationGatewayWafDynamicManifestsClientGetOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewayWafDynamicManifestsClientGetResponse]) +} + +// NewApplicationGatewayWafDynamicManifestsServerTransport creates a new instance of ApplicationGatewayWafDynamicManifestsServerTransport with the provided implementation. +// The returned ApplicationGatewayWafDynamicManifestsServerTransport instance is connected to an instance of armnetwork.ApplicationGatewayWafDynamicManifestsClient by way of the +// undefined.Transporter field. +func NewApplicationGatewayWafDynamicManifestsServerTransport(srv *ApplicationGatewayWafDynamicManifestsServer) *ApplicationGatewayWafDynamicManifestsServerTransport { + return &ApplicationGatewayWafDynamicManifestsServerTransport{srv: srv} +} + +// ApplicationGatewayWafDynamicManifestsServerTransport connects instances of armnetwork.ApplicationGatewayWafDynamicManifestsClient to instances of ApplicationGatewayWafDynamicManifestsServer. +// Don't use this type directly, use NewApplicationGatewayWafDynamicManifestsServerTransport instead. +type ApplicationGatewayWafDynamicManifestsServerTransport struct { + srv *ApplicationGatewayWafDynamicManifestsServer + newGetPager *azfake.PagerResponder[armnetwork.ApplicationGatewayWafDynamicManifestsClientGetResponse] +} + +// Do implements the policy.Transporter interface for ApplicationGatewayWafDynamicManifestsServerTransport. +func (a *ApplicationGatewayWafDynamicManifestsServerTransport) 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 "ApplicationGatewayWafDynamicManifestsClient.NewGetPager": + resp, err = a.dispatchNewGetPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationGatewayWafDynamicManifestsServerTransport) dispatchNewGetPager(req *http.Request) (*http.Response, error) { + if a.srv.NewGetPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewGetPager not implemented")} + } + if a.newGetPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applicationGatewayWafDynamicManifests` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := a.srv.NewGetPager(locationUnescaped, nil) + a.newGetPager = &resp + server.PagerResponderInjectNextLinks(a.newGetPager, req, func(page *armnetwork.ApplicationGatewayWafDynamicManifestsClientGetResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.newGetPager, 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.newGetPager) { + a.newGetPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/applicationgatewaywafdynamicmanifestsdefault_server.go b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewaywafdynamicmanifestsdefault_server.go new file mode 100644 index 000000000000..0223dd22626b --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/applicationgatewaywafdynamicmanifestsdefault_server.go @@ -0,0 +1,96 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ApplicationGatewayWafDynamicManifestsDefaultServer is a fake server for instances of the armnetwork.ApplicationGatewayWafDynamicManifestsDefaultClient type. +type ApplicationGatewayWafDynamicManifestsDefaultServer struct { + // Get is the fake for method ApplicationGatewayWafDynamicManifestsDefaultClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, location string, options *armnetwork.ApplicationGatewayWafDynamicManifestsDefaultClientGetOptions) (resp azfake.Responder[armnetwork.ApplicationGatewayWafDynamicManifestsDefaultClientGetResponse], errResp azfake.ErrorResponder) +} + +// NewApplicationGatewayWafDynamicManifestsDefaultServerTransport creates a new instance of ApplicationGatewayWafDynamicManifestsDefaultServerTransport with the provided implementation. +// The returned ApplicationGatewayWafDynamicManifestsDefaultServerTransport instance is connected to an instance of armnetwork.ApplicationGatewayWafDynamicManifestsDefaultClient by way of the +// undefined.Transporter field. +func NewApplicationGatewayWafDynamicManifestsDefaultServerTransport(srv *ApplicationGatewayWafDynamicManifestsDefaultServer) *ApplicationGatewayWafDynamicManifestsDefaultServerTransport { + return &ApplicationGatewayWafDynamicManifestsDefaultServerTransport{srv: srv} +} + +// ApplicationGatewayWafDynamicManifestsDefaultServerTransport connects instances of armnetwork.ApplicationGatewayWafDynamicManifestsDefaultClient to instances of ApplicationGatewayWafDynamicManifestsDefaultServer. +// Don't use this type directly, use NewApplicationGatewayWafDynamicManifestsDefaultServerTransport instead. +type ApplicationGatewayWafDynamicManifestsDefaultServerTransport struct { + srv *ApplicationGatewayWafDynamicManifestsDefaultServer +} + +// Do implements the policy.Transporter interface for ApplicationGatewayWafDynamicManifestsDefaultServerTransport. +func (a *ApplicationGatewayWafDynamicManifestsDefaultServerTransport) 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 "ApplicationGatewayWafDynamicManifestsDefaultClient.Get": + resp, err = a.dispatchGet(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationGatewayWafDynamicManifestsDefaultServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/applicationGatewayWafDynamicManifests/dafault` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), locationUnescaped, 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).ApplicationGatewayWafDynamicManifestResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/applicationsecuritygroups_server.go b/sdk/resourcemanager/network/armnetwork/fake/applicationsecuritygroups_server.go new file mode 100644 index 000000000000..0d5b13887e21 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/applicationsecuritygroups_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ApplicationSecurityGroupsServer is a fake server for instances of the armnetwork.ApplicationSecurityGroupsClient type. +type ApplicationSecurityGroupsServer struct { + // BeginCreateOrUpdate is the fake for method ApplicationSecurityGroupsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, parameters armnetwork.ApplicationSecurityGroup, options *armnetwork.ApplicationSecurityGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ApplicationSecurityGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, options *armnetwork.ApplicationSecurityGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ApplicationSecurityGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, options *armnetwork.ApplicationSecurityGroupsClientGetOptions) (resp azfake.Responder[armnetwork.ApplicationSecurityGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ApplicationSecurityGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.ApplicationSecurityGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListResponse]) + + // NewListAllPager is the fake for method ApplicationSecurityGroupsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.ApplicationSecurityGroupsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListAllResponse]) + + // UpdateTags is the fake for method ApplicationSecurityGroupsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, parameters armnetwork.TagsObject, options *armnetwork.ApplicationSecurityGroupsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ApplicationSecurityGroupsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewApplicationSecurityGroupsServerTransport creates a new instance of ApplicationSecurityGroupsServerTransport with the provided implementation. +// The returned ApplicationSecurityGroupsServerTransport instance is connected to an instance of armnetwork.ApplicationSecurityGroupsClient by way of the +// undefined.Transporter field. +func NewApplicationSecurityGroupsServerTransport(srv *ApplicationSecurityGroupsServer) *ApplicationSecurityGroupsServerTransport { + return &ApplicationSecurityGroupsServerTransport{srv: srv} +} + +// ApplicationSecurityGroupsServerTransport connects instances of armnetwork.ApplicationSecurityGroupsClient to instances of ApplicationSecurityGroupsServer. +// Don't use this type directly, use NewApplicationSecurityGroupsServerTransport instead. +type ApplicationSecurityGroupsServerTransport struct { + srv *ApplicationSecurityGroupsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListAllResponse] +} + +// Do implements the policy.Transporter interface for ApplicationSecurityGroupsServerTransport. +func (a *ApplicationSecurityGroupsServerTransport) 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 "ApplicationSecurityGroupsClient.BeginCreateOrUpdate": + resp, err = a.dispatchBeginCreateOrUpdate(req) + case "ApplicationSecurityGroupsClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "ApplicationSecurityGroupsClient.Get": + resp, err = a.dispatchGet(req) + case "ApplicationSecurityGroupsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "ApplicationSecurityGroupsClient.NewListAllPager": + resp, err = a.dispatchNewListAllPager(req) + case "ApplicationSecurityGroupsClient.UpdateTags": + resp, err = a.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationSecurityGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if a.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ApplicationSecurityGroup](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, applicationSecurityGroupNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginCreateOrUpdate) { + a.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (a *ApplicationSecurityGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if a.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, applicationSecurityGroupNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginDelete) { + a.beginDelete = nil + } + + return resp, nil +} + +func (a *ApplicationSecurityGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + 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.Network/applicationSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, applicationSecurityGroupNameUnescaped, 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).ApplicationSecurityGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationSecurityGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/applicationSecurityGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.ApplicationSecurityGroupsClientListResponse, 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 *ApplicationSecurityGroupsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if a.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationSecurityGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := a.srv.NewListAllPager(nil) + a.newListAllPager = &resp + server.PagerResponderInjectNextLinks(a.newListAllPager, req, func(page *armnetwork.ApplicationSecurityGroupsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListAllPager) { + a.newListAllPager = nil + } + return resp, nil +} + +func (a *ApplicationSecurityGroupsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if a.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/applicationSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, applicationSecurityGroupNameUnescaped, 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).ApplicationSecurityGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/availabledelegations_server.go b/sdk/resourcemanager/network/armnetwork/fake/availabledelegations_server.go new file mode 100644 index 000000000000..b0ca82084317 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/availabledelegations_server.go @@ -0,0 +1,102 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// AvailableDelegationsServer is a fake server for instances of the armnetwork.AvailableDelegationsClient type. +type AvailableDelegationsServer struct { + // NewListPager is the fake for method AvailableDelegationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armnetwork.AvailableDelegationsClientListOptions) (resp azfake.PagerResponder[armnetwork.AvailableDelegationsClientListResponse]) +} + +// NewAvailableDelegationsServerTransport creates a new instance of AvailableDelegationsServerTransport with the provided implementation. +// The returned AvailableDelegationsServerTransport instance is connected to an instance of armnetwork.AvailableDelegationsClient by way of the +// undefined.Transporter field. +func NewAvailableDelegationsServerTransport(srv *AvailableDelegationsServer) *AvailableDelegationsServerTransport { + return &AvailableDelegationsServerTransport{srv: srv} +} + +// AvailableDelegationsServerTransport connects instances of armnetwork.AvailableDelegationsClient to instances of AvailableDelegationsServer. +// Don't use this type directly, use NewAvailableDelegationsServerTransport instead. +type AvailableDelegationsServerTransport struct { + srv *AvailableDelegationsServer + newListPager *azfake.PagerResponder[armnetwork.AvailableDelegationsClientListResponse] +} + +// Do implements the policy.Transporter interface for AvailableDelegationsServerTransport. +func (a *AvailableDelegationsServerTransport) 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 "AvailableDelegationsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AvailableDelegationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if a.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availableDelegations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(locationUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AvailableDelegationsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/availableendpointservices_server.go b/sdk/resourcemanager/network/armnetwork/fake/availableendpointservices_server.go new file mode 100644 index 000000000000..45b992695376 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/availableendpointservices_server.go @@ -0,0 +1,102 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// AvailableEndpointServicesServer is a fake server for instances of the armnetwork.AvailableEndpointServicesClient type. +type AvailableEndpointServicesServer struct { + // NewListPager is the fake for method AvailableEndpointServicesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armnetwork.AvailableEndpointServicesClientListOptions) (resp azfake.PagerResponder[armnetwork.AvailableEndpointServicesClientListResponse]) +} + +// NewAvailableEndpointServicesServerTransport creates a new instance of AvailableEndpointServicesServerTransport with the provided implementation. +// The returned AvailableEndpointServicesServerTransport instance is connected to an instance of armnetwork.AvailableEndpointServicesClient by way of the +// undefined.Transporter field. +func NewAvailableEndpointServicesServerTransport(srv *AvailableEndpointServicesServer) *AvailableEndpointServicesServerTransport { + return &AvailableEndpointServicesServerTransport{srv: srv} +} + +// AvailableEndpointServicesServerTransport connects instances of armnetwork.AvailableEndpointServicesClient to instances of AvailableEndpointServicesServer. +// Don't use this type directly, use NewAvailableEndpointServicesServerTransport instead. +type AvailableEndpointServicesServerTransport struct { + srv *AvailableEndpointServicesServer + newListPager *azfake.PagerResponder[armnetwork.AvailableEndpointServicesClientListResponse] +} + +// Do implements the policy.Transporter interface for AvailableEndpointServicesServerTransport. +func (a *AvailableEndpointServicesServerTransport) 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 "AvailableEndpointServicesClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AvailableEndpointServicesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if a.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualNetworkAvailableEndpointServices` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(locationUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AvailableEndpointServicesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/availableprivateendpointtypes_server.go b/sdk/resourcemanager/network/armnetwork/fake/availableprivateendpointtypes_server.go new file mode 100644 index 000000000000..cf120bbb7a63 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/availableprivateendpointtypes_server.go @@ -0,0 +1,147 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// AvailablePrivateEndpointTypesServer is a fake server for instances of the armnetwork.AvailablePrivateEndpointTypesClient type. +type AvailablePrivateEndpointTypesServer struct { + // NewListPager is the fake for method AvailablePrivateEndpointTypesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armnetwork.AvailablePrivateEndpointTypesClientListOptions) (resp azfake.PagerResponder[armnetwork.AvailablePrivateEndpointTypesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method AvailablePrivateEndpointTypesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(location string, resourceGroupName string, options *armnetwork.AvailablePrivateEndpointTypesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.AvailablePrivateEndpointTypesClientListByResourceGroupResponse]) +} + +// NewAvailablePrivateEndpointTypesServerTransport creates a new instance of AvailablePrivateEndpointTypesServerTransport with the provided implementation. +// The returned AvailablePrivateEndpointTypesServerTransport instance is connected to an instance of armnetwork.AvailablePrivateEndpointTypesClient by way of the +// undefined.Transporter field. +func NewAvailablePrivateEndpointTypesServerTransport(srv *AvailablePrivateEndpointTypesServer) *AvailablePrivateEndpointTypesServerTransport { + return &AvailablePrivateEndpointTypesServerTransport{srv: srv} +} + +// AvailablePrivateEndpointTypesServerTransport connects instances of armnetwork.AvailablePrivateEndpointTypesClient to instances of AvailablePrivateEndpointTypesServer. +// Don't use this type directly, use NewAvailablePrivateEndpointTypesServerTransport instead. +type AvailablePrivateEndpointTypesServerTransport struct { + srv *AvailablePrivateEndpointTypesServer + newListPager *azfake.PagerResponder[armnetwork.AvailablePrivateEndpointTypesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.AvailablePrivateEndpointTypesClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for AvailablePrivateEndpointTypesServerTransport. +func (a *AvailablePrivateEndpointTypesServerTransport) 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 "AvailablePrivateEndpointTypesClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "AvailablePrivateEndpointTypesClient.NewListByResourceGroupPager": + resp, err = a.dispatchNewListByResourceGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AvailablePrivateEndpointTypesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if a.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availablePrivateEndpointTypes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(locationUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AvailablePrivateEndpointTypesClientListResponse, 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 *AvailablePrivateEndpointTypesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if a.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availablePrivateEndpointTypes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListByResourceGroupPager(locationUnescaped, resourceGroupNameUnescaped, nil) + a.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(a.newListByResourceGroupPager, req, func(page *armnetwork.AvailablePrivateEndpointTypesClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListByResourceGroupPager) { + a.newListByResourceGroupPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/availableresourcegroupdelegations_server.go b/sdk/resourcemanager/network/armnetwork/fake/availableresourcegroupdelegations_server.go new file mode 100644 index 000000000000..45e8f7b9ec87 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/availableresourcegroupdelegations_server.go @@ -0,0 +1,106 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// AvailableResourceGroupDelegationsServer is a fake server for instances of the armnetwork.AvailableResourceGroupDelegationsClient type. +type AvailableResourceGroupDelegationsServer struct { + // NewListPager is the fake for method AvailableResourceGroupDelegationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, resourceGroupName string, options *armnetwork.AvailableResourceGroupDelegationsClientListOptions) (resp azfake.PagerResponder[armnetwork.AvailableResourceGroupDelegationsClientListResponse]) +} + +// NewAvailableResourceGroupDelegationsServerTransport creates a new instance of AvailableResourceGroupDelegationsServerTransport with the provided implementation. +// The returned AvailableResourceGroupDelegationsServerTransport instance is connected to an instance of armnetwork.AvailableResourceGroupDelegationsClient by way of the +// undefined.Transporter field. +func NewAvailableResourceGroupDelegationsServerTransport(srv *AvailableResourceGroupDelegationsServer) *AvailableResourceGroupDelegationsServerTransport { + return &AvailableResourceGroupDelegationsServerTransport{srv: srv} +} + +// AvailableResourceGroupDelegationsServerTransport connects instances of armnetwork.AvailableResourceGroupDelegationsClient to instances of AvailableResourceGroupDelegationsServer. +// Don't use this type directly, use NewAvailableResourceGroupDelegationsServerTransport instead. +type AvailableResourceGroupDelegationsServerTransport struct { + srv *AvailableResourceGroupDelegationsServer + newListPager *azfake.PagerResponder[armnetwork.AvailableResourceGroupDelegationsClientListResponse] +} + +// Do implements the policy.Transporter interface for AvailableResourceGroupDelegationsServerTransport. +func (a *AvailableResourceGroupDelegationsServerTransport) 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 "AvailableResourceGroupDelegationsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AvailableResourceGroupDelegationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availableDelegations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(locationUnescaped, resourceGroupNameUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AvailableResourceGroupDelegationsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/availableservicealiases_server.go b/sdk/resourcemanager/network/armnetwork/fake/availableservicealiases_server.go new file mode 100644 index 000000000000..07f28072c656 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/availableservicealiases_server.go @@ -0,0 +1,147 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// AvailableServiceAliasesServer is a fake server for instances of the armnetwork.AvailableServiceAliasesClient type. +type AvailableServiceAliasesServer struct { + // NewListPager is the fake for method AvailableServiceAliasesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armnetwork.AvailableServiceAliasesClientListOptions) (resp azfake.PagerResponder[armnetwork.AvailableServiceAliasesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method AvailableServiceAliasesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, location string, options *armnetwork.AvailableServiceAliasesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.AvailableServiceAliasesClientListByResourceGroupResponse]) +} + +// NewAvailableServiceAliasesServerTransport creates a new instance of AvailableServiceAliasesServerTransport with the provided implementation. +// The returned AvailableServiceAliasesServerTransport instance is connected to an instance of armnetwork.AvailableServiceAliasesClient by way of the +// undefined.Transporter field. +func NewAvailableServiceAliasesServerTransport(srv *AvailableServiceAliasesServer) *AvailableServiceAliasesServerTransport { + return &AvailableServiceAliasesServerTransport{srv: srv} +} + +// AvailableServiceAliasesServerTransport connects instances of armnetwork.AvailableServiceAliasesClient to instances of AvailableServiceAliasesServer. +// Don't use this type directly, use NewAvailableServiceAliasesServerTransport instead. +type AvailableServiceAliasesServerTransport struct { + srv *AvailableServiceAliasesServer + newListPager *azfake.PagerResponder[armnetwork.AvailableServiceAliasesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.AvailableServiceAliasesClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for AvailableServiceAliasesServerTransport. +func (a *AvailableServiceAliasesServerTransport) 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 "AvailableServiceAliasesClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "AvailableServiceAliasesClient.NewListByResourceGroupPager": + resp, err = a.dispatchNewListByResourceGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AvailableServiceAliasesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if a.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availableServiceAliases` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListPager(locationUnescaped, nil) + a.newListPager = &resp + server.PagerResponderInjectNextLinks(a.newListPager, req, func(page *armnetwork.AvailableServiceAliasesClientListResponse, 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 *AvailableServiceAliasesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if a.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availableServiceAliases` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := a.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, locationUnescaped, nil) + a.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(a.newListByResourceGroupPager, req, func(page *armnetwork.AvailableServiceAliasesClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListByResourceGroupPager) { + a.newListByResourceGroupPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/azurefirewallfqdntags_server.go b/sdk/resourcemanager/network/armnetwork/fake/azurefirewallfqdntags_server.go new file mode 100644 index 000000000000..491c891f6960 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/azurefirewallfqdntags_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/network/armnetwork/v3" + "net/http" + "regexp" +) + +// AzureFirewallFqdnTagsServer is a fake server for instances of the armnetwork.AzureFirewallFqdnTagsClient type. +type AzureFirewallFqdnTagsServer struct { + // NewListAllPager is the fake for method AzureFirewallFqdnTagsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.AzureFirewallFqdnTagsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.AzureFirewallFqdnTagsClientListAllResponse]) +} + +// NewAzureFirewallFqdnTagsServerTransport creates a new instance of AzureFirewallFqdnTagsServerTransport with the provided implementation. +// The returned AzureFirewallFqdnTagsServerTransport instance is connected to an instance of armnetwork.AzureFirewallFqdnTagsClient by way of the +// undefined.Transporter field. +func NewAzureFirewallFqdnTagsServerTransport(srv *AzureFirewallFqdnTagsServer) *AzureFirewallFqdnTagsServerTransport { + return &AzureFirewallFqdnTagsServerTransport{srv: srv} +} + +// AzureFirewallFqdnTagsServerTransport connects instances of armnetwork.AzureFirewallFqdnTagsClient to instances of AzureFirewallFqdnTagsServer. +// Don't use this type directly, use NewAzureFirewallFqdnTagsServerTransport instead. +type AzureFirewallFqdnTagsServerTransport struct { + srv *AzureFirewallFqdnTagsServer + newListAllPager *azfake.PagerResponder[armnetwork.AzureFirewallFqdnTagsClientListAllResponse] +} + +// Do implements the policy.Transporter interface for AzureFirewallFqdnTagsServerTransport. +func (a *AzureFirewallFqdnTagsServerTransport) 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 "AzureFirewallFqdnTagsClient.NewListAllPager": + resp, err = a.dispatchNewListAllPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AzureFirewallFqdnTagsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if a.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewallFqdnTags` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := a.srv.NewListAllPager(nil) + a.newListAllPager = &resp + server.PagerResponderInjectNextLinks(a.newListAllPager, req, func(page *armnetwork.AzureFirewallFqdnTagsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListAllPager) { + a.newListAllPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/azurefirewalls_server.go b/sdk/resourcemanager/network/armnetwork/fake/azurefirewalls_server.go new file mode 100644 index 000000000000..2431a483e92a --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/azurefirewalls_server.go @@ -0,0 +1,431 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// AzureFirewallsServer is a fake server for instances of the armnetwork.AzureFirewallsClient type. +type AzureFirewallsServer struct { + // BeginCreateOrUpdate is the fake for method AzureFirewallsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, azureFirewallName string, parameters armnetwork.AzureFirewall, options *armnetwork.AzureFirewallsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.AzureFirewallsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method AzureFirewallsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, azureFirewallName string, options *armnetwork.AzureFirewallsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.AzureFirewallsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AzureFirewallsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, azureFirewallName string, options *armnetwork.AzureFirewallsClientGetOptions) (resp azfake.Responder[armnetwork.AzureFirewallsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AzureFirewallsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.AzureFirewallsClientListOptions) (resp azfake.PagerResponder[armnetwork.AzureFirewallsClientListResponse]) + + // NewListAllPager is the fake for method AzureFirewallsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.AzureFirewallsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.AzureFirewallsClientListAllResponse]) + + // BeginListLearnedPrefixes is the fake for method AzureFirewallsClient.BeginListLearnedPrefixes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListLearnedPrefixes func(ctx context.Context, resourceGroupName string, azureFirewallName string, options *armnetwork.AzureFirewallsClientBeginListLearnedPrefixesOptions) (resp azfake.PollerResponder[armnetwork.AzureFirewallsClientListLearnedPrefixesResponse], errResp azfake.ErrorResponder) + + // BeginPacketCapture is the fake for method AzureFirewallsClient.BeginPacketCapture + // HTTP status codes to indicate success: http.StatusAccepted + BeginPacketCapture func(ctx context.Context, resourceGroupName string, azureFirewallName string, parameters armnetwork.FirewallPacketCaptureParameters, options *armnetwork.AzureFirewallsClientBeginPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.AzureFirewallsClientPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginUpdateTags is the fake for method AzureFirewallsClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, azureFirewallName string, parameters armnetwork.TagsObject, options *armnetwork.AzureFirewallsClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.AzureFirewallsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewAzureFirewallsServerTransport creates a new instance of AzureFirewallsServerTransport with the provided implementation. +// The returned AzureFirewallsServerTransport instance is connected to an instance of armnetwork.AzureFirewallsClient by way of the +// undefined.Transporter field. +func NewAzureFirewallsServerTransport(srv *AzureFirewallsServer) *AzureFirewallsServerTransport { + return &AzureFirewallsServerTransport{srv: srv} +} + +// AzureFirewallsServerTransport connects instances of armnetwork.AzureFirewallsClient to instances of AzureFirewallsServer. +// Don't use this type directly, use NewAzureFirewallsServerTransport instead. +type AzureFirewallsServerTransport struct { + srv *AzureFirewallsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.AzureFirewallsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.AzureFirewallsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.AzureFirewallsClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.AzureFirewallsClientListAllResponse] + beginListLearnedPrefixes *azfake.PollerResponder[armnetwork.AzureFirewallsClientListLearnedPrefixesResponse] + beginPacketCapture *azfake.PollerResponder[armnetwork.AzureFirewallsClientPacketCaptureResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.AzureFirewallsClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for AzureFirewallsServerTransport. +func (a *AzureFirewallsServerTransport) 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 "AzureFirewallsClient.BeginCreateOrUpdate": + resp, err = a.dispatchBeginCreateOrUpdate(req) + case "AzureFirewallsClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "AzureFirewallsClient.Get": + resp, err = a.dispatchGet(req) + case "AzureFirewallsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "AzureFirewallsClient.NewListAllPager": + resp, err = a.dispatchNewListAllPager(req) + case "AzureFirewallsClient.BeginListLearnedPrefixes": + resp, err = a.dispatchBeginListLearnedPrefixes(req) + case "AzureFirewallsClient.BeginPacketCapture": + resp, err = a.dispatchBeginPacketCapture(req) + case "AzureFirewallsClient.BeginUpdateTags": + resp, err = a.dispatchBeginUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if a.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewalls/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.AzureFirewall](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + azureFirewallNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("azureFirewallName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, azureFirewallNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginCreateOrUpdate) { + a.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if a.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewalls/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + azureFirewallNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("azureFirewallName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, azureFirewallNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(a.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(a.beginDelete) { + a.beginDelete = nil + } + + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + 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.Network/azureFirewalls/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + azureFirewallNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("azureFirewallName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameUnescaped, azureFirewallNameUnescaped, 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).AzureFirewall, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + 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.Network/azureFirewalls` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.AzureFirewallsClientListResponse, 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 *AzureFirewallsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if a.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewalls` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := a.srv.NewListAllPager(nil) + a.newListAllPager = &resp + server.PagerResponderInjectNextLinks(a.newListAllPager, req, func(page *armnetwork.AzureFirewallsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(a.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(a.newListAllPager) { + a.newListAllPager = nil + } + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchBeginListLearnedPrefixes(req *http.Request) (*http.Response, error) { + if a.srv.BeginListLearnedPrefixes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListLearnedPrefixes not implemented")} + } + if a.beginListLearnedPrefixes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewalls/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/learnedIPPrefixes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + azureFirewallNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("azureFirewallName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginListLearnedPrefixes(req.Context(), resourceGroupNameUnescaped, azureFirewallNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginListLearnedPrefixes = &respr + } + + resp, err := server.PollerResponderNext(a.beginListLearnedPrefixes, 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(a.beginListLearnedPrefixes) { + a.beginListLearnedPrefixes = nil + } + + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchBeginPacketCapture(req *http.Request) (*http.Response, error) { + if a.srv.BeginPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginPacketCapture not implemented")} + } + if a.beginPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewalls/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.FirewallPacketCaptureParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + azureFirewallNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("azureFirewallName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginPacketCapture(req.Context(), resourceGroupNameUnescaped, azureFirewallNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(a.beginPacketCapture, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(a.beginPacketCapture) { + a.beginPacketCapture = nil + } + + return resp, nil +} + +func (a *AzureFirewallsServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if a.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if a.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureFirewalls/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + azureFirewallNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("azureFirewallName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, azureFirewallNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + a.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(a.beginUpdateTags, 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(a.beginUpdateTags) { + a.beginUpdateTags = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/bastionhosts_server.go b/sdk/resourcemanager/network/armnetwork/fake/bastionhosts_server.go new file mode 100644 index 000000000000..15970b25036a --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/bastionhosts_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// BastionHostsServer is a fake server for instances of the armnetwork.BastionHostsClient type. +type BastionHostsServer struct { + // BeginCreateOrUpdate is the fake for method BastionHostsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, bastionHostName string, parameters armnetwork.BastionHost, options *armnetwork.BastionHostsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.BastionHostsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method BastionHostsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, bastionHostName string, options *armnetwork.BastionHostsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.BastionHostsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method BastionHostsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, bastionHostName string, options *armnetwork.BastionHostsClientGetOptions) (resp azfake.Responder[armnetwork.BastionHostsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method BastionHostsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.BastionHostsClientListOptions) (resp azfake.PagerResponder[armnetwork.BastionHostsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method BastionHostsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.BastionHostsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.BastionHostsClientListByResourceGroupResponse]) + + // BeginUpdateTags is the fake for method BastionHostsClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, bastionHostName string, parameters armnetwork.TagsObject, options *armnetwork.BastionHostsClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.BastionHostsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewBastionHostsServerTransport creates a new instance of BastionHostsServerTransport with the provided implementation. +// The returned BastionHostsServerTransport instance is connected to an instance of armnetwork.BastionHostsClient by way of the +// undefined.Transporter field. +func NewBastionHostsServerTransport(srv *BastionHostsServer) *BastionHostsServerTransport { + return &BastionHostsServerTransport{srv: srv} +} + +// BastionHostsServerTransport connects instances of armnetwork.BastionHostsClient to instances of BastionHostsServer. +// Don't use this type directly, use NewBastionHostsServerTransport instead. +type BastionHostsServerTransport struct { + srv *BastionHostsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.BastionHostsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.BastionHostsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.BastionHostsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.BastionHostsClientListByResourceGroupResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.BastionHostsClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for BastionHostsServerTransport. +func (b *BastionHostsServerTransport) 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 "BastionHostsClient.BeginCreateOrUpdate": + resp, err = b.dispatchBeginCreateOrUpdate(req) + case "BastionHostsClient.BeginDelete": + resp, err = b.dispatchBeginDelete(req) + case "BastionHostsClient.Get": + resp, err = b.dispatchGet(req) + case "BastionHostsClient.NewListPager": + resp, err = b.dispatchNewListPager(req) + case "BastionHostsClient.NewListByResourceGroupPager": + resp, err = b.dispatchNewListByResourceGroupPager(req) + case "BastionHostsClient.BeginUpdateTags": + resp, err = b.dispatchBeginUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (b *BastionHostsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if b.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if b.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.BastionHost](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + b.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(b.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(b.beginCreateOrUpdate) { + b.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (b *BastionHostsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if b.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if b.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + b.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(b.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(b.beginDelete) { + b.beginDelete = nil + } + + return resp, nil +} + +func (b *BastionHostsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if b.srv.Get == nil { + 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.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.Get(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, 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).BastionHost, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (b *BastionHostsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if b.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if b.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := b.srv.NewListPager(nil) + b.newListPager = &resp + server.PagerResponderInjectNextLinks(b.newListPager, req, func(page *armnetwork.BastionHostsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(b.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(b.newListPager) { + b.newListPager = nil + } + return resp, nil +} + +func (b *BastionHostsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if b.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if b.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := b.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + b.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(b.newListByResourceGroupPager, req, func(page *armnetwork.BastionHostsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(b.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(b.newListByResourceGroupPager) { + b.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (b *BastionHostsServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if b.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if b.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + b.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(b.beginUpdateTags, 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(b.beginUpdateTags) { + b.beginUpdateTags = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/bgpservicecommunities_server.go b/sdk/resourcemanager/network/armnetwork/fake/bgpservicecommunities_server.go new file mode 100644 index 000000000000..58b60768fa54 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/bgpservicecommunities_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/network/armnetwork/v3" + "net/http" + "regexp" +) + +// BgpServiceCommunitiesServer is a fake server for instances of the armnetwork.BgpServiceCommunitiesClient type. +type BgpServiceCommunitiesServer struct { + // NewListPager is the fake for method BgpServiceCommunitiesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.BgpServiceCommunitiesClientListOptions) (resp azfake.PagerResponder[armnetwork.BgpServiceCommunitiesClientListResponse]) +} + +// NewBgpServiceCommunitiesServerTransport creates a new instance of BgpServiceCommunitiesServerTransport with the provided implementation. +// The returned BgpServiceCommunitiesServerTransport instance is connected to an instance of armnetwork.BgpServiceCommunitiesClient by way of the +// undefined.Transporter field. +func NewBgpServiceCommunitiesServerTransport(srv *BgpServiceCommunitiesServer) *BgpServiceCommunitiesServerTransport { + return &BgpServiceCommunitiesServerTransport{srv: srv} +} + +// BgpServiceCommunitiesServerTransport connects instances of armnetwork.BgpServiceCommunitiesClient to instances of BgpServiceCommunitiesServer. +// Don't use this type directly, use NewBgpServiceCommunitiesServerTransport instead. +type BgpServiceCommunitiesServerTransport struct { + srv *BgpServiceCommunitiesServer + newListPager *azfake.PagerResponder[armnetwork.BgpServiceCommunitiesClientListResponse] +} + +// Do implements the policy.Transporter interface for BgpServiceCommunitiesServerTransport. +func (b *BgpServiceCommunitiesServerTransport) 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 "BgpServiceCommunitiesClient.NewListPager": + resp, err = b.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (b *BgpServiceCommunitiesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if b.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if b.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bgpServiceCommunities` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := b.srv.NewListPager(nil) + b.newListPager = &resp + server.PagerResponderInjectNextLinks(b.newListPager, req, func(page *armnetwork.BgpServiceCommunitiesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(b.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(b.newListPager) { + b.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/configurationpolicygroups_server.go b/sdk/resourcemanager/network/armnetwork/fake/configurationpolicygroups_server.go new file mode 100644 index 000000000000..546276d6349c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/configurationpolicygroups_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ConfigurationPolicyGroupsServer is a fake server for instances of the armnetwork.ConfigurationPolicyGroupsClient type. +type ConfigurationPolicyGroupsServer struct { + // BeginCreateOrUpdate is the fake for method ConfigurationPolicyGroupsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, vpnServerConfigurationPolicyGroupParameters armnetwork.VPNServerConfigurationPolicyGroup, options *armnetwork.ConfigurationPolicyGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ConfigurationPolicyGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ConfigurationPolicyGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, options *armnetwork.ConfigurationPolicyGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ConfigurationPolicyGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ConfigurationPolicyGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, options *armnetwork.ConfigurationPolicyGroupsClientGetOptions) (resp azfake.Responder[armnetwork.ConfigurationPolicyGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByVPNServerConfigurationPager is the fake for method ConfigurationPolicyGroupsClient.NewListByVPNServerConfigurationPager + // HTTP status codes to indicate success: http.StatusOK + NewListByVPNServerConfigurationPager func(resourceGroupName string, vpnServerConfigurationName string, options *armnetwork.ConfigurationPolicyGroupsClientListByVPNServerConfigurationOptions) (resp azfake.PagerResponder[armnetwork.ConfigurationPolicyGroupsClientListByVPNServerConfigurationResponse]) +} + +// NewConfigurationPolicyGroupsServerTransport creates a new instance of ConfigurationPolicyGroupsServerTransport with the provided implementation. +// The returned ConfigurationPolicyGroupsServerTransport instance is connected to an instance of armnetwork.ConfigurationPolicyGroupsClient by way of the +// undefined.Transporter field. +func NewConfigurationPolicyGroupsServerTransport(srv *ConfigurationPolicyGroupsServer) *ConfigurationPolicyGroupsServerTransport { + return &ConfigurationPolicyGroupsServerTransport{srv: srv} +} + +// ConfigurationPolicyGroupsServerTransport connects instances of armnetwork.ConfigurationPolicyGroupsClient to instances of ConfigurationPolicyGroupsServer. +// Don't use this type directly, use NewConfigurationPolicyGroupsServerTransport instead. +type ConfigurationPolicyGroupsServerTransport struct { + srv *ConfigurationPolicyGroupsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ConfigurationPolicyGroupsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ConfigurationPolicyGroupsClientDeleteResponse] + newListByVPNServerConfigurationPager *azfake.PagerResponder[armnetwork.ConfigurationPolicyGroupsClientListByVPNServerConfigurationResponse] +} + +// Do implements the policy.Transporter interface for ConfigurationPolicyGroupsServerTransport. +func (c *ConfigurationPolicyGroupsServerTransport) 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 "ConfigurationPolicyGroupsClient.BeginCreateOrUpdate": + resp, err = c.dispatchBeginCreateOrUpdate(req) + case "ConfigurationPolicyGroupsClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "ConfigurationPolicyGroupsClient.Get": + resp, err = c.dispatchGet(req) + case "ConfigurationPolicyGroupsClient.NewListByVPNServerConfigurationPager": + resp, err = c.dispatchNewListByVPNServerConfigurationPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *ConfigurationPolicyGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginCreateOrUpdate == nil { + 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.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/configurationPolicyGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNServerConfigurationPolicyGroup](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + configurationPolicyGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationPolicyGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, configurationPolicyGroupNameUnescaped, 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 *ConfigurationPolicyGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + 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.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/configurationPolicyGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + configurationPolicyGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationPolicyGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, configurationPolicyGroupNameUnescaped, 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 *ConfigurationPolicyGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + 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.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/configurationPolicyGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + configurationPolicyGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationPolicyGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, configurationPolicyGroupNameUnescaped, 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).VPNServerConfigurationPolicyGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *ConfigurationPolicyGroupsServerTransport) dispatchNewListByVPNServerConfigurationPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListByVPNServerConfigurationPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByVPNServerConfigurationPager not implemented")} + } + if c.newListByVPNServerConfigurationPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/configurationPolicyGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListByVPNServerConfigurationPager(resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, nil) + c.newListByVPNServerConfigurationPager = &resp + server.PagerResponderInjectNextLinks(c.newListByVPNServerConfigurationPager, req, func(page *armnetwork.ConfigurationPolicyGroupsClientListByVPNServerConfigurationResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(c.newListByVPNServerConfigurationPager, 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.newListByVPNServerConfigurationPager) { + c.newListByVPNServerConfigurationPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/connectionmonitors_server.go b/sdk/resourcemanager/network/armnetwork/fake/connectionmonitors_server.go new file mode 100644 index 000000000000..e5c769b2e03e --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/connectionmonitors_server.go @@ -0,0 +1,469 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ConnectionMonitorsServer is a fake server for instances of the armnetwork.ConnectionMonitorsClient type. +type ConnectionMonitorsServer struct { + // BeginCreateOrUpdate is the fake for method ConnectionMonitorsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters armnetwork.ConnectionMonitor, options *armnetwork.ConnectionMonitorsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ConnectionMonitorsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ConnectionMonitorsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *armnetwork.ConnectionMonitorsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ConnectionMonitorsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ConnectionMonitorsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *armnetwork.ConnectionMonitorsClientGetOptions) (resp azfake.Responder[armnetwork.ConnectionMonitorsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ConnectionMonitorsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkWatcherName string, options *armnetwork.ConnectionMonitorsClientListOptions) (resp azfake.PagerResponder[armnetwork.ConnectionMonitorsClientListResponse]) + + // BeginQuery is the fake for method ConnectionMonitorsClient.BeginQuery + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginQuery func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *armnetwork.ConnectionMonitorsClientBeginQueryOptions) (resp azfake.PollerResponder[armnetwork.ConnectionMonitorsClientQueryResponse], errResp azfake.ErrorResponder) + + // BeginStart is the fake for method ConnectionMonitorsClient.BeginStart + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStart func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *armnetwork.ConnectionMonitorsClientBeginStartOptions) (resp azfake.PollerResponder[armnetwork.ConnectionMonitorsClientStartResponse], errResp azfake.ErrorResponder) + + // BeginStop is the fake for method ConnectionMonitorsClient.BeginStop + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStop func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, options *armnetwork.ConnectionMonitorsClientBeginStopOptions) (resp azfake.PollerResponder[armnetwork.ConnectionMonitorsClientStopResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method ConnectionMonitorsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters armnetwork.TagsObject, options *armnetwork.ConnectionMonitorsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ConnectionMonitorsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewConnectionMonitorsServerTransport creates a new instance of ConnectionMonitorsServerTransport with the provided implementation. +// The returned ConnectionMonitorsServerTransport instance is connected to an instance of armnetwork.ConnectionMonitorsClient by way of the +// undefined.Transporter field. +func NewConnectionMonitorsServerTransport(srv *ConnectionMonitorsServer) *ConnectionMonitorsServerTransport { + return &ConnectionMonitorsServerTransport{srv: srv} +} + +// ConnectionMonitorsServerTransport connects instances of armnetwork.ConnectionMonitorsClient to instances of ConnectionMonitorsServer. +// Don't use this type directly, use NewConnectionMonitorsServerTransport instead. +type ConnectionMonitorsServerTransport struct { + srv *ConnectionMonitorsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ConnectionMonitorsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ConnectionMonitorsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ConnectionMonitorsClientListResponse] + beginQuery *azfake.PollerResponder[armnetwork.ConnectionMonitorsClientQueryResponse] + beginStart *azfake.PollerResponder[armnetwork.ConnectionMonitorsClientStartResponse] + beginStop *azfake.PollerResponder[armnetwork.ConnectionMonitorsClientStopResponse] +} + +// Do implements the policy.Transporter interface for ConnectionMonitorsServerTransport. +func (c *ConnectionMonitorsServerTransport) 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 "ConnectionMonitorsClient.BeginCreateOrUpdate": + resp, err = c.dispatchBeginCreateOrUpdate(req) + case "ConnectionMonitorsClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "ConnectionMonitorsClient.Get": + resp, err = c.dispatchGet(req) + case "ConnectionMonitorsClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + case "ConnectionMonitorsClient.BeginQuery": + resp, err = c.dispatchBeginQuery(req) + case "ConnectionMonitorsClient.BeginStart": + resp, err = c.dispatchBeginStart(req) + case "ConnectionMonitorsClient.BeginStop": + resp, err = c.dispatchBeginStop(req) + case "ConnectionMonitorsClient.UpdateTags": + resp, err = c.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *ConnectionMonitorsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginCreateOrUpdate == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.ConnectionMonitor](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + migrateUnescaped, err := url.QueryUnescape(qp.Get("migrate")) + if err != nil { + return nil, err + } + migrateParam := getOptional(migrateUnescaped) + var options *armnetwork.ConnectionMonitorsClientBeginCreateOrUpdateOptions + if migrateParam != nil { + options = &armnetwork.ConnectionMonitorsClientBeginCreateOrUpdateOptions{ + Migrate: migrateParam, + } + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, body, options) + 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 *ConnectionMonitorsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, 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.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(c.beginDelete) { + c.beginDelete = nil + } + + return resp, nil +} + +func (c *ConnectionMonitorsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, 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).ConnectionMonitorResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *ConnectionMonitorsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + resp := c.srv.NewListPager(resourceGroupNameUnescaped, networkWatcherNameUnescaped, nil) + c.newListPager = &resp + } + 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 *ConnectionMonitorsServerTransport) dispatchBeginQuery(req *http.Request) (*http.Response, error) { + if c.srv.BeginQuery == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginQuery not implemented")} + } + if c.beginQuery == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/query` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginQuery(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginQuery = &respr + } + + resp, err := server.PollerResponderNext(c.beginQuery, 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.beginQuery) { + c.beginQuery = nil + } + + return resp, nil +} + +func (c *ConnectionMonitorsServerTransport) dispatchBeginStart(req *http.Request) (*http.Response, error) { + if c.srv.BeginStart == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/start` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginStart(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, 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 *ConnectionMonitorsServerTransport) dispatchBeginStop(req *http.Request) (*http.Response, error) { + if c.srv.BeginStop == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStop not implemented")} + } + if c.beginStop == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stop` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginStop(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + c.beginStop = &respr + } + + resp, err := server.PollerResponderNext(c.beginStop, 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.beginStop) { + c.beginStop = nil + } + + return resp, nil +} + +func (c *ConnectionMonitorsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if c.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectionMonitors/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + connectionMonitorNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionMonitorName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, connectionMonitorNameUnescaped, 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).ConnectionMonitorResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/connectivityconfigurations_server.go b/sdk/resourcemanager/network/armnetwork/fake/connectivityconfigurations_server.go new file mode 100644 index 000000000000..d4eb7746c2da --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/connectivityconfigurations_server.go @@ -0,0 +1,292 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ConnectivityConfigurationsServer is a fake server for instances of the armnetwork.ConnectivityConfigurationsClient type. +type ConnectivityConfigurationsServer struct { + // CreateOrUpdate is the fake for method ConnectivityConfigurationsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, connectivityConfiguration armnetwork.ConnectivityConfiguration, options *armnetwork.ConnectivityConfigurationsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.ConnectivityConfigurationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ConnectivityConfigurationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *armnetwork.ConnectivityConfigurationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ConnectivityConfigurationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ConnectivityConfigurationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *armnetwork.ConnectivityConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.ConnectivityConfigurationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ConnectivityConfigurationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, options *armnetwork.ConnectivityConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.ConnectivityConfigurationsClientListResponse]) +} + +// NewConnectivityConfigurationsServerTransport creates a new instance of ConnectivityConfigurationsServerTransport with the provided implementation. +// The returned ConnectivityConfigurationsServerTransport instance is connected to an instance of armnetwork.ConnectivityConfigurationsClient by way of the +// undefined.Transporter field. +func NewConnectivityConfigurationsServerTransport(srv *ConnectivityConfigurationsServer) *ConnectivityConfigurationsServerTransport { + return &ConnectivityConfigurationsServerTransport{srv: srv} +} + +// ConnectivityConfigurationsServerTransport connects instances of armnetwork.ConnectivityConfigurationsClient to instances of ConnectivityConfigurationsServer. +// Don't use this type directly, use NewConnectivityConfigurationsServerTransport instead. +type ConnectivityConfigurationsServerTransport struct { + srv *ConnectivityConfigurationsServer + beginDelete *azfake.PollerResponder[armnetwork.ConnectivityConfigurationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ConnectivityConfigurationsClientListResponse] +} + +// Do implements the policy.Transporter interface for ConnectivityConfigurationsServerTransport. +func (c *ConnectivityConfigurationsServerTransport) 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 "ConnectivityConfigurationsClient.CreateOrUpdate": + resp, err = c.dispatchCreateOrUpdate(req) + case "ConnectivityConfigurationsClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "ConnectivityConfigurationsClient.Get": + resp, err = c.dispatchGet(req) + case "ConnectivityConfigurationsClient.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 *ConnectivityConfigurationsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectivityConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ConnectivityConfiguration](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, 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).ConnectivityConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *ConnectivityConfigurationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectivityConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + forceUnescaped, err := url.QueryUnescape(qp.Get("force")) + if err != nil { + return nil, err + } + forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armnetwork.ConnectivityConfigurationsClientBeginDeleteOptions + if forceParam != nil { + options = &armnetwork.ConnectivityConfigurationsClientBeginDeleteOptions{ + Force: forceParam, + } + } + respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, options) + 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 *ConnectivityConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectivityConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, 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).ConnectivityConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *ConnectivityConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectivityConfigurations` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.ConnectivityConfigurationsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.ConnectivityConfigurationsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := c.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, options) + c.newListPager = &resp + server.PagerResponderInjectNextLinks(c.newListPager, req, func(page *armnetwork.ConnectivityConfigurationsClientListResponse, 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/network/armnetwork/fake/customipprefixes_server.go b/sdk/resourcemanager/network/armnetwork/fake/customipprefixes_server.go new file mode 100644 index 000000000000..ddb1da259cfe --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/customipprefixes_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// CustomIPPrefixesServer is a fake server for instances of the armnetwork.CustomIPPrefixesClient type. +type CustomIPPrefixesServer struct { + // BeginCreateOrUpdate is the fake for method CustomIPPrefixesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, customIPPrefixName string, parameters armnetwork.CustomIPPrefix, options *armnetwork.CustomIPPrefixesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.CustomIPPrefixesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method CustomIPPrefixesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, customIPPrefixName string, options *armnetwork.CustomIPPrefixesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.CustomIPPrefixesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method CustomIPPrefixesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, customIPPrefixName string, options *armnetwork.CustomIPPrefixesClientGetOptions) (resp azfake.Responder[armnetwork.CustomIPPrefixesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method CustomIPPrefixesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.CustomIPPrefixesClientListOptions) (resp azfake.PagerResponder[armnetwork.CustomIPPrefixesClientListResponse]) + + // NewListAllPager is the fake for method CustomIPPrefixesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.CustomIPPrefixesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.CustomIPPrefixesClientListAllResponse]) + + // UpdateTags is the fake for method CustomIPPrefixesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, customIPPrefixName string, parameters armnetwork.TagsObject, options *armnetwork.CustomIPPrefixesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.CustomIPPrefixesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewCustomIPPrefixesServerTransport creates a new instance of CustomIPPrefixesServerTransport with the provided implementation. +// The returned CustomIPPrefixesServerTransport instance is connected to an instance of armnetwork.CustomIPPrefixesClient by way of the +// undefined.Transporter field. +func NewCustomIPPrefixesServerTransport(srv *CustomIPPrefixesServer) *CustomIPPrefixesServerTransport { + return &CustomIPPrefixesServerTransport{srv: srv} +} + +// CustomIPPrefixesServerTransport connects instances of armnetwork.CustomIPPrefixesClient to instances of CustomIPPrefixesServer. +// Don't use this type directly, use NewCustomIPPrefixesServerTransport instead. +type CustomIPPrefixesServerTransport struct { + srv *CustomIPPrefixesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.CustomIPPrefixesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.CustomIPPrefixesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.CustomIPPrefixesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.CustomIPPrefixesClientListAllResponse] +} + +// Do implements the policy.Transporter interface for CustomIPPrefixesServerTransport. +func (c *CustomIPPrefixesServerTransport) 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 "CustomIPPrefixesClient.BeginCreateOrUpdate": + resp, err = c.dispatchBeginCreateOrUpdate(req) + case "CustomIPPrefixesClient.BeginDelete": + resp, err = c.dispatchBeginDelete(req) + case "CustomIPPrefixesClient.Get": + resp, err = c.dispatchGet(req) + case "CustomIPPrefixesClient.NewListPager": + resp, err = c.dispatchNewListPager(req) + case "CustomIPPrefixesClient.NewListAllPager": + resp, err = c.dispatchNewListAllPager(req) + case "CustomIPPrefixesClient.UpdateTags": + resp, err = c.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (c *CustomIPPrefixesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if c.srv.BeginCreateOrUpdate == nil { + 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.Network/customIpPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.CustomIPPrefix](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + customIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("customIpPrefixName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, customIPPrefixNameUnescaped, 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 *CustomIPPrefixesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if c.srv.BeginDelete == nil { + 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.Network/customIpPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + customIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("customIpPrefixName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, customIPPrefixNameUnescaped, 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 *CustomIPPrefixesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if c.srv.Get == nil { + 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.Network/customIpPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + customIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("customIpPrefixName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.CustomIPPrefixesClientGetOptions + if expandParam != nil { + options = &armnetwork.CustomIPPrefixesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameUnescaped, customIPPrefixNameUnescaped, 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).CustomIPPrefix, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *CustomIPPrefixesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListPager == nil { + 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.Network/customIpPrefixes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.CustomIPPrefixesClientListResponse, 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 *CustomIPPrefixesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if c.srv.NewListAllPager == nil { + 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.Network/customIpPrefixes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.CustomIPPrefixesClientListAllResponse, 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 *CustomIPPrefixesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if c.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/customIpPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + customIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("customIpPrefixName")]) + if err != nil { + return nil, err + } + respr, errRespr := c.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, customIPPrefixNameUnescaped, 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).CustomIPPrefix, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/ddoscustompolicies_server.go b/sdk/resourcemanager/network/armnetwork/fake/ddoscustompolicies_server.go new file mode 100644 index 000000000000..0842f0a0768d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/ddoscustompolicies_server.go @@ -0,0 +1,243 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// DdosCustomPoliciesServer is a fake server for instances of the armnetwork.DdosCustomPoliciesClient type. +type DdosCustomPoliciesServer struct { + // BeginCreateOrUpdate is the fake for method DdosCustomPoliciesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters armnetwork.DdosCustomPolicy, options *armnetwork.DdosCustomPoliciesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DdosCustomPoliciesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, options *armnetwork.DdosCustomPoliciesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DdosCustomPoliciesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, options *armnetwork.DdosCustomPoliciesClientGetOptions) (resp azfake.Responder[armnetwork.DdosCustomPoliciesClientGetResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method DdosCustomPoliciesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters armnetwork.TagsObject, options *armnetwork.DdosCustomPoliciesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.DdosCustomPoliciesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewDdosCustomPoliciesServerTransport creates a new instance of DdosCustomPoliciesServerTransport with the provided implementation. +// The returned DdosCustomPoliciesServerTransport instance is connected to an instance of armnetwork.DdosCustomPoliciesClient by way of the +// undefined.Transporter field. +func NewDdosCustomPoliciesServerTransport(srv *DdosCustomPoliciesServer) *DdosCustomPoliciesServerTransport { + return &DdosCustomPoliciesServerTransport{srv: srv} +} + +// DdosCustomPoliciesServerTransport connects instances of armnetwork.DdosCustomPoliciesClient to instances of DdosCustomPoliciesServer. +// Don't use this type directly, use NewDdosCustomPoliciesServerTransport instead. +type DdosCustomPoliciesServerTransport struct { + srv *DdosCustomPoliciesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientDeleteResponse] +} + +// Do implements the policy.Transporter interface for DdosCustomPoliciesServerTransport. +func (d *DdosCustomPoliciesServerTransport) 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 "DdosCustomPoliciesClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DdosCustomPoliciesClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DdosCustomPoliciesClient.Get": + resp, err = d.dispatchGet(req) + case "DdosCustomPoliciesClient.UpdateTags": + resp, err = d.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DdosCustomPoliciesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdate == nil { + 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.Network/ddosCustomPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.DdosCustomPolicy](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosCustomPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, ddosCustomPolicyNameUnescaped, 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 *DdosCustomPoliciesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if d.srv.BeginDelete == nil { + 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.Network/ddosCustomPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosCustomPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, ddosCustomPolicyNameUnescaped, 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 *DdosCustomPoliciesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + 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.Network/ddosCustomPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosCustomPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, ddosCustomPolicyNameUnescaped, 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).DdosCustomPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DdosCustomPoliciesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if d.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ddosCustomPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosCustomPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, ddosCustomPolicyNameUnescaped, 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).DdosCustomPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/ddosprotectionplans_server.go b/sdk/resourcemanager/network/armnetwork/fake/ddosprotectionplans_server.go new file mode 100644 index 000000000000..856810d1225d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/ddosprotectionplans_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// DdosProtectionPlansServer is a fake server for instances of the armnetwork.DdosProtectionPlansClient type. +type DdosProtectionPlansServer struct { + // BeginCreateOrUpdate is the fake for method DdosProtectionPlansClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, parameters armnetwork.DdosProtectionPlan, options *armnetwork.DdosProtectionPlansClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.DdosProtectionPlansClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DdosProtectionPlansClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, options *armnetwork.DdosProtectionPlansClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.DdosProtectionPlansClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DdosProtectionPlansClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, options *armnetwork.DdosProtectionPlansClientGetOptions) (resp azfake.Responder[armnetwork.DdosProtectionPlansClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DdosProtectionPlansClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.DdosProtectionPlansClientListOptions) (resp azfake.PagerResponder[armnetwork.DdosProtectionPlansClientListResponse]) + + // NewListByResourceGroupPager is the fake for method DdosProtectionPlansClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.DdosProtectionPlansClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.DdosProtectionPlansClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method DdosProtectionPlansClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, ddosProtectionPlanName string, parameters armnetwork.TagsObject, options *armnetwork.DdosProtectionPlansClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.DdosProtectionPlansClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewDdosProtectionPlansServerTransport creates a new instance of DdosProtectionPlansServerTransport with the provided implementation. +// The returned DdosProtectionPlansServerTransport instance is connected to an instance of armnetwork.DdosProtectionPlansClient by way of the +// undefined.Transporter field. +func NewDdosProtectionPlansServerTransport(srv *DdosProtectionPlansServer) *DdosProtectionPlansServerTransport { + return &DdosProtectionPlansServerTransport{srv: srv} +} + +// DdosProtectionPlansServerTransport connects instances of armnetwork.DdosProtectionPlansClient to instances of DdosProtectionPlansServer. +// Don't use this type directly, use NewDdosProtectionPlansServerTransport instead. +type DdosProtectionPlansServerTransport struct { + srv *DdosProtectionPlansServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.DdosProtectionPlansClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.DdosProtectionPlansClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.DdosProtectionPlansClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.DdosProtectionPlansClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for DdosProtectionPlansServerTransport. +func (d *DdosProtectionPlansServerTransport) 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 "DdosProtectionPlansClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DdosProtectionPlansClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DdosProtectionPlansClient.Get": + resp, err = d.dispatchGet(req) + case "DdosProtectionPlansClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DdosProtectionPlansClient.NewListByResourceGroupPager": + resp, err = d.dispatchNewListByResourceGroupPager(req) + case "DdosProtectionPlansClient.UpdateTags": + resp, err = d.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DdosProtectionPlansServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdate == nil { + 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.Network/ddosProtectionPlans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.DdosProtectionPlan](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosProtectionPlanNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosProtectionPlanName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, ddosProtectionPlanNameUnescaped, 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 *DdosProtectionPlansServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if d.srv.BeginDelete == nil { + 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.Network/ddosProtectionPlans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosProtectionPlanNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosProtectionPlanName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, ddosProtectionPlanNameUnescaped, 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 *DdosProtectionPlansServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + 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.Network/ddosProtectionPlans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosProtectionPlanNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosProtectionPlanName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, ddosProtectionPlanNameUnescaped, 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).DdosProtectionPlan, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DdosProtectionPlansServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPager == nil { + 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.Network/ddosProtectionPlans` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.DdosProtectionPlansClientListResponse, 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 *DdosProtectionPlansServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListByResourceGroupPager == nil { + 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.Network/ddosProtectionPlans` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.DdosProtectionPlansClientListByResourceGroupResponse, 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 *DdosProtectionPlansServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if d.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ddosProtectionPlans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ddosProtectionPlanNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ddosProtectionPlanName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, ddosProtectionPlanNameUnescaped, 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).DdosProtectionPlan, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/defaultsecurityrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/defaultsecurityrules_server.go new file mode 100644 index 000000000000..a2b8c77fa181 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/defaultsecurityrules_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// DefaultSecurityRulesServer is a fake server for instances of the armnetwork.DefaultSecurityRulesClient type. +type DefaultSecurityRulesServer struct { + // Get is the fake for method DefaultSecurityRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, defaultSecurityRuleName string, options *armnetwork.DefaultSecurityRulesClientGetOptions) (resp azfake.Responder[armnetwork.DefaultSecurityRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DefaultSecurityRulesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkSecurityGroupName string, options *armnetwork.DefaultSecurityRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.DefaultSecurityRulesClientListResponse]) +} + +// NewDefaultSecurityRulesServerTransport creates a new instance of DefaultSecurityRulesServerTransport with the provided implementation. +// The returned DefaultSecurityRulesServerTransport instance is connected to an instance of armnetwork.DefaultSecurityRulesClient by way of the +// undefined.Transporter field. +func NewDefaultSecurityRulesServerTransport(srv *DefaultSecurityRulesServer) *DefaultSecurityRulesServerTransport { + return &DefaultSecurityRulesServerTransport{srv: srv} +} + +// DefaultSecurityRulesServerTransport connects instances of armnetwork.DefaultSecurityRulesClient to instances of DefaultSecurityRulesServer. +// Don't use this type directly, use NewDefaultSecurityRulesServerTransport instead. +type DefaultSecurityRulesServerTransport struct { + srv *DefaultSecurityRulesServer + newListPager *azfake.PagerResponder[armnetwork.DefaultSecurityRulesClientListResponse] +} + +// Do implements the policy.Transporter interface for DefaultSecurityRulesServerTransport. +func (d *DefaultSecurityRulesServerTransport) 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 "DefaultSecurityRulesClient.Get": + resp, err = d.dispatchGet(req) + case "DefaultSecurityRulesClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DefaultSecurityRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/defaultSecurityRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + defaultSecurityRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("defaultSecurityRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, defaultSecurityRuleNameUnescaped, 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).SecurityRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefaultSecurityRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if d.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/defaultSecurityRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListPager(resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, nil) + d.newListPager = &resp + server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armnetwork.DefaultSecurityRulesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/dscpconfiguration_server.go b/sdk/resourcemanager/network/armnetwork/fake/dscpconfiguration_server.go new file mode 100644 index 000000000000..6e3f250394bb --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/dscpconfiguration_server.go @@ -0,0 +1,279 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// DscpConfigurationServer is a fake server for instances of the armnetwork.DscpConfigurationClient type. +type DscpConfigurationServer struct { + // BeginCreateOrUpdate is the fake for method DscpConfigurationClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, dscpConfigurationName string, parameters armnetwork.DscpConfiguration, options *armnetwork.DscpConfigurationClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.DscpConfigurationClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method DscpConfigurationClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *armnetwork.DscpConfigurationClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.DscpConfigurationClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DscpConfigurationClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *armnetwork.DscpConfigurationClientGetOptions) (resp azfake.Responder[armnetwork.DscpConfigurationClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DscpConfigurationClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.DscpConfigurationClientListOptions) (resp azfake.PagerResponder[armnetwork.DscpConfigurationClientListResponse]) + + // NewListAllPager is the fake for method DscpConfigurationClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.DscpConfigurationClientListAllOptions) (resp azfake.PagerResponder[armnetwork.DscpConfigurationClientListAllResponse]) +} + +// NewDscpConfigurationServerTransport creates a new instance of DscpConfigurationServerTransport with the provided implementation. +// The returned DscpConfigurationServerTransport instance is connected to an instance of armnetwork.DscpConfigurationClient by way of the +// undefined.Transporter field. +func NewDscpConfigurationServerTransport(srv *DscpConfigurationServer) *DscpConfigurationServerTransport { + return &DscpConfigurationServerTransport{srv: srv} +} + +// DscpConfigurationServerTransport connects instances of armnetwork.DscpConfigurationClient to instances of DscpConfigurationServer. +// Don't use this type directly, use NewDscpConfigurationServerTransport instead. +type DscpConfigurationServerTransport struct { + srv *DscpConfigurationServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.DscpConfigurationClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.DscpConfigurationClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.DscpConfigurationClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.DscpConfigurationClientListAllResponse] +} + +// Do implements the policy.Transporter interface for DscpConfigurationServerTransport. +func (d *DscpConfigurationServerTransport) 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 "DscpConfigurationClient.BeginCreateOrUpdate": + resp, err = d.dispatchBeginCreateOrUpdate(req) + case "DscpConfigurationClient.BeginDelete": + resp, err = d.dispatchBeginDelete(req) + case "DscpConfigurationClient.Get": + resp, err = d.dispatchGet(req) + case "DscpConfigurationClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DscpConfigurationClient.NewListAllPager": + resp, err = d.dispatchNewListAllPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DscpConfigurationServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if d.srv.BeginCreateOrUpdate == nil { + 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.Network/dscpConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.DscpConfiguration](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + dscpConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("dscpConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, dscpConfigurationNameUnescaped, 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 *DscpConfigurationServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if d.srv.BeginDelete == nil { + 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.Network/dscpConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + dscpConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("dscpConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, dscpConfigurationNameUnescaped, 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 *DscpConfigurationServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + 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.Network/dscpConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + dscpConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("dscpConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, dscpConfigurationNameUnescaped, 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).DscpConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DscpConfigurationServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if d.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/dscpConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := d.srv.NewListPager(resourceGroupNameUnescaped, nil) + d.newListPager = &resp + server.PagerResponderInjectNextLinks(d.newListPager, req, func(page *armnetwork.DscpConfigurationClientListResponse, 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 *DscpConfigurationServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if d.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/dscpConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := d.srv.NewListAllPager(nil) + d.newListAllPager = &resp + server.PagerResponderInjectNextLinks(d.newListAllPager, req, func(page *armnetwork.DscpConfigurationClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(d.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(d.newListAllPager) { + d.newListAllPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitauthorizations_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitauthorizations_server.go new file mode 100644 index 000000000000..ebb9b749fc24 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitauthorizations_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteCircuitAuthorizationsServer is a fake server for instances of the armnetwork.ExpressRouteCircuitAuthorizationsClient type. +type ExpressRouteCircuitAuthorizationsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteCircuitAuthorizationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, authorizationParameters armnetwork.ExpressRouteCircuitAuthorization, options *armnetwork.ExpressRouteCircuitAuthorizationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitAuthorizationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteCircuitAuthorizationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, options *armnetwork.ExpressRouteCircuitAuthorizationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitAuthorizationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteCircuitAuthorizationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, options *armnetwork.ExpressRouteCircuitAuthorizationsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitAuthorizationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteCircuitAuthorizationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, circuitName string, options *armnetwork.ExpressRouteCircuitAuthorizationsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCircuitAuthorizationsClientListResponse]) +} + +// NewExpressRouteCircuitAuthorizationsServerTransport creates a new instance of ExpressRouteCircuitAuthorizationsServerTransport with the provided implementation. +// The returned ExpressRouteCircuitAuthorizationsServerTransport instance is connected to an instance of armnetwork.ExpressRouteCircuitAuthorizationsClient by way of the +// undefined.Transporter field. +func NewExpressRouteCircuitAuthorizationsServerTransport(srv *ExpressRouteCircuitAuthorizationsServer) *ExpressRouteCircuitAuthorizationsServerTransport { + return &ExpressRouteCircuitAuthorizationsServerTransport{srv: srv} +} + +// ExpressRouteCircuitAuthorizationsServerTransport connects instances of armnetwork.ExpressRouteCircuitAuthorizationsClient to instances of ExpressRouteCircuitAuthorizationsServer. +// Don't use this type directly, use NewExpressRouteCircuitAuthorizationsServerTransport instead. +type ExpressRouteCircuitAuthorizationsServerTransport struct { + srv *ExpressRouteCircuitAuthorizationsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteCircuitAuthorizationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteCircuitAuthorizationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteCircuitAuthorizationsClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteCircuitAuthorizationsServerTransport. +func (e *ExpressRouteCircuitAuthorizationsServerTransport) 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 "ExpressRouteCircuitAuthorizationsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteCircuitAuthorizationsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteCircuitAuthorizationsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteCircuitAuthorizationsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteCircuitAuthorizationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteCircuitAuthorization](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + authorizationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("authorizationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, authorizationNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitAuthorizationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + authorizationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("authorizationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, authorizationNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitAuthorizationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + authorizationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("authorizationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, authorizationNameUnescaped, 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).ExpressRouteCircuitAuthorization, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCircuitAuthorizationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, circuitNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteCircuitAuthorizationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitconnections_server.go new file mode 100644 index 000000000000..abbd43d67e21 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitconnections_server.go @@ -0,0 +1,274 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteCircuitConnectionsServer is a fake server for instances of the armnetwork.ExpressRouteCircuitConnectionsClient type. +type ExpressRouteCircuitConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteCircuitConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, expressRouteCircuitConnectionParameters armnetwork.ExpressRouteCircuitConnection, options *armnetwork.ExpressRouteCircuitConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteCircuitConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *armnetwork.ExpressRouteCircuitConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteCircuitConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *armnetwork.ExpressRouteCircuitConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteCircuitConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, circuitName string, peeringName string, options *armnetwork.ExpressRouteCircuitConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCircuitConnectionsClientListResponse]) +} + +// NewExpressRouteCircuitConnectionsServerTransport creates a new instance of ExpressRouteCircuitConnectionsServerTransport with the provided implementation. +// The returned ExpressRouteCircuitConnectionsServerTransport instance is connected to an instance of armnetwork.ExpressRouteCircuitConnectionsClient by way of the +// undefined.Transporter field. +func NewExpressRouteCircuitConnectionsServerTransport(srv *ExpressRouteCircuitConnectionsServer) *ExpressRouteCircuitConnectionsServerTransport { + return &ExpressRouteCircuitConnectionsServerTransport{srv: srv} +} + +// ExpressRouteCircuitConnectionsServerTransport connects instances of armnetwork.ExpressRouteCircuitConnectionsClient to instances of ExpressRouteCircuitConnectionsServer. +// Don't use this type directly, use NewExpressRouteCircuitConnectionsServerTransport instead. +type ExpressRouteCircuitConnectionsServerTransport struct { + srv *ExpressRouteCircuitConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteCircuitConnectionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteCircuitConnectionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteCircuitConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteCircuitConnectionsServerTransport. +func (e *ExpressRouteCircuitConnectionsServerTransport) 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 "ExpressRouteCircuitConnectionsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteCircuitConnectionsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteCircuitConnectionsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteCircuitConnectionsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteCircuitConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteCircuitConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, connectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, connectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, connectionNameUnescaped, 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).ExpressRouteCircuitConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCircuitConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteCircuitConnectionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitpeerings_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitpeerings_server.go new file mode 100644 index 000000000000..2eaebd4c4ceb --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuitpeerings_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteCircuitPeeringsServer is a fake server for instances of the armnetwork.ExpressRouteCircuitPeeringsClient type. +type ExpressRouteCircuitPeeringsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteCircuitPeeringsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, peeringParameters armnetwork.ExpressRouteCircuitPeering, options *armnetwork.ExpressRouteCircuitPeeringsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitPeeringsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteCircuitPeeringsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *armnetwork.ExpressRouteCircuitPeeringsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitPeeringsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteCircuitPeeringsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *armnetwork.ExpressRouteCircuitPeeringsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitPeeringsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteCircuitPeeringsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, circuitName string, options *armnetwork.ExpressRouteCircuitPeeringsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCircuitPeeringsClientListResponse]) +} + +// NewExpressRouteCircuitPeeringsServerTransport creates a new instance of ExpressRouteCircuitPeeringsServerTransport with the provided implementation. +// The returned ExpressRouteCircuitPeeringsServerTransport instance is connected to an instance of armnetwork.ExpressRouteCircuitPeeringsClient by way of the +// undefined.Transporter field. +func NewExpressRouteCircuitPeeringsServerTransport(srv *ExpressRouteCircuitPeeringsServer) *ExpressRouteCircuitPeeringsServerTransport { + return &ExpressRouteCircuitPeeringsServerTransport{srv: srv} +} + +// ExpressRouteCircuitPeeringsServerTransport connects instances of armnetwork.ExpressRouteCircuitPeeringsClient to instances of ExpressRouteCircuitPeeringsServer. +// Don't use this type directly, use NewExpressRouteCircuitPeeringsServerTransport instead. +type ExpressRouteCircuitPeeringsServerTransport struct { + srv *ExpressRouteCircuitPeeringsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteCircuitPeeringsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteCircuitPeeringsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteCircuitPeeringsClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteCircuitPeeringsServerTransport. +func (e *ExpressRouteCircuitPeeringsServerTransport) 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 "ExpressRouteCircuitPeeringsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteCircuitPeeringsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteCircuitPeeringsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteCircuitPeeringsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteCircuitPeeringsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteCircuitPeering](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitPeeringsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitPeeringsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, 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).ExpressRouteCircuitPeering, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCircuitPeeringsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, circuitNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteCircuitPeeringsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuits_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuits_server.go new file mode 100644 index 000000000000..7a6fa6d378ae --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutecircuits_server.go @@ -0,0 +1,572 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteCircuitsServer is a fake server for instances of the armnetwork.ExpressRouteCircuitsClient type. +type ExpressRouteCircuitsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteCircuitsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, circuitName string, parameters armnetwork.ExpressRouteCircuit, options *armnetwork.ExpressRouteCircuitsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteCircuitsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, circuitName string, options *armnetwork.ExpressRouteCircuitsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteCircuitsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, circuitName string, options *armnetwork.ExpressRouteCircuitsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitsClientGetResponse], errResp azfake.ErrorResponder) + + // GetPeeringStats is the fake for method ExpressRouteCircuitsClient.GetPeeringStats + // HTTP status codes to indicate success: http.StatusOK + GetPeeringStats func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *armnetwork.ExpressRouteCircuitsClientGetPeeringStatsOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitsClientGetPeeringStatsResponse], errResp azfake.ErrorResponder) + + // GetStats is the fake for method ExpressRouteCircuitsClient.GetStats + // HTTP status codes to indicate success: http.StatusOK + GetStats func(ctx context.Context, resourceGroupName string, circuitName string, options *armnetwork.ExpressRouteCircuitsClientGetStatsOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitsClientGetStatsResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteCircuitsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.ExpressRouteCircuitsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCircuitsClientListResponse]) + + // NewListAllPager is the fake for method ExpressRouteCircuitsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.ExpressRouteCircuitsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCircuitsClientListAllResponse]) + + // BeginListArpTable is the fake for method ExpressRouteCircuitsClient.BeginListArpTable + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListArpTable func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, devicePath string, options *armnetwork.ExpressRouteCircuitsClientBeginListArpTableOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientListArpTableResponse], errResp azfake.ErrorResponder) + + // BeginListRoutesTable is the fake for method ExpressRouteCircuitsClient.BeginListRoutesTable + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListRoutesTable func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, devicePath string, options *armnetwork.ExpressRouteCircuitsClientBeginListRoutesTableOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientListRoutesTableResponse], errResp azfake.ErrorResponder) + + // BeginListRoutesTableSummary is the fake for method ExpressRouteCircuitsClient.BeginListRoutesTableSummary + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListRoutesTableSummary func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, devicePath string, options *armnetwork.ExpressRouteCircuitsClientBeginListRoutesTableSummaryOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientListRoutesTableSummaryResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method ExpressRouteCircuitsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, circuitName string, parameters armnetwork.TagsObject, options *armnetwork.ExpressRouteCircuitsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ExpressRouteCircuitsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewExpressRouteCircuitsServerTransport creates a new instance of ExpressRouteCircuitsServerTransport with the provided implementation. +// The returned ExpressRouteCircuitsServerTransport instance is connected to an instance of armnetwork.ExpressRouteCircuitsClient by way of the +// undefined.Transporter field. +func NewExpressRouteCircuitsServerTransport(srv *ExpressRouteCircuitsServer) *ExpressRouteCircuitsServerTransport { + return &ExpressRouteCircuitsServerTransport{srv: srv} +} + +// ExpressRouteCircuitsServerTransport connects instances of armnetwork.ExpressRouteCircuitsClient to instances of ExpressRouteCircuitsServer. +// Don't use this type directly, use NewExpressRouteCircuitsServerTransport instead. +type ExpressRouteCircuitsServerTransport struct { + srv *ExpressRouteCircuitsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteCircuitsClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.ExpressRouteCircuitsClientListAllResponse] + beginListArpTable *azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientListArpTableResponse] + beginListRoutesTable *azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientListRoutesTableResponse] + beginListRoutesTableSummary *azfake.PollerResponder[armnetwork.ExpressRouteCircuitsClientListRoutesTableSummaryResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteCircuitsServerTransport. +func (e *ExpressRouteCircuitsServerTransport) 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 "ExpressRouteCircuitsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteCircuitsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteCircuitsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteCircuitsClient.GetPeeringStats": + resp, err = e.dispatchGetPeeringStats(req) + case "ExpressRouteCircuitsClient.GetStats": + resp, err = e.dispatchGetStats(req) + case "ExpressRouteCircuitsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + case "ExpressRouteCircuitsClient.NewListAllPager": + resp, err = e.dispatchNewListAllPager(req) + case "ExpressRouteCircuitsClient.BeginListArpTable": + resp, err = e.dispatchBeginListArpTable(req) + case "ExpressRouteCircuitsClient.BeginListRoutesTable": + resp, err = e.dispatchBeginListRoutesTable(req) + case "ExpressRouteCircuitsClient.BeginListRoutesTableSummary": + resp, err = e.dispatchBeginListRoutesTableSummary(req) + case "ExpressRouteCircuitsClient.UpdateTags": + resp, err = e.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteCircuit](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, 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).ExpressRouteCircuit, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchGetPeeringStats(req *http.Request) (*http.Response, error) { + if e.srv.GetPeeringStats == nil { + return nil, &nonRetriableError{errors.New("fake for method GetPeeringStats not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stats` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.GetPeeringStats(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, 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).ExpressRouteCircuitStats, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchGetStats(req *http.Request) (*http.Response, error) { + if e.srv.GetStats == nil { + return nil, &nonRetriableError{errors.New("fake for method GetStats not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stats` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.GetStats(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, 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).ExpressRouteCircuitStats, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteCircuitsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if e.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := e.srv.NewListAllPager(nil) + e.newListAllPager = &resp + server.PagerResponderInjectNextLinks(e.newListAllPager, req, func(page *armnetwork.ExpressRouteCircuitsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListAllPager) { + e.newListAllPager = nil + } + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchBeginListArpTable(req *http.Request) (*http.Response, error) { + if e.srv.BeginListArpTable == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListArpTable not implemented")} + } + if e.beginListArpTable == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/arpTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + devicePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("devicePath")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginListArpTable(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, devicePathUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginListArpTable = &respr + } + + resp, err := server.PollerResponderNext(e.beginListArpTable, 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(e.beginListArpTable) { + e.beginListArpTable = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchBeginListRoutesTable(req *http.Request) (*http.Response, error) { + if e.srv.BeginListRoutesTable == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListRoutesTable not implemented")} + } + if e.beginListRoutesTable == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + devicePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("devicePath")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginListRoutesTable(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, devicePathUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginListRoutesTable = &respr + } + + resp, err := server.PollerResponderNext(e.beginListRoutesTable, 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(e.beginListRoutesTable) { + e.beginListRoutesTable = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchBeginListRoutesTableSummary(req *http.Request) (*http.Response, error) { + if e.srv.BeginListRoutesTableSummary == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListRoutesTableSummary not implemented")} + } + if e.beginListRoutesTableSummary == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTablesSummary/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + devicePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("devicePath")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginListRoutesTableSummary(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, devicePathUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginListRoutesTableSummary = &respr + } + + resp, err := server.PollerResponderNext(e.beginListRoutesTableSummary, 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(e.beginListRoutesTableSummary) { + e.beginListRoutesTableSummary = nil + } + + return resp, nil +} + +func (e *ExpressRouteCircuitsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if e.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, 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).ExpressRouteCircuit, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressrouteconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressrouteconnections_server.go new file mode 100644 index 000000000000..c602a9e129f0 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressrouteconnections_server.go @@ -0,0 +1,251 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteConnectionsServer is a fake server for instances of the armnetwork.ExpressRouteConnectionsClient type. +type ExpressRouteConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters armnetwork.ExpressRouteConnection, options *armnetwork.ExpressRouteConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *armnetwork.ExpressRouteConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *armnetwork.ExpressRouteConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method ExpressRouteConnectionsClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *armnetwork.ExpressRouteConnectionsClientListOptions) (resp azfake.Responder[armnetwork.ExpressRouteConnectionsClientListResponse], errResp azfake.ErrorResponder) +} + +// NewExpressRouteConnectionsServerTransport creates a new instance of ExpressRouteConnectionsServerTransport with the provided implementation. +// The returned ExpressRouteConnectionsServerTransport instance is connected to an instance of armnetwork.ExpressRouteConnectionsClient by way of the +// undefined.Transporter field. +func NewExpressRouteConnectionsServerTransport(srv *ExpressRouteConnectionsServer) *ExpressRouteConnectionsServerTransport { + return &ExpressRouteConnectionsServerTransport{srv: srv} +} + +// ExpressRouteConnectionsServerTransport connects instances of armnetwork.ExpressRouteConnectionsClient to instances of ExpressRouteConnectionsServer. +// Don't use this type directly, use NewExpressRouteConnectionsServerTransport instead. +type ExpressRouteConnectionsServerTransport struct { + srv *ExpressRouteConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteConnectionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteConnectionsClientDeleteResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteConnectionsServerTransport. +func (e *ExpressRouteConnectionsServerTransport) 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 "ExpressRouteConnectionsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteConnectionsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteConnectionsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteConnectionsClient.List": + resp, err = e.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/expressRouteConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, connectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/expressRouteConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, connectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/expressRouteConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, connectionNameUnescaped, 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).ExpressRouteConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteConnectionsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if e.srv.List == nil { + 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.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/expressRouteConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.List(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, 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).ExpressRouteConnectionList, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutecrossconnectionpeerings_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutecrossconnectionpeerings_server.go new file mode 100644 index 000000000000..b9781d5251e5 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutecrossconnectionpeerings_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteCrossConnectionPeeringsServer is a fake server for instances of the armnetwork.ExpressRouteCrossConnectionPeeringsClient type. +type ExpressRouteCrossConnectionPeeringsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteCrossConnectionPeeringsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, peeringParameters armnetwork.ExpressRouteCrossConnectionPeering, options *armnetwork.ExpressRouteCrossConnectionPeeringsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionPeeringsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteCrossConnectionPeeringsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, options *armnetwork.ExpressRouteCrossConnectionPeeringsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionPeeringsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteCrossConnectionPeeringsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, options *armnetwork.ExpressRouteCrossConnectionPeeringsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteCrossConnectionPeeringsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteCrossConnectionPeeringsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, crossConnectionName string, options *armnetwork.ExpressRouteCrossConnectionPeeringsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCrossConnectionPeeringsClientListResponse]) +} + +// NewExpressRouteCrossConnectionPeeringsServerTransport creates a new instance of ExpressRouteCrossConnectionPeeringsServerTransport with the provided implementation. +// The returned ExpressRouteCrossConnectionPeeringsServerTransport instance is connected to an instance of armnetwork.ExpressRouteCrossConnectionPeeringsClient by way of the +// undefined.Transporter field. +func NewExpressRouteCrossConnectionPeeringsServerTransport(srv *ExpressRouteCrossConnectionPeeringsServer) *ExpressRouteCrossConnectionPeeringsServerTransport { + return &ExpressRouteCrossConnectionPeeringsServerTransport{srv: srv} +} + +// ExpressRouteCrossConnectionPeeringsServerTransport connects instances of armnetwork.ExpressRouteCrossConnectionPeeringsClient to instances of ExpressRouteCrossConnectionPeeringsServer. +// Don't use this type directly, use NewExpressRouteCrossConnectionPeeringsServerTransport instead. +type ExpressRouteCrossConnectionPeeringsServerTransport struct { + srv *ExpressRouteCrossConnectionPeeringsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionPeeringsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionPeeringsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteCrossConnectionPeeringsClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteCrossConnectionPeeringsServerTransport. +func (e *ExpressRouteCrossConnectionPeeringsServerTransport) 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 "ExpressRouteCrossConnectionPeeringsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteCrossConnectionPeeringsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteCrossConnectionPeeringsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteCrossConnectionPeeringsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionPeeringsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteCrossConnectionPeering](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, peeringNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionPeeringsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, peeringNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionPeeringsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, peeringNameUnescaped, 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).ExpressRouteCrossConnectionPeering, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCrossConnectionPeeringsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, crossConnectionNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteCrossConnectionPeeringsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutecrossconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutecrossconnections_server.go new file mode 100644 index 000000000000..1dcb50215ec5 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutecrossconnections_server.go @@ -0,0 +1,442 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteCrossConnectionsServer is a fake server for instances of the armnetwork.ExpressRouteCrossConnectionsClient type. +type ExpressRouteCrossConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteCrossConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, crossConnectionName string, parameters armnetwork.ExpressRouteCrossConnection, options *armnetwork.ExpressRouteCrossConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteCrossConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, crossConnectionName string, options *armnetwork.ExpressRouteCrossConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteCrossConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteCrossConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.ExpressRouteCrossConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCrossConnectionsClientListResponse]) + + // BeginListArpTable is the fake for method ExpressRouteCrossConnectionsClient.BeginListArpTable + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListArpTable func(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, devicePath string, options *armnetwork.ExpressRouteCrossConnectionsClientBeginListArpTableOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientListArpTableResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method ExpressRouteCrossConnectionsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.ExpressRouteCrossConnectionsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteCrossConnectionsClientListByResourceGroupResponse]) + + // BeginListRoutesTable is the fake for method ExpressRouteCrossConnectionsClient.BeginListRoutesTable + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListRoutesTable func(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, devicePath string, options *armnetwork.ExpressRouteCrossConnectionsClientBeginListRoutesTableOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientListRoutesTableResponse], errResp azfake.ErrorResponder) + + // BeginListRoutesTableSummary is the fake for method ExpressRouteCrossConnectionsClient.BeginListRoutesTableSummary + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListRoutesTableSummary func(ctx context.Context, resourceGroupName string, crossConnectionName string, peeringName string, devicePath string, options *armnetwork.ExpressRouteCrossConnectionsClientBeginListRoutesTableSummaryOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientListRoutesTableSummaryResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method ExpressRouteCrossConnectionsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, crossConnectionName string, crossConnectionParameters armnetwork.TagsObject, options *armnetwork.ExpressRouteCrossConnectionsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ExpressRouteCrossConnectionsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewExpressRouteCrossConnectionsServerTransport creates a new instance of ExpressRouteCrossConnectionsServerTransport with the provided implementation. +// The returned ExpressRouteCrossConnectionsServerTransport instance is connected to an instance of armnetwork.ExpressRouteCrossConnectionsClient by way of the +// undefined.Transporter field. +func NewExpressRouteCrossConnectionsServerTransport(srv *ExpressRouteCrossConnectionsServer) *ExpressRouteCrossConnectionsServerTransport { + return &ExpressRouteCrossConnectionsServerTransport{srv: srv} +} + +// ExpressRouteCrossConnectionsServerTransport connects instances of armnetwork.ExpressRouteCrossConnectionsClient to instances of ExpressRouteCrossConnectionsServer. +// Don't use this type directly, use NewExpressRouteCrossConnectionsServerTransport instead. +type ExpressRouteCrossConnectionsServerTransport struct { + srv *ExpressRouteCrossConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientCreateOrUpdateResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteCrossConnectionsClientListResponse] + beginListArpTable *azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientListArpTableResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.ExpressRouteCrossConnectionsClientListByResourceGroupResponse] + beginListRoutesTable *azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientListRoutesTableResponse] + beginListRoutesTableSummary *azfake.PollerResponder[armnetwork.ExpressRouteCrossConnectionsClientListRoutesTableSummaryResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteCrossConnectionsServerTransport. +func (e *ExpressRouteCrossConnectionsServerTransport) 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 "ExpressRouteCrossConnectionsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteCrossConnectionsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteCrossConnectionsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + case "ExpressRouteCrossConnectionsClient.BeginListArpTable": + resp, err = e.dispatchBeginListArpTable(req) + case "ExpressRouteCrossConnectionsClient.NewListByResourceGroupPager": + resp, err = e.dispatchNewListByResourceGroupPager(req) + case "ExpressRouteCrossConnectionsClient.BeginListRoutesTable": + resp, err = e.dispatchBeginListRoutesTable(req) + case "ExpressRouteCrossConnectionsClient.BeginListRoutesTableSummary": + resp, err = e.dispatchBeginListRoutesTableSummary(req) + case "ExpressRouteCrossConnectionsClient.UpdateTags": + resp, err = e.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteCrossConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.beginCreateOrUpdate, 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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, 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).ExpressRouteCrossConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := e.srv.NewListPager(nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteCrossConnectionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchBeginListArpTable(req *http.Request) (*http.Response, error) { + if e.srv.BeginListArpTable == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListArpTable not implemented")} + } + if e.beginListArpTable == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/arpTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + devicePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("devicePath")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginListArpTable(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, peeringNameUnescaped, devicePathUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginListArpTable = &respr + } + + resp, err := server.PollerResponderNext(e.beginListArpTable, 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(e.beginListArpTable) { + e.beginListArpTable = nil + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if e.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + e.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(e.newListByResourceGroupPager, req, func(page *armnetwork.ExpressRouteCrossConnectionsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListByResourceGroupPager) { + e.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchBeginListRoutesTable(req *http.Request) (*http.Response, error) { + if e.srv.BeginListRoutesTable == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListRoutesTable not implemented")} + } + if e.beginListRoutesTable == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + devicePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("devicePath")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginListRoutesTable(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, peeringNameUnescaped, devicePathUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginListRoutesTable = &respr + } + + resp, err := server.PollerResponderNext(e.beginListRoutesTable, 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(e.beginListRoutesTable) { + e.beginListRoutesTable = nil + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchBeginListRoutesTableSummary(req *http.Request) (*http.Response, error) { + if e.srv.BeginListRoutesTableSummary == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListRoutesTableSummary not implemented")} + } + if e.beginListRoutesTableSummary == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTablesSummary/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + devicePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("devicePath")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginListRoutesTableSummary(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, peeringNameUnescaped, devicePathUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginListRoutesTableSummary = &respr + } + + resp, err := server.PollerResponderNext(e.beginListRoutesTableSummary, 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(e.beginListRoutesTableSummary) { + e.beginListRoutesTableSummary = nil + } + + return resp, nil +} + +func (e *ExpressRouteCrossConnectionsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if e.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCrossConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + crossConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("crossConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, crossConnectionNameUnescaped, 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).ExpressRouteCrossConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutegateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutegateways_server.go new file mode 100644 index 000000000000..b3ba88aafb9e --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutegateways_server.go @@ -0,0 +1,318 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteGatewaysServer is a fake server for instances of the armnetwork.ExpressRouteGatewaysClient type. +type ExpressRouteGatewaysServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRouteGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters armnetwork.ExpressRouteGateway, options *armnetwork.ExpressRouteGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRouteGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *armnetwork.ExpressRouteGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRouteGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *armnetwork.ExpressRouteGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // ListByResourceGroup is the fake for method ExpressRouteGatewaysClient.ListByResourceGroup + // HTTP status codes to indicate success: http.StatusOK + ListByResourceGroup func(ctx context.Context, resourceGroupName string, options *armnetwork.ExpressRouteGatewaysClientListByResourceGroupOptions) (resp azfake.Responder[armnetwork.ExpressRouteGatewaysClientListByResourceGroupResponse], errResp azfake.ErrorResponder) + + // ListBySubscription is the fake for method ExpressRouteGatewaysClient.ListBySubscription + // HTTP status codes to indicate success: http.StatusOK + ListBySubscription func(ctx context.Context, options *armnetwork.ExpressRouteGatewaysClientListBySubscriptionOptions) (resp azfake.Responder[armnetwork.ExpressRouteGatewaysClientListBySubscriptionResponse], errResp azfake.ErrorResponder) + + // BeginUpdateTags is the fake for method ExpressRouteGatewaysClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, expressRouteGatewayParameters armnetwork.TagsObject, options *armnetwork.ExpressRouteGatewaysClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewExpressRouteGatewaysServerTransport creates a new instance of ExpressRouteGatewaysServerTransport with the provided implementation. +// The returned ExpressRouteGatewaysServerTransport instance is connected to an instance of armnetwork.ExpressRouteGatewaysClient by way of the +// undefined.Transporter field. +func NewExpressRouteGatewaysServerTransport(srv *ExpressRouteGatewaysServer) *ExpressRouteGatewaysServerTransport { + return &ExpressRouteGatewaysServerTransport{srv: srv} +} + +// ExpressRouteGatewaysServerTransport connects instances of armnetwork.ExpressRouteGatewaysClient to instances of ExpressRouteGatewaysServer. +// Don't use this type directly, use NewExpressRouteGatewaysServerTransport instead. +type ExpressRouteGatewaysServerTransport struct { + srv *ExpressRouteGatewaysServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientDeleteResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteGatewaysServerTransport. +func (e *ExpressRouteGatewaysServerTransport) 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 "ExpressRouteGatewaysClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRouteGatewaysClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRouteGatewaysClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteGatewaysClient.ListByResourceGroup": + resp, err = e.dispatchListByResourceGroup(req) + case "ExpressRouteGatewaysClient.ListBySubscription": + resp, err = e.dispatchListBySubscription(req) + case "ExpressRouteGatewaysClient.BeginUpdateTags": + resp, err = e.dispatchBeginUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRouteGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRouteGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, 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).ExpressRouteGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteGatewaysServerTransport) dispatchListByResourceGroup(req *http.Request) (*http.Response, error) { + if e.srv.ListByResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method ListByResourceGroup not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.ListByResourceGroup(req.Context(), resourceGroupNameUnescaped, 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).ExpressRouteGatewayList, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteGatewaysServerTransport) dispatchListBySubscription(req *http.Request) (*http.Response, error) { + if e.srv.ListBySubscription == nil { + return nil, &nonRetriableError{errors.New("fake for method ListBySubscription not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + respr, errRespr := e.srv.ListBySubscription(req.Context(), 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).ExpressRouteGatewayList, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteGatewaysServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if e.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if e.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRouteGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, expressRouteGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(e.beginUpdateTags, 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(e.beginUpdateTags) { + e.beginUpdateTags = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressroutelinks_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressroutelinks_server.go new file mode 100644 index 000000000000..b522d988a098 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressroutelinks_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteLinksServer is a fake server for instances of the armnetwork.ExpressRouteLinksClient type. +type ExpressRouteLinksServer struct { + // Get is the fake for method ExpressRouteLinksClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, expressRoutePortName string, linkName string, options *armnetwork.ExpressRouteLinksClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteLinksClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRouteLinksClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, expressRoutePortName string, options *armnetwork.ExpressRouteLinksClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteLinksClientListResponse]) +} + +// NewExpressRouteLinksServerTransport creates a new instance of ExpressRouteLinksServerTransport with the provided implementation. +// The returned ExpressRouteLinksServerTransport instance is connected to an instance of armnetwork.ExpressRouteLinksClient by way of the +// undefined.Transporter field. +func NewExpressRouteLinksServerTransport(srv *ExpressRouteLinksServer) *ExpressRouteLinksServerTransport { + return &ExpressRouteLinksServerTransport{srv: srv} +} + +// ExpressRouteLinksServerTransport connects instances of armnetwork.ExpressRouteLinksClient to instances of ExpressRouteLinksServer. +// Don't use this type directly, use NewExpressRouteLinksServerTransport instead. +type ExpressRouteLinksServerTransport struct { + srv *ExpressRouteLinksServer + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteLinksClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteLinksServerTransport. +func (e *ExpressRouteLinksServerTransport) 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 "ExpressRouteLinksClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRouteLinksClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteLinksServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/ExpressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/links/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + linkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("linkName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, linkNameUnescaped, 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).ExpressRouteLink, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRouteLinksServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/links` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, expressRoutePortNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteLinksClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressrouteportauthorizations_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressrouteportauthorizations_server.go new file mode 100644 index 000000000000..5f65f4cdbf4e --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressrouteportauthorizations_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRoutePortAuthorizationsServer is a fake server for instances of the armnetwork.ExpressRoutePortAuthorizationsClient type. +type ExpressRoutePortAuthorizationsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRoutePortAuthorizationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, expressRoutePortName string, authorizationName string, authorizationParameters armnetwork.ExpressRoutePortAuthorization, options *armnetwork.ExpressRoutePortAuthorizationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRoutePortAuthorizationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRoutePortAuthorizationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, expressRoutePortName string, authorizationName string, options *armnetwork.ExpressRoutePortAuthorizationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRoutePortAuthorizationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRoutePortAuthorizationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, expressRoutePortName string, authorizationName string, options *armnetwork.ExpressRoutePortAuthorizationsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRoutePortAuthorizationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRoutePortAuthorizationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, expressRoutePortName string, options *armnetwork.ExpressRoutePortAuthorizationsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRoutePortAuthorizationsClientListResponse]) +} + +// NewExpressRoutePortAuthorizationsServerTransport creates a new instance of ExpressRoutePortAuthorizationsServerTransport with the provided implementation. +// The returned ExpressRoutePortAuthorizationsServerTransport instance is connected to an instance of armnetwork.ExpressRoutePortAuthorizationsClient by way of the +// undefined.Transporter field. +func NewExpressRoutePortAuthorizationsServerTransport(srv *ExpressRoutePortAuthorizationsServer) *ExpressRoutePortAuthorizationsServerTransport { + return &ExpressRoutePortAuthorizationsServerTransport{srv: srv} +} + +// ExpressRoutePortAuthorizationsServerTransport connects instances of armnetwork.ExpressRoutePortAuthorizationsClient to instances of ExpressRoutePortAuthorizationsServer. +// Don't use this type directly, use NewExpressRoutePortAuthorizationsServerTransport instead. +type ExpressRoutePortAuthorizationsServerTransport struct { + srv *ExpressRoutePortAuthorizationsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRoutePortAuthorizationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRoutePortAuthorizationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRoutePortAuthorizationsClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRoutePortAuthorizationsServerTransport. +func (e *ExpressRoutePortAuthorizationsServerTransport) 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 "ExpressRoutePortAuthorizationsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRoutePortAuthorizationsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRoutePortAuthorizationsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRoutePortAuthorizationsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRoutePortAuthorizationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRoutePortAuthorization](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + authorizationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("authorizationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, authorizationNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRoutePortAuthorizationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + authorizationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("authorizationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, authorizationNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRoutePortAuthorizationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/expressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + authorizationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("authorizationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, authorizationNameUnescaped, 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).ExpressRoutePortAuthorization, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRoutePortAuthorizationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/authorizations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListPager(resourceGroupNameUnescaped, expressRoutePortNameUnescaped, nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRoutePortAuthorizationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressrouteports_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressrouteports_server.go new file mode 100644 index 000000000000..6b8dbe7c1ad1 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressrouteports_server.go @@ -0,0 +1,365 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRoutePortsServer is a fake server for instances of the armnetwork.ExpressRoutePortsClient type. +type ExpressRoutePortsServer struct { + // BeginCreateOrUpdate is the fake for method ExpressRoutePortsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, expressRoutePortName string, parameters armnetwork.ExpressRoutePort, options *armnetwork.ExpressRoutePortsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRoutePortsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExpressRoutePortsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, expressRoutePortName string, options *armnetwork.ExpressRoutePortsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRoutePortsClientDeleteResponse], errResp azfake.ErrorResponder) + + // GenerateLOA is the fake for method ExpressRoutePortsClient.GenerateLOA + // HTTP status codes to indicate success: http.StatusOK + GenerateLOA func(ctx context.Context, resourceGroupName string, expressRoutePortName string, request armnetwork.GenerateExpressRoutePortsLOARequest, options *armnetwork.ExpressRoutePortsClientGenerateLOAOptions) (resp azfake.Responder[armnetwork.ExpressRoutePortsClientGenerateLOAResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExpressRoutePortsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, expressRoutePortName string, options *armnetwork.ExpressRoutePortsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRoutePortsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRoutePortsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.ExpressRoutePortsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRoutePortsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method ExpressRoutePortsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.ExpressRoutePortsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.ExpressRoutePortsClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method ExpressRoutePortsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, expressRoutePortName string, parameters armnetwork.TagsObject, options *armnetwork.ExpressRoutePortsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ExpressRoutePortsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewExpressRoutePortsServerTransport creates a new instance of ExpressRoutePortsServerTransport with the provided implementation. +// The returned ExpressRoutePortsServerTransport instance is connected to an instance of armnetwork.ExpressRoutePortsClient by way of the +// undefined.Transporter field. +func NewExpressRoutePortsServerTransport(srv *ExpressRoutePortsServer) *ExpressRoutePortsServerTransport { + return &ExpressRoutePortsServerTransport{srv: srv} +} + +// ExpressRoutePortsServerTransport connects instances of armnetwork.ExpressRoutePortsClient to instances of ExpressRoutePortsServer. +// Don't use this type directly, use NewExpressRoutePortsServerTransport instead. +type ExpressRoutePortsServerTransport struct { + srv *ExpressRoutePortsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ExpressRoutePortsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ExpressRoutePortsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ExpressRoutePortsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.ExpressRoutePortsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for ExpressRoutePortsServerTransport. +func (e *ExpressRoutePortsServerTransport) 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 "ExpressRoutePortsClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExpressRoutePortsClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExpressRoutePortsClient.GenerateLOA": + resp, err = e.dispatchGenerateLOA(req) + case "ExpressRoutePortsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRoutePortsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + case "ExpressRoutePortsClient.NewListByResourceGroupPager": + resp, err = e.dispatchNewListByResourceGroupPager(req) + case "ExpressRoutePortsClient.UpdateTags": + resp, err = e.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if e.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRoutePort](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginCreateOrUpdate) { + e.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if e.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + e.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(e.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(e.beginDelete) { + e.beginDelete = nil + } + + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchGenerateLOA(req *http.Request) (*http.Response, error) { + if e.srv.GenerateLOA == nil { + return nil, &nonRetriableError{errors.New("fake for method GenerateLOA not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generateLoa` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.GenerateExpressRoutePortsLOARequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.GenerateLOA(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, 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).GenerateExpressRoutePortsLOAResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + 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.Network/ExpressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, 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).ExpressRoutePort, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePorts` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := e.srv.NewListPager(nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRoutePortsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if e.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePorts` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + e.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(e.newListByResourceGroupPager, req, func(page *armnetwork.ExpressRoutePortsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListByResourceGroupPager) { + e.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (e *ExpressRoutePortsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if e.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expressRoutePortNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("expressRoutePortName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, expressRoutePortNameUnescaped, 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).ExpressRoutePort, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressrouteportslocations_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressrouteportslocations_server.go new file mode 100644 index 000000000000..ab9ab071fdae --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressrouteportslocations_server.go @@ -0,0 +1,134 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRoutePortsLocationsServer is a fake server for instances of the armnetwork.ExpressRoutePortsLocationsClient type. +type ExpressRoutePortsLocationsServer struct { + // Get is the fake for method ExpressRoutePortsLocationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, locationName string, options *armnetwork.ExpressRoutePortsLocationsClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRoutePortsLocationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExpressRoutePortsLocationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.ExpressRoutePortsLocationsClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRoutePortsLocationsClientListResponse]) +} + +// NewExpressRoutePortsLocationsServerTransport creates a new instance of ExpressRoutePortsLocationsServerTransport with the provided implementation. +// The returned ExpressRoutePortsLocationsServerTransport instance is connected to an instance of armnetwork.ExpressRoutePortsLocationsClient by way of the +// undefined.Transporter field. +func NewExpressRoutePortsLocationsServerTransport(srv *ExpressRoutePortsLocationsServer) *ExpressRoutePortsLocationsServerTransport { + return &ExpressRoutePortsLocationsServerTransport{srv: srv} +} + +// ExpressRoutePortsLocationsServerTransport connects instances of armnetwork.ExpressRoutePortsLocationsClient to instances of ExpressRoutePortsLocationsServer. +// Don't use this type directly, use NewExpressRoutePortsLocationsServerTransport instead. +type ExpressRoutePortsLocationsServerTransport struct { + srv *ExpressRoutePortsLocationsServer + newListPager *azfake.PagerResponder[armnetwork.ExpressRoutePortsLocationsClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRoutePortsLocationsServerTransport. +func (e *ExpressRoutePortsLocationsServerTransport) 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 "ExpressRoutePortsLocationsClient.Get": + resp, err = e.dispatchGet(req) + case "ExpressRoutePortsLocationsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRoutePortsLocationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePortsLocations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("locationName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), locationNameUnescaped, 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).ExpressRoutePortsLocation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExpressRoutePortsLocationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ExpressRoutePortsLocations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := e.srv.NewListPager(nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRoutePortsLocationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressrouteproviderportslocation_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressrouteproviderportslocation_server.go new file mode 100644 index 000000000000..7c0dc84ce5e2 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressrouteproviderportslocation_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ExpressRouteProviderPortsLocationServer is a fake server for instances of the armnetwork.ExpressRouteProviderPortsLocationClient type. +type ExpressRouteProviderPortsLocationServer struct { + // List is the fake for method ExpressRouteProviderPortsLocationClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, options *armnetwork.ExpressRouteProviderPortsLocationClientListOptions) (resp azfake.Responder[armnetwork.ExpressRouteProviderPortsLocationClientListResponse], errResp azfake.ErrorResponder) +} + +// NewExpressRouteProviderPortsLocationServerTransport creates a new instance of ExpressRouteProviderPortsLocationServerTransport with the provided implementation. +// The returned ExpressRouteProviderPortsLocationServerTransport instance is connected to an instance of armnetwork.ExpressRouteProviderPortsLocationClient by way of the +// undefined.Transporter field. +func NewExpressRouteProviderPortsLocationServerTransport(srv *ExpressRouteProviderPortsLocationServer) *ExpressRouteProviderPortsLocationServerTransport { + return &ExpressRouteProviderPortsLocationServerTransport{srv: srv} +} + +// ExpressRouteProviderPortsLocationServerTransport connects instances of armnetwork.ExpressRouteProviderPortsLocationClient to instances of ExpressRouteProviderPortsLocationServer. +// Don't use this type directly, use NewExpressRouteProviderPortsLocationServerTransport instead. +type ExpressRouteProviderPortsLocationServerTransport struct { + srv *ExpressRouteProviderPortsLocationServer +} + +// Do implements the policy.Transporter interface for ExpressRouteProviderPortsLocationServerTransport. +func (e *ExpressRouteProviderPortsLocationServerTransport) 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 "ExpressRouteProviderPortsLocationClient.List": + resp, err = e.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteProviderPortsLocationServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if e.srv.List == nil { + return nil, &nonRetriableError{errors.New("fake for method List not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteProviderPorts` + regex := regexp.MustCompile(regexStr) + 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() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armnetwork.ExpressRouteProviderPortsLocationClientListOptions + if filterParam != nil { + options = &armnetwork.ExpressRouteProviderPortsLocationClientListOptions{ + Filter: filterParam, + } + } + respr, errRespr := e.srv.List(req.Context(), 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).ExpressRouteProviderPortListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/expressrouteserviceproviders_server.go b/sdk/resourcemanager/network/armnetwork/fake/expressrouteserviceproviders_server.go new file mode 100644 index 000000000000..1cfcf667ea0c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/expressrouteserviceproviders_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/network/armnetwork/v3" + "net/http" + "regexp" +) + +// ExpressRouteServiceProvidersServer is a fake server for instances of the armnetwork.ExpressRouteServiceProvidersClient type. +type ExpressRouteServiceProvidersServer struct { + // NewListPager is the fake for method ExpressRouteServiceProvidersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.ExpressRouteServiceProvidersClientListOptions) (resp azfake.PagerResponder[armnetwork.ExpressRouteServiceProvidersClientListResponse]) +} + +// NewExpressRouteServiceProvidersServerTransport creates a new instance of ExpressRouteServiceProvidersServerTransport with the provided implementation. +// The returned ExpressRouteServiceProvidersServerTransport instance is connected to an instance of armnetwork.ExpressRouteServiceProvidersClient by way of the +// undefined.Transporter field. +func NewExpressRouteServiceProvidersServerTransport(srv *ExpressRouteServiceProvidersServer) *ExpressRouteServiceProvidersServerTransport { + return &ExpressRouteServiceProvidersServerTransport{srv: srv} +} + +// ExpressRouteServiceProvidersServerTransport connects instances of armnetwork.ExpressRouteServiceProvidersClient to instances of ExpressRouteServiceProvidersServer. +// Don't use this type directly, use NewExpressRouteServiceProvidersServerTransport instead. +type ExpressRouteServiceProvidersServerTransport struct { + srv *ExpressRouteServiceProvidersServer + newListPager *azfake.PagerResponder[armnetwork.ExpressRouteServiceProvidersClientListResponse] +} + +// Do implements the policy.Transporter interface for ExpressRouteServiceProvidersServerTransport. +func (e *ExpressRouteServiceProvidersServerTransport) 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 "ExpressRouteServiceProvidersClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExpressRouteServiceProvidersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if e.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteServiceProviders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := e.srv.NewListPager(nil) + e.newListPager = &resp + server.PagerResponderInjectNextLinks(e.newListPager, req, func(page *armnetwork.ExpressRouteServiceProvidersClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(e.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(e.newListPager) { + e.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/firewallpolicies_server.go b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicies_server.go new file mode 100644 index 000000000000..2a7226157e25 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicies_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// FirewallPoliciesServer is a fake server for instances of the armnetwork.FirewallPoliciesClient type. +type FirewallPoliciesServer struct { + // BeginCreateOrUpdate is the fake for method FirewallPoliciesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.FirewallPolicy, options *armnetwork.FirewallPoliciesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.FirewallPoliciesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method FirewallPoliciesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPoliciesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.FirewallPoliciesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method FirewallPoliciesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPoliciesClientGetOptions) (resp azfake.Responder[armnetwork.FirewallPoliciesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method FirewallPoliciesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.FirewallPoliciesClientListOptions) (resp azfake.PagerResponder[armnetwork.FirewallPoliciesClientListResponse]) + + // NewListAllPager is the fake for method FirewallPoliciesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.FirewallPoliciesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.FirewallPoliciesClientListAllResponse]) + + // UpdateTags is the fake for method FirewallPoliciesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.TagsObject, options *armnetwork.FirewallPoliciesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.FirewallPoliciesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewFirewallPoliciesServerTransport creates a new instance of FirewallPoliciesServerTransport with the provided implementation. +// The returned FirewallPoliciesServerTransport instance is connected to an instance of armnetwork.FirewallPoliciesClient by way of the +// undefined.Transporter field. +func NewFirewallPoliciesServerTransport(srv *FirewallPoliciesServer) *FirewallPoliciesServerTransport { + return &FirewallPoliciesServerTransport{srv: srv} +} + +// FirewallPoliciesServerTransport connects instances of armnetwork.FirewallPoliciesClient to instances of FirewallPoliciesServer. +// Don't use this type directly, use NewFirewallPoliciesServerTransport instead. +type FirewallPoliciesServerTransport struct { + srv *FirewallPoliciesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.FirewallPoliciesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.FirewallPoliciesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.FirewallPoliciesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.FirewallPoliciesClientListAllResponse] +} + +// Do implements the policy.Transporter interface for FirewallPoliciesServerTransport. +func (f *FirewallPoliciesServerTransport) 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 "FirewallPoliciesClient.BeginCreateOrUpdate": + resp, err = f.dispatchBeginCreateOrUpdate(req) + case "FirewallPoliciesClient.BeginDelete": + resp, err = f.dispatchBeginDelete(req) + case "FirewallPoliciesClient.Get": + resp, err = f.dispatchGet(req) + case "FirewallPoliciesClient.NewListPager": + resp, err = f.dispatchNewListPager(req) + case "FirewallPoliciesClient.NewListAllPager": + resp, err = f.dispatchNewListAllPager(req) + case "FirewallPoliciesClient.UpdateTags": + resp, err = f.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FirewallPoliciesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if f.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if f.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.FirewallPolicy](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + f.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(f.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(f.beginCreateOrUpdate) { + f.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (f *FirewallPoliciesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if f.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if f.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + f.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(f.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(f.beginDelete) { + f.beginDelete = nil + } + + return resp, nil +} + +func (f *FirewallPoliciesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if f.srv.Get == nil { + 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.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.FirewallPoliciesClientGetOptions + if expandParam != nil { + options = &armnetwork.FirewallPoliciesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).FirewallPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (f *FirewallPoliciesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if f.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if f.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := f.srv.NewListPager(resourceGroupNameUnescaped, nil) + f.newListPager = &resp + server.PagerResponderInjectNextLinks(f.newListPager, req, func(page *armnetwork.FirewallPoliciesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(f.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(f.newListPager) { + f.newListPager = nil + } + return resp, nil +} + +func (f *FirewallPoliciesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if f.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if f.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := f.srv.NewListAllPager(nil) + f.newListAllPager = &resp + server.PagerResponderInjectNextLinks(f.newListAllPager, req, func(page *armnetwork.FirewallPoliciesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(f.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(f.newListAllPager) { + f.newListAllPager = nil + } + return resp, nil +} + +func (f *FirewallPoliciesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if f.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).FirewallPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignatures_server.go b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignatures_server.go new file mode 100644 index 000000000000..a195c5305a95 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignatures_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// FirewallPolicyIdpsSignaturesServer is a fake server for instances of the armnetwork.FirewallPolicyIdpsSignaturesClient type. +type FirewallPolicyIdpsSignaturesServer struct { + // List is the fake for method FirewallPolicyIdpsSignaturesClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.IDPSQueryObject, options *armnetwork.FirewallPolicyIdpsSignaturesClientListOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesClientListResponse], errResp azfake.ErrorResponder) +} + +// NewFirewallPolicyIdpsSignaturesServerTransport creates a new instance of FirewallPolicyIdpsSignaturesServerTransport with the provided implementation. +// The returned FirewallPolicyIdpsSignaturesServerTransport instance is connected to an instance of armnetwork.FirewallPolicyIdpsSignaturesClient by way of the +// undefined.Transporter field. +func NewFirewallPolicyIdpsSignaturesServerTransport(srv *FirewallPolicyIdpsSignaturesServer) *FirewallPolicyIdpsSignaturesServerTransport { + return &FirewallPolicyIdpsSignaturesServerTransport{srv: srv} +} + +// FirewallPolicyIdpsSignaturesServerTransport connects instances of armnetwork.FirewallPolicyIdpsSignaturesClient to instances of FirewallPolicyIdpsSignaturesServer. +// Don't use this type directly, use NewFirewallPolicyIdpsSignaturesServerTransport instead. +type FirewallPolicyIdpsSignaturesServerTransport struct { + srv *FirewallPolicyIdpsSignaturesServer +} + +// Do implements the policy.Transporter interface for FirewallPolicyIdpsSignaturesServerTransport. +func (f *FirewallPolicyIdpsSignaturesServerTransport) 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 "FirewallPolicyIdpsSignaturesClient.List": + resp, err = f.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FirewallPolicyIdpsSignaturesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if f.srv.List == nil { + 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.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listIdpsSignatures` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.IDPSQueryObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.List(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).QueryResults, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignaturesfiltervalues_server.go b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignaturesfiltervalues_server.go new file mode 100644 index 000000000000..3afb0c1d02f8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignaturesfiltervalues_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// FirewallPolicyIdpsSignaturesFilterValuesServer is a fake server for instances of the armnetwork.FirewallPolicyIdpsSignaturesFilterValuesClient type. +type FirewallPolicyIdpsSignaturesFilterValuesServer struct { + // List is the fake for method FirewallPolicyIdpsSignaturesFilterValuesClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.SignatureOverridesFilterValuesQuery, options *armnetwork.FirewallPolicyIdpsSignaturesFilterValuesClientListOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesFilterValuesClientListResponse], errResp azfake.ErrorResponder) +} + +// NewFirewallPolicyIdpsSignaturesFilterValuesServerTransport creates a new instance of FirewallPolicyIdpsSignaturesFilterValuesServerTransport with the provided implementation. +// The returned FirewallPolicyIdpsSignaturesFilterValuesServerTransport instance is connected to an instance of armnetwork.FirewallPolicyIdpsSignaturesFilterValuesClient by way of the +// undefined.Transporter field. +func NewFirewallPolicyIdpsSignaturesFilterValuesServerTransport(srv *FirewallPolicyIdpsSignaturesFilterValuesServer) *FirewallPolicyIdpsSignaturesFilterValuesServerTransport { + return &FirewallPolicyIdpsSignaturesFilterValuesServerTransport{srv: srv} +} + +// FirewallPolicyIdpsSignaturesFilterValuesServerTransport connects instances of armnetwork.FirewallPolicyIdpsSignaturesFilterValuesClient to instances of FirewallPolicyIdpsSignaturesFilterValuesServer. +// Don't use this type directly, use NewFirewallPolicyIdpsSignaturesFilterValuesServerTransport instead. +type FirewallPolicyIdpsSignaturesFilterValuesServerTransport struct { + srv *FirewallPolicyIdpsSignaturesFilterValuesServer +} + +// Do implements the policy.Transporter interface for FirewallPolicyIdpsSignaturesFilterValuesServerTransport. +func (f *FirewallPolicyIdpsSignaturesFilterValuesServerTransport) 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 "FirewallPolicyIdpsSignaturesFilterValuesClient.List": + resp, err = f.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FirewallPolicyIdpsSignaturesFilterValuesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if f.srv.List == nil { + 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.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listIdpsFilterOptions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SignatureOverridesFilterValuesQuery](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.List(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).SignatureOverridesFilterValuesResponse, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignaturesoverrides_server.go b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignaturesoverrides_server.go new file mode 100644 index 000000000000..94fcb87c34bd --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyidpssignaturesoverrides_server.go @@ -0,0 +1,225 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// FirewallPolicyIdpsSignaturesOverridesServer is a fake server for instances of the armnetwork.FirewallPolicyIdpsSignaturesOverridesClient type. +type FirewallPolicyIdpsSignaturesOverridesServer struct { + // Get is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientGetOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientListOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientListResponse], errResp azfake.ErrorResponder) + + // Patch is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.Patch + // HTTP status codes to indicate success: http.StatusOK + Patch func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.SignaturesOverrides, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPatchOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPatchResponse], errResp azfake.ErrorResponder) + + // Put is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.Put + // HTTP status codes to indicate success: http.StatusOK + Put func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.SignaturesOverrides, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPutOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPutResponse], errResp azfake.ErrorResponder) +} + +// NewFirewallPolicyIdpsSignaturesOverridesServerTransport creates a new instance of FirewallPolicyIdpsSignaturesOverridesServerTransport with the provided implementation. +// The returned FirewallPolicyIdpsSignaturesOverridesServerTransport instance is connected to an instance of armnetwork.FirewallPolicyIdpsSignaturesOverridesClient by way of the +// undefined.Transporter field. +func NewFirewallPolicyIdpsSignaturesOverridesServerTransport(srv *FirewallPolicyIdpsSignaturesOverridesServer) *FirewallPolicyIdpsSignaturesOverridesServerTransport { + return &FirewallPolicyIdpsSignaturesOverridesServerTransport{srv: srv} +} + +// FirewallPolicyIdpsSignaturesOverridesServerTransport connects instances of armnetwork.FirewallPolicyIdpsSignaturesOverridesClient to instances of FirewallPolicyIdpsSignaturesOverridesServer. +// Don't use this type directly, use NewFirewallPolicyIdpsSignaturesOverridesServerTransport instead. +type FirewallPolicyIdpsSignaturesOverridesServerTransport struct { + srv *FirewallPolicyIdpsSignaturesOverridesServer +} + +// Do implements the policy.Transporter interface for FirewallPolicyIdpsSignaturesOverridesServerTransport. +func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) 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 "FirewallPolicyIdpsSignaturesOverridesClient.Get": + resp, err = f.dispatchGet(req) + case "FirewallPolicyIdpsSignaturesOverridesClient.List": + resp, err = f.dispatchList(req) + case "FirewallPolicyIdpsSignaturesOverridesClient.Patch": + resp, err = f.dispatchPatch(req) + case "FirewallPolicyIdpsSignaturesOverridesClient.Put": + resp, err = f.dispatchPut(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if f.srv.Get == nil { + 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.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/signatureOverrides/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).SignaturesOverrides, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if f.srv.List == nil { + 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.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/signatureOverrides` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.List(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).SignaturesOverridesList, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchPatch(req *http.Request) (*http.Response, error) { + if f.srv.Patch == nil { + return nil, &nonRetriableError{errors.New("fake for method Patch not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/signatureOverrides/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SignaturesOverrides](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.Patch(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).SignaturesOverrides, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchPut(req *http.Request) (*http.Response, error) { + if f.srv.Put == nil { + return nil, &nonRetriableError{errors.New("fake for method Put not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/signatureOverrides/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SignaturesOverrides](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.Put(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, 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).SignaturesOverrides, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyrulecollectiongroups_server.go b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyrulecollectiongroups_server.go new file mode 100644 index 000000000000..81c465eceb84 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/firewallpolicyrulecollectiongroups_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// FirewallPolicyRuleCollectionGroupsServer is a fake server for instances of the armnetwork.FirewallPolicyRuleCollectionGroupsClient type. +type FirewallPolicyRuleCollectionGroupsServer struct { + // BeginCreateOrUpdate is the fake for method FirewallPolicyRuleCollectionGroupsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, parameters armnetwork.FirewallPolicyRuleCollectionGroup, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method FirewallPolicyRuleCollectionGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method FirewallPolicyRuleCollectionGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientGetOptions) (resp azfake.Responder[armnetwork.FirewallPolicyRuleCollectionGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method FirewallPolicyRuleCollectionGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse]) +} + +// NewFirewallPolicyRuleCollectionGroupsServerTransport creates a new instance of FirewallPolicyRuleCollectionGroupsServerTransport with the provided implementation. +// The returned FirewallPolicyRuleCollectionGroupsServerTransport instance is connected to an instance of armnetwork.FirewallPolicyRuleCollectionGroupsClient by way of the +// undefined.Transporter field. +func NewFirewallPolicyRuleCollectionGroupsServerTransport(srv *FirewallPolicyRuleCollectionGroupsServer) *FirewallPolicyRuleCollectionGroupsServerTransport { + return &FirewallPolicyRuleCollectionGroupsServerTransport{srv: srv} +} + +// FirewallPolicyRuleCollectionGroupsServerTransport connects instances of armnetwork.FirewallPolicyRuleCollectionGroupsClient to instances of FirewallPolicyRuleCollectionGroupsServer. +// Don't use this type directly, use NewFirewallPolicyRuleCollectionGroupsServerTransport instead. +type FirewallPolicyRuleCollectionGroupsServerTransport struct { + srv *FirewallPolicyRuleCollectionGroupsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse] +} + +// Do implements the policy.Transporter interface for FirewallPolicyRuleCollectionGroupsServerTransport. +func (f *FirewallPolicyRuleCollectionGroupsServerTransport) 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 "FirewallPolicyRuleCollectionGroupsClient.BeginCreateOrUpdate": + resp, err = f.dispatchBeginCreateOrUpdate(req) + case "FirewallPolicyRuleCollectionGroupsClient.BeginDelete": + resp, err = f.dispatchBeginDelete(req) + case "FirewallPolicyRuleCollectionGroupsClient.Get": + resp, err = f.dispatchGet(req) + case "FirewallPolicyRuleCollectionGroupsClient.NewListPager": + resp, err = f.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if f.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if f.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.FirewallPolicyRuleCollectionGroup](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + ruleCollectionGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, ruleCollectionGroupNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + f.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(f.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(f.beginCreateOrUpdate) { + f.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if f.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if f.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + ruleCollectionGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, ruleCollectionGroupNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + f.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(f.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(f.beginDelete) { + f.beginDelete = nil + } + + return resp, nil +} + +func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if f.srv.Get == nil { + 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.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + ruleCollectionGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameUnescaped, firewallPolicyNameUnescaped, ruleCollectionGroupNameUnescaped, 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).FirewallPolicyRuleCollectionGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if f.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if f.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/firewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + firewallPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) + if err != nil { + return nil, err + } + resp := f.srv.NewListPager(resourceGroupNameUnescaped, firewallPolicyNameUnescaped, nil) + f.newListPager = &resp + server.PagerResponderInjectNextLinks(f.newListPager, req, func(page *armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(f.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(f.newListPager) { + f.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/flowlogs_server.go b/sdk/resourcemanager/network/armnetwork/fake/flowlogs_server.go new file mode 100644 index 000000000000..2eb325c46bbc --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/flowlogs_server.go @@ -0,0 +1,305 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// FlowLogsServer is a fake server for instances of the armnetwork.FlowLogsClient type. +type FlowLogsServer struct { + // BeginCreateOrUpdate is the fake for method FlowLogsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters armnetwork.FlowLog, options *armnetwork.FlowLogsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.FlowLogsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method FlowLogsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *armnetwork.FlowLogsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.FlowLogsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method FlowLogsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *armnetwork.FlowLogsClientGetOptions) (resp azfake.Responder[armnetwork.FlowLogsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method FlowLogsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkWatcherName string, options *armnetwork.FlowLogsClientListOptions) (resp azfake.PagerResponder[armnetwork.FlowLogsClientListResponse]) + + // UpdateTags is the fake for method FlowLogsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters armnetwork.TagsObject, options *armnetwork.FlowLogsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.FlowLogsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewFlowLogsServerTransport creates a new instance of FlowLogsServerTransport with the provided implementation. +// The returned FlowLogsServerTransport instance is connected to an instance of armnetwork.FlowLogsClient by way of the +// undefined.Transporter field. +func NewFlowLogsServerTransport(srv *FlowLogsServer) *FlowLogsServerTransport { + return &FlowLogsServerTransport{srv: srv} +} + +// FlowLogsServerTransport connects instances of armnetwork.FlowLogsClient to instances of FlowLogsServer. +// Don't use this type directly, use NewFlowLogsServerTransport instead. +type FlowLogsServerTransport struct { + srv *FlowLogsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.FlowLogsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.FlowLogsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.FlowLogsClientListResponse] +} + +// Do implements the policy.Transporter interface for FlowLogsServerTransport. +func (f *FlowLogsServerTransport) 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 "FlowLogsClient.BeginCreateOrUpdate": + resp, err = f.dispatchBeginCreateOrUpdate(req) + case "FlowLogsClient.BeginDelete": + resp, err = f.dispatchBeginDelete(req) + case "FlowLogsClient.Get": + resp, err = f.dispatchGet(req) + case "FlowLogsClient.NewListPager": + resp, err = f.dispatchNewListPager(req) + case "FlowLogsClient.UpdateTags": + resp, err = f.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FlowLogsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if f.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if f.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/flowLogs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.FlowLog](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + flowLogNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("flowLogName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, flowLogNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + f.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(f.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(f.beginCreateOrUpdate) { + f.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (f *FlowLogsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if f.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if f.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/flowLogs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + flowLogNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("flowLogName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, flowLogNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + f.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(f.beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(f.beginDelete) { + f.beginDelete = nil + } + + return resp, nil +} + +func (f *FlowLogsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if f.srv.Get == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/flowLogs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + flowLogNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("flowLogName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, flowLogNameUnescaped, 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).FlowLog, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (f *FlowLogsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if f.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if f.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/flowLogs` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + resp := f.srv.NewListPager(resourceGroupNameUnescaped, networkWatcherNameUnescaped, nil) + f.newListPager = &resp + server.PagerResponderInjectNextLinks(f.newListPager, req, func(page *armnetwork.FlowLogsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(f.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(f.newListPager) { + f.newListPager = nil + } + return resp, nil +} + +func (f *FlowLogsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if f.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/flowLogs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + flowLogNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("flowLogName")]) + if err != nil { + return nil, err + } + respr, errRespr := f.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, flowLogNameUnescaped, 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).FlowLog, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/groups_server.go b/sdk/resourcemanager/network/armnetwork/fake/groups_server.go new file mode 100644 index 000000000000..2d11e57d7ac8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/groups_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// GroupsServer is a fake server for instances of the armnetwork.GroupsClient type. +type GroupsServer struct { + // CreateOrUpdate is the fake for method GroupsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, parameters armnetwork.Group, options *armnetwork.GroupsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.GroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method GroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, options *armnetwork.GroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.GroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method GroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, options *armnetwork.GroupsClientGetOptions) (resp azfake.Responder[armnetwork.GroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method GroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, options *armnetwork.GroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.GroupsClientListResponse]) +} + +// NewGroupsServerTransport creates a new instance of GroupsServerTransport with the provided implementation. +// The returned GroupsServerTransport instance is connected to an instance of armnetwork.GroupsClient by way of the +// undefined.Transporter field. +func NewGroupsServerTransport(srv *GroupsServer) *GroupsServerTransport { + return &GroupsServerTransport{srv: srv} +} + +// GroupsServerTransport connects instances of armnetwork.GroupsClient to instances of GroupsServer. +// Don't use this type directly, use NewGroupsServerTransport instead. +type GroupsServerTransport struct { + srv *GroupsServer + beginDelete *azfake.PollerResponder[armnetwork.GroupsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.GroupsClientListResponse] +} + +// Do implements the policy.Transporter interface for GroupsServerTransport. +func (g *GroupsServerTransport) 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 "GroupsClient.CreateOrUpdate": + resp, err = g.dispatchCreateOrUpdate(req) + case "GroupsClient.BeginDelete": + resp, err = g.dispatchBeginDelete(req) + case "GroupsClient.Get": + resp, err = g.dispatchGet(req) + case "GroupsClient.NewListPager": + resp, err = g.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (g *GroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if g.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Group](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + ifMatchParam := getOptional(getHeaderValue(req.Header, "If-Match")) + var options *armnetwork.GroupsClientCreateOrUpdateOptions + if ifMatchParam != nil { + options = &armnetwork.GroupsClientCreateOrUpdateOptions{ + IfMatch: ifMatchParam, + } + } + respr, errRespr := g.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, body, options) + 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).Group, req) + if err != nil { + return nil, err + } + if val := server.GetResponse(respr).ETag; val != nil { + resp.Header.Set("ETag", *val) + } + return resp, nil +} + +func (g *GroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if g.srv.BeginDelete == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + forceUnescaped, err := url.QueryUnescape(qp.Get("force")) + if err != nil { + return nil, err + } + forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armnetwork.GroupsClientBeginDeleteOptions + if forceParam != nil { + options = &armnetwork.GroupsClientBeginDeleteOptions{ + Force: forceParam, + } + } + respr, errRespr := g.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, options) + 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 *GroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if g.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := g.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, 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).Group, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (g *GroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if g.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if g.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.GroupsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.GroupsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := g.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, options) + g.newListPager = &resp + server.PagerResponderInjectNextLinks(g.newListPager, req, func(page *armnetwork.GroupsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/hubroutetables_server.go b/sdk/resourcemanager/network/armnetwork/fake/hubroutetables_server.go new file mode 100644 index 000000000000..8f1df6fce729 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/hubroutetables_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// HubRouteTablesServer is a fake server for instances of the armnetwork.HubRouteTablesClient type. +type HubRouteTablesServer struct { + // BeginCreateOrUpdate is the fake for method HubRouteTablesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, routeTableParameters armnetwork.HubRouteTable, options *armnetwork.HubRouteTablesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.HubRouteTablesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method HubRouteTablesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *armnetwork.HubRouteTablesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.HubRouteTablesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method HubRouteTablesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *armnetwork.HubRouteTablesClientGetOptions) (resp azfake.Responder[armnetwork.HubRouteTablesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method HubRouteTablesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.HubRouteTablesClientListOptions) (resp azfake.PagerResponder[armnetwork.HubRouteTablesClientListResponse]) +} + +// NewHubRouteTablesServerTransport creates a new instance of HubRouteTablesServerTransport with the provided implementation. +// The returned HubRouteTablesServerTransport instance is connected to an instance of armnetwork.HubRouteTablesClient by way of the +// undefined.Transporter field. +func NewHubRouteTablesServerTransport(srv *HubRouteTablesServer) *HubRouteTablesServerTransport { + return &HubRouteTablesServerTransport{srv: srv} +} + +// HubRouteTablesServerTransport connects instances of armnetwork.HubRouteTablesClient to instances of HubRouteTablesServer. +// Don't use this type directly, use NewHubRouteTablesServerTransport instead. +type HubRouteTablesServerTransport struct { + srv *HubRouteTablesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.HubRouteTablesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.HubRouteTablesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.HubRouteTablesClientListResponse] +} + +// Do implements the policy.Transporter interface for HubRouteTablesServerTransport. +func (h *HubRouteTablesServerTransport) 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 "HubRouteTablesClient.BeginCreateOrUpdate": + resp, err = h.dispatchBeginCreateOrUpdate(req) + case "HubRouteTablesClient.BeginDelete": + resp, err = h.dispatchBeginDelete(req) + case "HubRouteTablesClient.Get": + resp, err = h.dispatchGet(req) + case "HubRouteTablesClient.NewListPager": + resp, err = h.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (h *HubRouteTablesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if h.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if h.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubRouteTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.HubRouteTable](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := h.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeTableNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + h.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(h.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(h.beginCreateOrUpdate) { + h.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (h *HubRouteTablesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if h.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if h.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubRouteTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := h.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeTableNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + h.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(h.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(h.beginDelete) { + h.beginDelete = nil + } + + return resp, nil +} + +func (h *HubRouteTablesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if h.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubRouteTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := h.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeTableNameUnescaped, 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).HubRouteTable, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (h *HubRouteTablesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if h.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if h.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubRouteTables` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := h.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + h.newListPager = &resp + server.PagerResponderInjectNextLinks(h.newListPager, req, func(page *armnetwork.HubRouteTablesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(h.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(h.newListPager) { + h.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/hubvirtualnetworkconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/hubvirtualnetworkconnections_server.go new file mode 100644 index 000000000000..ea74d216b72d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/hubvirtualnetworkconnections_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// HubVirtualNetworkConnectionsServer is a fake server for instances of the armnetwork.HubVirtualNetworkConnectionsClient type. +type HubVirtualNetworkConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method HubVirtualNetworkConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, hubVirtualNetworkConnectionParameters armnetwork.HubVirtualNetworkConnection, options *armnetwork.HubVirtualNetworkConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.HubVirtualNetworkConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method HubVirtualNetworkConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *armnetwork.HubVirtualNetworkConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.HubVirtualNetworkConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method HubVirtualNetworkConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *armnetwork.HubVirtualNetworkConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.HubVirtualNetworkConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method HubVirtualNetworkConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.HubVirtualNetworkConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.HubVirtualNetworkConnectionsClientListResponse]) +} + +// NewHubVirtualNetworkConnectionsServerTransport creates a new instance of HubVirtualNetworkConnectionsServerTransport with the provided implementation. +// The returned HubVirtualNetworkConnectionsServerTransport instance is connected to an instance of armnetwork.HubVirtualNetworkConnectionsClient by way of the +// undefined.Transporter field. +func NewHubVirtualNetworkConnectionsServerTransport(srv *HubVirtualNetworkConnectionsServer) *HubVirtualNetworkConnectionsServerTransport { + return &HubVirtualNetworkConnectionsServerTransport{srv: srv} +} + +// HubVirtualNetworkConnectionsServerTransport connects instances of armnetwork.HubVirtualNetworkConnectionsClient to instances of HubVirtualNetworkConnectionsServer. +// Don't use this type directly, use NewHubVirtualNetworkConnectionsServerTransport instead. +type HubVirtualNetworkConnectionsServerTransport struct { + srv *HubVirtualNetworkConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.HubVirtualNetworkConnectionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.HubVirtualNetworkConnectionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.HubVirtualNetworkConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for HubVirtualNetworkConnectionsServerTransport. +func (h *HubVirtualNetworkConnectionsServerTransport) 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 "HubVirtualNetworkConnectionsClient.BeginCreateOrUpdate": + resp, err = h.dispatchBeginCreateOrUpdate(req) + case "HubVirtualNetworkConnectionsClient.BeginDelete": + resp, err = h.dispatchBeginDelete(req) + case "HubVirtualNetworkConnectionsClient.Get": + resp, err = h.dispatchGet(req) + case "HubVirtualNetworkConnectionsClient.NewListPager": + resp, err = h.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (h *HubVirtualNetworkConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if h.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if h.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubVirtualNetworkConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.HubVirtualNetworkConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := h.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, connectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + h.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(h.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(h.beginCreateOrUpdate) { + h.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (h *HubVirtualNetworkConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if h.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if h.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubVirtualNetworkConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := h.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, connectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + h.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(h.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(h.beginDelete) { + h.beginDelete = nil + } + + return resp, nil +} + +func (h *HubVirtualNetworkConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if h.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubVirtualNetworkConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := h.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, connectionNameUnescaped, 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).HubVirtualNetworkConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (h *HubVirtualNetworkConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if h.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if h.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/hubVirtualNetworkConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := h.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + h.newListPager = &resp + server.PagerResponderInjectNextLinks(h.newListPager, req, func(page *armnetwork.HubVirtualNetworkConnectionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(h.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(h.newListPager) { + h.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/inboundnatrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/inboundnatrules_server.go new file mode 100644 index 000000000000..7310ea27d7db --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/inboundnatrules_server.go @@ -0,0 +1,270 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// InboundNatRulesServer is a fake server for instances of the armnetwork.InboundNatRulesClient type. +type InboundNatRulesServer struct { + // BeginCreateOrUpdate is the fake for method InboundNatRulesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, inboundNatRuleParameters armnetwork.InboundNatRule, options *armnetwork.InboundNatRulesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.InboundNatRulesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method InboundNatRulesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, options *armnetwork.InboundNatRulesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.InboundNatRulesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method InboundNatRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, options *armnetwork.InboundNatRulesClientGetOptions) (resp azfake.Responder[armnetwork.InboundNatRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method InboundNatRulesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.InboundNatRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.InboundNatRulesClientListResponse]) +} + +// NewInboundNatRulesServerTransport creates a new instance of InboundNatRulesServerTransport with the provided implementation. +// The returned InboundNatRulesServerTransport instance is connected to an instance of armnetwork.InboundNatRulesClient by way of the +// undefined.Transporter field. +func NewInboundNatRulesServerTransport(srv *InboundNatRulesServer) *InboundNatRulesServerTransport { + return &InboundNatRulesServerTransport{srv: srv} +} + +// InboundNatRulesServerTransport connects instances of armnetwork.InboundNatRulesClient to instances of InboundNatRulesServer. +// Don't use this type directly, use NewInboundNatRulesServerTransport instead. +type InboundNatRulesServerTransport struct { + srv *InboundNatRulesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.InboundNatRulesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.InboundNatRulesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.InboundNatRulesClientListResponse] +} + +// Do implements the policy.Transporter interface for InboundNatRulesServerTransport. +func (i *InboundNatRulesServerTransport) 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 "InboundNatRulesClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + case "InboundNatRulesClient.BeginDelete": + resp, err = i.dispatchBeginDelete(req) + case "InboundNatRulesClient.Get": + resp, err = i.dispatchGet(req) + case "InboundNatRulesClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *InboundNatRulesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/inboundNatRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.InboundNatRule](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + inboundNatRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("inboundNatRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, inboundNatRuleNameUnescaped, 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 *InboundNatRulesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if i.srv.BeginDelete == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/inboundNatRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + inboundNatRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("inboundNatRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, inboundNatRuleNameUnescaped, 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 *InboundNatRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/inboundNatRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + inboundNatRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("inboundNatRuleName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.InboundNatRulesClientGetOptions + if expandParam != nil { + options = &armnetwork.InboundNatRulesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, inboundNatRuleNameUnescaped, 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).InboundNatRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InboundNatRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if i.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/inboundNatRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + i.newListPager = &resp + server.PagerResponderInjectNextLinks(i.newListPager, req, func(page *armnetwork.InboundNatRulesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/inboundsecurityrule_server.go b/sdk/resourcemanager/network/armnetwork/fake/inboundsecurityrule_server.go new file mode 100644 index 000000000000..b9c288588ba9 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/inboundsecurityrule_server.go @@ -0,0 +1,117 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// InboundSecurityRuleServer is a fake server for instances of the armnetwork.InboundSecurityRuleClient type. +type InboundSecurityRuleServer struct { + // BeginCreateOrUpdate is the fake for method InboundSecurityRuleClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters armnetwork.InboundSecurityRule, options *armnetwork.InboundSecurityRuleClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.InboundSecurityRuleClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewInboundSecurityRuleServerTransport creates a new instance of InboundSecurityRuleServerTransport with the provided implementation. +// The returned InboundSecurityRuleServerTransport instance is connected to an instance of armnetwork.InboundSecurityRuleClient by way of the +// undefined.Transporter field. +func NewInboundSecurityRuleServerTransport(srv *InboundSecurityRuleServer) *InboundSecurityRuleServerTransport { + return &InboundSecurityRuleServerTransport{srv: srv} +} + +// InboundSecurityRuleServerTransport connects instances of armnetwork.InboundSecurityRuleClient to instances of InboundSecurityRuleServer. +// Don't use this type directly, use NewInboundSecurityRuleServerTransport instead. +type InboundSecurityRuleServerTransport struct { + srv *InboundSecurityRuleServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.InboundSecurityRuleClientCreateOrUpdateResponse] +} + +// Do implements the policy.Transporter interface for InboundSecurityRuleServerTransport. +func (i *InboundSecurityRuleServerTransport) 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 "InboundSecurityRuleClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *InboundSecurityRuleServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/inboundSecurityRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.InboundSecurityRule](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + ruleCollectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, ruleCollectionNameUnescaped, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/interfaceipconfigurations_server.go b/sdk/resourcemanager/network/armnetwork/fake/interfaceipconfigurations_server.go new file mode 100644 index 000000000000..e7c1c51cf926 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/interfaceipconfigurations_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// InterfaceIPConfigurationsServer is a fake server for instances of the armnetwork.InterfaceIPConfigurationsClient type. +type InterfaceIPConfigurationsServer struct { + // Get is the fake for method InterfaceIPConfigurationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *armnetwork.InterfaceIPConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.InterfaceIPConfigurationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method InterfaceIPConfigurationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfaceIPConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.InterfaceIPConfigurationsClientListResponse]) +} + +// NewInterfaceIPConfigurationsServerTransport creates a new instance of InterfaceIPConfigurationsServerTransport with the provided implementation. +// The returned InterfaceIPConfigurationsServerTransport instance is connected to an instance of armnetwork.InterfaceIPConfigurationsClient by way of the +// undefined.Transporter field. +func NewInterfaceIPConfigurationsServerTransport(srv *InterfaceIPConfigurationsServer) *InterfaceIPConfigurationsServerTransport { + return &InterfaceIPConfigurationsServerTransport{srv: srv} +} + +// InterfaceIPConfigurationsServerTransport connects instances of armnetwork.InterfaceIPConfigurationsClient to instances of InterfaceIPConfigurationsServer. +// Don't use this type directly, use NewInterfaceIPConfigurationsServerTransport instead. +type InterfaceIPConfigurationsServerTransport struct { + srv *InterfaceIPConfigurationsServer + newListPager *azfake.PagerResponder[armnetwork.InterfaceIPConfigurationsClientListResponse] +} + +// Do implements the policy.Transporter interface for InterfaceIPConfigurationsServerTransport. +func (i *InterfaceIPConfigurationsServerTransport) 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 "InterfaceIPConfigurationsClient.Get": + resp, err = i.dispatchGet(req) + case "InterfaceIPConfigurationsClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *InterfaceIPConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.srv.Get == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + ipConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, ipConfigurationNameUnescaped, 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).InterfaceIPConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InterfaceIPConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if i.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListPager(resourceGroupNameUnescaped, networkInterfaceNameUnescaped, nil) + i.newListPager = &resp + server.PagerResponderInjectNextLinks(i.newListPager, req, func(page *armnetwork.InterfaceIPConfigurationsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/interfaceloadbalancers_server.go b/sdk/resourcemanager/network/armnetwork/fake/interfaceloadbalancers_server.go new file mode 100644 index 000000000000..10c74f52c765 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/interfaceloadbalancers_server.go @@ -0,0 +1,106 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// InterfaceLoadBalancersServer is a fake server for instances of the armnetwork.InterfaceLoadBalancersClient type. +type InterfaceLoadBalancersServer struct { + // NewListPager is the fake for method InterfaceLoadBalancersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfaceLoadBalancersClientListOptions) (resp azfake.PagerResponder[armnetwork.InterfaceLoadBalancersClientListResponse]) +} + +// NewInterfaceLoadBalancersServerTransport creates a new instance of InterfaceLoadBalancersServerTransport with the provided implementation. +// The returned InterfaceLoadBalancersServerTransport instance is connected to an instance of armnetwork.InterfaceLoadBalancersClient by way of the +// undefined.Transporter field. +func NewInterfaceLoadBalancersServerTransport(srv *InterfaceLoadBalancersServer) *InterfaceLoadBalancersServerTransport { + return &InterfaceLoadBalancersServerTransport{srv: srv} +} + +// InterfaceLoadBalancersServerTransport connects instances of armnetwork.InterfaceLoadBalancersClient to instances of InterfaceLoadBalancersServer. +// Don't use this type directly, use NewInterfaceLoadBalancersServerTransport instead. +type InterfaceLoadBalancersServerTransport struct { + srv *InterfaceLoadBalancersServer + newListPager *azfake.PagerResponder[armnetwork.InterfaceLoadBalancersClientListResponse] +} + +// Do implements the policy.Transporter interface for InterfaceLoadBalancersServerTransport. +func (i *InterfaceLoadBalancersServerTransport) 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 "InterfaceLoadBalancersClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *InterfaceLoadBalancersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if i.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/loadBalancers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListPager(resourceGroupNameUnescaped, networkInterfaceNameUnescaped, nil) + i.newListPager = &resp + server.PagerResponderInjectNextLinks(i.newListPager, req, func(page *armnetwork.InterfaceLoadBalancersClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/interfaces_server.go b/sdk/resourcemanager/network/armnetwork/fake/interfaces_server.go new file mode 100644 index 000000000000..a78e5fd5072f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/interfaces_server.go @@ -0,0 +1,864 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// InterfacesServer is a fake server for instances of the armnetwork.InterfacesClient type. +type InterfacesServer struct { + // BeginCreateOrUpdate is the fake for method InterfacesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkInterfaceName string, parameters armnetwork.Interface, options *armnetwork.InterfacesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.InterfacesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method InterfacesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfacesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.InterfacesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method InterfacesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfacesClientGetOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetResponse], errResp azfake.ErrorResponder) + + // GetCloudServiceNetworkInterface is the fake for method InterfacesClient.GetCloudServiceNetworkInterface + // HTTP status codes to indicate success: http.StatusOK + GetCloudServiceNetworkInterface func(ctx context.Context, resourceGroupName string, cloudServiceName string, roleInstanceName string, networkInterfaceName string, options *armnetwork.InterfacesClientGetCloudServiceNetworkInterfaceOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetCloudServiceNetworkInterfaceResponse], errResp azfake.ErrorResponder) + + // BeginGetEffectiveRouteTable is the fake for method InterfacesClient.BeginGetEffectiveRouteTable + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetEffectiveRouteTable func(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfacesClientBeginGetEffectiveRouteTableOptions) (resp azfake.PollerResponder[armnetwork.InterfacesClientGetEffectiveRouteTableResponse], errResp azfake.ErrorResponder) + + // GetVirtualMachineScaleSetIPConfiguration is the fake for method InterfacesClient.GetVirtualMachineScaleSetIPConfiguration + // HTTP status codes to indicate success: http.StatusOK + GetVirtualMachineScaleSetIPConfiguration func(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, ipConfigurationName string, options *armnetwork.InterfacesClientGetVirtualMachineScaleSetIPConfigurationOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetVirtualMachineScaleSetIPConfigurationResponse], errResp azfake.ErrorResponder) + + // GetVirtualMachineScaleSetNetworkInterface is the fake for method InterfacesClient.GetVirtualMachineScaleSetNetworkInterface + // HTTP status codes to indicate success: http.StatusOK + GetVirtualMachineScaleSetNetworkInterface func(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, options *armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method InterfacesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.InterfacesClientListOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListResponse]) + + // NewListAllPager is the fake for method InterfacesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.InterfacesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListAllResponse]) + + // NewListCloudServiceNetworkInterfacesPager is the fake for method InterfacesClient.NewListCloudServiceNetworkInterfacesPager + // HTTP status codes to indicate success: http.StatusOK + NewListCloudServiceNetworkInterfacesPager func(resourceGroupName string, cloudServiceName string, options *armnetwork.InterfacesClientListCloudServiceNetworkInterfacesOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListCloudServiceNetworkInterfacesResponse]) + + // NewListCloudServiceRoleInstanceNetworkInterfacesPager is the fake for method InterfacesClient.NewListCloudServiceRoleInstanceNetworkInterfacesPager + // HTTP status codes to indicate success: http.StatusOK + NewListCloudServiceRoleInstanceNetworkInterfacesPager func(resourceGroupName string, cloudServiceName string, roleInstanceName string, options *armnetwork.InterfacesClientListCloudServiceRoleInstanceNetworkInterfacesOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListCloudServiceRoleInstanceNetworkInterfacesResponse]) + + // BeginListEffectiveNetworkSecurityGroups is the fake for method InterfacesClient.BeginListEffectiveNetworkSecurityGroups + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListEffectiveNetworkSecurityGroups func(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfacesClientBeginListEffectiveNetworkSecurityGroupsOptions) (resp azfake.PollerResponder[armnetwork.InterfacesClientListEffectiveNetworkSecurityGroupsResponse], errResp azfake.ErrorResponder) + + // NewListVirtualMachineScaleSetIPConfigurationsPager is the fake for method InterfacesClient.NewListVirtualMachineScaleSetIPConfigurationsPager + // HTTP status codes to indicate success: http.StatusOK + NewListVirtualMachineScaleSetIPConfigurationsPager func(resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, options *armnetwork.InterfacesClientListVirtualMachineScaleSetIPConfigurationsOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListVirtualMachineScaleSetIPConfigurationsResponse]) + + // NewListVirtualMachineScaleSetNetworkInterfacesPager is the fake for method InterfacesClient.NewListVirtualMachineScaleSetNetworkInterfacesPager + // HTTP status codes to indicate success: http.StatusOK + NewListVirtualMachineScaleSetNetworkInterfacesPager func(resourceGroupName string, virtualMachineScaleSetName string, options *armnetwork.InterfacesClientListVirtualMachineScaleSetNetworkInterfacesOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListVirtualMachineScaleSetNetworkInterfacesResponse]) + + // NewListVirtualMachineScaleSetVMNetworkInterfacesPager is the fake for method InterfacesClient.NewListVirtualMachineScaleSetVMNetworkInterfacesPager + // HTTP status codes to indicate success: http.StatusOK + NewListVirtualMachineScaleSetVMNetworkInterfacesPager func(resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, options *armnetwork.InterfacesClientListVirtualMachineScaleSetVMNetworkInterfacesOptions) (resp azfake.PagerResponder[armnetwork.InterfacesClientListVirtualMachineScaleSetVMNetworkInterfacesResponse]) + + // UpdateTags is the fake for method InterfacesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkInterfaceName string, parameters armnetwork.TagsObject, options *armnetwork.InterfacesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.InterfacesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewInterfacesServerTransport creates a new instance of InterfacesServerTransport with the provided implementation. +// The returned InterfacesServerTransport instance is connected to an instance of armnetwork.InterfacesClient by way of the +// undefined.Transporter field. +func NewInterfacesServerTransport(srv *InterfacesServer) *InterfacesServerTransport { + return &InterfacesServerTransport{srv: srv} +} + +// InterfacesServerTransport connects instances of armnetwork.InterfacesClient to instances of InterfacesServer. +// Don't use this type directly, use NewInterfacesServerTransport instead. +type InterfacesServerTransport struct { + srv *InterfacesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.InterfacesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.InterfacesClientDeleteResponse] + beginGetEffectiveRouteTable *azfake.PollerResponder[armnetwork.InterfacesClientGetEffectiveRouteTableResponse] + newListPager *azfake.PagerResponder[armnetwork.InterfacesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.InterfacesClientListAllResponse] + newListCloudServiceNetworkInterfacesPager *azfake.PagerResponder[armnetwork.InterfacesClientListCloudServiceNetworkInterfacesResponse] + newListCloudServiceRoleInstanceNetworkInterfacesPager *azfake.PagerResponder[armnetwork.InterfacesClientListCloudServiceRoleInstanceNetworkInterfacesResponse] + beginListEffectiveNetworkSecurityGroups *azfake.PollerResponder[armnetwork.InterfacesClientListEffectiveNetworkSecurityGroupsResponse] + newListVirtualMachineScaleSetIPConfigurationsPager *azfake.PagerResponder[armnetwork.InterfacesClientListVirtualMachineScaleSetIPConfigurationsResponse] + newListVirtualMachineScaleSetNetworkInterfacesPager *azfake.PagerResponder[armnetwork.InterfacesClientListVirtualMachineScaleSetNetworkInterfacesResponse] + newListVirtualMachineScaleSetVMNetworkInterfacesPager *azfake.PagerResponder[armnetwork.InterfacesClientListVirtualMachineScaleSetVMNetworkInterfacesResponse] +} + +// Do implements the policy.Transporter interface for InterfacesServerTransport. +func (i *InterfacesServerTransport) 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 "InterfacesClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + case "InterfacesClient.BeginDelete": + resp, err = i.dispatchBeginDelete(req) + case "InterfacesClient.Get": + resp, err = i.dispatchGet(req) + case "InterfacesClient.GetCloudServiceNetworkInterface": + resp, err = i.dispatchGetCloudServiceNetworkInterface(req) + case "InterfacesClient.BeginGetEffectiveRouteTable": + resp, err = i.dispatchBeginGetEffectiveRouteTable(req) + case "InterfacesClient.GetVirtualMachineScaleSetIPConfiguration": + resp, err = i.dispatchGetVirtualMachineScaleSetIPConfiguration(req) + case "InterfacesClient.GetVirtualMachineScaleSetNetworkInterface": + resp, err = i.dispatchGetVirtualMachineScaleSetNetworkInterface(req) + case "InterfacesClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + case "InterfacesClient.NewListAllPager": + resp, err = i.dispatchNewListAllPager(req) + case "InterfacesClient.NewListCloudServiceNetworkInterfacesPager": + resp, err = i.dispatchNewListCloudServiceNetworkInterfacesPager(req) + case "InterfacesClient.NewListCloudServiceRoleInstanceNetworkInterfacesPager": + resp, err = i.dispatchNewListCloudServiceRoleInstanceNetworkInterfacesPager(req) + case "InterfacesClient.BeginListEffectiveNetworkSecurityGroups": + resp, err = i.dispatchBeginListEffectiveNetworkSecurityGroups(req) + case "InterfacesClient.NewListVirtualMachineScaleSetIPConfigurationsPager": + resp, err = i.dispatchNewListVirtualMachineScaleSetIPConfigurationsPager(req) + case "InterfacesClient.NewListVirtualMachineScaleSetNetworkInterfacesPager": + resp, err = i.dispatchNewListVirtualMachineScaleSetNetworkInterfacesPager(req) + case "InterfacesClient.NewListVirtualMachineScaleSetVMNetworkInterfacesPager": + resp, err = i.dispatchNewListVirtualMachineScaleSetVMNetworkInterfacesPager(req) + case "InterfacesClient.UpdateTags": + resp, err = i.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Interface](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, 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 *InterfacesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if i.srv.BeginDelete == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, 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 *InterfacesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.srv.Get == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.InterfacesClientGetOptions + if expandParam != nil { + options = &armnetwork.InterfacesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, 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).Interface, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchGetCloudServiceNetworkInterface(req *http.Request) (*http.Response, error) { + if i.srv.GetCloudServiceNetworkInterface == nil { + return nil, &nonRetriableError{errors.New("fake for method GetCloudServiceNetworkInterface 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + 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 + } + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.InterfacesClientGetCloudServiceNetworkInterfaceOptions + if expandParam != nil { + options = &armnetwork.InterfacesClientGetCloudServiceNetworkInterfaceOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.GetCloudServiceNetworkInterface(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, roleInstanceNameUnescaped, networkInterfaceNameUnescaped, 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).Interface, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchBeginGetEffectiveRouteTable(req *http.Request) (*http.Response, error) { + if i.srv.BeginGetEffectiveRouteTable == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetEffectiveRouteTable not implemented")} + } + if i.beginGetEffectiveRouteTable == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/effectiveRouteTable` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginGetEffectiveRouteTable(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + i.beginGetEffectiveRouteTable = &respr + } + + resp, err := server.PollerResponderNext(i.beginGetEffectiveRouteTable, 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(i.beginGetEffectiveRouteTable) { + i.beginGetEffectiveRouteTable = nil + } + + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchGetVirtualMachineScaleSetIPConfiguration(req *http.Request) (*http.Response, error) { + if i.srv.GetVirtualMachineScaleSetIPConfiguration == nil { + return nil, &nonRetriableError{errors.New("fake for method GetVirtualMachineScaleSetIPConfiguration 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + 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 + } + virtualmachineIndexUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualmachineIndex")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + ipConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.InterfacesClientGetVirtualMachineScaleSetIPConfigurationOptions + if expandParam != nil { + options = &armnetwork.InterfacesClientGetVirtualMachineScaleSetIPConfigurationOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.GetVirtualMachineScaleSetIPConfiguration(req.Context(), resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, virtualmachineIndexUnescaped, networkInterfaceNameUnescaped, ipConfigurationNameUnescaped, 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).InterfaceIPConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchGetVirtualMachineScaleSetNetworkInterface(req *http.Request) (*http.Response, error) { + if i.srv.GetVirtualMachineScaleSetNetworkInterface == nil { + return nil, &nonRetriableError{errors.New("fake for method GetVirtualMachineScaleSetNetworkInterface 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + 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 + } + virtualmachineIndexUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualmachineIndex")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions + if expandParam != nil { + options = &armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.GetVirtualMachineScaleSetNetworkInterface(req.Context(), resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, virtualmachineIndexUnescaped, networkInterfaceNameUnescaped, 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).Interface, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if i.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListPager(resourceGroupNameUnescaped, nil) + i.newListPager = &resp + server.PagerResponderInjectNextLinks(i.newListPager, req, func(page *armnetwork.InterfacesClientListResponse, 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 *InterfacesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if i.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := i.srv.NewListAllPager(nil) + i.newListAllPager = &resp + server.PagerResponderInjectNextLinks(i.newListAllPager, req, func(page *armnetwork.InterfacesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.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(i.newListAllPager) { + i.newListAllPager = nil + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchNewListCloudServiceNetworkInterfacesPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListCloudServiceNetworkInterfacesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListCloudServiceNetworkInterfacesPager not implemented")} + } + if i.newListCloudServiceNetworkInterfacesPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 := i.srv.NewListCloudServiceNetworkInterfacesPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) + i.newListCloudServiceNetworkInterfacesPager = &resp + server.PagerResponderInjectNextLinks(i.newListCloudServiceNetworkInterfacesPager, req, func(page *armnetwork.InterfacesClientListCloudServiceNetworkInterfacesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.newListCloudServiceNetworkInterfacesPager, 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.newListCloudServiceNetworkInterfacesPager) { + i.newListCloudServiceNetworkInterfacesPager = nil + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchNewListCloudServiceRoleInstanceNetworkInterfacesPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListCloudServiceRoleInstanceNetworkInterfacesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListCloudServiceRoleInstanceNetworkInterfacesPager not implemented")} + } + if i.newListCloudServiceRoleInstanceNetworkInterfacesPager == 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~%@]+)/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 + } + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListCloudServiceRoleInstanceNetworkInterfacesPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, roleInstanceNameUnescaped, nil) + i.newListCloudServiceRoleInstanceNetworkInterfacesPager = &resp + server.PagerResponderInjectNextLinks(i.newListCloudServiceRoleInstanceNetworkInterfacesPager, req, func(page *armnetwork.InterfacesClientListCloudServiceRoleInstanceNetworkInterfacesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.newListCloudServiceRoleInstanceNetworkInterfacesPager, 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.newListCloudServiceRoleInstanceNetworkInterfacesPager) { + i.newListCloudServiceRoleInstanceNetworkInterfacesPager = nil + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchBeginListEffectiveNetworkSecurityGroups(req *http.Request) (*http.Response, error) { + if i.srv.BeginListEffectiveNetworkSecurityGroups == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListEffectiveNetworkSecurityGroups not implemented")} + } + if i.beginListEffectiveNetworkSecurityGroups == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/effectiveNetworkSecurityGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginListEffectiveNetworkSecurityGroups(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + i.beginListEffectiveNetworkSecurityGroups = &respr + } + + resp, err := server.PollerResponderNext(i.beginListEffectiveNetworkSecurityGroups, 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(i.beginListEffectiveNetworkSecurityGroups) { + i.beginListEffectiveNetworkSecurityGroups = nil + } + + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchNewListVirtualMachineScaleSetIPConfigurationsPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListVirtualMachineScaleSetIPConfigurationsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListVirtualMachineScaleSetIPConfigurationsPager not implemented")} + } + if i.newListVirtualMachineScaleSetIPConfigurationsPager == 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations` + regex := regexp.MustCompile(regexStr) + 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() + 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 + } + virtualmachineIndexUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualmachineIndex")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.InterfacesClientListVirtualMachineScaleSetIPConfigurationsOptions + if expandParam != nil { + options = &armnetwork.InterfacesClientListVirtualMachineScaleSetIPConfigurationsOptions{ + Expand: expandParam, + } + } + resp := i.srv.NewListVirtualMachineScaleSetIPConfigurationsPager(resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, virtualmachineIndexUnescaped, networkInterfaceNameUnescaped, options) + i.newListVirtualMachineScaleSetIPConfigurationsPager = &resp + server.PagerResponderInjectNextLinks(i.newListVirtualMachineScaleSetIPConfigurationsPager, req, func(page *armnetwork.InterfacesClientListVirtualMachineScaleSetIPConfigurationsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.newListVirtualMachineScaleSetIPConfigurationsPager, 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.newListVirtualMachineScaleSetIPConfigurationsPager) { + i.newListVirtualMachineScaleSetIPConfigurationsPager = nil + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchNewListVirtualMachineScaleSetNetworkInterfacesPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListVirtualMachineScaleSetNetworkInterfacesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListVirtualMachineScaleSetNetworkInterfacesPager not implemented")} + } + if i.newListVirtualMachineScaleSetNetworkInterfacesPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 + } + resp := i.srv.NewListVirtualMachineScaleSetNetworkInterfacesPager(resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, nil) + i.newListVirtualMachineScaleSetNetworkInterfacesPager = &resp + server.PagerResponderInjectNextLinks(i.newListVirtualMachineScaleSetNetworkInterfacesPager, req, func(page *armnetwork.InterfacesClientListVirtualMachineScaleSetNetworkInterfacesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.newListVirtualMachineScaleSetNetworkInterfacesPager, 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.newListVirtualMachineScaleSetNetworkInterfacesPager) { + i.newListVirtualMachineScaleSetNetworkInterfacesPager = nil + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchNewListVirtualMachineScaleSetVMNetworkInterfacesPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListVirtualMachineScaleSetVMNetworkInterfacesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListVirtualMachineScaleSetVMNetworkInterfacesPager not implemented")} + } + if i.newListVirtualMachineScaleSetVMNetworkInterfacesPager == 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~%@]+)/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 + } + virtualmachineIndexUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualmachineIndex")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListVirtualMachineScaleSetVMNetworkInterfacesPager(resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, virtualmachineIndexUnescaped, nil) + i.newListVirtualMachineScaleSetVMNetworkInterfacesPager = &resp + server.PagerResponderInjectNextLinks(i.newListVirtualMachineScaleSetVMNetworkInterfacesPager, req, func(page *armnetwork.InterfacesClientListVirtualMachineScaleSetVMNetworkInterfacesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(i.newListVirtualMachineScaleSetVMNetworkInterfacesPager, 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.newListVirtualMachineScaleSetVMNetworkInterfacesPager) { + i.newListVirtualMachineScaleSetVMNetworkInterfacesPager = nil + } + return resp, nil +} + +func (i *InterfacesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if i.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, 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).Interface, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/interfacetapconfigurations_server.go b/sdk/resourcemanager/network/armnetwork/fake/interfacetapconfigurations_server.go new file mode 100644 index 000000000000..9308041f97fa --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/interfacetapconfigurations_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// InterfaceTapConfigurationsServer is a fake server for instances of the armnetwork.InterfaceTapConfigurationsClient type. +type InterfaceTapConfigurationsServer struct { + // BeginCreateOrUpdate is the fake for method InterfaceTapConfigurationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkInterfaceName string, tapConfigurationName string, tapConfigurationParameters armnetwork.InterfaceTapConfiguration, options *armnetwork.InterfaceTapConfigurationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.InterfaceTapConfigurationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method InterfaceTapConfigurationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkInterfaceName string, tapConfigurationName string, options *armnetwork.InterfaceTapConfigurationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.InterfaceTapConfigurationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method InterfaceTapConfigurationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkInterfaceName string, tapConfigurationName string, options *armnetwork.InterfaceTapConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.InterfaceTapConfigurationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method InterfaceTapConfigurationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfaceTapConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.InterfaceTapConfigurationsClientListResponse]) +} + +// NewInterfaceTapConfigurationsServerTransport creates a new instance of InterfaceTapConfigurationsServerTransport with the provided implementation. +// The returned InterfaceTapConfigurationsServerTransport instance is connected to an instance of armnetwork.InterfaceTapConfigurationsClient by way of the +// undefined.Transporter field. +func NewInterfaceTapConfigurationsServerTransport(srv *InterfaceTapConfigurationsServer) *InterfaceTapConfigurationsServerTransport { + return &InterfaceTapConfigurationsServerTransport{srv: srv} +} + +// InterfaceTapConfigurationsServerTransport connects instances of armnetwork.InterfaceTapConfigurationsClient to instances of InterfaceTapConfigurationsServer. +// Don't use this type directly, use NewInterfaceTapConfigurationsServerTransport instead. +type InterfaceTapConfigurationsServerTransport struct { + srv *InterfaceTapConfigurationsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.InterfaceTapConfigurationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.InterfaceTapConfigurationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.InterfaceTapConfigurationsClientListResponse] +} + +// Do implements the policy.Transporter interface for InterfaceTapConfigurationsServerTransport. +func (i *InterfaceTapConfigurationsServerTransport) 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 "InterfaceTapConfigurationsClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + case "InterfaceTapConfigurationsClient.BeginDelete": + resp, err = i.dispatchBeginDelete(req) + case "InterfaceTapConfigurationsClient.Get": + resp, err = i.dispatchGet(req) + case "InterfaceTapConfigurationsClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *InterfaceTapConfigurationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tapConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.InterfaceTapConfiguration](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + tapConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, tapConfigurationNameUnescaped, 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 *InterfaceTapConfigurationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if i.srv.BeginDelete == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tapConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + tapConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, tapConfigurationNameUnescaped, 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 *InterfaceTapConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.srv.Get == nil { + 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.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tapConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + tapConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, networkInterfaceNameUnescaped, tapConfigurationNameUnescaped, 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).InterfaceTapConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *InterfaceTapConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if i.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tapConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + resp := i.srv.NewListPager(resourceGroupNameUnescaped, networkInterfaceNameUnescaped, nil) + i.newListPager = &resp + server.PagerResponderInjectNextLinks(i.newListPager, req, func(page *armnetwork.InterfaceTapConfigurationsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/internal.go b/sdk/resourcemanager/network/armnetwork/fake/internal.go new file mode 100644 index 000000000000..e9c8222f2199 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/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/network/armnetwork/fake/ipallocations_server.go b/sdk/resourcemanager/network/armnetwork/fake/ipallocations_server.go new file mode 100644 index 000000000000..fa2b84a16f86 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/ipallocations_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// IPAllocationsServer is a fake server for instances of the armnetwork.IPAllocationsClient type. +type IPAllocationsServer struct { + // BeginCreateOrUpdate is the fake for method IPAllocationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, ipAllocationName string, parameters armnetwork.IPAllocation, options *armnetwork.IPAllocationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.IPAllocationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method IPAllocationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, ipAllocationName string, options *armnetwork.IPAllocationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.IPAllocationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method IPAllocationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, ipAllocationName string, options *armnetwork.IPAllocationsClientGetOptions) (resp azfake.Responder[armnetwork.IPAllocationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method IPAllocationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.IPAllocationsClientListOptions) (resp azfake.PagerResponder[armnetwork.IPAllocationsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method IPAllocationsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.IPAllocationsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.IPAllocationsClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method IPAllocationsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, ipAllocationName string, parameters armnetwork.TagsObject, options *armnetwork.IPAllocationsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.IPAllocationsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewIPAllocationsServerTransport creates a new instance of IPAllocationsServerTransport with the provided implementation. +// The returned IPAllocationsServerTransport instance is connected to an instance of armnetwork.IPAllocationsClient by way of the +// undefined.Transporter field. +func NewIPAllocationsServerTransport(srv *IPAllocationsServer) *IPAllocationsServerTransport { + return &IPAllocationsServerTransport{srv: srv} +} + +// IPAllocationsServerTransport connects instances of armnetwork.IPAllocationsClient to instances of IPAllocationsServer. +// Don't use this type directly, use NewIPAllocationsServerTransport instead. +type IPAllocationsServerTransport struct { + srv *IPAllocationsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.IPAllocationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.IPAllocationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.IPAllocationsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.IPAllocationsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for IPAllocationsServerTransport. +func (i *IPAllocationsServerTransport) 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 "IPAllocationsClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + case "IPAllocationsClient.BeginDelete": + resp, err = i.dispatchBeginDelete(req) + case "IPAllocationsClient.Get": + resp, err = i.dispatchGet(req) + case "IPAllocationsClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + case "IPAllocationsClient.NewListByResourceGroupPager": + resp, err = i.dispatchNewListByResourceGroupPager(req) + case "IPAllocationsClient.UpdateTags": + resp, err = i.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *IPAllocationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + 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.Network/IpAllocations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.IPAllocation](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipAllocationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipAllocationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, ipAllocationNameUnescaped, 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 *IPAllocationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if i.srv.BeginDelete == nil { + 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.Network/IpAllocations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipAllocationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipAllocationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, ipAllocationNameUnescaped, 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 *IPAllocationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.srv.Get == nil { + 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.Network/IpAllocations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipAllocationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipAllocationName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.IPAllocationsClientGetOptions + if expandParam != nil { + options = &armnetwork.IPAllocationsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, ipAllocationNameUnescaped, 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).IPAllocation, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *IPAllocationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + 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.Network/IpAllocations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.IPAllocationsClientListResponse, 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 *IPAllocationsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListByResourceGroupPager == nil { + 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.Network/IpAllocations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.IPAllocationsClientListByResourceGroupResponse, 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 *IPAllocationsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if i.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/IpAllocations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipAllocationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipAllocationName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, ipAllocationNameUnescaped, 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).IPAllocation, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/ipgroups_server.go b/sdk/resourcemanager/network/armnetwork/fake/ipgroups_server.go new file mode 100644 index 000000000000..53b726a482fa --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/ipgroups_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// IPGroupsServer is a fake server for instances of the armnetwork.IPGroupsClient type. +type IPGroupsServer struct { + // BeginCreateOrUpdate is the fake for method IPGroupsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, ipGroupsName string, parameters armnetwork.IPGroup, options *armnetwork.IPGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.IPGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method IPGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, ipGroupsName string, options *armnetwork.IPGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.IPGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method IPGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, ipGroupsName string, options *armnetwork.IPGroupsClientGetOptions) (resp azfake.Responder[armnetwork.IPGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method IPGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.IPGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.IPGroupsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method IPGroupsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.IPGroupsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.IPGroupsClientListByResourceGroupResponse]) + + // UpdateGroups is the fake for method IPGroupsClient.UpdateGroups + // HTTP status codes to indicate success: http.StatusOK + UpdateGroups func(ctx context.Context, resourceGroupName string, ipGroupsName string, parameters armnetwork.TagsObject, options *armnetwork.IPGroupsClientUpdateGroupsOptions) (resp azfake.Responder[armnetwork.IPGroupsClientUpdateGroupsResponse], errResp azfake.ErrorResponder) +} + +// NewIPGroupsServerTransport creates a new instance of IPGroupsServerTransport with the provided implementation. +// The returned IPGroupsServerTransport instance is connected to an instance of armnetwork.IPGroupsClient by way of the +// undefined.Transporter field. +func NewIPGroupsServerTransport(srv *IPGroupsServer) *IPGroupsServerTransport { + return &IPGroupsServerTransport{srv: srv} +} + +// IPGroupsServerTransport connects instances of armnetwork.IPGroupsClient to instances of IPGroupsServer. +// Don't use this type directly, use NewIPGroupsServerTransport instead. +type IPGroupsServerTransport struct { + srv *IPGroupsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.IPGroupsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.IPGroupsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.IPGroupsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.IPGroupsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for IPGroupsServerTransport. +func (i *IPGroupsServerTransport) 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 "IPGroupsClient.BeginCreateOrUpdate": + resp, err = i.dispatchBeginCreateOrUpdate(req) + case "IPGroupsClient.BeginDelete": + resp, err = i.dispatchBeginDelete(req) + case "IPGroupsClient.Get": + resp, err = i.dispatchGet(req) + case "IPGroupsClient.NewListPager": + resp, err = i.dispatchNewListPager(req) + case "IPGroupsClient.NewListByResourceGroupPager": + resp, err = i.dispatchNewListByResourceGroupPager(req) + case "IPGroupsClient.UpdateGroups": + resp, err = i.dispatchUpdateGroups(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (i *IPGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if i.srv.BeginCreateOrUpdate == nil { + 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.Network/ipGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.IPGroup](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipGroupsNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipGroupsName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, ipGroupsNameUnescaped, 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 *IPGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if i.srv.BeginDelete == nil { + 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.Network/ipGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipGroupsNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipGroupsName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, ipGroupsNameUnescaped, 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 *IPGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if i.srv.Get == nil { + 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.Network/ipGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipGroupsNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipGroupsName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.IPGroupsClientGetOptions + if expandParam != nil { + options = &armnetwork.IPGroupsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameUnescaped, ipGroupsNameUnescaped, 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).IPGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (i *IPGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListPager == nil { + 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.Network/ipGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.IPGroupsClientListResponse, 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 *IPGroupsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if i.srv.NewListByResourceGroupPager == nil { + 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.Network/ipGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.IPGroupsClientListByResourceGroupResponse, 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 *IPGroupsServerTransport) dispatchUpdateGroups(req *http.Request) (*http.Response, error) { + if i.srv.UpdateGroups == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateGroups not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ipGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + ipGroupsNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipGroupsName")]) + if err != nil { + return nil, err + } + respr, errRespr := i.srv.UpdateGroups(req.Context(), resourceGroupNameUnescaped, ipGroupsNameUnescaped, 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).IPGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalancerbackendaddresspools_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerbackendaddresspools_server.go new file mode 100644 index 000000000000..ad06d42357f8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerbackendaddresspools_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancerBackendAddressPoolsServer is a fake server for instances of the armnetwork.LoadBalancerBackendAddressPoolsClient type. +type LoadBalancerBackendAddressPoolsServer struct { + // BeginCreateOrUpdate is the fake for method LoadBalancerBackendAddressPoolsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, parameters armnetwork.BackendAddressPool, options *armnetwork.LoadBalancerBackendAddressPoolsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.LoadBalancerBackendAddressPoolsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method LoadBalancerBackendAddressPoolsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, options *armnetwork.LoadBalancerBackendAddressPoolsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.LoadBalancerBackendAddressPoolsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method LoadBalancerBackendAddressPoolsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, options *armnetwork.LoadBalancerBackendAddressPoolsClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancerBackendAddressPoolsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LoadBalancerBackendAddressPoolsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerBackendAddressPoolsClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerBackendAddressPoolsClientListResponse]) +} + +// NewLoadBalancerBackendAddressPoolsServerTransport creates a new instance of LoadBalancerBackendAddressPoolsServerTransport with the provided implementation. +// The returned LoadBalancerBackendAddressPoolsServerTransport instance is connected to an instance of armnetwork.LoadBalancerBackendAddressPoolsClient by way of the +// undefined.Transporter field. +func NewLoadBalancerBackendAddressPoolsServerTransport(srv *LoadBalancerBackendAddressPoolsServer) *LoadBalancerBackendAddressPoolsServerTransport { + return &LoadBalancerBackendAddressPoolsServerTransport{srv: srv} +} + +// LoadBalancerBackendAddressPoolsServerTransport connects instances of armnetwork.LoadBalancerBackendAddressPoolsClient to instances of LoadBalancerBackendAddressPoolsServer. +// Don't use this type directly, use NewLoadBalancerBackendAddressPoolsServerTransport instead. +type LoadBalancerBackendAddressPoolsServerTransport struct { + srv *LoadBalancerBackendAddressPoolsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.LoadBalancerBackendAddressPoolsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.LoadBalancerBackendAddressPoolsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.LoadBalancerBackendAddressPoolsClientListResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancerBackendAddressPoolsServerTransport. +func (l *LoadBalancerBackendAddressPoolsServerTransport) 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 "LoadBalancerBackendAddressPoolsClient.BeginCreateOrUpdate": + resp, err = l.dispatchBeginCreateOrUpdate(req) + case "LoadBalancerBackendAddressPoolsClient.BeginDelete": + resp, err = l.dispatchBeginDelete(req) + case "LoadBalancerBackendAddressPoolsClient.Get": + resp, err = l.dispatchGet(req) + case "LoadBalancerBackendAddressPoolsClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancerBackendAddressPoolsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if l.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if l.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/backendAddressPools/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.BackendAddressPool](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + backendAddressPoolNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("backendAddressPoolName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, backendAddressPoolNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(l.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(l.beginCreateOrUpdate) { + l.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (l *LoadBalancerBackendAddressPoolsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if l.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if l.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/backendAddressPools/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + backendAddressPoolNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("backendAddressPoolName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, backendAddressPoolNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(l.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(l.beginDelete) { + l.beginDelete = nil + } + + return resp, nil +} + +func (l *LoadBalancerBackendAddressPoolsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/backendAddressPools/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + backendAddressPoolNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("backendAddressPoolName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, backendAddressPoolNameUnescaped, 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).BackendAddressPool, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LoadBalancerBackendAddressPoolsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/backendAddressPools` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancerBackendAddressPoolsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalancerfrontendipconfigurations_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerfrontendipconfigurations_server.go new file mode 100644 index 000000000000..a0a4933eec5c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerfrontendipconfigurations_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancerFrontendIPConfigurationsServer is a fake server for instances of the armnetwork.LoadBalancerFrontendIPConfigurationsClient type. +type LoadBalancerFrontendIPConfigurationsServer struct { + // Get is the fake for method LoadBalancerFrontendIPConfigurationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, frontendIPConfigurationName string, options *armnetwork.LoadBalancerFrontendIPConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancerFrontendIPConfigurationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LoadBalancerFrontendIPConfigurationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerFrontendIPConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerFrontendIPConfigurationsClientListResponse]) +} + +// NewLoadBalancerFrontendIPConfigurationsServerTransport creates a new instance of LoadBalancerFrontendIPConfigurationsServerTransport with the provided implementation. +// The returned LoadBalancerFrontendIPConfigurationsServerTransport instance is connected to an instance of armnetwork.LoadBalancerFrontendIPConfigurationsClient by way of the +// undefined.Transporter field. +func NewLoadBalancerFrontendIPConfigurationsServerTransport(srv *LoadBalancerFrontendIPConfigurationsServer) *LoadBalancerFrontendIPConfigurationsServerTransport { + return &LoadBalancerFrontendIPConfigurationsServerTransport{srv: srv} +} + +// LoadBalancerFrontendIPConfigurationsServerTransport connects instances of armnetwork.LoadBalancerFrontendIPConfigurationsClient to instances of LoadBalancerFrontendIPConfigurationsServer. +// Don't use this type directly, use NewLoadBalancerFrontendIPConfigurationsServerTransport instead. +type LoadBalancerFrontendIPConfigurationsServerTransport struct { + srv *LoadBalancerFrontendIPConfigurationsServer + newListPager *azfake.PagerResponder[armnetwork.LoadBalancerFrontendIPConfigurationsClientListResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancerFrontendIPConfigurationsServerTransport. +func (l *LoadBalancerFrontendIPConfigurationsServerTransport) 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 "LoadBalancerFrontendIPConfigurationsClient.Get": + resp, err = l.dispatchGet(req) + case "LoadBalancerFrontendIPConfigurationsClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancerFrontendIPConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/frontendIPConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + frontendIPConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("frontendIPConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, frontendIPConfigurationNameUnescaped, 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).FrontendIPConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LoadBalancerFrontendIPConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/frontendIPConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancerFrontendIPConfigurationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalancerloadbalancingrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerloadbalancingrules_server.go new file mode 100644 index 000000000000..b23394c296cc --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerloadbalancingrules_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancerLoadBalancingRulesServer is a fake server for instances of the armnetwork.LoadBalancerLoadBalancingRulesClient type. +type LoadBalancerLoadBalancingRulesServer struct { + // Get is the fake for method LoadBalancerLoadBalancingRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, loadBalancingRuleName string, options *armnetwork.LoadBalancerLoadBalancingRulesClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancerLoadBalancingRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LoadBalancerLoadBalancingRulesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerLoadBalancingRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerLoadBalancingRulesClientListResponse]) +} + +// NewLoadBalancerLoadBalancingRulesServerTransport creates a new instance of LoadBalancerLoadBalancingRulesServerTransport with the provided implementation. +// The returned LoadBalancerLoadBalancingRulesServerTransport instance is connected to an instance of armnetwork.LoadBalancerLoadBalancingRulesClient by way of the +// undefined.Transporter field. +func NewLoadBalancerLoadBalancingRulesServerTransport(srv *LoadBalancerLoadBalancingRulesServer) *LoadBalancerLoadBalancingRulesServerTransport { + return &LoadBalancerLoadBalancingRulesServerTransport{srv: srv} +} + +// LoadBalancerLoadBalancingRulesServerTransport connects instances of armnetwork.LoadBalancerLoadBalancingRulesClient to instances of LoadBalancerLoadBalancingRulesServer. +// Don't use this type directly, use NewLoadBalancerLoadBalancingRulesServerTransport instead. +type LoadBalancerLoadBalancingRulesServerTransport struct { + srv *LoadBalancerLoadBalancingRulesServer + newListPager *azfake.PagerResponder[armnetwork.LoadBalancerLoadBalancingRulesClientListResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancerLoadBalancingRulesServerTransport. +func (l *LoadBalancerLoadBalancingRulesServerTransport) 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 "LoadBalancerLoadBalancingRulesClient.Get": + resp, err = l.dispatchGet(req) + case "LoadBalancerLoadBalancingRulesClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancerLoadBalancingRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/loadBalancingRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + loadBalancingRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancingRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, loadBalancingRuleNameUnescaped, 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).LoadBalancingRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LoadBalancerLoadBalancingRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/loadBalancingRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancerLoadBalancingRulesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalancernetworkinterfaces_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalancernetworkinterfaces_server.go new file mode 100644 index 000000000000..ba276df99cfe --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalancernetworkinterfaces_server.go @@ -0,0 +1,106 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancerNetworkInterfacesServer is a fake server for instances of the armnetwork.LoadBalancerNetworkInterfacesClient type. +type LoadBalancerNetworkInterfacesServer struct { + // NewListPager is the fake for method LoadBalancerNetworkInterfacesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerNetworkInterfacesClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerNetworkInterfacesClientListResponse]) +} + +// NewLoadBalancerNetworkInterfacesServerTransport creates a new instance of LoadBalancerNetworkInterfacesServerTransport with the provided implementation. +// The returned LoadBalancerNetworkInterfacesServerTransport instance is connected to an instance of armnetwork.LoadBalancerNetworkInterfacesClient by way of the +// undefined.Transporter field. +func NewLoadBalancerNetworkInterfacesServerTransport(srv *LoadBalancerNetworkInterfacesServer) *LoadBalancerNetworkInterfacesServerTransport { + return &LoadBalancerNetworkInterfacesServerTransport{srv: srv} +} + +// LoadBalancerNetworkInterfacesServerTransport connects instances of armnetwork.LoadBalancerNetworkInterfacesClient to instances of LoadBalancerNetworkInterfacesServer. +// Don't use this type directly, use NewLoadBalancerNetworkInterfacesServerTransport instead. +type LoadBalancerNetworkInterfacesServerTransport struct { + srv *LoadBalancerNetworkInterfacesServer + newListPager *azfake.PagerResponder[armnetwork.LoadBalancerNetworkInterfacesClientListResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancerNetworkInterfacesServerTransport. +func (l *LoadBalancerNetworkInterfacesServerTransport) 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 "LoadBalancerNetworkInterfacesClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancerNetworkInterfacesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkInterfaces` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancerNetworkInterfacesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalanceroutboundrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalanceroutboundrules_server.go new file mode 100644 index 000000000000..83c0140ca0d2 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalanceroutboundrules_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancerOutboundRulesServer is a fake server for instances of the armnetwork.LoadBalancerOutboundRulesClient type. +type LoadBalancerOutboundRulesServer struct { + // Get is the fake for method LoadBalancerOutboundRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, outboundRuleName string, options *armnetwork.LoadBalancerOutboundRulesClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancerOutboundRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LoadBalancerOutboundRulesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerOutboundRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerOutboundRulesClientListResponse]) +} + +// NewLoadBalancerOutboundRulesServerTransport creates a new instance of LoadBalancerOutboundRulesServerTransport with the provided implementation. +// The returned LoadBalancerOutboundRulesServerTransport instance is connected to an instance of armnetwork.LoadBalancerOutboundRulesClient by way of the +// undefined.Transporter field. +func NewLoadBalancerOutboundRulesServerTransport(srv *LoadBalancerOutboundRulesServer) *LoadBalancerOutboundRulesServerTransport { + return &LoadBalancerOutboundRulesServerTransport{srv: srv} +} + +// LoadBalancerOutboundRulesServerTransport connects instances of armnetwork.LoadBalancerOutboundRulesClient to instances of LoadBalancerOutboundRulesServer. +// Don't use this type directly, use NewLoadBalancerOutboundRulesServerTransport instead. +type LoadBalancerOutboundRulesServerTransport struct { + srv *LoadBalancerOutboundRulesServer + newListPager *azfake.PagerResponder[armnetwork.LoadBalancerOutboundRulesClientListResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancerOutboundRulesServerTransport. +func (l *LoadBalancerOutboundRulesServerTransport) 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 "LoadBalancerOutboundRulesClient.Get": + resp, err = l.dispatchGet(req) + case "LoadBalancerOutboundRulesClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancerOutboundRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/outboundRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + outboundRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("outboundRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, outboundRuleNameUnescaped, 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).OutboundRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LoadBalancerOutboundRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/outboundRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancerOutboundRulesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalancerprobes_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerprobes_server.go new file mode 100644 index 000000000000..8815f0c0de32 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalancerprobes_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancerProbesServer is a fake server for instances of the armnetwork.LoadBalancerProbesClient type. +type LoadBalancerProbesServer struct { + // Get is the fake for method LoadBalancerProbesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, probeName string, options *armnetwork.LoadBalancerProbesClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancerProbesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LoadBalancerProbesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerProbesClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerProbesClientListResponse]) +} + +// NewLoadBalancerProbesServerTransport creates a new instance of LoadBalancerProbesServerTransport with the provided implementation. +// The returned LoadBalancerProbesServerTransport instance is connected to an instance of armnetwork.LoadBalancerProbesClient by way of the +// undefined.Transporter field. +func NewLoadBalancerProbesServerTransport(srv *LoadBalancerProbesServer) *LoadBalancerProbesServerTransport { + return &LoadBalancerProbesServerTransport{srv: srv} +} + +// LoadBalancerProbesServerTransport connects instances of armnetwork.LoadBalancerProbesClient to instances of LoadBalancerProbesServer. +// Don't use this type directly, use NewLoadBalancerProbesServerTransport instead. +type LoadBalancerProbesServerTransport struct { + srv *LoadBalancerProbesServer + newListPager *azfake.PagerResponder[armnetwork.LoadBalancerProbesClientListResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancerProbesServerTransport. +func (l *LoadBalancerProbesServerTransport) 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 "LoadBalancerProbesClient.Get": + resp, err = l.dispatchGet(req) + case "LoadBalancerProbesClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancerProbesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/probes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + probeNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("probeName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, probeNameUnescaped, 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).Probe, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LoadBalancerProbesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/probes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancerProbesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/loadbalancers_server.go b/sdk/resourcemanager/network/armnetwork/fake/loadbalancers_server.go new file mode 100644 index 000000000000..ad3207f009b5 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/loadbalancers_server.go @@ -0,0 +1,438 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LoadBalancersServer is a fake server for instances of the armnetwork.LoadBalancersClient type. +type LoadBalancersServer struct { + // BeginCreateOrUpdate is the fake for method LoadBalancersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters armnetwork.LoadBalancer, options *armnetwork.LoadBalancersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.LoadBalancersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method LoadBalancersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancersClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.LoadBalancersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method LoadBalancersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancersClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LoadBalancersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.LoadBalancersClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancersClientListResponse]) + + // NewListAllPager is the fake for method LoadBalancersClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.LoadBalancersClientListAllOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancersClientListAllResponse]) + + // BeginListInboundNatRulePortMappings is the fake for method LoadBalancersClient.BeginListInboundNatRulePortMappings + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListInboundNatRulePortMappings func(ctx context.Context, groupName string, loadBalancerName string, backendPoolName string, parameters armnetwork.QueryInboundNatRulePortMappingRequest, options *armnetwork.LoadBalancersClientBeginListInboundNatRulePortMappingsOptions) (resp azfake.PollerResponder[armnetwork.LoadBalancersClientListInboundNatRulePortMappingsResponse], errResp azfake.ErrorResponder) + + // BeginSwapPublicIPAddresses is the fake for method LoadBalancersClient.BeginSwapPublicIPAddresses + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginSwapPublicIPAddresses func(ctx context.Context, location string, parameters armnetwork.LoadBalancerVipSwapRequest, options *armnetwork.LoadBalancersClientBeginSwapPublicIPAddressesOptions) (resp azfake.PollerResponder[armnetwork.LoadBalancersClientSwapPublicIPAddressesResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method LoadBalancersClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters armnetwork.TagsObject, options *armnetwork.LoadBalancersClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.LoadBalancersClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewLoadBalancersServerTransport creates a new instance of LoadBalancersServerTransport with the provided implementation. +// The returned LoadBalancersServerTransport instance is connected to an instance of armnetwork.LoadBalancersClient by way of the +// undefined.Transporter field. +func NewLoadBalancersServerTransport(srv *LoadBalancersServer) *LoadBalancersServerTransport { + return &LoadBalancersServerTransport{srv: srv} +} + +// LoadBalancersServerTransport connects instances of armnetwork.LoadBalancersClient to instances of LoadBalancersServer. +// Don't use this type directly, use NewLoadBalancersServerTransport instead. +type LoadBalancersServerTransport struct { + srv *LoadBalancersServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.LoadBalancersClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.LoadBalancersClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.LoadBalancersClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.LoadBalancersClientListAllResponse] + beginListInboundNatRulePortMappings *azfake.PollerResponder[armnetwork.LoadBalancersClientListInboundNatRulePortMappingsResponse] + beginSwapPublicIPAddresses *azfake.PollerResponder[armnetwork.LoadBalancersClientSwapPublicIPAddressesResponse] +} + +// Do implements the policy.Transporter interface for LoadBalancersServerTransport. +func (l *LoadBalancersServerTransport) 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 "LoadBalancersClient.BeginCreateOrUpdate": + resp, err = l.dispatchBeginCreateOrUpdate(req) + case "LoadBalancersClient.BeginDelete": + resp, err = l.dispatchBeginDelete(req) + case "LoadBalancersClient.Get": + resp, err = l.dispatchGet(req) + case "LoadBalancersClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + case "LoadBalancersClient.NewListAllPager": + resp, err = l.dispatchNewListAllPager(req) + case "LoadBalancersClient.BeginListInboundNatRulePortMappings": + resp, err = l.dispatchBeginListInboundNatRulePortMappings(req) + case "LoadBalancersClient.BeginSwapPublicIPAddresses": + resp, err = l.dispatchBeginSwapPublicIPAddresses(req) + case "LoadBalancersClient.UpdateTags": + resp, err = l.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if l.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if l.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.LoadBalancer](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(l.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(l.beginCreateOrUpdate) { + l.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if l.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if l.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(l.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(l.beginDelete) { + l.beginDelete = nil + } + + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.LoadBalancersClientGetOptions + if expandParam != nil { + options = &armnetwork.LoadBalancersClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, 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).LoadBalancer, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LoadBalancersClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if l.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := l.srv.NewListAllPager(nil) + l.newListAllPager = &resp + server.PagerResponderInjectNextLinks(l.newListAllPager, req, func(page *armnetwork.LoadBalancersClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListAllPager) { + l.newListAllPager = nil + } + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchBeginListInboundNatRulePortMappings(req *http.Request) (*http.Response, error) { + if l.srv.BeginListInboundNatRulePortMappings == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListInboundNatRulePortMappings not implemented")} + } + if l.beginListInboundNatRulePortMappings == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/backendAddressPools/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/queryInboundNatRulePortMapping` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.QueryInboundNatRulePortMappingRequest](req) + if err != nil { + return nil, err + } + groupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + backendPoolNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("backendPoolName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginListInboundNatRulePortMappings(req.Context(), groupNameUnescaped, loadBalancerNameUnescaped, backendPoolNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginListInboundNatRulePortMappings = &respr + } + + resp, err := server.PollerResponderNext(l.beginListInboundNatRulePortMappings, 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.beginListInboundNatRulePortMappings) { + l.beginListInboundNatRulePortMappings = nil + } + + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchBeginSwapPublicIPAddresses(req *http.Request) (*http.Response, error) { + if l.srv.BeginSwapPublicIPAddresses == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginSwapPublicIPAddresses not implemented")} + } + if l.beginSwapPublicIPAddresses == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/setLoadBalancerFrontendPublicIpAddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.LoadBalancerVipSwapRequest](req) + if err != nil { + return nil, err + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginSwapPublicIPAddresses(req.Context(), locationUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginSwapPublicIPAddresses = &respr + } + + resp, err := server.PollerResponderNext(l.beginSwapPublicIPAddresses, 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.beginSwapPublicIPAddresses) { + l.beginSwapPublicIPAddresses = nil + } + + return resp, nil +} + +func (l *LoadBalancersServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if l.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/loadBalancers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + loadBalancerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, loadBalancerNameUnescaped, 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).LoadBalancer, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/localnetworkgateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/localnetworkgateways_server.go new file mode 100644 index 000000000000..57ee105d7a70 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/localnetworkgateways_server.go @@ -0,0 +1,285 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// LocalNetworkGatewaysServer is a fake server for instances of the armnetwork.LocalNetworkGatewaysClient type. +type LocalNetworkGatewaysServer struct { + // BeginCreateOrUpdate is the fake for method LocalNetworkGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters armnetwork.LocalNetworkGateway, options *armnetwork.LocalNetworkGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.LocalNetworkGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method LocalNetworkGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *armnetwork.LocalNetworkGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.LocalNetworkGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method LocalNetworkGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *armnetwork.LocalNetworkGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.LocalNetworkGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LocalNetworkGatewaysClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.LocalNetworkGatewaysClientListOptions) (resp azfake.PagerResponder[armnetwork.LocalNetworkGatewaysClientListResponse]) + + // UpdateTags is the fake for method LocalNetworkGatewaysClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters armnetwork.TagsObject, options *armnetwork.LocalNetworkGatewaysClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.LocalNetworkGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewLocalNetworkGatewaysServerTransport creates a new instance of LocalNetworkGatewaysServerTransport with the provided implementation. +// The returned LocalNetworkGatewaysServerTransport instance is connected to an instance of armnetwork.LocalNetworkGatewaysClient by way of the +// undefined.Transporter field. +func NewLocalNetworkGatewaysServerTransport(srv *LocalNetworkGatewaysServer) *LocalNetworkGatewaysServerTransport { + return &LocalNetworkGatewaysServerTransport{srv: srv} +} + +// LocalNetworkGatewaysServerTransport connects instances of armnetwork.LocalNetworkGatewaysClient to instances of LocalNetworkGatewaysServer. +// Don't use this type directly, use NewLocalNetworkGatewaysServerTransport instead. +type LocalNetworkGatewaysServerTransport struct { + srv *LocalNetworkGatewaysServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.LocalNetworkGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.LocalNetworkGatewaysClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.LocalNetworkGatewaysClientListResponse] +} + +// Do implements the policy.Transporter interface for LocalNetworkGatewaysServerTransport. +func (l *LocalNetworkGatewaysServerTransport) 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 "LocalNetworkGatewaysClient.BeginCreateOrUpdate": + resp, err = l.dispatchBeginCreateOrUpdate(req) + case "LocalNetworkGatewaysClient.BeginDelete": + resp, err = l.dispatchBeginDelete(req) + case "LocalNetworkGatewaysClient.Get": + resp, err = l.dispatchGet(req) + case "LocalNetworkGatewaysClient.NewListPager": + resp, err = l.dispatchNewListPager(req) + case "LocalNetworkGatewaysClient.UpdateTags": + resp, err = l.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (l *LocalNetworkGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if l.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if l.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/localNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.LocalNetworkGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + localNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("localNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, localNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(l.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(l.beginCreateOrUpdate) { + l.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (l *LocalNetworkGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if l.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if l.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/localNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + localNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("localNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, localNetworkGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + l.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(l.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(l.beginDelete) { + l.beginDelete = nil + } + + return resp, nil +} + +func (l *LocalNetworkGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + 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.Network/localNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + localNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("localNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameUnescaped, localNetworkGatewayNameUnescaped, 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).LocalNetworkGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LocalNetworkGatewaysServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if l.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/localNetworkGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := l.srv.NewListPager(resourceGroupNameUnescaped, nil) + l.newListPager = &resp + server.PagerResponderInjectNextLinks(l.newListPager, req, func(page *armnetwork.LocalNetworkGatewaysClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(l.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(l.newListPager) { + l.newListPager = nil + } + return resp, nil +} + +func (l *LocalNetworkGatewaysServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if l.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/localNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + localNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("localNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, localNetworkGatewayNameUnescaped, 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).LocalNetworkGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/management_server.go b/sdk/resourcemanager/network/armnetwork/fake/management_server.go new file mode 100644 index 000000000000..d9fbac9f6a5f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/management_server.go @@ -0,0 +1,735 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ManagementServer is a fake server for instances of the armnetwork.ManagementClient type. +type ManagementServer struct { + // CheckDNSNameAvailability is the fake for method ManagementClient.CheckDNSNameAvailability + // HTTP status codes to indicate success: http.StatusOK + CheckDNSNameAvailability func(ctx context.Context, location string, domainNameLabel string, options *armnetwork.ManagementClientCheckDNSNameAvailabilityOptions) (resp azfake.Responder[armnetwork.ManagementClientCheckDNSNameAvailabilityResponse], errResp azfake.ErrorResponder) + + // BeginDeleteBastionShareableLink is the fake for method ManagementClient.BeginDeleteBastionShareableLink + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDeleteBastionShareableLink func(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest armnetwork.BastionShareableLinkListRequest, options *armnetwork.ManagementClientBeginDeleteBastionShareableLinkOptions) (resp azfake.PollerResponder[armnetwork.ManagementClientDeleteBastionShareableLinkResponse], errResp azfake.ErrorResponder) + + // NewDisconnectActiveSessionsPager is the fake for method ManagementClient.NewDisconnectActiveSessionsPager + // HTTP status codes to indicate success: http.StatusOK + NewDisconnectActiveSessionsPager func(resourceGroupName string, bastionHostName string, sessionIDs armnetwork.SessionIDs, options *armnetwork.ManagementClientDisconnectActiveSessionsOptions) (resp azfake.PagerResponder[armnetwork.ManagementClientDisconnectActiveSessionsResponse]) + + // ExpressRouteProviderPort is the fake for method ManagementClient.ExpressRouteProviderPort + // HTTP status codes to indicate success: http.StatusOK + ExpressRouteProviderPort func(ctx context.Context, providerport string, options *armnetwork.ManagementClientExpressRouteProviderPortOptions) (resp azfake.Responder[armnetwork.ManagementClientExpressRouteProviderPortResponse], errResp azfake.ErrorResponder) + + // BeginGeneratevirtualwanvpnserverconfigurationvpnprofile is the fake for method ManagementClient.BeginGeneratevirtualwanvpnserverconfigurationvpnprofile + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGeneratevirtualwanvpnserverconfigurationvpnprofile func(ctx context.Context, resourceGroupName string, virtualWANName string, vpnClientParams armnetwork.VirtualWanVPNProfileParameters, options *armnetwork.ManagementClientBeginGeneratevirtualwanvpnserverconfigurationvpnprofileOptions) (resp azfake.PollerResponder[armnetwork.ManagementClientGeneratevirtualwanvpnserverconfigurationvpnprofileResponse], errResp azfake.ErrorResponder) + + // BeginGetActiveSessions is the fake for method ManagementClient.BeginGetActiveSessions + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetActiveSessions func(ctx context.Context, resourceGroupName string, bastionHostName string, options *armnetwork.ManagementClientBeginGetActiveSessionsOptions) (resp azfake.PollerResponder[azfake.PagerResponder[armnetwork.ManagementClientGetActiveSessionsResponse]], errResp azfake.ErrorResponder) + + // NewGetBastionShareableLinkPager is the fake for method ManagementClient.NewGetBastionShareableLinkPager + // HTTP status codes to indicate success: http.StatusOK + NewGetBastionShareableLinkPager func(resourceGroupName string, bastionHostName string, bslRequest armnetwork.BastionShareableLinkListRequest, options *armnetwork.ManagementClientGetBastionShareableLinkOptions) (resp azfake.PagerResponder[armnetwork.ManagementClientGetBastionShareableLinkResponse]) + + // ListActiveConnectivityConfigurations is the fake for method ManagementClient.ListActiveConnectivityConfigurations + // HTTP status codes to indicate success: http.StatusOK + ListActiveConnectivityConfigurations func(ctx context.Context, resourceGroupName string, networkManagerName string, parameters armnetwork.ActiveConfigurationParameter, options *armnetwork.ManagementClientListActiveConnectivityConfigurationsOptions) (resp azfake.Responder[armnetwork.ManagementClientListActiveConnectivityConfigurationsResponse], errResp azfake.ErrorResponder) + + // ListActiveSecurityAdminRules is the fake for method ManagementClient.ListActiveSecurityAdminRules + // HTTP status codes to indicate success: http.StatusOK + ListActiveSecurityAdminRules func(ctx context.Context, resourceGroupName string, networkManagerName string, parameters armnetwork.ActiveConfigurationParameter, options *armnetwork.ManagementClientListActiveSecurityAdminRulesOptions) (resp azfake.Responder[armnetwork.ManagementClientListActiveSecurityAdminRulesResponse], errResp azfake.ErrorResponder) + + // ListNetworkManagerEffectiveConnectivityConfigurations is the fake for method ManagementClient.ListNetworkManagerEffectiveConnectivityConfigurations + // HTTP status codes to indicate success: http.StatusOK + ListNetworkManagerEffectiveConnectivityConfigurations func(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters armnetwork.QueryRequestOptions, options *armnetwork.ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsOptions) (resp azfake.Responder[armnetwork.ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsResponse], errResp azfake.ErrorResponder) + + // ListNetworkManagerEffectiveSecurityAdminRules is the fake for method ManagementClient.ListNetworkManagerEffectiveSecurityAdminRules + // HTTP status codes to indicate success: http.StatusOK + ListNetworkManagerEffectiveSecurityAdminRules func(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters armnetwork.QueryRequestOptions, options *armnetwork.ManagementClientListNetworkManagerEffectiveSecurityAdminRulesOptions) (resp azfake.Responder[armnetwork.ManagementClientListNetworkManagerEffectiveSecurityAdminRulesResponse], errResp azfake.ErrorResponder) + + // BeginPutBastionShareableLink is the fake for method ManagementClient.BeginPutBastionShareableLink + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPutBastionShareableLink func(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest armnetwork.BastionShareableLinkListRequest, options *armnetwork.ManagementClientBeginPutBastionShareableLinkOptions) (resp azfake.PollerResponder[azfake.PagerResponder[armnetwork.ManagementClientPutBastionShareableLinkResponse]], errResp azfake.ErrorResponder) + + // SupportedSecurityProviders is the fake for method ManagementClient.SupportedSecurityProviders + // HTTP status codes to indicate success: http.StatusOK + SupportedSecurityProviders func(ctx context.Context, resourceGroupName string, virtualWANName string, options *armnetwork.ManagementClientSupportedSecurityProvidersOptions) (resp azfake.Responder[armnetwork.ManagementClientSupportedSecurityProvidersResponse], errResp azfake.ErrorResponder) +} + +// NewManagementServerTransport creates a new instance of ManagementServerTransport with the provided implementation. +// The returned ManagementServerTransport instance is connected to an instance of armnetwork.ManagementClient by way of the +// undefined.Transporter field. +func NewManagementServerTransport(srv *ManagementServer) *ManagementServerTransport { + return &ManagementServerTransport{srv: srv} +} + +// ManagementServerTransport connects instances of armnetwork.ManagementClient to instances of ManagementServer. +// Don't use this type directly, use NewManagementServerTransport instead. +type ManagementServerTransport struct { + srv *ManagementServer + beginDeleteBastionShareableLink *azfake.PollerResponder[armnetwork.ManagementClientDeleteBastionShareableLinkResponse] + newDisconnectActiveSessionsPager *azfake.PagerResponder[armnetwork.ManagementClientDisconnectActiveSessionsResponse] + beginGeneratevirtualwanvpnserverconfigurationvpnprofile *azfake.PollerResponder[armnetwork.ManagementClientGeneratevirtualwanvpnserverconfigurationvpnprofileResponse] + beginGetActiveSessions *azfake.PollerResponder[azfake.PagerResponder[armnetwork.ManagementClientGetActiveSessionsResponse]] + newGetBastionShareableLinkPager *azfake.PagerResponder[armnetwork.ManagementClientGetBastionShareableLinkResponse] + beginPutBastionShareableLink *azfake.PollerResponder[azfake.PagerResponder[armnetwork.ManagementClientPutBastionShareableLinkResponse]] +} + +// Do implements the policy.Transporter interface for ManagementServerTransport. +func (m *ManagementServerTransport) 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 "ManagementClient.CheckDNSNameAvailability": + resp, err = m.dispatchCheckDNSNameAvailability(req) + case "ManagementClient.BeginDeleteBastionShareableLink": + resp, err = m.dispatchBeginDeleteBastionShareableLink(req) + case "ManagementClient.NewDisconnectActiveSessionsPager": + resp, err = m.dispatchNewDisconnectActiveSessionsPager(req) + case "ManagementClient.ExpressRouteProviderPort": + resp, err = m.dispatchExpressRouteProviderPort(req) + case "ManagementClient.BeginGeneratevirtualwanvpnserverconfigurationvpnprofile": + resp, err = m.dispatchBeginGeneratevirtualwanvpnserverconfigurationvpnprofile(req) + case "ManagementClient.BeginGetActiveSessions": + resp, err = m.dispatchBeginGetActiveSessions(req) + case "ManagementClient.NewGetBastionShareableLinkPager": + resp, err = m.dispatchNewGetBastionShareableLinkPager(req) + case "ManagementClient.ListActiveConnectivityConfigurations": + resp, err = m.dispatchListActiveConnectivityConfigurations(req) + case "ManagementClient.ListActiveSecurityAdminRules": + resp, err = m.dispatchListActiveSecurityAdminRules(req) + case "ManagementClient.ListNetworkManagerEffectiveConnectivityConfigurations": + resp, err = m.dispatchListNetworkManagerEffectiveConnectivityConfigurations(req) + case "ManagementClient.ListNetworkManagerEffectiveSecurityAdminRules": + resp, err = m.dispatchListNetworkManagerEffectiveSecurityAdminRules(req) + case "ManagementClient.BeginPutBastionShareableLink": + resp, err = m.dispatchBeginPutBastionShareableLink(req) + case "ManagementClient.SupportedSecurityProviders": + resp, err = m.dispatchSupportedSecurityProviders(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *ManagementServerTransport) dispatchCheckDNSNameAvailability(req *http.Request) (*http.Response, error) { + if m.srv.CheckDNSNameAvailability == nil { + return nil, &nonRetriableError{errors.New("fake for method CheckDNSNameAvailability not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/CheckDnsNameAvailability` + regex := regexp.MustCompile(regexStr) + 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() + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + domainNameLabelUnescaped, err := url.QueryUnescape(qp.Get("domainNameLabel")) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CheckDNSNameAvailability(req.Context(), locationUnescaped, domainNameLabelUnescaped, 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).DNSNameAvailabilityResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchBeginDeleteBastionShareableLink(req *http.Request) (*http.Response, error) { + if m.srv.BeginDeleteBastionShareableLink == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteBastionShareableLink not implemented")} + } + if m.beginDeleteBastionShareableLink == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deleteShareableLinks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.BastionShareableLinkListRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.BeginDeleteBastionShareableLink(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + m.beginDeleteBastionShareableLink = &respr + } + + resp, err := server.PollerResponderNext(m.beginDeleteBastionShareableLink, 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(m.beginDeleteBastionShareableLink) { + m.beginDeleteBastionShareableLink = nil + } + + return resp, nil +} + +func (m *ManagementServerTransport) dispatchNewDisconnectActiveSessionsPager(req *http.Request) (*http.Response, error) { + if m.srv.NewDisconnectActiveSessionsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewDisconnectActiveSessionsPager not implemented")} + } + if m.newDisconnectActiveSessionsPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/disconnectActiveSessions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SessionIDs](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + resp := m.srv.NewDisconnectActiveSessionsPager(resourceGroupNameUnescaped, bastionHostNameUnescaped, body, nil) + m.newDisconnectActiveSessionsPager = &resp + server.PagerResponderInjectNextLinks(m.newDisconnectActiveSessionsPager, req, func(page *armnetwork.ManagementClientDisconnectActiveSessionsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(m.newDisconnectActiveSessionsPager, 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(m.newDisconnectActiveSessionsPager) { + m.newDisconnectActiveSessionsPager = nil + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchExpressRouteProviderPort(req *http.Request) (*http.Response, error) { + if m.srv.ExpressRouteProviderPort == nil { + return nil, &nonRetriableError{errors.New("fake for method ExpressRouteProviderPort not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteProviderPorts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + providerportUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("providerport")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.ExpressRouteProviderPort(req.Context(), providerportUnescaped, 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).ExpressRouteProviderPort, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchBeginGeneratevirtualwanvpnserverconfigurationvpnprofile(req *http.Request) (*http.Response, error) { + if m.srv.BeginGeneratevirtualwanvpnserverconfigurationvpnprofile == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGeneratevirtualwanvpnserverconfigurationvpnprofile not implemented")} + } + if m.beginGeneratevirtualwanvpnserverconfigurationvpnprofile == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/GenerateVpnProfile` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualWanVPNProfileParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.BeginGeneratevirtualwanvpnserverconfigurationvpnprofile(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + m.beginGeneratevirtualwanvpnserverconfigurationvpnprofile = &respr + } + + resp, err := server.PollerResponderNext(m.beginGeneratevirtualwanvpnserverconfigurationvpnprofile, 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(m.beginGeneratevirtualwanvpnserverconfigurationvpnprofile) { + m.beginGeneratevirtualwanvpnserverconfigurationvpnprofile = nil + } + + return resp, nil +} + +func (m *ManagementServerTransport) dispatchBeginGetActiveSessions(req *http.Request) (*http.Response, error) { + if m.srv.BeginGetActiveSessions == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetActiveSessions not implemented")} + } + if m.beginGetActiveSessions == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getActiveSessions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.BeginGetActiveSessions(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + m.beginGetActiveSessions = &respr + } + + resp, err := server.PollerResponderNext(m.beginGetActiveSessions, 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(m.beginGetActiveSessions) { + m.beginGetActiveSessions = nil + } + + return resp, nil +} + +func (m *ManagementServerTransport) dispatchNewGetBastionShareableLinkPager(req *http.Request) (*http.Response, error) { + if m.srv.NewGetBastionShareableLinkPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewGetBastionShareableLinkPager not implemented")} + } + if m.newGetBastionShareableLinkPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getShareableLinks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.BastionShareableLinkListRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + resp := m.srv.NewGetBastionShareableLinkPager(resourceGroupNameUnescaped, bastionHostNameUnescaped, body, nil) + m.newGetBastionShareableLinkPager = &resp + server.PagerResponderInjectNextLinks(m.newGetBastionShareableLinkPager, req, func(page *armnetwork.ManagementClientGetBastionShareableLinkResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(m.newGetBastionShareableLinkPager, 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(m.newGetBastionShareableLinkPager) { + m.newGetBastionShareableLinkPager = nil + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchListActiveConnectivityConfigurations(req *http.Request) (*http.Response, error) { + if m.srv.ListActiveConnectivityConfigurations == nil { + return nil, &nonRetriableError{errors.New("fake for method ListActiveConnectivityConfigurations not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listActiveConnectivityConfigurations` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.ActiveConfigurationParameter](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armnetwork.ManagementClientListActiveConnectivityConfigurationsOptions + if topParam != nil { + options = &armnetwork.ManagementClientListActiveConnectivityConfigurationsOptions{ + Top: topParam, + } + } + respr, errRespr := m.srv.ListActiveConnectivityConfigurations(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, body, 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).ActiveConnectivityConfigurationsListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchListActiveSecurityAdminRules(req *http.Request) (*http.Response, error) { + if m.srv.ListActiveSecurityAdminRules == nil { + return nil, &nonRetriableError{errors.New("fake for method ListActiveSecurityAdminRules not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listActiveSecurityAdminRules` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.ActiveConfigurationParameter](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armnetwork.ManagementClientListActiveSecurityAdminRulesOptions + if topParam != nil { + options = &armnetwork.ManagementClientListActiveSecurityAdminRulesOptions{ + Top: topParam, + } + } + respr, errRespr := m.srv.ListActiveSecurityAdminRules(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, body, 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).ActiveSecurityAdminRulesListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchListNetworkManagerEffectiveConnectivityConfigurations(req *http.Request) (*http.Response, error) { + if m.srv.ListNetworkManagerEffectiveConnectivityConfigurations == nil { + return nil, &nonRetriableError{errors.New("fake for method ListNetworkManagerEffectiveConnectivityConfigurations not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listNetworkManagerEffectiveConnectivityConfigurations` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.QueryRequestOptions](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armnetwork.ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsOptions + if topParam != nil { + options = &armnetwork.ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsOptions{ + Top: topParam, + } + } + respr, errRespr := m.srv.ListNetworkManagerEffectiveConnectivityConfigurations(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, body, 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).ManagerEffectiveConnectivityConfigurationListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchListNetworkManagerEffectiveSecurityAdminRules(req *http.Request) (*http.Response, error) { + if m.srv.ListNetworkManagerEffectiveSecurityAdminRules == nil { + return nil, &nonRetriableError{errors.New("fake for method ListNetworkManagerEffectiveSecurityAdminRules not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listNetworkManagerEffectiveSecurityAdminRules` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.QueryRequestOptions](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armnetwork.ManagementClientListNetworkManagerEffectiveSecurityAdminRulesOptions + if topParam != nil { + options = &armnetwork.ManagementClientListNetworkManagerEffectiveSecurityAdminRulesOptions{ + Top: topParam, + } + } + respr, errRespr := m.srv.ListNetworkManagerEffectiveSecurityAdminRules(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, body, 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).ManagerEffectiveSecurityAdminRulesListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementServerTransport) dispatchBeginPutBastionShareableLink(req *http.Request) (*http.Response, error) { + if m.srv.BeginPutBastionShareableLink == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginPutBastionShareableLink not implemented")} + } + if m.beginPutBastionShareableLink == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/bastionHosts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/createShareableLinks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.BastionShareableLinkListRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + bastionHostNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("bastionHostName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.BeginPutBastionShareableLink(req.Context(), resourceGroupNameUnescaped, bastionHostNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + m.beginPutBastionShareableLink = &respr + } + + resp, err := server.PollerResponderNext(m.beginPutBastionShareableLink, 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(m.beginPutBastionShareableLink) { + m.beginPutBastionShareableLink = nil + } + + return resp, nil +} + +func (m *ManagementServerTransport) dispatchSupportedSecurityProviders(req *http.Request) (*http.Response, error) { + if m.srv.SupportedSecurityProviders == nil { + return nil, &nonRetriableError{errors.New("fake for method SupportedSecurityProviders not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/supportedSecurityProviders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.SupportedSecurityProviders(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, 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).VirtualWanSecurityProviders, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/managementgroupnetworkmanagerconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/managementgroupnetworkmanagerconnections_server.go new file mode 100644 index 000000000000..e4f61634eba0 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/managementgroupnetworkmanagerconnections_server.go @@ -0,0 +1,252 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ManagementGroupNetworkManagerConnectionsServer is a fake server for instances of the armnetwork.ManagementGroupNetworkManagerConnectionsClient type. +type ManagementGroupNetworkManagerConnectionsServer struct { + // CreateOrUpdate is the fake for method ManagementGroupNetworkManagerConnectionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, managementGroupID string, networkManagerConnectionName string, parameters armnetwork.ManagerConnection, options *armnetwork.ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method ManagementGroupNetworkManagerConnectionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, managementGroupID string, networkManagerConnectionName string, options *armnetwork.ManagementGroupNetworkManagerConnectionsClientDeleteOptions) (resp azfake.Responder[armnetwork.ManagementGroupNetworkManagerConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ManagementGroupNetworkManagerConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, managementGroupID string, networkManagerConnectionName string, options *armnetwork.ManagementGroupNetworkManagerConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.ManagementGroupNetworkManagerConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ManagementGroupNetworkManagerConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(managementGroupID string, options *armnetwork.ManagementGroupNetworkManagerConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.ManagementGroupNetworkManagerConnectionsClientListResponse]) +} + +// NewManagementGroupNetworkManagerConnectionsServerTransport creates a new instance of ManagementGroupNetworkManagerConnectionsServerTransport with the provided implementation. +// The returned ManagementGroupNetworkManagerConnectionsServerTransport instance is connected to an instance of armnetwork.ManagementGroupNetworkManagerConnectionsClient by way of the +// undefined.Transporter field. +func NewManagementGroupNetworkManagerConnectionsServerTransport(srv *ManagementGroupNetworkManagerConnectionsServer) *ManagementGroupNetworkManagerConnectionsServerTransport { + return &ManagementGroupNetworkManagerConnectionsServerTransport{srv: srv} +} + +// ManagementGroupNetworkManagerConnectionsServerTransport connects instances of armnetwork.ManagementGroupNetworkManagerConnectionsClient to instances of ManagementGroupNetworkManagerConnectionsServer. +// Don't use this type directly, use NewManagementGroupNetworkManagerConnectionsServerTransport instead. +type ManagementGroupNetworkManagerConnectionsServerTransport struct { + srv *ManagementGroupNetworkManagerConnectionsServer + newListPager *azfake.PagerResponder[armnetwork.ManagementGroupNetworkManagerConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for ManagementGroupNetworkManagerConnectionsServerTransport. +func (m *ManagementGroupNetworkManagerConnectionsServerTransport) 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 "ManagementGroupNetworkManagerConnectionsClient.CreateOrUpdate": + resp, err = m.dispatchCreateOrUpdate(req) + case "ManagementGroupNetworkManagerConnectionsClient.Delete": + resp, err = m.dispatchDelete(req) + case "ManagementGroupNetworkManagerConnectionsClient.Get": + resp, err = m.dispatchGet(req) + case "ManagementGroupNetworkManagerConnectionsClient.NewListPager": + resp, err = m.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *ManagementGroupNetworkManagerConnectionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if m.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ManagerConnection](req) + if err != nil { + return nil, err + } + managementGroupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + networkManagerConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CreateOrUpdate(req.Context(), managementGroupIDUnescaped, networkManagerConnectionNameUnescaped, 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).ManagerConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementGroupNetworkManagerConnectionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if m.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + managementGroupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + networkManagerConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Delete(req.Context(), managementGroupIDUnescaped, networkManagerConnectionNameUnescaped, 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 (m *ManagementGroupNetworkManagerConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if m.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + managementGroupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + networkManagerConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Get(req.Context(), managementGroupIDUnescaped, networkManagerConnectionNameUnescaped, 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).ManagerConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementGroupNetworkManagerConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if m.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if m.newListPager == nil { + const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections` + regex := regexp.MustCompile(regexStr) + 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() + managementGroupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.ManagementGroupNetworkManagerConnectionsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.ManagementGroupNetworkManagerConnectionsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := m.srv.NewListPager(managementGroupIDUnescaped, options) + m.newListPager = &resp + server.PagerResponderInjectNextLinks(m.newListPager, req, func(page *armnetwork.ManagementGroupNetworkManagerConnectionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(m.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(m.newListPager) { + m.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/managercommits_server.go b/sdk/resourcemanager/network/armnetwork/fake/managercommits_server.go new file mode 100644 index 000000000000..9f19715a1a3e --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/managercommits_server.go @@ -0,0 +1,113 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ManagerCommitsServer is a fake server for instances of the armnetwork.ManagerCommitsClient type. +type ManagerCommitsServer struct { + // BeginPost is the fake for method ManagerCommitsClient.BeginPost + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPost func(ctx context.Context, resourceGroupName string, networkManagerName string, parameters armnetwork.ManagerCommit, options *armnetwork.ManagerCommitsClientBeginPostOptions) (resp azfake.PollerResponder[armnetwork.ManagerCommitsClientPostResponse], errResp azfake.ErrorResponder) +} + +// NewManagerCommitsServerTransport creates a new instance of ManagerCommitsServerTransport with the provided implementation. +// The returned ManagerCommitsServerTransport instance is connected to an instance of armnetwork.ManagerCommitsClient by way of the +// undefined.Transporter field. +func NewManagerCommitsServerTransport(srv *ManagerCommitsServer) *ManagerCommitsServerTransport { + return &ManagerCommitsServerTransport{srv: srv} +} + +// ManagerCommitsServerTransport connects instances of armnetwork.ManagerCommitsClient to instances of ManagerCommitsServer. +// Don't use this type directly, use NewManagerCommitsServerTransport instead. +type ManagerCommitsServerTransport struct { + srv *ManagerCommitsServer + beginPost *azfake.PollerResponder[armnetwork.ManagerCommitsClientPostResponse] +} + +// Do implements the policy.Transporter interface for ManagerCommitsServerTransport. +func (m *ManagerCommitsServerTransport) 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 "ManagerCommitsClient.BeginPost": + resp, err = m.dispatchBeginPost(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *ManagerCommitsServerTransport) dispatchBeginPost(req *http.Request) (*http.Response, error) { + if m.srv.BeginPost == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginPost not implemented")} + } + if m.beginPost == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/commit` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ManagerCommit](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.BeginPost(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + m.beginPost = &respr + } + + resp, err := server.PollerResponderNext(m.beginPost, 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(m.beginPost) { + m.beginPost = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/managerdeploymentstatus_server.go b/sdk/resourcemanager/network/armnetwork/fake/managerdeploymentstatus_server.go new file mode 100644 index 000000000000..df6f6be06a2d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/managerdeploymentstatus_server.go @@ -0,0 +1,126 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ManagerDeploymentStatusServer is a fake server for instances of the armnetwork.ManagerDeploymentStatusClient type. +type ManagerDeploymentStatusServer struct { + // List is the fake for method ManagerDeploymentStatusClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, networkManagerName string, parameters armnetwork.ManagerDeploymentStatusParameter, options *armnetwork.ManagerDeploymentStatusClientListOptions) (resp azfake.Responder[armnetwork.ManagerDeploymentStatusClientListResponse], errResp azfake.ErrorResponder) +} + +// NewManagerDeploymentStatusServerTransport creates a new instance of ManagerDeploymentStatusServerTransport with the provided implementation. +// The returned ManagerDeploymentStatusServerTransport instance is connected to an instance of armnetwork.ManagerDeploymentStatusClient by way of the +// undefined.Transporter field. +func NewManagerDeploymentStatusServerTransport(srv *ManagerDeploymentStatusServer) *ManagerDeploymentStatusServerTransport { + return &ManagerDeploymentStatusServerTransport{srv: srv} +} + +// ManagerDeploymentStatusServerTransport connects instances of armnetwork.ManagerDeploymentStatusClient to instances of ManagerDeploymentStatusServer. +// Don't use this type directly, use NewManagerDeploymentStatusServerTransport instead. +type ManagerDeploymentStatusServerTransport struct { + srv *ManagerDeploymentStatusServer +} + +// Do implements the policy.Transporter interface for ManagerDeploymentStatusServerTransport. +func (m *ManagerDeploymentStatusServerTransport) 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 "ManagerDeploymentStatusClient.List": + resp, err = m.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *ManagerDeploymentStatusServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if m.srv.List == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listDeploymentStatus` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.ManagerDeploymentStatusParameter](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armnetwork.ManagerDeploymentStatusClientListOptions + if topParam != nil { + options = &armnetwork.ManagerDeploymentStatusClientListOptions{ + Top: topParam, + } + } + respr, errRespr := m.srv.List(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, body, 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).ManagerDeploymentStatusListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/managers_server.go b/sdk/resourcemanager/network/armnetwork/fake/managers_server.go new file mode 100644 index 000000000000..7eaab7f447ce --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/managers_server.go @@ -0,0 +1,383 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ManagersServer is a fake server for instances of the armnetwork.ManagersClient type. +type ManagersServer struct { + // CreateOrUpdate is the fake for method ManagersClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, parameters armnetwork.Manager, options *armnetwork.ManagersClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.ManagersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ManagersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, options *armnetwork.ManagersClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ManagersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ManagersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, options *armnetwork.ManagersClientGetOptions) (resp azfake.Responder[armnetwork.ManagersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ManagersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.ManagersClientListOptions) (resp azfake.PagerResponder[armnetwork.ManagersClientListResponse]) + + // NewListBySubscriptionPager is the fake for method ManagersClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armnetwork.ManagersClientListBySubscriptionOptions) (resp azfake.PagerResponder[armnetwork.ManagersClientListBySubscriptionResponse]) + + // Patch is the fake for method ManagersClient.Patch + // HTTP status codes to indicate success: http.StatusOK + Patch func(ctx context.Context, resourceGroupName string, networkManagerName string, parameters armnetwork.PatchObject, options *armnetwork.ManagersClientPatchOptions) (resp azfake.Responder[armnetwork.ManagersClientPatchResponse], errResp azfake.ErrorResponder) +} + +// NewManagersServerTransport creates a new instance of ManagersServerTransport with the provided implementation. +// The returned ManagersServerTransport instance is connected to an instance of armnetwork.ManagersClient by way of the +// undefined.Transporter field. +func NewManagersServerTransport(srv *ManagersServer) *ManagersServerTransport { + return &ManagersServerTransport{srv: srv} +} + +// ManagersServerTransport connects instances of armnetwork.ManagersClient to instances of ManagersServer. +// Don't use this type directly, use NewManagersServerTransport instead. +type ManagersServerTransport struct { + srv *ManagersServer + beginDelete *azfake.PollerResponder[armnetwork.ManagersClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ManagersClientListResponse] + newListBySubscriptionPager *azfake.PagerResponder[armnetwork.ManagersClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for ManagersServerTransport. +func (m *ManagersServerTransport) 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 "ManagersClient.CreateOrUpdate": + resp, err = m.dispatchCreateOrUpdate(req) + case "ManagersClient.BeginDelete": + resp, err = m.dispatchBeginDelete(req) + case "ManagersClient.Get": + resp, err = m.dispatchGet(req) + case "ManagersClient.NewListPager": + resp, err = m.dispatchNewListPager(req) + case "ManagersClient.NewListBySubscriptionPager": + resp, err = m.dispatchNewListBySubscriptionPager(req) + case "ManagersClient.Patch": + resp, err = m.dispatchPatch(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *ManagersServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if m.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Manager](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, 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).Manager, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if m.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if m.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + forceUnescaped, err := url.QueryUnescape(qp.Get("force")) + if err != nil { + return nil, err + } + forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armnetwork.ManagersClientBeginDeleteOptions + if forceParam != nil { + options = &armnetwork.ManagersClientBeginDeleteOptions{ + Force: forceParam, + } + } + respr, errRespr := m.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + m.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(m.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(m.beginDelete) { + m.beginDelete = nil + } + + return resp, nil +} + +func (m *ManagersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if m.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, 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).Manager, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if m.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if m.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.ManagersClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.ManagersClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := m.srv.NewListPager(resourceGroupNameUnescaped, options) + m.newListPager = &resp + server.PagerResponderInjectNextLinks(m.newListPager, req, func(page *armnetwork.ManagersClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(m.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(m.newListPager) { + m.newListPager = nil + } + return resp, nil +} + +func (m *ManagersServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if m.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + if m.newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers` + regex := regexp.MustCompile(regexStr) + 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() + 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 + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.ManagersClientListBySubscriptionOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.ManagersClientListBySubscriptionOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := m.srv.NewListBySubscriptionPager(options) + m.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(m.newListBySubscriptionPager, req, func(page *armnetwork.ManagersClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(m.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(m.newListBySubscriptionPager) { + m.newListBySubscriptionPager = nil + } + return resp, nil +} + +func (m *ManagersServerTransport) dispatchPatch(req *http.Request) (*http.Response, error) { + if m.srv.Patch == nil { + return nil, &nonRetriableError{errors.New("fake for method Patch not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PatchObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Patch(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, 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).Manager, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/natgateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/natgateways_server.go new file mode 100644 index 000000000000..1d34c2613f93 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/natgateways_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// NatGatewaysServer is a fake server for instances of the armnetwork.NatGatewaysClient type. +type NatGatewaysServer struct { + // BeginCreateOrUpdate is the fake for method NatGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, natGatewayName string, parameters armnetwork.NatGateway, options *armnetwork.NatGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.NatGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method NatGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, natGatewayName string, options *armnetwork.NatGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.NatGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method NatGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, natGatewayName string, options *armnetwork.NatGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.NatGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method NatGatewaysClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.NatGatewaysClientListOptions) (resp azfake.PagerResponder[armnetwork.NatGatewaysClientListResponse]) + + // NewListAllPager is the fake for method NatGatewaysClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.NatGatewaysClientListAllOptions) (resp azfake.PagerResponder[armnetwork.NatGatewaysClientListAllResponse]) + + // UpdateTags is the fake for method NatGatewaysClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, natGatewayName string, parameters armnetwork.TagsObject, options *armnetwork.NatGatewaysClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.NatGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewNatGatewaysServerTransport creates a new instance of NatGatewaysServerTransport with the provided implementation. +// The returned NatGatewaysServerTransport instance is connected to an instance of armnetwork.NatGatewaysClient by way of the +// undefined.Transporter field. +func NewNatGatewaysServerTransport(srv *NatGatewaysServer) *NatGatewaysServerTransport { + return &NatGatewaysServerTransport{srv: srv} +} + +// NatGatewaysServerTransport connects instances of armnetwork.NatGatewaysClient to instances of NatGatewaysServer. +// Don't use this type directly, use NewNatGatewaysServerTransport instead. +type NatGatewaysServerTransport struct { + srv *NatGatewaysServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.NatGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.NatGatewaysClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.NatGatewaysClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.NatGatewaysClientListAllResponse] +} + +// Do implements the policy.Transporter interface for NatGatewaysServerTransport. +func (n *NatGatewaysServerTransport) 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 "NatGatewaysClient.BeginCreateOrUpdate": + resp, err = n.dispatchBeginCreateOrUpdate(req) + case "NatGatewaysClient.BeginDelete": + resp, err = n.dispatchBeginDelete(req) + case "NatGatewaysClient.Get": + resp, err = n.dispatchGet(req) + case "NatGatewaysClient.NewListPager": + resp, err = n.dispatchNewListPager(req) + case "NatGatewaysClient.NewListAllPager": + resp, err = n.dispatchNewListAllPager(req) + case "NatGatewaysClient.UpdateTags": + resp, err = n.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (n *NatGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if n.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if n.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/natGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.NatGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + natGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := n.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, natGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + n.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(n.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(n.beginCreateOrUpdate) { + n.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (n *NatGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if n.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if n.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/natGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + natGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := n.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, natGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + n.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(n.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(n.beginDelete) { + n.beginDelete = nil + } + + return resp, nil +} + +func (n *NatGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if n.srv.Get == nil { + 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.Network/natGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + natGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natGatewayName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.NatGatewaysClientGetOptions + if expandParam != nil { + options = &armnetwork.NatGatewaysClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := n.srv.Get(req.Context(), resourceGroupNameUnescaped, natGatewayNameUnescaped, 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).NatGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (n *NatGatewaysServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if n.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if n.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/natGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := n.srv.NewListPager(resourceGroupNameUnescaped, nil) + n.newListPager = &resp + server.PagerResponderInjectNextLinks(n.newListPager, req, func(page *armnetwork.NatGatewaysClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(n.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(n.newListPager) { + n.newListPager = nil + } + return resp, nil +} + +func (n *NatGatewaysServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if n.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if n.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/natGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := n.srv.NewListAllPager(nil) + n.newListAllPager = &resp + server.PagerResponderInjectNextLinks(n.newListAllPager, req, func(page *armnetwork.NatGatewaysClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(n.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(n.newListAllPager) { + n.newListAllPager = nil + } + return resp, nil +} + +func (n *NatGatewaysServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if n.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/natGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + natGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := n.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, natGatewayNameUnescaped, 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).NatGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/natrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/natrules_server.go new file mode 100644 index 000000000000..7a514addbece --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/natrules_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// NatRulesServer is a fake server for instances of the armnetwork.NatRulesClient type. +type NatRulesServer struct { + // BeginCreateOrUpdate is the fake for method NatRulesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, gatewayName string, natRuleName string, natRuleParameters armnetwork.VPNGatewayNatRule, options *armnetwork.NatRulesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.NatRulesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method NatRulesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, gatewayName string, natRuleName string, options *armnetwork.NatRulesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.NatRulesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method NatRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, gatewayName string, natRuleName string, options *armnetwork.NatRulesClientGetOptions) (resp azfake.Responder[armnetwork.NatRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByVPNGatewayPager is the fake for method NatRulesClient.NewListByVPNGatewayPager + // HTTP status codes to indicate success: http.StatusOK + NewListByVPNGatewayPager func(resourceGroupName string, gatewayName string, options *armnetwork.NatRulesClientListByVPNGatewayOptions) (resp azfake.PagerResponder[armnetwork.NatRulesClientListByVPNGatewayResponse]) +} + +// NewNatRulesServerTransport creates a new instance of NatRulesServerTransport with the provided implementation. +// The returned NatRulesServerTransport instance is connected to an instance of armnetwork.NatRulesClient by way of the +// undefined.Transporter field. +func NewNatRulesServerTransport(srv *NatRulesServer) *NatRulesServerTransport { + return &NatRulesServerTransport{srv: srv} +} + +// NatRulesServerTransport connects instances of armnetwork.NatRulesClient to instances of NatRulesServer. +// Don't use this type directly, use NewNatRulesServerTransport instead. +type NatRulesServerTransport struct { + srv *NatRulesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.NatRulesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.NatRulesClientDeleteResponse] + newListByVPNGatewayPager *azfake.PagerResponder[armnetwork.NatRulesClientListByVPNGatewayResponse] +} + +// Do implements the policy.Transporter interface for NatRulesServerTransport. +func (n *NatRulesServerTransport) 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 "NatRulesClient.BeginCreateOrUpdate": + resp, err = n.dispatchBeginCreateOrUpdate(req) + case "NatRulesClient.BeginDelete": + resp, err = n.dispatchBeginDelete(req) + case "NatRulesClient.Get": + resp, err = n.dispatchGet(req) + case "NatRulesClient.NewListByVPNGatewayPager": + resp, err = n.dispatchNewListByVPNGatewayPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (n *NatRulesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if n.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if n.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNGatewayNatRule](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + natRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := n.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, natRuleNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + n.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(n.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(n.beginCreateOrUpdate) { + n.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (n *NatRulesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if n.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if n.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + natRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := n.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, natRuleNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + n.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(n.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(n.beginDelete) { + n.beginDelete = nil + } + + return resp, nil +} + +func (n *NatRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if n.srv.Get == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + natRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := n.srv.Get(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, natRuleNameUnescaped, 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).VPNGatewayNatRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (n *NatRulesServerTransport) dispatchNewListByVPNGatewayPager(req *http.Request) (*http.Response, error) { + if n.srv.NewListByVPNGatewayPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByVPNGatewayPager not implemented")} + } + if n.newListByVPNGatewayPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + resp := n.srv.NewListByVPNGatewayPager(resourceGroupNameUnescaped, gatewayNameUnescaped, nil) + n.newListByVPNGatewayPager = &resp + server.PagerResponderInjectNextLinks(n.newListByVPNGatewayPager, req, func(page *armnetwork.NatRulesClientListByVPNGatewayResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(n.newListByVPNGatewayPager, 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(n.newListByVPNGatewayPager) { + n.newListByVPNGatewayPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/operations_server.go b/sdk/resourcemanager/network/armnetwork/fake/operations_server.go new file mode 100644 index 000000000000..1cd983ca681f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/operations_server.go @@ -0,0 +1,90 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3" + "net/http" +) + +// OperationsServer is a fake server for instances of the armnetwork.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.OperationsClientListOptions) (resp azfake.PagerResponder[armnetwork.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armnetwork.OperationsClient by way of the +// undefined.Transporter field. +func NewOperationsServerTransport(srv *OperationsServer) *OperationsServerTransport { + return &OperationsServerTransport{srv: srv} +} + +// OperationsServerTransport connects instances of armnetwork.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *azfake.PagerResponder[armnetwork.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("fake for method NewListPager not implemented")} + } + if o.newListPager == nil { + resp := o.srv.NewListPager(nil) + o.newListPager = &resp + server.PagerResponderInjectNextLinks(o.newListPager, req, func(page *armnetwork.OperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(o.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(o.newListPager) { + o.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/p2svpngateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/p2svpngateways_server.go new file mode 100644 index 000000000000..68a95764bc2f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/p2svpngateways_server.go @@ -0,0 +1,583 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// P2SVPNGatewaysServer is a fake server for instances of the armnetwork.P2SVPNGatewaysClient type. +type P2SVPNGatewaysServer struct { + // BeginCreateOrUpdate is the fake for method P2SVPNGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, gatewayName string, p2SVPNGatewayParameters armnetwork.P2SVPNGateway, options *armnetwork.P2SVPNGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method P2SVPNGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.P2SVPNGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDisconnectP2SVPNConnections is the fake for method P2SVPNGatewaysClient.BeginDisconnectP2SVPNConnections + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDisconnectP2SVPNConnections func(ctx context.Context, resourceGroupName string, p2SVPNGatewayName string, request armnetwork.P2SVPNConnectionRequest, options *armnetwork.P2SVPNGatewaysClientBeginDisconnectP2SVPNConnectionsOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientDisconnectP2SVPNConnectionsResponse], errResp azfake.ErrorResponder) + + // BeginGenerateVPNProfile is the fake for method P2SVPNGatewaysClient.BeginGenerateVPNProfile + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGenerateVPNProfile func(ctx context.Context, resourceGroupName string, gatewayName string, parameters armnetwork.P2SVPNProfileParameters, options *armnetwork.P2SVPNGatewaysClientBeginGenerateVPNProfileOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientGenerateVPNProfileResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method P2SVPNGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.P2SVPNGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.P2SVPNGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGetP2SVPNConnectionHealth is the fake for method P2SVPNGatewaysClient.BeginGetP2SVPNConnectionHealth + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetP2SVPNConnectionHealth func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.P2SVPNGatewaysClientBeginGetP2SVPNConnectionHealthOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientGetP2SVPNConnectionHealthResponse], errResp azfake.ErrorResponder) + + // BeginGetP2SVPNConnectionHealthDetailed is the fake for method P2SVPNGatewaysClient.BeginGetP2SVPNConnectionHealthDetailed + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetP2SVPNConnectionHealthDetailed func(ctx context.Context, resourceGroupName string, gatewayName string, request armnetwork.P2SVPNConnectionHealthRequest, options *armnetwork.P2SVPNGatewaysClientBeginGetP2SVPNConnectionHealthDetailedOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientGetP2SVPNConnectionHealthDetailedResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method P2SVPNGatewaysClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.P2SVPNGatewaysClientListOptions) (resp azfake.PagerResponder[armnetwork.P2SVPNGatewaysClientListResponse]) + + // NewListByResourceGroupPager is the fake for method P2SVPNGatewaysClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.P2SVPNGatewaysClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.P2SVPNGatewaysClientListByResourceGroupResponse]) + + // BeginReset is the fake for method P2SVPNGatewaysClient.BeginReset + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReset func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.P2SVPNGatewaysClientBeginResetOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientResetResponse], errResp azfake.ErrorResponder) + + // BeginUpdateTags is the fake for method P2SVPNGatewaysClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, gatewayName string, p2SVPNGatewayParameters armnetwork.TagsObject, options *armnetwork.P2SVPNGatewaysClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewP2SVPNGatewaysServerTransport creates a new instance of P2SVPNGatewaysServerTransport with the provided implementation. +// The returned P2SVPNGatewaysServerTransport instance is connected to an instance of armnetwork.P2SVPNGatewaysClient by way of the +// undefined.Transporter field. +func NewP2SVPNGatewaysServerTransport(srv *P2SVPNGatewaysServer) *P2SVPNGatewaysServerTransport { + return &P2SVPNGatewaysServerTransport{srv: srv} +} + +// P2SVPNGatewaysServerTransport connects instances of armnetwork.P2SVPNGatewaysClient to instances of P2SVPNGatewaysServer. +// Don't use this type directly, use NewP2SVPNGatewaysServerTransport instead. +type P2SVPNGatewaysServerTransport struct { + srv *P2SVPNGatewaysServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientDeleteResponse] + beginDisconnectP2SVPNConnections *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientDisconnectP2SVPNConnectionsResponse] + beginGenerateVPNProfile *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientGenerateVPNProfileResponse] + beginGetP2SVPNConnectionHealth *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientGetP2SVPNConnectionHealthResponse] + beginGetP2SVPNConnectionHealthDetailed *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientGetP2SVPNConnectionHealthDetailedResponse] + newListPager *azfake.PagerResponder[armnetwork.P2SVPNGatewaysClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.P2SVPNGatewaysClientListByResourceGroupResponse] + beginReset *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientResetResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.P2SVPNGatewaysClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for P2SVPNGatewaysServerTransport. +func (p *P2SVPNGatewaysServerTransport) 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 "P2SVPNGatewaysClient.BeginCreateOrUpdate": + resp, err = p.dispatchBeginCreateOrUpdate(req) + case "P2SVPNGatewaysClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "P2SVPNGatewaysClient.BeginDisconnectP2SVPNConnections": + resp, err = p.dispatchBeginDisconnectP2SVPNConnections(req) + case "P2SVPNGatewaysClient.BeginGenerateVPNProfile": + resp, err = p.dispatchBeginGenerateVPNProfile(req) + case "P2SVPNGatewaysClient.Get": + resp, err = p.dispatchGet(req) + case "P2SVPNGatewaysClient.BeginGetP2SVPNConnectionHealth": + resp, err = p.dispatchBeginGetP2SVPNConnectionHealth(req) + case "P2SVPNGatewaysClient.BeginGetP2SVPNConnectionHealthDetailed": + resp, err = p.dispatchBeginGetP2SVPNConnectionHealthDetailed(req) + case "P2SVPNGatewaysClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "P2SVPNGatewaysClient.NewListByResourceGroupPager": + resp, err = p.dispatchNewListByResourceGroupPager(req) + case "P2SVPNGatewaysClient.BeginReset": + resp, err = p.dispatchBeginReset(req) + case "P2SVPNGatewaysClient.BeginUpdateTags": + resp, err = p.dispatchBeginUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if p.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.P2SVPNGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreateOrUpdate) { + p.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginDisconnectP2SVPNConnections(req *http.Request) (*http.Response, error) { + if p.srv.BeginDisconnectP2SVPNConnections == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDisconnectP2SVPNConnections not implemented")} + } + if p.beginDisconnectP2SVPNConnections == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/disconnectP2sVpnConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.P2SVPNConnectionRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + p2SVPNGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("p2sVpnGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDisconnectP2SVPNConnections(req.Context(), resourceGroupNameUnescaped, p2SVPNGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDisconnectP2SVPNConnections = &respr + } + + resp, err := server.PollerResponderNext(p.beginDisconnectP2SVPNConnections, 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(p.beginDisconnectP2SVPNConnections) { + p.beginDisconnectP2SVPNConnections = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginGenerateVPNProfile(req *http.Request) (*http.Response, error) { + if p.srv.BeginGenerateVPNProfile == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGenerateVPNProfile not implemented")} + } + if p.beginGenerateVPNProfile == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generatevpnprofile` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.P2SVPNProfileParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginGenerateVPNProfile(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginGenerateVPNProfile = &respr + } + + resp, err := server.PollerResponderNext(p.beginGenerateVPNProfile, 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(p.beginGenerateVPNProfile) { + p.beginGenerateVPNProfile = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, 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).P2SVPNGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginGetP2SVPNConnectionHealth(req *http.Request) (*http.Response, error) { + if p.srv.BeginGetP2SVPNConnectionHealth == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetP2SVPNConnectionHealth not implemented")} + } + if p.beginGetP2SVPNConnectionHealth == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getP2sVpnConnectionHealth` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginGetP2SVPNConnectionHealth(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginGetP2SVPNConnectionHealth = &respr + } + + resp, err := server.PollerResponderNext(p.beginGetP2SVPNConnectionHealth, 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(p.beginGetP2SVPNConnectionHealth) { + p.beginGetP2SVPNConnectionHealth = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginGetP2SVPNConnectionHealthDetailed(req *http.Request) (*http.Response, error) { + if p.srv.BeginGetP2SVPNConnectionHealthDetailed == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetP2SVPNConnectionHealthDetailed not implemented")} + } + if p.beginGetP2SVPNConnectionHealthDetailed == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getP2sVpnConnectionHealthDetailed` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.P2SVPNConnectionHealthRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginGetP2SVPNConnectionHealthDetailed(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginGetP2SVPNConnectionHealthDetailed = &respr + } + + resp, err := server.PollerResponderNext(p.beginGetP2SVPNConnectionHealthDetailed, 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(p.beginGetP2SVPNConnectionHealthDetailed) { + p.beginGetP2SVPNConnectionHealthDetailed = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := p.srv.NewListPager(nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.P2SVPNGatewaysClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListByResourceGroupPager == nil { + 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.Network/p2svpnGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.P2SVPNGatewaysClientListByResourceGroupResponse, 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 *P2SVPNGatewaysServerTransport) dispatchBeginReset(req *http.Request) (*http.Response, error) { + if p.srv.BeginReset == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginReset not implemented")} + } + if p.beginReset == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reset` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginReset(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginReset = &respr + } + + resp, err := server.PollerResponderNext(p.beginReset, 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(p.beginReset) { + p.beginReset = nil + } + + return resp, nil +} + +func (p *P2SVPNGatewaysServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if p.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if p.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/p2svpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(p.beginUpdateTags, 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(p.beginUpdateTags) { + p.beginUpdateTags = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/packetcaptures_server.go b/sdk/resourcemanager/network/armnetwork/fake/packetcaptures_server.go new file mode 100644 index 000000000000..e1db336f8c85 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/packetcaptures_server.go @@ -0,0 +1,358 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PacketCapturesServer is a fake server for instances of the armnetwork.PacketCapturesClient type. +type PacketCapturesServer struct { + // BeginCreate is the fake for method PacketCapturesClient.BeginCreate + // HTTP status codes to indicate success: http.StatusCreated + BeginCreate func(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters armnetwork.PacketCapture, options *armnetwork.PacketCapturesClientBeginCreateOptions) (resp azfake.PollerResponder[armnetwork.PacketCapturesClientCreateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method PacketCapturesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *armnetwork.PacketCapturesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.PacketCapturesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method PacketCapturesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *armnetwork.PacketCapturesClientGetOptions) (resp azfake.Responder[armnetwork.PacketCapturesClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGetStatus is the fake for method PacketCapturesClient.BeginGetStatus + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetStatus func(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *armnetwork.PacketCapturesClientBeginGetStatusOptions) (resp azfake.PollerResponder[armnetwork.PacketCapturesClientGetStatusResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PacketCapturesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkWatcherName string, options *armnetwork.PacketCapturesClientListOptions) (resp azfake.PagerResponder[armnetwork.PacketCapturesClientListResponse]) + + // BeginStop is the fake for method PacketCapturesClient.BeginStop + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStop func(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *armnetwork.PacketCapturesClientBeginStopOptions) (resp azfake.PollerResponder[armnetwork.PacketCapturesClientStopResponse], errResp azfake.ErrorResponder) +} + +// NewPacketCapturesServerTransport creates a new instance of PacketCapturesServerTransport with the provided implementation. +// The returned PacketCapturesServerTransport instance is connected to an instance of armnetwork.PacketCapturesClient by way of the +// undefined.Transporter field. +func NewPacketCapturesServerTransport(srv *PacketCapturesServer) *PacketCapturesServerTransport { + return &PacketCapturesServerTransport{srv: srv} +} + +// PacketCapturesServerTransport connects instances of armnetwork.PacketCapturesClient to instances of PacketCapturesServer. +// Don't use this type directly, use NewPacketCapturesServerTransport instead. +type PacketCapturesServerTransport struct { + srv *PacketCapturesServer + beginCreate *azfake.PollerResponder[armnetwork.PacketCapturesClientCreateResponse] + beginDelete *azfake.PollerResponder[armnetwork.PacketCapturesClientDeleteResponse] + beginGetStatus *azfake.PollerResponder[armnetwork.PacketCapturesClientGetStatusResponse] + newListPager *azfake.PagerResponder[armnetwork.PacketCapturesClientListResponse] + beginStop *azfake.PollerResponder[armnetwork.PacketCapturesClientStopResponse] +} + +// Do implements the policy.Transporter interface for PacketCapturesServerTransport. +func (p *PacketCapturesServerTransport) 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 "PacketCapturesClient.BeginCreate": + resp, err = p.dispatchBeginCreate(req) + case "PacketCapturesClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "PacketCapturesClient.Get": + resp, err = p.dispatchGet(req) + case "PacketCapturesClient.BeginGetStatus": + resp, err = p.dispatchBeginGetStatus(req) + case "PacketCapturesClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "PacketCapturesClient.BeginStop": + resp, err = p.dispatchBeginStop(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PacketCapturesServerTransport) dispatchBeginCreate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreate not implemented")} + } + if p.beginCreate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCaptures/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PacketCapture](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + packetCaptureNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("packetCaptureName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreate(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, packetCaptureNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreate) { + p.beginCreate = nil + } + + return resp, nil +} + +func (p *PacketCapturesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCaptures/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + packetCaptureNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("packetCaptureName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, packetCaptureNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *PacketCapturesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCaptures/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + packetCaptureNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("packetCaptureName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, packetCaptureNameUnescaped, 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).PacketCaptureResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PacketCapturesServerTransport) dispatchBeginGetStatus(req *http.Request) (*http.Response, error) { + if p.srv.BeginGetStatus == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetStatus not implemented")} + } + if p.beginGetStatus == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCaptures/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/queryStatus` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + packetCaptureNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("packetCaptureName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginGetStatus(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, packetCaptureNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginGetStatus = &respr + } + + resp, err := server.PollerResponderNext(p.beginGetStatus, 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(p.beginGetStatus) { + p.beginGetStatus = nil + } + + return resp, nil +} + +func (p *PacketCapturesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCaptures` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, networkWatcherNameUnescaped, nil) + p.newListPager = &resp + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *PacketCapturesServerTransport) dispatchBeginStop(req *http.Request) (*http.Response, error) { + if p.srv.BeginStop == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStop not implemented")} + } + if p.beginStop == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/packetCaptures/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stop` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + packetCaptureNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("packetCaptureName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginStop(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, packetCaptureNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginStop = &respr + } + + resp, err := server.PollerResponderNext(p.beginStop, 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(p.beginStop) { + p.beginStop = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/peerexpressroutecircuitconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/peerexpressroutecircuitconnections_server.go new file mode 100644 index 000000000000..7ab7b4c6de9f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/peerexpressroutecircuitconnections_server.go @@ -0,0 +1,158 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PeerExpressRouteCircuitConnectionsServer is a fake server for instances of the armnetwork.PeerExpressRouteCircuitConnectionsClient type. +type PeerExpressRouteCircuitConnectionsServer struct { + // Get is the fake for method PeerExpressRouteCircuitConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *armnetwork.PeerExpressRouteCircuitConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.PeerExpressRouteCircuitConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PeerExpressRouteCircuitConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, circuitName string, peeringName string, options *armnetwork.PeerExpressRouteCircuitConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.PeerExpressRouteCircuitConnectionsClientListResponse]) +} + +// NewPeerExpressRouteCircuitConnectionsServerTransport creates a new instance of PeerExpressRouteCircuitConnectionsServerTransport with the provided implementation. +// The returned PeerExpressRouteCircuitConnectionsServerTransport instance is connected to an instance of armnetwork.PeerExpressRouteCircuitConnectionsClient by way of the +// undefined.Transporter field. +func NewPeerExpressRouteCircuitConnectionsServerTransport(srv *PeerExpressRouteCircuitConnectionsServer) *PeerExpressRouteCircuitConnectionsServerTransport { + return &PeerExpressRouteCircuitConnectionsServerTransport{srv: srv} +} + +// PeerExpressRouteCircuitConnectionsServerTransport connects instances of armnetwork.PeerExpressRouteCircuitConnectionsClient to instances of PeerExpressRouteCircuitConnectionsServer. +// Don't use this type directly, use NewPeerExpressRouteCircuitConnectionsServerTransport instead. +type PeerExpressRouteCircuitConnectionsServerTransport struct { + srv *PeerExpressRouteCircuitConnectionsServer + newListPager *azfake.PagerResponder[armnetwork.PeerExpressRouteCircuitConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for PeerExpressRouteCircuitConnectionsServerTransport. +func (p *PeerExpressRouteCircuitConnectionsServerTransport) 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 "PeerExpressRouteCircuitConnectionsClient.Get": + resp, err = p.dispatchGet(req) + case "PeerExpressRouteCircuitConnectionsClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PeerExpressRouteCircuitConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, connectionNameUnescaped, 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).PeerExpressRouteCircuitConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PeerExpressRouteCircuitConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/expressRouteCircuits/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + circuitNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("circuitName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, circuitNameUnescaped, peeringNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.PeerExpressRouteCircuitConnectionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/polymorphic_helpers.go b/sdk/resourcemanager/network/armnetwork/fake/polymorphic_helpers.go new file mode 100644 index 000000000000..54969dc26ff8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/polymorphic_helpers.go @@ -0,0 +1,226 @@ +//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" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3" +) + +func unmarshalActiveBaseSecurityAdminRuleClassification(rawMsg json.RawMessage) (armnetwork.ActiveBaseSecurityAdminRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]any + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b armnetwork.ActiveBaseSecurityAdminRuleClassification + switch m["kind"] { + case string(armnetwork.EffectiveAdminRuleKindCustom): + b = &armnetwork.ActiveSecurityAdminRule{} + case string(armnetwork.EffectiveAdminRuleKindDefault): + b = &armnetwork.ActiveDefaultSecurityAdminRule{} + default: + b = &armnetwork.ActiveBaseSecurityAdminRule{} + } + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil +} + +func unmarshalActiveBaseSecurityAdminRuleClassificationArray(rawMsg json.RawMessage) ([]armnetwork.ActiveBaseSecurityAdminRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]armnetwork.ActiveBaseSecurityAdminRuleClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalActiveBaseSecurityAdminRuleClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} + +func unmarshalBaseAdminRuleClassification(rawMsg json.RawMessage) (armnetwork.BaseAdminRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]any + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b armnetwork.BaseAdminRuleClassification + switch m["kind"] { + case string(armnetwork.AdminRuleKindCustom): + b = &armnetwork.AdminRule{} + case string(armnetwork.AdminRuleKindDefault): + b = &armnetwork.DefaultAdminRule{} + default: + b = &armnetwork.BaseAdminRule{} + } + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil +} + +func unmarshalBaseAdminRuleClassificationArray(rawMsg json.RawMessage) ([]armnetwork.BaseAdminRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]armnetwork.BaseAdminRuleClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalBaseAdminRuleClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} + +func unmarshalEffectiveBaseSecurityAdminRuleClassification(rawMsg json.RawMessage) (armnetwork.EffectiveBaseSecurityAdminRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]any + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b armnetwork.EffectiveBaseSecurityAdminRuleClassification + switch m["kind"] { + case string(armnetwork.EffectiveAdminRuleKindCustom): + b = &armnetwork.EffectiveSecurityAdminRule{} + case string(armnetwork.EffectiveAdminRuleKindDefault): + b = &armnetwork.EffectiveDefaultSecurityAdminRule{} + default: + b = &armnetwork.EffectiveBaseSecurityAdminRule{} + } + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil +} + +func unmarshalEffectiveBaseSecurityAdminRuleClassificationArray(rawMsg json.RawMessage) ([]armnetwork.EffectiveBaseSecurityAdminRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]armnetwork.EffectiveBaseSecurityAdminRuleClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalEffectiveBaseSecurityAdminRuleClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} + +func unmarshalFirewallPolicyRuleClassification(rawMsg json.RawMessage) (armnetwork.FirewallPolicyRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]any + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b armnetwork.FirewallPolicyRuleClassification + switch m["ruleType"] { + case string(armnetwork.FirewallPolicyRuleTypeApplicationRule): + b = &armnetwork.ApplicationRule{} + case string(armnetwork.FirewallPolicyRuleTypeNatRule): + b = &armnetwork.NatRule{} + case string(armnetwork.FirewallPolicyRuleTypeNetworkRule): + b = &armnetwork.Rule{} + default: + b = &armnetwork.FirewallPolicyRule{} + } + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil +} + +func unmarshalFirewallPolicyRuleClassificationArray(rawMsg json.RawMessage) ([]armnetwork.FirewallPolicyRuleClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]armnetwork.FirewallPolicyRuleClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalFirewallPolicyRuleClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} + +func unmarshalFirewallPolicyRuleCollectionClassification(rawMsg json.RawMessage) (armnetwork.FirewallPolicyRuleCollectionClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]any + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b armnetwork.FirewallPolicyRuleCollectionClassification + switch m["ruleCollectionType"] { + case string(armnetwork.FirewallPolicyRuleCollectionTypeFirewallPolicyFilterRuleCollection): + b = &armnetwork.FirewallPolicyFilterRuleCollection{} + case string(armnetwork.FirewallPolicyRuleCollectionTypeFirewallPolicyNatRuleCollection): + b = &armnetwork.FirewallPolicyNatRuleCollection{} + default: + b = &armnetwork.FirewallPolicyRuleCollection{} + } + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil +} + +func unmarshalFirewallPolicyRuleCollectionClassificationArray(rawMsg json.RawMessage) ([]armnetwork.FirewallPolicyRuleCollectionClassification, error) { + if rawMsg == nil { + return nil, nil + } + var rawMessages []json.RawMessage + if err := json.Unmarshal(rawMsg, &rawMessages); err != nil { + return nil, err + } + fArray := make([]armnetwork.FirewallPolicyRuleCollectionClassification, len(rawMessages)) + for index, rawMessage := range rawMessages { + f, err := unmarshalFirewallPolicyRuleCollectionClassification(rawMessage) + if err != nil { + return nil, err + } + fArray[index] = f + } + return fArray, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/privatednszonegroups_server.go b/sdk/resourcemanager/network/armnetwork/fake/privatednszonegroups_server.go new file mode 100644 index 000000000000..f62a8adc8dbc --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/privatednszonegroups_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PrivateDNSZoneGroupsServer is a fake server for instances of the armnetwork.PrivateDNSZoneGroupsClient type. +type PrivateDNSZoneGroupsServer struct { + // BeginCreateOrUpdate is the fake for method PrivateDNSZoneGroupsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, privateEndpointName string, privateDNSZoneGroupName string, parameters armnetwork.PrivateDNSZoneGroup, options *armnetwork.PrivateDNSZoneGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.PrivateDNSZoneGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method PrivateDNSZoneGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, privateEndpointName string, privateDNSZoneGroupName string, options *armnetwork.PrivateDNSZoneGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.PrivateDNSZoneGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method PrivateDNSZoneGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, privateEndpointName string, privateDNSZoneGroupName string, options *armnetwork.PrivateDNSZoneGroupsClientGetOptions) (resp azfake.Responder[armnetwork.PrivateDNSZoneGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PrivateDNSZoneGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(privateEndpointName string, resourceGroupName string, options *armnetwork.PrivateDNSZoneGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.PrivateDNSZoneGroupsClientListResponse]) +} + +// NewPrivateDNSZoneGroupsServerTransport creates a new instance of PrivateDNSZoneGroupsServerTransport with the provided implementation. +// The returned PrivateDNSZoneGroupsServerTransport instance is connected to an instance of armnetwork.PrivateDNSZoneGroupsClient by way of the +// undefined.Transporter field. +func NewPrivateDNSZoneGroupsServerTransport(srv *PrivateDNSZoneGroupsServer) *PrivateDNSZoneGroupsServerTransport { + return &PrivateDNSZoneGroupsServerTransport{srv: srv} +} + +// PrivateDNSZoneGroupsServerTransport connects instances of armnetwork.PrivateDNSZoneGroupsClient to instances of PrivateDNSZoneGroupsServer. +// Don't use this type directly, use NewPrivateDNSZoneGroupsServerTransport instead. +type PrivateDNSZoneGroupsServerTransport struct { + srv *PrivateDNSZoneGroupsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.PrivateDNSZoneGroupsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.PrivateDNSZoneGroupsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.PrivateDNSZoneGroupsClientListResponse] +} + +// Do implements the policy.Transporter interface for PrivateDNSZoneGroupsServerTransport. +func (p *PrivateDNSZoneGroupsServerTransport) 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 "PrivateDNSZoneGroupsClient.BeginCreateOrUpdate": + resp, err = p.dispatchBeginCreateOrUpdate(req) + case "PrivateDNSZoneGroupsClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "PrivateDNSZoneGroupsClient.Get": + resp, err = p.dispatchGet(req) + case "PrivateDNSZoneGroupsClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PrivateDNSZoneGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if p.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateDnsZoneGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PrivateDNSZoneGroup](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + privateDNSZoneGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateDnsZoneGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, privateEndpointNameUnescaped, privateDNSZoneGroupNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreateOrUpdate) { + p.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (p *PrivateDNSZoneGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateDnsZoneGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + privateDNSZoneGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateDnsZoneGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, privateEndpointNameUnescaped, privateDNSZoneGroupNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *PrivateDNSZoneGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateDnsZoneGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + privateDNSZoneGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateDnsZoneGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, privateEndpointNameUnescaped, privateDNSZoneGroupNameUnescaped, 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).PrivateDNSZoneGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PrivateDNSZoneGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateDnsZoneGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(privateEndpointNameUnescaped, resourceGroupNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.PrivateDNSZoneGroupsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/privateendpoints_server.go b/sdk/resourcemanager/network/armnetwork/fake/privateendpoints_server.go new file mode 100644 index 000000000000..f2bbee596bc1 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/privateendpoints_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PrivateEndpointsServer is a fake server for instances of the armnetwork.PrivateEndpointsClient type. +type PrivateEndpointsServer struct { + // BeginCreateOrUpdate is the fake for method PrivateEndpointsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, privateEndpointName string, parameters armnetwork.PrivateEndpoint, options *armnetwork.PrivateEndpointsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.PrivateEndpointsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method PrivateEndpointsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, privateEndpointName string, options *armnetwork.PrivateEndpointsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.PrivateEndpointsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method PrivateEndpointsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, privateEndpointName string, options *armnetwork.PrivateEndpointsClientGetOptions) (resp azfake.Responder[armnetwork.PrivateEndpointsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PrivateEndpointsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.PrivateEndpointsClientListOptions) (resp azfake.PagerResponder[armnetwork.PrivateEndpointsClientListResponse]) + + // NewListBySubscriptionPager is the fake for method PrivateEndpointsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armnetwork.PrivateEndpointsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armnetwork.PrivateEndpointsClientListBySubscriptionResponse]) +} + +// NewPrivateEndpointsServerTransport creates a new instance of PrivateEndpointsServerTransport with the provided implementation. +// The returned PrivateEndpointsServerTransport instance is connected to an instance of armnetwork.PrivateEndpointsClient by way of the +// undefined.Transporter field. +func NewPrivateEndpointsServerTransport(srv *PrivateEndpointsServer) *PrivateEndpointsServerTransport { + return &PrivateEndpointsServerTransport{srv: srv} +} + +// PrivateEndpointsServerTransport connects instances of armnetwork.PrivateEndpointsClient to instances of PrivateEndpointsServer. +// Don't use this type directly, use NewPrivateEndpointsServerTransport instead. +type PrivateEndpointsServerTransport struct { + srv *PrivateEndpointsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.PrivateEndpointsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.PrivateEndpointsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.PrivateEndpointsClientListResponse] + newListBySubscriptionPager *azfake.PagerResponder[armnetwork.PrivateEndpointsClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for PrivateEndpointsServerTransport. +func (p *PrivateEndpointsServerTransport) 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 "PrivateEndpointsClient.BeginCreateOrUpdate": + resp, err = p.dispatchBeginCreateOrUpdate(req) + case "PrivateEndpointsClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "PrivateEndpointsClient.Get": + resp, err = p.dispatchGet(req) + case "PrivateEndpointsClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "PrivateEndpointsClient.NewListBySubscriptionPager": + resp, err = p.dispatchNewListBySubscriptionPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PrivateEndpointsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if p.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PrivateEndpoint](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, privateEndpointNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreateOrUpdate) { + p.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (p *PrivateEndpointsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, privateEndpointNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *PrivateEndpointsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/privateEndpoints/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + privateEndpointNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("privateEndpointName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PrivateEndpointsClientGetOptions + if expandParam != nil { + options = &armnetwork.PrivateEndpointsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, privateEndpointNameUnescaped, 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).PrivateEndpoint, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PrivateEndpointsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateEndpoints` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.PrivateEndpointsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *PrivateEndpointsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListBySubscriptionPager == nil { + 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.Network/privateEndpoints` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.PrivateEndpointsClientListBySubscriptionResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/privatelinkservices_server.go b/sdk/resourcemanager/network/armnetwork/fake/privatelinkservices_server.go new file mode 100644 index 000000000000..6797675672b5 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/privatelinkservices_server.go @@ -0,0 +1,676 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PrivateLinkServicesServer is a fake server for instances of the armnetwork.PrivateLinkServicesClient type. +type PrivateLinkServicesServer struct { + // BeginCheckPrivateLinkServiceVisibility is the fake for method PrivateLinkServicesClient.BeginCheckPrivateLinkServiceVisibility + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCheckPrivateLinkServiceVisibility func(ctx context.Context, location string, parameters armnetwork.CheckPrivateLinkServiceVisibilityRequest, options *armnetwork.PrivateLinkServicesClientBeginCheckPrivateLinkServiceVisibilityOptions) (resp azfake.PollerResponder[armnetwork.PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityResponse], errResp azfake.ErrorResponder) + + // BeginCheckPrivateLinkServiceVisibilityByResourceGroup is the fake for method PrivateLinkServicesClient.BeginCheckPrivateLinkServiceVisibilityByResourceGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCheckPrivateLinkServiceVisibilityByResourceGroup func(ctx context.Context, location string, resourceGroupName string, parameters armnetwork.CheckPrivateLinkServiceVisibilityRequest, options *armnetwork.PrivateLinkServicesClientBeginCheckPrivateLinkServiceVisibilityByResourceGroupOptions) (resp azfake.PollerResponder[armnetwork.PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityByResourceGroupResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method PrivateLinkServicesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, serviceName string, parameters armnetwork.PrivateLinkService, options *armnetwork.PrivateLinkServicesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.PrivateLinkServicesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method PrivateLinkServicesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, serviceName string, options *armnetwork.PrivateLinkServicesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.PrivateLinkServicesClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeletePrivateEndpointConnection is the fake for method PrivateLinkServicesClient.BeginDeletePrivateEndpointConnection + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeletePrivateEndpointConnection func(ctx context.Context, resourceGroupName string, serviceName string, peConnectionName string, options *armnetwork.PrivateLinkServicesClientBeginDeletePrivateEndpointConnectionOptions) (resp azfake.PollerResponder[armnetwork.PrivateLinkServicesClientDeletePrivateEndpointConnectionResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method PrivateLinkServicesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, serviceName string, options *armnetwork.PrivateLinkServicesClientGetOptions) (resp azfake.Responder[armnetwork.PrivateLinkServicesClientGetResponse], errResp azfake.ErrorResponder) + + // GetPrivateEndpointConnection is the fake for method PrivateLinkServicesClient.GetPrivateEndpointConnection + // HTTP status codes to indicate success: http.StatusOK + GetPrivateEndpointConnection func(ctx context.Context, resourceGroupName string, serviceName string, peConnectionName string, options *armnetwork.PrivateLinkServicesClientGetPrivateEndpointConnectionOptions) (resp azfake.Responder[armnetwork.PrivateLinkServicesClientGetPrivateEndpointConnectionResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PrivateLinkServicesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.PrivateLinkServicesClientListOptions) (resp azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListResponse]) + + // NewListAutoApprovedPrivateLinkServicesPager is the fake for method PrivateLinkServicesClient.NewListAutoApprovedPrivateLinkServicesPager + // HTTP status codes to indicate success: http.StatusOK + NewListAutoApprovedPrivateLinkServicesPager func(location string, options *armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesOptions) (resp azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesResponse]) + + // NewListAutoApprovedPrivateLinkServicesByResourceGroupPager is the fake for method PrivateLinkServicesClient.NewListAutoApprovedPrivateLinkServicesByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListAutoApprovedPrivateLinkServicesByResourceGroupPager func(location string, resourceGroupName string, options *armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method PrivateLinkServicesClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armnetwork.PrivateLinkServicesClientListBySubscriptionOptions) (resp azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListBySubscriptionResponse]) + + // NewListPrivateEndpointConnectionsPager is the fake for method PrivateLinkServicesClient.NewListPrivateEndpointConnectionsPager + // HTTP status codes to indicate success: http.StatusOK + NewListPrivateEndpointConnectionsPager func(resourceGroupName string, serviceName string, options *armnetwork.PrivateLinkServicesClientListPrivateEndpointConnectionsOptions) (resp azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListPrivateEndpointConnectionsResponse]) + + // UpdatePrivateEndpointConnection is the fake for method PrivateLinkServicesClient.UpdatePrivateEndpointConnection + // HTTP status codes to indicate success: http.StatusOK + UpdatePrivateEndpointConnection func(ctx context.Context, resourceGroupName string, serviceName string, peConnectionName string, parameters armnetwork.PrivateEndpointConnection, options *armnetwork.PrivateLinkServicesClientUpdatePrivateEndpointConnectionOptions) (resp azfake.Responder[armnetwork.PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse], errResp azfake.ErrorResponder) +} + +// NewPrivateLinkServicesServerTransport creates a new instance of PrivateLinkServicesServerTransport with the provided implementation. +// The returned PrivateLinkServicesServerTransport instance is connected to an instance of armnetwork.PrivateLinkServicesClient by way of the +// undefined.Transporter field. +func NewPrivateLinkServicesServerTransport(srv *PrivateLinkServicesServer) *PrivateLinkServicesServerTransport { + return &PrivateLinkServicesServerTransport{srv: srv} +} + +// PrivateLinkServicesServerTransport connects instances of armnetwork.PrivateLinkServicesClient to instances of PrivateLinkServicesServer. +// Don't use this type directly, use NewPrivateLinkServicesServerTransport instead. +type PrivateLinkServicesServerTransport struct { + srv *PrivateLinkServicesServer + beginCheckPrivateLinkServiceVisibility *azfake.PollerResponder[armnetwork.PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityResponse] + beginCheckPrivateLinkServiceVisibilityByResourceGroup *azfake.PollerResponder[armnetwork.PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityByResourceGroupResponse] + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.PrivateLinkServicesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.PrivateLinkServicesClientDeleteResponse] + beginDeletePrivateEndpointConnection *azfake.PollerResponder[armnetwork.PrivateLinkServicesClientDeletePrivateEndpointConnectionResponse] + newListPager *azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListResponse] + newListAutoApprovedPrivateLinkServicesPager *azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesResponse] + newListAutoApprovedPrivateLinkServicesByResourceGroupPager *azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesByResourceGroupResponse] + newListBySubscriptionPager *azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListBySubscriptionResponse] + newListPrivateEndpointConnectionsPager *azfake.PagerResponder[armnetwork.PrivateLinkServicesClientListPrivateEndpointConnectionsResponse] +} + +// Do implements the policy.Transporter interface for PrivateLinkServicesServerTransport. +func (p *PrivateLinkServicesServerTransport) 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 "PrivateLinkServicesClient.BeginCheckPrivateLinkServiceVisibility": + resp, err = p.dispatchBeginCheckPrivateLinkServiceVisibility(req) + case "PrivateLinkServicesClient.BeginCheckPrivateLinkServiceVisibilityByResourceGroup": + resp, err = p.dispatchBeginCheckPrivateLinkServiceVisibilityByResourceGroup(req) + case "PrivateLinkServicesClient.BeginCreateOrUpdate": + resp, err = p.dispatchBeginCreateOrUpdate(req) + case "PrivateLinkServicesClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "PrivateLinkServicesClient.BeginDeletePrivateEndpointConnection": + resp, err = p.dispatchBeginDeletePrivateEndpointConnection(req) + case "PrivateLinkServicesClient.Get": + resp, err = p.dispatchGet(req) + case "PrivateLinkServicesClient.GetPrivateEndpointConnection": + resp, err = p.dispatchGetPrivateEndpointConnection(req) + case "PrivateLinkServicesClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "PrivateLinkServicesClient.NewListAutoApprovedPrivateLinkServicesPager": + resp, err = p.dispatchNewListAutoApprovedPrivateLinkServicesPager(req) + case "PrivateLinkServicesClient.NewListAutoApprovedPrivateLinkServicesByResourceGroupPager": + resp, err = p.dispatchNewListAutoApprovedPrivateLinkServicesByResourceGroupPager(req) + case "PrivateLinkServicesClient.NewListBySubscriptionPager": + resp, err = p.dispatchNewListBySubscriptionPager(req) + case "PrivateLinkServicesClient.NewListPrivateEndpointConnectionsPager": + resp, err = p.dispatchNewListPrivateEndpointConnectionsPager(req) + case "PrivateLinkServicesClient.UpdatePrivateEndpointConnection": + resp, err = p.dispatchUpdatePrivateEndpointConnection(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchBeginCheckPrivateLinkServiceVisibility(req *http.Request) (*http.Response, error) { + if p.srv.BeginCheckPrivateLinkServiceVisibility == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCheckPrivateLinkServiceVisibility not implemented")} + } + if p.beginCheckPrivateLinkServiceVisibility == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/checkPrivateLinkServiceVisibility` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.CheckPrivateLinkServiceVisibilityRequest](req) + if err != nil { + return nil, err + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCheckPrivateLinkServiceVisibility(req.Context(), locationUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCheckPrivateLinkServiceVisibility = &respr + } + + resp, err := server.PollerResponderNext(p.beginCheckPrivateLinkServiceVisibility, 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(p.beginCheckPrivateLinkServiceVisibility) { + p.beginCheckPrivateLinkServiceVisibility = nil + } + + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchBeginCheckPrivateLinkServiceVisibilityByResourceGroup(req *http.Request) (*http.Response, error) { + if p.srv.BeginCheckPrivateLinkServiceVisibilityByResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCheckPrivateLinkServiceVisibilityByResourceGroup not implemented")} + } + if p.beginCheckPrivateLinkServiceVisibilityByResourceGroup == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/checkPrivateLinkServiceVisibility` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.CheckPrivateLinkServiceVisibilityRequest](req) + if err != nil { + return nil, err + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCheckPrivateLinkServiceVisibilityByResourceGroup(req.Context(), locationUnescaped, resourceGroupNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCheckPrivateLinkServiceVisibilityByResourceGroup = &respr + } + + resp, err := server.PollerResponderNext(p.beginCheckPrivateLinkServiceVisibilityByResourceGroup, 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(p.beginCheckPrivateLinkServiceVisibilityByResourceGroup) { + p.beginCheckPrivateLinkServiceVisibilityByResourceGroup = nil + } + + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if p.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PrivateLinkService](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, serviceNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreateOrUpdate) { + p.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, serviceNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchBeginDeletePrivateEndpointConnection(req *http.Request) (*http.Response, error) { + if p.srv.BeginDeletePrivateEndpointConnection == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeletePrivateEndpointConnection not implemented")} + } + if p.beginDeletePrivateEndpointConnection == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + peConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDeletePrivateEndpointConnection(req.Context(), resourceGroupNameUnescaped, serviceNameUnescaped, peConnectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDeletePrivateEndpointConnection = &respr + } + + resp, err := server.PollerResponderNext(p.beginDeletePrivateEndpointConnection, 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(p.beginDeletePrivateEndpointConnection) { + p.beginDeletePrivateEndpointConnection = nil + } + + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PrivateLinkServicesClientGetOptions + if expandParam != nil { + options = &armnetwork.PrivateLinkServicesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, serviceNameUnescaped, 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).PrivateLinkService, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchGetPrivateEndpointConnection(req *http.Request) (*http.Response, error) { + if p.srv.GetPrivateEndpointConnection == nil { + return nil, &nonRetriableError{errors.New("fake for method GetPrivateEndpointConnection not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + peConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peConnectionName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PrivateLinkServicesClientGetPrivateEndpointConnectionOptions + if expandParam != nil { + options = &armnetwork.PrivateLinkServicesClientGetPrivateEndpointConnectionOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.GetPrivateEndpointConnection(req.Context(), resourceGroupNameUnescaped, serviceNameUnescaped, peConnectionNameUnescaped, 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).PrivateEndpointConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.PrivateLinkServicesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchNewListAutoApprovedPrivateLinkServicesPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListAutoApprovedPrivateLinkServicesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAutoApprovedPrivateLinkServicesPager not implemented")} + } + if p.newListAutoApprovedPrivateLinkServicesPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/autoApprovedPrivateLinkServices` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListAutoApprovedPrivateLinkServicesPager(locationUnescaped, nil) + p.newListAutoApprovedPrivateLinkServicesPager = &resp + server.PagerResponderInjectNextLinks(p.newListAutoApprovedPrivateLinkServicesPager, req, func(page *armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListAutoApprovedPrivateLinkServicesPager, 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.newListAutoApprovedPrivateLinkServicesPager) { + p.newListAutoApprovedPrivateLinkServicesPager = nil + } + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchNewListAutoApprovedPrivateLinkServicesByResourceGroupPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListAutoApprovedPrivateLinkServicesByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAutoApprovedPrivateLinkServicesByResourceGroupPager not implemented")} + } + if p.newListAutoApprovedPrivateLinkServicesByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/autoApprovedPrivateLinkServices` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListAutoApprovedPrivateLinkServicesByResourceGroupPager(locationUnescaped, resourceGroupNameUnescaped, nil) + p.newListAutoApprovedPrivateLinkServicesByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(p.newListAutoApprovedPrivateLinkServicesByResourceGroupPager, req, func(page *armnetwork.PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListAutoApprovedPrivateLinkServicesByResourceGroupPager, 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.newListAutoApprovedPrivateLinkServicesByResourceGroupPager) { + p.newListAutoApprovedPrivateLinkServicesByResourceGroupPager = nil + } + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListBySubscriptionPager == nil { + 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.Network/privateLinkServices` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.PrivateLinkServicesClientListBySubscriptionResponse, 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 *PrivateLinkServicesServerTransport) dispatchNewListPrivateEndpointConnectionsPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPrivateEndpointConnectionsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPrivateEndpointConnectionsPager not implemented")} + } + if p.newListPrivateEndpointConnectionsPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPrivateEndpointConnectionsPager(resourceGroupNameUnescaped, serviceNameUnescaped, nil) + p.newListPrivateEndpointConnectionsPager = &resp + server.PagerResponderInjectNextLinks(p.newListPrivateEndpointConnectionsPager, req, func(page *armnetwork.PrivateLinkServicesClientListPrivateEndpointConnectionsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.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(p.newListPrivateEndpointConnectionsPager) { + p.newListPrivateEndpointConnectionsPager = nil + } + return resp, nil +} + +func (p *PrivateLinkServicesServerTransport) dispatchUpdatePrivateEndpointConnection(req *http.Request) (*http.Response, error) { + if p.srv.UpdatePrivateEndpointConnection == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdatePrivateEndpointConnection not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/privateLinkServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateEndpointConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PrivateEndpointConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceName")]) + if err != nil { + return nil, err + } + peConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.UpdatePrivateEndpointConnection(req.Context(), resourceGroupNameUnescaped, serviceNameUnescaped, peConnectionNameUnescaped, 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).PrivateEndpointConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/profiles_server.go b/sdk/resourcemanager/network/armnetwork/fake/profiles_server.go new file mode 100644 index 000000000000..0e279a32b9a8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/profiles_server.go @@ -0,0 +1,325 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ProfilesServer is a fake server for instances of the armnetwork.ProfilesClient type. +type ProfilesServer struct { + // CreateOrUpdate is the fake for method ProfilesClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkProfileName string, parameters armnetwork.Profile, options *armnetwork.ProfilesClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.ProfilesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ProfilesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkProfileName string, options *armnetwork.ProfilesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ProfilesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ProfilesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkProfileName string, options *armnetwork.ProfilesClientGetOptions) (resp azfake.Responder[armnetwork.ProfilesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ProfilesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.ProfilesClientListOptions) (resp azfake.PagerResponder[armnetwork.ProfilesClientListResponse]) + + // NewListAllPager is the fake for method ProfilesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.ProfilesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.ProfilesClientListAllResponse]) + + // UpdateTags is the fake for method ProfilesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkProfileName string, parameters armnetwork.TagsObject, options *armnetwork.ProfilesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ProfilesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewProfilesServerTransport creates a new instance of ProfilesServerTransport with the provided implementation. +// The returned ProfilesServerTransport instance is connected to an instance of armnetwork.ProfilesClient by way of the +// undefined.Transporter field. +func NewProfilesServerTransport(srv *ProfilesServer) *ProfilesServerTransport { + return &ProfilesServerTransport{srv: srv} +} + +// ProfilesServerTransport connects instances of armnetwork.ProfilesClient to instances of ProfilesServer. +// Don't use this type directly, use NewProfilesServerTransport instead. +type ProfilesServerTransport struct { + srv *ProfilesServer + beginDelete *azfake.PollerResponder[armnetwork.ProfilesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ProfilesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.ProfilesClientListAllResponse] +} + +// Do implements the policy.Transporter interface for ProfilesServerTransport. +func (p *ProfilesServerTransport) 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 "ProfilesClient.CreateOrUpdate": + resp, err = p.dispatchCreateOrUpdate(req) + case "ProfilesClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "ProfilesClient.Get": + resp, err = p.dispatchGet(req) + case "ProfilesClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "ProfilesClient.NewListAllPager": + resp, err = p.dispatchNewListAllPager(req) + case "ProfilesClient.UpdateTags": + resp, err = p.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *ProfilesServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.CreateOrUpdate == nil { + 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.Network/networkProfiles/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Profile](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkProfileNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkProfileName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkProfileNameUnescaped, 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).Profile, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProfilesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkProfiles/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkProfileNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkProfileName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkProfileNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *ProfilesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/networkProfiles/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkProfileNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkProfileName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.ProfilesClientGetOptions + if expandParam != nil { + options = &armnetwork.ProfilesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, networkProfileNameUnescaped, 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).Profile, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *ProfilesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkProfiles` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.ProfilesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *ProfilesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if p.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkProfiles` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := p.srv.NewListAllPager(nil) + p.newListAllPager = &resp + server.PagerResponderInjectNextLinks(p.newListAllPager, req, func(page *armnetwork.ProfilesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.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(p.newListAllPager) { + p.newListAllPager = nil + } + return resp, nil +} + +func (p *ProfilesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if p.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkProfiles/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkProfileNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkProfileName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkProfileNameUnescaped, 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).Profile, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/publicipaddresses_server.go b/sdk/resourcemanager/network/armnetwork/fake/publicipaddresses_server.go new file mode 100644 index 000000000000..05d04a08246f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/publicipaddresses_server.go @@ -0,0 +1,720 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PublicIPAddressesServer is a fake server for instances of the armnetwork.PublicIPAddressesClient type. +type PublicIPAddressesServer struct { + // BeginCreateOrUpdate is the fake for method PublicIPAddressesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters armnetwork.PublicIPAddress, options *armnetwork.PublicIPAddressesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.PublicIPAddressesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDdosProtectionStatus is the fake for method PublicIPAddressesClient.BeginDdosProtectionStatus + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDdosProtectionStatus func(ctx context.Context, resourceGroupName string, publicIPAddressName string, options *armnetwork.PublicIPAddressesClientBeginDdosProtectionStatusOptions) (resp azfake.PollerResponder[armnetwork.PublicIPAddressesClientDdosProtectionStatusResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method PublicIPAddressesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, publicIPAddressName string, options *armnetwork.PublicIPAddressesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.PublicIPAddressesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method PublicIPAddressesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, publicIPAddressName string, options *armnetwork.PublicIPAddressesClientGetOptions) (resp azfake.Responder[armnetwork.PublicIPAddressesClientGetResponse], errResp azfake.ErrorResponder) + + // GetCloudServicePublicIPAddress is the fake for method PublicIPAddressesClient.GetCloudServicePublicIPAddress + // HTTP status codes to indicate success: http.StatusOK + GetCloudServicePublicIPAddress func(ctx context.Context, resourceGroupName string, cloudServiceName string, roleInstanceName string, networkInterfaceName string, ipConfigurationName string, publicIPAddressName string, options *armnetwork.PublicIPAddressesClientGetCloudServicePublicIPAddressOptions) (resp azfake.Responder[armnetwork.PublicIPAddressesClientGetCloudServicePublicIPAddressResponse], errResp azfake.ErrorResponder) + + // GetVirtualMachineScaleSetPublicIPAddress is the fake for method PublicIPAddressesClient.GetVirtualMachineScaleSetPublicIPAddress + // HTTP status codes to indicate success: http.StatusOK + GetVirtualMachineScaleSetPublicIPAddress func(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, ipConfigurationName string, publicIPAddressName string, options *armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressOptions) (resp azfake.Responder[armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PublicIPAddressesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.PublicIPAddressesClientListOptions) (resp azfake.PagerResponder[armnetwork.PublicIPAddressesClientListResponse]) + + // NewListAllPager is the fake for method PublicIPAddressesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.PublicIPAddressesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.PublicIPAddressesClientListAllResponse]) + + // NewListCloudServicePublicIPAddressesPager is the fake for method PublicIPAddressesClient.NewListCloudServicePublicIPAddressesPager + // HTTP status codes to indicate success: http.StatusOK + NewListCloudServicePublicIPAddressesPager func(resourceGroupName string, cloudServiceName string, options *armnetwork.PublicIPAddressesClientListCloudServicePublicIPAddressesOptions) (resp azfake.PagerResponder[armnetwork.PublicIPAddressesClientListCloudServicePublicIPAddressesResponse]) + + // NewListCloudServiceRoleInstancePublicIPAddressesPager is the fake for method PublicIPAddressesClient.NewListCloudServiceRoleInstancePublicIPAddressesPager + // HTTP status codes to indicate success: http.StatusOK + NewListCloudServiceRoleInstancePublicIPAddressesPager func(resourceGroupName string, cloudServiceName string, roleInstanceName string, networkInterfaceName string, ipConfigurationName string, options *armnetwork.PublicIPAddressesClientListCloudServiceRoleInstancePublicIPAddressesOptions) (resp azfake.PagerResponder[armnetwork.PublicIPAddressesClientListCloudServiceRoleInstancePublicIPAddressesResponse]) + + // NewListVirtualMachineScaleSetPublicIPAddressesPager is the fake for method PublicIPAddressesClient.NewListVirtualMachineScaleSetPublicIPAddressesPager + // HTTP status codes to indicate success: http.StatusOK + NewListVirtualMachineScaleSetPublicIPAddressesPager func(resourceGroupName string, virtualMachineScaleSetName string, options *armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetPublicIPAddressesOptions) (resp azfake.PagerResponder[armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetPublicIPAddressesResponse]) + + // NewListVirtualMachineScaleSetVMPublicIPAddressesPager is the fake for method PublicIPAddressesClient.NewListVirtualMachineScaleSetVMPublicIPAddressesPager + // HTTP status codes to indicate success: http.StatusOK + NewListVirtualMachineScaleSetVMPublicIPAddressesPager func(resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, ipConfigurationName string, options *armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetVMPublicIPAddressesOptions) (resp azfake.PagerResponder[armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetVMPublicIPAddressesResponse]) + + // UpdateTags is the fake for method PublicIPAddressesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters armnetwork.TagsObject, options *armnetwork.PublicIPAddressesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.PublicIPAddressesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewPublicIPAddressesServerTransport creates a new instance of PublicIPAddressesServerTransport with the provided implementation. +// The returned PublicIPAddressesServerTransport instance is connected to an instance of armnetwork.PublicIPAddressesClient by way of the +// undefined.Transporter field. +func NewPublicIPAddressesServerTransport(srv *PublicIPAddressesServer) *PublicIPAddressesServerTransport { + return &PublicIPAddressesServerTransport{srv: srv} +} + +// PublicIPAddressesServerTransport connects instances of armnetwork.PublicIPAddressesClient to instances of PublicIPAddressesServer. +// Don't use this type directly, use NewPublicIPAddressesServerTransport instead. +type PublicIPAddressesServerTransport struct { + srv *PublicIPAddressesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.PublicIPAddressesClientCreateOrUpdateResponse] + beginDdosProtectionStatus *azfake.PollerResponder[armnetwork.PublicIPAddressesClientDdosProtectionStatusResponse] + beginDelete *azfake.PollerResponder[armnetwork.PublicIPAddressesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.PublicIPAddressesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.PublicIPAddressesClientListAllResponse] + newListCloudServicePublicIPAddressesPager *azfake.PagerResponder[armnetwork.PublicIPAddressesClientListCloudServicePublicIPAddressesResponse] + newListCloudServiceRoleInstancePublicIPAddressesPager *azfake.PagerResponder[armnetwork.PublicIPAddressesClientListCloudServiceRoleInstancePublicIPAddressesResponse] + newListVirtualMachineScaleSetPublicIPAddressesPager *azfake.PagerResponder[armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetPublicIPAddressesResponse] + newListVirtualMachineScaleSetVMPublicIPAddressesPager *azfake.PagerResponder[armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetVMPublicIPAddressesResponse] +} + +// Do implements the policy.Transporter interface for PublicIPAddressesServerTransport. +func (p *PublicIPAddressesServerTransport) 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 "PublicIPAddressesClient.BeginCreateOrUpdate": + resp, err = p.dispatchBeginCreateOrUpdate(req) + case "PublicIPAddressesClient.BeginDdosProtectionStatus": + resp, err = p.dispatchBeginDdosProtectionStatus(req) + case "PublicIPAddressesClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "PublicIPAddressesClient.Get": + resp, err = p.dispatchGet(req) + case "PublicIPAddressesClient.GetCloudServicePublicIPAddress": + resp, err = p.dispatchGetCloudServicePublicIPAddress(req) + case "PublicIPAddressesClient.GetVirtualMachineScaleSetPublicIPAddress": + resp, err = p.dispatchGetVirtualMachineScaleSetPublicIPAddress(req) + case "PublicIPAddressesClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "PublicIPAddressesClient.NewListAllPager": + resp, err = p.dispatchNewListAllPager(req) + case "PublicIPAddressesClient.NewListCloudServicePublicIPAddressesPager": + resp, err = p.dispatchNewListCloudServicePublicIPAddressesPager(req) + case "PublicIPAddressesClient.NewListCloudServiceRoleInstancePublicIPAddressesPager": + resp, err = p.dispatchNewListCloudServiceRoleInstancePublicIPAddressesPager(req) + case "PublicIPAddressesClient.NewListVirtualMachineScaleSetPublicIPAddressesPager": + resp, err = p.dispatchNewListVirtualMachineScaleSetPublicIPAddressesPager(req) + case "PublicIPAddressesClient.NewListVirtualMachineScaleSetVMPublicIPAddressesPager": + resp, err = p.dispatchNewListVirtualMachineScaleSetVMPublicIPAddressesPager(req) + case "PublicIPAddressesClient.UpdateTags": + resp, err = p.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if p.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPAddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PublicIPAddress](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, publicIPAddressNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreateOrUpdate) { + p.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchBeginDdosProtectionStatus(req *http.Request) (*http.Response, error) { + if p.srv.BeginDdosProtectionStatus == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDdosProtectionStatus not implemented")} + } + if p.beginDdosProtectionStatus == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPAddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ddosProtectionStatus` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDdosProtectionStatus(req.Context(), resourceGroupNameUnescaped, publicIPAddressNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDdosProtectionStatus = &respr + } + + resp, err := server.PollerResponderNext(p.beginDdosProtectionStatus, 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(p.beginDdosProtectionStatus) { + p.beginDdosProtectionStatus = nil + } + + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPAddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, publicIPAddressNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/publicIPAddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PublicIPAddressesClientGetOptions + if expandParam != nil { + options = &armnetwork.PublicIPAddressesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, publicIPAddressNameUnescaped, 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).PublicIPAddress, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchGetCloudServicePublicIPAddress(req *http.Request) (*http.Response, error) { + if p.srv.GetCloudServicePublicIPAddress == nil { + return nil, &nonRetriableError{errors.New("fake for method GetCloudServicePublicIPAddress 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipconfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publicipaddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 7 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + 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 + } + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + ipConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PublicIPAddressesClientGetCloudServicePublicIPAddressOptions + if expandParam != nil { + options = &armnetwork.PublicIPAddressesClientGetCloudServicePublicIPAddressOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.GetCloudServicePublicIPAddress(req.Context(), resourceGroupNameUnescaped, cloudServiceNameUnescaped, roleInstanceNameUnescaped, networkInterfaceNameUnescaped, ipConfigurationNameUnescaped, publicIPAddressNameUnescaped, 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).PublicIPAddress, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchGetVirtualMachineScaleSetPublicIPAddress(req *http.Request) (*http.Response, error) { + if p.srv.GetVirtualMachineScaleSetPublicIPAddress == nil { + return nil, &nonRetriableError{errors.New("fake for method GetVirtualMachineScaleSetPublicIPAddress 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipconfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publicipaddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 7 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + 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 + } + virtualmachineIndexUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualmachineIndex")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + ipConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressOptions + if expandParam != nil { + options = &armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.GetVirtualMachineScaleSetPublicIPAddress(req.Context(), resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, virtualmachineIndexUnescaped, networkInterfaceNameUnescaped, ipConfigurationNameUnescaped, publicIPAddressNameUnescaped, 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).PublicIPAddress, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPAddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.PublicIPAddressesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if p.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPAddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := p.srv.NewListAllPager(nil) + p.newListAllPager = &resp + server.PagerResponderInjectNextLinks(p.newListAllPager, req, func(page *armnetwork.PublicIPAddressesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.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(p.newListAllPager) { + p.newListAllPager = nil + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchNewListCloudServicePublicIPAddressesPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListCloudServicePublicIPAddressesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListCloudServicePublicIPAddressesPager not implemented")} + } + if p.newListCloudServicePublicIPAddressesPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publicipaddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 := p.srv.NewListCloudServicePublicIPAddressesPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, nil) + p.newListCloudServicePublicIPAddressesPager = &resp + server.PagerResponderInjectNextLinks(p.newListCloudServicePublicIPAddressesPager, req, func(page *armnetwork.PublicIPAddressesClientListCloudServicePublicIPAddressesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListCloudServicePublicIPAddressesPager, 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.newListCloudServicePublicIPAddressesPager) { + p.newListCloudServicePublicIPAddressesPager = nil + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchNewListCloudServiceRoleInstancePublicIPAddressesPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListCloudServiceRoleInstancePublicIPAddressesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListCloudServiceRoleInstancePublicIPAddressesPager not implemented")} + } + if p.newListCloudServiceRoleInstancePublicIPAddressesPager == 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipconfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publicipaddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 + } + roleInstanceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("roleInstanceName")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + ipConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListCloudServiceRoleInstancePublicIPAddressesPager(resourceGroupNameUnescaped, cloudServiceNameUnescaped, roleInstanceNameUnescaped, networkInterfaceNameUnescaped, ipConfigurationNameUnescaped, nil) + p.newListCloudServiceRoleInstancePublicIPAddressesPager = &resp + server.PagerResponderInjectNextLinks(p.newListCloudServiceRoleInstancePublicIPAddressesPager, req, func(page *armnetwork.PublicIPAddressesClientListCloudServiceRoleInstancePublicIPAddressesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListCloudServiceRoleInstancePublicIPAddressesPager, 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.newListCloudServiceRoleInstancePublicIPAddressesPager) { + p.newListCloudServiceRoleInstancePublicIPAddressesPager = nil + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchNewListVirtualMachineScaleSetPublicIPAddressesPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListVirtualMachineScaleSetPublicIPAddressesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListVirtualMachineScaleSetPublicIPAddressesPager not implemented")} + } + if p.newListVirtualMachineScaleSetPublicIPAddressesPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publicipaddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 + } + resp := p.srv.NewListVirtualMachineScaleSetPublicIPAddressesPager(resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, nil) + p.newListVirtualMachineScaleSetPublicIPAddressesPager = &resp + server.PagerResponderInjectNextLinks(p.newListVirtualMachineScaleSetPublicIPAddressesPager, req, func(page *armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetPublicIPAddressesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListVirtualMachineScaleSetPublicIPAddressesPager, 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.newListVirtualMachineScaleSetPublicIPAddressesPager) { + p.newListVirtualMachineScaleSetPublicIPAddressesPager = nil + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchNewListVirtualMachineScaleSetVMPublicIPAddressesPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListVirtualMachineScaleSetVMPublicIPAddressesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListVirtualMachineScaleSetVMPublicIPAddressesPager not implemented")} + } + if p.newListVirtualMachineScaleSetVMPublicIPAddressesPager == 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~%@]+)/networkInterfaces/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipconfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publicipaddresses` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 + } + virtualmachineIndexUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualmachineIndex")]) + if err != nil { + return nil, err + } + networkInterfaceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")]) + if err != nil { + return nil, err + } + ipConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListVirtualMachineScaleSetVMPublicIPAddressesPager(resourceGroupNameUnescaped, virtualMachineScaleSetNameUnescaped, virtualmachineIndexUnescaped, networkInterfaceNameUnescaped, ipConfigurationNameUnescaped, nil) + p.newListVirtualMachineScaleSetVMPublicIPAddressesPager = &resp + server.PagerResponderInjectNextLinks(p.newListVirtualMachineScaleSetVMPublicIPAddressesPager, req, func(page *armnetwork.PublicIPAddressesClientListVirtualMachineScaleSetVMPublicIPAddressesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListVirtualMachineScaleSetVMPublicIPAddressesPager, 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.newListVirtualMachineScaleSetVMPublicIPAddressesPager) { + p.newListVirtualMachineScaleSetVMPublicIPAddressesPager = nil + } + return resp, nil +} + +func (p *PublicIPAddressesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if p.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPAddresses/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPAddressNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpAddressName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, publicIPAddressNameUnescaped, 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).PublicIPAddress, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/publicipprefixes_server.go b/sdk/resourcemanager/network/armnetwork/fake/publicipprefixes_server.go new file mode 100644 index 000000000000..3cccd36f7329 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/publicipprefixes_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// PublicIPPrefixesServer is a fake server for instances of the armnetwork.PublicIPPrefixesClient type. +type PublicIPPrefixesServer struct { + // BeginCreateOrUpdate is the fake for method PublicIPPrefixesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, publicIPPrefixName string, parameters armnetwork.PublicIPPrefix, options *armnetwork.PublicIPPrefixesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.PublicIPPrefixesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method PublicIPPrefixesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, publicIPPrefixName string, options *armnetwork.PublicIPPrefixesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.PublicIPPrefixesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method PublicIPPrefixesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, publicIPPrefixName string, options *armnetwork.PublicIPPrefixesClientGetOptions) (resp azfake.Responder[armnetwork.PublicIPPrefixesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PublicIPPrefixesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.PublicIPPrefixesClientListOptions) (resp azfake.PagerResponder[armnetwork.PublicIPPrefixesClientListResponse]) + + // NewListAllPager is the fake for method PublicIPPrefixesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.PublicIPPrefixesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.PublicIPPrefixesClientListAllResponse]) + + // UpdateTags is the fake for method PublicIPPrefixesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, publicIPPrefixName string, parameters armnetwork.TagsObject, options *armnetwork.PublicIPPrefixesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.PublicIPPrefixesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewPublicIPPrefixesServerTransport creates a new instance of PublicIPPrefixesServerTransport with the provided implementation. +// The returned PublicIPPrefixesServerTransport instance is connected to an instance of armnetwork.PublicIPPrefixesClient by way of the +// undefined.Transporter field. +func NewPublicIPPrefixesServerTransport(srv *PublicIPPrefixesServer) *PublicIPPrefixesServerTransport { + return &PublicIPPrefixesServerTransport{srv: srv} +} + +// PublicIPPrefixesServerTransport connects instances of armnetwork.PublicIPPrefixesClient to instances of PublicIPPrefixesServer. +// Don't use this type directly, use NewPublicIPPrefixesServerTransport instead. +type PublicIPPrefixesServerTransport struct { + srv *PublicIPPrefixesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.PublicIPPrefixesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.PublicIPPrefixesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.PublicIPPrefixesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.PublicIPPrefixesClientListAllResponse] +} + +// Do implements the policy.Transporter interface for PublicIPPrefixesServerTransport. +func (p *PublicIPPrefixesServerTransport) 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 "PublicIPPrefixesClient.BeginCreateOrUpdate": + resp, err = p.dispatchBeginCreateOrUpdate(req) + case "PublicIPPrefixesClient.BeginDelete": + resp, err = p.dispatchBeginDelete(req) + case "PublicIPPrefixesClient.Get": + resp, err = p.dispatchGet(req) + case "PublicIPPrefixesClient.NewListPager": + resp, err = p.dispatchNewListPager(req) + case "PublicIPPrefixesClient.NewListAllPager": + resp, err = p.dispatchNewListAllPager(req) + case "PublicIPPrefixesClient.UpdateTags": + resp, err = p.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (p *PublicIPPrefixesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if p.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if p.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PublicIPPrefix](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpPrefixName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, publicIPPrefixNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginCreateOrUpdate) { + p.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (p *PublicIPPrefixesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if p.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if p.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpPrefixName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, publicIPPrefixNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + p.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(p.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(p.beginDelete) { + p.beginDelete = nil + } + + return resp, nil +} + +func (p *PublicIPPrefixesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + 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.Network/publicIPPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpPrefixName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.PublicIPPrefixesClientGetOptions + if expandParam != nil { + options = &armnetwork.PublicIPPrefixesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := p.srv.Get(req.Context(), resourceGroupNameUnescaped, publicIPPrefixNameUnescaped, 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).PublicIPPrefix, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PublicIPPrefixesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if p.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPPrefixes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := p.srv.NewListPager(resourceGroupNameUnescaped, nil) + p.newListPager = &resp + server.PagerResponderInjectNextLinks(p.newListPager, req, func(page *armnetwork.PublicIPPrefixesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(p.newListPager) { + p.newListPager = nil + } + return resp, nil +} + +func (p *PublicIPPrefixesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if p.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPPrefixes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := p.srv.NewListAllPager(nil) + p.newListAllPager = &resp + server.PagerResponderInjectNextLinks(p.newListAllPager, req, func(page *armnetwork.PublicIPPrefixesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(p.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(p.newListAllPager) { + p.newListAllPager = nil + } + return resp, nil +} + +func (p *PublicIPPrefixesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if p.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/publicIPPrefixes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + publicIPPrefixNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publicIpPrefixName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, publicIPPrefixNameUnescaped, 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).PublicIPPrefix, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/resourcenavigationlinks_server.go b/sdk/resourcemanager/network/armnetwork/fake/resourcenavigationlinks_server.go new file mode 100644 index 000000000000..57783639dcaf --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/resourcenavigationlinks_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ResourceNavigationLinksServer is a fake server for instances of the armnetwork.ResourceNavigationLinksClient type. +type ResourceNavigationLinksServer struct { + // List is the fake for method ResourceNavigationLinksClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.ResourceNavigationLinksClientListOptions) (resp azfake.Responder[armnetwork.ResourceNavigationLinksClientListResponse], errResp azfake.ErrorResponder) +} + +// NewResourceNavigationLinksServerTransport creates a new instance of ResourceNavigationLinksServerTransport with the provided implementation. +// The returned ResourceNavigationLinksServerTransport instance is connected to an instance of armnetwork.ResourceNavigationLinksClient by way of the +// undefined.Transporter field. +func NewResourceNavigationLinksServerTransport(srv *ResourceNavigationLinksServer) *ResourceNavigationLinksServerTransport { + return &ResourceNavigationLinksServerTransport{srv: srv} +} + +// ResourceNavigationLinksServerTransport connects instances of armnetwork.ResourceNavigationLinksClient to instances of ResourceNavigationLinksServer. +// Don't use this type directly, use NewResourceNavigationLinksServerTransport instead. +type ResourceNavigationLinksServerTransport struct { + srv *ResourceNavigationLinksServer +} + +// Do implements the policy.Transporter interface for ResourceNavigationLinksServerTransport. +func (r *ResourceNavigationLinksServerTransport) 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 "ResourceNavigationLinksClient.List": + resp, err = r.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *ResourceNavigationLinksServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if r.srv.List == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ResourceNavigationLinks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.List(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, 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).ResourceNavigationLinksListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/routefilterrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/routefilterrules_server.go new file mode 100644 index 000000000000..74757ad4d514 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/routefilterrules_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// RouteFilterRulesServer is a fake server for instances of the armnetwork.RouteFilterRulesClient type. +type RouteFilterRulesServer struct { + // BeginCreateOrUpdate is the fake for method RouteFilterRulesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, routeFilterName string, ruleName string, routeFilterRuleParameters armnetwork.RouteFilterRule, options *armnetwork.RouteFilterRulesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.RouteFilterRulesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RouteFilterRulesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, routeFilterName string, ruleName string, options *armnetwork.RouteFilterRulesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RouteFilterRulesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RouteFilterRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, routeFilterName string, ruleName string, options *armnetwork.RouteFilterRulesClientGetOptions) (resp azfake.Responder[armnetwork.RouteFilterRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByRouteFilterPager is the fake for method RouteFilterRulesClient.NewListByRouteFilterPager + // HTTP status codes to indicate success: http.StatusOK + NewListByRouteFilterPager func(resourceGroupName string, routeFilterName string, options *armnetwork.RouteFilterRulesClientListByRouteFilterOptions) (resp azfake.PagerResponder[armnetwork.RouteFilterRulesClientListByRouteFilterResponse]) +} + +// NewRouteFilterRulesServerTransport creates a new instance of RouteFilterRulesServerTransport with the provided implementation. +// The returned RouteFilterRulesServerTransport instance is connected to an instance of armnetwork.RouteFilterRulesClient by way of the +// undefined.Transporter field. +func NewRouteFilterRulesServerTransport(srv *RouteFilterRulesServer) *RouteFilterRulesServerTransport { + return &RouteFilterRulesServerTransport{srv: srv} +} + +// RouteFilterRulesServerTransport connects instances of armnetwork.RouteFilterRulesClient to instances of RouteFilterRulesServer. +// Don't use this type directly, use NewRouteFilterRulesServerTransport instead. +type RouteFilterRulesServerTransport struct { + srv *RouteFilterRulesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.RouteFilterRulesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.RouteFilterRulesClientDeleteResponse] + newListByRouteFilterPager *azfake.PagerResponder[armnetwork.RouteFilterRulesClientListByRouteFilterResponse] +} + +// Do implements the policy.Transporter interface for RouteFilterRulesServerTransport. +func (r *RouteFilterRulesServerTransport) 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 "RouteFilterRulesClient.BeginCreateOrUpdate": + resp, err = r.dispatchBeginCreateOrUpdate(req) + case "RouteFilterRulesClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RouteFilterRulesClient.Get": + resp, err = r.dispatchGet(req) + case "RouteFilterRulesClient.NewListByRouteFilterPager": + resp, err = r.dispatchNewListByRouteFilterPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *RouteFilterRulesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if r.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeFilterRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.RouteFilterRule](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + ruleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, ruleNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(r.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(r.beginCreateOrUpdate) { + r.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (r *RouteFilterRulesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + 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.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeFilterRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + ruleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, ruleNameUnescaped, 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 *RouteFilterRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + 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.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeFilterRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + ruleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ruleName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, ruleNameUnescaped, 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).RouteFilterRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RouteFilterRulesServerTransport) dispatchNewListByRouteFilterPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListByRouteFilterPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByRouteFilterPager not implemented")} + } + if r.newListByRouteFilterPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeFilterRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + resp := r.srv.NewListByRouteFilterPager(resourceGroupNameUnescaped, routeFilterNameUnescaped, nil) + r.newListByRouteFilterPager = &resp + server.PagerResponderInjectNextLinks(r.newListByRouteFilterPager, req, func(page *armnetwork.RouteFilterRulesClientListByRouteFilterResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(r.newListByRouteFilterPager, 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.newListByRouteFilterPager) { + r.newListByRouteFilterPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/routefilters_server.go b/sdk/resourcemanager/network/armnetwork/fake/routefilters_server.go new file mode 100644 index 000000000000..4004ec987cc4 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/routefilters_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// RouteFiltersServer is a fake server for instances of the armnetwork.RouteFiltersClient type. +type RouteFiltersServer struct { + // BeginCreateOrUpdate is the fake for method RouteFiltersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, routeFilterName string, routeFilterParameters armnetwork.RouteFilter, options *armnetwork.RouteFiltersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.RouteFiltersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RouteFiltersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, routeFilterName string, options *armnetwork.RouteFiltersClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RouteFiltersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RouteFiltersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, routeFilterName string, options *armnetwork.RouteFiltersClientGetOptions) (resp azfake.Responder[armnetwork.RouteFiltersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RouteFiltersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.RouteFiltersClientListOptions) (resp azfake.PagerResponder[armnetwork.RouteFiltersClientListResponse]) + + // NewListByResourceGroupPager is the fake for method RouteFiltersClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.RouteFiltersClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.RouteFiltersClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method RouteFiltersClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, routeFilterName string, parameters armnetwork.TagsObject, options *armnetwork.RouteFiltersClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.RouteFiltersClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewRouteFiltersServerTransport creates a new instance of RouteFiltersServerTransport with the provided implementation. +// The returned RouteFiltersServerTransport instance is connected to an instance of armnetwork.RouteFiltersClient by way of the +// undefined.Transporter field. +func NewRouteFiltersServerTransport(srv *RouteFiltersServer) *RouteFiltersServerTransport { + return &RouteFiltersServerTransport{srv: srv} +} + +// RouteFiltersServerTransport connects instances of armnetwork.RouteFiltersClient to instances of RouteFiltersServer. +// Don't use this type directly, use NewRouteFiltersServerTransport instead. +type RouteFiltersServerTransport struct { + srv *RouteFiltersServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.RouteFiltersClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.RouteFiltersClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.RouteFiltersClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.RouteFiltersClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for RouteFiltersServerTransport. +func (r *RouteFiltersServerTransport) 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 "RouteFiltersClient.BeginCreateOrUpdate": + resp, err = r.dispatchBeginCreateOrUpdate(req) + case "RouteFiltersClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RouteFiltersClient.Get": + resp, err = r.dispatchGet(req) + case "RouteFiltersClient.NewListPager": + resp, err = r.dispatchNewListPager(req) + case "RouteFiltersClient.NewListByResourceGroupPager": + resp, err = r.dispatchNewListByResourceGroupPager(req) + case "RouteFiltersClient.UpdateTags": + resp, err = r.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *RouteFiltersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if r.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.RouteFilter](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(r.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(r.beginCreateOrUpdate) { + r.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (r *RouteFiltersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + 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.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, 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 *RouteFiltersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + 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.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.RouteFiltersClientGetOptions + if expandParam != nil { + options = &armnetwork.RouteFiltersClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, 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).RouteFilter, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RouteFiltersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + 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.Network/routeFilters` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := r.srv.NewListPager(nil) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armnetwork.RouteFiltersClientListResponse, 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 *RouteFiltersServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if r.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeFilters` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := r.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + r.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(r.newListByResourceGroupPager, req, func(page *armnetwork.RouteFiltersClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(r.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(r.newListByResourceGroupPager) { + r.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (r *RouteFiltersServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if r.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeFilters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeFilterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeFilterName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, routeFilterNameUnescaped, 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).RouteFilter, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/routemaps_server.go b/sdk/resourcemanager/network/armnetwork/fake/routemaps_server.go new file mode 100644 index 000000000000..ea4e6b96a4a8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/routemaps_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// RouteMapsServer is a fake server for instances of the armnetwork.RouteMapsClient type. +type RouteMapsServer struct { + // BeginCreateOrUpdate is the fake for method RouteMapsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, routeMapParameters armnetwork.RouteMap, options *armnetwork.RouteMapsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.RouteMapsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RouteMapsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *armnetwork.RouteMapsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RouteMapsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RouteMapsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *armnetwork.RouteMapsClientGetOptions) (resp azfake.Responder[armnetwork.RouteMapsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RouteMapsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.RouteMapsClientListOptions) (resp azfake.PagerResponder[armnetwork.RouteMapsClientListResponse]) +} + +// NewRouteMapsServerTransport creates a new instance of RouteMapsServerTransport with the provided implementation. +// The returned RouteMapsServerTransport instance is connected to an instance of armnetwork.RouteMapsClient by way of the +// undefined.Transporter field. +func NewRouteMapsServerTransport(srv *RouteMapsServer) *RouteMapsServerTransport { + return &RouteMapsServerTransport{srv: srv} +} + +// RouteMapsServerTransport connects instances of armnetwork.RouteMapsClient to instances of RouteMapsServer. +// Don't use this type directly, use NewRouteMapsServerTransport instead. +type RouteMapsServerTransport struct { + srv *RouteMapsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.RouteMapsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.RouteMapsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.RouteMapsClientListResponse] +} + +// Do implements the policy.Transporter interface for RouteMapsServerTransport. +func (r *RouteMapsServerTransport) 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 "RouteMapsClient.BeginCreateOrUpdate": + resp, err = r.dispatchBeginCreateOrUpdate(req) + case "RouteMapsClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RouteMapsClient.Get": + resp, err = r.dispatchGet(req) + case "RouteMapsClient.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 *RouteMapsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if r.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeMaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.RouteMap](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeMapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeMapName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeMapNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(r.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(r.beginCreateOrUpdate) { + r.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (r *RouteMapsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeMaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeMapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeMapName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeMapNameUnescaped, 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 *RouteMapsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeMaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeMapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeMapName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeMapNameUnescaped, 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).RouteMap, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RouteMapsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeMaps` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := r.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armnetwork.RouteMapsClientListResponse, 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/network/armnetwork/fake/routes_server.go b/sdk/resourcemanager/network/armnetwork/fake/routes_server.go new file mode 100644 index 000000000000..f54b7a2e89d6 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/routes_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// RoutesServer is a fake server for instances of the armnetwork.RoutesClient type. +type RoutesServer struct { + // BeginCreateOrUpdate is the fake for method RoutesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters armnetwork.Route, options *armnetwork.RoutesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.RoutesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RoutesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *armnetwork.RoutesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RoutesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RoutesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *armnetwork.RoutesClientGetOptions) (resp azfake.Responder[armnetwork.RoutesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RoutesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, routeTableName string, options *armnetwork.RoutesClientListOptions) (resp azfake.PagerResponder[armnetwork.RoutesClientListResponse]) +} + +// NewRoutesServerTransport creates a new instance of RoutesServerTransport with the provided implementation. +// The returned RoutesServerTransport instance is connected to an instance of armnetwork.RoutesClient by way of the +// undefined.Transporter field. +func NewRoutesServerTransport(srv *RoutesServer) *RoutesServerTransport { + return &RoutesServerTransport{srv: srv} +} + +// RoutesServerTransport connects instances of armnetwork.RoutesClient to instances of RoutesServer. +// Don't use this type directly, use NewRoutesServerTransport instead. +type RoutesServerTransport struct { + srv *RoutesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.RoutesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.RoutesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.RoutesClientListResponse] +} + +// Do implements the policy.Transporter interface for RoutesServerTransport. +func (r *RoutesServerTransport) 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 "RoutesClient.BeginCreateOrUpdate": + resp, err = r.dispatchBeginCreateOrUpdate(req) + case "RoutesClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RoutesClient.Get": + resp, err = r.dispatchGet(req) + case "RoutesClient.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 *RoutesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if r.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Route](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + routeNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, routeNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(r.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(r.beginCreateOrUpdate) { + r.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (r *RoutesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + 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.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + routeNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, routeNameUnescaped, 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 *RoutesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + 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.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + routeNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, routeNameUnescaped, 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).Route, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RoutesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + 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.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + resp := r.srv.NewListPager(resourceGroupNameUnescaped, routeTableNameUnescaped, nil) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armnetwork.RoutesClientListResponse, 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/network/armnetwork/fake/routetables_server.go b/sdk/resourcemanager/network/armnetwork/fake/routetables_server.go new file mode 100644 index 000000000000..b610a79f647d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/routetables_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// RouteTablesServer is a fake server for instances of the armnetwork.RouteTablesClient type. +type RouteTablesServer struct { + // BeginCreateOrUpdate is the fake for method RouteTablesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, routeTableName string, parameters armnetwork.RouteTable, options *armnetwork.RouteTablesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.RouteTablesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RouteTablesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, routeTableName string, options *armnetwork.RouteTablesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RouteTablesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RouteTablesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, routeTableName string, options *armnetwork.RouteTablesClientGetOptions) (resp azfake.Responder[armnetwork.RouteTablesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RouteTablesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.RouteTablesClientListOptions) (resp azfake.PagerResponder[armnetwork.RouteTablesClientListResponse]) + + // NewListAllPager is the fake for method RouteTablesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.RouteTablesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.RouteTablesClientListAllResponse]) + + // UpdateTags is the fake for method RouteTablesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, routeTableName string, parameters armnetwork.TagsObject, options *armnetwork.RouteTablesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.RouteTablesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewRouteTablesServerTransport creates a new instance of RouteTablesServerTransport with the provided implementation. +// The returned RouteTablesServerTransport instance is connected to an instance of armnetwork.RouteTablesClient by way of the +// undefined.Transporter field. +func NewRouteTablesServerTransport(srv *RouteTablesServer) *RouteTablesServerTransport { + return &RouteTablesServerTransport{srv: srv} +} + +// RouteTablesServerTransport connects instances of armnetwork.RouteTablesClient to instances of RouteTablesServer. +// Don't use this type directly, use NewRouteTablesServerTransport instead. +type RouteTablesServerTransport struct { + srv *RouteTablesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.RouteTablesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.RouteTablesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.RouteTablesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.RouteTablesClientListAllResponse] +} + +// Do implements the policy.Transporter interface for RouteTablesServerTransport. +func (r *RouteTablesServerTransport) 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 "RouteTablesClient.BeginCreateOrUpdate": + resp, err = r.dispatchBeginCreateOrUpdate(req) + case "RouteTablesClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RouteTablesClient.Get": + resp, err = r.dispatchGet(req) + case "RouteTablesClient.NewListPager": + resp, err = r.dispatchNewListPager(req) + case "RouteTablesClient.NewListAllPager": + resp, err = r.dispatchNewListAllPager(req) + case "RouteTablesClient.UpdateTags": + resp, err = r.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *RouteTablesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if r.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.RouteTable](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(r.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(r.beginCreateOrUpdate) { + r.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (r *RouteTablesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + 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.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, 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 *RouteTablesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + 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.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.RouteTablesClientGetOptions + if expandParam != nil { + options = &armnetwork.RouteTablesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, 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).RouteTable, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RouteTablesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + 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.Network/routeTables` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.RouteTablesClientListResponse, 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 *RouteTablesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListAllPager == nil { + 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.Network/routeTables` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.RouteTablesClientListAllResponse, 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 *RouteTablesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if r.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, routeTableNameUnescaped, 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).RouteTable, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/routingintent_server.go b/sdk/resourcemanager/network/armnetwork/fake/routingintent_server.go new file mode 100644 index 000000000000..e9000f86f2a5 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/routingintent_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// RoutingIntentServer is a fake server for instances of the armnetwork.RoutingIntentClient type. +type RoutingIntentServer struct { + // BeginCreateOrUpdate is the fake for method RoutingIntentClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, routingIntentName string, routingIntentParameters armnetwork.RoutingIntent, options *armnetwork.RoutingIntentClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.RoutingIntentClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RoutingIntentClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, routingIntentName string, options *armnetwork.RoutingIntentClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RoutingIntentClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RoutingIntentClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, routingIntentName string, options *armnetwork.RoutingIntentClientGetOptions) (resp azfake.Responder[armnetwork.RoutingIntentClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RoutingIntentClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.RoutingIntentClientListOptions) (resp azfake.PagerResponder[armnetwork.RoutingIntentClientListResponse]) +} + +// NewRoutingIntentServerTransport creates a new instance of RoutingIntentServerTransport with the provided implementation. +// The returned RoutingIntentServerTransport instance is connected to an instance of armnetwork.RoutingIntentClient by way of the +// undefined.Transporter field. +func NewRoutingIntentServerTransport(srv *RoutingIntentServer) *RoutingIntentServerTransport { + return &RoutingIntentServerTransport{srv: srv} +} + +// RoutingIntentServerTransport connects instances of armnetwork.RoutingIntentClient to instances of RoutingIntentServer. +// Don't use this type directly, use NewRoutingIntentServerTransport instead. +type RoutingIntentServerTransport struct { + srv *RoutingIntentServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.RoutingIntentClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.RoutingIntentClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.RoutingIntentClientListResponse] +} + +// Do implements the policy.Transporter interface for RoutingIntentServerTransport. +func (r *RoutingIntentServerTransport) 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 "RoutingIntentClient.BeginCreateOrUpdate": + resp, err = r.dispatchBeginCreateOrUpdate(req) + case "RoutingIntentClient.BeginDelete": + resp, err = r.dispatchBeginDelete(req) + case "RoutingIntentClient.Get": + resp, err = r.dispatchGet(req) + case "RoutingIntentClient.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 *RoutingIntentServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + if r.beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingIntent/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.RoutingIntent](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routingIntentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routingIntentName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routingIntentNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + r.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(r.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(r.beginCreateOrUpdate) { + r.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (r *RoutingIntentServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingIntent/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routingIntentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routingIntentName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routingIntentNameUnescaped, 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 *RoutingIntentServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingIntent/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routingIntentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routingIntentName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routingIntentNameUnescaped, 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).RoutingIntent, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RoutingIntentServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingIntent` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := r.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + r.newListPager = &resp + server.PagerResponderInjectNextLinks(r.newListPager, req, func(page *armnetwork.RoutingIntentClientListResponse, 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/network/armnetwork/fake/scopeconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/scopeconnections_server.go new file mode 100644 index 000000000000..4b7bb94cee82 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/scopeconnections_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/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ScopeConnectionsServer is a fake server for instances of the armnetwork.ScopeConnectionsClient type. +type ScopeConnectionsServer struct { + // CreateOrUpdate is the fake for method ScopeConnectionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, scopeConnectionName string, parameters armnetwork.ScopeConnection, options *armnetwork.ScopeConnectionsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.ScopeConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method ScopeConnectionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, networkManagerName string, scopeConnectionName string, options *armnetwork.ScopeConnectionsClientDeleteOptions) (resp azfake.Responder[armnetwork.ScopeConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ScopeConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, scopeConnectionName string, options *armnetwork.ScopeConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.ScopeConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ScopeConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, options *armnetwork.ScopeConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.ScopeConnectionsClientListResponse]) +} + +// NewScopeConnectionsServerTransport creates a new instance of ScopeConnectionsServerTransport with the provided implementation. +// The returned ScopeConnectionsServerTransport instance is connected to an instance of armnetwork.ScopeConnectionsClient by way of the +// undefined.Transporter field. +func NewScopeConnectionsServerTransport(srv *ScopeConnectionsServer) *ScopeConnectionsServerTransport { + return &ScopeConnectionsServerTransport{srv: srv} +} + +// ScopeConnectionsServerTransport connects instances of armnetwork.ScopeConnectionsClient to instances of ScopeConnectionsServer. +// Don't use this type directly, use NewScopeConnectionsServerTransport instead. +type ScopeConnectionsServerTransport struct { + srv *ScopeConnectionsServer + newListPager *azfake.PagerResponder[armnetwork.ScopeConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for ScopeConnectionsServerTransport. +func (s *ScopeConnectionsServerTransport) 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 "ScopeConnectionsClient.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "ScopeConnectionsClient.Delete": + resp, err = s.dispatchDelete(req) + case "ScopeConnectionsClient.Get": + resp, err = s.dispatchGet(req) + case "ScopeConnectionsClient.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 *ScopeConnectionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/scopeConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ScopeConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + scopeConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scopeConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, scopeConnectionNameUnescaped, 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).ScopeConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ScopeConnectionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/scopeConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + scopeConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scopeConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, scopeConnectionNameUnescaped, 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 *ScopeConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/scopeConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + scopeConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scopeConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, scopeConnectionNameUnescaped, 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).ScopeConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ScopeConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/scopeConnections` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.ScopeConnectionsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.ScopeConnectionsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := s.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.ScopeConnectionsClientListResponse, 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/network/armnetwork/fake/securityadminconfigurations_server.go b/sdk/resourcemanager/network/armnetwork/fake/securityadminconfigurations_server.go new file mode 100644 index 000000000000..e74a88501ee4 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/securityadminconfigurations_server.go @@ -0,0 +1,292 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// SecurityAdminConfigurationsServer is a fake server for instances of the armnetwork.SecurityAdminConfigurationsClient type. +type SecurityAdminConfigurationsServer struct { + // CreateOrUpdate is the fake for method SecurityAdminConfigurationsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, securityAdminConfiguration armnetwork.SecurityAdminConfiguration, options *armnetwork.SecurityAdminConfigurationsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.SecurityAdminConfigurationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SecurityAdminConfigurationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *armnetwork.SecurityAdminConfigurationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.SecurityAdminConfigurationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SecurityAdminConfigurationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *armnetwork.SecurityAdminConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.SecurityAdminConfigurationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SecurityAdminConfigurationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, options *armnetwork.SecurityAdminConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.SecurityAdminConfigurationsClientListResponse]) +} + +// NewSecurityAdminConfigurationsServerTransport creates a new instance of SecurityAdminConfigurationsServerTransport with the provided implementation. +// The returned SecurityAdminConfigurationsServerTransport instance is connected to an instance of armnetwork.SecurityAdminConfigurationsClient by way of the +// undefined.Transporter field. +func NewSecurityAdminConfigurationsServerTransport(srv *SecurityAdminConfigurationsServer) *SecurityAdminConfigurationsServerTransport { + return &SecurityAdminConfigurationsServerTransport{srv: srv} +} + +// SecurityAdminConfigurationsServerTransport connects instances of armnetwork.SecurityAdminConfigurationsClient to instances of SecurityAdminConfigurationsServer. +// Don't use this type directly, use NewSecurityAdminConfigurationsServerTransport instead. +type SecurityAdminConfigurationsServerTransport struct { + srv *SecurityAdminConfigurationsServer + beginDelete *azfake.PollerResponder[armnetwork.SecurityAdminConfigurationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.SecurityAdminConfigurationsClientListResponse] +} + +// Do implements the policy.Transporter interface for SecurityAdminConfigurationsServerTransport. +func (s *SecurityAdminConfigurationsServerTransport) 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 "SecurityAdminConfigurationsClient.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "SecurityAdminConfigurationsClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "SecurityAdminConfigurationsClient.Get": + resp, err = s.dispatchGet(req) + case "SecurityAdminConfigurationsClient.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 *SecurityAdminConfigurationsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SecurityAdminConfiguration](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, 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).SecurityAdminConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SecurityAdminConfigurationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + forceUnescaped, err := url.QueryUnescape(qp.Get("force")) + if err != nil { + return nil, err + } + forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + var options *armnetwork.SecurityAdminConfigurationsClientBeginDeleteOptions + if forceParam != nil { + options = &armnetwork.SecurityAdminConfigurationsClientBeginDeleteOptions{ + Force: forceParam, + } + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, options) + 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 *SecurityAdminConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + configurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, configurationNameUnescaped, 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).SecurityAdminConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SecurityAdminConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityAdminConfigurations` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.SecurityAdminConfigurationsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.SecurityAdminConfigurationsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := s.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.SecurityAdminConfigurationsClientListResponse, 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/network/armnetwork/fake/securitygroups_server.go b/sdk/resourcemanager/network/armnetwork/fake/securitygroups_server.go new file mode 100644 index 000000000000..3d792e0ae09c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/securitygroups_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// SecurityGroupsServer is a fake server for instances of the armnetwork.SecurityGroupsClient type. +type SecurityGroupsServer struct { + // BeginCreateOrUpdate is the fake for method SecurityGroupsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters armnetwork.SecurityGroup, options *armnetwork.SecurityGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.SecurityGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SecurityGroupsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *armnetwork.SecurityGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.SecurityGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SecurityGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *armnetwork.SecurityGroupsClientGetOptions) (resp azfake.Responder[armnetwork.SecurityGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SecurityGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.SecurityGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.SecurityGroupsClientListResponse]) + + // NewListAllPager is the fake for method SecurityGroupsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.SecurityGroupsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.SecurityGroupsClientListAllResponse]) + + // UpdateTags is the fake for method SecurityGroupsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters armnetwork.TagsObject, options *armnetwork.SecurityGroupsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.SecurityGroupsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewSecurityGroupsServerTransport creates a new instance of SecurityGroupsServerTransport with the provided implementation. +// The returned SecurityGroupsServerTransport instance is connected to an instance of armnetwork.SecurityGroupsClient by way of the +// undefined.Transporter field. +func NewSecurityGroupsServerTransport(srv *SecurityGroupsServer) *SecurityGroupsServerTransport { + return &SecurityGroupsServerTransport{srv: srv} +} + +// SecurityGroupsServerTransport connects instances of armnetwork.SecurityGroupsClient to instances of SecurityGroupsServer. +// Don't use this type directly, use NewSecurityGroupsServerTransport instead. +type SecurityGroupsServerTransport struct { + srv *SecurityGroupsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.SecurityGroupsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.SecurityGroupsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.SecurityGroupsClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.SecurityGroupsClientListAllResponse] +} + +// Do implements the policy.Transporter interface for SecurityGroupsServerTransport. +func (s *SecurityGroupsServerTransport) 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 "SecurityGroupsClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "SecurityGroupsClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "SecurityGroupsClient.Get": + resp, err = s.dispatchGet(req) + case "SecurityGroupsClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "SecurityGroupsClient.NewListAllPager": + resp, err = s.dispatchNewListAllPager(req) + case "SecurityGroupsClient.UpdateTags": + resp, err = s.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SecurityGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SecurityGroup](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *SecurityGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, 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 *SecurityGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.SecurityGroupsClientGetOptions + if expandParam != nil { + options = &armnetwork.SecurityGroupsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, 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).SecurityGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SecurityGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkSecurityGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListPager(resourceGroupNameUnescaped, nil) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.SecurityGroupsClientListResponse, 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 *SecurityGroupsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if s.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkSecurityGroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := s.srv.NewListAllPager(nil) + s.newListAllPager = &resp + server.PagerResponderInjectNextLinks(s.newListAllPager, req, func(page *armnetwork.SecurityGroupsClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(s.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(s.newListAllPager) { + s.newListAllPager = nil + } + return resp, nil +} + +func (s *SecurityGroupsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if s.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, 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).SecurityGroup, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/securitypartnerproviders_server.go b/sdk/resourcemanager/network/armnetwork/fake/securitypartnerproviders_server.go new file mode 100644 index 000000000000..1cb136c1967b --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/securitypartnerproviders_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// SecurityPartnerProvidersServer is a fake server for instances of the armnetwork.SecurityPartnerProvidersClient type. +type SecurityPartnerProvidersServer struct { + // BeginCreateOrUpdate is the fake for method SecurityPartnerProvidersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, parameters armnetwork.SecurityPartnerProvider, options *armnetwork.SecurityPartnerProvidersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.SecurityPartnerProvidersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SecurityPartnerProvidersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, options *armnetwork.SecurityPartnerProvidersClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.SecurityPartnerProvidersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SecurityPartnerProvidersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, options *armnetwork.SecurityPartnerProvidersClientGetOptions) (resp azfake.Responder[armnetwork.SecurityPartnerProvidersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SecurityPartnerProvidersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.SecurityPartnerProvidersClientListOptions) (resp azfake.PagerResponder[armnetwork.SecurityPartnerProvidersClientListResponse]) + + // NewListByResourceGroupPager is the fake for method SecurityPartnerProvidersClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.SecurityPartnerProvidersClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.SecurityPartnerProvidersClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method SecurityPartnerProvidersClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, parameters armnetwork.TagsObject, options *armnetwork.SecurityPartnerProvidersClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.SecurityPartnerProvidersClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewSecurityPartnerProvidersServerTransport creates a new instance of SecurityPartnerProvidersServerTransport with the provided implementation. +// The returned SecurityPartnerProvidersServerTransport instance is connected to an instance of armnetwork.SecurityPartnerProvidersClient by way of the +// undefined.Transporter field. +func NewSecurityPartnerProvidersServerTransport(srv *SecurityPartnerProvidersServer) *SecurityPartnerProvidersServerTransport { + return &SecurityPartnerProvidersServerTransport{srv: srv} +} + +// SecurityPartnerProvidersServerTransport connects instances of armnetwork.SecurityPartnerProvidersClient to instances of SecurityPartnerProvidersServer. +// Don't use this type directly, use NewSecurityPartnerProvidersServerTransport instead. +type SecurityPartnerProvidersServerTransport struct { + srv *SecurityPartnerProvidersServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.SecurityPartnerProvidersClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.SecurityPartnerProvidersClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.SecurityPartnerProvidersClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.SecurityPartnerProvidersClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for SecurityPartnerProvidersServerTransport. +func (s *SecurityPartnerProvidersServerTransport) 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 "SecurityPartnerProvidersClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "SecurityPartnerProvidersClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "SecurityPartnerProvidersClient.Get": + resp, err = s.dispatchGet(req) + case "SecurityPartnerProvidersClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "SecurityPartnerProvidersClient.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "SecurityPartnerProvidersClient.UpdateTags": + resp, err = s.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SecurityPartnerProvidersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + 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.Network/securityPartnerProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SecurityPartnerProvider](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + securityPartnerProviderNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityPartnerProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, securityPartnerProviderNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *SecurityPartnerProvidersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/securityPartnerProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + securityPartnerProviderNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityPartnerProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, securityPartnerProviderNameUnescaped, 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 *SecurityPartnerProvidersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/securityPartnerProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + securityPartnerProviderNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityPartnerProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, securityPartnerProviderNameUnescaped, 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).SecurityPartnerProvider, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SecurityPartnerProvidersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + 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.Network/securityPartnerProviders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.SecurityPartnerProvidersClientListResponse, 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 *SecurityPartnerProvidersServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByResourceGroupPager == nil { + 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.Network/securityPartnerProviders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.SecurityPartnerProvidersClientListByResourceGroupResponse, 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 *SecurityPartnerProvidersServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if s.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/securityPartnerProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + securityPartnerProviderNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityPartnerProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, securityPartnerProviderNameUnescaped, 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).SecurityPartnerProvider, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/securityrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/securityrules_server.go new file mode 100644 index 000000000000..8a7653bbfde3 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/securityrules_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// SecurityRulesServer is a fake server for instances of the armnetwork.SecurityRulesClient type. +type SecurityRulesServer struct { + // BeginCreateOrUpdate is the fake for method SecurityRulesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, securityRuleName string, securityRuleParameters armnetwork.SecurityRule, options *armnetwork.SecurityRulesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.SecurityRulesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SecurityRulesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, securityRuleName string, options *armnetwork.SecurityRulesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.SecurityRulesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SecurityRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, securityRuleName string, options *armnetwork.SecurityRulesClientGetOptions) (resp azfake.Responder[armnetwork.SecurityRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SecurityRulesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkSecurityGroupName string, options *armnetwork.SecurityRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.SecurityRulesClientListResponse]) +} + +// NewSecurityRulesServerTransport creates a new instance of SecurityRulesServerTransport with the provided implementation. +// The returned SecurityRulesServerTransport instance is connected to an instance of armnetwork.SecurityRulesClient by way of the +// undefined.Transporter field. +func NewSecurityRulesServerTransport(srv *SecurityRulesServer) *SecurityRulesServerTransport { + return &SecurityRulesServerTransport{srv: srv} +} + +// SecurityRulesServerTransport connects instances of armnetwork.SecurityRulesClient to instances of SecurityRulesServer. +// Don't use this type directly, use NewSecurityRulesServerTransport instead. +type SecurityRulesServerTransport struct { + srv *SecurityRulesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.SecurityRulesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.SecurityRulesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.SecurityRulesClientListResponse] +} + +// Do implements the policy.Transporter interface for SecurityRulesServerTransport. +func (s *SecurityRulesServerTransport) 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 "SecurityRulesClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "SecurityRulesClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "SecurityRulesClient.Get": + resp, err = s.dispatchGet(req) + case "SecurityRulesClient.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 *SecurityRulesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SecurityRule](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + securityRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, securityRuleNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *SecurityRulesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + securityRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, securityRuleNameUnescaped, 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 *SecurityRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + securityRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("securityRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, securityRuleNameUnescaped, 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).SecurityRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SecurityRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkSecurityGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkSecurityGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkSecurityGroupName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListPager(resourceGroupNameUnescaped, networkSecurityGroupNameUnescaped, nil) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.SecurityRulesClientListResponse, 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/network/armnetwork/fake/serviceassociationlinks_server.go b/sdk/resourcemanager/network/armnetwork/fake/serviceassociationlinks_server.go new file mode 100644 index 000000000000..83b35b828017 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/serviceassociationlinks_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ServiceAssociationLinksServer is a fake server for instances of the armnetwork.ServiceAssociationLinksClient type. +type ServiceAssociationLinksServer struct { + // List is the fake for method ServiceAssociationLinksClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.ServiceAssociationLinksClientListOptions) (resp azfake.Responder[armnetwork.ServiceAssociationLinksClientListResponse], errResp azfake.ErrorResponder) +} + +// NewServiceAssociationLinksServerTransport creates a new instance of ServiceAssociationLinksServerTransport with the provided implementation. +// The returned ServiceAssociationLinksServerTransport instance is connected to an instance of armnetwork.ServiceAssociationLinksClient by way of the +// undefined.Transporter field. +func NewServiceAssociationLinksServerTransport(srv *ServiceAssociationLinksServer) *ServiceAssociationLinksServerTransport { + return &ServiceAssociationLinksServerTransport{srv: srv} +} + +// ServiceAssociationLinksServerTransport connects instances of armnetwork.ServiceAssociationLinksClient to instances of ServiceAssociationLinksServer. +// Don't use this type directly, use NewServiceAssociationLinksServerTransport instead. +type ServiceAssociationLinksServerTransport struct { + srv *ServiceAssociationLinksServer +} + +// Do implements the policy.Transporter interface for ServiceAssociationLinksServerTransport. +func (s *ServiceAssociationLinksServerTransport) 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 "ServiceAssociationLinksClient.List": + resp, err = s.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServiceAssociationLinksServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if s.srv.List == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ServiceAssociationLinks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.List(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, 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).ServiceAssociationLinksListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/serviceendpointpolicies_server.go b/sdk/resourcemanager/network/armnetwork/fake/serviceendpointpolicies_server.go new file mode 100644 index 000000000000..28590a4aed87 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/serviceendpointpolicies_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ServiceEndpointPoliciesServer is a fake server for instances of the armnetwork.ServiceEndpointPoliciesClient type. +type ServiceEndpointPoliciesServer struct { + // BeginCreateOrUpdate is the fake for method ServiceEndpointPoliciesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, parameters armnetwork.ServiceEndpointPolicy, options *armnetwork.ServiceEndpointPoliciesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ServiceEndpointPoliciesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ServiceEndpointPoliciesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, options *armnetwork.ServiceEndpointPoliciesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ServiceEndpointPoliciesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ServiceEndpointPoliciesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, options *armnetwork.ServiceEndpointPoliciesClientGetOptions) (resp azfake.Responder[armnetwork.ServiceEndpointPoliciesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ServiceEndpointPoliciesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.ServiceEndpointPoliciesClientListOptions) (resp azfake.PagerResponder[armnetwork.ServiceEndpointPoliciesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method ServiceEndpointPoliciesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.ServiceEndpointPoliciesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.ServiceEndpointPoliciesClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method ServiceEndpointPoliciesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, parameters armnetwork.TagsObject, options *armnetwork.ServiceEndpointPoliciesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ServiceEndpointPoliciesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewServiceEndpointPoliciesServerTransport creates a new instance of ServiceEndpointPoliciesServerTransport with the provided implementation. +// The returned ServiceEndpointPoliciesServerTransport instance is connected to an instance of armnetwork.ServiceEndpointPoliciesClient by way of the +// undefined.Transporter field. +func NewServiceEndpointPoliciesServerTransport(srv *ServiceEndpointPoliciesServer) *ServiceEndpointPoliciesServerTransport { + return &ServiceEndpointPoliciesServerTransport{srv: srv} +} + +// ServiceEndpointPoliciesServerTransport connects instances of armnetwork.ServiceEndpointPoliciesClient to instances of ServiceEndpointPoliciesServer. +// Don't use this type directly, use NewServiceEndpointPoliciesServerTransport instead. +type ServiceEndpointPoliciesServerTransport struct { + srv *ServiceEndpointPoliciesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ServiceEndpointPoliciesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ServiceEndpointPoliciesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.ServiceEndpointPoliciesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.ServiceEndpointPoliciesClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for ServiceEndpointPoliciesServerTransport. +func (s *ServiceEndpointPoliciesServerTransport) 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 "ServiceEndpointPoliciesClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "ServiceEndpointPoliciesClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "ServiceEndpointPoliciesClient.Get": + resp, err = s.dispatchGet(req) + case "ServiceEndpointPoliciesClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "ServiceEndpointPoliciesClient.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "ServiceEndpointPoliciesClient.UpdateTags": + resp, err = s.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServiceEndpointPoliciesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ServiceEndpointPolicy](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *ServiceEndpointPoliciesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, 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 *ServiceEndpointPoliciesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.ServiceEndpointPoliciesClientGetOptions + if expandParam != nil { + options = &armnetwork.ServiceEndpointPoliciesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, 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).ServiceEndpointPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServiceEndpointPoliciesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + 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.Network/ServiceEndpointPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.ServiceEndpointPoliciesClientListResponse, 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 *ServiceEndpointPoliciesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByResourceGroupPager == nil { + 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.Network/serviceEndpointPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.ServiceEndpointPoliciesClientListByResourceGroupResponse, 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 *ServiceEndpointPoliciesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if s.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, 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).ServiceEndpointPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/serviceendpointpolicydefinitions_server.go b/sdk/resourcemanager/network/armnetwork/fake/serviceendpointpolicydefinitions_server.go new file mode 100644 index 000000000000..1235bef457ed --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/serviceendpointpolicydefinitions_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ServiceEndpointPolicyDefinitionsServer is a fake server for instances of the armnetwork.ServiceEndpointPolicyDefinitionsClient type. +type ServiceEndpointPolicyDefinitionsServer struct { + // BeginCreateOrUpdate is the fake for method ServiceEndpointPolicyDefinitionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, serviceEndpointPolicyDefinitionName string, serviceEndpointPolicyDefinitions armnetwork.ServiceEndpointPolicyDefinition, options *armnetwork.ServiceEndpointPolicyDefinitionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ServiceEndpointPolicyDefinitionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ServiceEndpointPolicyDefinitionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, serviceEndpointPolicyDefinitionName string, options *armnetwork.ServiceEndpointPolicyDefinitionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ServiceEndpointPolicyDefinitionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ServiceEndpointPolicyDefinitionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, serviceEndpointPolicyDefinitionName string, options *armnetwork.ServiceEndpointPolicyDefinitionsClientGetOptions) (resp azfake.Responder[armnetwork.ServiceEndpointPolicyDefinitionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method ServiceEndpointPolicyDefinitionsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, serviceEndpointPolicyName string, options *armnetwork.ServiceEndpointPolicyDefinitionsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.ServiceEndpointPolicyDefinitionsClientListByResourceGroupResponse]) +} + +// NewServiceEndpointPolicyDefinitionsServerTransport creates a new instance of ServiceEndpointPolicyDefinitionsServerTransport with the provided implementation. +// The returned ServiceEndpointPolicyDefinitionsServerTransport instance is connected to an instance of armnetwork.ServiceEndpointPolicyDefinitionsClient by way of the +// undefined.Transporter field. +func NewServiceEndpointPolicyDefinitionsServerTransport(srv *ServiceEndpointPolicyDefinitionsServer) *ServiceEndpointPolicyDefinitionsServerTransport { + return &ServiceEndpointPolicyDefinitionsServerTransport{srv: srv} +} + +// ServiceEndpointPolicyDefinitionsServerTransport connects instances of armnetwork.ServiceEndpointPolicyDefinitionsClient to instances of ServiceEndpointPolicyDefinitionsServer. +// Don't use this type directly, use NewServiceEndpointPolicyDefinitionsServerTransport instead. +type ServiceEndpointPolicyDefinitionsServerTransport struct { + srv *ServiceEndpointPolicyDefinitionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.ServiceEndpointPolicyDefinitionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.ServiceEndpointPolicyDefinitionsClientDeleteResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.ServiceEndpointPolicyDefinitionsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for ServiceEndpointPolicyDefinitionsServerTransport. +func (s *ServiceEndpointPolicyDefinitionsServerTransport) 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 "ServiceEndpointPolicyDefinitionsClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "ServiceEndpointPolicyDefinitionsClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "ServiceEndpointPolicyDefinitionsClient.Get": + resp, err = s.dispatchGet(req) + case "ServiceEndpointPolicyDefinitionsClient.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServiceEndpointPolicyDefinitionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/serviceEndpointPolicyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ServiceEndpointPolicyDefinition](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyDefinitionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, serviceEndpointPolicyDefinitionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *ServiceEndpointPolicyDefinitionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/serviceEndpointPolicyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyDefinitionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, serviceEndpointPolicyDefinitionNameUnescaped, 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 *ServiceEndpointPolicyDefinitionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/serviceEndpointPolicyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyDefinitionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, serviceEndpointPolicyDefinitionNameUnescaped, 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).ServiceEndpointPolicyDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServiceEndpointPolicyDefinitionsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByResourceGroupPager == nil { + 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.Network/serviceEndpointPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/serviceEndpointPolicyDefinitions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + serviceEndpointPolicyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("serviceEndpointPolicyName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, serviceEndpointPolicyNameUnescaped, nil) + s.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(s.newListByResourceGroupPager, req, func(page *armnetwork.ServiceEndpointPolicyDefinitionsClientListByResourceGroupResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/servicetaginformation_server.go b/sdk/resourcemanager/network/armnetwork/fake/servicetaginformation_server.go new file mode 100644 index 000000000000..7c464c9cad8b --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/servicetaginformation_server.go @@ -0,0 +1,124 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// ServiceTagInformationServer is a fake server for instances of the armnetwork.ServiceTagInformationClient type. +type ServiceTagInformationServer struct { + // NewListPager is the fake for method ServiceTagInformationClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armnetwork.ServiceTagInformationClientListOptions) (resp azfake.PagerResponder[armnetwork.ServiceTagInformationClientListResponse]) +} + +// NewServiceTagInformationServerTransport creates a new instance of ServiceTagInformationServerTransport with the provided implementation. +// The returned ServiceTagInformationServerTransport instance is connected to an instance of armnetwork.ServiceTagInformationClient by way of the +// undefined.Transporter field. +func NewServiceTagInformationServerTransport(srv *ServiceTagInformationServer) *ServiceTagInformationServerTransport { + return &ServiceTagInformationServerTransport{srv: srv} +} + +// ServiceTagInformationServerTransport connects instances of armnetwork.ServiceTagInformationClient to instances of ServiceTagInformationServer. +// Don't use this type directly, use NewServiceTagInformationServerTransport instead. +type ServiceTagInformationServerTransport struct { + srv *ServiceTagInformationServer + newListPager *azfake.PagerResponder[armnetwork.ServiceTagInformationClientListResponse] +} + +// Do implements the policy.Transporter interface for ServiceTagInformationServerTransport. +func (s *ServiceTagInformationServerTransport) 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 "ServiceTagInformationClient.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 *ServiceTagInformationServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + 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.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/serviceTagDetails` + regex := regexp.MustCompile(regexStr) + 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() + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + noAddressPrefixesUnescaped, err := url.QueryUnescape(qp.Get("noAddressPrefixes")) + if err != nil { + return nil, err + } + noAddressPrefixesParam, err := parseOptional(noAddressPrefixesUnescaped, strconv.ParseBool) + if err != nil { + return nil, err + } + tagNameUnescaped, err := url.QueryUnescape(qp.Get("tagName")) + if err != nil { + return nil, err + } + tagNameParam := getOptional(tagNameUnescaped) + var options *armnetwork.ServiceTagInformationClientListOptions + if noAddressPrefixesParam != nil || tagNameParam != nil { + options = &armnetwork.ServiceTagInformationClientListOptions{ + NoAddressPrefixes: noAddressPrefixesParam, + TagName: tagNameParam, + } + } + resp := s.srv.NewListPager(locationUnescaped, options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.ServiceTagInformationClientListResponse, 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/network/armnetwork/fake/servicetags_server.go b/sdk/resourcemanager/network/armnetwork/fake/servicetags_server.go new file mode 100644 index 000000000000..e788bf218a1c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/servicetags_server.go @@ -0,0 +1,96 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// ServiceTagsServer is a fake server for instances of the armnetwork.ServiceTagsClient type. +type ServiceTagsServer struct { + // List is the fake for method ServiceTagsClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, location string, options *armnetwork.ServiceTagsClientListOptions) (resp azfake.Responder[armnetwork.ServiceTagsClientListResponse], errResp azfake.ErrorResponder) +} + +// NewServiceTagsServerTransport creates a new instance of ServiceTagsServerTransport with the provided implementation. +// The returned ServiceTagsServerTransport instance is connected to an instance of armnetwork.ServiceTagsClient by way of the +// undefined.Transporter field. +func NewServiceTagsServerTransport(srv *ServiceTagsServer) *ServiceTagsServerTransport { + return &ServiceTagsServerTransport{srv: srv} +} + +// ServiceTagsServerTransport connects instances of armnetwork.ServiceTagsClient to instances of ServiceTagsServer. +// Don't use this type directly, use NewServiceTagsServerTransport instead. +type ServiceTagsServerTransport struct { + srv *ServiceTagsServer +} + +// Do implements the policy.Transporter interface for ServiceTagsServerTransport. +func (s *ServiceTagsServerTransport) 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 "ServiceTagsClient.List": + resp, err = s.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServiceTagsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if s.srv.List == nil { + return nil, &nonRetriableError{errors.New("fake for method List not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/serviceTags` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + locationUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("location")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.List(req.Context(), locationUnescaped, 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).ServiceTagsListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/staticmembers_server.go b/sdk/resourcemanager/network/armnetwork/fake/staticmembers_server.go new file mode 100644 index 000000000000..4d45dff229f6 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/staticmembers_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// StaticMembersServer is a fake server for instances of the armnetwork.StaticMembersClient type. +type StaticMembersServer struct { + // CreateOrUpdate is the fake for method StaticMembersClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, staticMemberName string, parameters armnetwork.StaticMember, options *armnetwork.StaticMembersClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.StaticMembersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method StaticMembersClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, staticMemberName string, options *armnetwork.StaticMembersClientDeleteOptions) (resp azfake.Responder[armnetwork.StaticMembersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method StaticMembersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, staticMemberName string, options *armnetwork.StaticMembersClientGetOptions) (resp azfake.Responder[armnetwork.StaticMembersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method StaticMembersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkManagerName string, networkGroupName string, options *armnetwork.StaticMembersClientListOptions) (resp azfake.PagerResponder[armnetwork.StaticMembersClientListResponse]) +} + +// NewStaticMembersServerTransport creates a new instance of StaticMembersServerTransport with the provided implementation. +// The returned StaticMembersServerTransport instance is connected to an instance of armnetwork.StaticMembersClient by way of the +// undefined.Transporter field. +func NewStaticMembersServerTransport(srv *StaticMembersServer) *StaticMembersServerTransport { + return &StaticMembersServerTransport{srv: srv} +} + +// StaticMembersServerTransport connects instances of armnetwork.StaticMembersClient to instances of StaticMembersServer. +// Don't use this type directly, use NewStaticMembersServerTransport instead. +type StaticMembersServerTransport struct { + srv *StaticMembersServer + newListPager *azfake.PagerResponder[armnetwork.StaticMembersClientListResponse] +} + +// Do implements the policy.Transporter interface for StaticMembersServerTransport. +func (s *StaticMembersServerTransport) 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 "StaticMembersClient.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "StaticMembersClient.Delete": + resp, err = s.dispatchDelete(req) + case "StaticMembersClient.Get": + resp, err = s.dispatchGet(req) + case "StaticMembersClient.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 *StaticMembersServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/staticMembers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.StaticMember](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + staticMemberNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("staticMemberName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, staticMemberNameUnescaped, 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).StaticMember, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *StaticMembersServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/staticMembers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + staticMemberNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("staticMemberName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, staticMemberNameUnescaped, 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 *StaticMembersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/staticMembers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + staticMemberNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("staticMemberName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, staticMemberNameUnescaped, 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).StaticMember, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *StaticMembersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/staticMembers` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkManagerNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) + if err != nil { + return nil, err + } + networkGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkGroupName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.StaticMembersClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.StaticMembersClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := s.srv.NewListPager(resourceGroupNameUnescaped, networkManagerNameUnescaped, networkGroupNameUnescaped, options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.StaticMembersClientListResponse, 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/network/armnetwork/fake/subnets_server.go b/sdk/resourcemanager/network/armnetwork/fake/subnets_server.go new file mode 100644 index 000000000000..78b9b870b43f --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/subnets_server.go @@ -0,0 +1,382 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// SubnetsServer is a fake server for instances of the armnetwork.SubnetsClient type. +type SubnetsServer struct { + // BeginCreateOrUpdate is the fake for method SubnetsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters armnetwork.Subnet, options *armnetwork.SubnetsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.SubnetsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SubnetsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.SubnetsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.SubnetsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SubnetsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.SubnetsClientGetOptions) (resp azfake.Responder[armnetwork.SubnetsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SubnetsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualNetworkName string, options *armnetwork.SubnetsClientListOptions) (resp azfake.PagerResponder[armnetwork.SubnetsClientListResponse]) + + // BeginPrepareNetworkPolicies is the fake for method SubnetsClient.BeginPrepareNetworkPolicies + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginPrepareNetworkPolicies func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, prepareNetworkPoliciesRequestParameters armnetwork.PrepareNetworkPoliciesRequest, options *armnetwork.SubnetsClientBeginPrepareNetworkPoliciesOptions) (resp azfake.PollerResponder[armnetwork.SubnetsClientPrepareNetworkPoliciesResponse], errResp azfake.ErrorResponder) + + // BeginUnprepareNetworkPolicies is the fake for method SubnetsClient.BeginUnprepareNetworkPolicies + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUnprepareNetworkPolicies func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, unprepareNetworkPoliciesRequestParameters armnetwork.UnprepareNetworkPoliciesRequest, options *armnetwork.SubnetsClientBeginUnprepareNetworkPoliciesOptions) (resp azfake.PollerResponder[armnetwork.SubnetsClientUnprepareNetworkPoliciesResponse], errResp azfake.ErrorResponder) +} + +// NewSubnetsServerTransport creates a new instance of SubnetsServerTransport with the provided implementation. +// The returned SubnetsServerTransport instance is connected to an instance of armnetwork.SubnetsClient by way of the +// undefined.Transporter field. +func NewSubnetsServerTransport(srv *SubnetsServer) *SubnetsServerTransport { + return &SubnetsServerTransport{srv: srv} +} + +// SubnetsServerTransport connects instances of armnetwork.SubnetsClient to instances of SubnetsServer. +// Don't use this type directly, use NewSubnetsServerTransport instead. +type SubnetsServerTransport struct { + srv *SubnetsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.SubnetsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.SubnetsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.SubnetsClientListResponse] + beginPrepareNetworkPolicies *azfake.PollerResponder[armnetwork.SubnetsClientPrepareNetworkPoliciesResponse] + beginUnprepareNetworkPolicies *azfake.PollerResponder[armnetwork.SubnetsClientUnprepareNetworkPoliciesResponse] +} + +// Do implements the policy.Transporter interface for SubnetsServerTransport. +func (s *SubnetsServerTransport) 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 "SubnetsClient.BeginCreateOrUpdate": + resp, err = s.dispatchBeginCreateOrUpdate(req) + case "SubnetsClient.BeginDelete": + resp, err = s.dispatchBeginDelete(req) + case "SubnetsClient.Get": + resp, err = s.dispatchGet(req) + case "SubnetsClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "SubnetsClient.BeginPrepareNetworkPolicies": + resp, err = s.dispatchBeginPrepareNetworkPolicies(req) + case "SubnetsClient.BeginUnprepareNetworkPolicies": + resp, err = s.dispatchBeginUnprepareNetworkPolicies(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SubnetsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Subnet](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginCreateOrUpdate = &respr + } + + resp, err := server.PollerResponderNext(s.beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(s.beginCreateOrUpdate) { + s.beginCreateOrUpdate = nil + } + + return resp, nil +} + +func (s *SubnetsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, 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 *SubnetsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.SubnetsClientGetOptions + if expandParam != nil { + options = &armnetwork.SubnetsClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, 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).Subnet, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SubnetsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if s.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListPager(resourceGroupNameUnescaped, virtualNetworkNameUnescaped, nil) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.SubnetsClientListResponse, 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 *SubnetsServerTransport) dispatchBeginPrepareNetworkPolicies(req *http.Request) (*http.Response, error) { + if s.srv.BeginPrepareNetworkPolicies == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginPrepareNetworkPolicies not implemented")} + } + if s.beginPrepareNetworkPolicies == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/PrepareNetworkPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.PrepareNetworkPoliciesRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginPrepareNetworkPolicies(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginPrepareNetworkPolicies = &respr + } + + resp, err := server.PollerResponderNext(s.beginPrepareNetworkPolicies, 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.beginPrepareNetworkPolicies) { + s.beginPrepareNetworkPolicies = nil + } + + return resp, nil +} + +func (s *SubnetsServerTransport) dispatchBeginUnprepareNetworkPolicies(req *http.Request) (*http.Response, error) { + if s.srv.BeginUnprepareNetworkPolicies == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUnprepareNetworkPolicies not implemented")} + } + if s.beginUnprepareNetworkPolicies == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/UnprepareNetworkPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.UnprepareNetworkPoliciesRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + subnetNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUnprepareNetworkPolicies(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, subnetNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + s.beginUnprepareNetworkPolicies = &respr + } + + resp, err := server.PollerResponderNext(s.beginUnprepareNetworkPolicies, 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.beginUnprepareNetworkPolicies) { + s.beginUnprepareNetworkPolicies = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/subscriptionnetworkmanagerconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/subscriptionnetworkmanagerconnections_server.go new file mode 100644 index 000000000000..4422d6370fbe --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/subscriptionnetworkmanagerconnections_server.go @@ -0,0 +1,236 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// SubscriptionNetworkManagerConnectionsServer is a fake server for instances of the armnetwork.SubscriptionNetworkManagerConnectionsClient type. +type SubscriptionNetworkManagerConnectionsServer struct { + // CreateOrUpdate is the fake for method SubscriptionNetworkManagerConnectionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, networkManagerConnectionName string, parameters armnetwork.ManagerConnection, options *armnetwork.SubscriptionNetworkManagerConnectionsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.SubscriptionNetworkManagerConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method SubscriptionNetworkManagerConnectionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, networkManagerConnectionName string, options *armnetwork.SubscriptionNetworkManagerConnectionsClientDeleteOptions) (resp azfake.Responder[armnetwork.SubscriptionNetworkManagerConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SubscriptionNetworkManagerConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, networkManagerConnectionName string, options *armnetwork.SubscriptionNetworkManagerConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.SubscriptionNetworkManagerConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SubscriptionNetworkManagerConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.SubscriptionNetworkManagerConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.SubscriptionNetworkManagerConnectionsClientListResponse]) +} + +// NewSubscriptionNetworkManagerConnectionsServerTransport creates a new instance of SubscriptionNetworkManagerConnectionsServerTransport with the provided implementation. +// The returned SubscriptionNetworkManagerConnectionsServerTransport instance is connected to an instance of armnetwork.SubscriptionNetworkManagerConnectionsClient by way of the +// undefined.Transporter field. +func NewSubscriptionNetworkManagerConnectionsServerTransport(srv *SubscriptionNetworkManagerConnectionsServer) *SubscriptionNetworkManagerConnectionsServerTransport { + return &SubscriptionNetworkManagerConnectionsServerTransport{srv: srv} +} + +// SubscriptionNetworkManagerConnectionsServerTransport connects instances of armnetwork.SubscriptionNetworkManagerConnectionsClient to instances of SubscriptionNetworkManagerConnectionsServer. +// Don't use this type directly, use NewSubscriptionNetworkManagerConnectionsServerTransport instead. +type SubscriptionNetworkManagerConnectionsServerTransport struct { + srv *SubscriptionNetworkManagerConnectionsServer + newListPager *azfake.PagerResponder[armnetwork.SubscriptionNetworkManagerConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for SubscriptionNetworkManagerConnectionsServerTransport. +func (s *SubscriptionNetworkManagerConnectionsServerTransport) 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 "SubscriptionNetworkManagerConnectionsClient.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "SubscriptionNetworkManagerConnectionsClient.Delete": + resp, err = s.dispatchDelete(req) + case "SubscriptionNetworkManagerConnectionsClient.Get": + resp, err = s.dispatchGet(req) + case "SubscriptionNetworkManagerConnectionsClient.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 *SubscriptionNetworkManagerConnectionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ManagerConnection](req) + if err != nil { + return nil, err + } + networkManagerConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), networkManagerConnectionNameUnescaped, 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).ManagerConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SubscriptionNetworkManagerConnectionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + networkManagerConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), networkManagerConnectionNameUnescaped, 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 *SubscriptionNetworkManagerConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkManagerConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + networkManagerConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), networkManagerConnectionNameUnescaped, 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).ManagerConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SubscriptionNetworkManagerConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + 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.Network/networkManagerConnections` + regex := regexp.MustCompile(regexStr) + 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() + 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 + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.SubscriptionNetworkManagerConnectionsClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.SubscriptionNetworkManagerConnectionsClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := s.srv.NewListPager(options) + s.newListPager = &resp + server.PagerResponderInjectNextLinks(s.newListPager, req, func(page *armnetwork.SubscriptionNetworkManagerConnectionsClientListResponse, 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/network/armnetwork/fake/time_rfc3339.go b/sdk/resourcemanager/network/armnetwork/fake/time_rfc3339.go new file mode 100644 index 000000000000..45fe10cbc6df --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/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/network/armnetwork/fake/usages_server.go b/sdk/resourcemanager/network/armnetwork/fake/usages_server.go new file mode 100644 index 000000000000..98fee5e4214b --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/usages_server.go @@ -0,0 +1,102 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// UsagesServer is a fake server for instances of the armnetwork.UsagesClient type. +type UsagesServer struct { + // NewListPager is the fake for method UsagesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(location string, options *armnetwork.UsagesClientListOptions) (resp azfake.PagerResponder[armnetwork.UsagesClientListResponse]) +} + +// NewUsagesServerTransport creates a new instance of UsagesServerTransport with the provided implementation. +// The returned UsagesServerTransport instance is connected to an instance of armnetwork.UsagesClient by way of the +// undefined.Transporter field. +func NewUsagesServerTransport(srv *UsagesServer) *UsagesServerTransport { + return &UsagesServerTransport{srv: srv} +} + +// UsagesServerTransport connects instances of armnetwork.UsagesClient to instances of UsagesServer. +// Don't use this type directly, use NewUsagesServerTransport instead. +type UsagesServerTransport struct { + srv *UsagesServer + newListPager *azfake.PagerResponder[armnetwork.UsagesClientListResponse] +} + +// Do implements the policy.Transporter interface for UsagesServerTransport. +func (u *UsagesServerTransport) 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 "UsagesClient.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 *UsagesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if u.srv.NewListPager == nil { + 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.Network/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/usages` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.UsagesClientListResponse, 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/network/armnetwork/fake/vipswap_server.go b/sdk/resourcemanager/network/armnetwork/fake/vipswap_server.go new file mode 100644 index 000000000000..52b08f78042d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vipswap_server.go @@ -0,0 +1,191 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VipSwapServer is a fake server for instances of the armnetwork.VipSwapClient type. +type VipSwapServer struct { + // BeginCreate is the fake for method VipSwapClient.BeginCreate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCreate func(ctx context.Context, groupName string, resourceName string, parameters armnetwork.SwapResource, options *armnetwork.VipSwapClientBeginCreateOptions) (resp azfake.PollerResponder[armnetwork.VipSwapClientCreateResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VipSwapClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, groupName string, resourceName string, options *armnetwork.VipSwapClientGetOptions) (resp azfake.Responder[armnetwork.VipSwapClientGetResponse], errResp azfake.ErrorResponder) + + // List is the fake for method VipSwapClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, groupName string, resourceName string, options *armnetwork.VipSwapClientListOptions) (resp azfake.Responder[armnetwork.VipSwapClientListResponse], errResp azfake.ErrorResponder) +} + +// NewVipSwapServerTransport creates a new instance of VipSwapServerTransport with the provided implementation. +// The returned VipSwapServerTransport instance is connected to an instance of armnetwork.VipSwapClient by way of the +// undefined.Transporter field. +func NewVipSwapServerTransport(srv *VipSwapServer) *VipSwapServerTransport { + return &VipSwapServerTransport{srv: srv} +} + +// VipSwapServerTransport connects instances of armnetwork.VipSwapClient to instances of VipSwapServer. +// Don't use this type directly, use NewVipSwapServerTransport instead. +type VipSwapServerTransport struct { + srv *VipSwapServer + beginCreate *azfake.PollerResponder[armnetwork.VipSwapClientCreateResponse] +} + +// Do implements the policy.Transporter interface for VipSwapServerTransport. +func (v *VipSwapServerTransport) 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 "VipSwapClient.BeginCreate": + resp, err = v.dispatchBeginCreate(req) + case "VipSwapClient.Get": + resp, err = v.dispatchGet(req) + case "VipSwapClient.List": + resp, err = v.dispatchList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VipSwapServerTransport) dispatchBeginCreate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreate not implemented")} + } + if v.beginCreate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Compute/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/cloudServiceSlots/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SwapResource](req) + if err != nil { + return nil, err + } + groupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupName")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreate(req.Context(), groupNameUnescaped, resourceNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginCreate = &respr + } + + resp, err := server.PollerResponderNext(v.beginCreate, 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.beginCreate) { + v.beginCreate = nil + } + + return resp, nil +} + +func (v *VipSwapServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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~%@]+)/providers/Microsoft.Network/cloudServiceSlots/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + groupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupName")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), groupNameUnescaped, resourceNameUnescaped, 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).SwapResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VipSwapServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if v.srv.List == nil { + 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/cloudServices/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/cloudServiceSlots` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + groupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupName")]) + if err != nil { + return nil, err + } + resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.List(req.Context(), groupNameUnescaped, resourceNameUnescaped, 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).SwapResourceListResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualapplianceconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualapplianceconnections_server.go new file mode 100644 index 000000000000..9933b3351641 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualapplianceconnections_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualApplianceConnectionsServer is a fake server for instances of the armnetwork.VirtualApplianceConnectionsClient type. +type VirtualApplianceConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualApplianceConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, connectionName string, networkVirtualApplianceConnectionParameters armnetwork.VirtualApplianceConnection, options *armnetwork.VirtualApplianceConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualApplianceConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualApplianceConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, connectionName string, options *armnetwork.VirtualApplianceConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualApplianceConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualApplianceConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, connectionName string, options *armnetwork.VirtualApplianceConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualApplianceConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualApplianceConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualApplianceConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualApplianceConnectionsClientListResponse]) +} + +// NewVirtualApplianceConnectionsServerTransport creates a new instance of VirtualApplianceConnectionsServerTransport with the provided implementation. +// The returned VirtualApplianceConnectionsServerTransport instance is connected to an instance of armnetwork.VirtualApplianceConnectionsClient by way of the +// undefined.Transporter field. +func NewVirtualApplianceConnectionsServerTransport(srv *VirtualApplianceConnectionsServer) *VirtualApplianceConnectionsServerTransport { + return &VirtualApplianceConnectionsServerTransport{srv: srv} +} + +// VirtualApplianceConnectionsServerTransport connects instances of armnetwork.VirtualApplianceConnectionsClient to instances of VirtualApplianceConnectionsServer. +// Don't use this type directly, use NewVirtualApplianceConnectionsServerTransport instead. +type VirtualApplianceConnectionsServerTransport struct { + srv *VirtualApplianceConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualApplianceConnectionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualApplianceConnectionsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualApplianceConnectionsClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualApplianceConnectionsServerTransport. +func (v *VirtualApplianceConnectionsServerTransport) 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 "VirtualApplianceConnectionsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualApplianceConnectionsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualApplianceConnectionsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualApplianceConnectionsClient.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 *VirtualApplianceConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkVirtualApplianceConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualApplianceConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, connectionNameUnescaped, 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 *VirtualApplianceConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkVirtualApplianceConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, connectionNameUnescaped, 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 *VirtualApplianceConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkVirtualApplianceConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, connectionNameUnescaped, 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).VirtualApplianceConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualApplianceConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkVirtualApplianceConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualApplianceConnectionsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualappliances_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualappliances_server.go new file mode 100644 index 000000000000..6834be34c4a1 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualappliances_server.go @@ -0,0 +1,334 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualAppliancesServer is a fake server for instances of the armnetwork.VirtualAppliancesClient type. +type VirtualAppliancesServer struct { + // BeginCreateOrUpdate is the fake for method VirtualAppliancesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, parameters armnetwork.VirtualAppliance, options *armnetwork.VirtualAppliancesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualAppliancesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualAppliancesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualAppliancesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualAppliancesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualAppliancesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualAppliancesClientGetOptions) (resp azfake.Responder[armnetwork.VirtualAppliancesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualAppliancesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VirtualAppliancesClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualAppliancesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VirtualAppliancesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VirtualAppliancesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VirtualAppliancesClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method VirtualAppliancesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, parameters armnetwork.TagsObject, options *armnetwork.VirtualAppliancesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VirtualAppliancesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualAppliancesServerTransport creates a new instance of VirtualAppliancesServerTransport with the provided implementation. +// The returned VirtualAppliancesServerTransport instance is connected to an instance of armnetwork.VirtualAppliancesClient by way of the +// undefined.Transporter field. +func NewVirtualAppliancesServerTransport(srv *VirtualAppliancesServer) *VirtualAppliancesServerTransport { + return &VirtualAppliancesServerTransport{srv: srv} +} + +// VirtualAppliancesServerTransport connects instances of armnetwork.VirtualAppliancesClient to instances of VirtualAppliancesServer. +// Don't use this type directly, use NewVirtualAppliancesServerTransport instead. +type VirtualAppliancesServerTransport struct { + srv *VirtualAppliancesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualAppliancesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualAppliancesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualAppliancesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VirtualAppliancesClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VirtualAppliancesServerTransport. +func (v *VirtualAppliancesServerTransport) 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 "VirtualAppliancesClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualAppliancesClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualAppliancesClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualAppliancesClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualAppliancesClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VirtualAppliancesClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualAppliancesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualAppliance](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, 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 *VirtualAppliancesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, 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 *VirtualAppliancesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.VirtualAppliancesClientGetOptions + if expandParam != nil { + options = &armnetwork.VirtualAppliancesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, 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).VirtualAppliance, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualAppliancesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/networkVirtualAppliances` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualAppliancesClientListResponse, 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 *VirtualAppliancesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkVirtualAppliances` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VirtualAppliancesClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VirtualAppliancesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, 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).VirtualAppliance, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualappliancesites_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualappliancesites_server.go new file mode 100644 index 000000000000..7ee29ef675d0 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualappliancesites_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualApplianceSitesServer is a fake server for instances of the armnetwork.VirtualApplianceSitesClient type. +type VirtualApplianceSitesServer struct { + // BeginCreateOrUpdate is the fake for method VirtualApplianceSitesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, siteName string, parameters armnetwork.VirtualApplianceSite, options *armnetwork.VirtualApplianceSitesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualApplianceSitesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualApplianceSitesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, siteName string, options *armnetwork.VirtualApplianceSitesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualApplianceSitesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualApplianceSitesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, siteName string, options *armnetwork.VirtualApplianceSitesClientGetOptions) (resp azfake.Responder[armnetwork.VirtualApplianceSitesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualApplianceSitesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualApplianceSitesClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualApplianceSitesClientListResponse]) +} + +// NewVirtualApplianceSitesServerTransport creates a new instance of VirtualApplianceSitesServerTransport with the provided implementation. +// The returned VirtualApplianceSitesServerTransport instance is connected to an instance of armnetwork.VirtualApplianceSitesClient by way of the +// undefined.Transporter field. +func NewVirtualApplianceSitesServerTransport(srv *VirtualApplianceSitesServer) *VirtualApplianceSitesServerTransport { + return &VirtualApplianceSitesServerTransport{srv: srv} +} + +// VirtualApplianceSitesServerTransport connects instances of armnetwork.VirtualApplianceSitesClient to instances of VirtualApplianceSitesServer. +// Don't use this type directly, use NewVirtualApplianceSitesServerTransport instead. +type VirtualApplianceSitesServerTransport struct { + srv *VirtualApplianceSitesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualApplianceSitesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualApplianceSitesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualApplianceSitesClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualApplianceSitesServerTransport. +func (v *VirtualApplianceSitesServerTransport) 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 "VirtualApplianceSitesClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualApplianceSitesClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualApplianceSitesClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualApplianceSitesClient.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 *VirtualApplianceSitesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualApplianceSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualApplianceSite](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + siteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("siteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, siteNameUnescaped, 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 *VirtualApplianceSitesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualApplianceSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + siteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("siteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, siteNameUnescaped, 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 *VirtualApplianceSitesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualApplianceSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + siteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("siteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, siteNameUnescaped, 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).VirtualApplianceSite, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualApplianceSitesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/networkVirtualAppliances/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualApplianceSites` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkVirtualApplianceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, networkVirtualApplianceNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualApplianceSitesClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualapplianceskus_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualapplianceskus_server.go new file mode 100644 index 000000000000..efbd18982b2c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualapplianceskus_server.go @@ -0,0 +1,134 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualApplianceSKUsServer is a fake server for instances of the armnetwork.VirtualApplianceSKUsClient type. +type VirtualApplianceSKUsServer struct { + // Get is the fake for method VirtualApplianceSKUsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, skuName string, options *armnetwork.VirtualApplianceSKUsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualApplianceSKUsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualApplianceSKUsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VirtualApplianceSKUsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualApplianceSKUsClientListResponse]) +} + +// NewVirtualApplianceSKUsServerTransport creates a new instance of VirtualApplianceSKUsServerTransport with the provided implementation. +// The returned VirtualApplianceSKUsServerTransport instance is connected to an instance of armnetwork.VirtualApplianceSKUsClient by way of the +// undefined.Transporter field. +func NewVirtualApplianceSKUsServerTransport(srv *VirtualApplianceSKUsServer) *VirtualApplianceSKUsServerTransport { + return &VirtualApplianceSKUsServerTransport{srv: srv} +} + +// VirtualApplianceSKUsServerTransport connects instances of armnetwork.VirtualApplianceSKUsClient to instances of VirtualApplianceSKUsServer. +// Don't use this type directly, use NewVirtualApplianceSKUsServerTransport instead. +type VirtualApplianceSKUsServerTransport struct { + srv *VirtualApplianceSKUsServer + newListPager *azfake.PagerResponder[armnetwork.VirtualApplianceSKUsClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualApplianceSKUsServerTransport. +func (v *VirtualApplianceSKUsServerTransport) 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 "VirtualApplianceSKUsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualApplianceSKUsClient.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 *VirtualApplianceSKUsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkVirtualApplianceSkus/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + skuNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("skuName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), skuNameUnescaped, 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).VirtualApplianceSKU, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualApplianceSKUsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/networkVirtualApplianceSkus` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualApplianceSKUsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualhubbgpconnection_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualhubbgpconnection_server.go new file mode 100644 index 000000000000..6762d7df9fdf --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualhubbgpconnection_server.go @@ -0,0 +1,212 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualHubBgpConnectionServer is a fake server for instances of the armnetwork.VirtualHubBgpConnectionClient type. +type VirtualHubBgpConnectionServer struct { + // BeginCreateOrUpdate is the fake for method VirtualHubBgpConnectionClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, parameters armnetwork.BgpConnection, options *armnetwork.VirtualHubBgpConnectionClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualHubBgpConnectionClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualHubBgpConnectionClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionClientGetOptions) (resp azfake.Responder[armnetwork.VirtualHubBgpConnectionClientGetResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualHubBgpConnectionServerTransport creates a new instance of VirtualHubBgpConnectionServerTransport with the provided implementation. +// The returned VirtualHubBgpConnectionServerTransport instance is connected to an instance of armnetwork.VirtualHubBgpConnectionClient by way of the +// undefined.Transporter field. +func NewVirtualHubBgpConnectionServerTransport(srv *VirtualHubBgpConnectionServer) *VirtualHubBgpConnectionServerTransport { + return &VirtualHubBgpConnectionServerTransport{srv: srv} +} + +// VirtualHubBgpConnectionServerTransport connects instances of armnetwork.VirtualHubBgpConnectionClient to instances of VirtualHubBgpConnectionServer. +// Don't use this type directly, use NewVirtualHubBgpConnectionServerTransport instead. +type VirtualHubBgpConnectionServerTransport struct { + srv *VirtualHubBgpConnectionServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientDeleteResponse] +} + +// Do implements the policy.Transporter interface for VirtualHubBgpConnectionServerTransport. +func (v *VirtualHubBgpConnectionServerTransport) 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 "VirtualHubBgpConnectionClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualHubBgpConnectionClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualHubBgpConnectionClient.Get": + resp, err = v.dispatchGet(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualHubBgpConnectionServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.BgpConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, connectionNameUnescaped, 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 *VirtualHubBgpConnectionServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, connectionNameUnescaped, 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 *VirtualHubBgpConnectionServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, connectionNameUnescaped, 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).BgpConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualhubbgpconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualhubbgpconnections_server.go new file mode 100644 index 000000000000..30e5892a851b --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualhubbgpconnections_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/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualHubBgpConnectionsServer is a fake server for instances of the armnetwork.VirtualHubBgpConnectionsClient type. +type VirtualHubBgpConnectionsServer struct { + // NewListPager is the fake for method VirtualHubBgpConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubBgpConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualHubBgpConnectionsClientListResponse]) + + // BeginListAdvertisedRoutes is the fake for method VirtualHubBgpConnectionsClient.BeginListAdvertisedRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListAdvertisedRoutes func(ctx context.Context, resourceGroupName string, hubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionsClientBeginListAdvertisedRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse], errResp azfake.ErrorResponder) + + // BeginListLearnedRoutes is the fake for method VirtualHubBgpConnectionsClient.BeginListLearnedRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListLearnedRoutes func(ctx context.Context, resourceGroupName string, hubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionsClientBeginListLearnedRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListLearnedRoutesResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualHubBgpConnectionsServerTransport creates a new instance of VirtualHubBgpConnectionsServerTransport with the provided implementation. +// The returned VirtualHubBgpConnectionsServerTransport instance is connected to an instance of armnetwork.VirtualHubBgpConnectionsClient by way of the +// undefined.Transporter field. +func NewVirtualHubBgpConnectionsServerTransport(srv *VirtualHubBgpConnectionsServer) *VirtualHubBgpConnectionsServerTransport { + return &VirtualHubBgpConnectionsServerTransport{srv: srv} +} + +// VirtualHubBgpConnectionsServerTransport connects instances of armnetwork.VirtualHubBgpConnectionsClient to instances of VirtualHubBgpConnectionsServer. +// Don't use this type directly, use NewVirtualHubBgpConnectionsServerTransport instead. +type VirtualHubBgpConnectionsServerTransport struct { + srv *VirtualHubBgpConnectionsServer + newListPager *azfake.PagerResponder[armnetwork.VirtualHubBgpConnectionsClientListResponse] + beginListAdvertisedRoutes *azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse] + beginListLearnedRoutes *azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListLearnedRoutesResponse] +} + +// Do implements the policy.Transporter interface for VirtualHubBgpConnectionsServerTransport. +func (v *VirtualHubBgpConnectionsServerTransport) 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 "VirtualHubBgpConnectionsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualHubBgpConnectionsClient.BeginListAdvertisedRoutes": + resp, err = v.dispatchBeginListAdvertisedRoutes(req) + case "VirtualHubBgpConnectionsClient.BeginListLearnedRoutes": + resp, err = v.dispatchBeginListLearnedRoutes(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualHubBgpConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualHubBgpConnectionsClientListResponse, 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 *VirtualHubBgpConnectionsServerTransport) dispatchBeginListAdvertisedRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginListAdvertisedRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListAdvertisedRoutes not implemented")} + } + if v.beginListAdvertisedRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/advertisedRoutes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginListAdvertisedRoutes(req.Context(), resourceGroupNameUnescaped, hubNameUnescaped, connectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginListAdvertisedRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginListAdvertisedRoutes, 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.beginListAdvertisedRoutes) { + v.beginListAdvertisedRoutes = nil + } + + return resp, nil +} + +func (v *VirtualHubBgpConnectionsServerTransport) dispatchBeginListLearnedRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginListLearnedRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListLearnedRoutes not implemented")} + } + if v.beginListLearnedRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/learnedRoutes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + hubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("hubName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginListLearnedRoutes(req.Context(), resourceGroupNameUnescaped, hubNameUnescaped, connectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginListLearnedRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginListLearnedRoutes, 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.beginListLearnedRoutes) { + v.beginListLearnedRoutes = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualhubipconfiguration_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualhubipconfiguration_server.go new file mode 100644 index 000000000000..73b1fe33884c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualhubipconfiguration_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualHubIPConfigurationServer is a fake server for instances of the armnetwork.VirtualHubIPConfigurationClient type. +type VirtualHubIPConfigurationServer struct { + // BeginCreateOrUpdate is the fake for method VirtualHubIPConfigurationClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, ipConfigName string, parameters armnetwork.HubIPConfiguration, options *armnetwork.VirtualHubIPConfigurationClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubIPConfigurationClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualHubIPConfigurationClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, ipConfigName string, options *armnetwork.VirtualHubIPConfigurationClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubIPConfigurationClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualHubIPConfigurationClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, ipConfigName string, options *armnetwork.VirtualHubIPConfigurationClientGetOptions) (resp azfake.Responder[armnetwork.VirtualHubIPConfigurationClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualHubIPConfigurationClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubIPConfigurationClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualHubIPConfigurationClientListResponse]) +} + +// NewVirtualHubIPConfigurationServerTransport creates a new instance of VirtualHubIPConfigurationServerTransport with the provided implementation. +// The returned VirtualHubIPConfigurationServerTransport instance is connected to an instance of armnetwork.VirtualHubIPConfigurationClient by way of the +// undefined.Transporter field. +func NewVirtualHubIPConfigurationServerTransport(srv *VirtualHubIPConfigurationServer) *VirtualHubIPConfigurationServerTransport { + return &VirtualHubIPConfigurationServerTransport{srv: srv} +} + +// VirtualHubIPConfigurationServerTransport connects instances of armnetwork.VirtualHubIPConfigurationClient to instances of VirtualHubIPConfigurationServer. +// Don't use this type directly, use NewVirtualHubIPConfigurationServerTransport instead. +type VirtualHubIPConfigurationServerTransport struct { + srv *VirtualHubIPConfigurationServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualHubIPConfigurationClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualHubIPConfigurationClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualHubIPConfigurationClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualHubIPConfigurationServerTransport. +func (v *VirtualHubIPConfigurationServerTransport) 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 "VirtualHubIPConfigurationClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualHubIPConfigurationClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualHubIPConfigurationClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualHubIPConfigurationClient.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 *VirtualHubIPConfigurationServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.HubIPConfiguration](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + ipConfigNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, ipConfigNameUnescaped, 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 *VirtualHubIPConfigurationServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + ipConfigNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, ipConfigNameUnescaped, 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 *VirtualHubIPConfigurationServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + ipConfigNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, ipConfigNameUnescaped, 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).HubIPConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualHubIPConfigurationServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualHubIPConfigurationClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualhubroutetablev2s_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualhubroutetablev2s_server.go new file mode 100644 index 000000000000..aa50ef753365 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualhubroutetablev2s_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualHubRouteTableV2SServer is a fake server for instances of the armnetwork.VirtualHubRouteTableV2SClient type. +type VirtualHubRouteTableV2SServer struct { + // BeginCreateOrUpdate is the fake for method VirtualHubRouteTableV2SClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, virtualHubRouteTableV2Parameters armnetwork.VirtualHubRouteTableV2, options *armnetwork.VirtualHubRouteTableV2SClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubRouteTableV2SClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualHubRouteTableV2SClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *armnetwork.VirtualHubRouteTableV2SClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubRouteTableV2SClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualHubRouteTableV2SClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *armnetwork.VirtualHubRouteTableV2SClientGetOptions) (resp azfake.Responder[armnetwork.VirtualHubRouteTableV2SClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualHubRouteTableV2SClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubRouteTableV2SClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualHubRouteTableV2SClientListResponse]) +} + +// NewVirtualHubRouteTableV2SServerTransport creates a new instance of VirtualHubRouteTableV2SServerTransport with the provided implementation. +// The returned VirtualHubRouteTableV2SServerTransport instance is connected to an instance of armnetwork.VirtualHubRouteTableV2SClient by way of the +// undefined.Transporter field. +func NewVirtualHubRouteTableV2SServerTransport(srv *VirtualHubRouteTableV2SServer) *VirtualHubRouteTableV2SServerTransport { + return &VirtualHubRouteTableV2SServerTransport{srv: srv} +} + +// VirtualHubRouteTableV2SServerTransport connects instances of armnetwork.VirtualHubRouteTableV2SClient to instances of VirtualHubRouteTableV2SServer. +// Don't use this type directly, use NewVirtualHubRouteTableV2SServerTransport instead. +type VirtualHubRouteTableV2SServerTransport struct { + srv *VirtualHubRouteTableV2SServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualHubRouteTableV2SClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualHubRouteTableV2SClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualHubRouteTableV2SClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualHubRouteTableV2SServerTransport. +func (v *VirtualHubRouteTableV2SServerTransport) 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 "VirtualHubRouteTableV2SClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualHubRouteTableV2SClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualHubRouteTableV2SClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualHubRouteTableV2SClient.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 *VirtualHubRouteTableV2SServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualHubRouteTableV2](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeTableNameUnescaped, 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 *VirtualHubRouteTableV2SServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeTableNameUnescaped, 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 *VirtualHubRouteTableV2SServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + routeTableNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("routeTableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, routeTableNameUnescaped, 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).VirtualHubRouteTableV2, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualHubRouteTableV2SServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routeTables` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, virtualHubNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualHubRouteTableV2SClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualhubs_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualhubs_server.go new file mode 100644 index 000000000000..40983d2bed5c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualhubs_server.go @@ -0,0 +1,485 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// VirtualHubsServer is a fake server for instances of the armnetwork.VirtualHubsClient type. +type VirtualHubsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualHubsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters armnetwork.VirtualHub, options *armnetwork.VirtualHubsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualHubsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualHubsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualHubsClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGetEffectiveVirtualHubRoutes is the fake for method VirtualHubsClient.BeginGetEffectiveVirtualHubRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetEffectiveVirtualHubRoutes func(ctx context.Context, resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubsClientGetEffectiveVirtualHubRoutesResponse], errResp azfake.ErrorResponder) + + // BeginGetInboundRoutes is the fake for method VirtualHubsClient.BeginGetInboundRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetInboundRoutes func(ctx context.Context, resourceGroupName string, virtualHubName string, getInboundRoutesParameters armnetwork.GetInboundRoutesParameters, options *armnetwork.VirtualHubsClientBeginGetInboundRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubsClientGetInboundRoutesResponse], errResp azfake.ErrorResponder) + + // BeginGetOutboundRoutes is the fake for method VirtualHubsClient.BeginGetOutboundRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetOutboundRoutes func(ctx context.Context, resourceGroupName string, virtualHubName string, getOutboundRoutesParameters armnetwork.GetOutboundRoutesParameters, options *armnetwork.VirtualHubsClientBeginGetOutboundRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubsClientGetOutboundRoutesResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualHubsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VirtualHubsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualHubsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VirtualHubsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VirtualHubsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VirtualHubsClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method VirtualHubsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters armnetwork.TagsObject, options *armnetwork.VirtualHubsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VirtualHubsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualHubsServerTransport creates a new instance of VirtualHubsServerTransport with the provided implementation. +// The returned VirtualHubsServerTransport instance is connected to an instance of armnetwork.VirtualHubsClient by way of the +// undefined.Transporter field. +func NewVirtualHubsServerTransport(srv *VirtualHubsServer) *VirtualHubsServerTransport { + return &VirtualHubsServerTransport{srv: srv} +} + +// VirtualHubsServerTransport connects instances of armnetwork.VirtualHubsClient to instances of VirtualHubsServer. +// Don't use this type directly, use NewVirtualHubsServerTransport instead. +type VirtualHubsServerTransport struct { + srv *VirtualHubsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualHubsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualHubsClientDeleteResponse] + beginGetEffectiveVirtualHubRoutes *azfake.PollerResponder[armnetwork.VirtualHubsClientGetEffectiveVirtualHubRoutesResponse] + beginGetInboundRoutes *azfake.PollerResponder[armnetwork.VirtualHubsClientGetInboundRoutesResponse] + beginGetOutboundRoutes *azfake.PollerResponder[armnetwork.VirtualHubsClientGetOutboundRoutesResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualHubsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VirtualHubsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VirtualHubsServerTransport. +func (v *VirtualHubsServerTransport) 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 "VirtualHubsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualHubsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualHubsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualHubsClient.BeginGetEffectiveVirtualHubRoutes": + resp, err = v.dispatchBeginGetEffectiveVirtualHubRoutes(req) + case "VirtualHubsClient.BeginGetInboundRoutes": + resp, err = v.dispatchBeginGetInboundRoutes(req) + case "VirtualHubsClient.BeginGetOutboundRoutes": + resp, err = v.dispatchBeginGetOutboundRoutes(req) + case "VirtualHubsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualHubsClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VirtualHubsClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualHubsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualHub](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, 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 *VirtualHubsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, 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 *VirtualHubsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, 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).VirtualHub, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualHubsServerTransport) dispatchBeginGetEffectiveVirtualHubRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetEffectiveVirtualHubRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetEffectiveVirtualHubRoutes not implemented")} + } + if v.beginGetEffectiveVirtualHubRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/effectiveRoutes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.EffectiveRoutesParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions{ + EffectiveRoutesParameters: &body, + } + } + respr, errRespr := v.srv.BeginGetEffectiveVirtualHubRoutes(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetEffectiveVirtualHubRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetEffectiveVirtualHubRoutes, 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.beginGetEffectiveVirtualHubRoutes) { + v.beginGetEffectiveVirtualHubRoutes = nil + } + + return resp, nil +} + +func (v *VirtualHubsServerTransport) dispatchBeginGetInboundRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetInboundRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetInboundRoutes not implemented")} + } + if v.beginGetInboundRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/inboundRoutes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.GetInboundRoutesParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetInboundRoutes(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetInboundRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetInboundRoutes, 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.beginGetInboundRoutes) { + v.beginGetInboundRoutes = nil + } + + return resp, nil +} + +func (v *VirtualHubsServerTransport) dispatchBeginGetOutboundRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetOutboundRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetOutboundRoutes not implemented")} + } + if v.beginGetOutboundRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/outboundRoutes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.GetOutboundRoutesParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetOutboundRoutes(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetOutboundRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetOutboundRoutes, 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.beginGetOutboundRoutes) { + v.beginGetOutboundRoutes = nil + } + + return resp, nil +} + +func (v *VirtualHubsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualHubs` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualHubsClientListResponse, 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 *VirtualHubsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VirtualHubsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VirtualHubsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualHubNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, virtualHubNameUnescaped, 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).VirtualHub, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgatewayconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgatewayconnections_server.go new file mode 100644 index 000000000000..f57038a68de4 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgatewayconnections_server.go @@ -0,0 +1,644 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// VirtualNetworkGatewayConnectionsServer is a fake server for instances of the armnetwork.VirtualNetworkGatewayConnectionsClient type. +type VirtualNetworkGatewayConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualNetworkGatewayConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters armnetwork.VirtualNetworkGatewayConnection, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualNetworkGatewayConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualNetworkGatewayConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualNetworkGatewayConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGetIkeSas is the fake for method VirtualNetworkGatewayConnectionsClient.BeginGetIkeSas + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetIkeSas func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginGetIkeSasOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientGetIkeSasResponse], errResp azfake.ErrorResponder) + + // GetSharedKey is the fake for method VirtualNetworkGatewayConnectionsClient.GetSharedKey + // HTTP status codes to indicate success: http.StatusOK + GetSharedKey func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientGetSharedKeyOptions) (resp azfake.Responder[armnetwork.VirtualNetworkGatewayConnectionsClientGetSharedKeyResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualNetworkGatewayConnectionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientListResponse]) + + // BeginResetConnection is the fake for method VirtualNetworkGatewayConnectionsClient.BeginResetConnection + // HTTP status codes to indicate success: http.StatusAccepted + BeginResetConnection func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginResetConnectionOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientResetConnectionResponse], errResp azfake.ErrorResponder) + + // BeginResetSharedKey is the fake for method VirtualNetworkGatewayConnectionsClient.BeginResetSharedKey + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginResetSharedKey func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters armnetwork.ConnectionResetSharedKey, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginResetSharedKeyOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientResetSharedKeyResponse], errResp azfake.ErrorResponder) + + // BeginSetSharedKey is the fake for method VirtualNetworkGatewayConnectionsClient.BeginSetSharedKey + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginSetSharedKey func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters armnetwork.ConnectionSharedKey, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginSetSharedKeyOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientSetSharedKeyResponse], errResp azfake.ErrorResponder) + + // BeginStartPacketCapture is the fake for method VirtualNetworkGatewayConnectionsClient.BeginStartPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStartPacketCapture func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginStartPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientStartPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginStopPacketCapture is the fake for method VirtualNetworkGatewayConnectionsClient.BeginStopPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStopPacketCapture func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters armnetwork.VPNPacketCaptureStopParameters, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginStopPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientStopPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginUpdateTags is the fake for method VirtualNetworkGatewayConnectionsClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters armnetwork.TagsObject, options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualNetworkGatewayConnectionsServerTransport creates a new instance of VirtualNetworkGatewayConnectionsServerTransport with the provided implementation. +// The returned VirtualNetworkGatewayConnectionsServerTransport instance is connected to an instance of armnetwork.VirtualNetworkGatewayConnectionsClient by way of the +// undefined.Transporter field. +func NewVirtualNetworkGatewayConnectionsServerTransport(srv *VirtualNetworkGatewayConnectionsServer) *VirtualNetworkGatewayConnectionsServerTransport { + return &VirtualNetworkGatewayConnectionsServerTransport{srv: srv} +} + +// VirtualNetworkGatewayConnectionsServerTransport connects instances of armnetwork.VirtualNetworkGatewayConnectionsClient to instances of VirtualNetworkGatewayConnectionsServer. +// Don't use this type directly, use NewVirtualNetworkGatewayConnectionsServerTransport instead. +type VirtualNetworkGatewayConnectionsServerTransport struct { + srv *VirtualNetworkGatewayConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientDeleteResponse] + beginGetIkeSas *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientGetIkeSasResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientListResponse] + beginResetConnection *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientResetConnectionResponse] + beginResetSharedKey *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientResetSharedKeyResponse] + beginSetSharedKey *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientSetSharedKeyResponse] + beginStartPacketCapture *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientStartPacketCaptureResponse] + beginStopPacketCapture *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientStopPacketCaptureResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayConnectionsClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for VirtualNetworkGatewayConnectionsServerTransport. +func (v *VirtualNetworkGatewayConnectionsServerTransport) 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 "VirtualNetworkGatewayConnectionsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualNetworkGatewayConnectionsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualNetworkGatewayConnectionsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualNetworkGatewayConnectionsClient.BeginGetIkeSas": + resp, err = v.dispatchBeginGetIkeSas(req) + case "VirtualNetworkGatewayConnectionsClient.GetSharedKey": + resp, err = v.dispatchGetSharedKey(req) + case "VirtualNetworkGatewayConnectionsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualNetworkGatewayConnectionsClient.BeginResetConnection": + resp, err = v.dispatchBeginResetConnection(req) + case "VirtualNetworkGatewayConnectionsClient.BeginResetSharedKey": + resp, err = v.dispatchBeginResetSharedKey(req) + case "VirtualNetworkGatewayConnectionsClient.BeginSetSharedKey": + resp, err = v.dispatchBeginSetSharedKey(req) + case "VirtualNetworkGatewayConnectionsClient.BeginStartPacketCapture": + resp, err = v.dispatchBeginStartPacketCapture(req) + case "VirtualNetworkGatewayConnectionsClient.BeginStopPacketCapture": + resp, err = v.dispatchBeginStopPacketCapture(req) + case "VirtualNetworkGatewayConnectionsClient.BeginUpdateTags": + resp, err = v.dispatchBeginUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualNetworkGatewayConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, 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 *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, 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 *VirtualNetworkGatewayConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, 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).VirtualNetworkGatewayConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginGetIkeSas(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetIkeSas == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetIkeSas not implemented")} + } + if v.beginGetIkeSas == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getikesas` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetIkeSas(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetIkeSas = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetIkeSas, 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.beginGetIkeSas) { + v.beginGetIkeSas = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchGetSharedKey(req *http.Request) (*http.Response, error) { + if v.srv.GetSharedKey == nil { + return nil, &nonRetriableError{errors.New("fake for method GetSharedKey not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedkey` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.GetSharedKey(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, 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).ConnectionSharedKey, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/connections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.VirtualNetworkGatewayConnectionsClientListResponse, 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 *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginResetConnection(req *http.Request) (*http.Response, error) { + if v.srv.BeginResetConnection == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginResetConnection not implemented")} + } + if v.beginResetConnection == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resetconnection` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginResetConnection(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginResetConnection = &respr + } + + resp, err := server.PollerResponderNext(v.beginResetConnection, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(v.beginResetConnection) { + v.beginResetConnection = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginResetSharedKey(req *http.Request) (*http.Response, error) { + if v.srv.BeginResetSharedKey == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginResetSharedKey not implemented")} + } + if v.beginResetSharedKey == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedkey/reset` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ConnectionResetSharedKey](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginResetSharedKey(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginResetSharedKey = &respr + } + + resp, err := server.PollerResponderNext(v.beginResetSharedKey, 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.beginResetSharedKey) { + v.beginResetSharedKey = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginSetSharedKey(req *http.Request) (*http.Response, error) { + if v.srv.BeginSetSharedKey == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginSetSharedKey not implemented")} + } + if v.beginSetSharedKey == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sharedkey` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ConnectionSharedKey](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginSetSharedKey(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginSetSharedKey = &respr + } + + resp, err := server.PollerResponderNext(v.beginSetSharedKey, 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.beginSetSharedKey) { + v.beginSetSharedKey = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginStartPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStartPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStartPacketCapture not implemented")} + } + if v.beginStartPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/startPacketCapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNPacketCaptureStartParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VirtualNetworkGatewayConnectionsClientBeginStartPacketCaptureOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VirtualNetworkGatewayConnectionsClientBeginStartPacketCaptureOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginStartPacketCapture(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStartPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStartPacketCapture, 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.beginStartPacketCapture) { + v.beginStartPacketCapture = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginStopPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStopPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStopPacketCapture not implemented")} + } + if v.beginStopPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stopPacketCapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNPacketCaptureStopParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginStopPacketCapture(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStopPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStopPacketCapture, 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.beginStopPacketCapture) { + v.beginStopPacketCapture = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayConnectionsServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if v.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdateTags, 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.beginUpdateTags) { + v.beginUpdateTags = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgatewaynatrules_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgatewaynatrules_server.go new file mode 100644 index 000000000000..f0c496e3ae23 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgatewaynatrules_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualNetworkGatewayNatRulesServer is a fake server for instances of the armnetwork.VirtualNetworkGatewayNatRulesClient type. +type VirtualNetworkGatewayNatRulesServer struct { + // BeginCreateOrUpdate is the fake for method VirtualNetworkGatewayNatRulesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, natRuleName string, natRuleParameters armnetwork.VirtualNetworkGatewayNatRule, options *armnetwork.VirtualNetworkGatewayNatRulesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayNatRulesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualNetworkGatewayNatRulesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, natRuleName string, options *armnetwork.VirtualNetworkGatewayNatRulesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewayNatRulesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualNetworkGatewayNatRulesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, natRuleName string, options *armnetwork.VirtualNetworkGatewayNatRulesClientGetOptions) (resp azfake.Responder[armnetwork.VirtualNetworkGatewayNatRulesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByVirtualNetworkGatewayPager is the fake for method VirtualNetworkGatewayNatRulesClient.NewListByVirtualNetworkGatewayPager + // HTTP status codes to indicate success: http.StatusOK + NewListByVirtualNetworkGatewayPager func(resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewayNatRulesClientListByVirtualNetworkGatewayOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkGatewayNatRulesClientListByVirtualNetworkGatewayResponse]) +} + +// NewVirtualNetworkGatewayNatRulesServerTransport creates a new instance of VirtualNetworkGatewayNatRulesServerTransport with the provided implementation. +// The returned VirtualNetworkGatewayNatRulesServerTransport instance is connected to an instance of armnetwork.VirtualNetworkGatewayNatRulesClient by way of the +// undefined.Transporter field. +func NewVirtualNetworkGatewayNatRulesServerTransport(srv *VirtualNetworkGatewayNatRulesServer) *VirtualNetworkGatewayNatRulesServerTransport { + return &VirtualNetworkGatewayNatRulesServerTransport{srv: srv} +} + +// VirtualNetworkGatewayNatRulesServerTransport connects instances of armnetwork.VirtualNetworkGatewayNatRulesClient to instances of VirtualNetworkGatewayNatRulesServer. +// Don't use this type directly, use NewVirtualNetworkGatewayNatRulesServerTransport instead. +type VirtualNetworkGatewayNatRulesServerTransport struct { + srv *VirtualNetworkGatewayNatRulesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayNatRulesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualNetworkGatewayNatRulesClientDeleteResponse] + newListByVirtualNetworkGatewayPager *azfake.PagerResponder[armnetwork.VirtualNetworkGatewayNatRulesClientListByVirtualNetworkGatewayResponse] +} + +// Do implements the policy.Transporter interface for VirtualNetworkGatewayNatRulesServerTransport. +func (v *VirtualNetworkGatewayNatRulesServerTransport) 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 "VirtualNetworkGatewayNatRulesClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualNetworkGatewayNatRulesClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualNetworkGatewayNatRulesClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualNetworkGatewayNatRulesClient.NewListByVirtualNetworkGatewayPager": + resp, err = v.dispatchNewListByVirtualNetworkGatewayPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualNetworkGatewayNatRulesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualNetworkGatewayNatRule](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + natRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, natRuleNameUnescaped, 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 *VirtualNetworkGatewayNatRulesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + natRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, natRuleNameUnescaped, 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 *VirtualNetworkGatewayNatRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + natRuleNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("natRuleName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, natRuleNameUnescaped, 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).VirtualNetworkGatewayNatRule, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkGatewayNatRulesServerTransport) dispatchNewListByVirtualNetworkGatewayPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByVirtualNetworkGatewayPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByVirtualNetworkGatewayPager not implemented")} + } + if v.newListByVirtualNetworkGatewayPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/natRules` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByVirtualNetworkGatewayPager(resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + v.newListByVirtualNetworkGatewayPager = &resp + server.PagerResponderInjectNextLinks(v.newListByVirtualNetworkGatewayPager, req, func(page *armnetwork.VirtualNetworkGatewayNatRulesClientListByVirtualNetworkGatewayResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByVirtualNetworkGatewayPager, 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.newListByVirtualNetworkGatewayPager) { + v.newListByVirtualNetworkGatewayPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgateways_server.go new file mode 100644 index 000000000000..d83bb4202fcb --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkgateways_server.go @@ -0,0 +1,1153 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// VirtualNetworkGatewaysServer is a fake server for instances of the armnetwork.VirtualNetworkGatewaysClient type. +type VirtualNetworkGatewaysServer struct { + // BeginCreateOrUpdate is the fake for method VirtualNetworkGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters armnetwork.VirtualNetworkGateway, options *armnetwork.VirtualNetworkGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualNetworkGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDisconnectVirtualNetworkGatewayVPNConnections is the fake for method VirtualNetworkGatewaysClient.BeginDisconnectVirtualNetworkGatewayVPNConnections + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDisconnectVirtualNetworkGatewayVPNConnections func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, request armnetwork.P2SVPNConnectionRequest, options *armnetwork.VirtualNetworkGatewaysClientBeginDisconnectVirtualNetworkGatewayVPNConnectionsOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientDisconnectVirtualNetworkGatewayVPNConnectionsResponse], errResp azfake.ErrorResponder) + + // BeginGenerateVPNProfile is the fake for method VirtualNetworkGatewaysClient.BeginGenerateVPNProfile + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGenerateVPNProfile func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters armnetwork.VPNClientParameters, options *armnetwork.VirtualNetworkGatewaysClientBeginGenerateVPNProfileOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGenerateVPNProfileResponse], errResp azfake.ErrorResponder) + + // BeginGeneratevpnclientpackage is the fake for method VirtualNetworkGatewaysClient.BeginGeneratevpnclientpackage + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGeneratevpnclientpackage func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters armnetwork.VPNClientParameters, options *armnetwork.VirtualNetworkGatewaysClientBeginGeneratevpnclientpackageOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGeneratevpnclientpackageResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualNetworkGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.VirtualNetworkGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGetAdvertisedRoutes is the fake for method VirtualNetworkGatewaysClient.BeginGetAdvertisedRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetAdvertisedRoutes func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, peer string, options *armnetwork.VirtualNetworkGatewaysClientBeginGetAdvertisedRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetAdvertisedRoutesResponse], errResp azfake.ErrorResponder) + + // BeginGetBgpPeerStatus is the fake for method VirtualNetworkGatewaysClient.BeginGetBgpPeerStatus + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetBgpPeerStatus func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginGetBgpPeerStatusOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetBgpPeerStatusResponse], errResp azfake.ErrorResponder) + + // BeginGetLearnedRoutes is the fake for method VirtualNetworkGatewaysClient.BeginGetLearnedRoutes + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetLearnedRoutes func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginGetLearnedRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetLearnedRoutesResponse], errResp azfake.ErrorResponder) + + // BeginGetVPNProfilePackageURL is the fake for method VirtualNetworkGatewaysClient.BeginGetVPNProfilePackageURL + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetVPNProfilePackageURL func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginGetVPNProfilePackageURLOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetVPNProfilePackageURLResponse], errResp azfake.ErrorResponder) + + // BeginGetVpnclientConnectionHealth is the fake for method VirtualNetworkGatewaysClient.BeginGetVpnclientConnectionHealth + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetVpnclientConnectionHealth func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginGetVpnclientConnectionHealthOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetVpnclientConnectionHealthResponse], errResp azfake.ErrorResponder) + + // BeginGetVpnclientIPSecParameters is the fake for method VirtualNetworkGatewaysClient.BeginGetVpnclientIPSecParameters + // HTTP status codes to indicate success: http.StatusOK + BeginGetVpnclientIPSecParameters func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginGetVpnclientIPSecParametersOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetVpnclientIPSecParametersResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualNetworkGatewaysClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.VirtualNetworkGatewaysClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkGatewaysClientListResponse]) + + // NewListConnectionsPager is the fake for method VirtualNetworkGatewaysClient.NewListConnectionsPager + // HTTP status codes to indicate success: http.StatusOK + NewListConnectionsPager func(resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientListConnectionsOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkGatewaysClientListConnectionsResponse]) + + // BeginReset is the fake for method VirtualNetworkGatewaysClient.BeginReset + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReset func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginResetOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientResetResponse], errResp azfake.ErrorResponder) + + // BeginResetVPNClientSharedKey is the fake for method VirtualNetworkGatewaysClient.BeginResetVPNClientSharedKey + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginResetVPNClientSharedKey func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginResetVPNClientSharedKeyOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientResetVPNClientSharedKeyResponse], errResp azfake.ErrorResponder) + + // BeginSetVpnclientIPSecParameters is the fake for method VirtualNetworkGatewaysClient.BeginSetVpnclientIPSecParameters + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginSetVpnclientIPSecParameters func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, vpnclientIPSecParams armnetwork.VPNClientIPsecParameters, options *armnetwork.VirtualNetworkGatewaysClientBeginSetVpnclientIPSecParametersOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientSetVpnclientIPSecParametersResponse], errResp azfake.ErrorResponder) + + // BeginStartPacketCapture is the fake for method VirtualNetworkGatewaysClient.BeginStartPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStartPacketCapture func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientBeginStartPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientStartPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginStopPacketCapture is the fake for method VirtualNetworkGatewaysClient.BeginStopPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStopPacketCapture func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters armnetwork.VPNPacketCaptureStopParameters, options *armnetwork.VirtualNetworkGatewaysClientBeginStopPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientStopPacketCaptureResponse], errResp azfake.ErrorResponder) + + // SupportedVPNDevices is the fake for method VirtualNetworkGatewaysClient.SupportedVPNDevices + // HTTP status codes to indicate success: http.StatusOK + SupportedVPNDevices func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *armnetwork.VirtualNetworkGatewaysClientSupportedVPNDevicesOptions) (resp azfake.Responder[armnetwork.VirtualNetworkGatewaysClientSupportedVPNDevicesResponse], errResp azfake.ErrorResponder) + + // BeginUpdateTags is the fake for method VirtualNetworkGatewaysClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters armnetwork.TagsObject, options *armnetwork.VirtualNetworkGatewaysClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) + + // VPNDeviceConfigurationScript is the fake for method VirtualNetworkGatewaysClient.VPNDeviceConfigurationScript + // HTTP status codes to indicate success: http.StatusOK + VPNDeviceConfigurationScript func(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters armnetwork.VPNDeviceScriptParameters, options *armnetwork.VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptOptions) (resp azfake.Responder[armnetwork.VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualNetworkGatewaysServerTransport creates a new instance of VirtualNetworkGatewaysServerTransport with the provided implementation. +// The returned VirtualNetworkGatewaysServerTransport instance is connected to an instance of armnetwork.VirtualNetworkGatewaysClient by way of the +// undefined.Transporter field. +func NewVirtualNetworkGatewaysServerTransport(srv *VirtualNetworkGatewaysServer) *VirtualNetworkGatewaysServerTransport { + return &VirtualNetworkGatewaysServerTransport{srv: srv} +} + +// VirtualNetworkGatewaysServerTransport connects instances of armnetwork.VirtualNetworkGatewaysClient to instances of VirtualNetworkGatewaysServer. +// Don't use this type directly, use NewVirtualNetworkGatewaysServerTransport instead. +type VirtualNetworkGatewaysServerTransport struct { + srv *VirtualNetworkGatewaysServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientDeleteResponse] + beginDisconnectVirtualNetworkGatewayVPNConnections *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientDisconnectVirtualNetworkGatewayVPNConnectionsResponse] + beginGenerateVPNProfile *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGenerateVPNProfileResponse] + beginGeneratevpnclientpackage *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGeneratevpnclientpackageResponse] + beginGetAdvertisedRoutes *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetAdvertisedRoutesResponse] + beginGetBgpPeerStatus *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetBgpPeerStatusResponse] + beginGetLearnedRoutes *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetLearnedRoutesResponse] + beginGetVPNProfilePackageURL *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetVPNProfilePackageURLResponse] + beginGetVpnclientConnectionHealth *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetVpnclientConnectionHealthResponse] + beginGetVpnclientIPSecParameters *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientGetVpnclientIPSecParametersResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualNetworkGatewaysClientListResponse] + newListConnectionsPager *azfake.PagerResponder[armnetwork.VirtualNetworkGatewaysClientListConnectionsResponse] + beginReset *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientResetResponse] + beginResetVPNClientSharedKey *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientResetVPNClientSharedKeyResponse] + beginSetVpnclientIPSecParameters *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientSetVpnclientIPSecParametersResponse] + beginStartPacketCapture *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientStartPacketCaptureResponse] + beginStopPacketCapture *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientStopPacketCaptureResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.VirtualNetworkGatewaysClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for VirtualNetworkGatewaysServerTransport. +func (v *VirtualNetworkGatewaysServerTransport) 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 "VirtualNetworkGatewaysClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualNetworkGatewaysClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualNetworkGatewaysClient.BeginDisconnectVirtualNetworkGatewayVPNConnections": + resp, err = v.dispatchBeginDisconnectVirtualNetworkGatewayVPNConnections(req) + case "VirtualNetworkGatewaysClient.BeginGenerateVPNProfile": + resp, err = v.dispatchBeginGenerateVPNProfile(req) + case "VirtualNetworkGatewaysClient.BeginGeneratevpnclientpackage": + resp, err = v.dispatchBeginGeneratevpnclientpackage(req) + case "VirtualNetworkGatewaysClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualNetworkGatewaysClient.BeginGetAdvertisedRoutes": + resp, err = v.dispatchBeginGetAdvertisedRoutes(req) + case "VirtualNetworkGatewaysClient.BeginGetBgpPeerStatus": + resp, err = v.dispatchBeginGetBgpPeerStatus(req) + case "VirtualNetworkGatewaysClient.BeginGetLearnedRoutes": + resp, err = v.dispatchBeginGetLearnedRoutes(req) + case "VirtualNetworkGatewaysClient.BeginGetVPNProfilePackageURL": + resp, err = v.dispatchBeginGetVPNProfilePackageURL(req) + case "VirtualNetworkGatewaysClient.BeginGetVpnclientConnectionHealth": + resp, err = v.dispatchBeginGetVpnclientConnectionHealth(req) + case "VirtualNetworkGatewaysClient.BeginGetVpnclientIPSecParameters": + resp, err = v.dispatchBeginGetVpnclientIPSecParameters(req) + case "VirtualNetworkGatewaysClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualNetworkGatewaysClient.NewListConnectionsPager": + resp, err = v.dispatchNewListConnectionsPager(req) + case "VirtualNetworkGatewaysClient.BeginReset": + resp, err = v.dispatchBeginReset(req) + case "VirtualNetworkGatewaysClient.BeginResetVPNClientSharedKey": + resp, err = v.dispatchBeginResetVPNClientSharedKey(req) + case "VirtualNetworkGatewaysClient.BeginSetVpnclientIPSecParameters": + resp, err = v.dispatchBeginSetVpnclientIPSecParameters(req) + case "VirtualNetworkGatewaysClient.BeginStartPacketCapture": + resp, err = v.dispatchBeginStartPacketCapture(req) + case "VirtualNetworkGatewaysClient.BeginStopPacketCapture": + resp, err = v.dispatchBeginStopPacketCapture(req) + case "VirtualNetworkGatewaysClient.SupportedVPNDevices": + resp, err = v.dispatchSupportedVPNDevices(req) + case "VirtualNetworkGatewaysClient.BeginUpdateTags": + resp, err = v.dispatchBeginUpdateTags(req) + case "VirtualNetworkGatewaysClient.VPNDeviceConfigurationScript": + resp, err = v.dispatchVPNDeviceConfigurationScript(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualNetworkGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, 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 *VirtualNetworkGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, 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 *VirtualNetworkGatewaysServerTransport) dispatchBeginDisconnectVirtualNetworkGatewayVPNConnections(req *http.Request) (*http.Response, error) { + if v.srv.BeginDisconnectVirtualNetworkGatewayVPNConnections == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDisconnectVirtualNetworkGatewayVPNConnections not implemented")} + } + if v.beginDisconnectVirtualNetworkGatewayVPNConnections == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/disconnectVirtualNetworkGatewayVpnConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.P2SVPNConnectionRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDisconnectVirtualNetworkGatewayVPNConnections(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDisconnectVirtualNetworkGatewayVPNConnections = &respr + } + + resp, err := server.PollerResponderNext(v.beginDisconnectVirtualNetworkGatewayVPNConnections, 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.beginDisconnectVirtualNetworkGatewayVPNConnections) { + v.beginDisconnectVirtualNetworkGatewayVPNConnections = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGenerateVPNProfile(req *http.Request) (*http.Response, error) { + if v.srv.BeginGenerateVPNProfile == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGenerateVPNProfile not implemented")} + } + if v.beginGenerateVPNProfile == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generatevpnprofile` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNClientParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGenerateVPNProfile(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGenerateVPNProfile = &respr + } + + resp, err := server.PollerResponderNext(v.beginGenerateVPNProfile, 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.beginGenerateVPNProfile) { + v.beginGenerateVPNProfile = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGeneratevpnclientpackage(req *http.Request) (*http.Response, error) { + if v.srv.BeginGeneratevpnclientpackage == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGeneratevpnclientpackage not implemented")} + } + if v.beginGeneratevpnclientpackage == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generatevpnclientpackage` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNClientParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGeneratevpnclientpackage(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGeneratevpnclientpackage = &respr + } + + resp, err := server.PollerResponderNext(v.beginGeneratevpnclientpackage, 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.beginGeneratevpnclientpackage) { + v.beginGeneratevpnclientpackage = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, 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).VirtualNetworkGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGetAdvertisedRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetAdvertisedRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetAdvertisedRoutes not implemented")} + } + if v.beginGetAdvertisedRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getAdvertisedRoutes` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + peerUnescaped, err := url.QueryUnescape(qp.Get("peer")) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetAdvertisedRoutes(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, peerUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetAdvertisedRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetAdvertisedRoutes, 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.beginGetAdvertisedRoutes) { + v.beginGetAdvertisedRoutes = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGetBgpPeerStatus(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetBgpPeerStatus == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetBgpPeerStatus not implemented")} + } + if v.beginGetBgpPeerStatus == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getBgpPeerStatus` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + peerUnescaped, err := url.QueryUnescape(qp.Get("peer")) + if err != nil { + return nil, err + } + peerParam := getOptional(peerUnescaped) + var options *armnetwork.VirtualNetworkGatewaysClientBeginGetBgpPeerStatusOptions + if peerParam != nil { + options = &armnetwork.VirtualNetworkGatewaysClientBeginGetBgpPeerStatusOptions{ + Peer: peerParam, + } + } + respr, errRespr := v.srv.BeginGetBgpPeerStatus(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetBgpPeerStatus = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetBgpPeerStatus, 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.beginGetBgpPeerStatus) { + v.beginGetBgpPeerStatus = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGetLearnedRoutes(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetLearnedRoutes == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetLearnedRoutes not implemented")} + } + if v.beginGetLearnedRoutes == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getLearnedRoutes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetLearnedRoutes(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetLearnedRoutes = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetLearnedRoutes, 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.beginGetLearnedRoutes) { + v.beginGetLearnedRoutes = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGetVPNProfilePackageURL(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetVPNProfilePackageURL == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetVPNProfilePackageURL not implemented")} + } + if v.beginGetVPNProfilePackageURL == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getvpnprofilepackageurl` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetVPNProfilePackageURL(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetVPNProfilePackageURL = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetVPNProfilePackageURL, 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.beginGetVPNProfilePackageURL) { + v.beginGetVPNProfilePackageURL = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGetVpnclientConnectionHealth(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetVpnclientConnectionHealth == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetVpnclientConnectionHealth not implemented")} + } + if v.beginGetVpnclientConnectionHealth == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getVpnClientConnectionHealth` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetVpnclientConnectionHealth(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetVpnclientConnectionHealth = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetVpnclientConnectionHealth, 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.beginGetVpnclientConnectionHealth) { + v.beginGetVpnclientConnectionHealth = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginGetVpnclientIPSecParameters(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetVpnclientIPSecParameters == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetVpnclientIPSecParameters not implemented")} + } + if v.beginGetVpnclientIPSecParameters == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getvpnclientipsecparameters` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetVpnclientIPSecParameters(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetVpnclientIPSecParameters = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetVpnclientIPSecParameters, 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.beginGetVpnclientIPSecParameters) { + v.beginGetVpnclientIPSecParameters = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualNetworkGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.VirtualNetworkGatewaysClientListResponse, 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 *VirtualNetworkGatewaysServerTransport) dispatchNewListConnectionsPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListConnectionsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListConnectionsPager not implemented")} + } + if v.newListConnectionsPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListConnectionsPager(resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + v.newListConnectionsPager = &resp + server.PagerResponderInjectNextLinks(v.newListConnectionsPager, req, func(page *armnetwork.VirtualNetworkGatewaysClientListConnectionsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListConnectionsPager, 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.newListConnectionsPager) { + v.newListConnectionsPager = nil + } + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginReset(req *http.Request) (*http.Response, error) { + if v.srv.BeginReset == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginReset not implemented")} + } + if v.beginReset == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reset` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + gatewayVipUnescaped, err := url.QueryUnescape(qp.Get("gatewayVip")) + if err != nil { + return nil, err + } + gatewayVipParam := getOptional(gatewayVipUnescaped) + var options *armnetwork.VirtualNetworkGatewaysClientBeginResetOptions + if gatewayVipParam != nil { + options = &armnetwork.VirtualNetworkGatewaysClientBeginResetOptions{ + GatewayVip: gatewayVipParam, + } + } + respr, errRespr := v.srv.BeginReset(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReset = &respr + } + + resp, err := server.PollerResponderNext(v.beginReset, 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.beginReset) { + v.beginReset = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginResetVPNClientSharedKey(req *http.Request) (*http.Response, error) { + if v.srv.BeginResetVPNClientSharedKey == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginResetVPNClientSharedKey not implemented")} + } + if v.beginResetVPNClientSharedKey == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resetvpnclientsharedkey` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginResetVPNClientSharedKey(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginResetVPNClientSharedKey = &respr + } + + resp, err := server.PollerResponderNext(v.beginResetVPNClientSharedKey, 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.beginResetVPNClientSharedKey) { + v.beginResetVPNClientSharedKey = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginSetVpnclientIPSecParameters(req *http.Request) (*http.Response, error) { + if v.srv.BeginSetVpnclientIPSecParameters == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginSetVpnclientIPSecParameters not implemented")} + } + if v.beginSetVpnclientIPSecParameters == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/setvpnclientipsecparameters` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNClientIPsecParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginSetVpnclientIPSecParameters(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginSetVpnclientIPSecParameters = &respr + } + + resp, err := server.PollerResponderNext(v.beginSetVpnclientIPSecParameters, 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.beginSetVpnclientIPSecParameters) { + v.beginSetVpnclientIPSecParameters = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginStartPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStartPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStartPacketCapture not implemented")} + } + if v.beginStartPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/startPacketCapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNPacketCaptureStartParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VirtualNetworkGatewaysClientBeginStartPacketCaptureOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VirtualNetworkGatewaysClientBeginStartPacketCaptureOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginStartPacketCapture(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStartPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStartPacketCapture, 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.beginStartPacketCapture) { + v.beginStartPacketCapture = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginStopPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStopPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStopPacketCapture not implemented")} + } + if v.beginStopPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stopPacketCapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNPacketCaptureStopParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginStopPacketCapture(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStopPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStopPacketCapture, 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.beginStopPacketCapture) { + v.beginStopPacketCapture = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchSupportedVPNDevices(req *http.Request) (*http.Response, error) { + if v.srv.SupportedVPNDevices == nil { + return nil, &nonRetriableError{errors.New("fake for method SupportedVPNDevices not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/supportedvpndevices` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.SupportedVPNDevices(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, 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).Value, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if v.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdateTags, 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.beginUpdateTags) { + v.beginUpdateTags = nil + } + + return resp, nil +} + +func (v *VirtualNetworkGatewaysServerTransport) dispatchVPNDeviceConfigurationScript(req *http.Request) (*http.Response, error) { + if v.srv.VPNDeviceConfigurationScript == nil { + return nil, &nonRetriableError{errors.New("fake for method VPNDeviceConfigurationScript not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/connections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpndeviceconfigurationscript` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNDeviceScriptParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkGatewayConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkGatewayConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.VPNDeviceConfigurationScript(req.Context(), resourceGroupNameUnescaped, virtualNetworkGatewayConnectionNameUnescaped, 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).Value, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkpeerings_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkpeerings_server.go new file mode 100644 index 000000000000..37dcfd36fc73 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworkpeerings_server.go @@ -0,0 +1,270 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualNetworkPeeringsServer is a fake server for instances of the armnetwork.VirtualNetworkPeeringsClient type. +type VirtualNetworkPeeringsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualNetworkPeeringsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, virtualNetworkPeeringParameters armnetwork.VirtualNetworkPeering, options *armnetwork.VirtualNetworkPeeringsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkPeeringsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualNetworkPeeringsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, options *armnetwork.VirtualNetworkPeeringsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkPeeringsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualNetworkPeeringsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, options *armnetwork.VirtualNetworkPeeringsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualNetworkPeeringsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualNetworkPeeringsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualNetworkName string, options *armnetwork.VirtualNetworkPeeringsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkPeeringsClientListResponse]) +} + +// NewVirtualNetworkPeeringsServerTransport creates a new instance of VirtualNetworkPeeringsServerTransport with the provided implementation. +// The returned VirtualNetworkPeeringsServerTransport instance is connected to an instance of armnetwork.VirtualNetworkPeeringsClient by way of the +// undefined.Transporter field. +func NewVirtualNetworkPeeringsServerTransport(srv *VirtualNetworkPeeringsServer) *VirtualNetworkPeeringsServerTransport { + return &VirtualNetworkPeeringsServerTransport{srv: srv} +} + +// VirtualNetworkPeeringsServerTransport connects instances of armnetwork.VirtualNetworkPeeringsClient to instances of VirtualNetworkPeeringsServer. +// Don't use this type directly, use NewVirtualNetworkPeeringsServerTransport instead. +type VirtualNetworkPeeringsServerTransport struct { + srv *VirtualNetworkPeeringsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualNetworkPeeringsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualNetworkPeeringsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualNetworkPeeringsClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualNetworkPeeringsServerTransport. +func (v *VirtualNetworkPeeringsServerTransport) 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 "VirtualNetworkPeeringsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualNetworkPeeringsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualNetworkPeeringsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualNetworkPeeringsClient.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 *VirtualNetworkPeeringsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualNetworkPeerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualNetworkPeering](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + virtualNetworkPeeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkPeeringName")]) + if err != nil { + return nil, err + } + syncRemoteAddressSpaceUnescaped, err := url.QueryUnescape(qp.Get("syncRemoteAddressSpace")) + if err != nil { + return nil, err + } + syncRemoteAddressSpaceParam := getOptional(armnetwork.SyncRemoteAddressSpace(syncRemoteAddressSpaceUnescaped)) + var options *armnetwork.VirtualNetworkPeeringsClientBeginCreateOrUpdateOptions + if syncRemoteAddressSpaceParam != nil { + options = &armnetwork.VirtualNetworkPeeringsClientBeginCreateOrUpdateOptions{ + SyncRemoteAddressSpace: syncRemoteAddressSpaceParam, + } + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, virtualNetworkPeeringNameUnescaped, body, options) + 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 *VirtualNetworkPeeringsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualNetworkPeerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + virtualNetworkPeeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkPeeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, virtualNetworkPeeringNameUnescaped, 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 *VirtualNetworkPeeringsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualNetworkPeerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + virtualNetworkPeeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkPeeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, virtualNetworkPeeringNameUnescaped, 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).VirtualNetworkPeering, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkPeeringsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/virtualNetworkPeerings` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, virtualNetworkNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualNetworkPeeringsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualnetworks_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworks_server.go new file mode 100644 index 000000000000..accaa21f8d90 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworks_server.go @@ -0,0 +1,499 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// VirtualNetworksServer is a fake server for instances of the armnetwork.VirtualNetworksClient type. +type VirtualNetworksServer struct { + // CheckIPAddressAvailability is the fake for method VirtualNetworksClient.CheckIPAddressAvailability + // HTTP status codes to indicate success: http.StatusOK + CheckIPAddressAvailability func(ctx context.Context, resourceGroupName string, virtualNetworkName string, ipAddress string, options *armnetwork.VirtualNetworksClientCheckIPAddressAvailabilityOptions) (resp azfake.Responder[armnetwork.VirtualNetworksClientCheckIPAddressAvailabilityResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method VirtualNetworksClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters armnetwork.VirtualNetwork, options *armnetwork.VirtualNetworksClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworksClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualNetworksClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *armnetwork.VirtualNetworksClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworksClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualNetworksClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *armnetwork.VirtualNetworksClientGetOptions) (resp azfake.Responder[armnetwork.VirtualNetworksClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualNetworksClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.VirtualNetworksClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworksClientListResponse]) + + // NewListAllPager is the fake for method VirtualNetworksClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.VirtualNetworksClientListAllOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworksClientListAllResponse]) + + // BeginListDdosProtectionStatus is the fake for method VirtualNetworksClient.BeginListDdosProtectionStatus + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListDdosProtectionStatus func(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *armnetwork.VirtualNetworksClientBeginListDdosProtectionStatusOptions) (resp azfake.PollerResponder[azfake.PagerResponder[armnetwork.VirtualNetworksClientListDdosProtectionStatusResponse]], errResp azfake.ErrorResponder) + + // NewListUsagePager is the fake for method VirtualNetworksClient.NewListUsagePager + // HTTP status codes to indicate success: http.StatusOK + NewListUsagePager func(resourceGroupName string, virtualNetworkName string, options *armnetwork.VirtualNetworksClientListUsageOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworksClientListUsageResponse]) + + // UpdateTags is the fake for method VirtualNetworksClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters armnetwork.TagsObject, options *armnetwork.VirtualNetworksClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VirtualNetworksClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualNetworksServerTransport creates a new instance of VirtualNetworksServerTransport with the provided implementation. +// The returned VirtualNetworksServerTransport instance is connected to an instance of armnetwork.VirtualNetworksClient by way of the +// undefined.Transporter field. +func NewVirtualNetworksServerTransport(srv *VirtualNetworksServer) *VirtualNetworksServerTransport { + return &VirtualNetworksServerTransport{srv: srv} +} + +// VirtualNetworksServerTransport connects instances of armnetwork.VirtualNetworksClient to instances of VirtualNetworksServer. +// Don't use this type directly, use NewVirtualNetworksServerTransport instead. +type VirtualNetworksServerTransport struct { + srv *VirtualNetworksServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualNetworksClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualNetworksClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualNetworksClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.VirtualNetworksClientListAllResponse] + beginListDdosProtectionStatus *azfake.PollerResponder[azfake.PagerResponder[armnetwork.VirtualNetworksClientListDdosProtectionStatusResponse]] + newListUsagePager *azfake.PagerResponder[armnetwork.VirtualNetworksClientListUsageResponse] +} + +// Do implements the policy.Transporter interface for VirtualNetworksServerTransport. +func (v *VirtualNetworksServerTransport) 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 "VirtualNetworksClient.CheckIPAddressAvailability": + resp, err = v.dispatchCheckIPAddressAvailability(req) + case "VirtualNetworksClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualNetworksClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualNetworksClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualNetworksClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualNetworksClient.NewListAllPager": + resp, err = v.dispatchNewListAllPager(req) + case "VirtualNetworksClient.BeginListDdosProtectionStatus": + resp, err = v.dispatchBeginListDdosProtectionStatus(req) + case "VirtualNetworksClient.NewListUsagePager": + resp, err = v.dispatchNewListUsagePager(req) + case "VirtualNetworksClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualNetworksServerTransport) dispatchCheckIPAddressAvailability(req *http.Request) (*http.Response, error) { + if v.srv.CheckIPAddressAvailability == nil { + return nil, &nonRetriableError{errors.New("fake for method CheckIPAddressAvailability not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/CheckIPAddressAvailability` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + ipAddressUnescaped, err := url.QueryUnescape(qp.Get("ipAddress")) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.CheckIPAddressAvailability(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, ipAddressUnescaped, 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).IPAddressAvailabilityResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworksServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualNetwork](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, 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 *VirtualNetworksServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, 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 *VirtualNetworksServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.VirtualNetworksClientGetOptions + if expandParam != nil { + options = &armnetwork.VirtualNetworksClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, 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).VirtualNetwork, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworksServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualNetworks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + 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 *armnetwork.VirtualNetworksClientListResponse, 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 *VirtualNetworksServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListAllPager == nil { + 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.Network/virtualNetworks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.VirtualNetworksClientListAllResponse, 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 *VirtualNetworksServerTransport) dispatchBeginListDdosProtectionStatus(req *http.Request) (*http.Response, error) { + if v.srv.BeginListDdosProtectionStatus == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListDdosProtectionStatus not implemented")} + } + if v.beginListDdosProtectionStatus == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ddosProtectionStatus` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armnetwork.VirtualNetworksClientBeginListDdosProtectionStatusOptions + if topParam != nil || skipTokenParam != nil { + options = &armnetwork.VirtualNetworksClientBeginListDdosProtectionStatusOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + respr, errRespr := v.srv.BeginListDdosProtectionStatus(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginListDdosProtectionStatus = &respr + } + + resp, err := server.PollerResponderNext(v.beginListDdosProtectionStatus, 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.beginListDdosProtectionStatus) { + v.beginListDdosProtectionStatus = nil + } + + return resp, nil +} + +func (v *VirtualNetworksServerTransport) dispatchNewListUsagePager(req *http.Request) (*http.Response, error) { + if v.srv.NewListUsagePager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListUsagePager not implemented")} + } + if v.newListUsagePager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/usages` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListUsagePager(resourceGroupNameUnescaped, virtualNetworkNameUnescaped, nil) + v.newListUsagePager = &resp + server.PagerResponderInjectNextLinks(v.newListUsagePager, req, func(page *armnetwork.VirtualNetworksClientListUsageResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListUsagePager, 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.newListUsagePager) { + v.newListUsagePager = nil + } + return resp, nil +} + +func (v *VirtualNetworksServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualNetworkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, virtualNetworkNameUnescaped, 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).VirtualNetwork, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualnetworktaps_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworktaps_server.go new file mode 100644 index 000000000000..7381ba1ebe08 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualnetworktaps_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualNetworkTapsServer is a fake server for instances of the armnetwork.VirtualNetworkTapsClient type. +type VirtualNetworkTapsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualNetworkTapsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, tapName string, parameters armnetwork.VirtualNetworkTap, options *armnetwork.VirtualNetworkTapsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkTapsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualNetworkTapsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, tapName string, options *armnetwork.VirtualNetworkTapsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualNetworkTapsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualNetworkTapsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, tapName string, options *armnetwork.VirtualNetworkTapsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualNetworkTapsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListAllPager is the fake for method VirtualNetworkTapsClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.VirtualNetworkTapsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkTapsClientListAllResponse]) + + // NewListByResourceGroupPager is the fake for method VirtualNetworkTapsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VirtualNetworkTapsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VirtualNetworkTapsClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method VirtualNetworkTapsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, tapName string, tapParameters armnetwork.TagsObject, options *armnetwork.VirtualNetworkTapsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VirtualNetworkTapsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualNetworkTapsServerTransport creates a new instance of VirtualNetworkTapsServerTransport with the provided implementation. +// The returned VirtualNetworkTapsServerTransport instance is connected to an instance of armnetwork.VirtualNetworkTapsClient by way of the +// undefined.Transporter field. +func NewVirtualNetworkTapsServerTransport(srv *VirtualNetworkTapsServer) *VirtualNetworkTapsServerTransport { + return &VirtualNetworkTapsServerTransport{srv: srv} +} + +// VirtualNetworkTapsServerTransport connects instances of armnetwork.VirtualNetworkTapsClient to instances of VirtualNetworkTapsServer. +// Don't use this type directly, use NewVirtualNetworkTapsServerTransport instead. +type VirtualNetworkTapsServerTransport struct { + srv *VirtualNetworkTapsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualNetworkTapsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualNetworkTapsClientDeleteResponse] + newListAllPager *azfake.PagerResponder[armnetwork.VirtualNetworkTapsClientListAllResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VirtualNetworkTapsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VirtualNetworkTapsServerTransport. +func (v *VirtualNetworkTapsServerTransport) 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 "VirtualNetworkTapsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualNetworkTapsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualNetworkTapsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualNetworkTapsClient.NewListAllPager": + resp, err = v.dispatchNewListAllPager(req) + case "VirtualNetworkTapsClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VirtualNetworkTapsClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualNetworkTapsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualNetworkTaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualNetworkTap](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + tapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, tapNameUnescaped, 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 *VirtualNetworkTapsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualNetworkTaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + tapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, tapNameUnescaped, 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 *VirtualNetworkTapsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualNetworkTaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + tapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, tapNameUnescaped, 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).VirtualNetworkTap, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualNetworkTapsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListAllPager == nil { + 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.Network/virtualNetworkTaps` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + 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 *armnetwork.VirtualNetworkTapsClientListAllResponse, 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 *VirtualNetworkTapsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkTaps` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VirtualNetworkTapsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VirtualNetworkTapsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualNetworkTaps/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + tapNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tapName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, tapNameUnescaped, 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).VirtualNetworkTap, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualrouterpeerings_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualrouterpeerings_server.go new file mode 100644 index 000000000000..b628cb6f3a7d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualrouterpeerings_server.go @@ -0,0 +1,258 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualRouterPeeringsServer is a fake server for instances of the armnetwork.VirtualRouterPeeringsClient type. +type VirtualRouterPeeringsServer struct { + // BeginCreateOrUpdate is the fake for method VirtualRouterPeeringsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, parameters armnetwork.VirtualRouterPeering, options *armnetwork.VirtualRouterPeeringsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualRouterPeeringsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualRouterPeeringsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, options *armnetwork.VirtualRouterPeeringsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualRouterPeeringsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualRouterPeeringsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, options *armnetwork.VirtualRouterPeeringsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualRouterPeeringsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualRouterPeeringsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, virtualRouterName string, options *armnetwork.VirtualRouterPeeringsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualRouterPeeringsClientListResponse]) +} + +// NewVirtualRouterPeeringsServerTransport creates a new instance of VirtualRouterPeeringsServerTransport with the provided implementation. +// The returned VirtualRouterPeeringsServerTransport instance is connected to an instance of armnetwork.VirtualRouterPeeringsClient by way of the +// undefined.Transporter field. +func NewVirtualRouterPeeringsServerTransport(srv *VirtualRouterPeeringsServer) *VirtualRouterPeeringsServerTransport { + return &VirtualRouterPeeringsServerTransport{srv: srv} +} + +// VirtualRouterPeeringsServerTransport connects instances of armnetwork.VirtualRouterPeeringsClient to instances of VirtualRouterPeeringsServer. +// Don't use this type directly, use NewVirtualRouterPeeringsServerTransport instead. +type VirtualRouterPeeringsServerTransport struct { + srv *VirtualRouterPeeringsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualRouterPeeringsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualRouterPeeringsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualRouterPeeringsClientListResponse] +} + +// Do implements the policy.Transporter interface for VirtualRouterPeeringsServerTransport. +func (v *VirtualRouterPeeringsServerTransport) 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 "VirtualRouterPeeringsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualRouterPeeringsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualRouterPeeringsClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualRouterPeeringsClient.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 *VirtualRouterPeeringsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualRouterPeering](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualRouterNameUnescaped, peeringNameUnescaped, 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 *VirtualRouterPeeringsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualRouterNameUnescaped, peeringNameUnescaped, 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 *VirtualRouterPeeringsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + peeringNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("peeringName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualRouterNameUnescaped, peeringNameUnescaped, 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).VirtualRouterPeering, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualRouterPeeringsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/peerings` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(resourceGroupNameUnescaped, virtualRouterNameUnescaped, nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualRouterPeeringsClientListResponse, 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 +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualrouters_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualrouters_server.go new file mode 100644 index 000000000000..b6daf691a24b --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualrouters_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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualRoutersServer is a fake server for instances of the armnetwork.VirtualRoutersClient type. +type VirtualRoutersServer struct { + // BeginCreateOrUpdate is the fake for method VirtualRoutersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualRouterName string, parameters armnetwork.VirtualRouter, options *armnetwork.VirtualRoutersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualRoutersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualRoutersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualRouterName string, options *armnetwork.VirtualRoutersClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualRoutersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualRoutersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualRouterName string, options *armnetwork.VirtualRoutersClientGetOptions) (resp azfake.Responder[armnetwork.VirtualRoutersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualRoutersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VirtualRoutersClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualRoutersClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VirtualRoutersClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VirtualRoutersClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VirtualRoutersClientListByResourceGroupResponse]) +} + +// NewVirtualRoutersServerTransport creates a new instance of VirtualRoutersServerTransport with the provided implementation. +// The returned VirtualRoutersServerTransport instance is connected to an instance of armnetwork.VirtualRoutersClient by way of the +// undefined.Transporter field. +func NewVirtualRoutersServerTransport(srv *VirtualRoutersServer) *VirtualRoutersServerTransport { + return &VirtualRoutersServerTransport{srv: srv} +} + +// VirtualRoutersServerTransport connects instances of armnetwork.VirtualRoutersClient to instances of VirtualRoutersServer. +// Don't use this type directly, use NewVirtualRoutersServerTransport instead. +type VirtualRoutersServerTransport struct { + srv *VirtualRoutersServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualRoutersClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualRoutersClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualRoutersClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VirtualRoutersClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VirtualRoutersServerTransport. +func (v *VirtualRoutersServerTransport) 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 "VirtualRoutersClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualRoutersClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualRoutersClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualRoutersClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualRoutersClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualRoutersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualRouter](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualRouterNameUnescaped, 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 *VirtualRoutersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualRouterNameUnescaped, 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 *VirtualRoutersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualRouters/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualRouterNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualRouterName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.VirtualRoutersClientGetOptions + if expandParam != nil { + options = &armnetwork.VirtualRoutersClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualRouterNameUnescaped, 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).VirtualRouter, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualRoutersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualRouters` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualRoutersClientListResponse, 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 *VirtualRoutersServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualRouters` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VirtualRoutersClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/virtualwans_server.go b/sdk/resourcemanager/network/armnetwork/fake/virtualwans_server.go new file mode 100644 index 000000000000..416a8b75e406 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/virtualwans_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VirtualWansServer is a fake server for instances of the armnetwork.VirtualWansClient type. +type VirtualWansServer struct { + // BeginCreateOrUpdate is the fake for method VirtualWansClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualWANName string, wanParameters armnetwork.VirtualWAN, options *armnetwork.VirtualWansClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualWansClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VirtualWansClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, virtualWANName string, options *armnetwork.VirtualWansClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualWansClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VirtualWansClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, virtualWANName string, options *armnetwork.VirtualWansClientGetOptions) (resp azfake.Responder[armnetwork.VirtualWansClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VirtualWansClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VirtualWansClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualWansClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VirtualWansClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VirtualWansClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VirtualWansClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method VirtualWansClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, virtualWANName string, wanParameters armnetwork.TagsObject, options *armnetwork.VirtualWansClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VirtualWansClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVirtualWansServerTransport creates a new instance of VirtualWansServerTransport with the provided implementation. +// The returned VirtualWansServerTransport instance is connected to an instance of armnetwork.VirtualWansClient by way of the +// undefined.Transporter field. +func NewVirtualWansServerTransport(srv *VirtualWansServer) *VirtualWansServerTransport { + return &VirtualWansServerTransport{srv: srv} +} + +// VirtualWansServerTransport connects instances of armnetwork.VirtualWansClient to instances of VirtualWansServer. +// Don't use this type directly, use NewVirtualWansServerTransport instead. +type VirtualWansServerTransport struct { + srv *VirtualWansServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VirtualWansClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VirtualWansClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VirtualWansClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VirtualWansClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VirtualWansServerTransport. +func (v *VirtualWansServerTransport) 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 "VirtualWansClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VirtualWansClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VirtualWansClient.Get": + resp, err = v.dispatchGet(req) + case "VirtualWansClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VirtualWansClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VirtualWansClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VirtualWansServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualWAN](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("VirtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, 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 *VirtualWansServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("VirtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, 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 *VirtualWansServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("VirtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, 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).VirtualWAN, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VirtualWansServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/virtualWans` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VirtualWansClientListResponse, 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 *VirtualWansServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualWans` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VirtualWansClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VirtualWansServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("VirtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, 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).VirtualWAN, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnconnections_server.go new file mode 100644 index 000000000000..d92458e51ae3 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnconnections_server.go @@ -0,0 +1,383 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// VPNConnectionsServer is a fake server for instances of the armnetwork.VPNConnectionsClient type. +type VPNConnectionsServer struct { + // BeginCreateOrUpdate is the fake for method VPNConnectionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters armnetwork.VPNConnection, options *armnetwork.VPNConnectionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VPNConnectionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *armnetwork.VPNConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VPNConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *armnetwork.VPNConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.VPNConnectionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByVPNGatewayPager is the fake for method VPNConnectionsClient.NewListByVPNGatewayPager + // HTTP status codes to indicate success: http.StatusOK + NewListByVPNGatewayPager func(resourceGroupName string, gatewayName string, options *armnetwork.VPNConnectionsClientListByVPNGatewayOptions) (resp azfake.PagerResponder[armnetwork.VPNConnectionsClientListByVPNGatewayResponse]) + + // BeginStartPacketCapture is the fake for method VPNConnectionsClient.BeginStartPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStartPacketCapture func(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *armnetwork.VPNConnectionsClientBeginStartPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientStartPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginStopPacketCapture is the fake for method VPNConnectionsClient.BeginStopPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStopPacketCapture func(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *armnetwork.VPNConnectionsClientBeginStopPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientStopPacketCaptureResponse], errResp azfake.ErrorResponder) +} + +// NewVPNConnectionsServerTransport creates a new instance of VPNConnectionsServerTransport with the provided implementation. +// The returned VPNConnectionsServerTransport instance is connected to an instance of armnetwork.VPNConnectionsClient by way of the +// undefined.Transporter field. +func NewVPNConnectionsServerTransport(srv *VPNConnectionsServer) *VPNConnectionsServerTransport { + return &VPNConnectionsServerTransport{srv: srv} +} + +// VPNConnectionsServerTransport connects instances of armnetwork.VPNConnectionsClient to instances of VPNConnectionsServer. +// Don't use this type directly, use NewVPNConnectionsServerTransport instead. +type VPNConnectionsServerTransport struct { + srv *VPNConnectionsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VPNConnectionsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VPNConnectionsClientDeleteResponse] + newListByVPNGatewayPager *azfake.PagerResponder[armnetwork.VPNConnectionsClientListByVPNGatewayResponse] + beginStartPacketCapture *azfake.PollerResponder[armnetwork.VPNConnectionsClientStartPacketCaptureResponse] + beginStopPacketCapture *azfake.PollerResponder[armnetwork.VPNConnectionsClientStopPacketCaptureResponse] +} + +// Do implements the policy.Transporter interface for VPNConnectionsServerTransport. +func (v *VPNConnectionsServerTransport) 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 "VPNConnectionsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VPNConnectionsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VPNConnectionsClient.Get": + resp, err = v.dispatchGet(req) + case "VPNConnectionsClient.NewListByVPNGatewayPager": + resp, err = v.dispatchNewListByVPNGatewayPager(req) + case "VPNConnectionsClient.BeginStartPacketCapture": + resp, err = v.dispatchBeginStartPacketCapture(req) + case "VPNConnectionsClient.BeginStopPacketCapture": + resp, err = v.dispatchBeginStopPacketCapture(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNConnection](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, 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 *VPNConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, 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 *VPNConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, 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).VPNConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VPNConnectionsServerTransport) dispatchNewListByVPNGatewayPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByVPNGatewayPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByVPNGatewayPager not implemented")} + } + if v.newListByVPNGatewayPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByVPNGatewayPager(resourceGroupNameUnescaped, gatewayNameUnescaped, nil) + v.newListByVPNGatewayPager = &resp + server.PagerResponderInjectNextLinks(v.newListByVPNGatewayPager, req, func(page *armnetwork.VPNConnectionsClientListByVPNGatewayResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByVPNGatewayPager, 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.newListByVPNGatewayPager) { + v.newListByVPNGatewayPager = nil + } + return resp, nil +} + +func (v *VPNConnectionsServerTransport) dispatchBeginStartPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStartPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStartPacketCapture not implemented")} + } + if v.beginStartPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/startpacketcapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNConnectionPacketCaptureStartParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + vpnConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnConnectionName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VPNConnectionsClientBeginStartPacketCaptureOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VPNConnectionsClientBeginStartPacketCaptureOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginStartPacketCapture(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, vpnConnectionNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStartPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStartPacketCapture, 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.beginStartPacketCapture) { + v.beginStartPacketCapture = nil + } + + return resp, nil +} + +func (v *VPNConnectionsServerTransport) dispatchBeginStopPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStopPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStopPacketCapture not implemented")} + } + if v.beginStopPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stoppacketcapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNConnectionPacketCaptureStopParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + vpnConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnConnectionName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VPNConnectionsClientBeginStopPacketCaptureOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VPNConnectionsClientBeginStopPacketCaptureOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginStopPacketCapture(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, vpnConnectionNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStopPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStopPacketCapture, 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.beginStopPacketCapture) { + v.beginStopPacketCapture = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpngateways_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpngateways_server.go new file mode 100644 index 000000000000..df8c901ecb99 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpngateways_server.go @@ -0,0 +1,508 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// VPNGatewaysServer is a fake server for instances of the armnetwork.VPNGatewaysClient type. +type VPNGatewaysServer struct { + // BeginCreateOrUpdate is the fake for method VPNGatewaysClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters armnetwork.VPNGateway, options *armnetwork.VPNGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VPNGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VPNGatewaysClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.VPNGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VPNGatewaysClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VPNGatewaysClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.VPNGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.VPNGatewaysClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VPNGatewaysClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VPNGatewaysClientListOptions) (resp azfake.PagerResponder[armnetwork.VPNGatewaysClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VPNGatewaysClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VPNGatewaysClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VPNGatewaysClientListByResourceGroupResponse]) + + // BeginReset is the fake for method VPNGatewaysClient.BeginReset + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginReset func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.VPNGatewaysClientBeginResetOptions) (resp azfake.PollerResponder[armnetwork.VPNGatewaysClientResetResponse], errResp azfake.ErrorResponder) + + // BeginStartPacketCapture is the fake for method VPNGatewaysClient.BeginStartPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStartPacketCapture func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.VPNGatewaysClientBeginStartPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VPNGatewaysClientStartPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginStopPacketCapture is the fake for method VPNGatewaysClient.BeginStopPacketCapture + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginStopPacketCapture func(ctx context.Context, resourceGroupName string, gatewayName string, options *armnetwork.VPNGatewaysClientBeginStopPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VPNGatewaysClientStopPacketCaptureResponse], errResp azfake.ErrorResponder) + + // BeginUpdateTags is the fake for method VPNGatewaysClient.BeginUpdateTags + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdateTags func(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters armnetwork.TagsObject, options *armnetwork.VPNGatewaysClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.VPNGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVPNGatewaysServerTransport creates a new instance of VPNGatewaysServerTransport with the provided implementation. +// The returned VPNGatewaysServerTransport instance is connected to an instance of armnetwork.VPNGatewaysClient by way of the +// undefined.Transporter field. +func NewVPNGatewaysServerTransport(srv *VPNGatewaysServer) *VPNGatewaysServerTransport { + return &VPNGatewaysServerTransport{srv: srv} +} + +// VPNGatewaysServerTransport connects instances of armnetwork.VPNGatewaysClient to instances of VPNGatewaysServer. +// Don't use this type directly, use NewVPNGatewaysServerTransport instead. +type VPNGatewaysServerTransport struct { + srv *VPNGatewaysServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VPNGatewaysClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VPNGatewaysClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VPNGatewaysClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VPNGatewaysClientListByResourceGroupResponse] + beginReset *azfake.PollerResponder[armnetwork.VPNGatewaysClientResetResponse] + beginStartPacketCapture *azfake.PollerResponder[armnetwork.VPNGatewaysClientStartPacketCaptureResponse] + beginStopPacketCapture *azfake.PollerResponder[armnetwork.VPNGatewaysClientStopPacketCaptureResponse] + beginUpdateTags *azfake.PollerResponder[armnetwork.VPNGatewaysClientUpdateTagsResponse] +} + +// Do implements the policy.Transporter interface for VPNGatewaysServerTransport. +func (v *VPNGatewaysServerTransport) 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 "VPNGatewaysClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VPNGatewaysClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VPNGatewaysClient.Get": + resp, err = v.dispatchGet(req) + case "VPNGatewaysClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VPNGatewaysClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VPNGatewaysClient.BeginReset": + resp, err = v.dispatchBeginReset(req) + case "VPNGatewaysClient.BeginStartPacketCapture": + resp, err = v.dispatchBeginStartPacketCapture(req) + case "VPNGatewaysClient.BeginStopPacketCapture": + resp, err = v.dispatchBeginStopPacketCapture(req) + case "VPNGatewaysClient.BeginUpdateTags": + resp, err = v.dispatchBeginUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNGateway](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, 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 *VPNGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, 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 *VPNGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, 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).VPNGateway, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VPNGatewaysServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/vpnGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VPNGatewaysClientListResponse, 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 *VPNGatewaysServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VPNGatewaysClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VPNGatewaysServerTransport) dispatchBeginReset(req *http.Request) (*http.Response, error) { + if v.srv.BeginReset == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginReset not implemented")} + } + if v.beginReset == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reset` + regex := regexp.MustCompile(regexStr) + 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() + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + iPConfigurationIDUnescaped, err := url.QueryUnescape(qp.Get("ipConfigurationId")) + if err != nil { + return nil, err + } + iPConfigurationIDParam := getOptional(iPConfigurationIDUnescaped) + var options *armnetwork.VPNGatewaysClientBeginResetOptions + if iPConfigurationIDParam != nil { + options = &armnetwork.VPNGatewaysClientBeginResetOptions{ + IPConfigurationID: iPConfigurationIDParam, + } + } + respr, errRespr := v.srv.BeginReset(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginReset = &respr + } + + resp, err := server.PollerResponderNext(v.beginReset, 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.beginReset) { + v.beginReset = nil + } + + return resp, nil +} + +func (v *VPNGatewaysServerTransport) dispatchBeginStartPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStartPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStartPacketCapture not implemented")} + } + if v.beginStartPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/startpacketcapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNGatewayPacketCaptureStartParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VPNGatewaysClientBeginStartPacketCaptureOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VPNGatewaysClientBeginStartPacketCaptureOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginStartPacketCapture(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStartPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStartPacketCapture, 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.beginStartPacketCapture) { + v.beginStartPacketCapture = nil + } + + return resp, nil +} + +func (v *VPNGatewaysServerTransport) dispatchBeginStopPacketCapture(req *http.Request) (*http.Response, error) { + if v.srv.BeginStopPacketCapture == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginStopPacketCapture not implemented")} + } + if v.beginStopPacketCapture == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stoppacketcapture` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNGatewayPacketCaptureStopParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + var options *armnetwork.VPNGatewaysClientBeginStopPacketCaptureOptions + if !reflect.ValueOf(body).IsZero() { + options = &armnetwork.VPNGatewaysClientBeginStopPacketCaptureOptions{ + Parameters: &body, + } + } + respr, errRespr := v.srv.BeginStopPacketCapture(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginStopPacketCapture = &respr + } + + resp, err := server.PollerResponderNext(v.beginStopPacketCapture, 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.beginStopPacketCapture) { + v.beginStopPacketCapture = nil + } + + return resp, nil +} + +func (v *VPNGatewaysServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.BeginUpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")} + } + if v.beginUpdateTags == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginUpdateTags(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginUpdateTags = &respr + } + + resp, err := server.PollerResponderNext(v.beginUpdateTags, 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.beginUpdateTags) { + v.beginUpdateTags = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnlinkconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnlinkconnections_server.go new file mode 100644 index 000000000000..e44a46ff64b8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnlinkconnections_server.go @@ -0,0 +1,223 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNLinkConnectionsServer is a fake server for instances of the armnetwork.VPNLinkConnectionsClient type. +type VPNLinkConnectionsServer struct { + // BeginGetIkeSas is the fake for method VPNLinkConnectionsClient.BeginGetIkeSas + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetIkeSas func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *armnetwork.VPNLinkConnectionsClientBeginGetIkeSasOptions) (resp azfake.PollerResponder[armnetwork.VPNLinkConnectionsClientGetIkeSasResponse], errResp azfake.ErrorResponder) + + // NewListByVPNConnectionPager is the fake for method VPNLinkConnectionsClient.NewListByVPNConnectionPager + // HTTP status codes to indicate success: http.StatusOK + NewListByVPNConnectionPager func(resourceGroupName string, gatewayName string, connectionName string, options *armnetwork.VPNLinkConnectionsClientListByVPNConnectionOptions) (resp azfake.PagerResponder[armnetwork.VPNLinkConnectionsClientListByVPNConnectionResponse]) + + // BeginResetConnection is the fake for method VPNLinkConnectionsClient.BeginResetConnection + // HTTP status codes to indicate success: http.StatusAccepted + BeginResetConnection func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *armnetwork.VPNLinkConnectionsClientBeginResetConnectionOptions) (resp azfake.PollerResponder[armnetwork.VPNLinkConnectionsClientResetConnectionResponse], errResp azfake.ErrorResponder) +} + +// NewVPNLinkConnectionsServerTransport creates a new instance of VPNLinkConnectionsServerTransport with the provided implementation. +// The returned VPNLinkConnectionsServerTransport instance is connected to an instance of armnetwork.VPNLinkConnectionsClient by way of the +// undefined.Transporter field. +func NewVPNLinkConnectionsServerTransport(srv *VPNLinkConnectionsServer) *VPNLinkConnectionsServerTransport { + return &VPNLinkConnectionsServerTransport{srv: srv} +} + +// VPNLinkConnectionsServerTransport connects instances of armnetwork.VPNLinkConnectionsClient to instances of VPNLinkConnectionsServer. +// Don't use this type directly, use NewVPNLinkConnectionsServerTransport instead. +type VPNLinkConnectionsServerTransport struct { + srv *VPNLinkConnectionsServer + beginGetIkeSas *azfake.PollerResponder[armnetwork.VPNLinkConnectionsClientGetIkeSasResponse] + newListByVPNConnectionPager *azfake.PagerResponder[armnetwork.VPNLinkConnectionsClientListByVPNConnectionResponse] + beginResetConnection *azfake.PollerResponder[armnetwork.VPNLinkConnectionsClientResetConnectionResponse] +} + +// Do implements the policy.Transporter interface for VPNLinkConnectionsServerTransport. +func (v *VPNLinkConnectionsServerTransport) 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 "VPNLinkConnectionsClient.BeginGetIkeSas": + resp, err = v.dispatchBeginGetIkeSas(req) + case "VPNLinkConnectionsClient.NewListByVPNConnectionPager": + resp, err = v.dispatchNewListByVPNConnectionPager(req) + case "VPNLinkConnectionsClient.BeginResetConnection": + resp, err = v.dispatchBeginResetConnection(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNLinkConnectionsServerTransport) dispatchBeginGetIkeSas(req *http.Request) (*http.Response, error) { + if v.srv.BeginGetIkeSas == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetIkeSas not implemented")} + } + if v.beginGetIkeSas == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnLinkConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getikesas` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + linkConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("linkConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginGetIkeSas(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, linkConnectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginGetIkeSas = &respr + } + + resp, err := server.PollerResponderNext(v.beginGetIkeSas, 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.beginGetIkeSas) { + v.beginGetIkeSas = nil + } + + return resp, nil +} + +func (v *VPNLinkConnectionsServerTransport) dispatchNewListByVPNConnectionPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByVPNConnectionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByVPNConnectionPager not implemented")} + } + if v.newListByVPNConnectionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnLinkConnections` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByVPNConnectionPager(resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, nil) + v.newListByVPNConnectionPager = &resp + server.PagerResponderInjectNextLinks(v.newListByVPNConnectionPager, req, func(page *armnetwork.VPNLinkConnectionsClientListByVPNConnectionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByVPNConnectionPager, 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.newListByVPNConnectionPager) { + v.newListByVPNConnectionPager = nil + } + return resp, nil +} + +func (v *VPNLinkConnectionsServerTransport) dispatchBeginResetConnection(req *http.Request) (*http.Response, error) { + if v.srv.BeginResetConnection == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginResetConnection not implemented")} + } + if v.beginResetConnection == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnLinkConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resetconnection` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + linkConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("linkConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginResetConnection(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, linkConnectionNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginResetConnection = &respr + } + + resp, err := server.PollerResponderNext(v.beginResetConnection, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(v.beginResetConnection) { + v.beginResetConnection = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnserverconfigurations_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnserverconfigurations_server.go new file mode 100644 index 000000000000..ce632cacd91c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnserverconfigurations_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNServerConfigurationsServer is a fake server for instances of the armnetwork.VPNServerConfigurationsClient type. +type VPNServerConfigurationsServer struct { + // BeginCreateOrUpdate is the fake for method VPNServerConfigurationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters armnetwork.VPNServerConfiguration, options *armnetwork.VPNServerConfigurationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VPNServerConfigurationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VPNServerConfigurationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *armnetwork.VPNServerConfigurationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VPNServerConfigurationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VPNServerConfigurationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *armnetwork.VPNServerConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.VPNServerConfigurationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VPNServerConfigurationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VPNServerConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.VPNServerConfigurationsClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VPNServerConfigurationsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VPNServerConfigurationsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VPNServerConfigurationsClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method VPNServerConfigurationsClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters armnetwork.TagsObject, options *armnetwork.VPNServerConfigurationsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VPNServerConfigurationsClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVPNServerConfigurationsServerTransport creates a new instance of VPNServerConfigurationsServerTransport with the provided implementation. +// The returned VPNServerConfigurationsServerTransport instance is connected to an instance of armnetwork.VPNServerConfigurationsClient by way of the +// undefined.Transporter field. +func NewVPNServerConfigurationsServerTransport(srv *VPNServerConfigurationsServer) *VPNServerConfigurationsServerTransport { + return &VPNServerConfigurationsServerTransport{srv: srv} +} + +// VPNServerConfigurationsServerTransport connects instances of armnetwork.VPNServerConfigurationsClient to instances of VPNServerConfigurationsServer. +// Don't use this type directly, use NewVPNServerConfigurationsServerTransport instead. +type VPNServerConfigurationsServerTransport struct { + srv *VPNServerConfigurationsServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VPNServerConfigurationsClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VPNServerConfigurationsClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VPNServerConfigurationsClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VPNServerConfigurationsClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VPNServerConfigurationsServerTransport. +func (v *VPNServerConfigurationsServerTransport) 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 "VPNServerConfigurationsClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VPNServerConfigurationsClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VPNServerConfigurationsClient.Get": + resp, err = v.dispatchGet(req) + case "VPNServerConfigurationsClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VPNServerConfigurationsClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VPNServerConfigurationsClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNServerConfigurationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNServerConfiguration](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, 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 *VPNServerConfigurationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, 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 *VPNServerConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, 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).VPNServerConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VPNServerConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/vpnServerConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VPNServerConfigurationsClientListResponse, 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 *VPNServerConfigurationsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnServerConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VPNServerConfigurationsClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VPNServerConfigurationsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnServerConfigurations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnServerConfigurationNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnServerConfigurationName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, vpnServerConfigurationNameUnescaped, 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).VPNServerConfiguration, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnserverconfigurationsassociatedwithvirtualwan_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnserverconfigurationsassociatedwithvirtualwan_server.go new file mode 100644 index 000000000000..f00fad417b1d --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnserverconfigurationsassociatedwithvirtualwan_server.go @@ -0,0 +1,109 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNServerConfigurationsAssociatedWithVirtualWanServer is a fake server for instances of the armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClient type. +type VPNServerConfigurationsAssociatedWithVirtualWanServer struct { + // BeginList is the fake for method VPNServerConfigurationsAssociatedWithVirtualWanClient.BeginList + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginList func(ctx context.Context, resourceGroupName string, virtualWANName string, options *armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientBeginListOptions) (resp azfake.PollerResponder[armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse], errResp azfake.ErrorResponder) +} + +// NewVPNServerConfigurationsAssociatedWithVirtualWanServerTransport creates a new instance of VPNServerConfigurationsAssociatedWithVirtualWanServerTransport with the provided implementation. +// The returned VPNServerConfigurationsAssociatedWithVirtualWanServerTransport instance is connected to an instance of armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClient by way of the +// undefined.Transporter field. +func NewVPNServerConfigurationsAssociatedWithVirtualWanServerTransport(srv *VPNServerConfigurationsAssociatedWithVirtualWanServer) *VPNServerConfigurationsAssociatedWithVirtualWanServerTransport { + return &VPNServerConfigurationsAssociatedWithVirtualWanServerTransport{srv: srv} +} + +// VPNServerConfigurationsAssociatedWithVirtualWanServerTransport connects instances of armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClient to instances of VPNServerConfigurationsAssociatedWithVirtualWanServer. +// Don't use this type directly, use NewVPNServerConfigurationsAssociatedWithVirtualWanServerTransport instead. +type VPNServerConfigurationsAssociatedWithVirtualWanServerTransport struct { + srv *VPNServerConfigurationsAssociatedWithVirtualWanServer + beginList *azfake.PollerResponder[armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse] +} + +// Do implements the policy.Transporter interface for VPNServerConfigurationsAssociatedWithVirtualWanServerTransport. +func (v *VPNServerConfigurationsAssociatedWithVirtualWanServerTransport) 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 "VPNServerConfigurationsAssociatedWithVirtualWanClient.BeginList": + resp, err = v.dispatchBeginList(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNServerConfigurationsAssociatedWithVirtualWanServerTransport) dispatchBeginList(req *http.Request) (*http.Response, error) { + if v.srv.BeginList == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginList not implemented")} + } + if v.beginList == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnServerConfigurations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginList(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginList = &respr + } + + resp, err := server.PollerResponderNext(v.beginList, 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.beginList) { + v.beginList = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnsitelinkconnections_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnsitelinkconnections_server.go new file mode 100644 index 000000000000..123c0a135c65 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnsitelinkconnections_server.go @@ -0,0 +1,108 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNSiteLinkConnectionsServer is a fake server for instances of the armnetwork.VPNSiteLinkConnectionsClient type. +type VPNSiteLinkConnectionsServer struct { + // Get is the fake for method VPNSiteLinkConnectionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *armnetwork.VPNSiteLinkConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.VPNSiteLinkConnectionsClientGetResponse], errResp azfake.ErrorResponder) +} + +// NewVPNSiteLinkConnectionsServerTransport creates a new instance of VPNSiteLinkConnectionsServerTransport with the provided implementation. +// The returned VPNSiteLinkConnectionsServerTransport instance is connected to an instance of armnetwork.VPNSiteLinkConnectionsClient by way of the +// undefined.Transporter field. +func NewVPNSiteLinkConnectionsServerTransport(srv *VPNSiteLinkConnectionsServer) *VPNSiteLinkConnectionsServerTransport { + return &VPNSiteLinkConnectionsServerTransport{srv: srv} +} + +// VPNSiteLinkConnectionsServerTransport connects instances of armnetwork.VPNSiteLinkConnectionsClient to instances of VPNSiteLinkConnectionsServer. +// Don't use this type directly, use NewVPNSiteLinkConnectionsServerTransport instead. +type VPNSiteLinkConnectionsServerTransport struct { + srv *VPNSiteLinkConnectionsServer +} + +// Do implements the policy.Transporter interface for VPNSiteLinkConnectionsServerTransport. +func (v *VPNSiteLinkConnectionsServerTransport) 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 "VPNSiteLinkConnectionsClient.Get": + resp, err = v.dispatchGet(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNSiteLinkConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/vpnGateways/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnLinkConnections/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + gatewayNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) + if err != nil { + return nil, err + } + connectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) + if err != nil { + return nil, err + } + linkConnectionNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("linkConnectionName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, gatewayNameUnescaped, connectionNameUnescaped, linkConnectionNameUnescaped, 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).VPNSiteLinkConnection, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnsitelinks_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnsitelinks_server.go new file mode 100644 index 000000000000..fe8b4d76f325 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnsitelinks_server.go @@ -0,0 +1,150 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNSiteLinksServer is a fake server for instances of the armnetwork.VPNSiteLinksClient type. +type VPNSiteLinksServer struct { + // Get is the fake for method VPNSiteLinksClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteLinkName string, options *armnetwork.VPNSiteLinksClientGetOptions) (resp azfake.Responder[armnetwork.VPNSiteLinksClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByVPNSitePager is the fake for method VPNSiteLinksClient.NewListByVPNSitePager + // HTTP status codes to indicate success: http.StatusOK + NewListByVPNSitePager func(resourceGroupName string, vpnSiteName string, options *armnetwork.VPNSiteLinksClientListByVPNSiteOptions) (resp azfake.PagerResponder[armnetwork.VPNSiteLinksClientListByVPNSiteResponse]) +} + +// NewVPNSiteLinksServerTransport creates a new instance of VPNSiteLinksServerTransport with the provided implementation. +// The returned VPNSiteLinksServerTransport instance is connected to an instance of armnetwork.VPNSiteLinksClient by way of the +// undefined.Transporter field. +func NewVPNSiteLinksServerTransport(srv *VPNSiteLinksServer) *VPNSiteLinksServerTransport { + return &VPNSiteLinksServerTransport{srv: srv} +} + +// VPNSiteLinksServerTransport connects instances of armnetwork.VPNSiteLinksClient to instances of VPNSiteLinksServer. +// Don't use this type directly, use NewVPNSiteLinksServerTransport instead. +type VPNSiteLinksServerTransport struct { + srv *VPNSiteLinksServer + newListByVPNSitePager *azfake.PagerResponder[armnetwork.VPNSiteLinksClientListByVPNSiteResponse] +} + +// Do implements the policy.Transporter interface for VPNSiteLinksServerTransport. +func (v *VPNSiteLinksServerTransport) 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 "VPNSiteLinksClient.Get": + resp, err = v.dispatchGet(req) + case "VPNSiteLinksClient.NewListByVPNSitePager": + resp, err = v.dispatchNewListByVPNSitePager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNSiteLinksServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/vpnSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnSiteLinks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnSiteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteName")]) + if err != nil { + return nil, err + } + vpnSiteLinkNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteLinkName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vpnSiteNameUnescaped, vpnSiteLinkNameUnescaped, 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).VPNSiteLink, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VPNSiteLinksServerTransport) dispatchNewListByVPNSitePager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByVPNSitePager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByVPNSitePager not implemented")} + } + if v.newListByVPNSitePager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnSiteLinks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnSiteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByVPNSitePager(resourceGroupNameUnescaped, vpnSiteNameUnescaped, nil) + v.newListByVPNSitePager = &resp + server.PagerResponderInjectNextLinks(v.newListByVPNSitePager, req, func(page *armnetwork.VPNSiteLinksClientListByVPNSiteResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.newListByVPNSitePager, 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.newListByVPNSitePager) { + v.newListByVPNSitePager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnsites_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnsites_server.go new file mode 100644 index 000000000000..449ae6b03668 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnsites_server.go @@ -0,0 +1,322 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNSitesServer is a fake server for instances of the armnetwork.VPNSitesClient type. +type VPNSitesServer struct { + // BeginCreateOrUpdate is the fake for method VPNSitesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteParameters armnetwork.VPNSite, options *armnetwork.VPNSitesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VPNSitesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method VPNSitesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, vpnSiteName string, options *armnetwork.VPNSitesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VPNSitesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VPNSitesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, vpnSiteName string, options *armnetwork.VPNSitesClientGetOptions) (resp azfake.Responder[armnetwork.VPNSitesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VPNSitesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armnetwork.VPNSitesClientListOptions) (resp azfake.PagerResponder[armnetwork.VPNSitesClientListResponse]) + + // NewListByResourceGroupPager is the fake for method VPNSitesClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VPNSitesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VPNSitesClientListByResourceGroupResponse]) + + // UpdateTags is the fake for method VPNSitesClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteParameters armnetwork.TagsObject, options *armnetwork.VPNSitesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VPNSitesClientUpdateTagsResponse], errResp azfake.ErrorResponder) +} + +// NewVPNSitesServerTransport creates a new instance of VPNSitesServerTransport with the provided implementation. +// The returned VPNSitesServerTransport instance is connected to an instance of armnetwork.VPNSitesClient by way of the +// undefined.Transporter field. +func NewVPNSitesServerTransport(srv *VPNSitesServer) *VPNSitesServerTransport { + return &VPNSitesServerTransport{srv: srv} +} + +// VPNSitesServerTransport connects instances of armnetwork.VPNSitesClient to instances of VPNSitesServer. +// Don't use this type directly, use NewVPNSitesServerTransport instead. +type VPNSitesServerTransport struct { + srv *VPNSitesServer + beginCreateOrUpdate *azfake.PollerResponder[armnetwork.VPNSitesClientCreateOrUpdateResponse] + beginDelete *azfake.PollerResponder[armnetwork.VPNSitesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.VPNSitesClientListResponse] + newListByResourceGroupPager *azfake.PagerResponder[armnetwork.VPNSitesClientListByResourceGroupResponse] +} + +// Do implements the policy.Transporter interface for VPNSitesServerTransport. +func (v *VPNSitesServerTransport) 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 "VPNSitesClient.BeginCreateOrUpdate": + resp, err = v.dispatchBeginCreateOrUpdate(req) + case "VPNSitesClient.BeginDelete": + resp, err = v.dispatchBeginDelete(req) + case "VPNSitesClient.Get": + resp, err = v.dispatchGet(req) + case "VPNSitesClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VPNSitesClient.NewListByResourceGroupPager": + resp, err = v.dispatchNewListByResourceGroupPager(req) + case "VPNSitesClient.UpdateTags": + resp, err = v.dispatchUpdateTags(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNSitesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.BeginCreateOrUpdate == nil { + 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.Network/vpnSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNSite](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnSiteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, vpnSiteNameUnescaped, 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 *VPNSitesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if v.srv.BeginDelete == nil { + 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.Network/vpnSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnSiteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, vpnSiteNameUnescaped, 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 *VPNSitesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + 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.Network/vpnSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnSiteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameUnescaped, vpnSiteNameUnescaped, 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).VPNSite, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VPNSitesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + 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.Network/vpnSites` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := v.srv.NewListPager(nil) + v.newListPager = &resp + server.PagerResponderInjectNextLinks(v.newListPager, req, func(page *armnetwork.VPNSitesClientListResponse, 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 *VPNSitesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + if v.newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnSites` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, nil) + v.newListByResourceGroupPager = &resp + server.PagerResponderInjectNextLinks(v.newListByResourceGroupPager, req, func(page *armnetwork.VPNSitesClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(v.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(v.newListByResourceGroupPager) { + v.newListByResourceGroupPager = nil + } + return resp, nil +} + +func (v *VPNSitesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if v.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/vpnSites/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + vpnSiteNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("vpnSiteName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, vpnSiteNameUnescaped, 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).VPNSite, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/vpnsitesconfiguration_server.go b/sdk/resourcemanager/network/armnetwork/fake/vpnsitesconfiguration_server.go new file mode 100644 index 000000000000..aa9133606a7c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/vpnsitesconfiguration_server.go @@ -0,0 +1,113 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// VPNSitesConfigurationServer is a fake server for instances of the armnetwork.VPNSitesConfigurationClient type. +type VPNSitesConfigurationServer struct { + // BeginDownload is the fake for method VPNSitesConfigurationClient.BeginDownload + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDownload func(ctx context.Context, resourceGroupName string, virtualWANName string, request armnetwork.GetVPNSitesConfigurationRequest, options *armnetwork.VPNSitesConfigurationClientBeginDownloadOptions) (resp azfake.PollerResponder[armnetwork.VPNSitesConfigurationClientDownloadResponse], errResp azfake.ErrorResponder) +} + +// NewVPNSitesConfigurationServerTransport creates a new instance of VPNSitesConfigurationServerTransport with the provided implementation. +// The returned VPNSitesConfigurationServerTransport instance is connected to an instance of armnetwork.VPNSitesConfigurationClient by way of the +// undefined.Transporter field. +func NewVPNSitesConfigurationServerTransport(srv *VPNSitesConfigurationServer) *VPNSitesConfigurationServerTransport { + return &VPNSitesConfigurationServerTransport{srv: srv} +} + +// VPNSitesConfigurationServerTransport connects instances of armnetwork.VPNSitesConfigurationClient to instances of VPNSitesConfigurationServer. +// Don't use this type directly, use NewVPNSitesConfigurationServerTransport instead. +type VPNSitesConfigurationServerTransport struct { + srv *VPNSitesConfigurationServer + beginDownload *azfake.PollerResponder[armnetwork.VPNSitesConfigurationClientDownloadResponse] +} + +// Do implements the policy.Transporter interface for VPNSitesConfigurationServerTransport. +func (v *VPNSitesConfigurationServerTransport) 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 "VPNSitesConfigurationClient.BeginDownload": + resp, err = v.dispatchBeginDownload(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VPNSitesConfigurationServerTransport) dispatchBeginDownload(req *http.Request) (*http.Response, error) { + if v.srv.BeginDownload == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDownload not implemented")} + } + if v.beginDownload == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/virtualWans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConfiguration` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.GetVPNSitesConfigurationRequest](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + virtualWANNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("virtualWANName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.BeginDownload(req.Context(), resourceGroupNameUnescaped, virtualWANNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + v.beginDownload = &respr + } + + resp, err := server.PollerResponderNext(v.beginDownload, 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.beginDownload) { + v.beginDownload = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/watchers_server.go b/sdk/resourcemanager/network/armnetwork/fake/watchers_server.go new file mode 100644 index 000000000000..796b272866ca --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/watchers_server.go @@ -0,0 +1,921 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// WatchersServer is a fake server for instances of the armnetwork.WatchersClient type. +type WatchersServer struct { + // BeginCheckConnectivity is the fake for method WatchersClient.BeginCheckConnectivity + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginCheckConnectivity func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.ConnectivityParameters, options *armnetwork.WatchersClientBeginCheckConnectivityOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientCheckConnectivityResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdate is the fake for method WatchersClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.Watcher, options *armnetwork.WatchersClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.WatchersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method WatchersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, networkWatcherName string, options *armnetwork.WatchersClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method WatchersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, networkWatcherName string, options *armnetwork.WatchersClientGetOptions) (resp azfake.Responder[armnetwork.WatchersClientGetResponse], errResp azfake.ErrorResponder) + + // BeginGetAzureReachabilityReport is the fake for method WatchersClient.BeginGetAzureReachabilityReport + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetAzureReachabilityReport func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.AzureReachabilityReportParameters, options *armnetwork.WatchersClientBeginGetAzureReachabilityReportOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetAzureReachabilityReportResponse], errResp azfake.ErrorResponder) + + // BeginGetFlowLogStatus is the fake for method WatchersClient.BeginGetFlowLogStatus + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetFlowLogStatus func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.FlowLogStatusParameters, options *armnetwork.WatchersClientBeginGetFlowLogStatusOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetFlowLogStatusResponse], errResp azfake.ErrorResponder) + + // BeginGetNetworkConfigurationDiagnostic is the fake for method WatchersClient.BeginGetNetworkConfigurationDiagnostic + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetNetworkConfigurationDiagnostic func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.ConfigurationDiagnosticParameters, options *armnetwork.WatchersClientBeginGetNetworkConfigurationDiagnosticOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetNetworkConfigurationDiagnosticResponse], errResp azfake.ErrorResponder) + + // BeginGetNextHop is the fake for method WatchersClient.BeginGetNextHop + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetNextHop func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.NextHopParameters, options *armnetwork.WatchersClientBeginGetNextHopOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetNextHopResponse], errResp azfake.ErrorResponder) + + // GetTopology is the fake for method WatchersClient.GetTopology + // HTTP status codes to indicate success: http.StatusOK + GetTopology func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.TopologyParameters, options *armnetwork.WatchersClientGetTopologyOptions) (resp azfake.Responder[armnetwork.WatchersClientGetTopologyResponse], errResp azfake.ErrorResponder) + + // BeginGetTroubleshooting is the fake for method WatchersClient.BeginGetTroubleshooting + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetTroubleshooting func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.TroubleshootingParameters, options *armnetwork.WatchersClientBeginGetTroubleshootingOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetTroubleshootingResponse], errResp azfake.ErrorResponder) + + // BeginGetTroubleshootingResult is the fake for method WatchersClient.BeginGetTroubleshootingResult + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetTroubleshootingResult func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.QueryTroubleshootingParameters, options *armnetwork.WatchersClientBeginGetTroubleshootingResultOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetTroubleshootingResultResponse], errResp azfake.ErrorResponder) + + // BeginGetVMSecurityRules is the fake for method WatchersClient.BeginGetVMSecurityRules + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGetVMSecurityRules func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.SecurityGroupViewParameters, options *armnetwork.WatchersClientBeginGetVMSecurityRulesOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientGetVMSecurityRulesResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method WatchersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.WatchersClientListOptions) (resp azfake.PagerResponder[armnetwork.WatchersClientListResponse]) + + // NewListAllPager is the fake for method WatchersClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.WatchersClientListAllOptions) (resp azfake.PagerResponder[armnetwork.WatchersClientListAllResponse]) + + // BeginListAvailableProviders is the fake for method WatchersClient.BeginListAvailableProviders + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginListAvailableProviders func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.AvailableProvidersListParameters, options *armnetwork.WatchersClientBeginListAvailableProvidersOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientListAvailableProvidersResponse], errResp azfake.ErrorResponder) + + // BeginSetFlowLogConfiguration is the fake for method WatchersClient.BeginSetFlowLogConfiguration + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginSetFlowLogConfiguration func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.FlowLogInformation, options *armnetwork.WatchersClientBeginSetFlowLogConfigurationOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientSetFlowLogConfigurationResponse], errResp azfake.ErrorResponder) + + // UpdateTags is the fake for method WatchersClient.UpdateTags + // HTTP status codes to indicate success: http.StatusOK + UpdateTags func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.TagsObject, options *armnetwork.WatchersClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.WatchersClientUpdateTagsResponse], errResp azfake.ErrorResponder) + + // BeginVerifyIPFlow is the fake for method WatchersClient.BeginVerifyIPFlow + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginVerifyIPFlow func(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters armnetwork.VerificationIPFlowParameters, options *armnetwork.WatchersClientBeginVerifyIPFlowOptions) (resp azfake.PollerResponder[armnetwork.WatchersClientVerifyIPFlowResponse], errResp azfake.ErrorResponder) +} + +// NewWatchersServerTransport creates a new instance of WatchersServerTransport with the provided implementation. +// The returned WatchersServerTransport instance is connected to an instance of armnetwork.WatchersClient by way of the +// undefined.Transporter field. +func NewWatchersServerTransport(srv *WatchersServer) *WatchersServerTransport { + return &WatchersServerTransport{srv: srv} +} + +// WatchersServerTransport connects instances of armnetwork.WatchersClient to instances of WatchersServer. +// Don't use this type directly, use NewWatchersServerTransport instead. +type WatchersServerTransport struct { + srv *WatchersServer + beginCheckConnectivity *azfake.PollerResponder[armnetwork.WatchersClientCheckConnectivityResponse] + beginDelete *azfake.PollerResponder[armnetwork.WatchersClientDeleteResponse] + beginGetAzureReachabilityReport *azfake.PollerResponder[armnetwork.WatchersClientGetAzureReachabilityReportResponse] + beginGetFlowLogStatus *azfake.PollerResponder[armnetwork.WatchersClientGetFlowLogStatusResponse] + beginGetNetworkConfigurationDiagnostic *azfake.PollerResponder[armnetwork.WatchersClientGetNetworkConfigurationDiagnosticResponse] + beginGetNextHop *azfake.PollerResponder[armnetwork.WatchersClientGetNextHopResponse] + beginGetTroubleshooting *azfake.PollerResponder[armnetwork.WatchersClientGetTroubleshootingResponse] + beginGetTroubleshootingResult *azfake.PollerResponder[armnetwork.WatchersClientGetTroubleshootingResultResponse] + beginGetVMSecurityRules *azfake.PollerResponder[armnetwork.WatchersClientGetVMSecurityRulesResponse] + newListPager *azfake.PagerResponder[armnetwork.WatchersClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.WatchersClientListAllResponse] + beginListAvailableProviders *azfake.PollerResponder[armnetwork.WatchersClientListAvailableProvidersResponse] + beginSetFlowLogConfiguration *azfake.PollerResponder[armnetwork.WatchersClientSetFlowLogConfigurationResponse] + beginVerifyIPFlow *azfake.PollerResponder[armnetwork.WatchersClientVerifyIPFlowResponse] +} + +// Do implements the policy.Transporter interface for WatchersServerTransport. +func (w *WatchersServerTransport) 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 "WatchersClient.BeginCheckConnectivity": + resp, err = w.dispatchBeginCheckConnectivity(req) + case "WatchersClient.CreateOrUpdate": + resp, err = w.dispatchCreateOrUpdate(req) + case "WatchersClient.BeginDelete": + resp, err = w.dispatchBeginDelete(req) + case "WatchersClient.Get": + resp, err = w.dispatchGet(req) + case "WatchersClient.BeginGetAzureReachabilityReport": + resp, err = w.dispatchBeginGetAzureReachabilityReport(req) + case "WatchersClient.BeginGetFlowLogStatus": + resp, err = w.dispatchBeginGetFlowLogStatus(req) + case "WatchersClient.BeginGetNetworkConfigurationDiagnostic": + resp, err = w.dispatchBeginGetNetworkConfigurationDiagnostic(req) + case "WatchersClient.BeginGetNextHop": + resp, err = w.dispatchBeginGetNextHop(req) + case "WatchersClient.GetTopology": + resp, err = w.dispatchGetTopology(req) + case "WatchersClient.BeginGetTroubleshooting": + resp, err = w.dispatchBeginGetTroubleshooting(req) + case "WatchersClient.BeginGetTroubleshootingResult": + resp, err = w.dispatchBeginGetTroubleshootingResult(req) + case "WatchersClient.BeginGetVMSecurityRules": + resp, err = w.dispatchBeginGetVMSecurityRules(req) + case "WatchersClient.NewListPager": + resp, err = w.dispatchNewListPager(req) + case "WatchersClient.NewListAllPager": + resp, err = w.dispatchNewListAllPager(req) + case "WatchersClient.BeginListAvailableProviders": + resp, err = w.dispatchBeginListAvailableProviders(req) + case "WatchersClient.BeginSetFlowLogConfiguration": + resp, err = w.dispatchBeginSetFlowLogConfiguration(req) + case "WatchersClient.UpdateTags": + resp, err = w.dispatchUpdateTags(req) + case "WatchersClient.BeginVerifyIPFlow": + resp, err = w.dispatchBeginVerifyIPFlow(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginCheckConnectivity(req *http.Request) (*http.Response, error) { + if w.srv.BeginCheckConnectivity == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCheckConnectivity not implemented")} + } + if w.beginCheckConnectivity == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/connectivityCheck` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ConnectivityParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginCheckConnectivity(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginCheckConnectivity = &respr + } + + resp, err := server.PollerResponderNext(w.beginCheckConnectivity, 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(w.beginCheckConnectivity) { + w.beginCheckConnectivity = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if w.srv.CreateOrUpdate == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.Watcher](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, 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).Watcher, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if w.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if w.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(w.beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(w.beginDelete) { + w.beginDelete = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if w.srv.Get == nil { + 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.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.Get(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, 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).Watcher, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetAzureReachabilityReport(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetAzureReachabilityReport == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetAzureReachabilityReport not implemented")} + } + if w.beginGetAzureReachabilityReport == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/azureReachabilityReport` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.AzureReachabilityReportParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetAzureReachabilityReport(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetAzureReachabilityReport = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetAzureReachabilityReport, 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(w.beginGetAzureReachabilityReport) { + w.beginGetAzureReachabilityReport = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetFlowLogStatus(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetFlowLogStatus == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetFlowLogStatus not implemented")} + } + if w.beginGetFlowLogStatus == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/queryFlowLogStatus` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.FlowLogStatusParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetFlowLogStatus(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetFlowLogStatus = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetFlowLogStatus, 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(w.beginGetFlowLogStatus) { + w.beginGetFlowLogStatus = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetNetworkConfigurationDiagnostic(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetNetworkConfigurationDiagnostic == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetNetworkConfigurationDiagnostic not implemented")} + } + if w.beginGetNetworkConfigurationDiagnostic == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/networkConfigurationDiagnostic` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.ConfigurationDiagnosticParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetNetworkConfigurationDiagnostic(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetNetworkConfigurationDiagnostic = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetNetworkConfigurationDiagnostic, 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(w.beginGetNetworkConfigurationDiagnostic) { + w.beginGetNetworkConfigurationDiagnostic = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetNextHop(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetNextHop == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetNextHop not implemented")} + } + if w.beginGetNextHop == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nextHop` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.NextHopParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetNextHop(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetNextHop = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetNextHop, 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(w.beginGetNextHop) { + w.beginGetNextHop = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchGetTopology(req *http.Request) (*http.Response, error) { + if w.srv.GetTopology == nil { + return nil, &nonRetriableError{errors.New("fake for method GetTopology not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/topology` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TopologyParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.GetTopology(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, 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).Topology, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetTroubleshooting(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetTroubleshooting == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetTroubleshooting not implemented")} + } + if w.beginGetTroubleshooting == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/troubleshoot` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TroubleshootingParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetTroubleshooting(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetTroubleshooting = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetTroubleshooting, 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(w.beginGetTroubleshooting) { + w.beginGetTroubleshooting = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetTroubleshootingResult(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetTroubleshootingResult == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetTroubleshootingResult not implemented")} + } + if w.beginGetTroubleshootingResult == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/queryTroubleshootResult` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.QueryTroubleshootingParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetTroubleshootingResult(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetTroubleshootingResult = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetTroubleshootingResult, 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(w.beginGetTroubleshootingResult) { + w.beginGetTroubleshootingResult = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginGetVMSecurityRules(req *http.Request) (*http.Response, error) { + if w.srv.BeginGetVMSecurityRules == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGetVMSecurityRules not implemented")} + } + if w.beginGetVMSecurityRules == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/securityGroupView` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.SecurityGroupViewParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginGetVMSecurityRules(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginGetVMSecurityRules = &respr + } + + resp, err := server.PollerResponderNext(w.beginGetVMSecurityRules, 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(w.beginGetVMSecurityRules) { + w.beginGetVMSecurityRules = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if w.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if w.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := w.srv.NewListPager(resourceGroupNameUnescaped, nil) + w.newListPager = &resp + } + resp, err := server.PagerResponderNext(w.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(w.newListPager) { + w.newListPager = nil + } + return resp, nil +} + +func (w *WatchersServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if w.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if w.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := w.srv.NewListAllPager(nil) + w.newListAllPager = &resp + } + resp, err := server.PagerResponderNext(w.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(w.newListAllPager) { + w.newListAllPager = nil + } + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginListAvailableProviders(req *http.Request) (*http.Response, error) { + if w.srv.BeginListAvailableProviders == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginListAvailableProviders not implemented")} + } + if w.beginListAvailableProviders == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/availableProvidersList` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.AvailableProvidersListParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginListAvailableProviders(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginListAvailableProviders = &respr + } + + resp, err := server.PollerResponderNext(w.beginListAvailableProviders, 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(w.beginListAvailableProviders) { + w.beginListAvailableProviders = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginSetFlowLogConfiguration(req *http.Request) (*http.Response, error) { + if w.srv.BeginSetFlowLogConfiguration == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginSetFlowLogConfiguration not implemented")} + } + if w.beginSetFlowLogConfiguration == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/configureFlowLog` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.FlowLogInformation](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginSetFlowLogConfiguration(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginSetFlowLogConfiguration = &respr + } + + resp, err := server.PollerResponderNext(w.beginSetFlowLogConfiguration, 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(w.beginSetFlowLogConfiguration) { + w.beginSetFlowLogConfiguration = nil + } + + return resp, nil +} + +func (w *WatchersServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { + if w.srv.UpdateTags == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.UpdateTags(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, 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).Watcher, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WatchersServerTransport) dispatchBeginVerifyIPFlow(req *http.Request) (*http.Response, error) { + if w.srv.BeginVerifyIPFlow == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginVerifyIPFlow not implemented")} + } + if w.beginVerifyIPFlow == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/networkWatchers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipFlowVerify` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.VerificationIPFlowParameters](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + networkWatcherNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("networkWatcherName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginVerifyIPFlow(req.Context(), resourceGroupNameUnescaped, networkWatcherNameUnescaped, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginVerifyIPFlow = &respr + } + + resp, err := server.PollerResponderNext(w.beginVerifyIPFlow, 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(w.beginVerifyIPFlow) { + w.beginVerifyIPFlow = nil + } + + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/webapplicationfirewallpolicies_server.go b/sdk/resourcemanager/network/armnetwork/fake/webapplicationfirewallpolicies_server.go new file mode 100644 index 000000000000..6ab4076efbcf --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/webapplicationfirewallpolicies_server.go @@ -0,0 +1,270 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// WebApplicationFirewallPoliciesServer is a fake server for instances of the armnetwork.WebApplicationFirewallPoliciesClient type. +type WebApplicationFirewallPoliciesServer struct { + // CreateOrUpdate is the fake for method WebApplicationFirewallPoliciesClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, policyName string, parameters armnetwork.WebApplicationFirewallPolicy, options *armnetwork.WebApplicationFirewallPoliciesClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.WebApplicationFirewallPoliciesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method WebApplicationFirewallPoliciesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, policyName string, options *armnetwork.WebApplicationFirewallPoliciesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.WebApplicationFirewallPoliciesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method WebApplicationFirewallPoliciesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, policyName string, options *armnetwork.WebApplicationFirewallPoliciesClientGetOptions) (resp azfake.Responder[armnetwork.WebApplicationFirewallPoliciesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method WebApplicationFirewallPoliciesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, options *armnetwork.WebApplicationFirewallPoliciesClientListOptions) (resp azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListResponse]) + + // NewListAllPager is the fake for method WebApplicationFirewallPoliciesClient.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armnetwork.WebApplicationFirewallPoliciesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListAllResponse]) +} + +// NewWebApplicationFirewallPoliciesServerTransport creates a new instance of WebApplicationFirewallPoliciesServerTransport with the provided implementation. +// The returned WebApplicationFirewallPoliciesServerTransport instance is connected to an instance of armnetwork.WebApplicationFirewallPoliciesClient by way of the +// undefined.Transporter field. +func NewWebApplicationFirewallPoliciesServerTransport(srv *WebApplicationFirewallPoliciesServer) *WebApplicationFirewallPoliciesServerTransport { + return &WebApplicationFirewallPoliciesServerTransport{srv: srv} +} + +// WebApplicationFirewallPoliciesServerTransport connects instances of armnetwork.WebApplicationFirewallPoliciesClient to instances of WebApplicationFirewallPoliciesServer. +// Don't use this type directly, use NewWebApplicationFirewallPoliciesServerTransport instead. +type WebApplicationFirewallPoliciesServerTransport struct { + srv *WebApplicationFirewallPoliciesServer + beginDelete *azfake.PollerResponder[armnetwork.WebApplicationFirewallPoliciesClientDeleteResponse] + newListPager *azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListResponse] + newListAllPager *azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListAllResponse] +} + +// Do implements the policy.Transporter interface for WebApplicationFirewallPoliciesServerTransport. +func (w *WebApplicationFirewallPoliciesServerTransport) 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 "WebApplicationFirewallPoliciesClient.CreateOrUpdate": + resp, err = w.dispatchCreateOrUpdate(req) + case "WebApplicationFirewallPoliciesClient.BeginDelete": + resp, err = w.dispatchBeginDelete(req) + case "WebApplicationFirewallPoliciesClient.Get": + resp, err = w.dispatchGet(req) + case "WebApplicationFirewallPoliciesClient.NewListPager": + resp, err = w.dispatchNewListPager(req) + case "WebApplicationFirewallPoliciesClient.NewListAllPager": + resp, err = w.dispatchNewListAllPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (w *WebApplicationFirewallPoliciesServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if w.srv.CreateOrUpdate == nil { + 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.Network/ApplicationGatewayWebApplicationFirewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armnetwork.WebApplicationFirewallPolicy](req) + if err != nil { + return nil, err + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + policyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("policyName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, policyNameUnescaped, 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).WebApplicationFirewallPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WebApplicationFirewallPoliciesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if w.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + if w.beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + policyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("policyName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, policyNameUnescaped, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + w.beginDelete = &respr + } + + resp, err := server.PollerResponderNext(w.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(w.beginDelete) { + w.beginDelete = nil + } + + return resp, nil +} + +func (w *WebApplicationFirewallPoliciesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if w.srv.Get == nil { + 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.Network/ApplicationGatewayWebApplicationFirewallPolicies/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + policyNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("policyName")]) + if err != nil { + return nil, err + } + respr, errRespr := w.srv.Get(req.Context(), resourceGroupNameUnescaped, policyNameUnescaped, 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).WebApplicationFirewallPolicy, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WebApplicationFirewallPoliciesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if w.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + if w.newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := w.srv.NewListPager(resourceGroupNameUnescaped, nil) + w.newListPager = &resp + server.PagerResponderInjectNextLinks(w.newListPager, req, func(page *armnetwork.WebApplicationFirewallPoliciesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(w.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(w.newListPager) { + w.newListPager = nil + } + return resp, nil +} + +func (w *WebApplicationFirewallPoliciesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if w.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + if w.newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := w.srv.NewListAllPager(nil) + w.newListAllPager = &resp + server.PagerResponderInjectNextLinks(w.newListAllPager, req, func(page *armnetwork.WebApplicationFirewallPoliciesClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(w.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(w.newListAllPager) { + w.newListAllPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake/webcategories_server.go b/sdk/resourcemanager/network/armnetwork/fake/webcategories_server.go new file mode 100644 index 000000000000..676b2fdd05c8 --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/fake/webcategories_server.go @@ -0,0 +1,146 @@ +//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/network/armnetwork/v3" + "net/http" + "net/url" + "regexp" +) + +// WebCategoriesServer is a fake server for instances of the armnetwork.WebCategoriesClient type. +type WebCategoriesServer struct { + // Get is the fake for method WebCategoriesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, name string, options *armnetwork.WebCategoriesClientGetOptions) (resp azfake.Responder[armnetwork.WebCategoriesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListBySubscriptionPager is the fake for method WebCategoriesClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armnetwork.WebCategoriesClientListBySubscriptionOptions) (resp azfake.PagerResponder[armnetwork.WebCategoriesClientListBySubscriptionResponse]) +} + +// NewWebCategoriesServerTransport creates a new instance of WebCategoriesServerTransport with the provided implementation. +// The returned WebCategoriesServerTransport instance is connected to an instance of armnetwork.WebCategoriesClient by way of the +// undefined.Transporter field. +func NewWebCategoriesServerTransport(srv *WebCategoriesServer) *WebCategoriesServerTransport { + return &WebCategoriesServerTransport{srv: srv} +} + +// WebCategoriesServerTransport connects instances of armnetwork.WebCategoriesClient to instances of WebCategoriesServer. +// Don't use this type directly, use NewWebCategoriesServerTransport instead. +type WebCategoriesServerTransport struct { + srv *WebCategoriesServer + newListBySubscriptionPager *azfake.PagerResponder[armnetwork.WebCategoriesClientListBySubscriptionResponse] +} + +// Do implements the policy.Transporter interface for WebCategoriesServerTransport. +func (w *WebCategoriesServerTransport) 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 "WebCategoriesClient.Get": + resp, err = w.dispatchGet(req) + case "WebCategoriesClient.NewListBySubscriptionPager": + resp, err = w.dispatchNewListBySubscriptionPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (w *WebCategoriesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if w.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureWebCategories/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + 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() + nameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("name")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(expandUnescaped) + var options *armnetwork.WebCategoriesClientGetOptions + if expandParam != nil { + options = &armnetwork.WebCategoriesClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := w.srv.Get(req.Context(), nameUnescaped, 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).AzureWebCategory, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (w *WebCategoriesServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if w.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + if w.newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Network/azureWebCategories` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := w.srv.NewListBySubscriptionPager(nil) + w.newListBySubscriptionPager = &resp + server.PagerResponderInjectNextLinks(w.newListBySubscriptionPager, req, func(page *armnetwork.WebCategoriesClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(w.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(w.newListBySubscriptionPager) { + w.newListBySubscriptionPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/network/armnetwork/fake_example_test.go b/sdk/resourcemanager/network/armnetwork/fake_example_test.go new file mode 100644 index 000000000000..c28cf0927d4c --- /dev/null +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork_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/network/armnetwork/v3" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3/fake" +) + +func ExampleInterfacesServer() { + // 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". + fakeInterfacesServer := fake.InterfacesServer{ + + // next, provide implementations for the APIs you wish to fake. + // this fake corresponds to the InterfacesClient.Get() API. + Get: func(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfacesClientGetOptions) (resp azfake.Responder[armnetwork.InterfacesClientGetResponse], 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 + interfaceResp := armnetwork.InterfacesClientGetResponse{} + interfaceResp.ID = to.Ptr("/fake/resource/id") + + // use resp to set the desired response + resp.SetResponse(http.StatusOK, interfaceResp, 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 := armnetwork.NewInterfacesClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewInterfacesServerTransport(&fakeInterfacesServer), + }, + }) + 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", "fakeInterface", nil) + if err != nil { + log.Fatal(err) + } + + fmt.Println(*resp.ID) + + // APIs that haven't been faked will return an error + _, err = client.BeginDelete(context.TODO(), "fakeResourceGroup", "fakeInterface", nil) + + fmt.Println(err.Error()) + + // Output: + // /fake/resource/id + // fake for method BeginDelete not implemented +} diff --git a/sdk/resourcemanager/network/armnetwork/firewallpolicies_client.go b/sdk/resourcemanager/network/armnetwork/firewallpolicies_client.go index 006ec02c6717..ef629df8560d 100644 --- a/sdk/resourcemanager/network/armnetwork/firewallpolicies_client.go +++ b/sdk/resourcemanager/network/armnetwork/firewallpolicies_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 armnetwork @@ -60,9 +59,10 @@ func (client *FirewallPoliciesClient) BeginCreateOrUpdate(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPoliciesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPoliciesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[FirewallPoliciesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *FirewallPoliciesClient) BeginCreateOrUpdate(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *FirewallPoliciesClient) createOrUpdate(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters FirewallPolicy, options *FirewallPoliciesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "FirewallPoliciesClient.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, firewallPolicyName, 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. @@ -110,7 +116,10 @@ func (client *FirewallPoliciesClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 the specified Firewall Policy. @@ -127,9 +136,10 @@ func (client *FirewallPoliciesClient) BeginDelete(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPoliciesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPoliciesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[FirewallPoliciesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *FirewallPoliciesClient) BeginDelete(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *FirewallPoliciesClient) deleteOperation(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPoliciesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "FirewallPoliciesClient.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, firewallPolicyName, 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 *FirewallPoliciesClient) deleteCreateRequest(ctx context.Context, r // - firewallPolicyName - The name of the Firewall Policy. // - options - FirewallPoliciesClientGetOptions contains the optional parameters for the FirewallPoliciesClient.Get method. func (client *FirewallPoliciesClient) Get(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPoliciesClientGetOptions) (FirewallPoliciesClientGetResponse, error) { + var err error + const operationName = "FirewallPoliciesClient.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, firewallPolicyName, options) if err != nil { return FirewallPoliciesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPoliciesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPoliciesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPoliciesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -252,6 +275,7 @@ func (client *FirewallPoliciesClient) NewListPager(resourceGroupName string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *FirewallPoliciesClientListResponse) (FirewallPoliciesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "FirewallPoliciesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -271,6 +295,7 @@ func (client *FirewallPoliciesClient) NewListPager(resourceGroupName string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -316,6 +341,7 @@ func (client *FirewallPoliciesClient) NewListAllPager(options *FirewallPoliciesC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *FirewallPoliciesClientListAllResponse) (FirewallPoliciesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "FirewallPoliciesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -335,6 +361,7 @@ func (client *FirewallPoliciesClient) NewListAllPager(options *FirewallPoliciesC } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -375,18 +402,25 @@ func (client *FirewallPoliciesClient) listAllHandleResponse(resp *http.Response) // - options - FirewallPoliciesClientUpdateTagsOptions contains the optional parameters for the FirewallPoliciesClient.UpdateTags // method. func (client *FirewallPoliciesClient) UpdateTags(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters TagsObject, options *FirewallPoliciesClientUpdateTagsOptions) (FirewallPoliciesClientUpdateTagsResponse, error) { + var err error + const operationName = "FirewallPoliciesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options) if err != nil { return FirewallPoliciesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPoliciesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPoliciesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPoliciesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -412,7 +446,10 @@ func (client *FirewallPoliciesClient) updateTagsCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignatures_client.go b/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignatures_client.go index c120ebda4b5e..a2079f509b1c 100644 --- a/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignatures_client.go +++ b/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignatures_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 armnetwork @@ -54,18 +53,25 @@ func NewFirewallPolicyIdpsSignaturesClient(subscriptionID string, credential azc // - options - FirewallPolicyIdpsSignaturesClientListOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesClient.List // method. func (client *FirewallPolicyIdpsSignaturesClient) List(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters IDPSQueryObject, options *FirewallPolicyIdpsSignaturesClientListOptions) (FirewallPolicyIdpsSignaturesClientListResponse, error) { + var err error + const operationName = "FirewallPolicyIdpsSignaturesClient.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, firewallPolicyName, parameters, options) if err != nil { return FirewallPolicyIdpsSignaturesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyIdpsSignaturesClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyIdpsSignaturesClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyIdpsSignaturesClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -91,7 +97,10 @@ func (client *FirewallPolicyIdpsSignaturesClient) listCreateRequest(ctx context. reqQP.Set("api-version", "2022-11-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 } // listHandleResponse handles the List response. diff --git a/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesfiltervalues_client.go b/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesfiltervalues_client.go index 2ed3fd641c2c..284a1d8caf7f 100644 --- a/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesfiltervalues_client.go +++ b/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesfiltervalues_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 armnetwork @@ -54,18 +53,25 @@ func NewFirewallPolicyIdpsSignaturesFilterValuesClient(subscriptionID string, cr // - options - FirewallPolicyIdpsSignaturesFilterValuesClientListOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesFilterValuesClient.List // method. func (client *FirewallPolicyIdpsSignaturesFilterValuesClient) List(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignatureOverridesFilterValuesQuery, options *FirewallPolicyIdpsSignaturesFilterValuesClientListOptions) (FirewallPolicyIdpsSignaturesFilterValuesClientListResponse, error) { + var err error + const operationName = "FirewallPolicyIdpsSignaturesFilterValuesClient.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, firewallPolicyName, parameters, options) if err != nil { return FirewallPolicyIdpsSignaturesFilterValuesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyIdpsSignaturesFilterValuesClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyIdpsSignaturesFilterValuesClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyIdpsSignaturesFilterValuesClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -91,7 +97,10 @@ func (client *FirewallPolicyIdpsSignaturesFilterValuesClient) listCreateRequest( reqQP.Set("api-version", "2022-11-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 } // listHandleResponse handles the List response. diff --git a/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesoverrides_client.go b/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesoverrides_client.go index 28887718c2cc..7b6b55d679c4 100644 --- a/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesoverrides_client.go +++ b/sdk/resourcemanager/network/armnetwork/firewallpolicyidpssignaturesoverrides_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 armnetwork @@ -54,18 +53,25 @@ func NewFirewallPolicyIdpsSignaturesOverridesClient(subscriptionID string, crede // - options - FirewallPolicyIdpsSignaturesOverridesClientGetOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.Get // method. func (client *FirewallPolicyIdpsSignaturesOverridesClient) Get(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyIdpsSignaturesOverridesClientGetOptions) (FirewallPolicyIdpsSignaturesOverridesClientGetResponse, error) { + var err error + const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.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, firewallPolicyName, options) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -112,18 +118,25 @@ func (client *FirewallPolicyIdpsSignaturesOverridesClient) getHandleResponse(res // - options - FirewallPolicyIdpsSignaturesOverridesClientListOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.List // method. func (client *FirewallPolicyIdpsSignaturesOverridesClient) List(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyIdpsSignaturesOverridesClientListOptions) (FirewallPolicyIdpsSignaturesOverridesClientListResponse, error) { + var err error + const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.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, firewallPolicyName, options) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -171,18 +184,25 @@ func (client *FirewallPolicyIdpsSignaturesOverridesClient) listHandleResponse(re // - options - FirewallPolicyIdpsSignaturesOverridesClientPatchOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.Patch // method. func (client *FirewallPolicyIdpsSignaturesOverridesClient) Patch(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignaturesOverrides, options *FirewallPolicyIdpsSignaturesOverridesClientPatchOptions) (FirewallPolicyIdpsSignaturesOverridesClientPatchResponse, error) { + var err error + const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.Patch" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.patchCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err } - return client.patchHandleResponse(resp) + resp, err := client.patchHandleResponse(httpResp) + return resp, err } // patchCreateRequest creates the Patch request. @@ -208,7 +228,10 @@ func (client *FirewallPolicyIdpsSignaturesOverridesClient) patchCreateRequest(ct reqQP.Set("api-version", "2022-11-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 } // patchHandleResponse handles the Patch response. @@ -230,18 +253,25 @@ func (client *FirewallPolicyIdpsSignaturesOverridesClient) patchHandleResponse(r // - options - FirewallPolicyIdpsSignaturesOverridesClientPutOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.Put // method. func (client *FirewallPolicyIdpsSignaturesOverridesClient) Put(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignaturesOverrides, options *FirewallPolicyIdpsSignaturesOverridesClientPutOptions) (FirewallPolicyIdpsSignaturesOverridesClientPutResponse, error) { + var err error + const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.Put" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.putCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err } - return client.putHandleResponse(resp) + resp, err := client.putHandleResponse(httpResp) + return resp, err } // putCreateRequest creates the Put request. @@ -267,7 +297,10 @@ func (client *FirewallPolicyIdpsSignaturesOverridesClient) putCreateRequest(ctx reqQP.Set("api-version", "2022-11-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 } // putHandleResponse handles the Put response. diff --git a/sdk/resourcemanager/network/armnetwork/firewallpolicyrulecollectiongroups_client.go b/sdk/resourcemanager/network/armnetwork/firewallpolicyrulecollectiongroups_client.go index b48649bc355a..f33bdefdafbc 100644 --- a/sdk/resourcemanager/network/armnetwork/firewallpolicyrulecollectiongroups_client.go +++ b/sdk/resourcemanager/network/armnetwork/firewallpolicyrulecollectiongroups_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 armnetwork @@ -61,9 +60,10 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) BeginCreateOrUpdate(ctx if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) BeginCreateOrUpdate(ctx // // Generated from API version 2022-11-01 func (client *FirewallPolicyRuleCollectionGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, parameters FirewallPolicyRuleCollectionGroup, options *FirewallPolicyRuleCollectionGroupsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "FirewallPolicyRuleCollectionGroupsClient.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, firewallPolicyName, ruleCollectionGroupName, 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. @@ -115,7 +121,10 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) createOrUpdateCreateRequ reqQP.Set("api-version", "2022-11-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 the specified FirewallPolicyRuleCollectionGroup. @@ -133,9 +142,10 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) BeginDelete(ctx context. if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPolicyRuleCollectionGroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallPolicyRuleCollectionGroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[FirewallPolicyRuleCollectionGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) BeginDelete(ctx context. // // Generated from API version 2022-11-01 func (client *FirewallPolicyRuleCollectionGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *FirewallPolicyRuleCollectionGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "FirewallPolicyRuleCollectionGroupsClient.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, firewallPolicyName, ruleCollectionGroupName, 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. @@ -200,18 +216,25 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) deleteCreateRequest(ctx // - options - FirewallPolicyRuleCollectionGroupsClientGetOptions contains the optional parameters for the FirewallPolicyRuleCollectionGroupsClient.Get // method. func (client *FirewallPolicyRuleCollectionGroupsClient) Get(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *FirewallPolicyRuleCollectionGroupsClientGetOptions) (FirewallPolicyRuleCollectionGroupsClientGetResponse, error) { + var err error + const operationName = "FirewallPolicyRuleCollectionGroupsClient.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, firewallPolicyName, ruleCollectionGroupName, options) if err != nil { return FirewallPolicyRuleCollectionGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FirewallPolicyRuleCollectionGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FirewallPolicyRuleCollectionGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FirewallPolicyRuleCollectionGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) NewListPager(resourceGro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *FirewallPolicyRuleCollectionGroupsClientListResponse) (FirewallPolicyRuleCollectionGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "FirewallPolicyRuleCollectionGroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *FirewallPolicyRuleCollectionGroupsClient) NewListPager(resourceGro } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/flowlogs_client.go b/sdk/resourcemanager/network/armnetwork/flowlogs_client.go index 6806a628fc77..784d9b9c24d3 100644 --- a/sdk/resourcemanager/network/armnetwork/flowlogs_client.go +++ b/sdk/resourcemanager/network/armnetwork/flowlogs_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 armnetwork @@ -61,9 +60,10 @@ func (client *FlowLogsClient) BeginCreateOrUpdate(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FlowLogsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FlowLogsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[FlowLogsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *FlowLogsClient) BeginCreateOrUpdate(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *FlowLogsClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters FlowLog, options *FlowLogsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "FlowLogsClient.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, networkWatcherName, flowLogName, 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. @@ -115,7 +121,10 @@ func (client *FlowLogsClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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 the specified flow log resource. @@ -132,9 +141,10 @@ func (client *FlowLogsClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FlowLogsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FlowLogsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[FlowLogsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -145,18 +155,24 @@ func (client *FlowLogsClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *FlowLogsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *FlowLogsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "FlowLogsClient.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, networkWatcherName, flowLogName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -198,18 +214,25 @@ func (client *FlowLogsClient) deleteCreateRequest(ctx context.Context, resourceG // - flowLogName - The name of the flow log resource. // - options - FlowLogsClientGetOptions contains the optional parameters for the FlowLogsClient.Get method. func (client *FlowLogsClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *FlowLogsClientGetOptions) (FlowLogsClientGetResponse, error) { + var err error + const operationName = "FlowLogsClient.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, networkWatcherName, flowLogName, options) if err != nil { return FlowLogsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FlowLogsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FlowLogsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FlowLogsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -263,6 +286,7 @@ func (client *FlowLogsClient) NewListPager(resourceGroupName string, networkWatc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *FlowLogsClientListResponse) (FlowLogsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "FlowLogsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -282,6 +306,7 @@ func (client *FlowLogsClient) NewListPager(resourceGroupName string, networkWatc } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -330,18 +355,25 @@ func (client *FlowLogsClient) listHandleResponse(resp *http.Response) (FlowLogsC // - parameters - Parameters supplied to update flow log tags. // - options - FlowLogsClientUpdateTagsOptions contains the optional parameters for the FlowLogsClient.UpdateTags method. func (client *FlowLogsClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters TagsObject, options *FlowLogsClientUpdateTagsOptions) (FlowLogsClientUpdateTagsResponse, error) { + var err error + const operationName = "FlowLogsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkWatcherName, flowLogName, parameters, options) if err != nil { return FlowLogsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return FlowLogsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FlowLogsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return FlowLogsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -371,7 +403,10 @@ func (client *FlowLogsClient) updateTagsCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/go.mod b/sdk/resourcemanager/network/armnetwork/go.mod index bb1025f2a00f..d92a79e85611 100644 --- a/sdk/resourcemanager/network/armnetwork/go.mod +++ b/sdk/resourcemanager/network/armnetwork/go.mod @@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/ go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.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/stretchr/testify v1.8.2 diff --git a/sdk/resourcemanager/network/armnetwork/go.sum b/sdk/resourcemanager/network/armnetwork/go.sum index 6befdf11bc6e..7cbb704590fa 100644 --- a/sdk/resourcemanager/network/armnetwork/go.sum +++ b/sdk/resourcemanager/network/armnetwork/go.sum @@ -1,5 +1,5 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.0 h1:xGLAFFd9D3iLGxYiUGPdITSzsFmU1K8VtfuUHWAoN7M= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +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.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= diff --git a/sdk/resourcemanager/network/armnetwork/groups_client.go b/sdk/resourcemanager/network/armnetwork/groups_client.go index 34f1eb45b133..10f89ffa8aad 100644 --- a/sdk/resourcemanager/network/armnetwork/groups_client.go +++ b/sdk/resourcemanager/network/armnetwork/groups_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 armnetwork @@ -56,18 +55,25 @@ func NewGroupsClient(subscriptionID string, credential azcore.TokenCredential, o // - parameters - Parameters supplied to the specify which network group need to create // - options - GroupsClientCreateOrUpdateOptions contains the optional parameters for the GroupsClient.CreateOrUpdate method. func (client *GroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, parameters Group, options *GroupsClientCreateOrUpdateOptions) (GroupsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "GroupsClient.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, networkManagerName, networkGroupName, parameters, options) if err != nil { return GroupsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GroupsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return GroupsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return GroupsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -100,7 +106,10 @@ func (client *GroupsClient) createOrUpdateCreateRequest(ctx context.Context, res req.Raw().Header["If-Match"] = []string{*options.IfMatch} } 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. @@ -129,9 +138,10 @@ func (client *GroupsClient) BeginDelete(ctx context.Context, resourceGroupName s if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[GroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[GroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[GroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -142,18 +152,24 @@ func (client *GroupsClient) BeginDelete(ctx context.Context, resourceGroupName s // // Generated from API version 2022-11-01 func (client *GroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, options *GroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "GroupsClient.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, networkManagerName, networkGroupName, 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. @@ -198,18 +214,25 @@ func (client *GroupsClient) deleteCreateRequest(ctx context.Context, resourceGro // - networkGroupName - The name of the network group. // - options - GroupsClientGetOptions contains the optional parameters for the GroupsClient.Get method. func (client *GroupsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, options *GroupsClientGetOptions) (GroupsClientGetResponse, error) { + var err error + const operationName = "GroupsClient.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, networkManagerName, networkGroupName, options) if err != nil { return GroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return GroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return GroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return GroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -263,6 +286,7 @@ func (client *GroupsClient) NewListPager(resourceGroupName string, networkManage return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *GroupsClientListResponse) (GroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "GroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -282,6 +306,7 @@ func (client *GroupsClient) NewListPager(resourceGroupName string, networkManage } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/hubroutetables_client.go b/sdk/resourcemanager/network/armnetwork/hubroutetables_client.go index 4f45c9bdf2b9..f14281e4fcd1 100644 --- a/sdk/resourcemanager/network/armnetwork/hubroutetables_client.go +++ b/sdk/resourcemanager/network/armnetwork/hubroutetables_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 armnetwork @@ -61,9 +60,10 @@ func (client *HubRouteTablesClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubRouteTablesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubRouteTablesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[HubRouteTablesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *HubRouteTablesClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *HubRouteTablesClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, routeTableParameters HubRouteTable, options *HubRouteTablesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "HubRouteTablesClient.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, virtualHubName, routeTableName, routeTableParameters, 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. @@ -115,7 +121,10 @@ func (client *HubRouteTablesClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, routeTableParameters) + if err := runtime.MarshalAsJSON(req, routeTableParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a RouteTable. @@ -133,9 +142,10 @@ func (client *HubRouteTablesClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubRouteTablesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubRouteTablesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[HubRouteTablesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *HubRouteTablesClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *HubRouteTablesClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *HubRouteTablesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "HubRouteTablesClient.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, virtualHubName, routeTableName, 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. @@ -199,18 +215,25 @@ func (client *HubRouteTablesClient) deleteCreateRequest(ctx context.Context, res // - routeTableName - The name of the RouteTable. // - options - HubRouteTablesClientGetOptions contains the optional parameters for the HubRouteTablesClient.Get method. func (client *HubRouteTablesClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *HubRouteTablesClientGetOptions) (HubRouteTablesClientGetResponse, error) { + var err error + const operationName = "HubRouteTablesClient.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, virtualHubName, routeTableName, options) if err != nil { return HubRouteTablesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return HubRouteTablesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return HubRouteTablesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return HubRouteTablesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -264,6 +287,7 @@ func (client *HubRouteTablesClient) NewListPager(resourceGroupName string, virtu return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *HubRouteTablesClientListResponse) (HubRouteTablesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "HubRouteTablesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -283,6 +307,7 @@ func (client *HubRouteTablesClient) NewListPager(resourceGroupName string, virtu } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/hubvirtualnetworkconnections_client.go b/sdk/resourcemanager/network/armnetwork/hubvirtualnetworkconnections_client.go index a5513deb24bc..b89533d412ce 100644 --- a/sdk/resourcemanager/network/armnetwork/hubvirtualnetworkconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/hubvirtualnetworkconnections_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 armnetwork @@ -61,9 +60,10 @@ func (client *HubVirtualNetworkConnectionsClient) BeginCreateOrUpdate(ctx contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubVirtualNetworkConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubVirtualNetworkConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[HubVirtualNetworkConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *HubVirtualNetworkConnectionsClient) BeginCreateOrUpdate(ctx contex // // Generated from API version 2022-11-01 func (client *HubVirtualNetworkConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, hubVirtualNetworkConnectionParameters HubVirtualNetworkConnection, options *HubVirtualNetworkConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "HubVirtualNetworkConnectionsClient.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, virtualHubName, connectionName, hubVirtualNetworkConnectionParameters, 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. @@ -115,7 +121,10 @@ func (client *HubVirtualNetworkConnectionsClient) createOrUpdateCreateRequest(ct reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, hubVirtualNetworkConnectionParameters) + if err := runtime.MarshalAsJSON(req, hubVirtualNetworkConnectionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a HubVirtualNetworkConnection. @@ -133,9 +142,10 @@ func (client *HubVirtualNetworkConnectionsClient) BeginDelete(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubVirtualNetworkConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[HubVirtualNetworkConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[HubVirtualNetworkConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *HubVirtualNetworkConnectionsClient) BeginDelete(ctx context.Contex // // Generated from API version 2022-11-01 func (client *HubVirtualNetworkConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *HubVirtualNetworkConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "HubVirtualNetworkConnectionsClient.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, virtualHubName, connectionName, 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. @@ -200,18 +216,25 @@ func (client *HubVirtualNetworkConnectionsClient) deleteCreateRequest(ctx contex // - options - HubVirtualNetworkConnectionsClientGetOptions contains the optional parameters for the HubVirtualNetworkConnectionsClient.Get // method. func (client *HubVirtualNetworkConnectionsClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *HubVirtualNetworkConnectionsClientGetOptions) (HubVirtualNetworkConnectionsClientGetResponse, error) { + var err error + const operationName = "HubVirtualNetworkConnectionsClient.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, virtualHubName, connectionName, options) if err != nil { return HubVirtualNetworkConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return HubVirtualNetworkConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return HubVirtualNetworkConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return HubVirtualNetworkConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *HubVirtualNetworkConnectionsClient) NewListPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *HubVirtualNetworkConnectionsClientListResponse) (HubVirtualNetworkConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "HubVirtualNetworkConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *HubVirtualNetworkConnectionsClient) NewListPager(resourceGroupName } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/inboundnatrules_client.go b/sdk/resourcemanager/network/armnetwork/inboundnatrules_client.go index 2ae1ad8bf928..064d953d8eca 100644 --- a/sdk/resourcemanager/network/armnetwork/inboundnatrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/inboundnatrules_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 armnetwork @@ -61,9 +60,10 @@ func (client *InboundNatRulesClient) BeginCreateOrUpdate(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundNatRulesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundNatRulesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InboundNatRulesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *InboundNatRulesClient) BeginCreateOrUpdate(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *InboundNatRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, inboundNatRuleParameters InboundNatRule, options *InboundNatRulesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "InboundNatRulesClient.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, loadBalancerName, inboundNatRuleName, inboundNatRuleParameters, 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. @@ -115,7 +121,10 @@ func (client *InboundNatRulesClient) createOrUpdateCreateRequest(ctx context.Con reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, inboundNatRuleParameters) + if err := runtime.MarshalAsJSON(req, inboundNatRuleParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified load balancer inbound NAT rule. @@ -133,9 +142,10 @@ func (client *InboundNatRulesClient) BeginDelete(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundNatRulesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundNatRulesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InboundNatRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *InboundNatRulesClient) BeginDelete(ctx context.Context, resourceGr // // Generated from API version 2022-11-01 func (client *InboundNatRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, options *InboundNatRulesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "InboundNatRulesClient.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, loadBalancerName, inboundNatRuleName, 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. @@ -199,18 +215,25 @@ func (client *InboundNatRulesClient) deleteCreateRequest(ctx context.Context, re // - inboundNatRuleName - The name of the inbound NAT rule. // - options - InboundNatRulesClientGetOptions contains the optional parameters for the InboundNatRulesClient.Get method. func (client *InboundNatRulesClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, options *InboundNatRulesClientGetOptions) (InboundNatRulesClientGetResponse, error) { + var err error + const operationName = "InboundNatRulesClient.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, loadBalancerName, inboundNatRuleName, options) if err != nil { return InboundNatRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InboundNatRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InboundNatRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InboundNatRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -268,6 +291,7 @@ func (client *InboundNatRulesClient) NewListPager(resourceGroupName string, load return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InboundNatRulesClientListResponse) (InboundNatRulesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InboundNatRulesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -287,6 +311,7 @@ func (client *InboundNatRulesClient) NewListPager(resourceGroupName string, load } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/inboundsecurityrule_client.go b/sdk/resourcemanager/network/armnetwork/inboundsecurityrule_client.go index b6bad8e905e6..a859881d1fc2 100644 --- a/sdk/resourcemanager/network/armnetwork/inboundsecurityrule_client.go +++ b/sdk/resourcemanager/network/armnetwork/inboundsecurityrule_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 armnetwork @@ -61,9 +60,10 @@ func (client *InboundSecurityRuleClient) BeginCreateOrUpdate(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundSecurityRuleClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundSecurityRuleClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InboundSecurityRuleClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *InboundSecurityRuleClient) BeginCreateOrUpdate(ctx context.Context // // Generated from API version 2022-11-01 func (client *InboundSecurityRuleClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters InboundSecurityRule, options *InboundSecurityRuleClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "InboundSecurityRuleClient.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, networkVirtualApplianceName, ruleCollectionName, 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. @@ -115,5 +121,8 @@ func (client *InboundSecurityRuleClient) createOrUpdateCreateRequest(ctx context reqQP.Set("api-version", "2022-11-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/network/armnetwork/interfaceipconfigurations_client.go b/sdk/resourcemanager/network/armnetwork/interfaceipconfigurations_client.go index 6c3eaad8d91e..9211772e2d0b 100644 --- a/sdk/resourcemanager/network/armnetwork/interfaceipconfigurations_client.go +++ b/sdk/resourcemanager/network/armnetwork/interfaceipconfigurations_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 armnetwork @@ -55,18 +54,25 @@ func NewInterfaceIPConfigurationsClient(subscriptionID string, credential azcore // - options - InterfaceIPConfigurationsClientGetOptions contains the optional parameters for the InterfaceIPConfigurationsClient.Get // method. func (client *InterfaceIPConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *InterfaceIPConfigurationsClientGetOptions) (InterfaceIPConfigurationsClientGetResponse, error) { + var err error + const operationName = "InterfaceIPConfigurationsClient.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, networkInterfaceName, ipConfigurationName, options) if err != nil { return InterfaceIPConfigurationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfaceIPConfigurationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfaceIPConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfaceIPConfigurationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *InterfaceIPConfigurationsClient) NewListPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfaceIPConfigurationsClientListResponse) (InterfaceIPConfigurationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfaceIPConfigurationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *InterfaceIPConfigurationsClient) NewListPager(resourceGroupName st } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/interfaceloadbalancers_client.go b/sdk/resourcemanager/network/armnetwork/interfaceloadbalancers_client.go index 4c0c85b9da78..521f813e7493 100644 --- a/sdk/resourcemanager/network/armnetwork/interfaceloadbalancers_client.go +++ b/sdk/resourcemanager/network/armnetwork/interfaceloadbalancers_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 armnetwork @@ -58,6 +57,7 @@ func (client *InterfaceLoadBalancersClient) NewListPager(resourceGroupName strin return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfaceLoadBalancersClientListResponse) (InterfaceLoadBalancersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfaceLoadBalancersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -77,6 +77,7 @@ func (client *InterfaceLoadBalancersClient) NewListPager(resourceGroupName strin } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/interfaces_client.go b/sdk/resourcemanager/network/armnetwork/interfaces_client.go index 506764757a11..68eb342aca61 100644 --- a/sdk/resourcemanager/network/armnetwork/interfaces_client.go +++ b/sdk/resourcemanager/network/armnetwork/interfaces_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 armnetwork @@ -60,9 +59,10 @@ func (client *InterfacesClient) BeginCreateOrUpdate(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InterfacesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *InterfacesClient) BeginCreateOrUpdate(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *InterfacesClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkInterfaceName string, parameters Interface, options *InterfacesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "InterfacesClient.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, networkInterfaceName, 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. @@ -110,7 +116,10 @@ func (client *InterfacesClient) createOrUpdateCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-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 the specified network interface. @@ -126,9 +135,10 @@ func (client *InterfacesClient) BeginDelete(ctx context.Context, resourceGroupNa if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InterfacesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *InterfacesClient) BeginDelete(ctx context.Context, resourceGroupNa // // Generated from API version 2022-11-01 func (client *InterfacesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *InterfacesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "InterfacesClient.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, networkInterfaceName, 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. @@ -187,18 +203,25 @@ func (client *InterfacesClient) deleteCreateRequest(ctx context.Context, resourc // - networkInterfaceName - The name of the network interface. // - options - InterfacesClientGetOptions contains the optional parameters for the InterfacesClient.Get method. func (client *InterfacesClient) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *InterfacesClientGetOptions) (InterfacesClientGetResponse, error) { + var err error + const operationName = "InterfacesClient.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, networkInterfaceName, options) if err != nil { return InterfacesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfacesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfacesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfacesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,18 +273,25 @@ func (client *InterfacesClient) getHandleResponse(resp *http.Response) (Interfac // - options - InterfacesClientGetCloudServiceNetworkInterfaceOptions contains the optional parameters for the InterfacesClient.GetCloudServiceNetworkInterface // method. func (client *InterfacesClient) GetCloudServiceNetworkInterface(ctx context.Context, resourceGroupName string, cloudServiceName string, roleInstanceName string, networkInterfaceName string, options *InterfacesClientGetCloudServiceNetworkInterfaceOptions) (InterfacesClientGetCloudServiceNetworkInterfaceResponse, error) { + var err error + const operationName = "InterfacesClient.GetCloudServiceNetworkInterface" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCloudServiceNetworkInterfaceCreateRequest(ctx, resourceGroupName, cloudServiceName, roleInstanceName, networkInterfaceName, options) if err != nil { return InterfacesClientGetCloudServiceNetworkInterfaceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfacesClientGetCloudServiceNetworkInterfaceResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfacesClientGetCloudServiceNetworkInterfaceResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfacesClientGetCloudServiceNetworkInterfaceResponse{}, err } - return client.getCloudServiceNetworkInterfaceHandleResponse(resp) + resp, err := client.getCloudServiceNetworkInterfaceHandleResponse(httpResp) + return resp, err } // getCloudServiceNetworkInterfaceCreateRequest creates the GetCloudServiceNetworkInterface request. @@ -324,9 +354,10 @@ func (client *InterfacesClient) BeginGetEffectiveRouteTable(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientGetEffectiveRouteTableResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientGetEffectiveRouteTableResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InterfacesClientGetEffectiveRouteTableResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -337,18 +368,24 @@ func (client *InterfacesClient) BeginGetEffectiveRouteTable(ctx context.Context, // // Generated from API version 2022-11-01 func (client *InterfacesClient) getEffectiveRouteTable(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *InterfacesClientBeginGetEffectiveRouteTableOptions) (*http.Response, error) { + var err error + const operationName = "InterfacesClient.BeginGetEffectiveRouteTable" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getEffectiveRouteTableCreateRequest(ctx, resourceGroupName, networkInterfaceName, 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 } // getEffectiveRouteTableCreateRequest creates the GetEffectiveRouteTable request. @@ -390,18 +427,25 @@ func (client *InterfacesClient) getEffectiveRouteTableCreateRequest(ctx context. // - options - InterfacesClientGetVirtualMachineScaleSetIPConfigurationOptions contains the optional parameters for the InterfacesClient.GetVirtualMachineScaleSetIPConfiguration // method. func (client *InterfacesClient) GetVirtualMachineScaleSetIPConfiguration(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, ipConfigurationName string, options *InterfacesClientGetVirtualMachineScaleSetIPConfigurationOptions) (InterfacesClientGetVirtualMachineScaleSetIPConfigurationResponse, error) { + var err error + const operationName = "InterfacesClient.GetVirtualMachineScaleSetIPConfiguration" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVirtualMachineScaleSetIPConfigurationCreateRequest(ctx, resourceGroupName, virtualMachineScaleSetName, virtualmachineIndex, networkInterfaceName, ipConfigurationName, options) if err != nil { return InterfacesClientGetVirtualMachineScaleSetIPConfigurationResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfacesClientGetVirtualMachineScaleSetIPConfigurationResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfacesClientGetVirtualMachineScaleSetIPConfigurationResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfacesClientGetVirtualMachineScaleSetIPConfigurationResponse{}, err } - return client.getVirtualMachineScaleSetIPConfigurationHandleResponse(resp) + resp, err := client.getVirtualMachineScaleSetIPConfigurationHandleResponse(httpResp) + return resp, err } // getVirtualMachineScaleSetIPConfigurationCreateRequest creates the GetVirtualMachineScaleSetIPConfiguration request. @@ -465,18 +509,25 @@ func (client *InterfacesClient) getVirtualMachineScaleSetIPConfigurationHandleRe // - options - InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions contains the optional parameters for the InterfacesClient.GetVirtualMachineScaleSetNetworkInterface // method. func (client *InterfacesClient) GetVirtualMachineScaleSetNetworkInterface(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, options *InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions) (InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse, error) { + var err error + const operationName = "InterfacesClient.GetVirtualMachineScaleSetNetworkInterface" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVirtualMachineScaleSetNetworkInterfaceCreateRequest(ctx, resourceGroupName, virtualMachineScaleSetName, virtualmachineIndex, networkInterfaceName, options) if err != nil { return InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse{}, err } - return client.getVirtualMachineScaleSetNetworkInterfaceHandleResponse(resp) + resp, err := client.getVirtualMachineScaleSetNetworkInterfaceHandleResponse(httpResp) + return resp, err } // getVirtualMachineScaleSetNetworkInterfaceCreateRequest creates the GetVirtualMachineScaleSetNetworkInterface request. @@ -536,6 +587,7 @@ func (client *InterfacesClient) NewListPager(resourceGroupName string, options * return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListResponse) (InterfacesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -555,6 +607,7 @@ func (client *InterfacesClient) NewListPager(resourceGroupName string, options * } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -599,6 +652,7 @@ func (client *InterfacesClient) NewListAllPager(options *InterfacesClientListAll return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListAllResponse) (InterfacesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -618,6 +672,7 @@ func (client *InterfacesClient) NewListAllPager(options *InterfacesClientListAll } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -661,6 +716,7 @@ func (client *InterfacesClient) NewListCloudServiceNetworkInterfacesPager(resour return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListCloudServiceNetworkInterfacesResponse) (InterfacesClientListCloudServiceNetworkInterfacesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListCloudServiceNetworkInterfacesPager") var req *policy.Request var err error if page == nil { @@ -680,6 +736,7 @@ func (client *InterfacesClient) NewListCloudServiceNetworkInterfacesPager(resour } return client.listCloudServiceNetworkInterfacesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -733,6 +790,7 @@ func (client *InterfacesClient) NewListCloudServiceRoleInstanceNetworkInterfaces return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListCloudServiceRoleInstanceNetworkInterfacesResponse) (InterfacesClientListCloudServiceRoleInstanceNetworkInterfacesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListCloudServiceRoleInstanceNetworkInterfacesPager") var req *policy.Request var err error if page == nil { @@ -752,6 +810,7 @@ func (client *InterfacesClient) NewListCloudServiceRoleInstanceNetworkInterfaces } return client.listCloudServiceRoleInstanceNetworkInterfacesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -808,9 +867,10 @@ func (client *InterfacesClient) BeginListEffectiveNetworkSecurityGroups(ctx cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientListEffectiveNetworkSecurityGroupsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfacesClientListEffectiveNetworkSecurityGroupsResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InterfacesClientListEffectiveNetworkSecurityGroupsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -821,18 +881,24 @@ func (client *InterfacesClient) BeginListEffectiveNetworkSecurityGroups(ctx cont // // Generated from API version 2022-11-01 func (client *InterfacesClient) listEffectiveNetworkSecurityGroups(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *InterfacesClientBeginListEffectiveNetworkSecurityGroupsOptions) (*http.Response, error) { + var err error + const operationName = "InterfacesClient.BeginListEffectiveNetworkSecurityGroups" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listEffectiveNetworkSecurityGroupsCreateRequest(ctx, resourceGroupName, networkInterfaceName, 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 } // listEffectiveNetworkSecurityGroupsCreateRequest creates the ListEffectiveNetworkSecurityGroups request. @@ -877,6 +943,7 @@ func (client *InterfacesClient) NewListVirtualMachineScaleSetIPConfigurationsPag return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListVirtualMachineScaleSetIPConfigurationsResponse) (InterfacesClientListVirtualMachineScaleSetIPConfigurationsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListVirtualMachineScaleSetIPConfigurationsPager") var req *policy.Request var err error if page == nil { @@ -896,6 +963,7 @@ func (client *InterfacesClient) NewListVirtualMachineScaleSetIPConfigurationsPag } return client.listVirtualMachineScaleSetIPConfigurationsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -958,6 +1026,7 @@ func (client *InterfacesClient) NewListVirtualMachineScaleSetNetworkInterfacesPa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListVirtualMachineScaleSetNetworkInterfacesResponse) (InterfacesClientListVirtualMachineScaleSetNetworkInterfacesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListVirtualMachineScaleSetNetworkInterfacesPager") var req *policy.Request var err error if page == nil { @@ -977,6 +1046,7 @@ func (client *InterfacesClient) NewListVirtualMachineScaleSetNetworkInterfacesPa } return client.listVirtualMachineScaleSetNetworkInterfacesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -1030,6 +1100,7 @@ func (client *InterfacesClient) NewListVirtualMachineScaleSetVMNetworkInterfaces return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfacesClientListVirtualMachineScaleSetVMNetworkInterfacesResponse) (InterfacesClientListVirtualMachineScaleSetVMNetworkInterfacesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfacesClient.NewListVirtualMachineScaleSetVMNetworkInterfacesPager") var req *policy.Request var err error if page == nil { @@ -1049,6 +1120,7 @@ func (client *InterfacesClient) NewListVirtualMachineScaleSetVMNetworkInterfaces } return client.listVirtualMachineScaleSetVMNetworkInterfacesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -1100,18 +1172,25 @@ func (client *InterfacesClient) listVirtualMachineScaleSetVMNetworkInterfacesHan // - parameters - Parameters supplied to update network interface tags. // - options - InterfacesClientUpdateTagsOptions contains the optional parameters for the InterfacesClient.UpdateTags method. func (client *InterfacesClient) UpdateTags(ctx context.Context, resourceGroupName string, networkInterfaceName string, parameters TagsObject, options *InterfacesClientUpdateTagsOptions) (InterfacesClientUpdateTagsResponse, error) { + var err error + const operationName = "InterfacesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkInterfaceName, parameters, options) if err != nil { return InterfacesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfacesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfacesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfacesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -1137,7 +1216,10 @@ func (client *InterfacesClient) updateTagsCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/interfacetapconfigurations_client.go b/sdk/resourcemanager/network/armnetwork/interfacetapconfigurations_client.go index 4f7c1bbcb948..d19ac9c5919d 100644 --- a/sdk/resourcemanager/network/armnetwork/interfacetapconfigurations_client.go +++ b/sdk/resourcemanager/network/armnetwork/interfacetapconfigurations_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 armnetwork @@ -61,9 +60,10 @@ func (client *InterfaceTapConfigurationsClient) BeginCreateOrUpdate(ctx context. if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfaceTapConfigurationsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfaceTapConfigurationsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InterfaceTapConfigurationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *InterfaceTapConfigurationsClient) BeginCreateOrUpdate(ctx context. // // Generated from API version 2022-11-01 func (client *InterfaceTapConfigurationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkInterfaceName string, tapConfigurationName string, tapConfigurationParameters InterfaceTapConfiguration, options *InterfaceTapConfigurationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "InterfaceTapConfigurationsClient.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, networkInterfaceName, tapConfigurationName, tapConfigurationParameters, 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. @@ -115,7 +121,10 @@ func (client *InterfaceTapConfigurationsClient) createOrUpdateCreateRequest(ctx reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, tapConfigurationParameters) + if err := runtime.MarshalAsJSON(req, tapConfigurationParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified tap configuration from the NetworkInterface. @@ -133,9 +142,10 @@ func (client *InterfaceTapConfigurationsClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfaceTapConfigurationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InterfaceTapConfigurationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[InterfaceTapConfigurationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *InterfaceTapConfigurationsClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-11-01 func (client *InterfaceTapConfigurationsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkInterfaceName string, tapConfigurationName string, options *InterfaceTapConfigurationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "InterfaceTapConfigurationsClient.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, networkInterfaceName, tapConfigurationName, 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. @@ -200,18 +216,25 @@ func (client *InterfaceTapConfigurationsClient) deleteCreateRequest(ctx context. // - options - InterfaceTapConfigurationsClientGetOptions contains the optional parameters for the InterfaceTapConfigurationsClient.Get // method. func (client *InterfaceTapConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, tapConfigurationName string, options *InterfaceTapConfigurationsClientGetOptions) (InterfaceTapConfigurationsClientGetResponse, error) { + var err error + const operationName = "InterfaceTapConfigurationsClient.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, networkInterfaceName, tapConfigurationName, options) if err != nil { return InterfaceTapConfigurationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return InterfaceTapConfigurationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return InterfaceTapConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return InterfaceTapConfigurationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *InterfaceTapConfigurationsClient) NewListPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *InterfaceTapConfigurationsClientListResponse) (InterfaceTapConfigurationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfaceTapConfigurationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *InterfaceTapConfigurationsClient) NewListPager(resourceGroupName s } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/ipallocations_client.go b/sdk/resourcemanager/network/armnetwork/ipallocations_client.go index 0fc1c5287881..585a3dcbb6e7 100644 --- a/sdk/resourcemanager/network/armnetwork/ipallocations_client.go +++ b/sdk/resourcemanager/network/armnetwork/ipallocations_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 armnetwork @@ -60,9 +59,10 @@ func (client *IPAllocationsClient) BeginCreateOrUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPAllocationsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPAllocationsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[IPAllocationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *IPAllocationsClient) BeginCreateOrUpdate(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *IPAllocationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, ipAllocationName string, parameters IPAllocation, options *IPAllocationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "IPAllocationsClient.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, ipAllocationName, 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. @@ -110,7 +116,10 @@ func (client *IPAllocationsClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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 the specified IpAllocation. @@ -127,9 +136,10 @@ func (client *IPAllocationsClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPAllocationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPAllocationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[IPAllocationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *IPAllocationsClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2022-11-01 func (client *IPAllocationsClient) deleteOperation(ctx context.Context, resourceGroupName string, ipAllocationName string, options *IPAllocationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "IPAllocationsClient.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, ipAllocationName, 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 *IPAllocationsClient) deleteCreateRequest(ctx context.Context, reso // - ipAllocationName - The name of the IpAllocation. // - options - IPAllocationsClientGetOptions contains the optional parameters for the IPAllocationsClient.Get method. func (client *IPAllocationsClient) Get(ctx context.Context, resourceGroupName string, ipAllocationName string, options *IPAllocationsClientGetOptions) (IPAllocationsClientGetResponse, error) { + var err error + const operationName = "IPAllocationsClient.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, ipAllocationName, options) if err != nil { return IPAllocationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return IPAllocationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return IPAllocationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return IPAllocationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *IPAllocationsClient) NewListPager(options *IPAllocationsClientList return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *IPAllocationsClientListResponse) (IPAllocationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "IPAllocationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *IPAllocationsClient) NewListPager(options *IPAllocationsClientList } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -311,6 +336,7 @@ func (client *IPAllocationsClient) NewListByResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *IPAllocationsClientListByResourceGroupResponse) (IPAllocationsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "IPAllocationsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -330,6 +356,7 @@ func (client *IPAllocationsClient) NewListByResourceGroupPager(resourceGroupName } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -374,18 +401,25 @@ func (client *IPAllocationsClient) listByResourceGroupHandleResponse(resp *http. // - options - IPAllocationsClientUpdateTagsOptions contains the optional parameters for the IPAllocationsClient.UpdateTags // method. func (client *IPAllocationsClient) UpdateTags(ctx context.Context, resourceGroupName string, ipAllocationName string, parameters TagsObject, options *IPAllocationsClientUpdateTagsOptions) (IPAllocationsClientUpdateTagsResponse, error) { + var err error + const operationName = "IPAllocationsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, ipAllocationName, parameters, options) if err != nil { return IPAllocationsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return IPAllocationsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return IPAllocationsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return IPAllocationsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -411,7 +445,10 @@ func (client *IPAllocationsClient) updateTagsCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/ipgroups_client.go b/sdk/resourcemanager/network/armnetwork/ipgroups_client.go index 06ca172507c8..61c2e59672a3 100644 --- a/sdk/resourcemanager/network/armnetwork/ipgroups_client.go +++ b/sdk/resourcemanager/network/armnetwork/ipgroups_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 armnetwork @@ -60,9 +59,10 @@ func (client *IPGroupsClient) BeginCreateOrUpdate(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPGroupsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPGroupsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[IPGroupsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *IPGroupsClient) BeginCreateOrUpdate(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *IPGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, ipGroupsName string, parameters IPGroup, options *IPGroupsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "IPGroupsClient.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, ipGroupsName, 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. @@ -110,7 +116,10 @@ func (client *IPGroupsClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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 the specified ipGroups. @@ -126,9 +135,10 @@ func (client *IPGroupsClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPGroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[IPGroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[IPGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *IPGroupsClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *IPGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, ipGroupsName string, options *IPGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "IPGroupsClient.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, ipGroupsName, 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. @@ -187,18 +203,25 @@ func (client *IPGroupsClient) deleteCreateRequest(ctx context.Context, resourceG // - ipGroupsName - The name of the ipGroups. // - options - IPGroupsClientGetOptions contains the optional parameters for the IPGroupsClient.Get method. func (client *IPGroupsClient) Get(ctx context.Context, resourceGroupName string, ipGroupsName string, options *IPGroupsClientGetOptions) (IPGroupsClientGetResponse, error) { + var err error + const operationName = "IPGroupsClient.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, ipGroupsName, options) if err != nil { return IPGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return IPGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return IPGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return IPGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -249,6 +272,7 @@ func (client *IPGroupsClient) NewListPager(options *IPGroupsClientListOptions) * return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *IPGroupsClientListResponse) (IPGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "IPGroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -268,6 +292,7 @@ func (client *IPGroupsClient) NewListPager(options *IPGroupsClientListOptions) * } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -310,6 +335,7 @@ func (client *IPGroupsClient) NewListByResourceGroupPager(resourceGroupName stri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *IPGroupsClientListByResourceGroupResponse) (IPGroupsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "IPGroupsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -329,6 +355,7 @@ func (client *IPGroupsClient) NewListByResourceGroupPager(resourceGroupName stri } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -372,18 +399,25 @@ func (client *IPGroupsClient) listByResourceGroupHandleResponse(resp *http.Respo // - parameters - Parameters supplied to the update ipGroups operation. // - options - IPGroupsClientUpdateGroupsOptions contains the optional parameters for the IPGroupsClient.UpdateGroups method. func (client *IPGroupsClient) UpdateGroups(ctx context.Context, resourceGroupName string, ipGroupsName string, parameters TagsObject, options *IPGroupsClientUpdateGroupsOptions) (IPGroupsClientUpdateGroupsResponse, error) { + var err error + const operationName = "IPGroupsClient.UpdateGroups" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateGroupsCreateRequest(ctx, resourceGroupName, ipGroupsName, parameters, options) if err != nil { return IPGroupsClientUpdateGroupsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return IPGroupsClientUpdateGroupsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return IPGroupsClientUpdateGroupsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return IPGroupsClientUpdateGroupsResponse{}, err } - return client.updateGroupsHandleResponse(resp) + resp, err := client.updateGroupsHandleResponse(httpResp) + return resp, err } // updateGroupsCreateRequest creates the UpdateGroups request. @@ -409,7 +443,10 @@ func (client *IPGroupsClient) updateGroupsCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2022-11-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 } // updateGroupsHandleResponse handles the UpdateGroups response. diff --git a/sdk/resourcemanager/network/armnetwork/loadbalancerbackendaddresspools_client.go b/sdk/resourcemanager/network/armnetwork/loadbalancerbackendaddresspools_client.go index 2fa8ca0badb5..387d56905524 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalancerbackendaddresspools_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalancerbackendaddresspools_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 armnetwork @@ -61,9 +60,10 @@ func (client *LoadBalancerBackendAddressPoolsClient) BeginCreateOrUpdate(ctx con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancerBackendAddressPoolsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancerBackendAddressPoolsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LoadBalancerBackendAddressPoolsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *LoadBalancerBackendAddressPoolsClient) BeginCreateOrUpdate(ctx con // // Generated from API version 2022-11-01 func (client *LoadBalancerBackendAddressPoolsClient) createOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, parameters BackendAddressPool, options *LoadBalancerBackendAddressPoolsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "LoadBalancerBackendAddressPoolsClient.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, loadBalancerName, backendAddressPoolName, 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. @@ -115,7 +121,10 @@ func (client *LoadBalancerBackendAddressPoolsClient) createOrUpdateCreateRequest reqQP.Set("api-version", "2022-11-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 the specified load balancer backend address pool. @@ -133,9 +142,10 @@ func (client *LoadBalancerBackendAddressPoolsClient) BeginDelete(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancerBackendAddressPoolsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancerBackendAddressPoolsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LoadBalancerBackendAddressPoolsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *LoadBalancerBackendAddressPoolsClient) BeginDelete(ctx context.Con // // Generated from API version 2022-11-01 func (client *LoadBalancerBackendAddressPoolsClient) deleteOperation(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, options *LoadBalancerBackendAddressPoolsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "LoadBalancerBackendAddressPoolsClient.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, loadBalancerName, backendAddressPoolName, 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. @@ -200,18 +216,25 @@ func (client *LoadBalancerBackendAddressPoolsClient) deleteCreateRequest(ctx con // - options - LoadBalancerBackendAddressPoolsClientGetOptions contains the optional parameters for the LoadBalancerBackendAddressPoolsClient.Get // method. func (client *LoadBalancerBackendAddressPoolsClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, options *LoadBalancerBackendAddressPoolsClientGetOptions) (LoadBalancerBackendAddressPoolsClientGetResponse, error) { + var err error + const operationName = "LoadBalancerBackendAddressPoolsClient.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, loadBalancerName, backendAddressPoolName, options) if err != nil { return LoadBalancerBackendAddressPoolsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancerBackendAddressPoolsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancerBackendAddressPoolsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancerBackendAddressPoolsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *LoadBalancerBackendAddressPoolsClient) NewListPager(resourceGroupN return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancerBackendAddressPoolsClientListResponse) (LoadBalancerBackendAddressPoolsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerBackendAddressPoolsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *LoadBalancerBackendAddressPoolsClient) NewListPager(resourceGroupN } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/loadbalancerfrontendipconfigurations_client.go b/sdk/resourcemanager/network/armnetwork/loadbalancerfrontendipconfigurations_client.go index 38aa761d5888..86a567f0b9e3 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalancerfrontendipconfigurations_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalancerfrontendipconfigurations_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 armnetwork @@ -55,18 +54,25 @@ func NewLoadBalancerFrontendIPConfigurationsClient(subscriptionID string, creden // - options - LoadBalancerFrontendIPConfigurationsClientGetOptions contains the optional parameters for the LoadBalancerFrontendIPConfigurationsClient.Get // method. func (client *LoadBalancerFrontendIPConfigurationsClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, frontendIPConfigurationName string, options *LoadBalancerFrontendIPConfigurationsClientGetOptions) (LoadBalancerFrontendIPConfigurationsClientGetResponse, error) { + var err error + const operationName = "LoadBalancerFrontendIPConfigurationsClient.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, loadBalancerName, frontendIPConfigurationName, options) if err != nil { return LoadBalancerFrontendIPConfigurationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancerFrontendIPConfigurationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancerFrontendIPConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancerFrontendIPConfigurationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *LoadBalancerFrontendIPConfigurationsClient) NewListPager(resourceG return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancerFrontendIPConfigurationsClientListResponse) (LoadBalancerFrontendIPConfigurationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerFrontendIPConfigurationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *LoadBalancerFrontendIPConfigurationsClient) NewListPager(resourceG } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/loadbalancerloadbalancingrules_client.go b/sdk/resourcemanager/network/armnetwork/loadbalancerloadbalancingrules_client.go index e27f43711c04..05f9b3258399 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalancerloadbalancingrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalancerloadbalancingrules_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 armnetwork @@ -55,18 +54,25 @@ func NewLoadBalancerLoadBalancingRulesClient(subscriptionID string, credential a // - options - LoadBalancerLoadBalancingRulesClientGetOptions contains the optional parameters for the LoadBalancerLoadBalancingRulesClient.Get // method. func (client *LoadBalancerLoadBalancingRulesClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, loadBalancingRuleName string, options *LoadBalancerLoadBalancingRulesClientGetOptions) (LoadBalancerLoadBalancingRulesClientGetResponse, error) { + var err error + const operationName = "LoadBalancerLoadBalancingRulesClient.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, loadBalancerName, loadBalancingRuleName, options) if err != nil { return LoadBalancerLoadBalancingRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancerLoadBalancingRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancerLoadBalancingRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancerLoadBalancingRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *LoadBalancerLoadBalancingRulesClient) NewListPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancerLoadBalancingRulesClientListResponse) (LoadBalancerLoadBalancingRulesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerLoadBalancingRulesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *LoadBalancerLoadBalancingRulesClient) NewListPager(resourceGroupNa } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/loadbalancernetworkinterfaces_client.go b/sdk/resourcemanager/network/armnetwork/loadbalancernetworkinterfaces_client.go index e1c36b3b4882..73a393d1cb97 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalancernetworkinterfaces_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalancernetworkinterfaces_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 armnetwork @@ -58,6 +57,7 @@ func (client *LoadBalancerNetworkInterfacesClient) NewListPager(resourceGroupNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancerNetworkInterfacesClientListResponse) (LoadBalancerNetworkInterfacesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerNetworkInterfacesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -77,6 +77,7 @@ func (client *LoadBalancerNetworkInterfacesClient) NewListPager(resourceGroupNam } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/loadbalanceroutboundrules_client.go b/sdk/resourcemanager/network/armnetwork/loadbalanceroutboundrules_client.go index 7862f543c090..84fed1f48fc6 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalanceroutboundrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalanceroutboundrules_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 armnetwork @@ -55,18 +54,25 @@ func NewLoadBalancerOutboundRulesClient(subscriptionID string, credential azcore // - options - LoadBalancerOutboundRulesClientGetOptions contains the optional parameters for the LoadBalancerOutboundRulesClient.Get // method. func (client *LoadBalancerOutboundRulesClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, outboundRuleName string, options *LoadBalancerOutboundRulesClientGetOptions) (LoadBalancerOutboundRulesClientGetResponse, error) { + var err error + const operationName = "LoadBalancerOutboundRulesClient.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, loadBalancerName, outboundRuleName, options) if err != nil { return LoadBalancerOutboundRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancerOutboundRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancerOutboundRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancerOutboundRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -121,6 +127,7 @@ func (client *LoadBalancerOutboundRulesClient) NewListPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancerOutboundRulesClientListResponse) (LoadBalancerOutboundRulesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerOutboundRulesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -140,6 +147,7 @@ func (client *LoadBalancerOutboundRulesClient) NewListPager(resourceGroupName st } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/loadbalancerprobes_client.go b/sdk/resourcemanager/network/armnetwork/loadbalancerprobes_client.go index bcb5af1923b6..ba7c079c461c 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalancerprobes_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalancerprobes_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 armnetwork @@ -54,18 +53,25 @@ func NewLoadBalancerProbesClient(subscriptionID string, credential azcore.TokenC // - probeName - The name of the probe. // - options - LoadBalancerProbesClientGetOptions contains the optional parameters for the LoadBalancerProbesClient.Get method. func (client *LoadBalancerProbesClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, probeName string, options *LoadBalancerProbesClientGetOptions) (LoadBalancerProbesClientGetResponse, error) { + var err error + const operationName = "LoadBalancerProbesClient.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, loadBalancerName, probeName, options) if err != nil { return LoadBalancerProbesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancerProbesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancerProbesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancerProbesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -120,6 +126,7 @@ func (client *LoadBalancerProbesClient) NewListPager(resourceGroupName string, l return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancerProbesClientListResponse) (LoadBalancerProbesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerProbesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -139,6 +146,7 @@ func (client *LoadBalancerProbesClient) NewListPager(resourceGroupName string, l } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/loadbalancers_client.go b/sdk/resourcemanager/network/armnetwork/loadbalancers_client.go index 11035ae5c03f..d7a826f9fef6 100644 --- a/sdk/resourcemanager/network/armnetwork/loadbalancers_client.go +++ b/sdk/resourcemanager/network/armnetwork/loadbalancers_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 armnetwork @@ -60,9 +59,10 @@ func (client *LoadBalancersClient) BeginCreateOrUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LoadBalancersClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *LoadBalancersClient) BeginCreateOrUpdate(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *LoadBalancersClient) createOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters LoadBalancer, options *LoadBalancersClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "LoadBalancersClient.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, loadBalancerName, 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. @@ -110,7 +116,10 @@ func (client *LoadBalancersClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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 the specified load balancer. @@ -127,9 +136,10 @@ func (client *LoadBalancersClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LoadBalancersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *LoadBalancersClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2022-11-01 func (client *LoadBalancersClient) deleteOperation(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "LoadBalancersClient.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, loadBalancerName, 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 *LoadBalancersClient) deleteCreateRequest(ctx context.Context, reso // - loadBalancerName - The name of the load balancer. // - options - LoadBalancersClientGetOptions contains the optional parameters for the LoadBalancersClient.Get method. func (client *LoadBalancersClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientGetOptions) (LoadBalancersClientGetResponse, error) { + var err error + const operationName = "LoadBalancersClient.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, loadBalancerName, options) if err != nil { return LoadBalancersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -251,6 +274,7 @@ func (client *LoadBalancersClient) NewListPager(resourceGroupName string, option return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancersClientListResponse) (LoadBalancersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -270,6 +294,7 @@ func (client *LoadBalancersClient) NewListPager(resourceGroupName string, option } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -315,6 +340,7 @@ func (client *LoadBalancersClient) NewListAllPager(options *LoadBalancersClientL return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LoadBalancersClientListAllResponse) (LoadBalancersClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancersClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -334,6 +360,7 @@ func (client *LoadBalancersClient) NewListAllPager(options *LoadBalancersClientL } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -380,9 +407,10 @@ func (client *LoadBalancersClient) BeginListInboundNatRulePortMappings(ctx conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientListInboundNatRulePortMappingsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientListInboundNatRulePortMappingsResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LoadBalancersClientListInboundNatRulePortMappingsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -393,18 +421,24 @@ func (client *LoadBalancersClient) BeginListInboundNatRulePortMappings(ctx conte // // Generated from API version 2022-11-01 func (client *LoadBalancersClient) listInboundNatRulePortMappings(ctx context.Context, groupName string, loadBalancerName string, backendPoolName string, parameters QueryInboundNatRulePortMappingRequest, options *LoadBalancersClientBeginListInboundNatRulePortMappingsOptions) (*http.Response, error) { + var err error + const operationName = "LoadBalancersClient.BeginListInboundNatRulePortMappings" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listInboundNatRulePortMappingsCreateRequest(ctx, groupName, loadBalancerName, backendPoolName, 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 } // listInboundNatRulePortMappingsCreateRequest creates the ListInboundNatRulePortMappings request. @@ -434,7 +468,10 @@ func (client *LoadBalancersClient) listInboundNatRulePortMappingsCreateRequest(c reqQP.Set("api-version", "2022-11-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 } // BeginSwapPublicIPAddresses - Swaps VIPs between two load balancers. @@ -451,9 +488,10 @@ func (client *LoadBalancersClient) BeginSwapPublicIPAddresses(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientSwapPublicIPAddressesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientSwapPublicIPAddressesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LoadBalancersClientSwapPublicIPAddressesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -464,18 +502,24 @@ func (client *LoadBalancersClient) BeginSwapPublicIPAddresses(ctx context.Contex // // Generated from API version 2022-11-01 func (client *LoadBalancersClient) swapPublicIPAddresses(ctx context.Context, location string, parameters LoadBalancerVipSwapRequest, options *LoadBalancersClientBeginSwapPublicIPAddressesOptions) (*http.Response, error) { + var err error + const operationName = "LoadBalancersClient.BeginSwapPublicIPAddresses" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.swapPublicIPAddressesCreateRequest(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 } // swapPublicIPAddressesCreateRequest creates the SwapPublicIPAddresses request. @@ -497,7 +541,10 @@ func (client *LoadBalancersClient) swapPublicIPAddressesCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-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 } // UpdateTags - Updates a load balancer tags. @@ -510,18 +557,25 @@ func (client *LoadBalancersClient) swapPublicIPAddressesCreateRequest(ctx contex // - options - LoadBalancersClientUpdateTagsOptions contains the optional parameters for the LoadBalancersClient.UpdateTags // method. func (client *LoadBalancersClient) UpdateTags(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters TagsObject, options *LoadBalancersClientUpdateTagsOptions) (LoadBalancersClientUpdateTagsResponse, error) { + var err error + const operationName = "LoadBalancersClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, loadBalancerName, parameters, options) if err != nil { return LoadBalancersClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LoadBalancersClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LoadBalancersClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LoadBalancersClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -547,7 +601,10 @@ func (client *LoadBalancersClient) updateTagsCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/localnetworkgateways_client.go b/sdk/resourcemanager/network/armnetwork/localnetworkgateways_client.go index c2d865e747c4..90ee2464c159 100644 --- a/sdk/resourcemanager/network/armnetwork/localnetworkgateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/localnetworkgateways_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 armnetwork @@ -60,9 +59,10 @@ func (client *LocalNetworkGatewaysClient) BeginCreateOrUpdate(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LocalNetworkGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LocalNetworkGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LocalNetworkGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *LocalNetworkGatewaysClient) BeginCreateOrUpdate(ctx context.Contex // // Generated from API version 2022-11-01 func (client *LocalNetworkGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters LocalNetworkGateway, options *LocalNetworkGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "LocalNetworkGatewaysClient.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, localNetworkGatewayName, 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. @@ -110,7 +116,10 @@ func (client *LocalNetworkGatewaysClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-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 the specified local network gateway. @@ -127,9 +136,10 @@ func (client *LocalNetworkGatewaysClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LocalNetworkGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LocalNetworkGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[LocalNetworkGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *LocalNetworkGatewaysClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *LocalNetworkGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "LocalNetworkGatewaysClient.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, localNetworkGatewayName, 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. @@ -189,18 +205,25 @@ func (client *LocalNetworkGatewaysClient) deleteCreateRequest(ctx context.Contex // - options - LocalNetworkGatewaysClientGetOptions contains the optional parameters for the LocalNetworkGatewaysClient.Get // method. func (client *LocalNetworkGatewaysClient) Get(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientGetOptions) (LocalNetworkGatewaysClientGetResponse, error) { + var err error + const operationName = "LocalNetworkGatewaysClient.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, localNetworkGatewayName, options) if err != nil { return LocalNetworkGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LocalNetworkGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LocalNetworkGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LocalNetworkGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *LocalNetworkGatewaysClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LocalNetworkGatewaysClientListResponse) (LocalNetworkGatewaysClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LocalNetworkGatewaysClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *LocalNetworkGatewaysClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -313,18 +338,25 @@ func (client *LocalNetworkGatewaysClient) listHandleResponse(resp *http.Response // - options - LocalNetworkGatewaysClientUpdateTagsOptions contains the optional parameters for the LocalNetworkGatewaysClient.UpdateTags // method. func (client *LocalNetworkGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters TagsObject, options *LocalNetworkGatewaysClientUpdateTagsOptions) (LocalNetworkGatewaysClientUpdateTagsResponse, error) { + var err error + const operationName = "LocalNetworkGatewaysClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, localNetworkGatewayName, parameters, options) if err != nil { return LocalNetworkGatewaysClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return LocalNetworkGatewaysClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return LocalNetworkGatewaysClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return LocalNetworkGatewaysClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -350,7 +382,10 @@ func (client *LocalNetworkGatewaysClient) updateTagsCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/management_client.go b/sdk/resourcemanager/network/armnetwork/management_client.go index 9bab86ae3c55..297655066479 100644 --- a/sdk/resourcemanager/network/armnetwork/management_client.go +++ b/sdk/resourcemanager/network/armnetwork/management_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 armnetwork @@ -55,18 +54,25 @@ func NewManagementClient(subscriptionID string, credential azcore.TokenCredentia // - options - ManagementClientCheckDNSNameAvailabilityOptions contains the optional parameters for the ManagementClient.CheckDNSNameAvailability // method. func (client *ManagementClient) CheckDNSNameAvailability(ctx context.Context, location string, domainNameLabel string, options *ManagementClientCheckDNSNameAvailabilityOptions) (ManagementClientCheckDNSNameAvailabilityResponse, error) { + var err error + const operationName = "ManagementClient.CheckDNSNameAvailability" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkDNSNameAvailabilityCreateRequest(ctx, location, domainNameLabel, options) if err != nil { return ManagementClientCheckDNSNameAvailabilityResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientCheckDNSNameAvailabilityResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientCheckDNSNameAvailabilityResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientCheckDNSNameAvailabilityResponse{}, err } - return client.checkDNSNameAvailabilityHandleResponse(resp) + resp, err := client.checkDNSNameAvailabilityHandleResponse(httpResp) + return resp, err } // checkDNSNameAvailabilityCreateRequest creates the CheckDNSNameAvailability request. @@ -116,9 +122,10 @@ func (client *ManagementClient) BeginDeleteBastionShareableLink(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagementClientDeleteBastionShareableLinkResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagementClientDeleteBastionShareableLinkResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ManagementClientDeleteBastionShareableLinkResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -129,18 +136,24 @@ func (client *ManagementClient) BeginDeleteBastionShareableLink(ctx context.Cont // // Generated from API version 2022-11-01 func (client *ManagementClient) deleteBastionShareableLink(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *ManagementClientBeginDeleteBastionShareableLinkOptions) (*http.Response, error) { + var err error + const operationName = "ManagementClient.BeginDeleteBastionShareableLink" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteBastionShareableLinkCreateRequest(ctx, resourceGroupName, bastionHostName, bslRequest, 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 } // deleteBastionShareableLinkCreateRequest creates the DeleteBastionShareableLink request. @@ -166,7 +179,10 @@ func (client *ManagementClient) deleteBastionShareableLinkCreateRequest(ctx cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, bslRequest) + if err := runtime.MarshalAsJSON(req, bslRequest); err != nil { + return nil, err + } + return req, nil } // NewDisconnectActiveSessionsPager - Returns the list of currently active sessions on the Bastion. @@ -183,6 +199,7 @@ func (client *ManagementClient) NewDisconnectActiveSessionsPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementClientDisconnectActiveSessionsResponse) (ManagementClientDisconnectActiveSessionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementClient.NewDisconnectActiveSessionsPager") var req *policy.Request var err error if page == nil { @@ -202,6 +219,7 @@ func (client *ManagementClient) NewDisconnectActiveSessionsPager(resourceGroupNa } return client.disconnectActiveSessionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -228,7 +246,10 @@ func (client *ManagementClient) disconnectActiveSessionsCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, sessionIDs) + if err := runtime.MarshalAsJSON(req, sessionIDs); err != nil { + return nil, err + } + return req, nil } // disconnectActiveSessionsHandleResponse handles the DisconnectActiveSessions response. @@ -248,18 +269,25 @@ func (client *ManagementClient) disconnectActiveSessionsHandleResponse(resp *htt // - options - ManagementClientExpressRouteProviderPortOptions contains the optional parameters for the ManagementClient.ExpressRouteProviderPort // method. func (client *ManagementClient) ExpressRouteProviderPort(ctx context.Context, providerport string, options *ManagementClientExpressRouteProviderPortOptions) (ManagementClientExpressRouteProviderPortResponse, error) { + var err error + const operationName = "ManagementClient.ExpressRouteProviderPort" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.expressRouteProviderPortCreateRequest(ctx, providerport, options) if err != nil { return ManagementClientExpressRouteProviderPortResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientExpressRouteProviderPortResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientExpressRouteProviderPortResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientExpressRouteProviderPortResponse{}, err } - return client.expressRouteProviderPortHandleResponse(resp) + resp, err := client.expressRouteProviderPortHandleResponse(httpResp) + return resp, err } // expressRouteProviderPortCreateRequest creates the ExpressRouteProviderPort request. @@ -309,9 +337,10 @@ func (client *ManagementClient) BeginGeneratevirtualwanvpnserverconfigurationvpn if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagementClientGeneratevirtualwanvpnserverconfigurationvpnprofileResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagementClientGeneratevirtualwanvpnserverconfigurationvpnprofileResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ManagementClientGeneratevirtualwanvpnserverconfigurationvpnprofileResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -323,18 +352,24 @@ func (client *ManagementClient) BeginGeneratevirtualwanvpnserverconfigurationvpn // // Generated from API version 2022-11-01 func (client *ManagementClient) generatevirtualwanvpnserverconfigurationvpnprofile(ctx context.Context, resourceGroupName string, virtualWANName string, vpnClientParams VirtualWanVPNProfileParameters, options *ManagementClientBeginGeneratevirtualwanvpnserverconfigurationvpnprofileOptions) (*http.Response, error) { + var err error + const operationName = "ManagementClient.BeginGeneratevirtualwanvpnserverconfigurationvpnprofile" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generatevirtualwanvpnserverconfigurationvpnprofileCreateRequest(ctx, resourceGroupName, virtualWANName, vpnClientParams, 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 } // generatevirtualwanvpnserverconfigurationvpnprofileCreateRequest creates the Generatevirtualwanvpnserverconfigurationvpnprofile request. @@ -360,7 +395,10 @@ func (client *ManagementClient) generatevirtualwanvpnserverconfigurationvpnprofi reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnClientParams) + if err := runtime.MarshalAsJSON(req, vpnClientParams); err != nil { + return nil, err + } + return req, nil } // BeginGetActiveSessions - Returns the list of currently active sessions on the Bastion. @@ -376,6 +414,7 @@ func (client *ManagementClient) BeginGetActiveSessions(ctx context.Context, reso return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementClientGetActiveSessionsResponse) (ManagementClientGetActiveSessionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementClient.BeginGetActiveSessions") req, err := runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) if err != nil { return ManagementClientGetActiveSessionsResponse{}, err @@ -389,16 +428,18 @@ func (client *ManagementClient) BeginGetActiveSessions(ctx context.Context, reso } return client.getActiveSessionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) if options == nil || options.ResumeToken == "" { resp, err := client.getActiveSessions(ctx, resourceGroupName, bastionHostName, options) if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[ManagementClientGetActiveSessionsResponse]]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[ManagementClientGetActiveSessionsResponse]]{ FinalStateVia: runtime.FinalStateViaLocation, Response: &pager, }) + return poller, err } else { return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[*runtime.Pager[ManagementClientGetActiveSessionsResponse]]{ Response: &pager, @@ -410,18 +451,24 @@ func (client *ManagementClient) BeginGetActiveSessions(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *ManagementClient) getActiveSessions(ctx context.Context, resourceGroupName string, bastionHostName string, options *ManagementClientBeginGetActiveSessionsOptions) (*http.Response, error) { + var err error + const operationName = "ManagementClient.BeginGetActiveSessions" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getActiveSessionsCreateRequest(ctx, resourceGroupName, bastionHostName, 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 } // getActiveSessionsCreateRequest creates the GetActiveSessions request. @@ -473,6 +520,7 @@ func (client *ManagementClient) NewGetBastionShareableLinkPager(resourceGroupNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementClientGetBastionShareableLinkResponse) (ManagementClientGetBastionShareableLinkResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementClient.NewGetBastionShareableLinkPager") var req *policy.Request var err error if page == nil { @@ -492,6 +540,7 @@ func (client *ManagementClient) NewGetBastionShareableLinkPager(resourceGroupNam } return client.getBastionShareableLinkHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -518,7 +567,10 @@ func (client *ManagementClient) getBastionShareableLinkCreateRequest(ctx context reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, bslRequest) + if err := runtime.MarshalAsJSON(req, bslRequest); err != nil { + return nil, err + } + return req, nil } // getBastionShareableLinkHandleResponse handles the GetBastionShareableLink response. @@ -540,18 +592,25 @@ func (client *ManagementClient) getBastionShareableLinkHandleResponse(resp *http // - options - ManagementClientListActiveConnectivityConfigurationsOptions contains the optional parameters for the ManagementClient.ListActiveConnectivityConfigurations // method. func (client *ManagementClient) ListActiveConnectivityConfigurations(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ActiveConfigurationParameter, options *ManagementClientListActiveConnectivityConfigurationsOptions) (ManagementClientListActiveConnectivityConfigurationsResponse, error) { + var err error + const operationName = "ManagementClient.ListActiveConnectivityConfigurations" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listActiveConnectivityConfigurationsCreateRequest(ctx, resourceGroupName, networkManagerName, parameters, options) if err != nil { return ManagementClientListActiveConnectivityConfigurationsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientListActiveConnectivityConfigurationsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientListActiveConnectivityConfigurationsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientListActiveConnectivityConfigurationsResponse{}, err } - return client.listActiveConnectivityConfigurationsHandleResponse(resp) + resp, err := client.listActiveConnectivityConfigurationsHandleResponse(httpResp) + return resp, err } // listActiveConnectivityConfigurationsCreateRequest creates the ListActiveConnectivityConfigurations request. @@ -580,7 +639,10 @@ func (client *ManagementClient) listActiveConnectivityConfigurationsCreateReques } 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 } // listActiveConnectivityConfigurationsHandleResponse handles the ListActiveConnectivityConfigurations response. @@ -602,18 +664,25 @@ func (client *ManagementClient) listActiveConnectivityConfigurationsHandleRespon // - options - ManagementClientListActiveSecurityAdminRulesOptions contains the optional parameters for the ManagementClient.ListActiveSecurityAdminRules // method. func (client *ManagementClient) ListActiveSecurityAdminRules(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ActiveConfigurationParameter, options *ManagementClientListActiveSecurityAdminRulesOptions) (ManagementClientListActiveSecurityAdminRulesResponse, error) { + var err error + const operationName = "ManagementClient.ListActiveSecurityAdminRules" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listActiveSecurityAdminRulesCreateRequest(ctx, resourceGroupName, networkManagerName, parameters, options) if err != nil { return ManagementClientListActiveSecurityAdminRulesResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientListActiveSecurityAdminRulesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientListActiveSecurityAdminRulesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientListActiveSecurityAdminRulesResponse{}, err } - return client.listActiveSecurityAdminRulesHandleResponse(resp) + resp, err := client.listActiveSecurityAdminRulesHandleResponse(httpResp) + return resp, err } // listActiveSecurityAdminRulesCreateRequest creates the ListActiveSecurityAdminRules request. @@ -642,7 +711,10 @@ func (client *ManagementClient) listActiveSecurityAdminRulesCreateRequest(ctx co } 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 } // listActiveSecurityAdminRulesHandleResponse handles the ListActiveSecurityAdminRules response. @@ -665,18 +737,25 @@ func (client *ManagementClient) listActiveSecurityAdminRulesHandleResponse(resp // - options - ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsOptions contains the optional parameters // for the ManagementClient.ListNetworkManagerEffectiveConnectivityConfigurations method. func (client *ManagementClient) ListNetworkManagerEffectiveConnectivityConfigurations(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters QueryRequestOptions, options *ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsOptions) (ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsResponse, error) { + var err error + const operationName = "ManagementClient.ListNetworkManagerEffectiveConnectivityConfigurations" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listNetworkManagerEffectiveConnectivityConfigurationsCreateRequest(ctx, resourceGroupName, virtualNetworkName, parameters, options) if err != nil { return ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientListNetworkManagerEffectiveConnectivityConfigurationsResponse{}, err } - return client.listNetworkManagerEffectiveConnectivityConfigurationsHandleResponse(resp) + resp, err := client.listNetworkManagerEffectiveConnectivityConfigurationsHandleResponse(httpResp) + return resp, err } // listNetworkManagerEffectiveConnectivityConfigurationsCreateRequest creates the ListNetworkManagerEffectiveConnectivityConfigurations request. @@ -705,7 +784,10 @@ func (client *ManagementClient) listNetworkManagerEffectiveConnectivityConfigura } 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 } // listNetworkManagerEffectiveConnectivityConfigurationsHandleResponse handles the ListNetworkManagerEffectiveConnectivityConfigurations response. @@ -727,18 +809,25 @@ func (client *ManagementClient) listNetworkManagerEffectiveConnectivityConfigura // - options - ManagementClientListNetworkManagerEffectiveSecurityAdminRulesOptions contains the optional parameters for the // ManagementClient.ListNetworkManagerEffectiveSecurityAdminRules method. func (client *ManagementClient) ListNetworkManagerEffectiveSecurityAdminRules(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters QueryRequestOptions, options *ManagementClientListNetworkManagerEffectiveSecurityAdminRulesOptions) (ManagementClientListNetworkManagerEffectiveSecurityAdminRulesResponse, error) { + var err error + const operationName = "ManagementClient.ListNetworkManagerEffectiveSecurityAdminRules" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listNetworkManagerEffectiveSecurityAdminRulesCreateRequest(ctx, resourceGroupName, virtualNetworkName, parameters, options) if err != nil { return ManagementClientListNetworkManagerEffectiveSecurityAdminRulesResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientListNetworkManagerEffectiveSecurityAdminRulesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientListNetworkManagerEffectiveSecurityAdminRulesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientListNetworkManagerEffectiveSecurityAdminRulesResponse{}, err } - return client.listNetworkManagerEffectiveSecurityAdminRulesHandleResponse(resp) + resp, err := client.listNetworkManagerEffectiveSecurityAdminRulesHandleResponse(httpResp) + return resp, err } // listNetworkManagerEffectiveSecurityAdminRulesCreateRequest creates the ListNetworkManagerEffectiveSecurityAdminRules request. @@ -767,7 +856,10 @@ func (client *ManagementClient) listNetworkManagerEffectiveSecurityAdminRulesCre } 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 } // listNetworkManagerEffectiveSecurityAdminRulesHandleResponse handles the ListNetworkManagerEffectiveSecurityAdminRules response. @@ -793,6 +885,7 @@ func (client *ManagementClient) BeginPutBastionShareableLink(ctx context.Context return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementClientPutBastionShareableLinkResponse) (ManagementClientPutBastionShareableLinkResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementClient.BeginPutBastionShareableLink") req, err := runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) if err != nil { return ManagementClientPutBastionShareableLinkResponse{}, err @@ -806,16 +899,18 @@ func (client *ManagementClient) BeginPutBastionShareableLink(ctx context.Context } return client.putBastionShareableLinkHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) if options == nil || options.ResumeToken == "" { resp, err := client.putBastionShareableLink(ctx, resourceGroupName, bastionHostName, bslRequest, options) if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[ManagementClientPutBastionShareableLinkResponse]]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[ManagementClientPutBastionShareableLinkResponse]]{ FinalStateVia: runtime.FinalStateViaLocation, Response: &pager, }) + return poller, err } else { return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[*runtime.Pager[ManagementClientPutBastionShareableLinkResponse]]{ Response: &pager, @@ -827,18 +922,24 @@ func (client *ManagementClient) BeginPutBastionShareableLink(ctx context.Context // // Generated from API version 2022-11-01 func (client *ManagementClient) putBastionShareableLink(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *ManagementClientBeginPutBastionShareableLinkOptions) (*http.Response, error) { + var err error + const operationName = "ManagementClient.BeginPutBastionShareableLink" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.putBastionShareableLinkCreateRequest(ctx, resourceGroupName, bastionHostName, bslRequest, 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 } // putBastionShareableLinkCreateRequest creates the PutBastionShareableLink request. @@ -864,7 +965,10 @@ func (client *ManagementClient) putBastionShareableLinkCreateRequest(ctx context reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, bslRequest) + if err := runtime.MarshalAsJSON(req, bslRequest); err != nil { + return nil, err + } + return req, nil } // putBastionShareableLinkHandleResponse handles the PutBastionShareableLink response. @@ -885,18 +989,25 @@ func (client *ManagementClient) putBastionShareableLinkHandleResponse(resp *http // - options - ManagementClientSupportedSecurityProvidersOptions contains the optional parameters for the ManagementClient.SupportedSecurityProviders // method. func (client *ManagementClient) SupportedSecurityProviders(ctx context.Context, resourceGroupName string, virtualWANName string, options *ManagementClientSupportedSecurityProvidersOptions) (ManagementClientSupportedSecurityProvidersResponse, error) { + var err error + const operationName = "ManagementClient.SupportedSecurityProviders" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.supportedSecurityProvidersCreateRequest(ctx, resourceGroupName, virtualWANName, options) if err != nil { return ManagementClientSupportedSecurityProvidersResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementClientSupportedSecurityProvidersResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementClientSupportedSecurityProvidersResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementClientSupportedSecurityProvidersResponse{}, err } - return client.supportedSecurityProvidersHandleResponse(resp) + resp, err := client.supportedSecurityProvidersHandleResponse(httpResp) + return resp, err } // supportedSecurityProvidersCreateRequest creates the SupportedSecurityProviders request. diff --git a/sdk/resourcemanager/network/armnetwork/managementgroupnetworkmanagerconnections_client.go b/sdk/resourcemanager/network/armnetwork/managementgroupnetworkmanagerconnections_client.go index e77721203344..2934ac5250cb 100644 --- a/sdk/resourcemanager/network/armnetwork/managementgroupnetworkmanagerconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/managementgroupnetworkmanagerconnections_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 armnetwork @@ -52,18 +51,25 @@ func NewManagementGroupNetworkManagerConnectionsClient(credential azcore.TokenCr // - options - ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateOptions contains the optional parameters for the // ManagementGroupNetworkManagerConnectionsClient.CreateOrUpdate method. func (client *ManagementGroupNetworkManagerConnectionsClient) CreateOrUpdate(ctx context.Context, managementGroupID string, networkManagerConnectionName string, parameters ManagerConnection, options *ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateOptions) (ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ManagementGroupNetworkManagerConnectionsClient.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, managementGroupID, networkManagerConnectionName, parameters, options) if err != nil { return ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ManagementGroupNetworkManagerConnectionsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -85,7 +91,10 @@ func (client *ManagementGroupNetworkManagerConnectionsClient) createOrUpdateCrea reqQP.Set("api-version", "2022-11-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. @@ -106,16 +115,22 @@ func (client *ManagementGroupNetworkManagerConnectionsClient) createOrUpdateHand // - options - ManagementGroupNetworkManagerConnectionsClientDeleteOptions contains the optional parameters for the ManagementGroupNetworkManagerConnectionsClient.Delete // method. func (client *ManagementGroupNetworkManagerConnectionsClient) Delete(ctx context.Context, managementGroupID string, networkManagerConnectionName string, options *ManagementGroupNetworkManagerConnectionsClientDeleteOptions) (ManagementGroupNetworkManagerConnectionsClientDeleteResponse, error) { + var err error + const operationName = "ManagementGroupNetworkManagerConnectionsClient.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, managementGroupID, networkManagerConnectionName, options) if err != nil { return ManagementGroupNetworkManagerConnectionsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementGroupNetworkManagerConnectionsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ManagementGroupNetworkManagerConnectionsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ManagementGroupNetworkManagerConnectionsClientDeleteResponse{}, err } return ManagementGroupNetworkManagerConnectionsClientDeleteResponse{}, nil } @@ -151,18 +166,25 @@ func (client *ManagementGroupNetworkManagerConnectionsClient) deleteCreateReques // - options - ManagementGroupNetworkManagerConnectionsClientGetOptions contains the optional parameters for the ManagementGroupNetworkManagerConnectionsClient.Get // method. func (client *ManagementGroupNetworkManagerConnectionsClient) Get(ctx context.Context, managementGroupID string, networkManagerConnectionName string, options *ManagementGroupNetworkManagerConnectionsClientGetOptions) (ManagementGroupNetworkManagerConnectionsClientGetResponse, error) { + var err error + const operationName = "ManagementGroupNetworkManagerConnectionsClient.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, managementGroupID, networkManagerConnectionName, options) if err != nil { return ManagementGroupNetworkManagerConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementGroupNetworkManagerConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementGroupNetworkManagerConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementGroupNetworkManagerConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -208,6 +230,7 @@ func (client *ManagementGroupNetworkManagerConnectionsClient) NewListPager(manag return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementGroupNetworkManagerConnectionsClientListResponse) (ManagementGroupNetworkManagerConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementGroupNetworkManagerConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -227,6 +250,7 @@ func (client *ManagementGroupNetworkManagerConnectionsClient) NewListPager(manag } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/managercommits_client.go b/sdk/resourcemanager/network/armnetwork/managercommits_client.go index 1d3dd894bc02..1ad47120b424 100644 --- a/sdk/resourcemanager/network/armnetwork/managercommits_client.go +++ b/sdk/resourcemanager/network/armnetwork/managercommits_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 armnetwork @@ -60,9 +59,10 @@ func (client *ManagerCommitsClient) BeginPost(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagerCommitsClientPostResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagerCommitsClientPostResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ManagerCommitsClientPostResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ManagerCommitsClient) BeginPost(ctx context.Context, resourceGroup // // Generated from API version 2022-11-01 func (client *ManagerCommitsClient) post(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ManagerCommit, options *ManagerCommitsClientBeginPostOptions) (*http.Response, error) { + var err error + const operationName = "ManagerCommitsClient.BeginPost" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.postCreateRequest(ctx, resourceGroupName, networkManagerName, 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 } // postCreateRequest creates the Post request. @@ -110,5 +116,8 @@ func (client *ManagerCommitsClient) postCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-11-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/network/armnetwork/managerdeploymentstatus_client.go b/sdk/resourcemanager/network/armnetwork/managerdeploymentstatus_client.go index e57c6dae55d4..917d3da57afe 100644 --- a/sdk/resourcemanager/network/armnetwork/managerdeploymentstatus_client.go +++ b/sdk/resourcemanager/network/armnetwork/managerdeploymentstatus_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 armnetwork @@ -56,18 +55,25 @@ func NewManagerDeploymentStatusClient(subscriptionID string, credential azcore.T // - options - ManagerDeploymentStatusClientListOptions contains the optional parameters for the ManagerDeploymentStatusClient.List // method. func (client *ManagerDeploymentStatusClient) List(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ManagerDeploymentStatusParameter, options *ManagerDeploymentStatusClientListOptions) (ManagerDeploymentStatusClientListResponse, error) { + var err error + const operationName = "ManagerDeploymentStatusClient.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, networkManagerName, parameters, options) if err != nil { return ManagerDeploymentStatusClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagerDeploymentStatusClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagerDeploymentStatusClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagerDeploymentStatusClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -96,7 +102,10 @@ func (client *ManagerDeploymentStatusClient) listCreateRequest(ctx context.Conte } 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 } // listHandleResponse handles the List response. diff --git a/sdk/resourcemanager/network/armnetwork/managers_client.go b/sdk/resourcemanager/network/armnetwork/managers_client.go index 455b820eb621..d51f26b3dda9 100644 --- a/sdk/resourcemanager/network/armnetwork/managers_client.go +++ b/sdk/resourcemanager/network/armnetwork/managers_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 armnetwork @@ -55,18 +54,25 @@ func NewManagersClient(subscriptionID string, credential azcore.TokenCredential, // - parameters - Parameters supplied to specify which network manager is. // - options - ManagersClientCreateOrUpdateOptions contains the optional parameters for the ManagersClient.CreateOrUpdate method. func (client *ManagersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, parameters Manager, options *ManagersClientCreateOrUpdateOptions) (ManagersClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ManagersClient.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, networkManagerName, parameters, options) if err != nil { return ManagersClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagersClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ManagersClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ManagersClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -92,7 +98,10 @@ func (client *ManagersClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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,9 +126,10 @@ func (client *ManagersClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagersClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagersClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ManagersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -130,18 +140,24 @@ func (client *ManagersClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *ManagersClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, options *ManagersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ManagersClient.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, networkManagerName, 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 *ManagersClient) deleteCreateRequest(ctx context.Context, resourceG // - networkManagerName - The name of the network manager. // - options - ManagersClientGetOptions contains the optional parameters for the ManagersClient.Get method. func (client *ManagersClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, options *ManagersClientGetOptions) (ManagersClientGetResponse, error) { + var err error + const operationName = "ManagersClient.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, networkManagerName, options) if err != nil { return ManagersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -241,6 +264,7 @@ func (client *ManagersClient) NewListPager(resourceGroupName string, options *Ma return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagersClientListResponse) (ManagersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -260,6 +284,7 @@ func (client *ManagersClient) NewListPager(resourceGroupName string, options *Ma } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -311,6 +336,7 @@ func (client *ManagersClient) NewListBySubscriptionPager(options *ManagersClient return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagersClientListBySubscriptionResponse) (ManagersClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagersClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -330,6 +356,7 @@ func (client *ManagersClient) NewListBySubscriptionPager(options *ManagersClient } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -375,18 +402,25 @@ func (client *ManagersClient) listBySubscriptionHandleResponse(resp *http.Respon // - parameters - Parameters supplied to specify which network manager is. // - options - ManagersClientPatchOptions contains the optional parameters for the ManagersClient.Patch method. func (client *ManagersClient) Patch(ctx context.Context, resourceGroupName string, networkManagerName string, parameters PatchObject, options *ManagersClientPatchOptions) (ManagersClientPatchResponse, error) { + var err error + const operationName = "ManagersClient.Patch" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.patchCreateRequest(ctx, resourceGroupName, networkManagerName, parameters, options) if err != nil { return ManagersClientPatchResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagersClientPatchResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagersClientPatchResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagersClientPatchResponse{}, err } - return client.patchHandleResponse(resp) + resp, err := client.patchHandleResponse(httpResp) + return resp, err } // patchCreateRequest creates the Patch request. @@ -412,7 +446,10 @@ func (client *ManagersClient) patchCreateRequest(ctx context.Context, resourceGr reqQP.Set("api-version", "2022-11-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 } // patchHandleResponse handles the Patch response. diff --git a/sdk/resourcemanager/network/armnetwork/models.go b/sdk/resourcemanager/network/armnetwork/models.go index 42ec7fb9a0a2..1e17d40ca332 100644 --- a/sdk/resourcemanager/network/armnetwork/models.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork diff --git a/sdk/resourcemanager/network/armnetwork/models_serde.go b/sdk/resourcemanager/network/armnetwork/models_serde.go index c9a95a03c050..1919290714fc 100644 --- a/sdk/resourcemanager/network/armnetwork/models_serde.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork diff --git a/sdk/resourcemanager/network/armnetwork/natgateways_client.go b/sdk/resourcemanager/network/armnetwork/natgateways_client.go index 090faf30a43b..79c51a020b61 100644 --- a/sdk/resourcemanager/network/armnetwork/natgateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/natgateways_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 armnetwork @@ -60,9 +59,10 @@ func (client *NatGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[NatGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *NatGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *NatGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, natGatewayName string, parameters NatGateway, options *NatGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "NatGatewaysClient.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, natGatewayName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -110,7 +116,10 @@ func (client *NatGatewaysClient) createOrUpdateCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-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 the specified nat gateway. @@ -126,9 +135,10 @@ func (client *NatGatewaysClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[NatGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *NatGatewaysClient) BeginDelete(ctx context.Context, resourceGroupN // // Generated from API version 2022-11-01 func (client *NatGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, natGatewayName string, options *NatGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "NatGatewaysClient.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, natGatewayName, 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. @@ -187,18 +203,25 @@ func (client *NatGatewaysClient) deleteCreateRequest(ctx context.Context, resour // - natGatewayName - The name of the nat gateway. // - options - NatGatewaysClientGetOptions contains the optional parameters for the NatGatewaysClient.Get method. func (client *NatGatewaysClient) Get(ctx context.Context, resourceGroupName string, natGatewayName string, options *NatGatewaysClientGetOptions) (NatGatewaysClientGetResponse, error) { + var err error + const operationName = "NatGatewaysClient.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, natGatewayName, options) if err != nil { return NatGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return NatGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return NatGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return NatGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *NatGatewaysClient) NewListPager(resourceGroupName string, options return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *NatGatewaysClientListResponse) (NatGatewaysClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "NatGatewaysClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *NatGatewaysClient) NewListPager(resourceGroupName string, options } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -313,6 +338,7 @@ func (client *NatGatewaysClient) NewListAllPager(options *NatGatewaysClientListA return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *NatGatewaysClientListAllResponse) (NatGatewaysClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "NatGatewaysClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -332,6 +358,7 @@ func (client *NatGatewaysClient) NewListAllPager(options *NatGatewaysClientListA } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -371,18 +398,25 @@ func (client *NatGatewaysClient) listAllHandleResponse(resp *http.Response) (Nat // - parameters - Parameters supplied to update nat gateway tags. // - options - NatGatewaysClientUpdateTagsOptions contains the optional parameters for the NatGatewaysClient.UpdateTags method. func (client *NatGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, natGatewayName string, parameters TagsObject, options *NatGatewaysClientUpdateTagsOptions) (NatGatewaysClientUpdateTagsResponse, error) { + var err error + const operationName = "NatGatewaysClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, natGatewayName, parameters, options) if err != nil { return NatGatewaysClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return NatGatewaysClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return NatGatewaysClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return NatGatewaysClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -408,7 +442,10 @@ func (client *NatGatewaysClient) updateTagsCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/natrules_client.go b/sdk/resourcemanager/network/armnetwork/natrules_client.go index 2abc00afee85..a6ecc88d421a 100644 --- a/sdk/resourcemanager/network/armnetwork/natrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/natrules_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 armnetwork @@ -61,9 +60,10 @@ func (client *NatRulesClient) BeginCreateOrUpdate(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatRulesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatRulesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[NatRulesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *NatRulesClient) BeginCreateOrUpdate(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *NatRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, natRuleName string, natRuleParameters VPNGatewayNatRule, options *NatRulesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "NatRulesClient.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, gatewayName, natRuleName, natRuleParameters, 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. @@ -115,7 +121,10 @@ func (client *NatRulesClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, natRuleParameters) + if err := runtime.MarshalAsJSON(req, natRuleParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a nat rule. @@ -132,9 +141,10 @@ func (client *NatRulesClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatRulesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NatRulesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[NatRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -145,18 +155,24 @@ func (client *NatRulesClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *NatRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, gatewayName string, natRuleName string, options *NatRulesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "NatRulesClient.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, gatewayName, natRuleName, 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. @@ -198,18 +214,25 @@ func (client *NatRulesClient) deleteCreateRequest(ctx context.Context, resourceG // - natRuleName - The name of the nat rule. // - options - NatRulesClientGetOptions contains the optional parameters for the NatRulesClient.Get method. func (client *NatRulesClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, natRuleName string, options *NatRulesClientGetOptions) (NatRulesClientGetResponse, error) { + var err error + const operationName = "NatRulesClient.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, gatewayName, natRuleName, options) if err != nil { return NatRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return NatRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return NatRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return NatRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -264,6 +287,7 @@ func (client *NatRulesClient) NewListByVPNGatewayPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *NatRulesClientListByVPNGatewayResponse) (NatRulesClientListByVPNGatewayResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "NatRulesClient.NewListByVPNGatewayPager") var req *policy.Request var err error if page == nil { @@ -283,6 +307,7 @@ func (client *NatRulesClient) NewListByVPNGatewayPager(resourceGroupName string, } return client.listByVPNGatewayHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/operations_client.go b/sdk/resourcemanager/network/armnetwork/operations_client.go index f88e76558566..fe55c3724f27 100644 --- a/sdk/resourcemanager/network/armnetwork/operations_client.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork @@ -48,6 +47,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -67,6 +67,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/p2svpngateways_client.go b/sdk/resourcemanager/network/armnetwork/p2svpngateways_client.go index e6037f698ecd..7e8e5603502a 100644 --- a/sdk/resourcemanager/network/armnetwork/p2svpngateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/p2svpngateways_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 armnetwork @@ -60,9 +59,10 @@ func (client *P2SVPNGatewaysClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *P2SVPNGatewaysClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, p2SVPNGatewayParameters P2SVPNGateway, options *P2SVPNGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.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, gatewayName, p2SVPNGatewayParameters, 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. @@ -110,7 +116,10 @@ func (client *P2SVPNGatewaysClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, p2SVPNGatewayParameters) + if err := runtime.MarshalAsJSON(req, p2SVPNGatewayParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a virtual wan p2s vpn gateway. @@ -127,9 +136,10 @@ func (client *P2SVPNGatewaysClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *P2SVPNGatewaysClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, gatewayName string, options *P2SVPNGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.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, gatewayName, 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,9 +212,10 @@ func (client *P2SVPNGatewaysClient) BeginDisconnectP2SVPNConnections(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientDisconnectP2SVPNConnectionsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientDisconnectP2SVPNConnectionsResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientDisconnectP2SVPNConnectionsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -210,18 +227,24 @@ func (client *P2SVPNGatewaysClient) BeginDisconnectP2SVPNConnections(ctx context // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) disconnectP2SVPNConnections(ctx context.Context, resourceGroupName string, p2SVPNGatewayName string, request P2SVPNConnectionRequest, options *P2SVPNGatewaysClientBeginDisconnectP2SVPNConnectionsOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.BeginDisconnectP2SVPNConnections" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.disconnectP2SVPNConnectionsCreateRequest(ctx, resourceGroupName, p2SVPNGatewayName, request, 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 } // disconnectP2SVPNConnectionsCreateRequest creates the DisconnectP2SVPNConnections request. @@ -247,7 +270,10 @@ func (client *P2SVPNGatewaysClient) disconnectP2SVPNConnectionsCreateRequest(ctx reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, request) + if err := runtime.MarshalAsJSON(req, request); err != nil { + return nil, err + } + return req, nil } // BeginGenerateVPNProfile - Generates VPN profile for P2S client of the P2SVpnGateway in the specified resource group. @@ -265,9 +291,10 @@ func (client *P2SVPNGatewaysClient) BeginGenerateVPNProfile(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientGenerateVPNProfileResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientGenerateVPNProfileResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientGenerateVPNProfileResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -278,18 +305,24 @@ func (client *P2SVPNGatewaysClient) BeginGenerateVPNProfile(ctx context.Context, // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) generateVPNProfile(ctx context.Context, resourceGroupName string, gatewayName string, parameters P2SVPNProfileParameters, options *P2SVPNGatewaysClientBeginGenerateVPNProfileOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.BeginGenerateVPNProfile" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generateVPNProfileCreateRequest(ctx, resourceGroupName, gatewayName, 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 } // generateVPNProfileCreateRequest creates the GenerateVPNProfile request. @@ -315,7 +348,10 @@ func (client *P2SVPNGatewaysClient) generateVPNProfileCreateRequest(ctx context. reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // Get - Retrieves the details of a virtual wan p2s vpn gateway. @@ -326,18 +362,25 @@ func (client *P2SVPNGatewaysClient) generateVPNProfileCreateRequest(ctx context. // - gatewayName - The name of the gateway. // - options - P2SVPNGatewaysClientGetOptions contains the optional parameters for the P2SVPNGatewaysClient.Get method. func (client *P2SVPNGatewaysClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, options *P2SVPNGatewaysClientGetOptions) (P2SVPNGatewaysClientGetResponse, error) { + var err error + const operationName = "P2SVPNGatewaysClient.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, gatewayName, options) if err != nil { return P2SVPNGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return P2SVPNGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return P2SVPNGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return P2SVPNGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -390,9 +433,10 @@ func (client *P2SVPNGatewaysClient) BeginGetP2SVPNConnectionHealth(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientGetP2SVPNConnectionHealthResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientGetP2SVPNConnectionHealthResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientGetP2SVPNConnectionHealthResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -404,18 +448,24 @@ func (client *P2SVPNGatewaysClient) BeginGetP2SVPNConnectionHealth(ctx context.C // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) getP2SVPNConnectionHealth(ctx context.Context, resourceGroupName string, gatewayName string, options *P2SVPNGatewaysClientBeginGetP2SVPNConnectionHealthOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.BeginGetP2SVPNConnectionHealth" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getP2SVPNConnectionHealthCreateRequest(ctx, resourceGroupName, gatewayName, 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 } // getP2SVPNConnectionHealthCreateRequest creates the GetP2SVPNConnectionHealth request. @@ -460,9 +510,10 @@ func (client *P2SVPNGatewaysClient) BeginGetP2SVPNConnectionHealthDetailed(ctx c if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientGetP2SVPNConnectionHealthDetailedResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientGetP2SVPNConnectionHealthDetailedResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientGetP2SVPNConnectionHealthDetailedResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -474,18 +525,24 @@ func (client *P2SVPNGatewaysClient) BeginGetP2SVPNConnectionHealthDetailed(ctx c // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) getP2SVPNConnectionHealthDetailed(ctx context.Context, resourceGroupName string, gatewayName string, request P2SVPNConnectionHealthRequest, options *P2SVPNGatewaysClientBeginGetP2SVPNConnectionHealthDetailedOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.BeginGetP2SVPNConnectionHealthDetailed" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getP2SVPNConnectionHealthDetailedCreateRequest(ctx, resourceGroupName, gatewayName, request, 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 } // getP2SVPNConnectionHealthDetailedCreateRequest creates the GetP2SVPNConnectionHealthDetailed request. @@ -511,7 +568,10 @@ func (client *P2SVPNGatewaysClient) getP2SVPNConnectionHealthDetailedCreateReque reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, request) + if err := runtime.MarshalAsJSON(req, request); err != nil { + return nil, err + } + return req, nil } // NewListPager - Lists all the P2SVpnGateways in a subscription. @@ -524,6 +584,7 @@ func (client *P2SVPNGatewaysClient) NewListPager(options *P2SVPNGatewaysClientLi return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *P2SVPNGatewaysClientListResponse) (P2SVPNGatewaysClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "P2SVPNGatewaysClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -543,6 +604,7 @@ func (client *P2SVPNGatewaysClient) NewListPager(options *P2SVPNGatewaysClientLi } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -585,6 +647,7 @@ func (client *P2SVPNGatewaysClient) NewListByResourceGroupPager(resourceGroupNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *P2SVPNGatewaysClientListByResourceGroupResponse) (P2SVPNGatewaysClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "P2SVPNGatewaysClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -604,6 +667,7 @@ func (client *P2SVPNGatewaysClient) NewListByResourceGroupPager(resourceGroupNam } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -652,9 +716,10 @@ func (client *P2SVPNGatewaysClient) BeginReset(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientResetResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientResetResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientResetResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -665,18 +730,24 @@ func (client *P2SVPNGatewaysClient) BeginReset(ctx context.Context, resourceGrou // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) reset(ctx context.Context, resourceGroupName string, gatewayName string, options *P2SVPNGatewaysClientBeginResetOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.BeginReset" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetCreateRequest(ctx, resourceGroupName, gatewayName, 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 } // resetCreateRequest creates the Reset request. @@ -720,9 +791,10 @@ func (client *P2SVPNGatewaysClient) BeginUpdateTags(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[P2SVPNGatewaysClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[P2SVPNGatewaysClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -733,18 +805,24 @@ func (client *P2SVPNGatewaysClient) BeginUpdateTags(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *P2SVPNGatewaysClient) updateTags(ctx context.Context, resourceGroupName string, gatewayName string, p2SVPNGatewayParameters TagsObject, options *P2SVPNGatewaysClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "P2SVPNGatewaysClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, gatewayName, p2SVPNGatewayParameters, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -770,5 +848,8 @@ func (client *P2SVPNGatewaysClient) updateTagsCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, p2SVPNGatewayParameters) + if err := runtime.MarshalAsJSON(req, p2SVPNGatewayParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/network/armnetwork/packetcaptures_client.go b/sdk/resourcemanager/network/armnetwork/packetcaptures_client.go index a0320efbfe44..71a837080297 100644 --- a/sdk/resourcemanager/network/armnetwork/packetcaptures_client.go +++ b/sdk/resourcemanager/network/armnetwork/packetcaptures_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 armnetwork @@ -61,9 +60,10 @@ func (client *PacketCapturesClient) BeginCreate(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientCreateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientCreateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PacketCapturesClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *PacketCapturesClient) BeginCreate(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *PacketCapturesClient) create(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, parameters PacketCapture, options *PacketCapturesClientBeginCreateOptions) (*http.Response, error) { + var err error + const operationName = "PacketCapturesClient.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, networkWatcherName, packetCaptureName, 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. @@ -115,7 +121,10 @@ func (client *PacketCapturesClient) createCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2022-11-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 the specified packet capture session. @@ -133,9 +142,10 @@ func (client *PacketCapturesClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PacketCapturesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *PacketCapturesClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *PacketCapturesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "PacketCapturesClient.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, networkWatcherName, packetCaptureName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -199,18 +215,25 @@ func (client *PacketCapturesClient) deleteCreateRequest(ctx context.Context, res // - packetCaptureName - The name of the packet capture session. // - options - PacketCapturesClientGetOptions contains the optional parameters for the PacketCapturesClient.Get method. func (client *PacketCapturesClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientGetOptions) (PacketCapturesClientGetResponse, error) { + var err error + const operationName = "PacketCapturesClient.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, networkWatcherName, packetCaptureName, options) if err != nil { return PacketCapturesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PacketCapturesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PacketCapturesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PacketCapturesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -267,9 +290,10 @@ func (client *PacketCapturesClient) BeginGetStatus(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientGetStatusResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientGetStatusResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PacketCapturesClientGetStatusResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -280,18 +304,24 @@ func (client *PacketCapturesClient) BeginGetStatus(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *PacketCapturesClient) getStatus(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginGetStatusOptions) (*http.Response, error) { + var err error + const operationName = "PacketCapturesClient.BeginGetStatus" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getStatusCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, 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 } // getStatusCreateRequest creates the GetStatus request. @@ -336,6 +366,7 @@ func (client *PacketCapturesClient) NewListPager(resourceGroupName string, netwo return false }, Fetcher: func(ctx context.Context, page *PacketCapturesClientListResponse) (PacketCapturesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PacketCapturesClient.NewListPager") req, err := client.listCreateRequest(ctx, resourceGroupName, networkWatcherName, options) if err != nil { return PacketCapturesClientListResponse{}, err @@ -349,6 +380,7 @@ func (client *PacketCapturesClient) NewListPager(resourceGroupName string, netwo } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -402,9 +434,10 @@ func (client *PacketCapturesClient) BeginStop(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientStopResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PacketCapturesClientStopResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PacketCapturesClientStopResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -415,18 +448,24 @@ func (client *PacketCapturesClient) BeginStop(ctx context.Context, resourceGroup // // Generated from API version 2022-11-01 func (client *PacketCapturesClient) stop(ctx context.Context, resourceGroupName string, networkWatcherName string, packetCaptureName string, options *PacketCapturesClientBeginStopOptions) (*http.Response, error) { + var err error + const operationName = "PacketCapturesClient.BeginStop" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopCreateRequest(ctx, resourceGroupName, networkWatcherName, packetCaptureName, 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 } // stopCreateRequest creates the Stop request. diff --git a/sdk/resourcemanager/network/armnetwork/peerexpressroutecircuitconnections_client.go b/sdk/resourcemanager/network/armnetwork/peerexpressroutecircuitconnections_client.go index eb49f2c0302d..79ffed970ff8 100644 --- a/sdk/resourcemanager/network/armnetwork/peerexpressroutecircuitconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/peerexpressroutecircuitconnections_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 armnetwork @@ -56,18 +55,25 @@ func NewPeerExpressRouteCircuitConnectionsClient(subscriptionID string, credenti // - options - PeerExpressRouteCircuitConnectionsClientGetOptions contains the optional parameters for the PeerExpressRouteCircuitConnectionsClient.Get // method. func (client *PeerExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *PeerExpressRouteCircuitConnectionsClientGetOptions) (PeerExpressRouteCircuitConnectionsClientGetResponse, error) { + var err error + const operationName = "PeerExpressRouteCircuitConnectionsClient.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, circuitName, peeringName, connectionName, options) if err != nil { return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PeerExpressRouteCircuitConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -127,6 +133,7 @@ func (client *PeerExpressRouteCircuitConnectionsClient) NewListPager(resourceGro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PeerExpressRouteCircuitConnectionsClientListResponse) (PeerExpressRouteCircuitConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PeerExpressRouteCircuitConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -146,6 +153,7 @@ func (client *PeerExpressRouteCircuitConnectionsClient) NewListPager(resourceGro } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/polymorphic_helpers.go b/sdk/resourcemanager/network/armnetwork/polymorphic_helpers.go index 882756d3f505..0f6cd182a473 100644 --- a/sdk/resourcemanager/network/armnetwork/polymorphic_helpers.go +++ b/sdk/resourcemanager/network/armnetwork/polymorphic_helpers.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 armnetwork @@ -28,7 +27,10 @@ func unmarshalActiveBaseSecurityAdminRuleClassification(rawMsg json.RawMessage) default: b = &ActiveBaseSecurityAdminRule{} } - return b, json.Unmarshal(rawMsg, b) + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil } func unmarshalActiveBaseSecurityAdminRuleClassificationArray(rawMsg json.RawMessage) ([]ActiveBaseSecurityAdminRuleClassification, error) { @@ -67,7 +69,10 @@ func unmarshalBaseAdminRuleClassification(rawMsg json.RawMessage) (BaseAdminRule default: b = &BaseAdminRule{} } - return b, json.Unmarshal(rawMsg, b) + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil } func unmarshalBaseAdminRuleClassificationArray(rawMsg json.RawMessage) ([]BaseAdminRuleClassification, error) { @@ -106,7 +111,10 @@ func unmarshalEffectiveBaseSecurityAdminRuleClassification(rawMsg json.RawMessag default: b = &EffectiveBaseSecurityAdminRule{} } - return b, json.Unmarshal(rawMsg, b) + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil } func unmarshalEffectiveBaseSecurityAdminRuleClassificationArray(rawMsg json.RawMessage) ([]EffectiveBaseSecurityAdminRuleClassification, error) { @@ -147,7 +155,10 @@ func unmarshalFirewallPolicyRuleClassification(rawMsg json.RawMessage) (Firewall default: b = &FirewallPolicyRule{} } - return b, json.Unmarshal(rawMsg, b) + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil } func unmarshalFirewallPolicyRuleClassificationArray(rawMsg json.RawMessage) ([]FirewallPolicyRuleClassification, error) { @@ -186,7 +197,10 @@ func unmarshalFirewallPolicyRuleCollectionClassification(rawMsg json.RawMessage) default: b = &FirewallPolicyRuleCollection{} } - return b, json.Unmarshal(rawMsg, b) + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil } func unmarshalFirewallPolicyRuleCollectionClassificationArray(rawMsg json.RawMessage) ([]FirewallPolicyRuleCollectionClassification, error) { diff --git a/sdk/resourcemanager/network/armnetwork/privatednszonegroups_client.go b/sdk/resourcemanager/network/armnetwork/privatednszonegroups_client.go index a8abb7b5a824..48112aa59ece 100644 --- a/sdk/resourcemanager/network/armnetwork/privatednszonegroups_client.go +++ b/sdk/resourcemanager/network/armnetwork/privatednszonegroups_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 armnetwork @@ -61,9 +60,10 @@ func (client *PrivateDNSZoneGroupsClient) BeginCreateOrUpdate(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateDNSZoneGroupsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateDNSZoneGroupsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateDNSZoneGroupsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *PrivateDNSZoneGroupsClient) BeginCreateOrUpdate(ctx context.Contex // // Generated from API version 2022-11-01 func (client *PrivateDNSZoneGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, privateEndpointName string, privateDNSZoneGroupName string, parameters PrivateDNSZoneGroup, options *PrivateDNSZoneGroupsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "PrivateDNSZoneGroupsClient.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, privateEndpointName, privateDNSZoneGroupName, 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. @@ -115,7 +121,10 @@ func (client *PrivateDNSZoneGroupsClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-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 the specified private dns zone group. @@ -133,9 +142,10 @@ func (client *PrivateDNSZoneGroupsClient) BeginDelete(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateDNSZoneGroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateDNSZoneGroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateDNSZoneGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *PrivateDNSZoneGroupsClient) BeginDelete(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *PrivateDNSZoneGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, privateEndpointName string, privateDNSZoneGroupName string, options *PrivateDNSZoneGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "PrivateDNSZoneGroupsClient.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, privateEndpointName, privateDNSZoneGroupName, 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. @@ -200,18 +216,25 @@ func (client *PrivateDNSZoneGroupsClient) deleteCreateRequest(ctx context.Contex // - options - PrivateDNSZoneGroupsClientGetOptions contains the optional parameters for the PrivateDNSZoneGroupsClient.Get // method. func (client *PrivateDNSZoneGroupsClient) Get(ctx context.Context, resourceGroupName string, privateEndpointName string, privateDNSZoneGroupName string, options *PrivateDNSZoneGroupsClientGetOptions) (PrivateDNSZoneGroupsClientGetResponse, error) { + var err error + const operationName = "PrivateDNSZoneGroupsClient.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, privateEndpointName, privateDNSZoneGroupName, options) if err != nil { return PrivateDNSZoneGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PrivateDNSZoneGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PrivateDNSZoneGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PrivateDNSZoneGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *PrivateDNSZoneGroupsClient) NewListPager(privateEndpointName strin return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateDNSZoneGroupsClientListResponse) (PrivateDNSZoneGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateDNSZoneGroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *PrivateDNSZoneGroupsClient) NewListPager(privateEndpointName strin } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/privateendpoints_client.go b/sdk/resourcemanager/network/armnetwork/privateendpoints_client.go index ab60d1ac4159..e96804e26255 100644 --- a/sdk/resourcemanager/network/armnetwork/privateendpoints_client.go +++ b/sdk/resourcemanager/network/armnetwork/privateendpoints_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 armnetwork @@ -60,9 +59,10 @@ func (client *PrivateEndpointsClient) BeginCreateOrUpdate(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateEndpointsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateEndpointsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateEndpointsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *PrivateEndpointsClient) BeginCreateOrUpdate(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *PrivateEndpointsClient) createOrUpdate(ctx context.Context, resourceGroupName string, privateEndpointName string, parameters PrivateEndpoint, options *PrivateEndpointsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "PrivateEndpointsClient.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, privateEndpointName, 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. @@ -110,7 +116,10 @@ func (client *PrivateEndpointsClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 the specified private endpoint. @@ -127,9 +136,10 @@ func (client *PrivateEndpointsClient) BeginDelete(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateEndpointsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateEndpointsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateEndpointsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *PrivateEndpointsClient) BeginDelete(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *PrivateEndpointsClient) deleteOperation(ctx context.Context, resourceGroupName string, privateEndpointName string, options *PrivateEndpointsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "PrivateEndpointsClient.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, privateEndpointName, 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 *PrivateEndpointsClient) deleteCreateRequest(ctx context.Context, r // - privateEndpointName - The name of the private endpoint. // - options - PrivateEndpointsClientGetOptions contains the optional parameters for the PrivateEndpointsClient.Get method. func (client *PrivateEndpointsClient) Get(ctx context.Context, resourceGroupName string, privateEndpointName string, options *PrivateEndpointsClientGetOptions) (PrivateEndpointsClientGetResponse, error) { + var err error + const operationName = "PrivateEndpointsClient.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, privateEndpointName, options) if err != nil { return PrivateEndpointsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PrivateEndpointsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PrivateEndpointsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PrivateEndpointsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -252,6 +275,7 @@ func (client *PrivateEndpointsClient) NewListPager(resourceGroupName string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateEndpointsClientListResponse) (PrivateEndpointsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateEndpointsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -271,6 +295,7 @@ func (client *PrivateEndpointsClient) NewListPager(resourceGroupName string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -316,6 +341,7 @@ func (client *PrivateEndpointsClient) NewListBySubscriptionPager(options *Privat return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateEndpointsClientListBySubscriptionResponse) (PrivateEndpointsClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateEndpointsClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -335,6 +361,7 @@ func (client *PrivateEndpointsClient) NewListBySubscriptionPager(options *Privat } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/privatelinkservices_client.go b/sdk/resourcemanager/network/armnetwork/privatelinkservices_client.go index ad13b3403a06..b150fa5fb43d 100644 --- a/sdk/resourcemanager/network/armnetwork/privatelinkservices_client.go +++ b/sdk/resourcemanager/network/armnetwork/privatelinkservices_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 armnetwork @@ -59,9 +58,10 @@ func (client *PrivateLinkServicesClient) BeginCheckPrivateLinkServiceVisibility( if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *PrivateLinkServicesClient) BeginCheckPrivateLinkServiceVisibility( // // Generated from API version 2022-11-01 func (client *PrivateLinkServicesClient) checkPrivateLinkServiceVisibility(ctx context.Context, location string, parameters CheckPrivateLinkServiceVisibilityRequest, options *PrivateLinkServicesClientBeginCheckPrivateLinkServiceVisibilityOptions) (*http.Response, error) { + var err error + const operationName = "PrivateLinkServicesClient.BeginCheckPrivateLinkServiceVisibility" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkPrivateLinkServiceVisibilityCreateRequest(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 } // checkPrivateLinkServiceVisibilityCreateRequest creates the CheckPrivateLinkServiceVisibility request. @@ -105,7 +111,10 @@ func (client *PrivateLinkServicesClient) checkPrivateLinkServiceVisibilityCreate reqQP.Set("api-version", "2022-11-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 } // BeginCheckPrivateLinkServiceVisibilityByResourceGroup - Checks whether the subscription is visible to private link service @@ -124,9 +133,10 @@ func (client *PrivateLinkServicesClient) BeginCheckPrivateLinkServiceVisibilityB if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityByResourceGroupResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityByResourceGroupResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateLinkServicesClientCheckPrivateLinkServiceVisibilityByResourceGroupResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -138,18 +148,24 @@ func (client *PrivateLinkServicesClient) BeginCheckPrivateLinkServiceVisibilityB // // Generated from API version 2022-11-01 func (client *PrivateLinkServicesClient) checkPrivateLinkServiceVisibilityByResourceGroup(ctx context.Context, location string, resourceGroupName string, parameters CheckPrivateLinkServiceVisibilityRequest, options *PrivateLinkServicesClientBeginCheckPrivateLinkServiceVisibilityByResourceGroupOptions) (*http.Response, error) { + var err error + const operationName = "PrivateLinkServicesClient.BeginCheckPrivateLinkServiceVisibilityByResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkPrivateLinkServiceVisibilityByResourceGroupCreateRequest(ctx, location, resourceGroupName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // checkPrivateLinkServiceVisibilityByResourceGroupCreateRequest creates the CheckPrivateLinkServiceVisibilityByResourceGroup request. @@ -175,7 +191,10 @@ func (client *PrivateLinkServicesClient) checkPrivateLinkServiceVisibilityByReso reqQP.Set("api-version", "2022-11-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 - Creates or updates an private link service in the specified resource group. @@ -193,9 +212,10 @@ func (client *PrivateLinkServicesClient) BeginCreateOrUpdate(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateLinkServicesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -206,18 +226,24 @@ func (client *PrivateLinkServicesClient) BeginCreateOrUpdate(ctx context.Context // // Generated from API version 2022-11-01 func (client *PrivateLinkServicesClient) createOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, parameters PrivateLinkService, options *PrivateLinkServicesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "PrivateLinkServicesClient.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, serviceName, 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. @@ -243,7 +269,10 @@ func (client *PrivateLinkServicesClient) createOrUpdateCreateRequest(ctx context reqQP.Set("api-version", "2022-11-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 the specified private link service. @@ -260,9 +289,10 @@ func (client *PrivateLinkServicesClient) BeginDelete(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateLinkServicesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -273,18 +303,24 @@ func (client *PrivateLinkServicesClient) BeginDelete(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *PrivateLinkServicesClient) deleteOperation(ctx context.Context, resourceGroupName string, serviceName string, options *PrivateLinkServicesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "PrivateLinkServicesClient.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, serviceName, 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. @@ -328,9 +364,10 @@ func (client *PrivateLinkServicesClient) BeginDeletePrivateEndpointConnection(ct if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientDeletePrivateEndpointConnectionResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateLinkServicesClientDeletePrivateEndpointConnectionResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PrivateLinkServicesClientDeletePrivateEndpointConnectionResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -341,18 +378,24 @@ func (client *PrivateLinkServicesClient) BeginDeletePrivateEndpointConnection(ct // // Generated from API version 2022-11-01 func (client *PrivateLinkServicesClient) deletePrivateEndpointConnection(ctx context.Context, resourceGroupName string, serviceName string, peConnectionName string, options *PrivateLinkServicesClientBeginDeletePrivateEndpointConnectionOptions) (*http.Response, error) { + var err error + const operationName = "PrivateLinkServicesClient.BeginDeletePrivateEndpointConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deletePrivateEndpointConnectionCreateRequest(ctx, resourceGroupName, serviceName, peConnectionName, 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 } // deletePrivateEndpointConnectionCreateRequest creates the DeletePrivateEndpointConnection request. @@ -393,18 +436,25 @@ func (client *PrivateLinkServicesClient) deletePrivateEndpointConnectionCreateRe // - serviceName - The name of the private link service. // - options - PrivateLinkServicesClientGetOptions contains the optional parameters for the PrivateLinkServicesClient.Get method. func (client *PrivateLinkServicesClient) Get(ctx context.Context, resourceGroupName string, serviceName string, options *PrivateLinkServicesClientGetOptions) (PrivateLinkServicesClientGetResponse, error) { + var err error + const operationName = "PrivateLinkServicesClient.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, serviceName, options) if err != nil { return PrivateLinkServicesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PrivateLinkServicesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PrivateLinkServicesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PrivateLinkServicesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -456,18 +506,25 @@ func (client *PrivateLinkServicesClient) getHandleResponse(resp *http.Response) // - options - PrivateLinkServicesClientGetPrivateEndpointConnectionOptions contains the optional parameters for the PrivateLinkServicesClient.GetPrivateEndpointConnection // method. func (client *PrivateLinkServicesClient) GetPrivateEndpointConnection(ctx context.Context, resourceGroupName string, serviceName string, peConnectionName string, options *PrivateLinkServicesClientGetPrivateEndpointConnectionOptions) (PrivateLinkServicesClientGetPrivateEndpointConnectionResponse, error) { + var err error + const operationName = "PrivateLinkServicesClient.GetPrivateEndpointConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getPrivateEndpointConnectionCreateRequest(ctx, resourceGroupName, serviceName, peConnectionName, options) if err != nil { return PrivateLinkServicesClientGetPrivateEndpointConnectionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PrivateLinkServicesClientGetPrivateEndpointConnectionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PrivateLinkServicesClientGetPrivateEndpointConnectionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PrivateLinkServicesClientGetPrivateEndpointConnectionResponse{}, err } - return client.getPrivateEndpointConnectionHandleResponse(resp) + resp, err := client.getPrivateEndpointConnectionHandleResponse(httpResp) + return resp, err } // getPrivateEndpointConnectionCreateRequest creates the GetPrivateEndpointConnection request. @@ -524,6 +581,7 @@ func (client *PrivateLinkServicesClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateLinkServicesClientListResponse) (PrivateLinkServicesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateLinkServicesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -543,6 +601,7 @@ func (client *PrivateLinkServicesClient) NewListPager(resourceGroupName string, } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -590,6 +649,7 @@ func (client *PrivateLinkServicesClient) NewListAutoApprovedPrivateLinkServicesP return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesResponse) (PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateLinkServicesClient.NewListAutoApprovedPrivateLinkServicesPager") var req *policy.Request var err error if page == nil { @@ -609,6 +669,7 @@ func (client *PrivateLinkServicesClient) NewListAutoApprovedPrivateLinkServicesP } return client.listAutoApprovedPrivateLinkServicesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -657,6 +718,7 @@ func (client *PrivateLinkServicesClient) NewListAutoApprovedPrivateLinkServicesB return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesByResourceGroupResponse) (PrivateLinkServicesClientListAutoApprovedPrivateLinkServicesByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateLinkServicesClient.NewListAutoApprovedPrivateLinkServicesByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -676,6 +738,7 @@ func (client *PrivateLinkServicesClient) NewListAutoApprovedPrivateLinkServicesB } return client.listAutoApprovedPrivateLinkServicesByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -725,6 +788,7 @@ func (client *PrivateLinkServicesClient) NewListBySubscriptionPager(options *Pri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateLinkServicesClientListBySubscriptionResponse) (PrivateLinkServicesClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateLinkServicesClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -744,6 +808,7 @@ func (client *PrivateLinkServicesClient) NewListBySubscriptionPager(options *Pri } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -787,6 +852,7 @@ func (client *PrivateLinkServicesClient) NewListPrivateEndpointConnectionsPager( return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PrivateLinkServicesClientListPrivateEndpointConnectionsResponse) (PrivateLinkServicesClientListPrivateEndpointConnectionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PrivateLinkServicesClient.NewListPrivateEndpointConnectionsPager") var req *policy.Request var err error if page == nil { @@ -806,6 +872,7 @@ func (client *PrivateLinkServicesClient) NewListPrivateEndpointConnectionsPager( } return client.listPrivateEndpointConnectionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -855,18 +922,25 @@ func (client *PrivateLinkServicesClient) listPrivateEndpointConnectionsHandleRes // - options - PrivateLinkServicesClientUpdatePrivateEndpointConnectionOptions contains the optional parameters for the PrivateLinkServicesClient.UpdatePrivateEndpointConnection // method. func (client *PrivateLinkServicesClient) UpdatePrivateEndpointConnection(ctx context.Context, resourceGroupName string, serviceName string, peConnectionName string, parameters PrivateEndpointConnection, options *PrivateLinkServicesClientUpdatePrivateEndpointConnectionOptions) (PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse, error) { + var err error + const operationName = "PrivateLinkServicesClient.UpdatePrivateEndpointConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updatePrivateEndpointConnectionCreateRequest(ctx, resourceGroupName, serviceName, peConnectionName, parameters, options) if err != nil { return PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse{}, err } - return client.updatePrivateEndpointConnectionHandleResponse(resp) + resp, err := client.updatePrivateEndpointConnectionHandleResponse(httpResp) + return resp, err } // updatePrivateEndpointConnectionCreateRequest creates the UpdatePrivateEndpointConnection request. @@ -896,7 +970,10 @@ func (client *PrivateLinkServicesClient) updatePrivateEndpointConnectionCreateRe reqQP.Set("api-version", "2022-11-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 } // updatePrivateEndpointConnectionHandleResponse handles the UpdatePrivateEndpointConnection response. diff --git a/sdk/resourcemanager/network/armnetwork/profiles_client.go b/sdk/resourcemanager/network/armnetwork/profiles_client.go index b37a9e9f85b5..b5cc5b915c3c 100644 --- a/sdk/resourcemanager/network/armnetwork/profiles_client.go +++ b/sdk/resourcemanager/network/armnetwork/profiles_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 armnetwork @@ -54,18 +53,25 @@ func NewProfilesClient(subscriptionID string, credential azcore.TokenCredential, // - parameters - Parameters supplied to the create or update network profile operation. // - options - ProfilesClientCreateOrUpdateOptions contains the optional parameters for the ProfilesClient.CreateOrUpdate method. func (client *ProfilesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkProfileName string, parameters Profile, options *ProfilesClientCreateOrUpdateOptions) (ProfilesClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ProfilesClient.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, networkProfileName, parameters, options) if err != nil { return ProfilesClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProfilesClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ProfilesClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ProfilesClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -91,7 +97,10 @@ func (client *ProfilesClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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. @@ -116,9 +125,10 @@ func (client *ProfilesClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ProfilesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ProfilesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ProfilesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -129,18 +139,24 @@ func (client *ProfilesClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *ProfilesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ProfilesClient.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, networkProfileName, 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. @@ -177,18 +193,25 @@ func (client *ProfilesClient) deleteCreateRequest(ctx context.Context, resourceG // - networkProfileName - The name of the public IP prefix. // - options - ProfilesClientGetOptions contains the optional parameters for the ProfilesClient.Get method. func (client *ProfilesClient) Get(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientGetOptions) (ProfilesClientGetResponse, error) { + var err error + const operationName = "ProfilesClient.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, networkProfileName, options) if err != nil { return ProfilesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProfilesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProfilesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProfilesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -240,6 +263,7 @@ func (client *ProfilesClient) NewListPager(resourceGroupName string, options *Pr return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ProfilesClientListResponse) (ProfilesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProfilesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -259,6 +283,7 @@ func (client *ProfilesClient) NewListPager(resourceGroupName string, options *Pr } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -303,6 +328,7 @@ func (client *ProfilesClient) NewListAllPager(options *ProfilesClientListAllOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ProfilesClientListAllResponse) (ProfilesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProfilesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -322,6 +348,7 @@ func (client *ProfilesClient) NewListAllPager(options *ProfilesClientListAllOpti } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -361,18 +388,25 @@ func (client *ProfilesClient) listAllHandleResponse(resp *http.Response) (Profil // - parameters - Parameters supplied to update network profile tags. // - options - ProfilesClientUpdateTagsOptions contains the optional parameters for the ProfilesClient.UpdateTags method. func (client *ProfilesClient) UpdateTags(ctx context.Context, resourceGroupName string, networkProfileName string, parameters TagsObject, options *ProfilesClientUpdateTagsOptions) (ProfilesClientUpdateTagsResponse, error) { + var err error + const operationName = "ProfilesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkProfileName, parameters, options) if err != nil { return ProfilesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ProfilesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProfilesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ProfilesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -398,7 +432,10 @@ func (client *ProfilesClient) updateTagsCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/publicipaddresses_client.go b/sdk/resourcemanager/network/armnetwork/publicipaddresses_client.go index 56ec24dc0734..78514f7a9905 100644 --- a/sdk/resourcemanager/network/armnetwork/publicipaddresses_client.go +++ b/sdk/resourcemanager/network/armnetwork/publicipaddresses_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 armnetwork @@ -60,9 +59,10 @@ func (client *PublicIPAddressesClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPAddressesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPAddressesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PublicIPAddressesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *PublicIPAddressesClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *PublicIPAddressesClient) createOrUpdate(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress, options *PublicIPAddressesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "PublicIPAddressesClient.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, publicIPAddressName, 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. @@ -110,7 +116,10 @@ func (client *PublicIPAddressesClient) createOrUpdateCreateRequest(ctx context.C reqQP.Set("api-version", "2022-11-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 } // BeginDdosProtectionStatus - Gets the Ddos Protection Status of a Public IP Address @@ -127,9 +136,10 @@ func (client *PublicIPAddressesClient) BeginDdosProtectionStatus(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPAddressesClientDdosProtectionStatusResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPAddressesClientDdosProtectionStatusResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PublicIPAddressesClientDdosProtectionStatusResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *PublicIPAddressesClient) BeginDdosProtectionStatus(ctx context.Con // // Generated from API version 2022-11-01 func (client *PublicIPAddressesClient) ddosProtectionStatus(ctx context.Context, resourceGroupName string, publicIPAddressName string, options *PublicIPAddressesClientBeginDdosProtectionStatusOptions) (*http.Response, error) { + var err error + const operationName = "PublicIPAddressesClient.BeginDdosProtectionStatus" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.ddosProtectionStatusCreateRequest(ctx, resourceGroupName, publicIPAddressName, 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 } // ddosProtectionStatusCreateRequest creates the DdosProtectionStatus request. @@ -194,9 +210,10 @@ func (client *PublicIPAddressesClient) BeginDelete(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPAddressesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPAddressesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PublicIPAddressesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -207,18 +224,24 @@ func (client *PublicIPAddressesClient) BeginDelete(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *PublicIPAddressesClient) deleteOperation(ctx context.Context, resourceGroupName string, publicIPAddressName string, options *PublicIPAddressesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "PublicIPAddressesClient.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, publicIPAddressName, 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. @@ -255,18 +278,25 @@ func (client *PublicIPAddressesClient) deleteCreateRequest(ctx context.Context, // - publicIPAddressName - The name of the public IP address. // - options - PublicIPAddressesClientGetOptions contains the optional parameters for the PublicIPAddressesClient.Get method. func (client *PublicIPAddressesClient) Get(ctx context.Context, resourceGroupName string, publicIPAddressName string, options *PublicIPAddressesClientGetOptions) (PublicIPAddressesClientGetResponse, error) { + var err error + const operationName = "PublicIPAddressesClient.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, publicIPAddressName, options) if err != nil { return PublicIPAddressesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PublicIPAddressesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PublicIPAddressesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublicIPAddressesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -320,18 +350,25 @@ func (client *PublicIPAddressesClient) getHandleResponse(resp *http.Response) (P // - options - PublicIPAddressesClientGetCloudServicePublicIPAddressOptions contains the optional parameters for the PublicIPAddressesClient.GetCloudServicePublicIPAddress // method. func (client *PublicIPAddressesClient) GetCloudServicePublicIPAddress(ctx context.Context, resourceGroupName string, cloudServiceName string, roleInstanceName string, networkInterfaceName string, ipConfigurationName string, publicIPAddressName string, options *PublicIPAddressesClientGetCloudServicePublicIPAddressOptions) (PublicIPAddressesClientGetCloudServicePublicIPAddressResponse, error) { + var err error + const operationName = "PublicIPAddressesClient.GetCloudServicePublicIPAddress" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getCloudServicePublicIPAddressCreateRequest(ctx, resourceGroupName, cloudServiceName, roleInstanceName, networkInterfaceName, ipConfigurationName, publicIPAddressName, options) if err != nil { return PublicIPAddressesClientGetCloudServicePublicIPAddressResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PublicIPAddressesClientGetCloudServicePublicIPAddressResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PublicIPAddressesClientGetCloudServicePublicIPAddressResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublicIPAddressesClientGetCloudServicePublicIPAddressResponse{}, err } - return client.getCloudServicePublicIPAddressHandleResponse(resp) + resp, err := client.getCloudServicePublicIPAddressHandleResponse(httpResp) + return resp, err } // getCloudServicePublicIPAddressCreateRequest creates the GetCloudServicePublicIPAddress request. @@ -401,18 +438,25 @@ func (client *PublicIPAddressesClient) getCloudServicePublicIPAddressHandleRespo // - options - PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressOptions contains the optional parameters for the // PublicIPAddressesClient.GetVirtualMachineScaleSetPublicIPAddress method. func (client *PublicIPAddressesClient) GetVirtualMachineScaleSetPublicIPAddress(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, ipConfigurationName string, publicIPAddressName string, options *PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressOptions) (PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse, error) { + var err error + const operationName = "PublicIPAddressesClient.GetVirtualMachineScaleSetPublicIPAddress" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVirtualMachineScaleSetPublicIPAddressCreateRequest(ctx, resourceGroupName, virtualMachineScaleSetName, virtualmachineIndex, networkInterfaceName, ipConfigurationName, publicIPAddressName, options) if err != nil { return PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse{}, err } - return client.getVirtualMachineScaleSetPublicIPAddressHandleResponse(resp) + resp, err := client.getVirtualMachineScaleSetPublicIPAddressHandleResponse(httpResp) + return resp, err } // getVirtualMachineScaleSetPublicIPAddressCreateRequest creates the GetVirtualMachineScaleSetPublicIPAddress request. @@ -481,6 +525,7 @@ func (client *PublicIPAddressesClient) NewListPager(resourceGroupName string, op return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPAddressesClientListResponse) (PublicIPAddressesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPAddressesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -500,6 +545,7 @@ func (client *PublicIPAddressesClient) NewListPager(resourceGroupName string, op } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -545,6 +591,7 @@ func (client *PublicIPAddressesClient) NewListAllPager(options *PublicIPAddresse return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPAddressesClientListAllResponse) (PublicIPAddressesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPAddressesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -564,6 +611,7 @@ func (client *PublicIPAddressesClient) NewListAllPager(options *PublicIPAddresse } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -607,6 +655,7 @@ func (client *PublicIPAddressesClient) NewListCloudServicePublicIPAddressesPager return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPAddressesClientListCloudServicePublicIPAddressesResponse) (PublicIPAddressesClientListCloudServicePublicIPAddressesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPAddressesClient.NewListCloudServicePublicIPAddressesPager") var req *policy.Request var err error if page == nil { @@ -626,6 +675,7 @@ func (client *PublicIPAddressesClient) NewListCloudServicePublicIPAddressesPager } return client.listCloudServicePublicIPAddressesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -681,6 +731,7 @@ func (client *PublicIPAddressesClient) NewListCloudServiceRoleInstancePublicIPAd return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPAddressesClientListCloudServiceRoleInstancePublicIPAddressesResponse) (PublicIPAddressesClientListCloudServiceRoleInstancePublicIPAddressesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPAddressesClient.NewListCloudServiceRoleInstancePublicIPAddressesPager") var req *policy.Request var err error if page == nil { @@ -700,6 +751,7 @@ func (client *PublicIPAddressesClient) NewListCloudServiceRoleInstancePublicIPAd } return client.listCloudServiceRoleInstancePublicIPAddressesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -764,6 +816,7 @@ func (client *PublicIPAddressesClient) NewListVirtualMachineScaleSetPublicIPAddr return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPAddressesClientListVirtualMachineScaleSetPublicIPAddressesResponse) (PublicIPAddressesClientListVirtualMachineScaleSetPublicIPAddressesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPAddressesClient.NewListVirtualMachineScaleSetPublicIPAddressesPager") var req *policy.Request var err error if page == nil { @@ -783,6 +836,7 @@ func (client *PublicIPAddressesClient) NewListVirtualMachineScaleSetPublicIPAddr } return client.listVirtualMachineScaleSetPublicIPAddressesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -838,6 +892,7 @@ func (client *PublicIPAddressesClient) NewListVirtualMachineScaleSetVMPublicIPAd return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPAddressesClientListVirtualMachineScaleSetVMPublicIPAddressesResponse) (PublicIPAddressesClientListVirtualMachineScaleSetVMPublicIPAddressesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPAddressesClient.NewListVirtualMachineScaleSetVMPublicIPAddressesPager") var req *policy.Request var err error if page == nil { @@ -857,6 +912,7 @@ func (client *PublicIPAddressesClient) NewListVirtualMachineScaleSetVMPublicIPAd } return client.listVirtualMachineScaleSetVMPublicIPAddressesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -917,18 +973,25 @@ func (client *PublicIPAddressesClient) listVirtualMachineScaleSetVMPublicIPAddre // - options - PublicIPAddressesClientUpdateTagsOptions contains the optional parameters for the PublicIPAddressesClient.UpdateTags // method. func (client *PublicIPAddressesClient) UpdateTags(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters TagsObject, options *PublicIPAddressesClientUpdateTagsOptions) (PublicIPAddressesClientUpdateTagsResponse, error) { + var err error + const operationName = "PublicIPAddressesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, publicIPAddressName, parameters, options) if err != nil { return PublicIPAddressesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PublicIPAddressesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PublicIPAddressesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublicIPAddressesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -954,7 +1017,10 @@ func (client *PublicIPAddressesClient) updateTagsCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/publicipprefixes_client.go b/sdk/resourcemanager/network/armnetwork/publicipprefixes_client.go index d0a6ba78aca3..74bc63332737 100644 --- a/sdk/resourcemanager/network/armnetwork/publicipprefixes_client.go +++ b/sdk/resourcemanager/network/armnetwork/publicipprefixes_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 armnetwork @@ -60,9 +59,10 @@ func (client *PublicIPPrefixesClient) BeginCreateOrUpdate(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPPrefixesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPPrefixesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PublicIPPrefixesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *PublicIPPrefixesClient) BeginCreateOrUpdate(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *PublicIPPrefixesClient) createOrUpdate(ctx context.Context, resourceGroupName string, publicIPPrefixName string, parameters PublicIPPrefix, options *PublicIPPrefixesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "PublicIPPrefixesClient.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, publicIPPrefixName, 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. @@ -110,7 +116,10 @@ func (client *PublicIPPrefixesClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 the specified public IP prefix. @@ -127,9 +136,10 @@ func (client *PublicIPPrefixesClient) BeginDelete(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPPrefixesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PublicIPPrefixesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[PublicIPPrefixesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *PublicIPPrefixesClient) BeginDelete(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *PublicIPPrefixesClient) deleteOperation(ctx context.Context, resourceGroupName string, publicIPPrefixName string, options *PublicIPPrefixesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "PublicIPPrefixesClient.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, publicIPPrefixName, 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 *PublicIPPrefixesClient) deleteCreateRequest(ctx context.Context, r // - publicIPPrefixName - The name of the public IP prefix. // - options - PublicIPPrefixesClientGetOptions contains the optional parameters for the PublicIPPrefixesClient.Get method. func (client *PublicIPPrefixesClient) Get(ctx context.Context, resourceGroupName string, publicIPPrefixName string, options *PublicIPPrefixesClientGetOptions) (PublicIPPrefixesClientGetResponse, error) { + var err error + const operationName = "PublicIPPrefixesClient.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, publicIPPrefixName, options) if err != nil { return PublicIPPrefixesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PublicIPPrefixesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PublicIPPrefixesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublicIPPrefixesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -252,6 +275,7 @@ func (client *PublicIPPrefixesClient) NewListPager(resourceGroupName string, opt return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPPrefixesClientListResponse) (PublicIPPrefixesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPPrefixesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -271,6 +295,7 @@ func (client *PublicIPPrefixesClient) NewListPager(resourceGroupName string, opt } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -316,6 +341,7 @@ func (client *PublicIPPrefixesClient) NewListAllPager(options *PublicIPPrefixesC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PublicIPPrefixesClientListAllResponse) (PublicIPPrefixesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublicIPPrefixesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -335,6 +361,7 @@ func (client *PublicIPPrefixesClient) NewListAllPager(options *PublicIPPrefixesC } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -375,18 +402,25 @@ func (client *PublicIPPrefixesClient) listAllHandleResponse(resp *http.Response) // - options - PublicIPPrefixesClientUpdateTagsOptions contains the optional parameters for the PublicIPPrefixesClient.UpdateTags // method. func (client *PublicIPPrefixesClient) UpdateTags(ctx context.Context, resourceGroupName string, publicIPPrefixName string, parameters TagsObject, options *PublicIPPrefixesClientUpdateTagsOptions) (PublicIPPrefixesClientUpdateTagsResponse, error) { + var err error + const operationName = "PublicIPPrefixesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, publicIPPrefixName, parameters, options) if err != nil { return PublicIPPrefixesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return PublicIPPrefixesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return PublicIPPrefixesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublicIPPrefixesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -412,7 +446,10 @@ func (client *PublicIPPrefixesClient) updateTagsCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/resourcenavigationlinks_client.go b/sdk/resourcemanager/network/armnetwork/resourcenavigationlinks_client.go index de0c85004f97..03a0f6ddfaba 100644 --- a/sdk/resourcemanager/network/armnetwork/resourcenavigationlinks_client.go +++ b/sdk/resourcemanager/network/armnetwork/resourcenavigationlinks_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 armnetwork @@ -55,18 +54,25 @@ func NewResourceNavigationLinksClient(subscriptionID string, credential azcore.T // - options - ResourceNavigationLinksClientListOptions contains the optional parameters for the ResourceNavigationLinksClient.List // method. func (client *ResourceNavigationLinksClient) List(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *ResourceNavigationLinksClientListOptions) (ResourceNavigationLinksClientListResponse, error) { + var err error + const operationName = "ResourceNavigationLinksClient.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, virtualNetworkName, subnetName, options) if err != nil { return ResourceNavigationLinksClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceNavigationLinksClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceNavigationLinksClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ResourceNavigationLinksClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/response_types.go b/sdk/resourcemanager/network/armnetwork/response_types.go index 7c3dbc12c52d..4cdf009ba2a9 100644 --- a/sdk/resourcemanager/network/armnetwork/response_types.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork diff --git a/sdk/resourcemanager/network/armnetwork/routefilterrules_client.go b/sdk/resourcemanager/network/armnetwork/routefilterrules_client.go index 6facebf89d54..bc1697966db6 100644 --- a/sdk/resourcemanager/network/armnetwork/routefilterrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/routefilterrules_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 armnetwork @@ -61,9 +60,10 @@ func (client *RouteFilterRulesClient) BeginCreateOrUpdate(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFilterRulesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFilterRulesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteFilterRulesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *RouteFilterRulesClient) BeginCreateOrUpdate(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *RouteFilterRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, routeFilterName string, ruleName string, routeFilterRuleParameters RouteFilterRule, options *RouteFilterRulesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "RouteFilterRulesClient.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, routeFilterName, ruleName, routeFilterRuleParameters, 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. @@ -115,7 +121,10 @@ func (client *RouteFilterRulesClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, routeFilterRuleParameters) + if err := runtime.MarshalAsJSON(req, routeFilterRuleParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified rule from a route filter. @@ -133,9 +142,10 @@ func (client *RouteFilterRulesClient) BeginDelete(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFilterRulesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFilterRulesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteFilterRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *RouteFilterRulesClient) BeginDelete(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *RouteFilterRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, routeFilterName string, ruleName string, options *RouteFilterRulesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RouteFilterRulesClient.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, routeFilterName, ruleName, 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. @@ -199,18 +215,25 @@ func (client *RouteFilterRulesClient) deleteCreateRequest(ctx context.Context, r // - ruleName - The name of the rule. // - options - RouteFilterRulesClientGetOptions contains the optional parameters for the RouteFilterRulesClient.Get method. func (client *RouteFilterRulesClient) Get(ctx context.Context, resourceGroupName string, routeFilterName string, ruleName string, options *RouteFilterRulesClientGetOptions) (RouteFilterRulesClientGetResponse, error) { + var err error + const operationName = "RouteFilterRulesClient.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, routeFilterName, ruleName, options) if err != nil { return RouteFilterRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RouteFilterRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RouteFilterRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RouteFilterRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -265,6 +288,7 @@ func (client *RouteFilterRulesClient) NewListByRouteFilterPager(resourceGroupNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RouteFilterRulesClientListByRouteFilterResponse) (RouteFilterRulesClientListByRouteFilterResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteFilterRulesClient.NewListByRouteFilterPager") var req *policy.Request var err error if page == nil { @@ -284,6 +308,7 @@ func (client *RouteFilterRulesClient) NewListByRouteFilterPager(resourceGroupNam } return client.listByRouteFilterHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/routefilters_client.go b/sdk/resourcemanager/network/armnetwork/routefilters_client.go index 46fe30df9c79..0698a8d6c446 100644 --- a/sdk/resourcemanager/network/armnetwork/routefilters_client.go +++ b/sdk/resourcemanager/network/armnetwork/routefilters_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 armnetwork @@ -60,9 +59,10 @@ func (client *RouteFiltersClient) BeginCreateOrUpdate(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFiltersClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFiltersClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteFiltersClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *RouteFiltersClient) BeginCreateOrUpdate(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *RouteFiltersClient) createOrUpdate(ctx context.Context, resourceGroupName string, routeFilterName string, routeFilterParameters RouteFilter, options *RouteFiltersClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "RouteFiltersClient.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, routeFilterName, routeFilterParameters, 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. @@ -110,7 +116,10 @@ func (client *RouteFiltersClient) createOrUpdateCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, routeFilterParameters) + if err := runtime.MarshalAsJSON(req, routeFilterParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified route filter. @@ -127,9 +136,10 @@ func (client *RouteFiltersClient) BeginDelete(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFiltersClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteFiltersClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteFiltersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *RouteFiltersClient) BeginDelete(ctx context.Context, resourceGroup // // Generated from API version 2022-11-01 func (client *RouteFiltersClient) deleteOperation(ctx context.Context, resourceGroupName string, routeFilterName string, options *RouteFiltersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RouteFiltersClient.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, routeFilterName, 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 *RouteFiltersClient) deleteCreateRequest(ctx context.Context, resou // - routeFilterName - The name of the route filter. // - options - RouteFiltersClientGetOptions contains the optional parameters for the RouteFiltersClient.Get method. func (client *RouteFiltersClient) Get(ctx context.Context, resourceGroupName string, routeFilterName string, options *RouteFiltersClientGetOptions) (RouteFiltersClientGetResponse, error) { + var err error + const operationName = "RouteFiltersClient.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, routeFilterName, options) if err != nil { return RouteFiltersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RouteFiltersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RouteFiltersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RouteFiltersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *RouteFiltersClient) NewListPager(options *RouteFiltersClientListOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RouteFiltersClientListResponse) (RouteFiltersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteFiltersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *RouteFiltersClient) NewListPager(options *RouteFiltersClientListOp } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -311,6 +336,7 @@ func (client *RouteFiltersClient) NewListByResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RouteFiltersClientListByResourceGroupResponse) (RouteFiltersClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteFiltersClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -330,6 +356,7 @@ func (client *RouteFiltersClient) NewListByResourceGroupPager(resourceGroupName } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -373,18 +400,25 @@ func (client *RouteFiltersClient) listByResourceGroupHandleResponse(resp *http.R // - parameters - Parameters supplied to update route filter tags. // - options - RouteFiltersClientUpdateTagsOptions contains the optional parameters for the RouteFiltersClient.UpdateTags method. func (client *RouteFiltersClient) UpdateTags(ctx context.Context, resourceGroupName string, routeFilterName string, parameters TagsObject, options *RouteFiltersClientUpdateTagsOptions) (RouteFiltersClientUpdateTagsResponse, error) { + var err error + const operationName = "RouteFiltersClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, routeFilterName, parameters, options) if err != nil { return RouteFiltersClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RouteFiltersClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RouteFiltersClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RouteFiltersClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -410,7 +444,10 @@ func (client *RouteFiltersClient) updateTagsCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/routemaps_client.go b/sdk/resourcemanager/network/armnetwork/routemaps_client.go index c70e7aaa465c..3c573c244bf2 100644 --- a/sdk/resourcemanager/network/armnetwork/routemaps_client.go +++ b/sdk/resourcemanager/network/armnetwork/routemaps_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 armnetwork @@ -61,9 +60,10 @@ func (client *RouteMapsClient) BeginCreateOrUpdate(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteMapsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteMapsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteMapsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *RouteMapsClient) BeginCreateOrUpdate(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *RouteMapsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, routeMapParameters RouteMap, options *RouteMapsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "RouteMapsClient.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, virtualHubName, routeMapName, routeMapParameters, 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. @@ -115,7 +121,10 @@ func (client *RouteMapsClient) createOrUpdateCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, routeMapParameters) + if err := runtime.MarshalAsJSON(req, routeMapParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a RouteMap. @@ -132,9 +141,10 @@ func (client *RouteMapsClient) BeginDelete(ctx context.Context, resourceGroupNam if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteMapsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteMapsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteMapsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -145,18 +155,24 @@ func (client *RouteMapsClient) BeginDelete(ctx context.Context, resourceGroupNam // // Generated from API version 2022-11-01 func (client *RouteMapsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RouteMapsClient.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, virtualHubName, routeMapName, 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. @@ -198,18 +214,25 @@ func (client *RouteMapsClient) deleteCreateRequest(ctx context.Context, resource // - routeMapName - The name of the RouteMap. // - options - RouteMapsClientGetOptions contains the optional parameters for the RouteMapsClient.Get method. func (client *RouteMapsClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientGetOptions) (RouteMapsClientGetResponse, error) { + var err error + const operationName = "RouteMapsClient.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, virtualHubName, routeMapName, options) if err != nil { return RouteMapsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RouteMapsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RouteMapsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RouteMapsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -263,6 +286,7 @@ func (client *RouteMapsClient) NewListPager(resourceGroupName string, virtualHub return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RouteMapsClientListResponse) (RouteMapsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteMapsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -282,6 +306,7 @@ func (client *RouteMapsClient) NewListPager(resourceGroupName string, virtualHub } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/routes_client.go b/sdk/resourcemanager/network/armnetwork/routes_client.go index e7e2499cbbb4..9ee57523953c 100644 --- a/sdk/resourcemanager/network/armnetwork/routes_client.go +++ b/sdk/resourcemanager/network/armnetwork/routes_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 armnetwork @@ -61,9 +60,10 @@ func (client *RoutesClient) BeginCreateOrUpdate(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RoutesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *RoutesClient) BeginCreateOrUpdate(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *RoutesClient) createOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters Route, options *RoutesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "RoutesClient.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, routeTableName, routeName, routeParameters, 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. @@ -115,7 +121,10 @@ func (client *RoutesClient) createOrUpdateCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, routeParameters) + if err := runtime.MarshalAsJSON(req, routeParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified route from a route table. @@ -132,9 +141,10 @@ func (client *RoutesClient) BeginDelete(ctx context.Context, resourceGroupName s if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RoutesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -145,18 +155,24 @@ func (client *RoutesClient) BeginDelete(ctx context.Context, resourceGroupName s // // Generated from API version 2022-11-01 func (client *RoutesClient) deleteOperation(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RoutesClient.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, routeTableName, routeName, 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. @@ -198,18 +214,25 @@ func (client *RoutesClient) deleteCreateRequest(ctx context.Context, resourceGro // - routeName - The name of the route. // - options - RoutesClientGetOptions contains the optional parameters for the RoutesClient.Get method. func (client *RoutesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientGetOptions) (RoutesClientGetResponse, error) { + var err error + const operationName = "RoutesClient.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, routeTableName, routeName, options) if err != nil { return RoutesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RoutesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RoutesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RoutesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -263,6 +286,7 @@ func (client *RoutesClient) NewListPager(resourceGroupName string, routeTableNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RoutesClientListResponse) (RoutesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoutesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -282,6 +306,7 @@ func (client *RoutesClient) NewListPager(resourceGroupName string, routeTableNam } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/routetables_client.go b/sdk/resourcemanager/network/armnetwork/routetables_client.go index 79711457db0f..13a0f60c9794 100644 --- a/sdk/resourcemanager/network/armnetwork/routetables_client.go +++ b/sdk/resourcemanager/network/armnetwork/routetables_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 armnetwork @@ -60,9 +59,10 @@ func (client *RouteTablesClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteTablesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteTablesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteTablesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *RouteTablesClient) BeginCreateOrUpdate(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *RouteTablesClient) createOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters RouteTable, options *RouteTablesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "RouteTablesClient.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, routeTableName, 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. @@ -110,7 +116,10 @@ func (client *RouteTablesClient) createOrUpdateCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-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 the specified route table. @@ -126,9 +135,10 @@ func (client *RouteTablesClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteTablesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteTablesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RouteTablesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *RouteTablesClient) BeginDelete(ctx context.Context, resourceGroupN // // Generated from API version 2022-11-01 func (client *RouteTablesClient) deleteOperation(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RouteTablesClient.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, routeTableName, 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. @@ -187,18 +203,25 @@ func (client *RouteTablesClient) deleteCreateRequest(ctx context.Context, resour // - routeTableName - The name of the route table. // - options - RouteTablesClientGetOptions contains the optional parameters for the RouteTablesClient.Get method. func (client *RouteTablesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientGetOptions) (RouteTablesClientGetResponse, error) { + var err error + const operationName = "RouteTablesClient.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, routeTableName, options) if err != nil { return RouteTablesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RouteTablesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RouteTablesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RouteTablesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *RouteTablesClient) NewListPager(resourceGroupName string, options return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RouteTablesClientListResponse) (RouteTablesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteTablesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *RouteTablesClient) NewListPager(resourceGroupName string, options } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -313,6 +338,7 @@ func (client *RouteTablesClient) NewListAllPager(options *RouteTablesClientListA return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RouteTablesClientListAllResponse) (RouteTablesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteTablesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -332,6 +358,7 @@ func (client *RouteTablesClient) NewListAllPager(options *RouteTablesClientListA } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -371,18 +398,25 @@ func (client *RouteTablesClient) listAllHandleResponse(resp *http.Response) (Rou // - parameters - Parameters supplied to update route table tags. // - options - RouteTablesClientUpdateTagsOptions contains the optional parameters for the RouteTablesClient.UpdateTags method. func (client *RouteTablesClient) UpdateTags(ctx context.Context, resourceGroupName string, routeTableName string, parameters TagsObject, options *RouteTablesClientUpdateTagsOptions) (RouteTablesClientUpdateTagsResponse, error) { + var err error + const operationName = "RouteTablesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, routeTableName, parameters, options) if err != nil { return RouteTablesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RouteTablesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RouteTablesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RouteTablesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -408,7 +442,10 @@ func (client *RouteTablesClient) updateTagsCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/routingintent_client.go b/sdk/resourcemanager/network/armnetwork/routingintent_client.go index 67ac90e32a47..7246d3a20f24 100644 --- a/sdk/resourcemanager/network/armnetwork/routingintent_client.go +++ b/sdk/resourcemanager/network/armnetwork/routingintent_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 armnetwork @@ -61,9 +60,10 @@ func (client *RoutingIntentClient) BeginCreateOrUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutingIntentClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutingIntentClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RoutingIntentClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *RoutingIntentClient) BeginCreateOrUpdate(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *RoutingIntentClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routingIntentName string, routingIntentParameters RoutingIntent, options *RoutingIntentClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "RoutingIntentClient.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, virtualHubName, routingIntentName, routingIntentParameters, 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. @@ -115,7 +121,10 @@ func (client *RoutingIntentClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, routingIntentParameters) + if err := runtime.MarshalAsJSON(req, routingIntentParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a RoutingIntent. @@ -133,9 +142,10 @@ func (client *RoutingIntentClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutingIntentClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutingIntentClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[RoutingIntentClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *RoutingIntentClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2022-11-01 func (client *RoutingIntentClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, routingIntentName string, options *RoutingIntentClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "RoutingIntentClient.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, virtualHubName, routingIntentName, 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. @@ -199,18 +215,25 @@ func (client *RoutingIntentClient) deleteCreateRequest(ctx context.Context, reso // - routingIntentName - The name of the RoutingIntent. // - options - RoutingIntentClientGetOptions contains the optional parameters for the RoutingIntentClient.Get method. func (client *RoutingIntentClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, routingIntentName string, options *RoutingIntentClientGetOptions) (RoutingIntentClientGetResponse, error) { + var err error + const operationName = "RoutingIntentClient.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, virtualHubName, routingIntentName, options) if err != nil { return RoutingIntentClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return RoutingIntentClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return RoutingIntentClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return RoutingIntentClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -264,6 +287,7 @@ func (client *RoutingIntentClient) NewListPager(resourceGroupName string, virtua return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RoutingIntentClientListResponse) (RoutingIntentClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoutingIntentClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -283,6 +307,7 @@ func (client *RoutingIntentClient) NewListPager(resourceGroupName string, virtua } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/scopeconnections_client.go b/sdk/resourcemanager/network/armnetwork/scopeconnections_client.go index a44dedebe222..ece094912bf7 100644 --- a/sdk/resourcemanager/network/armnetwork/scopeconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/scopeconnections_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 armnetwork @@ -57,18 +56,25 @@ func NewScopeConnectionsClient(subscriptionID string, credential azcore.TokenCre // - options - ScopeConnectionsClientCreateOrUpdateOptions contains the optional parameters for the ScopeConnectionsClient.CreateOrUpdate // method. func (client *ScopeConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, scopeConnectionName string, parameters ScopeConnection, options *ScopeConnectionsClientCreateOrUpdateOptions) (ScopeConnectionsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ScopeConnectionsClient.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, networkManagerName, scopeConnectionName, parameters, options) if err != nil { return ScopeConnectionsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ScopeConnectionsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ScopeConnectionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ScopeConnectionsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -98,7 +104,10 @@ func (client *ScopeConnectionsClient) createOrUpdateCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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. @@ -119,16 +128,22 @@ func (client *ScopeConnectionsClient) createOrUpdateHandleResponse(resp *http.Re // - scopeConnectionName - Name for the cross-tenant connection. // - options - ScopeConnectionsClientDeleteOptions contains the optional parameters for the ScopeConnectionsClient.Delete method. func (client *ScopeConnectionsClient) Delete(ctx context.Context, resourceGroupName string, networkManagerName string, scopeConnectionName string, options *ScopeConnectionsClientDeleteOptions) (ScopeConnectionsClientDeleteResponse, error) { + var err error + const operationName = "ScopeConnectionsClient.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, networkManagerName, scopeConnectionName, options) if err != nil { return ScopeConnectionsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ScopeConnectionsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ScopeConnectionsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ScopeConnectionsClientDeleteResponse{}, err } return ScopeConnectionsClientDeleteResponse{}, nil } @@ -172,18 +187,25 @@ func (client *ScopeConnectionsClient) deleteCreateRequest(ctx context.Context, r // - scopeConnectionName - Name for the cross-tenant connection. // - options - ScopeConnectionsClientGetOptions contains the optional parameters for the ScopeConnectionsClient.Get method. func (client *ScopeConnectionsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, scopeConnectionName string, options *ScopeConnectionsClientGetOptions) (ScopeConnectionsClientGetResponse, error) { + var err error + const operationName = "ScopeConnectionsClient.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, networkManagerName, scopeConnectionName, options) if err != nil { return ScopeConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ScopeConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ScopeConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ScopeConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -238,6 +260,7 @@ func (client *ScopeConnectionsClient) NewListPager(resourceGroupName string, net return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ScopeConnectionsClientListResponse) (ScopeConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ScopeConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -257,6 +280,7 @@ func (client *ScopeConnectionsClient) NewListPager(resourceGroupName string, net } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/securityadminconfigurations_client.go b/sdk/resourcemanager/network/armnetwork/securityadminconfigurations_client.go index c99f94908341..c6f2f9bf8dfc 100644 --- a/sdk/resourcemanager/network/armnetwork/securityadminconfigurations_client.go +++ b/sdk/resourcemanager/network/armnetwork/securityadminconfigurations_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 armnetwork @@ -57,18 +56,25 @@ func NewSecurityAdminConfigurationsClient(subscriptionID string, credential azco // - options - SecurityAdminConfigurationsClientCreateOrUpdateOptions contains the optional parameters for the SecurityAdminConfigurationsClient.CreateOrUpdate // method. func (client *SecurityAdminConfigurationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, securityAdminConfiguration SecurityAdminConfiguration, options *SecurityAdminConfigurationsClientCreateOrUpdateOptions) (SecurityAdminConfigurationsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "SecurityAdminConfigurationsClient.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, networkManagerName, configurationName, securityAdminConfiguration, options) if err != nil { return SecurityAdminConfigurationsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityAdminConfigurationsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return SecurityAdminConfigurationsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return SecurityAdminConfigurationsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -98,7 +104,10 @@ func (client *SecurityAdminConfigurationsClient) createOrUpdateCreateRequest(ctx reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, securityAdminConfiguration) + if err := runtime.MarshalAsJSON(req, securityAdminConfiguration); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -125,9 +134,10 @@ func (client *SecurityAdminConfigurationsClient) BeginDelete(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityAdminConfigurationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityAdminConfigurationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityAdminConfigurationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -138,18 +148,24 @@ func (client *SecurityAdminConfigurationsClient) BeginDelete(ctx context.Context // // Generated from API version 2022-11-01 func (client *SecurityAdminConfigurationsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *SecurityAdminConfigurationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SecurityAdminConfigurationsClient.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, networkManagerName, configurationName, 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 *SecurityAdminConfigurationsClient) deleteCreateRequest(ctx context // - options - SecurityAdminConfigurationsClientGetOptions contains the optional parameters for the SecurityAdminConfigurationsClient.Get // method. func (client *SecurityAdminConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *SecurityAdminConfigurationsClientGetOptions) (SecurityAdminConfigurationsClientGetResponse, error) { + var err error + const operationName = "SecurityAdminConfigurationsClient.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, networkManagerName, configurationName, options) if err != nil { return SecurityAdminConfigurationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityAdminConfigurationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SecurityAdminConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SecurityAdminConfigurationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -261,6 +284,7 @@ func (client *SecurityAdminConfigurationsClient) NewListPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SecurityAdminConfigurationsClientListResponse) (SecurityAdminConfigurationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityAdminConfigurationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -280,6 +304,7 @@ func (client *SecurityAdminConfigurationsClient) NewListPager(resourceGroupName } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/securitygroups_client.go b/sdk/resourcemanager/network/armnetwork/securitygroups_client.go index c578f4542977..0fa4696ec997 100644 --- a/sdk/resourcemanager/network/armnetwork/securitygroups_client.go +++ b/sdk/resourcemanager/network/armnetwork/securitygroups_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 armnetwork @@ -60,9 +59,10 @@ func (client *SecurityGroupsClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityGroupsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityGroupsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityGroupsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *SecurityGroupsClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *SecurityGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters SecurityGroup, options *SecurityGroupsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SecurityGroupsClient.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, networkSecurityGroupName, 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. @@ -110,7 +116,10 @@ func (client *SecurityGroupsClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-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 the specified network security group. @@ -127,9 +136,10 @@ func (client *SecurityGroupsClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityGroupsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityGroupsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *SecurityGroupsClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *SecurityGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *SecurityGroupsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SecurityGroupsClient.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, networkSecurityGroupName, 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 *SecurityGroupsClient) deleteCreateRequest(ctx context.Context, res // - networkSecurityGroupName - The name of the network security group. // - options - SecurityGroupsClientGetOptions contains the optional parameters for the SecurityGroupsClient.Get method. func (client *SecurityGroupsClient) Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *SecurityGroupsClientGetOptions) (SecurityGroupsClientGetResponse, error) { + var err error + const operationName = "SecurityGroupsClient.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, networkSecurityGroupName, options) if err != nil { return SecurityGroupsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityGroupsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SecurityGroupsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SecurityGroupsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -251,6 +274,7 @@ func (client *SecurityGroupsClient) NewListPager(resourceGroupName string, optio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SecurityGroupsClientListResponse) (SecurityGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityGroupsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -270,6 +294,7 @@ func (client *SecurityGroupsClient) NewListPager(resourceGroupName string, optio } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -315,6 +340,7 @@ func (client *SecurityGroupsClient) NewListAllPager(options *SecurityGroupsClien return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SecurityGroupsClientListAllResponse) (SecurityGroupsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityGroupsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -334,6 +360,7 @@ func (client *SecurityGroupsClient) NewListAllPager(options *SecurityGroupsClien } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -374,18 +401,25 @@ func (client *SecurityGroupsClient) listAllHandleResponse(resp *http.Response) ( // - options - SecurityGroupsClientUpdateTagsOptions contains the optional parameters for the SecurityGroupsClient.UpdateTags // method. func (client *SecurityGroupsClient) UpdateTags(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters TagsObject, options *SecurityGroupsClientUpdateTagsOptions) (SecurityGroupsClientUpdateTagsResponse, error) { + var err error + const operationName = "SecurityGroupsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkSecurityGroupName, parameters, options) if err != nil { return SecurityGroupsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityGroupsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SecurityGroupsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SecurityGroupsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -411,7 +445,10 @@ func (client *SecurityGroupsClient) updateTagsCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/securitypartnerproviders_client.go b/sdk/resourcemanager/network/armnetwork/securitypartnerproviders_client.go index fa88fbec81ce..3f549a55350b 100644 --- a/sdk/resourcemanager/network/armnetwork/securitypartnerproviders_client.go +++ b/sdk/resourcemanager/network/armnetwork/securitypartnerproviders_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 armnetwork @@ -60,9 +59,10 @@ func (client *SecurityPartnerProvidersClient) BeginCreateOrUpdate(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityPartnerProvidersClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityPartnerProvidersClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityPartnerProvidersClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *SecurityPartnerProvidersClient) BeginCreateOrUpdate(ctx context.Co // // Generated from API version 2022-11-01 func (client *SecurityPartnerProvidersClient) createOrUpdate(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, parameters SecurityPartnerProvider, options *SecurityPartnerProvidersClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SecurityPartnerProvidersClient.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, securityPartnerProviderName, 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. @@ -110,7 +116,10 @@ func (client *SecurityPartnerProvidersClient) createOrUpdateCreateRequest(ctx co reqQP.Set("api-version", "2022-11-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 the specified Security Partner Provider. @@ -127,9 +136,10 @@ func (client *SecurityPartnerProvidersClient) BeginDelete(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityPartnerProvidersClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityPartnerProvidersClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityPartnerProvidersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *SecurityPartnerProvidersClient) BeginDelete(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *SecurityPartnerProvidersClient) deleteOperation(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, options *SecurityPartnerProvidersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SecurityPartnerProvidersClient.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, securityPartnerProviderName, 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. @@ -189,18 +205,25 @@ func (client *SecurityPartnerProvidersClient) deleteCreateRequest(ctx context.Co // - options - SecurityPartnerProvidersClientGetOptions contains the optional parameters for the SecurityPartnerProvidersClient.Get // method. func (client *SecurityPartnerProvidersClient) Get(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, options *SecurityPartnerProvidersClientGetOptions) (SecurityPartnerProvidersClientGetResponse, error) { + var err error + const operationName = "SecurityPartnerProvidersClient.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, securityPartnerProviderName, options) if err != nil { return SecurityPartnerProvidersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityPartnerProvidersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SecurityPartnerProvidersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SecurityPartnerProvidersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -249,6 +272,7 @@ func (client *SecurityPartnerProvidersClient) NewListPager(options *SecurityPart return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SecurityPartnerProvidersClientListResponse) (SecurityPartnerProvidersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityPartnerProvidersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -268,6 +292,7 @@ func (client *SecurityPartnerProvidersClient) NewListPager(options *SecurityPart } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -310,6 +335,7 @@ func (client *SecurityPartnerProvidersClient) NewListByResourceGroupPager(resour return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SecurityPartnerProvidersClientListByResourceGroupResponse) (SecurityPartnerProvidersClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityPartnerProvidersClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -329,6 +355,7 @@ func (client *SecurityPartnerProvidersClient) NewListByResourceGroupPager(resour } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -373,18 +400,25 @@ func (client *SecurityPartnerProvidersClient) listByResourceGroupHandleResponse( // - options - SecurityPartnerProvidersClientUpdateTagsOptions contains the optional parameters for the SecurityPartnerProvidersClient.UpdateTags // method. func (client *SecurityPartnerProvidersClient) UpdateTags(ctx context.Context, resourceGroupName string, securityPartnerProviderName string, parameters TagsObject, options *SecurityPartnerProvidersClientUpdateTagsOptions) (SecurityPartnerProvidersClientUpdateTagsResponse, error) { + var err error + const operationName = "SecurityPartnerProvidersClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, securityPartnerProviderName, parameters, options) if err != nil { return SecurityPartnerProvidersClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityPartnerProvidersClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SecurityPartnerProvidersClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SecurityPartnerProvidersClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -410,7 +444,10 @@ func (client *SecurityPartnerProvidersClient) updateTagsCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/securityrules_client.go b/sdk/resourcemanager/network/armnetwork/securityrules_client.go index 786d903506bc..87ce9f006a0a 100644 --- a/sdk/resourcemanager/network/armnetwork/securityrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/securityrules_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 armnetwork @@ -61,9 +60,10 @@ func (client *SecurityRulesClient) BeginCreateOrUpdate(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityRulesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityRulesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityRulesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *SecurityRulesClient) BeginCreateOrUpdate(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *SecurityRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, securityRuleName string, securityRuleParameters SecurityRule, options *SecurityRulesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SecurityRulesClient.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, networkSecurityGroupName, securityRuleName, securityRuleParameters, 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. @@ -115,7 +121,10 @@ func (client *SecurityRulesClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, securityRuleParameters) + if err := runtime.MarshalAsJSON(req, securityRuleParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified network security rule. @@ -133,9 +142,10 @@ func (client *SecurityRulesClient) BeginDelete(ctx context.Context, resourceGrou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityRulesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityRulesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SecurityRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *SecurityRulesClient) BeginDelete(ctx context.Context, resourceGrou // // Generated from API version 2022-11-01 func (client *SecurityRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, securityRuleName string, options *SecurityRulesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SecurityRulesClient.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, networkSecurityGroupName, securityRuleName, 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. @@ -199,18 +215,25 @@ func (client *SecurityRulesClient) deleteCreateRequest(ctx context.Context, reso // - securityRuleName - The name of the security rule. // - options - SecurityRulesClientGetOptions contains the optional parameters for the SecurityRulesClient.Get method. func (client *SecurityRulesClient) Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, securityRuleName string, options *SecurityRulesClientGetOptions) (SecurityRulesClientGetResponse, error) { + var err error + const operationName = "SecurityRulesClient.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, networkSecurityGroupName, securityRuleName, options) if err != nil { return SecurityRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SecurityRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SecurityRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SecurityRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -264,6 +287,7 @@ func (client *SecurityRulesClient) NewListPager(resourceGroupName string, networ return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SecurityRulesClientListResponse) (SecurityRulesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityRulesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -283,6 +307,7 @@ func (client *SecurityRulesClient) NewListPager(resourceGroupName string, networ } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/serviceassociationlinks_client.go b/sdk/resourcemanager/network/armnetwork/serviceassociationlinks_client.go index 4b18602b57cc..2dccf99b7375 100644 --- a/sdk/resourcemanager/network/armnetwork/serviceassociationlinks_client.go +++ b/sdk/resourcemanager/network/armnetwork/serviceassociationlinks_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 armnetwork @@ -55,18 +54,25 @@ func NewServiceAssociationLinksClient(subscriptionID string, credential azcore.T // - options - ServiceAssociationLinksClientListOptions contains the optional parameters for the ServiceAssociationLinksClient.List // method. func (client *ServiceAssociationLinksClient) List(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *ServiceAssociationLinksClientListOptions) (ServiceAssociationLinksClientListResponse, error) { + var err error + const operationName = "ServiceAssociationLinksClient.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, virtualNetworkName, subnetName, options) if err != nil { return ServiceAssociationLinksClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ServiceAssociationLinksClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ServiceAssociationLinksClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ServiceAssociationLinksClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/serviceendpointpolicies_client.go b/sdk/resourcemanager/network/armnetwork/serviceendpointpolicies_client.go index 1444885fc018..32d114da471a 100644 --- a/sdk/resourcemanager/network/armnetwork/serviceendpointpolicies_client.go +++ b/sdk/resourcemanager/network/armnetwork/serviceendpointpolicies_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 armnetwork @@ -60,9 +59,10 @@ func (client *ServiceEndpointPoliciesClient) BeginCreateOrUpdate(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPoliciesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPoliciesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ServiceEndpointPoliciesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *ServiceEndpointPoliciesClient) BeginCreateOrUpdate(ctx context.Con // // Generated from API version 2022-11-01 func (client *ServiceEndpointPoliciesClient) createOrUpdate(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, parameters ServiceEndpointPolicy, options *ServiceEndpointPoliciesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ServiceEndpointPoliciesClient.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, serviceEndpointPolicyName, 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. @@ -110,7 +116,10 @@ func (client *ServiceEndpointPoliciesClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2022-11-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 the specified service endpoint policy. @@ -127,9 +136,10 @@ func (client *ServiceEndpointPoliciesClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPoliciesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPoliciesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ServiceEndpointPoliciesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *ServiceEndpointPoliciesClient) BeginDelete(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *ServiceEndpointPoliciesClient) deleteOperation(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, options *ServiceEndpointPoliciesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ServiceEndpointPoliciesClient.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, serviceEndpointPolicyName, 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. @@ -189,18 +205,25 @@ func (client *ServiceEndpointPoliciesClient) deleteCreateRequest(ctx context.Con // - options - ServiceEndpointPoliciesClientGetOptions contains the optional parameters for the ServiceEndpointPoliciesClient.Get // method. func (client *ServiceEndpointPoliciesClient) Get(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, options *ServiceEndpointPoliciesClientGetOptions) (ServiceEndpointPoliciesClientGetResponse, error) { + var err error + const operationName = "ServiceEndpointPoliciesClient.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, serviceEndpointPolicyName, options) if err != nil { return ServiceEndpointPoliciesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ServiceEndpointPoliciesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ServiceEndpointPoliciesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ServiceEndpointPoliciesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -252,6 +275,7 @@ func (client *ServiceEndpointPoliciesClient) NewListPager(options *ServiceEndpoi return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ServiceEndpointPoliciesClientListResponse) (ServiceEndpointPoliciesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ServiceEndpointPoliciesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -271,6 +295,7 @@ func (client *ServiceEndpointPoliciesClient) NewListPager(options *ServiceEndpoi } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -313,6 +338,7 @@ func (client *ServiceEndpointPoliciesClient) NewListByResourceGroupPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ServiceEndpointPoliciesClientListByResourceGroupResponse) (ServiceEndpointPoliciesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ServiceEndpointPoliciesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -332,6 +358,7 @@ func (client *ServiceEndpointPoliciesClient) NewListByResourceGroupPager(resourc } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -376,18 +403,25 @@ func (client *ServiceEndpointPoliciesClient) listByResourceGroupHandleResponse(r // - options - ServiceEndpointPoliciesClientUpdateTagsOptions contains the optional parameters for the ServiceEndpointPoliciesClient.UpdateTags // method. func (client *ServiceEndpointPoliciesClient) UpdateTags(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, parameters TagsObject, options *ServiceEndpointPoliciesClientUpdateTagsOptions) (ServiceEndpointPoliciesClientUpdateTagsResponse, error) { + var err error + const operationName = "ServiceEndpointPoliciesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, serviceEndpointPolicyName, parameters, options) if err != nil { return ServiceEndpointPoliciesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ServiceEndpointPoliciesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ServiceEndpointPoliciesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ServiceEndpointPoliciesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -413,7 +447,10 @@ func (client *ServiceEndpointPoliciesClient) updateTagsCreateRequest(ctx context reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/serviceendpointpolicydefinitions_client.go b/sdk/resourcemanager/network/armnetwork/serviceendpointpolicydefinitions_client.go index 400503e6ea9c..9af97f7ff05c 100644 --- a/sdk/resourcemanager/network/armnetwork/serviceendpointpolicydefinitions_client.go +++ b/sdk/resourcemanager/network/armnetwork/serviceendpointpolicydefinitions_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 armnetwork @@ -61,9 +60,10 @@ func (client *ServiceEndpointPolicyDefinitionsClient) BeginCreateOrUpdate(ctx co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPolicyDefinitionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPolicyDefinitionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ServiceEndpointPolicyDefinitionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *ServiceEndpointPolicyDefinitionsClient) BeginCreateOrUpdate(ctx co // // Generated from API version 2022-11-01 func (client *ServiceEndpointPolicyDefinitionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, serviceEndpointPolicyDefinitionName string, serviceEndpointPolicyDefinitions ServiceEndpointPolicyDefinition, options *ServiceEndpointPolicyDefinitionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ServiceEndpointPolicyDefinitionsClient.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, serviceEndpointPolicyName, serviceEndpointPolicyDefinitionName, serviceEndpointPolicyDefinitions, 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. @@ -115,7 +121,10 @@ func (client *ServiceEndpointPolicyDefinitionsClient) createOrUpdateCreateReques reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, serviceEndpointPolicyDefinitions) + if err := runtime.MarshalAsJSON(req, serviceEndpointPolicyDefinitions); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified ServiceEndpoint policy definitions. @@ -133,9 +142,10 @@ func (client *ServiceEndpointPolicyDefinitionsClient) BeginDelete(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPolicyDefinitionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ServiceEndpointPolicyDefinitionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[ServiceEndpointPolicyDefinitionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *ServiceEndpointPolicyDefinitionsClient) BeginDelete(ctx context.Co // // Generated from API version 2022-11-01 func (client *ServiceEndpointPolicyDefinitionsClient) deleteOperation(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, serviceEndpointPolicyDefinitionName string, options *ServiceEndpointPolicyDefinitionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ServiceEndpointPolicyDefinitionsClient.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, serviceEndpointPolicyName, serviceEndpointPolicyDefinitionName, 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. @@ -200,18 +216,25 @@ func (client *ServiceEndpointPolicyDefinitionsClient) deleteCreateRequest(ctx co // - options - ServiceEndpointPolicyDefinitionsClientGetOptions contains the optional parameters for the ServiceEndpointPolicyDefinitionsClient.Get // method. func (client *ServiceEndpointPolicyDefinitionsClient) Get(ctx context.Context, resourceGroupName string, serviceEndpointPolicyName string, serviceEndpointPolicyDefinitionName string, options *ServiceEndpointPolicyDefinitionsClientGetOptions) (ServiceEndpointPolicyDefinitionsClientGetResponse, error) { + var err error + const operationName = "ServiceEndpointPolicyDefinitionsClient.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, serviceEndpointPolicyName, serviceEndpointPolicyDefinitionName, options) if err != nil { return ServiceEndpointPolicyDefinitionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ServiceEndpointPolicyDefinitionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ServiceEndpointPolicyDefinitionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ServiceEndpointPolicyDefinitionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *ServiceEndpointPolicyDefinitionsClient) NewListByResourceGroupPage return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ServiceEndpointPolicyDefinitionsClientListByResourceGroupResponse) (ServiceEndpointPolicyDefinitionsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ServiceEndpointPolicyDefinitionsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *ServiceEndpointPolicyDefinitionsClient) NewListByResourceGroupPage } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/servicetaginformation_client.go b/sdk/resourcemanager/network/armnetwork/servicetaginformation_client.go index ddfa4d241657..b349f1f6012e 100644 --- a/sdk/resourcemanager/network/armnetwork/servicetaginformation_client.go +++ b/sdk/resourcemanager/network/armnetwork/servicetaginformation_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 armnetwork @@ -60,6 +59,7 @@ func (client *ServiceTagInformationClient) NewListPager(location string, options return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ServiceTagInformationClientListResponse) (ServiceTagInformationClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ServiceTagInformationClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -79,6 +79,7 @@ func (client *ServiceTagInformationClient) NewListPager(location string, options } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/servicetags_client.go b/sdk/resourcemanager/network/armnetwork/servicetags_client.go index 9a6e901e56cb..3c58a057fd14 100644 --- a/sdk/resourcemanager/network/armnetwork/servicetags_client.go +++ b/sdk/resourcemanager/network/armnetwork/servicetags_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 armnetwork @@ -54,18 +53,25 @@ func NewServiceTagsClient(subscriptionID string, credential azcore.TokenCredenti // your subscription belongs to). // - options - ServiceTagsClientListOptions contains the optional parameters for the ServiceTagsClient.List method. func (client *ServiceTagsClient) List(ctx context.Context, location string, options *ServiceTagsClientListOptions) (ServiceTagsClientListResponse, error) { + var err error + const operationName = "ServiceTagsClient.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, options) if err != nil { return ServiceTagsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ServiceTagsClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ServiceTagsClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ServiceTagsClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/staticmembers_client.go b/sdk/resourcemanager/network/armnetwork/staticmembers_client.go index b7a662f30aea..41a213d11027 100644 --- a/sdk/resourcemanager/network/armnetwork/staticmembers_client.go +++ b/sdk/resourcemanager/network/armnetwork/staticmembers_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 armnetwork @@ -58,18 +57,25 @@ func NewStaticMembersClient(subscriptionID string, credential azcore.TokenCreden // - options - StaticMembersClientCreateOrUpdateOptions contains the optional parameters for the StaticMembersClient.CreateOrUpdate // method. func (client *StaticMembersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, staticMemberName string, parameters StaticMember, options *StaticMembersClientCreateOrUpdateOptions) (StaticMembersClientCreateOrUpdateResponse, error) { + var err error + const operationName = "StaticMembersClient.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, networkManagerName, networkGroupName, staticMemberName, parameters, options) if err != nil { return StaticMembersClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return StaticMembersClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return StaticMembersClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return StaticMembersClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -103,7 +109,10 @@ func (client *StaticMembersClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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. @@ -125,16 +134,22 @@ func (client *StaticMembersClient) createOrUpdateHandleResponse(resp *http.Respo // - staticMemberName - The name of the static member. // - options - StaticMembersClientDeleteOptions contains the optional parameters for the StaticMembersClient.Delete method. func (client *StaticMembersClient) Delete(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, staticMemberName string, options *StaticMembersClientDeleteOptions) (StaticMembersClientDeleteResponse, error) { + var err error + const operationName = "StaticMembersClient.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, networkManagerName, networkGroupName, staticMemberName, options) if err != nil { return StaticMembersClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return StaticMembersClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return StaticMembersClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return StaticMembersClientDeleteResponse{}, err } return StaticMembersClientDeleteResponse{}, nil } @@ -183,18 +198,25 @@ func (client *StaticMembersClient) deleteCreateRequest(ctx context.Context, reso // - staticMemberName - The name of the static member. // - options - StaticMembersClientGetOptions contains the optional parameters for the StaticMembersClient.Get method. func (client *StaticMembersClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, networkGroupName string, staticMemberName string, options *StaticMembersClientGetOptions) (StaticMembersClientGetResponse, error) { + var err error + const operationName = "StaticMembersClient.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, networkManagerName, networkGroupName, staticMemberName, options) if err != nil { return StaticMembersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return StaticMembersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return StaticMembersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return StaticMembersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -253,6 +275,7 @@ func (client *StaticMembersClient) NewListPager(resourceGroupName string, networ return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *StaticMembersClientListResponse) (StaticMembersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "StaticMembersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -272,6 +295,7 @@ func (client *StaticMembersClient) NewListPager(resourceGroupName string, networ } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/subnets_client.go b/sdk/resourcemanager/network/armnetwork/subnets_client.go index 8013b2cce875..5556c942e074 100644 --- a/sdk/resourcemanager/network/armnetwork/subnets_client.go +++ b/sdk/resourcemanager/network/armnetwork/subnets_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 armnetwork @@ -61,9 +60,10 @@ func (client *SubnetsClient) BeginCreateOrUpdate(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SubnetsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *SubnetsClient) BeginCreateOrUpdate(ctx context.Context, resourceGr // // Generated from API version 2022-11-01 func (client *SubnetsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters Subnet, options *SubnetsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SubnetsClient.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, virtualNetworkName, subnetName, subnetParameters, 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. @@ -115,7 +121,10 @@ func (client *SubnetsClient) createOrUpdateCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, subnetParameters) + if err := runtime.MarshalAsJSON(req, subnetParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified subnet. @@ -132,9 +141,10 @@ func (client *SubnetsClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SubnetsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -145,18 +155,24 @@ func (client *SubnetsClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *SubnetsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *SubnetsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SubnetsClient.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, virtualNetworkName, subnetName, 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. @@ -198,18 +214,25 @@ func (client *SubnetsClient) deleteCreateRequest(ctx context.Context, resourceGr // - subnetName - The name of the subnet. // - options - SubnetsClientGetOptions contains the optional parameters for the SubnetsClient.Get method. func (client *SubnetsClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *SubnetsClientGetOptions) (SubnetsClientGetResponse, error) { + var err error + const operationName = "SubnetsClient.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, virtualNetworkName, subnetName, options) if err != nil { return SubnetsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubnetsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SubnetsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SubnetsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *SubnetsClient) NewListPager(resourceGroupName string, virtualNetwo return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SubnetsClientListResponse) (SubnetsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SubnetsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *SubnetsClient) NewListPager(resourceGroupName string, virtualNetwo } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -339,9 +364,10 @@ func (client *SubnetsClient) BeginPrepareNetworkPolicies(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientPrepareNetworkPoliciesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientPrepareNetworkPoliciesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SubnetsClientPrepareNetworkPoliciesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -352,18 +378,24 @@ func (client *SubnetsClient) BeginPrepareNetworkPolicies(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *SubnetsClient) prepareNetworkPolicies(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, prepareNetworkPoliciesRequestParameters PrepareNetworkPoliciesRequest, options *SubnetsClientBeginPrepareNetworkPoliciesOptions) (*http.Response, error) { + var err error + const operationName = "SubnetsClient.BeginPrepareNetworkPolicies" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.prepareNetworkPoliciesCreateRequest(ctx, resourceGroupName, virtualNetworkName, subnetName, prepareNetworkPoliciesRequestParameters, 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 } // prepareNetworkPoliciesCreateRequest creates the PrepareNetworkPolicies request. @@ -393,7 +425,10 @@ func (client *SubnetsClient) prepareNetworkPoliciesCreateRequest(ctx context.Con reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, prepareNetworkPoliciesRequestParameters) + if err := runtime.MarshalAsJSON(req, prepareNetworkPoliciesRequestParameters); err != nil { + return nil, err + } + return req, nil } // BeginUnprepareNetworkPolicies - Unprepares a subnet by removing network intent policies. @@ -412,9 +447,10 @@ func (client *SubnetsClient) BeginUnprepareNetworkPolicies(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientUnprepareNetworkPoliciesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SubnetsClientUnprepareNetworkPoliciesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[SubnetsClientUnprepareNetworkPoliciesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -425,18 +461,24 @@ func (client *SubnetsClient) BeginUnprepareNetworkPolicies(ctx context.Context, // // Generated from API version 2022-11-01 func (client *SubnetsClient) unprepareNetworkPolicies(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, unprepareNetworkPoliciesRequestParameters UnprepareNetworkPoliciesRequest, options *SubnetsClientBeginUnprepareNetworkPoliciesOptions) (*http.Response, error) { + var err error + const operationName = "SubnetsClient.BeginUnprepareNetworkPolicies" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.unprepareNetworkPoliciesCreateRequest(ctx, resourceGroupName, virtualNetworkName, subnetName, unprepareNetworkPoliciesRequestParameters, 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 } // unprepareNetworkPoliciesCreateRequest creates the UnprepareNetworkPolicies request. @@ -466,5 +508,8 @@ func (client *SubnetsClient) unprepareNetworkPoliciesCreateRequest(ctx context.C reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, unprepareNetworkPoliciesRequestParameters) + if err := runtime.MarshalAsJSON(req, unprepareNetworkPoliciesRequestParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/network/armnetwork/subscriptionnetworkmanagerconnections_client.go b/sdk/resourcemanager/network/armnetwork/subscriptionnetworkmanagerconnections_client.go index 6bb638b169c5..950db9ba069d 100644 --- a/sdk/resourcemanager/network/armnetwork/subscriptionnetworkmanagerconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/subscriptionnetworkmanagerconnections_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 armnetwork @@ -55,18 +54,25 @@ func NewSubscriptionNetworkManagerConnectionsClient(subscriptionID string, crede // - options - SubscriptionNetworkManagerConnectionsClientCreateOrUpdateOptions contains the optional parameters for the SubscriptionNetworkManagerConnectionsClient.CreateOrUpdate // method. func (client *SubscriptionNetworkManagerConnectionsClient) CreateOrUpdate(ctx context.Context, networkManagerConnectionName string, parameters ManagerConnection, options *SubscriptionNetworkManagerConnectionsClientCreateOrUpdateOptions) (SubscriptionNetworkManagerConnectionsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "SubscriptionNetworkManagerConnectionsClient.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, networkManagerConnectionName, parameters, options) if err != nil { return SubscriptionNetworkManagerConnectionsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubscriptionNetworkManagerConnectionsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return SubscriptionNetworkManagerConnectionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return SubscriptionNetworkManagerConnectionsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -88,7 +94,10 @@ func (client *SubscriptionNetworkManagerConnectionsClient) createOrUpdateCreateR reqQP.Set("api-version", "2022-11-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. @@ -108,16 +117,22 @@ func (client *SubscriptionNetworkManagerConnectionsClient) createOrUpdateHandleR // - options - SubscriptionNetworkManagerConnectionsClientDeleteOptions contains the optional parameters for the SubscriptionNetworkManagerConnectionsClient.Delete // method. func (client *SubscriptionNetworkManagerConnectionsClient) Delete(ctx context.Context, networkManagerConnectionName string, options *SubscriptionNetworkManagerConnectionsClientDeleteOptions) (SubscriptionNetworkManagerConnectionsClientDeleteResponse, error) { + var err error + const operationName = "SubscriptionNetworkManagerConnectionsClient.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, networkManagerConnectionName, options) if err != nil { return SubscriptionNetworkManagerConnectionsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubscriptionNetworkManagerConnectionsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return SubscriptionNetworkManagerConnectionsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return SubscriptionNetworkManagerConnectionsClientDeleteResponse{}, err } return SubscriptionNetworkManagerConnectionsClientDeleteResponse{}, nil } @@ -152,18 +167,25 @@ func (client *SubscriptionNetworkManagerConnectionsClient) deleteCreateRequest(c // - options - SubscriptionNetworkManagerConnectionsClientGetOptions contains the optional parameters for the SubscriptionNetworkManagerConnectionsClient.Get // method. func (client *SubscriptionNetworkManagerConnectionsClient) Get(ctx context.Context, networkManagerConnectionName string, options *SubscriptionNetworkManagerConnectionsClientGetOptions) (SubscriptionNetworkManagerConnectionsClientGetResponse, error) { + var err error + const operationName = "SubscriptionNetworkManagerConnectionsClient.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, networkManagerConnectionName, options) if err != nil { return SubscriptionNetworkManagerConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubscriptionNetworkManagerConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SubscriptionNetworkManagerConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SubscriptionNetworkManagerConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -208,6 +230,7 @@ func (client *SubscriptionNetworkManagerConnectionsClient) NewListPager(options return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SubscriptionNetworkManagerConnectionsClientListResponse) (SubscriptionNetworkManagerConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SubscriptionNetworkManagerConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -227,6 +250,7 @@ func (client *SubscriptionNetworkManagerConnectionsClient) NewListPager(options } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/time_rfc3339.go b/sdk/resourcemanager/network/armnetwork/time_rfc3339.go index 6da2de17a36a..851a2002c57a 100644 --- a/sdk/resourcemanager/network/armnetwork/time_rfc3339.go +++ b/sdk/resourcemanager/network/armnetwork/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 armnetwork diff --git a/sdk/resourcemanager/network/armnetwork/usages_client.go b/sdk/resourcemanager/network/armnetwork/usages_client.go index 1aec45017089..8e607d23b84e 100644 --- a/sdk/resourcemanager/network/armnetwork/usages_client.go +++ b/sdk/resourcemanager/network/armnetwork/usages_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 armnetwork @@ -56,6 +55,7 @@ func (client *UsagesClient) NewListPager(location string, options *UsagesClientL return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *UsagesClientListResponse) (UsagesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "UsagesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -75,6 +75,7 @@ func (client *UsagesClient) NewListPager(location string, options *UsagesClientL } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/vipswap_client.go b/sdk/resourcemanager/network/armnetwork/vipswap_client.go index ba4820a9e018..79417542d6fd 100644 --- a/sdk/resourcemanager/network/armnetwork/vipswap_client.go +++ b/sdk/resourcemanager/network/armnetwork/vipswap_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 armnetwork @@ -59,7 +58,8 @@ func (client *VipSwapClient) BeginCreate(ctx context.Context, groupName string, if err != nil { return nil, err } - return runtime.NewPoller[VipSwapClientCreateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller[VipSwapClientCreateResponse](resp, client.internal.Pipeline(), nil) + return poller, err } else { return runtime.NewPollerFromResumeToken[VipSwapClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -70,18 +70,24 @@ func (client *VipSwapClient) BeginCreate(ctx context.Context, groupName string, // // Generated from API version 2022-11-01 func (client *VipSwapClient) create(ctx context.Context, groupName string, resourceName string, parameters SwapResource, options *VipSwapClientBeginCreateOptions) (*http.Response, error) { + var err error + const operationName = "VipSwapClient.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, groupName, resourceName, 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 } // createCreateRequest creates the Create request. @@ -108,7 +114,10 @@ func (client *VipSwapClient) createCreateRequest(ctx context.Context, groupName reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // Get - Gets the SwapResource which identifies the slot type for the specified cloud service. The slot type on a cloud service @@ -120,18 +129,25 @@ func (client *VipSwapClient) createCreateRequest(ctx context.Context, groupName // - resourceName - The name of the cloud service. // - options - VipSwapClientGetOptions contains the optional parameters for the VipSwapClient.Get method. func (client *VipSwapClient) Get(ctx context.Context, groupName string, resourceName string, options *VipSwapClientGetOptions) (VipSwapClientGetResponse, error) { + var err error + const operationName = "VipSwapClient.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, groupName, resourceName, options) if err != nil { return VipSwapClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VipSwapClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VipSwapClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VipSwapClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -179,18 +195,25 @@ func (client *VipSwapClient) getHandleResponse(resp *http.Response) (VipSwapClie // - resourceName - The name of the cloud service. // - options - VipSwapClientListOptions contains the optional parameters for the VipSwapClient.List method. func (client *VipSwapClient) List(ctx context.Context, groupName string, resourceName string, options *VipSwapClientListOptions) (VipSwapClientListResponse, error) { + var err error + const operationName = "VipSwapClient.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, groupName, resourceName, options) if err != nil { return VipSwapClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VipSwapClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VipSwapClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VipSwapClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/virtualapplianceconnections_client.go b/sdk/resourcemanager/network/armnetwork/virtualapplianceconnections_client.go index d0bbd8fe67a8..aaa18b363bca 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualapplianceconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualapplianceconnections_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 armnetwork @@ -62,9 +61,10 @@ func (client *VirtualApplianceConnectionsClient) BeginCreateOrUpdate(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualApplianceConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -75,18 +75,24 @@ func (client *VirtualApplianceConnectionsClient) BeginCreateOrUpdate(ctx context // // Generated from API version 2022-11-01 func (client *VirtualApplianceConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, connectionName string, networkVirtualApplianceConnectionParameters VirtualApplianceConnection, options *VirtualApplianceConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualApplianceConnectionsClient.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, networkVirtualApplianceName, connectionName, networkVirtualApplianceConnectionParameters, 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. @@ -116,7 +122,10 @@ func (client *VirtualApplianceConnectionsClient) createOrUpdateCreateRequest(ctx reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, networkVirtualApplianceConnectionParameters) + if err := runtime.MarshalAsJSON(req, networkVirtualApplianceConnectionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a NVA connection. @@ -134,9 +143,10 @@ func (client *VirtualApplianceConnectionsClient) BeginDelete(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualApplianceConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -147,18 +157,24 @@ func (client *VirtualApplianceConnectionsClient) BeginDelete(ctx context.Context // // Generated from API version 2022-11-01 func (client *VirtualApplianceConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, connectionName string, options *VirtualApplianceConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualApplianceConnectionsClient.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, networkVirtualApplianceName, connectionName, 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. @@ -201,18 +217,25 @@ func (client *VirtualApplianceConnectionsClient) deleteCreateRequest(ctx context // - options - VirtualApplianceConnectionsClientGetOptions contains the optional parameters for the VirtualApplianceConnectionsClient.Get // method. func (client *VirtualApplianceConnectionsClient) Get(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, connectionName string, options *VirtualApplianceConnectionsClientGetOptions) (VirtualApplianceConnectionsClientGetResponse, error) { + var err error + const operationName = "VirtualApplianceConnectionsClient.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, networkVirtualApplianceName, connectionName, options) if err != nil { return VirtualApplianceConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualApplianceConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualApplianceConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualApplianceConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -267,6 +290,7 @@ func (client *VirtualApplianceConnectionsClient) NewListPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualApplianceConnectionsClientListResponse) (VirtualApplianceConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualApplianceConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -286,6 +310,7 @@ func (client *VirtualApplianceConnectionsClient) NewListPager(resourceGroupName } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualappliances_client.go b/sdk/resourcemanager/network/armnetwork/virtualappliances_client.go index 95311fdb4448..134d85a29ff9 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualappliances_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualappliances_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualAppliancesClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualAppliancesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualAppliancesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualAppliancesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualAppliancesClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *VirtualAppliancesClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, parameters VirtualAppliance, options *VirtualAppliancesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualAppliancesClient.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, networkVirtualApplianceName, 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. @@ -110,7 +116,10 @@ func (client *VirtualAppliancesClient) createOrUpdateCreateRequest(ctx context.C reqQP.Set("api-version", "2022-11-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 the specified Network Virtual Appliance. @@ -127,9 +136,10 @@ func (client *VirtualAppliancesClient) BeginDelete(ctx context.Context, resource if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualAppliancesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualAppliancesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualAppliancesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *VirtualAppliancesClient) BeginDelete(ctx context.Context, resource // // Generated from API version 2022-11-01 func (client *VirtualAppliancesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *VirtualAppliancesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualAppliancesClient.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, networkVirtualApplianceName, 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 *VirtualAppliancesClient) deleteCreateRequest(ctx context.Context, // - networkVirtualApplianceName - The name of Network Virtual Appliance. // - options - VirtualAppliancesClientGetOptions contains the optional parameters for the VirtualAppliancesClient.Get method. func (client *VirtualAppliancesClient) Get(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *VirtualAppliancesClientGetOptions) (VirtualAppliancesClientGetResponse, error) { + var err error + const operationName = "VirtualAppliancesClient.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, networkVirtualApplianceName, options) if err != nil { return VirtualAppliancesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualAppliancesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualAppliancesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualAppliancesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -251,6 +274,7 @@ func (client *VirtualAppliancesClient) NewListPager(options *VirtualAppliancesCl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualAppliancesClientListResponse) (VirtualAppliancesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualAppliancesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -270,6 +294,7 @@ func (client *VirtualAppliancesClient) NewListPager(options *VirtualAppliancesCl } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -312,6 +337,7 @@ func (client *VirtualAppliancesClient) NewListByResourceGroupPager(resourceGroup return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualAppliancesClientListByResourceGroupResponse) (VirtualAppliancesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualAppliancesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -331,6 +357,7 @@ func (client *VirtualAppliancesClient) NewListByResourceGroupPager(resourceGroup } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -375,18 +402,25 @@ func (client *VirtualAppliancesClient) listByResourceGroupHandleResponse(resp *h // - options - VirtualAppliancesClientUpdateTagsOptions contains the optional parameters for the VirtualAppliancesClient.UpdateTags // method. func (client *VirtualAppliancesClient) UpdateTags(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, parameters TagsObject, options *VirtualAppliancesClientUpdateTagsOptions) (VirtualAppliancesClientUpdateTagsResponse, error) { + var err error + const operationName = "VirtualAppliancesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkVirtualApplianceName, parameters, options) if err != nil { return VirtualAppliancesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualAppliancesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualAppliancesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualAppliancesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -412,7 +446,10 @@ func (client *VirtualAppliancesClient) updateTagsCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/virtualappliancesites_client.go b/sdk/resourcemanager/network/armnetwork/virtualappliancesites_client.go index c98435c254e7..34a4426d68d7 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualappliancesites_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualappliancesites_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 armnetwork @@ -61,9 +60,10 @@ func (client *VirtualApplianceSitesClient) BeginCreateOrUpdate(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceSitesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceSitesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualApplianceSitesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VirtualApplianceSitesClient) BeginCreateOrUpdate(ctx context.Conte // // Generated from API version 2022-11-01 func (client *VirtualApplianceSitesClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, siteName string, parameters VirtualApplianceSite, options *VirtualApplianceSitesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualApplianceSitesClient.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, networkVirtualApplianceName, siteName, 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. @@ -115,7 +121,10 @@ func (client *VirtualApplianceSitesClient) createOrUpdateCreateRequest(ctx conte reqQP.Set("api-version", "2022-11-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 the specified site from a Virtual Appliance. @@ -133,9 +142,10 @@ func (client *VirtualApplianceSitesClient) BeginDelete(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceSitesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualApplianceSitesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualApplianceSitesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *VirtualApplianceSitesClient) BeginDelete(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *VirtualApplianceSitesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, siteName string, options *VirtualApplianceSitesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualApplianceSitesClient.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, networkVirtualApplianceName, siteName, 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. @@ -200,18 +216,25 @@ func (client *VirtualApplianceSitesClient) deleteCreateRequest(ctx context.Conte // - options - VirtualApplianceSitesClientGetOptions contains the optional parameters for the VirtualApplianceSitesClient.Get // method. func (client *VirtualApplianceSitesClient) Get(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, siteName string, options *VirtualApplianceSitesClientGetOptions) (VirtualApplianceSitesClientGetResponse, error) { + var err error + const operationName = "VirtualApplianceSitesClient.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, networkVirtualApplianceName, siteName, options) if err != nil { return VirtualApplianceSitesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualApplianceSitesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualApplianceSitesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualApplianceSitesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *VirtualApplianceSitesClient) NewListPager(resourceGroupName string return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualApplianceSitesClientListResponse) (VirtualApplianceSitesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualApplianceSitesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *VirtualApplianceSitesClient) NewListPager(resourceGroupName string } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualapplianceskus_client.go b/sdk/resourcemanager/network/armnetwork/virtualapplianceskus_client.go index 0a52592f92f2..db32427a2566 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualapplianceskus_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualapplianceskus_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 armnetwork @@ -53,18 +52,25 @@ func NewVirtualApplianceSKUsClient(subscriptionID string, credential azcore.Toke // - options - VirtualApplianceSKUsClientGetOptions contains the optional parameters for the VirtualApplianceSKUsClient.Get // method. func (client *VirtualApplianceSKUsClient) Get(ctx context.Context, skuName string, options *VirtualApplianceSKUsClientGetOptions) (VirtualApplianceSKUsClientGetResponse, error) { + var err error + const operationName = "VirtualApplianceSKUsClient.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, skuName, options) if err != nil { return VirtualApplianceSKUsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualApplianceSKUsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualApplianceSKUsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualApplianceSKUsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -109,6 +115,7 @@ func (client *VirtualApplianceSKUsClient) NewListPager(options *VirtualAppliance return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualApplianceSKUsClientListResponse) (VirtualApplianceSKUsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualApplianceSKUsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -128,6 +135,7 @@ func (client *VirtualApplianceSKUsClient) NewListPager(options *VirtualAppliance } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnection_client.go b/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnection_client.go index 3189170e5a70..9acecc0b5bf6 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnection_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnection_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 armnetwork @@ -61,9 +60,10 @@ func (client *VirtualHubBgpConnectionClient) BeginCreateOrUpdate(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubBgpConnectionClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VirtualHubBgpConnectionClient) BeginCreateOrUpdate(ctx context.Con // // Generated from API version 2022-11-01 func (client *VirtualHubBgpConnectionClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, parameters BgpConnection, options *VirtualHubBgpConnectionClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubBgpConnectionClient.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, virtualHubName, connectionName, 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. @@ -115,7 +121,10 @@ func (client *VirtualHubBgpConnectionClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2022-11-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 a VirtualHubBgpConnection. @@ -133,9 +142,10 @@ func (client *VirtualHubBgpConnectionClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubBgpConnectionClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *VirtualHubBgpConnectionClient) BeginDelete(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *VirtualHubBgpConnectionClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *VirtualHubBgpConnectionClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubBgpConnectionClient.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, virtualHubName, connectionName, 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. @@ -200,18 +216,25 @@ func (client *VirtualHubBgpConnectionClient) deleteCreateRequest(ctx context.Con // - options - VirtualHubBgpConnectionClientGetOptions contains the optional parameters for the VirtualHubBgpConnectionClient.Get // method. func (client *VirtualHubBgpConnectionClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *VirtualHubBgpConnectionClientGetOptions) (VirtualHubBgpConnectionClientGetResponse, error) { + var err error + const operationName = "VirtualHubBgpConnectionClient.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, virtualHubName, connectionName, options) if err != nil { return VirtualHubBgpConnectionClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualHubBgpConnectionClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualHubBgpConnectionClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualHubBgpConnectionClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. diff --git a/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnections_client.go b/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnections_client.go index 4294b848f9f2..e56d8cef4d8a 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualhubbgpconnections_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 armnetwork @@ -58,6 +57,7 @@ func (client *VirtualHubBgpConnectionsClient) NewListPager(resourceGroupName str return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualHubBgpConnectionsClientListResponse) (VirtualHubBgpConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubBgpConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -77,6 +77,7 @@ func (client *VirtualHubBgpConnectionsClient) NewListPager(resourceGroupName str } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -130,9 +131,10 @@ func (client *VirtualHubBgpConnectionsClient) BeginListAdvertisedRoutes(ctx cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -143,18 +145,24 @@ func (client *VirtualHubBgpConnectionsClient) BeginListAdvertisedRoutes(ctx cont // // Generated from API version 2022-11-01 func (client *VirtualHubBgpConnectionsClient) listAdvertisedRoutes(ctx context.Context, resourceGroupName string, hubName string, connectionName string, options *VirtualHubBgpConnectionsClientBeginListAdvertisedRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubBgpConnectionsClient.BeginListAdvertisedRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAdvertisedRoutesCreateRequest(ctx, resourceGroupName, hubName, connectionName, 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 } // listAdvertisedRoutesCreateRequest creates the ListAdvertisedRoutes request. @@ -202,9 +210,10 @@ func (client *VirtualHubBgpConnectionsClient) BeginListLearnedRoutes(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionsClientListLearnedRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubBgpConnectionsClientListLearnedRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubBgpConnectionsClientListLearnedRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -215,18 +224,24 @@ func (client *VirtualHubBgpConnectionsClient) BeginListLearnedRoutes(ctx context // // Generated from API version 2022-11-01 func (client *VirtualHubBgpConnectionsClient) listLearnedRoutes(ctx context.Context, resourceGroupName string, hubName string, connectionName string, options *VirtualHubBgpConnectionsClientBeginListLearnedRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubBgpConnectionsClient.BeginListLearnedRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listLearnedRoutesCreateRequest(ctx, resourceGroupName, hubName, connectionName, 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 } // listLearnedRoutesCreateRequest creates the ListLearnedRoutes request. diff --git a/sdk/resourcemanager/network/armnetwork/virtualhubipconfiguration_client.go b/sdk/resourcemanager/network/armnetwork/virtualhubipconfiguration_client.go index 49dbb71e7313..1d181aecf943 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualhubipconfiguration_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualhubipconfiguration_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 armnetwork @@ -61,9 +60,10 @@ func (client *VirtualHubIPConfigurationClient) BeginCreateOrUpdate(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubIPConfigurationClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubIPConfigurationClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubIPConfigurationClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VirtualHubIPConfigurationClient) BeginCreateOrUpdate(ctx context.C // // Generated from API version 2022-11-01 func (client *VirtualHubIPConfigurationClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, ipConfigName string, parameters HubIPConfiguration, options *VirtualHubIPConfigurationClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubIPConfigurationClient.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, virtualHubName, ipConfigName, 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. @@ -115,7 +121,10 @@ func (client *VirtualHubIPConfigurationClient) createOrUpdateCreateRequest(ctx c reqQP.Set("api-version", "2022-11-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 a VirtualHubIpConfiguration. @@ -133,9 +142,10 @@ func (client *VirtualHubIPConfigurationClient) BeginDelete(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubIPConfigurationClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubIPConfigurationClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubIPConfigurationClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *VirtualHubIPConfigurationClient) BeginDelete(ctx context.Context, // // Generated from API version 2022-11-01 func (client *VirtualHubIPConfigurationClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, ipConfigName string, options *VirtualHubIPConfigurationClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubIPConfigurationClient.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, virtualHubName, ipConfigName, 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. @@ -200,18 +216,25 @@ func (client *VirtualHubIPConfigurationClient) deleteCreateRequest(ctx context.C // - options - VirtualHubIPConfigurationClientGetOptions contains the optional parameters for the VirtualHubIPConfigurationClient.Get // method. func (client *VirtualHubIPConfigurationClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, ipConfigName string, options *VirtualHubIPConfigurationClientGetOptions) (VirtualHubIPConfigurationClientGetResponse, error) { + var err error + const operationName = "VirtualHubIPConfigurationClient.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, virtualHubName, ipConfigName, options) if err != nil { return VirtualHubIPConfigurationClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualHubIPConfigurationClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualHubIPConfigurationClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualHubIPConfigurationClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *VirtualHubIPConfigurationClient) NewListPager(resourceGroupName st return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualHubIPConfigurationClientListResponse) (VirtualHubIPConfigurationClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubIPConfigurationClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *VirtualHubIPConfigurationClient) NewListPager(resourceGroupName st } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualhubroutetablev2s_client.go b/sdk/resourcemanager/network/armnetwork/virtualhubroutetablev2s_client.go index da55866cf746..e86bb5107104 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualhubroutetablev2s_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualhubroutetablev2s_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 armnetwork @@ -61,9 +60,10 @@ func (client *VirtualHubRouteTableV2SClient) BeginCreateOrUpdate(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubRouteTableV2SClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubRouteTableV2SClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubRouteTableV2SClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VirtualHubRouteTableV2SClient) BeginCreateOrUpdate(ctx context.Con // // Generated from API version 2022-11-01 func (client *VirtualHubRouteTableV2SClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, virtualHubRouteTableV2Parameters VirtualHubRouteTableV2, options *VirtualHubRouteTableV2SClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubRouteTableV2SClient.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, virtualHubName, routeTableName, virtualHubRouteTableV2Parameters, 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. @@ -115,7 +121,10 @@ func (client *VirtualHubRouteTableV2SClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, virtualHubRouteTableV2Parameters) + if err := runtime.MarshalAsJSON(req, virtualHubRouteTableV2Parameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a VirtualHubRouteTableV2. @@ -133,9 +142,10 @@ func (client *VirtualHubRouteTableV2SClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubRouteTableV2SClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubRouteTableV2SClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubRouteTableV2SClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *VirtualHubRouteTableV2SClient) BeginDelete(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *VirtualHubRouteTableV2SClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *VirtualHubRouteTableV2SClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubRouteTableV2SClient.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, virtualHubName, routeTableName, 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. @@ -200,18 +216,25 @@ func (client *VirtualHubRouteTableV2SClient) deleteCreateRequest(ctx context.Con // - options - VirtualHubRouteTableV2SClientGetOptions contains the optional parameters for the VirtualHubRouteTableV2SClient.Get // method. func (client *VirtualHubRouteTableV2SClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, routeTableName string, options *VirtualHubRouteTableV2SClientGetOptions) (VirtualHubRouteTableV2SClientGetResponse, error) { + var err error + const operationName = "VirtualHubRouteTableV2SClient.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, virtualHubName, routeTableName, options) if err != nil { return VirtualHubRouteTableV2SClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualHubRouteTableV2SClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualHubRouteTableV2SClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualHubRouteTableV2SClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *VirtualHubRouteTableV2SClient) NewListPager(resourceGroupName stri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualHubRouteTableV2SClientListResponse) (VirtualHubRouteTableV2SClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubRouteTableV2SClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *VirtualHubRouteTableV2SClient) NewListPager(resourceGroupName stri } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualhubs_client.go b/sdk/resourcemanager/network/armnetwork/virtualhubs_client.go index 2df34c1051c7..5f3c7e2f312d 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualhubs_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualhubs_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualHubsClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualHubsClient) BeginCreateOrUpdate(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *VirtualHubsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters VirtualHub, options *VirtualHubsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubsClient.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, virtualHubName, virtualHubParameters, 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. @@ -110,7 +116,10 @@ func (client *VirtualHubsClient) createOrUpdateCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, virtualHubParameters) + if err := runtime.MarshalAsJSON(req, virtualHubParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a VirtualHub. @@ -126,9 +135,10 @@ func (client *VirtualHubsClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *VirtualHubsClient) BeginDelete(ctx context.Context, resourceGroupN // // Generated from API version 2022-11-01 func (client *VirtualHubsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubsClient.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, virtualHubName, 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. @@ -187,18 +203,25 @@ func (client *VirtualHubsClient) deleteCreateRequest(ctx context.Context, resour // - virtualHubName - The name of the VirtualHub. // - options - VirtualHubsClientGetOptions contains the optional parameters for the VirtualHubsClient.Get method. func (client *VirtualHubsClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientGetOptions) (VirtualHubsClientGetResponse, error) { + var err error + const operationName = "VirtualHubsClient.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, virtualHubName, options) if err != nil { return VirtualHubsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualHubsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualHubsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualHubsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -251,9 +274,10 @@ func (client *VirtualHubsClient) BeginGetEffectiveVirtualHubRoutes(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetEffectiveVirtualHubRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetEffectiveVirtualHubRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubsClientGetEffectiveVirtualHubRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -265,18 +289,24 @@ func (client *VirtualHubsClient) BeginGetEffectiveVirtualHubRoutes(ctx context.C // // Generated from API version 2022-11-01 func (client *VirtualHubsClient) getEffectiveVirtualHubRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubsClient.BeginGetEffectiveVirtualHubRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getEffectiveVirtualHubRoutesCreateRequest(ctx, resourceGroupName, virtualHubName, 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 } // getEffectiveVirtualHubRoutesCreateRequest creates the GetEffectiveVirtualHubRoutes request. @@ -303,7 +333,10 @@ func (client *VirtualHubsClient) getEffectiveVirtualHubRoutesCreateRequest(ctx c req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.EffectiveRoutesParameters != nil { - return req, runtime.MarshalAsJSON(req, *options.EffectiveRoutesParameters) + if err := runtime.MarshalAsJSON(req, *options.EffectiveRoutesParameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -323,9 +356,10 @@ func (client *VirtualHubsClient) BeginGetInboundRoutes(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetInboundRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetInboundRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubsClientGetInboundRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -336,18 +370,24 @@ func (client *VirtualHubsClient) BeginGetInboundRoutes(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *VirtualHubsClient) getInboundRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, getInboundRoutesParameters GetInboundRoutesParameters, options *VirtualHubsClientBeginGetInboundRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubsClient.BeginGetInboundRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getInboundRoutesCreateRequest(ctx, resourceGroupName, virtualHubName, getInboundRoutesParameters, 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 } // getInboundRoutesCreateRequest creates the GetInboundRoutes request. @@ -373,7 +413,10 @@ func (client *VirtualHubsClient) getInboundRoutesCreateRequest(ctx context.Conte reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, getInboundRoutesParameters) + if err := runtime.MarshalAsJSON(req, getInboundRoutesParameters); err != nil { + return nil, err + } + return req, nil } // BeginGetOutboundRoutes - Gets the outbound routes configured for the Virtual Hub on a particular connection. @@ -391,9 +434,10 @@ func (client *VirtualHubsClient) BeginGetOutboundRoutes(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetOutboundRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetOutboundRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualHubsClientGetOutboundRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -404,18 +448,24 @@ func (client *VirtualHubsClient) BeginGetOutboundRoutes(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *VirtualHubsClient) getOutboundRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, getOutboundRoutesParameters GetOutboundRoutesParameters, options *VirtualHubsClientBeginGetOutboundRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualHubsClient.BeginGetOutboundRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getOutboundRoutesCreateRequest(ctx, resourceGroupName, virtualHubName, getOutboundRoutesParameters, 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 } // getOutboundRoutesCreateRequest creates the GetOutboundRoutes request. @@ -441,7 +491,10 @@ func (client *VirtualHubsClient) getOutboundRoutesCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, getOutboundRoutesParameters) + if err := runtime.MarshalAsJSON(req, getOutboundRoutesParameters); err != nil { + return nil, err + } + return req, nil } // NewListPager - Lists all the VirtualHubs in a subscription. @@ -454,6 +507,7 @@ func (client *VirtualHubsClient) NewListPager(options *VirtualHubsClientListOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualHubsClientListResponse) (VirtualHubsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -473,6 +527,7 @@ func (client *VirtualHubsClient) NewListPager(options *VirtualHubsClientListOpti } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -515,6 +570,7 @@ func (client *VirtualHubsClient) NewListByResourceGroupPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualHubsClientListByResourceGroupResponse) (VirtualHubsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -534,6 +590,7 @@ func (client *VirtualHubsClient) NewListByResourceGroupPager(resourceGroupName s } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -577,18 +634,25 @@ func (client *VirtualHubsClient) listByResourceGroupHandleResponse(resp *http.Re // - virtualHubParameters - Parameters supplied to update VirtualHub tags. // - options - VirtualHubsClientUpdateTagsOptions contains the optional parameters for the VirtualHubsClient.UpdateTags method. func (client *VirtualHubsClient) UpdateTags(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters TagsObject, options *VirtualHubsClientUpdateTagsOptions) (VirtualHubsClientUpdateTagsResponse, error) { + var err error + const operationName = "VirtualHubsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualHubName, virtualHubParameters, options) if err != nil { return VirtualHubsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualHubsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualHubsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualHubsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -614,7 +678,10 @@ func (client *VirtualHubsClient) updateTagsCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, virtualHubParameters) + if err := runtime.MarshalAsJSON(req, virtualHubParameters); err != nil { + return nil, err + } + return req, nil } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewayconnections_client.go b/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewayconnections_client.go index f07343fa3296..f7f489c017b3 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewayconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewayconnections_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginCreateOrUpdate(ctx co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginCreateOrUpdate(ctx co // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters VirtualNetworkGatewayConnection, options *VirtualNetworkGatewayConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.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, virtualNetworkGatewayConnectionName, 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. @@ -110,7 +116,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) createOrUpdateCreateReques reqQP.Set("api-version", "2022-11-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 the specified virtual network Gateway connection. @@ -127,9 +136,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginDelete(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginDelete(ctx context.Co // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *VirtualNetworkGatewayConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.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, virtualNetworkGatewayConnectionName, 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. @@ -189,18 +205,25 @@ func (client *VirtualNetworkGatewayConnectionsClient) deleteCreateRequest(ctx co // - options - VirtualNetworkGatewayConnectionsClientGetOptions contains the optional parameters for the VirtualNetworkGatewayConnectionsClient.Get // method. func (client *VirtualNetworkGatewayConnectionsClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *VirtualNetworkGatewayConnectionsClientGetOptions) (VirtualNetworkGatewayConnectionsClientGetResponse, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.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, virtualNetworkGatewayConnectionName, options) if err != nil { return VirtualNetworkGatewayConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkGatewayConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkGatewayConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkGatewayConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -252,9 +275,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginGetIkeSas(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientGetIkeSasResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientGetIkeSasResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientGetIkeSasResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -265,18 +289,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginGetIkeSas(ctx context // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) getIkeSas(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *VirtualNetworkGatewayConnectionsClientBeginGetIkeSasOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginGetIkeSas" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getIkeSasCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, 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 } // getIkeSasCreateRequest creates the GetIkeSas request. @@ -315,18 +345,25 @@ func (client *VirtualNetworkGatewayConnectionsClient) getIkeSasCreateRequest(ctx // - options - VirtualNetworkGatewayConnectionsClientGetSharedKeyOptions contains the optional parameters for the VirtualNetworkGatewayConnectionsClient.GetSharedKey // method. func (client *VirtualNetworkGatewayConnectionsClient) GetSharedKey(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *VirtualNetworkGatewayConnectionsClientGetSharedKeyOptions) (VirtualNetworkGatewayConnectionsClientGetSharedKeyResponse, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.GetSharedKey" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getSharedKeyCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, options) if err != nil { return VirtualNetworkGatewayConnectionsClientGetSharedKeyResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkGatewayConnectionsClientGetSharedKeyResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkGatewayConnectionsClientGetSharedKeyResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkGatewayConnectionsClientGetSharedKeyResponse{}, err } - return client.getSharedKeyHandleResponse(resp) + resp, err := client.getSharedKeyHandleResponse(httpResp) + return resp, err } // getSharedKeyCreateRequest creates the GetSharedKey request. @@ -377,6 +414,7 @@ func (client *VirtualNetworkGatewayConnectionsClient) NewListPager(resourceGroup return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkGatewayConnectionsClientListResponse) (VirtualNetworkGatewayConnectionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkGatewayConnectionsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -396,6 +434,7 @@ func (client *VirtualNetworkGatewayConnectionsClient) NewListPager(resourceGroup } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -444,9 +483,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginResetConnection(ctx c if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientResetConnectionResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientResetConnectionResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientResetConnectionResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -457,18 +497,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginResetConnection(ctx c // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) resetConnection(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *VirtualNetworkGatewayConnectionsClientBeginResetConnectionOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginResetConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetConnectionCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // resetConnectionCreateRequest creates the ResetConnection request. @@ -515,9 +561,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginResetSharedKey(ctx co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientResetSharedKeyResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientResetSharedKeyResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientResetSharedKeyResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -530,18 +577,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginResetSharedKey(ctx co // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) resetSharedKey(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters ConnectionResetSharedKey, options *VirtualNetworkGatewayConnectionsClientBeginResetSharedKeyOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginResetSharedKey" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetSharedKeyCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, 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 } // resetSharedKeyCreateRequest creates the ResetSharedKey request. @@ -567,7 +620,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) resetSharedKeyCreateReques reqQP.Set("api-version", "2022-11-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 } // BeginSetSharedKey - The Put VirtualNetworkGatewayConnectionSharedKey operation sets the virtual network gateway connection @@ -588,9 +644,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginSetSharedKey(ctx cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientSetSharedKeyResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientSetSharedKeyResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientSetSharedKeyResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -603,18 +660,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginSetSharedKey(ctx cont // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) setSharedKey(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters ConnectionSharedKey, options *VirtualNetworkGatewayConnectionsClientBeginSetSharedKeyOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginSetSharedKey" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.setSharedKeyCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, 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 } // setSharedKeyCreateRequest creates the SetSharedKey request. @@ -640,7 +703,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) setSharedKeyCreateRequest( reqQP.Set("api-version", "2022-11-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 } // BeginStartPacketCapture - Starts packet capture on virtual network gateway connection in the specified resource group. @@ -657,9 +723,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginStartPacketCapture(ct if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientStartPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientStartPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientStartPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -670,18 +737,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginStartPacketCapture(ct // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) startPacketCapture(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, options *VirtualNetworkGatewayConnectionsClientBeginStartPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginStartPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startPacketCaptureCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, 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 } // startPacketCaptureCreateRequest creates the StartPacketCapture request. @@ -708,7 +781,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) startPacketCaptureCreateRe 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 } @@ -728,9 +804,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginStopPacketCapture(ctx if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientStopPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientStopPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientStopPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -741,18 +818,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginStopPacketCapture(ctx // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) stopPacketCapture(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters VPNPacketCaptureStopParameters, options *VirtualNetworkGatewayConnectionsClientBeginStopPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginStopPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopPacketCaptureCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, 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 } // stopPacketCaptureCreateRequest creates the StopPacketCapture request. @@ -778,7 +861,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) stopPacketCaptureCreateReq reqQP.Set("api-version", "2022-11-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 } // BeginUpdateTags - Updates a virtual network gateway connection tags. @@ -796,9 +882,10 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginUpdateTags(ctx contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayConnectionsClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayConnectionsClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -809,18 +896,24 @@ func (client *VirtualNetworkGatewayConnectionsClient) BeginUpdateTags(ctx contex // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayConnectionsClient) updateTags(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters TagsObject, options *VirtualNetworkGatewayConnectionsClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayConnectionsClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -846,5 +939,8 @@ func (client *VirtualNetworkGatewayConnectionsClient) updateTagsCreateRequest(ct reqQP.Set("api-version", "2022-11-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/network/armnetwork/virtualnetworkgatewaynatrules_client.go b/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewaynatrules_client.go index f09d1ba28ba4..cbfc0b65790d 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewaynatrules_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualnetworkgatewaynatrules_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 armnetwork @@ -62,9 +61,10 @@ func (client *VirtualNetworkGatewayNatRulesClient) BeginCreateOrUpdate(ctx conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayNatRulesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayNatRulesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayNatRulesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -76,18 +76,24 @@ func (client *VirtualNetworkGatewayNatRulesClient) BeginCreateOrUpdate(ctx conte // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayNatRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, natRuleName string, natRuleParameters VirtualNetworkGatewayNatRule, options *VirtualNetworkGatewayNatRulesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayNatRulesClient.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, virtualNetworkGatewayName, natRuleName, natRuleParameters, 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 *VirtualNetworkGatewayNatRulesClient) createOrUpdateCreateRequest(c reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, natRuleParameters) + if err := runtime.MarshalAsJSON(req, natRuleParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a nat rule. @@ -135,9 +144,10 @@ func (client *VirtualNetworkGatewayNatRulesClient) BeginDelete(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayNatRulesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewayNatRulesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewayNatRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -148,18 +158,24 @@ func (client *VirtualNetworkGatewayNatRulesClient) BeginDelete(ctx context.Conte // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewayNatRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, natRuleName string, options *VirtualNetworkGatewayNatRulesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewayNatRulesClient.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, virtualNetworkGatewayName, natRuleName, 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. @@ -202,18 +218,25 @@ func (client *VirtualNetworkGatewayNatRulesClient) deleteCreateRequest(ctx conte // - options - VirtualNetworkGatewayNatRulesClientGetOptions contains the optional parameters for the VirtualNetworkGatewayNatRulesClient.Get // method. func (client *VirtualNetworkGatewayNatRulesClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, natRuleName string, options *VirtualNetworkGatewayNatRulesClientGetOptions) (VirtualNetworkGatewayNatRulesClientGetResponse, error) { + var err error + const operationName = "VirtualNetworkGatewayNatRulesClient.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, virtualNetworkGatewayName, natRuleName, options) if err != nil { return VirtualNetworkGatewayNatRulesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkGatewayNatRulesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkGatewayNatRulesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkGatewayNatRulesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -268,6 +291,7 @@ func (client *VirtualNetworkGatewayNatRulesClient) NewListByVirtualNetworkGatewa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkGatewayNatRulesClientListByVirtualNetworkGatewayResponse) (VirtualNetworkGatewayNatRulesClientListByVirtualNetworkGatewayResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkGatewayNatRulesClient.NewListByVirtualNetworkGatewayPager") var req *policy.Request var err error if page == nil { @@ -287,6 +311,7 @@ func (client *VirtualNetworkGatewayNatRulesClient) NewListByVirtualNetworkGatewa } return client.listByVirtualNetworkGatewayHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualnetworkgateways_client.go b/sdk/resourcemanager/network/armnetwork/virtualnetworkgateways_client.go index 7518bae48de2..deadf563869e 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualnetworkgateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualnetworkgateways_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualNetworkGatewaysClient) BeginCreateOrUpdate(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualNetworkGatewaysClient) BeginCreateOrUpdate(ctx context.Cont // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VirtualNetworkGateway, options *VirtualNetworkGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.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, virtualNetworkGatewayName, 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. @@ -110,7 +116,10 @@ func (client *VirtualNetworkGatewaysClient) createOrUpdateCreateRequest(ctx cont reqQP.Set("api-version", "2022-11-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 the specified virtual network gateway. @@ -127,9 +136,10 @@ func (client *VirtualNetworkGatewaysClient) BeginDelete(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *VirtualNetworkGatewaysClient) BeginDelete(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.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, virtualNetworkGatewayName, 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,9 +212,10 @@ func (client *VirtualNetworkGatewaysClient) BeginDisconnectVirtualNetworkGateway if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientDisconnectVirtualNetworkGatewayVPNConnectionsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientDisconnectVirtualNetworkGatewayVPNConnectionsResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientDisconnectVirtualNetworkGatewayVPNConnectionsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -210,18 +227,24 @@ func (client *VirtualNetworkGatewaysClient) BeginDisconnectVirtualNetworkGateway // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) disconnectVirtualNetworkGatewayVPNConnections(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, request P2SVPNConnectionRequest, options *VirtualNetworkGatewaysClientBeginDisconnectVirtualNetworkGatewayVPNConnectionsOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginDisconnectVirtualNetworkGatewayVPNConnections" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.disconnectVirtualNetworkGatewayVPNConnectionsCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, request, 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 } // disconnectVirtualNetworkGatewayVPNConnectionsCreateRequest creates the DisconnectVirtualNetworkGatewayVPNConnections request. @@ -247,7 +270,10 @@ func (client *VirtualNetworkGatewaysClient) disconnectVirtualNetworkGatewayVPNCo reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, request) + if err := runtime.MarshalAsJSON(req, request); err != nil { + return nil, err + } + return req, nil } // BeginGenerateVPNProfile - Generates VPN profile for P2S client of the virtual network gateway in the specified resource @@ -266,9 +292,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGenerateVPNProfile(ctx context. if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGenerateVPNProfileResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGenerateVPNProfileResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGenerateVPNProfileResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -280,18 +307,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGenerateVPNProfile(ctx context. // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) generateVPNProfile(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VPNClientParameters, options *VirtualNetworkGatewaysClientBeginGenerateVPNProfileOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGenerateVPNProfile" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generateVPNProfileCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // generateVPNProfileCreateRequest creates the GenerateVPNProfile request. @@ -317,7 +350,10 @@ func (client *VirtualNetworkGatewaysClient) generateVPNProfileCreateRequest(ctx reqQP.Set("api-version", "2022-11-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 } // BeginGeneratevpnclientpackage - Generates VPN client package for P2S client of the virtual network gateway in the specified @@ -336,9 +372,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGeneratevpnclientpackage(ctx co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGeneratevpnclientpackageResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGeneratevpnclientpackageResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGeneratevpnclientpackageResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -350,18 +387,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGeneratevpnclientpackage(ctx co // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) generatevpnclientpackage(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VPNClientParameters, options *VirtualNetworkGatewaysClientBeginGeneratevpnclientpackageOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGeneratevpnclientpackage" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.generatevpnclientpackageCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // generatevpnclientpackageCreateRequest creates the Generatevpnclientpackage request. @@ -387,7 +430,10 @@ func (client *VirtualNetworkGatewaysClient) generatevpnclientpackageCreateReques reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // Get - Gets the specified virtual network gateway by resource group. @@ -399,18 +445,25 @@ func (client *VirtualNetworkGatewaysClient) generatevpnclientpackageCreateReques // - options - VirtualNetworkGatewaysClientGetOptions contains the optional parameters for the VirtualNetworkGatewaysClient.Get // method. func (client *VirtualNetworkGatewaysClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientGetOptions) (VirtualNetworkGatewaysClientGetResponse, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.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, virtualNetworkGatewayName, options) if err != nil { return VirtualNetworkGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -464,9 +517,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGetAdvertisedRoutes(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetAdvertisedRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetAdvertisedRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGetAdvertisedRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -478,18 +532,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGetAdvertisedRoutes(ctx context // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) getAdvertisedRoutes(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, peer string, options *VirtualNetworkGatewaysClientBeginGetAdvertisedRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGetAdvertisedRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAdvertisedRoutesCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, peer, 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 } // getAdvertisedRoutesCreateRequest creates the GetAdvertisedRoutes request. @@ -533,9 +593,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGetBgpPeerStatus(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetBgpPeerStatusResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetBgpPeerStatusResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGetBgpPeerStatusResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -546,18 +607,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGetBgpPeerStatus(ctx context.Co // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) getBgpPeerStatus(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginGetBgpPeerStatusOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGetBgpPeerStatus" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getBgpPeerStatusCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // getBgpPeerStatusCreateRequest creates the GetBgpPeerStatus request. @@ -604,9 +671,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGetLearnedRoutes(ctx context.Co if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetLearnedRoutesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetLearnedRoutesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGetLearnedRoutesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -618,18 +686,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGetLearnedRoutes(ctx context.Co // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) getLearnedRoutes(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginGetLearnedRoutesOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGetLearnedRoutes" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getLearnedRoutesCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // getLearnedRoutesCreateRequest creates the GetLearnedRoutes request. @@ -673,9 +747,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGetVPNProfilePackageURL(ctx con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetVPNProfilePackageURLResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetVPNProfilePackageURLResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGetVPNProfilePackageURLResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -687,18 +762,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGetVPNProfilePackageURL(ctx con // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) getVPNProfilePackageURL(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginGetVPNProfilePackageURLOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGetVPNProfilePackageURL" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVPNProfilePackageURLCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // getVPNProfilePackageURLCreateRequest creates the GetVPNProfilePackageURL request. @@ -742,9 +823,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGetVpnclientConnectionHealth(ct if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetVpnclientConnectionHealthResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetVpnclientConnectionHealthResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGetVpnclientConnectionHealthResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -756,18 +838,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGetVpnclientConnectionHealth(ct // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) getVpnclientConnectionHealth(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginGetVpnclientConnectionHealthOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGetVpnclientConnectionHealth" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVpnclientConnectionHealthCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // getVpnclientConnectionHealthCreateRequest creates the GetVpnclientConnectionHealth request. @@ -812,9 +900,10 @@ func (client *VirtualNetworkGatewaysClient) BeginGetVpnclientIPSecParameters(ctx if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetVpnclientIPSecParametersResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientGetVpnclientIPSecParametersResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientGetVpnclientIPSecParametersResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -827,18 +916,24 @@ func (client *VirtualNetworkGatewaysClient) BeginGetVpnclientIPSecParameters(ctx // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) getVpnclientIPSecParameters(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginGetVpnclientIPSecParametersOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginGetVpnclientIPSecParameters" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVpnclientIPSecParametersCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // getVpnclientIPSecParametersCreateRequest creates the GetVpnclientIPSecParameters request. @@ -879,6 +974,7 @@ func (client *VirtualNetworkGatewaysClient) NewListPager(resourceGroupName strin return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkGatewaysClientListResponse) (VirtualNetworkGatewaysClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkGatewaysClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -898,6 +994,7 @@ func (client *VirtualNetworkGatewaysClient) NewListPager(resourceGroupName strin } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -945,6 +1042,7 @@ func (client *VirtualNetworkGatewaysClient) NewListConnectionsPager(resourceGrou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkGatewaysClientListConnectionsResponse) (VirtualNetworkGatewaysClientListConnectionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkGatewaysClient.NewListConnectionsPager") var req *policy.Request var err error if page == nil { @@ -964,6 +1062,7 @@ func (client *VirtualNetworkGatewaysClient) NewListConnectionsPager(resourceGrou } return client.listConnectionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -1016,9 +1115,10 @@ func (client *VirtualNetworkGatewaysClient) BeginReset(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientResetResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientResetResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientResetResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1029,18 +1129,24 @@ func (client *VirtualNetworkGatewaysClient) BeginReset(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) reset(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginResetOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginReset" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // resetCreateRequest creates the Reset request. @@ -1087,9 +1193,10 @@ func (client *VirtualNetworkGatewaysClient) BeginResetVPNClientSharedKey(ctx con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientResetVPNClientSharedKeyResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientResetVPNClientSharedKeyResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientResetVPNClientSharedKeyResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1100,18 +1207,24 @@ func (client *VirtualNetworkGatewaysClient) BeginResetVPNClientSharedKey(ctx con // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) resetVPNClientSharedKey(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginResetVPNClientSharedKeyOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginResetVPNClientSharedKey" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetVPNClientSharedKeyCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // resetVPNClientSharedKeyCreateRequest creates the ResetVPNClientSharedKey request. @@ -1157,9 +1270,10 @@ func (client *VirtualNetworkGatewaysClient) BeginSetVpnclientIPSecParameters(ctx if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientSetVpnclientIPSecParametersResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientSetVpnclientIPSecParametersResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientSetVpnclientIPSecParametersResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1171,18 +1285,24 @@ func (client *VirtualNetworkGatewaysClient) BeginSetVpnclientIPSecParameters(ctx // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) setVpnclientIPSecParameters(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, vpnclientIPSecParams VPNClientIPsecParameters, options *VirtualNetworkGatewaysClientBeginSetVpnclientIPSecParametersOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginSetVpnclientIPSecParameters" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.setVpnclientIPSecParametersCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, vpnclientIPSecParams, 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 } // setVpnclientIPSecParametersCreateRequest creates the SetVpnclientIPSecParameters request. @@ -1208,7 +1328,10 @@ func (client *VirtualNetworkGatewaysClient) setVpnclientIPSecParametersCreateReq reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnclientIPSecParams) + if err := runtime.MarshalAsJSON(req, vpnclientIPSecParams); err != nil { + return nil, err + } + return req, nil } // BeginStartPacketCapture - Starts packet capture on virtual network gateway in the specified resource group. @@ -1225,9 +1348,10 @@ func (client *VirtualNetworkGatewaysClient) BeginStartPacketCapture(ctx context. if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientStartPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientStartPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientStartPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1238,18 +1362,24 @@ func (client *VirtualNetworkGatewaysClient) BeginStartPacketCapture(ctx context. // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) startPacketCapture(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientBeginStartPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginStartPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startPacketCaptureCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // startPacketCaptureCreateRequest creates the StartPacketCapture request. @@ -1276,7 +1406,10 @@ func (client *VirtualNetworkGatewaysClient) startPacketCaptureCreateRequest(ctx 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 } @@ -1296,9 +1429,10 @@ func (client *VirtualNetworkGatewaysClient) BeginStopPacketCapture(ctx context.C if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientStopPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientStopPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientStopPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1309,18 +1443,24 @@ func (client *VirtualNetworkGatewaysClient) BeginStopPacketCapture(ctx context.C // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) stopPacketCapture(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters VPNPacketCaptureStopParameters, options *VirtualNetworkGatewaysClientBeginStopPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginStopPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopPacketCaptureCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // stopPacketCaptureCreateRequest creates the StopPacketCapture request. @@ -1346,7 +1486,10 @@ func (client *VirtualNetworkGatewaysClient) stopPacketCaptureCreateRequest(ctx c reqQP.Set("api-version", "2022-11-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 } // SupportedVPNDevices - Gets a xml format representation for supported vpn devices. @@ -1358,18 +1501,25 @@ func (client *VirtualNetworkGatewaysClient) stopPacketCaptureCreateRequest(ctx c // - options - VirtualNetworkGatewaysClientSupportedVPNDevicesOptions contains the optional parameters for the VirtualNetworkGatewaysClient.SupportedVPNDevices // method. func (client *VirtualNetworkGatewaysClient) SupportedVPNDevices(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, options *VirtualNetworkGatewaysClientSupportedVPNDevicesOptions) (VirtualNetworkGatewaysClientSupportedVPNDevicesResponse, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.SupportedVPNDevices" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.supportedVPNDevicesCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, options) if err != nil { return VirtualNetworkGatewaysClientSupportedVPNDevicesResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkGatewaysClientSupportedVPNDevicesResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkGatewaysClientSupportedVPNDevicesResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkGatewaysClientSupportedVPNDevicesResponse{}, err } - return client.supportedVPNDevicesHandleResponse(resp) + resp, err := client.supportedVPNDevicesHandleResponse(httpResp) + return resp, err } // supportedVPNDevicesCreateRequest creates the SupportedVPNDevices request. @@ -1422,9 +1572,10 @@ func (client *VirtualNetworkGatewaysClient) BeginUpdateTags(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkGatewaysClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkGatewaysClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1435,18 +1586,24 @@ func (client *VirtualNetworkGatewaysClient) BeginUpdateTags(ctx context.Context, // // Generated from API version 2022-11-01 func (client *VirtualNetworkGatewaysClient) updateTags(ctx context.Context, resourceGroupName string, virtualNetworkGatewayName string, parameters TagsObject, options *VirtualNetworkGatewaysClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayName, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -1472,7 +1629,10 @@ func (client *VirtualNetworkGatewaysClient) updateTagsCreateRequest(ctx context. reqQP.Set("api-version", "2022-11-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 } // VPNDeviceConfigurationScript - Gets a xml format representation for vpn device configuration script. @@ -1486,18 +1646,25 @@ func (client *VirtualNetworkGatewaysClient) updateTagsCreateRequest(ctx context. // - options - VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptOptions contains the optional parameters for the VirtualNetworkGatewaysClient.VPNDeviceConfigurationScript // method. func (client *VirtualNetworkGatewaysClient) VPNDeviceConfigurationScript(ctx context.Context, resourceGroupName string, virtualNetworkGatewayConnectionName string, parameters VPNDeviceScriptParameters, options *VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptOptions) (VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptResponse, error) { + var err error + const operationName = "VirtualNetworkGatewaysClient.VPNDeviceConfigurationScript" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.vpnDeviceConfigurationScriptCreateRequest(ctx, resourceGroupName, virtualNetworkGatewayConnectionName, parameters, options) if err != nil { return VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkGatewaysClientVPNDeviceConfigurationScriptResponse{}, err } - return client.vpnDeviceConfigurationScriptHandleResponse(resp) + resp, err := client.vpnDeviceConfigurationScriptHandleResponse(httpResp) + return resp, err } // vpnDeviceConfigurationScriptCreateRequest creates the VPNDeviceConfigurationScript request. @@ -1523,7 +1690,10 @@ func (client *VirtualNetworkGatewaysClient) vpnDeviceConfigurationScriptCreateRe reqQP.Set("api-version", "2022-11-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 } // vpnDeviceConfigurationScriptHandleResponse handles the VPNDeviceConfigurationScript response. diff --git a/sdk/resourcemanager/network/armnetwork/virtualnetworkpeerings_client.go b/sdk/resourcemanager/network/armnetwork/virtualnetworkpeerings_client.go index c14ca3f0ea69..3e2a62e44328 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualnetworkpeerings_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualnetworkpeerings_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 armnetwork @@ -61,9 +60,10 @@ func (client *VirtualNetworkPeeringsClient) BeginCreateOrUpdate(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkPeeringsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkPeeringsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkPeeringsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VirtualNetworkPeeringsClient) BeginCreateOrUpdate(ctx context.Cont // // Generated from API version 2022-11-01 func (client *VirtualNetworkPeeringsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, virtualNetworkPeeringParameters VirtualNetworkPeering, options *VirtualNetworkPeeringsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkPeeringsClient.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, virtualNetworkName, virtualNetworkPeeringName, virtualNetworkPeeringParameters, 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 *VirtualNetworkPeeringsClient) createOrUpdateCreateRequest(ctx cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, virtualNetworkPeeringParameters) + if err := runtime.MarshalAsJSON(req, virtualNetworkPeeringParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the specified virtual network peering. @@ -136,9 +145,10 @@ func (client *VirtualNetworkPeeringsClient) BeginDelete(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkPeeringsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkPeeringsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkPeeringsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -149,18 +159,24 @@ func (client *VirtualNetworkPeeringsClient) BeginDelete(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *VirtualNetworkPeeringsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, options *VirtualNetworkPeeringsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkPeeringsClient.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, virtualNetworkName, virtualNetworkPeeringName, 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 +219,25 @@ func (client *VirtualNetworkPeeringsClient) deleteCreateRequest(ctx context.Cont // - options - VirtualNetworkPeeringsClientGetOptions contains the optional parameters for the VirtualNetworkPeeringsClient.Get // method. func (client *VirtualNetworkPeeringsClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, options *VirtualNetworkPeeringsClientGetOptions) (VirtualNetworkPeeringsClientGetResponse, error) { + var err error + const operationName = "VirtualNetworkPeeringsClient.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, virtualNetworkName, virtualNetworkPeeringName, options) if err != nil { return VirtualNetworkPeeringsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkPeeringsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkPeeringsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkPeeringsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -269,6 +292,7 @@ func (client *VirtualNetworkPeeringsClient) NewListPager(resourceGroupName strin return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkPeeringsClientListResponse) (VirtualNetworkPeeringsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkPeeringsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -288,6 +312,7 @@ func (client *VirtualNetworkPeeringsClient) NewListPager(resourceGroupName strin } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualnetworks_client.go b/sdk/resourcemanager/network/armnetwork/virtualnetworks_client.go index 361877c732e3..7d8ad09264eb 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualnetworks_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualnetworks_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 armnetwork @@ -56,18 +55,25 @@ func NewVirtualNetworksClient(subscriptionID string, credential azcore.TokenCred // - options - VirtualNetworksClientCheckIPAddressAvailabilityOptions contains the optional parameters for the VirtualNetworksClient.CheckIPAddressAvailability // method. func (client *VirtualNetworksClient) CheckIPAddressAvailability(ctx context.Context, resourceGroupName string, virtualNetworkName string, ipAddress string, options *VirtualNetworksClientCheckIPAddressAvailabilityOptions) (VirtualNetworksClientCheckIPAddressAvailabilityResponse, error) { + var err error + const operationName = "VirtualNetworksClient.CheckIPAddressAvailability" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkIPAddressAvailabilityCreateRequest(ctx, resourceGroupName, virtualNetworkName, ipAddress, options) if err != nil { return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err } - return client.checkIPAddressAvailabilityHandleResponse(resp) + resp, err := client.checkIPAddressAvailabilityHandleResponse(httpResp) + return resp, err } // checkIPAddressAvailabilityCreateRequest creates the CheckIPAddressAvailability request. @@ -121,9 +127,10 @@ func (client *VirtualNetworksClient) BeginCreateOrUpdate(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworksClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworksClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworksClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -134,18 +141,24 @@ func (client *VirtualNetworksClient) BeginCreateOrUpdate(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *VirtualNetworksClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters VirtualNetwork, options *VirtualNetworksClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworksClient.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, virtualNetworkName, 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. @@ -171,7 +184,10 @@ func (client *VirtualNetworksClient) createOrUpdateCreateRequest(ctx context.Con reqQP.Set("api-version", "2022-11-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 the specified virtual network. @@ -188,9 +204,10 @@ func (client *VirtualNetworksClient) BeginDelete(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworksClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworksClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworksClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -201,18 +218,24 @@ func (client *VirtualNetworksClient) BeginDelete(ctx context.Context, resourceGr // // Generated from API version 2022-11-01 func (client *VirtualNetworksClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworksClient.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, virtualNetworkName, 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. @@ -249,18 +272,25 @@ func (client *VirtualNetworksClient) deleteCreateRequest(ctx context.Context, re // - virtualNetworkName - The name of the virtual network. // - options - VirtualNetworksClientGetOptions contains the optional parameters for the VirtualNetworksClient.Get method. func (client *VirtualNetworksClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientGetOptions) (VirtualNetworksClientGetResponse, error) { + var err error + const operationName = "VirtualNetworksClient.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, virtualNetworkName, options) if err != nil { return VirtualNetworksClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworksClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworksClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworksClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -313,6 +343,7 @@ func (client *VirtualNetworksClient) NewListPager(resourceGroupName string, opti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworksClientListResponse) (VirtualNetworksClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -332,6 +363,7 @@ func (client *VirtualNetworksClient) NewListPager(resourceGroupName string, opti } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -377,6 +409,7 @@ func (client *VirtualNetworksClient) NewListAllPager(options *VirtualNetworksCli return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworksClientListAllResponse) (VirtualNetworksClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -396,6 +429,7 @@ func (client *VirtualNetworksClient) NewListAllPager(options *VirtualNetworksCli } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -439,6 +473,7 @@ func (client *VirtualNetworksClient) BeginListDdosProtectionStatus(ctx context.C return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworksClientListDdosProtectionStatusResponse) (VirtualNetworksClientListDdosProtectionStatusResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.BeginListDdosProtectionStatus") req, err := runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) if err != nil { return VirtualNetworksClientListDdosProtectionStatusResponse{}, err @@ -452,16 +487,18 @@ func (client *VirtualNetworksClient) BeginListDdosProtectionStatus(ctx context.C } return client.listDdosProtectionStatusHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) if options == nil || options.ResumeToken == "" { resp, err := client.listDdosProtectionStatus(ctx, resourceGroupName, virtualNetworkName, options) if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[VirtualNetworksClientListDdosProtectionStatusResponse]]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[VirtualNetworksClientListDdosProtectionStatusResponse]]{ FinalStateVia: runtime.FinalStateViaLocation, Response: &pager, }) + return poller, err } else { return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[*runtime.Pager[VirtualNetworksClientListDdosProtectionStatusResponse]]{ Response: &pager, @@ -473,18 +510,24 @@ func (client *VirtualNetworksClient) BeginListDdosProtectionStatus(ctx context.C // // Generated from API version 2022-11-01 func (client *VirtualNetworksClient) listDdosProtectionStatus(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginListDdosProtectionStatusOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworksClient.BeginListDdosProtectionStatus" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listDdosProtectionStatusCreateRequest(ctx, resourceGroupName, virtualNetworkName, 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 } // listDdosProtectionStatusCreateRequest creates the ListDdosProtectionStatus request. @@ -541,6 +584,7 @@ func (client *VirtualNetworksClient) NewListUsagePager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworksClientListUsageResponse) (VirtualNetworksClientListUsageResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.NewListUsagePager") var req *policy.Request var err error if page == nil { @@ -560,6 +604,7 @@ func (client *VirtualNetworksClient) NewListUsagePager(resourceGroupName string, } return client.listUsageHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -608,18 +653,25 @@ func (client *VirtualNetworksClient) listUsageHandleResponse(resp *http.Response // - options - VirtualNetworksClientUpdateTagsOptions contains the optional parameters for the VirtualNetworksClient.UpdateTags // method. func (client *VirtualNetworksClient) UpdateTags(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters TagsObject, options *VirtualNetworksClientUpdateTagsOptions) (VirtualNetworksClientUpdateTagsResponse, error) { + var err error + const operationName = "VirtualNetworksClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualNetworkName, parameters, options) if err != nil { return VirtualNetworksClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworksClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworksClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworksClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -645,7 +697,10 @@ func (client *VirtualNetworksClient) updateTagsCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/virtualnetworktaps_client.go b/sdk/resourcemanager/network/armnetwork/virtualnetworktaps_client.go index 6c359aefbf77..195976943dc4 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualnetworktaps_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualnetworktaps_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualNetworkTapsClient) BeginCreateOrUpdate(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkTapsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkTapsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkTapsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualNetworkTapsClient) BeginCreateOrUpdate(ctx context.Context, // // Generated from API version 2022-11-01 func (client *VirtualNetworkTapsClient) createOrUpdate(ctx context.Context, resourceGroupName string, tapName string, parameters VirtualNetworkTap, options *VirtualNetworkTapsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkTapsClient.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, tapName, 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. @@ -110,7 +116,10 @@ func (client *VirtualNetworkTapsClient) createOrUpdateCreateRequest(ctx context. reqQP.Set("api-version", "2022-11-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 the specified virtual network tap. @@ -127,9 +136,10 @@ func (client *VirtualNetworkTapsClient) BeginDelete(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkTapsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworkTapsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualNetworkTapsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *VirtualNetworkTapsClient) BeginDelete(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *VirtualNetworkTapsClient) deleteOperation(ctx context.Context, resourceGroupName string, tapName string, options *VirtualNetworkTapsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualNetworkTapsClient.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, tapName, 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 *VirtualNetworkTapsClient) deleteCreateRequest(ctx context.Context, // - tapName - The name of virtual network tap. // - options - VirtualNetworkTapsClientGetOptions contains the optional parameters for the VirtualNetworkTapsClient.Get method. func (client *VirtualNetworkTapsClient) Get(ctx context.Context, resourceGroupName string, tapName string, options *VirtualNetworkTapsClientGetOptions) (VirtualNetworkTapsClientGetResponse, error) { + var err error + const operationName = "VirtualNetworkTapsClient.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, tapName, options) if err != nil { return VirtualNetworkTapsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkTapsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkTapsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkTapsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -248,6 +271,7 @@ func (client *VirtualNetworkTapsClient) NewListAllPager(options *VirtualNetworkT return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkTapsClientListAllResponse) (VirtualNetworkTapsClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkTapsClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -267,6 +291,7 @@ func (client *VirtualNetworkTapsClient) NewListAllPager(options *VirtualNetworkT } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -309,6 +334,7 @@ func (client *VirtualNetworkTapsClient) NewListByResourceGroupPager(resourceGrou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualNetworkTapsClientListByResourceGroupResponse) (VirtualNetworkTapsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworkTapsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -328,6 +354,7 @@ func (client *VirtualNetworkTapsClient) NewListByResourceGroupPager(resourceGrou } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -372,18 +399,25 @@ func (client *VirtualNetworkTapsClient) listByResourceGroupHandleResponse(resp * // - options - VirtualNetworkTapsClientUpdateTagsOptions contains the optional parameters for the VirtualNetworkTapsClient.UpdateTags // method. func (client *VirtualNetworkTapsClient) UpdateTags(ctx context.Context, resourceGroupName string, tapName string, tapParameters TagsObject, options *VirtualNetworkTapsClientUpdateTagsOptions) (VirtualNetworkTapsClientUpdateTagsResponse, error) { + var err error + const operationName = "VirtualNetworkTapsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, tapName, tapParameters, options) if err != nil { return VirtualNetworkTapsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualNetworkTapsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualNetworkTapsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualNetworkTapsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -409,7 +443,10 @@ func (client *VirtualNetworkTapsClient) updateTagsCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, tapParameters) + if err := runtime.MarshalAsJSON(req, tapParameters); err != nil { + return nil, err + } + return req, nil } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/virtualrouterpeerings_client.go b/sdk/resourcemanager/network/armnetwork/virtualrouterpeerings_client.go index 487d89035e4b..78f3bd3643f7 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualrouterpeerings_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualrouterpeerings_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 armnetwork @@ -61,9 +60,10 @@ func (client *VirtualRouterPeeringsClient) BeginCreateOrUpdate(ctx context.Conte if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRouterPeeringsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRouterPeeringsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualRouterPeeringsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VirtualRouterPeeringsClient) BeginCreateOrUpdate(ctx context.Conte // // Generated from API version 2022-11-01 func (client *VirtualRouterPeeringsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, parameters VirtualRouterPeering, options *VirtualRouterPeeringsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualRouterPeeringsClient.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, virtualRouterName, peeringName, 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. @@ -115,7 +121,10 @@ func (client *VirtualRouterPeeringsClient) createOrUpdateCreateRequest(ctx conte reqQP.Set("api-version", "2022-11-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 the specified peering from a Virtual Router. @@ -133,9 +142,10 @@ func (client *VirtualRouterPeeringsClient) BeginDelete(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRouterPeeringsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRouterPeeringsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualRouterPeeringsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -146,18 +156,24 @@ func (client *VirtualRouterPeeringsClient) BeginDelete(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *VirtualRouterPeeringsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, options *VirtualRouterPeeringsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualRouterPeeringsClient.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, virtualRouterName, peeringName, 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. @@ -200,18 +216,25 @@ func (client *VirtualRouterPeeringsClient) deleteCreateRequest(ctx context.Conte // - options - VirtualRouterPeeringsClientGetOptions contains the optional parameters for the VirtualRouterPeeringsClient.Get // method. func (client *VirtualRouterPeeringsClient) Get(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, options *VirtualRouterPeeringsClientGetOptions) (VirtualRouterPeeringsClientGetResponse, error) { + var err error + const operationName = "VirtualRouterPeeringsClient.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, virtualRouterName, peeringName, options) if err != nil { return VirtualRouterPeeringsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualRouterPeeringsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualRouterPeeringsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualRouterPeeringsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *VirtualRouterPeeringsClient) NewListPager(resourceGroupName string return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualRouterPeeringsClientListResponse) (VirtualRouterPeeringsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualRouterPeeringsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *VirtualRouterPeeringsClient) NewListPager(resourceGroupName string } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualrouters_client.go b/sdk/resourcemanager/network/armnetwork/virtualrouters_client.go index 8e6f2c4f2578..400182eef659 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualrouters_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualrouters_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualRoutersClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRoutersClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRoutersClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualRoutersClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualRoutersClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *VirtualRoutersClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualRouterName string, parameters VirtualRouter, options *VirtualRoutersClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualRoutersClient.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, virtualRouterName, 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. @@ -110,7 +116,10 @@ func (client *VirtualRoutersClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-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 the specified Virtual Router. @@ -127,9 +136,10 @@ func (client *VirtualRoutersClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRoutersClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualRoutersClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualRoutersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *VirtualRoutersClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *VirtualRoutersClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualRouterName string, options *VirtualRoutersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualRoutersClient.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, virtualRouterName, 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 *VirtualRoutersClient) deleteCreateRequest(ctx context.Context, res // - virtualRouterName - The name of the Virtual Router. // - options - VirtualRoutersClientGetOptions contains the optional parameters for the VirtualRoutersClient.Get method. func (client *VirtualRoutersClient) Get(ctx context.Context, resourceGroupName string, virtualRouterName string, options *VirtualRoutersClientGetOptions) (VirtualRoutersClientGetResponse, error) { + var err error + const operationName = "VirtualRoutersClient.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, virtualRouterName, options) if err != nil { return VirtualRoutersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualRoutersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualRoutersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualRoutersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -250,6 +273,7 @@ func (client *VirtualRoutersClient) NewListPager(options *VirtualRoutersClientLi return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualRoutersClientListResponse) (VirtualRoutersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualRoutersClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -269,6 +293,7 @@ func (client *VirtualRoutersClient) NewListPager(options *VirtualRoutersClientLi } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -311,6 +336,7 @@ func (client *VirtualRoutersClient) NewListByResourceGroupPager(resourceGroupNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualRoutersClientListByResourceGroupResponse) (VirtualRoutersClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualRoutersClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -330,6 +356,7 @@ func (client *VirtualRoutersClient) NewListByResourceGroupPager(resourceGroupNam } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/virtualwans_client.go b/sdk/resourcemanager/network/armnetwork/virtualwans_client.go index f50a887cbbd3..db60de605ae0 100644 --- a/sdk/resourcemanager/network/armnetwork/virtualwans_client.go +++ b/sdk/resourcemanager/network/armnetwork/virtualwans_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 armnetwork @@ -60,9 +59,10 @@ func (client *VirtualWansClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualWansClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualWansClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualWansClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VirtualWansClient) BeginCreateOrUpdate(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *VirtualWansClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualWANName string, wanParameters VirtualWAN, options *VirtualWansClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VirtualWansClient.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, virtualWANName, wanParameters, 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. @@ -110,7 +116,10 @@ func (client *VirtualWansClient) createOrUpdateCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, wanParameters) + if err := runtime.MarshalAsJSON(req, wanParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a VirtualWAN. @@ -126,9 +135,10 @@ func (client *VirtualWansClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualWansClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualWansClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VirtualWansClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *VirtualWansClient) BeginDelete(ctx context.Context, resourceGroupN // // Generated from API version 2022-11-01 func (client *VirtualWansClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualWANName string, options *VirtualWansClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VirtualWansClient.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, virtualWANName, 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. @@ -187,18 +203,25 @@ func (client *VirtualWansClient) deleteCreateRequest(ctx context.Context, resour // - virtualWANName - The name of the VirtualWAN being retrieved. // - options - VirtualWansClientGetOptions contains the optional parameters for the VirtualWansClient.Get method. func (client *VirtualWansClient) Get(ctx context.Context, resourceGroupName string, virtualWANName string, options *VirtualWansClientGetOptions) (VirtualWansClientGetResponse, error) { + var err error + const operationName = "VirtualWansClient.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, virtualWANName, options) if err != nil { return VirtualWansClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualWansClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualWansClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualWansClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -246,6 +269,7 @@ func (client *VirtualWansClient) NewListPager(options *VirtualWansClientListOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualWansClientListResponse) (VirtualWansClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualWansClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -265,6 +289,7 @@ func (client *VirtualWansClient) NewListPager(options *VirtualWansClientListOpti } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -307,6 +332,7 @@ func (client *VirtualWansClient) NewListByResourceGroupPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VirtualWansClientListByResourceGroupResponse) (VirtualWansClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualWansClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -326,6 +352,7 @@ func (client *VirtualWansClient) NewListByResourceGroupPager(resourceGroupName s } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -369,18 +396,25 @@ func (client *VirtualWansClient) listByResourceGroupHandleResponse(resp *http.Re // - wanParameters - Parameters supplied to Update VirtualWAN tags. // - options - VirtualWansClientUpdateTagsOptions contains the optional parameters for the VirtualWansClient.UpdateTags method. func (client *VirtualWansClient) UpdateTags(ctx context.Context, resourceGroupName string, virtualWANName string, wanParameters TagsObject, options *VirtualWansClientUpdateTagsOptions) (VirtualWansClientUpdateTagsResponse, error) { + var err error + const operationName = "VirtualWansClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualWANName, wanParameters, options) if err != nil { return VirtualWansClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VirtualWansClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VirtualWansClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VirtualWansClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -406,7 +440,10 @@ func (client *VirtualWansClient) updateTagsCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, wanParameters) + if err := runtime.MarshalAsJSON(req, wanParameters); err != nil { + return nil, err + } + return req, nil } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/vpnconnections_client.go b/sdk/resourcemanager/network/armnetwork/vpnconnections_client.go index 259256ac90af..3c8df75297c1 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnconnections_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 armnetwork @@ -62,9 +61,10 @@ func (client *VPNConnectionsClient) BeginCreateOrUpdate(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -75,18 +75,24 @@ func (client *VPNConnectionsClient) BeginCreateOrUpdate(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *VPNConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VPNConnection, options *VPNConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VPNConnectionsClient.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, gatewayName, connectionName, vpnConnectionParameters, 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. @@ -116,7 +122,10 @@ func (client *VPNConnectionsClient) createOrUpdateCreateRequest(ctx context.Cont reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnConnectionParameters) + if err := runtime.MarshalAsJSON(req, vpnConnectionParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a vpn connection. @@ -134,9 +143,10 @@ func (client *VPNConnectionsClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -147,18 +157,24 @@ func (client *VPNConnectionsClient) BeginDelete(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *VPNConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VPNConnectionsClient.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, gatewayName, connectionName, 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. @@ -200,18 +216,25 @@ func (client *VPNConnectionsClient) deleteCreateRequest(ctx context.Context, res // - connectionName - The name of the vpn connection. // - options - VPNConnectionsClientGetOptions contains the optional parameters for the VPNConnectionsClient.Get method. func (client *VPNConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientGetOptions) (VPNConnectionsClientGetResponse, error) { + var err error + const operationName = "VPNConnectionsClient.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, gatewayName, connectionName, options) if err != nil { return VPNConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -266,6 +289,7 @@ func (client *VPNConnectionsClient) NewListByVPNGatewayPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNConnectionsClientListByVPNGatewayResponse) (VPNConnectionsClientListByVPNGatewayResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNConnectionsClient.NewListByVPNGatewayPager") var req *policy.Request var err error if page == nil { @@ -285,6 +309,7 @@ func (client *VPNConnectionsClient) NewListByVPNGatewayPager(resourceGroupName s } return client.listByVPNGatewayHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -338,9 +363,10 @@ func (client *VPNConnectionsClient) BeginStartPacketCapture(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientStartPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientStartPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNConnectionsClientStartPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -351,18 +377,24 @@ func (client *VPNConnectionsClient) BeginStartPacketCapture(ctx context.Context, // // Generated from API version 2022-11-01 func (client *VPNConnectionsClient) startPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStartPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VPNConnectionsClient.BeginStartPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, vpnConnectionName, 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 } // startPacketCaptureCreateRequest creates the StartPacketCapture request. @@ -393,7 +425,10 @@ func (client *VPNConnectionsClient) startPacketCaptureCreateRequest(ctx context. 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 } @@ -413,9 +448,10 @@ func (client *VPNConnectionsClient) BeginStopPacketCapture(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientStopPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientStopPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNConnectionsClientStopPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -426,18 +462,24 @@ func (client *VPNConnectionsClient) BeginStopPacketCapture(ctx context.Context, // // Generated from API version 2022-11-01 func (client *VPNConnectionsClient) stopPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStopPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VPNConnectionsClient.BeginStopPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, vpnConnectionName, 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 } // stopPacketCaptureCreateRequest creates the StopPacketCapture request. @@ -468,7 +510,10 @@ func (client *VPNConnectionsClient) stopPacketCaptureCreateRequest(ctx context.C 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 } diff --git a/sdk/resourcemanager/network/armnetwork/vpngateways_client.go b/sdk/resourcemanager/network/armnetwork/vpngateways_client.go index ba1054b30dde..fb142497dcb8 100644 --- a/sdk/resourcemanager/network/armnetwork/vpngateways_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpngateways_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 armnetwork @@ -60,9 +59,10 @@ func (client *VPNGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNGatewaysClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VPNGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *VPNGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters VPNGateway, options *VPNGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VPNGatewaysClient.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, gatewayName, vpnGatewayParameters, 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. @@ -110,7 +116,10 @@ func (client *VPNGatewaysClient) createOrUpdateCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnGatewayParameters) + if err := runtime.MarshalAsJSON(req, vpnGatewayParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a virtual wan vpn gateway. @@ -126,9 +135,10 @@ func (client *VPNGatewaysClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNGatewaysClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *VPNGatewaysClient) BeginDelete(ctx context.Context, resourceGroupN // // Generated from API version 2022-11-01 func (client *VPNGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VPNGatewaysClient.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, gatewayName, 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. @@ -187,18 +203,25 @@ func (client *VPNGatewaysClient) deleteCreateRequest(ctx context.Context, resour // - gatewayName - The name of the gateway. // - options - VPNGatewaysClientGetOptions contains the optional parameters for the VPNGatewaysClient.Get method. func (client *VPNGatewaysClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientGetOptions) (VPNGatewaysClientGetResponse, error) { + var err error + const operationName = "VPNGatewaysClient.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, gatewayName, options) if err != nil { return VPNGatewaysClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNGatewaysClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNGatewaysClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNGatewaysClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -246,6 +269,7 @@ func (client *VPNGatewaysClient) NewListPager(options *VPNGatewaysClientListOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNGatewaysClientListResponse) (VPNGatewaysClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNGatewaysClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -265,6 +289,7 @@ func (client *VPNGatewaysClient) NewListPager(options *VPNGatewaysClientListOpti } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -307,6 +332,7 @@ func (client *VPNGatewaysClient) NewListByResourceGroupPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNGatewaysClientListByResourceGroupResponse) (VPNGatewaysClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNGatewaysClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -326,6 +352,7 @@ func (client *VPNGatewaysClient) NewListByResourceGroupPager(resourceGroupName s } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -373,9 +400,10 @@ func (client *VPNGatewaysClient) BeginReset(ctx context.Context, resourceGroupNa if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientResetResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientResetResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNGatewaysClientResetResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -386,18 +414,24 @@ func (client *VPNGatewaysClient) BeginReset(ctx context.Context, resourceGroupNa // // Generated from API version 2022-11-01 func (client *VPNGatewaysClient) reset(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginResetOptions) (*http.Response, error) { + var err error + const operationName = "VPNGatewaysClient.BeginReset" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetCreateRequest(ctx, resourceGroupName, gatewayName, 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 } // resetCreateRequest creates the Reset request. @@ -443,9 +477,10 @@ func (client *VPNGatewaysClient) BeginStartPacketCapture(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientStartPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientStartPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNGatewaysClientStartPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -456,18 +491,24 @@ func (client *VPNGatewaysClient) BeginStartPacketCapture(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *VPNGatewaysClient) startPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStartPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VPNGatewaysClient.BeginStartPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.startPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, 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 } // startPacketCaptureCreateRequest creates the StartPacketCapture request. @@ -494,7 +535,10 @@ func (client *VPNGatewaysClient) startPacketCaptureCreateRequest(ctx context.Con 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 } @@ -513,9 +557,10 @@ func (client *VPNGatewaysClient) BeginStopPacketCapture(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientStopPacketCaptureResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientStopPacketCaptureResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNGatewaysClientStopPacketCaptureResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -526,18 +571,24 @@ func (client *VPNGatewaysClient) BeginStopPacketCapture(ctx context.Context, res // // Generated from API version 2022-11-01 func (client *VPNGatewaysClient) stopPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStopPacketCaptureOptions) (*http.Response, error) { + var err error + const operationName = "VPNGatewaysClient.BeginStopPacketCapture" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.stopPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, 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 } // stopPacketCaptureCreateRequest creates the StopPacketCapture request. @@ -564,7 +615,10 @@ func (client *VPNGatewaysClient) stopPacketCaptureCreateRequest(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 } @@ -584,9 +638,10 @@ func (client *VPNGatewaysClient) BeginUpdateTags(ctx context.Context, resourceGr if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientUpdateTagsResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientUpdateTagsResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNGatewaysClientUpdateTagsResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -597,18 +652,24 @@ func (client *VPNGatewaysClient) BeginUpdateTags(ctx context.Context, resourceGr // // Generated from API version 2022-11-01 func (client *VPNGatewaysClient) updateTags(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters TagsObject, options *VPNGatewaysClientBeginUpdateTagsOptions) (*http.Response, error) { + var err error + const operationName = "VPNGatewaysClient.BeginUpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, gatewayName, vpnGatewayParameters, 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 } // updateTagsCreateRequest creates the UpdateTags request. @@ -634,5 +695,8 @@ func (client *VPNGatewaysClient) updateTagsCreateRequest(ctx context.Context, re reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnGatewayParameters) + if err := runtime.MarshalAsJSON(req, vpnGatewayParameters); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/network/armnetwork/vpnlinkconnections_client.go b/sdk/resourcemanager/network/armnetwork/vpnlinkconnections_client.go index 6f22c706cb41..2fa44128776c 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnlinkconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnlinkconnections_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 armnetwork @@ -61,9 +60,10 @@ func (client *VPNLinkConnectionsClient) BeginGetIkeSas(ctx context.Context, reso if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNLinkConnectionsClientGetIkeSasResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNLinkConnectionsClientGetIkeSasResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNLinkConnectionsClientGetIkeSasResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -74,18 +74,24 @@ func (client *VPNLinkConnectionsClient) BeginGetIkeSas(ctx context.Context, reso // // Generated from API version 2022-11-01 func (client *VPNLinkConnectionsClient) getIkeSas(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *VPNLinkConnectionsClientBeginGetIkeSasOptions) (*http.Response, error) { + var err error + const operationName = "VPNLinkConnectionsClient.BeginGetIkeSas" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getIkeSasCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, linkConnectionName, 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 } // getIkeSasCreateRequest creates the GetIkeSas request. @@ -136,6 +142,7 @@ func (client *VPNLinkConnectionsClient) NewListByVPNConnectionPager(resourceGrou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNLinkConnectionsClientListByVPNConnectionResponse) (VPNLinkConnectionsClientListByVPNConnectionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNLinkConnectionsClient.NewListByVPNConnectionPager") var req *policy.Request var err error if page == nil { @@ -155,6 +162,7 @@ func (client *VPNLinkConnectionsClient) NewListByVPNConnectionPager(resourceGrou } return client.listByVPNConnectionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -213,9 +221,10 @@ func (client *VPNLinkConnectionsClient) BeginResetConnection(ctx context.Context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNLinkConnectionsClientResetConnectionResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNLinkConnectionsClientResetConnectionResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNLinkConnectionsClientResetConnectionResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -226,18 +235,24 @@ func (client *VPNLinkConnectionsClient) BeginResetConnection(ctx context.Context // // Generated from API version 2022-11-01 func (client *VPNLinkConnectionsClient) resetConnection(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *VPNLinkConnectionsClientBeginResetConnectionOptions) (*http.Response, error) { + var err error + const operationName = "VPNLinkConnectionsClient.BeginResetConnection" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.resetConnectionCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, linkConnectionName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // resetConnectionCreateRequest creates the ResetConnection request. diff --git a/sdk/resourcemanager/network/armnetwork/vpnserverconfigurations_client.go b/sdk/resourcemanager/network/armnetwork/vpnserverconfigurations_client.go index 6a506b9f6f91..9cdd595cd696 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnserverconfigurations_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnserverconfigurations_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 armnetwork @@ -60,9 +59,10 @@ func (client *VPNServerConfigurationsClient) BeginCreateOrUpdate(ctx context.Con if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNServerConfigurationsClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNServerConfigurationsClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNServerConfigurationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VPNServerConfigurationsClient) BeginCreateOrUpdate(ctx context.Con // // Generated from API version 2022-11-01 func (client *VPNServerConfigurationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters VPNServerConfiguration, options *VPNServerConfigurationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VPNServerConfigurationsClient.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, vpnServerConfigurationName, vpnServerConfigurationParameters, 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. @@ -110,7 +116,10 @@ func (client *VPNServerConfigurationsClient) createOrUpdateCreateRequest(ctx con reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnServerConfigurationParameters) + if err := runtime.MarshalAsJSON(req, vpnServerConfigurationParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a VpnServerConfiguration. @@ -127,9 +136,10 @@ func (client *VPNServerConfigurationsClient) BeginDelete(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNServerConfigurationsClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNServerConfigurationsClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNServerConfigurationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -140,18 +150,24 @@ func (client *VPNServerConfigurationsClient) BeginDelete(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *VPNServerConfigurationsClient) deleteOperation(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VPNServerConfigurationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VPNServerConfigurationsClient.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, vpnServerConfigurationName, 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. @@ -189,18 +205,25 @@ func (client *VPNServerConfigurationsClient) deleteCreateRequest(ctx context.Con // - options - VPNServerConfigurationsClientGetOptions contains the optional parameters for the VPNServerConfigurationsClient.Get // method. func (client *VPNServerConfigurationsClient) Get(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VPNServerConfigurationsClientGetOptions) (VPNServerConfigurationsClientGetResponse, error) { + var err error + const operationName = "VPNServerConfigurationsClient.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, vpnServerConfigurationName, options) if err != nil { return VPNServerConfigurationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNServerConfigurationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNServerConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNServerConfigurationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -249,6 +272,7 @@ func (client *VPNServerConfigurationsClient) NewListPager(options *VPNServerConf return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNServerConfigurationsClientListResponse) (VPNServerConfigurationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNServerConfigurationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -268,6 +292,7 @@ func (client *VPNServerConfigurationsClient) NewListPager(options *VPNServerConf } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -310,6 +335,7 @@ func (client *VPNServerConfigurationsClient) NewListByResourceGroupPager(resourc return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNServerConfigurationsClientListByResourceGroupResponse) (VPNServerConfigurationsClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNServerConfigurationsClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -329,6 +355,7 @@ func (client *VPNServerConfigurationsClient) NewListByResourceGroupPager(resourc } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -373,18 +400,25 @@ func (client *VPNServerConfigurationsClient) listByResourceGroupHandleResponse(r // - options - VPNServerConfigurationsClientUpdateTagsOptions contains the optional parameters for the VPNServerConfigurationsClient.UpdateTags // method. func (client *VPNServerConfigurationsClient) UpdateTags(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters TagsObject, options *VPNServerConfigurationsClientUpdateTagsOptions) (VPNServerConfigurationsClientUpdateTagsResponse, error) { + var err error + const operationName = "VPNServerConfigurationsClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, vpnServerConfigurationName, vpnServerConfigurationParameters, options) if err != nil { return VPNServerConfigurationsClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNServerConfigurationsClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNServerConfigurationsClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNServerConfigurationsClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -410,7 +444,10 @@ func (client *VPNServerConfigurationsClient) updateTagsCreateRequest(ctx context reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnServerConfigurationParameters) + if err := runtime.MarshalAsJSON(req, vpnServerConfigurationParameters); err != nil { + return nil, err + } + return req, nil } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/vpnserverconfigurationsassociatedwithvirtualwan_client.go b/sdk/resourcemanager/network/armnetwork/vpnserverconfigurationsassociatedwithvirtualwan_client.go index 9a6420f3fc2d..7706d4cb5de8 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnserverconfigurationsassociatedwithvirtualwan_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnserverconfigurationsassociatedwithvirtualwan_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 armnetwork @@ -59,9 +58,10 @@ func (client *VPNServerConfigurationsAssociatedWithVirtualWanClient) BeginList(c if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -72,18 +72,24 @@ func (client *VPNServerConfigurationsAssociatedWithVirtualWanClient) BeginList(c // // Generated from API version 2022-11-01 func (client *VPNServerConfigurationsAssociatedWithVirtualWanClient) listOperation(ctx context.Context, resourceGroupName string, virtualWANName string, options *VPNServerConfigurationsAssociatedWithVirtualWanClientBeginListOptions) (*http.Response, error) { + var err error + const operationName = "VPNServerConfigurationsAssociatedWithVirtualWanClient.BeginList" + 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, virtualWANName, 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 } // listCreateRequest creates the List request. diff --git a/sdk/resourcemanager/network/armnetwork/vpnsitelinkconnections_client.go b/sdk/resourcemanager/network/armnetwork/vpnsitelinkconnections_client.go index a81a43d0d21a..97e1385ac4d8 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnsitelinkconnections_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnsitelinkconnections_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 armnetwork @@ -56,18 +55,25 @@ func NewVPNSiteLinkConnectionsClient(subscriptionID string, credential azcore.To // - options - VPNSiteLinkConnectionsClientGetOptions contains the optional parameters for the VPNSiteLinkConnectionsClient.Get // method. func (client *VPNSiteLinkConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *VPNSiteLinkConnectionsClientGetOptions) (VPNSiteLinkConnectionsClientGetResponse, error) { + var err error + const operationName = "VPNSiteLinkConnectionsClient.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, gatewayName, connectionName, linkConnectionName, options) if err != nil { return VPNSiteLinkConnectionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNSiteLinkConnectionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNSiteLinkConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNSiteLinkConnectionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. diff --git a/sdk/resourcemanager/network/armnetwork/vpnsitelinks_client.go b/sdk/resourcemanager/network/armnetwork/vpnsitelinks_client.go index 3fdd532e79f3..0a512bc43733 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnsitelinks_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnsitelinks_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 armnetwork @@ -54,18 +53,25 @@ func NewVPNSiteLinksClient(subscriptionID string, credential azcore.TokenCredent // - vpnSiteLinkName - The name of the VpnSiteLink being retrieved. // - options - VPNSiteLinksClientGetOptions contains the optional parameters for the VPNSiteLinksClient.Get method. func (client *VPNSiteLinksClient) Get(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteLinkName string, options *VPNSiteLinksClientGetOptions) (VPNSiteLinksClientGetResponse, error) { + var err error + const operationName = "VPNSiteLinksClient.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, vpnSiteName, vpnSiteLinkName, options) if err != nil { return VPNSiteLinksClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNSiteLinksClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNSiteLinksClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNSiteLinksClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -120,6 +126,7 @@ func (client *VPNSiteLinksClient) NewListByVPNSitePager(resourceGroupName string return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNSiteLinksClientListByVPNSiteResponse) (VPNSiteLinksClientListByVPNSiteResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNSiteLinksClient.NewListByVPNSitePager") var req *policy.Request var err error if page == nil { @@ -139,6 +146,7 @@ func (client *VPNSiteLinksClient) NewListByVPNSitePager(resourceGroupName string } return client.listByVPNSiteHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/vpnsites_client.go b/sdk/resourcemanager/network/armnetwork/vpnsites_client.go index 90d68f6d52a8..d849c1b2d992 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnsites_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnsites_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 armnetwork @@ -60,9 +59,10 @@ func (client *VPNSitesClient) BeginCreateOrUpdate(ctx context.Context, resourceG if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNSitesClientCreateOrUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNSitesClientCreateOrUpdateResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNSitesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VPNSitesClient) BeginCreateOrUpdate(ctx context.Context, resourceG // // Generated from API version 2022-11-01 func (client *VPNSitesClient) createOrUpdate(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteParameters VPNSite, options *VPNSitesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "VPNSitesClient.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, vpnSiteName, vpnSiteParameters, 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. @@ -110,7 +116,10 @@ func (client *VPNSitesClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnSiteParameters) + if err := runtime.MarshalAsJSON(req, vpnSiteParameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes a VpnSite. @@ -126,9 +135,10 @@ func (client *VPNSitesClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNSitesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNSitesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNSitesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -139,18 +149,24 @@ func (client *VPNSitesClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *VPNSitesClient) deleteOperation(ctx context.Context, resourceGroupName string, vpnSiteName string, options *VPNSitesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "VPNSitesClient.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, vpnSiteName, 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. @@ -187,18 +203,25 @@ func (client *VPNSitesClient) deleteCreateRequest(ctx context.Context, resourceG // - vpnSiteName - The name of the VpnSite being retrieved. // - options - VPNSitesClientGetOptions contains the optional parameters for the VPNSitesClient.Get method. func (client *VPNSitesClient) Get(ctx context.Context, resourceGroupName string, vpnSiteName string, options *VPNSitesClientGetOptions) (VPNSitesClientGetResponse, error) { + var err error + const operationName = "VPNSitesClient.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, vpnSiteName, options) if err != nil { return VPNSitesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNSitesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNSitesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNSitesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -246,6 +269,7 @@ func (client *VPNSitesClient) NewListPager(options *VPNSitesClientListOptions) * return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNSitesClientListResponse) (VPNSitesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNSitesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -265,6 +289,7 @@ func (client *VPNSitesClient) NewListPager(options *VPNSitesClientListOptions) * } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -307,6 +332,7 @@ func (client *VPNSitesClient) NewListByResourceGroupPager(resourceGroupName stri return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VPNSitesClientListByResourceGroupResponse) (VPNSitesClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNSitesClient.NewListByResourceGroupPager") var req *policy.Request var err error if page == nil { @@ -326,6 +352,7 @@ func (client *VPNSitesClient) NewListByResourceGroupPager(resourceGroupName stri } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -369,18 +396,25 @@ func (client *VPNSitesClient) listByResourceGroupHandleResponse(resp *http.Respo // - vpnSiteParameters - Parameters supplied to update VpnSite tags. // - options - VPNSitesClientUpdateTagsOptions contains the optional parameters for the VPNSitesClient.UpdateTags method. func (client *VPNSitesClient) UpdateTags(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteParameters TagsObject, options *VPNSitesClientUpdateTagsOptions) (VPNSitesClientUpdateTagsResponse, error) { + var err error + const operationName = "VPNSitesClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, vpnSiteName, vpnSiteParameters, options) if err != nil { return VPNSitesClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return VPNSitesClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VPNSitesClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return VPNSitesClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -406,7 +440,10 @@ func (client *VPNSitesClient) updateTagsCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, vpnSiteParameters) + if err := runtime.MarshalAsJSON(req, vpnSiteParameters); err != nil { + return nil, err + } + return req, nil } // updateTagsHandleResponse handles the UpdateTags response. diff --git a/sdk/resourcemanager/network/armnetwork/vpnsitesconfiguration_client.go b/sdk/resourcemanager/network/armnetwork/vpnsitesconfiguration_client.go index 97209e5baeef..181408f6ea14 100644 --- a/sdk/resourcemanager/network/armnetwork/vpnsitesconfiguration_client.go +++ b/sdk/resourcemanager/network/armnetwork/vpnsitesconfiguration_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 armnetwork @@ -60,9 +59,10 @@ func (client *VPNSitesConfigurationClient) BeginDownload(ctx context.Context, re if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNSitesConfigurationClientDownloadResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNSitesConfigurationClientDownloadResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[VPNSitesConfigurationClientDownloadResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -73,18 +73,24 @@ func (client *VPNSitesConfigurationClient) BeginDownload(ctx context.Context, re // // Generated from API version 2022-11-01 func (client *VPNSitesConfigurationClient) download(ctx context.Context, resourceGroupName string, virtualWANName string, request GetVPNSitesConfigurationRequest, options *VPNSitesConfigurationClientBeginDownloadOptions) (*http.Response, error) { + var err error + const operationName = "VPNSitesConfigurationClient.BeginDownload" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.downloadCreateRequest(ctx, resourceGroupName, virtualWANName, request, 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 } // downloadCreateRequest creates the Download request. @@ -110,5 +116,8 @@ func (client *VPNSitesConfigurationClient) downloadCreateRequest(ctx context.Con reqQP.Set("api-version", "2022-11-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, request) + if err := runtime.MarshalAsJSON(req, request); err != nil { + return nil, err + } + return req, nil } diff --git a/sdk/resourcemanager/network/armnetwork/watchers_client.go b/sdk/resourcemanager/network/armnetwork/watchers_client.go index b03e5bfa4551..57b6cae90f9c 100644 --- a/sdk/resourcemanager/network/armnetwork/watchers_client.go +++ b/sdk/resourcemanager/network/armnetwork/watchers_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 armnetwork @@ -61,9 +60,10 @@ func (client *WatchersClient) BeginCheckConnectivity(ctx context.Context, resour if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientCheckConnectivityResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientCheckConnectivityResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientCheckConnectivityResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -75,18 +75,24 @@ func (client *WatchersClient) BeginCheckConnectivity(ctx context.Context, resour // // Generated from API version 2022-11-01 func (client *WatchersClient) checkConnectivity(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters ConnectivityParameters, options *WatchersClientBeginCheckConnectivityOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginCheckConnectivity" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.checkConnectivityCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // checkConnectivityCreateRequest creates the CheckConnectivity request. @@ -112,7 +118,10 @@ func (client *WatchersClient) checkConnectivityCreateRequest(ctx context.Context reqQP.Set("api-version", "2022-11-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 } // CreateOrUpdate - Creates or updates a network watcher in the specified resource group. @@ -124,18 +133,25 @@ func (client *WatchersClient) checkConnectivityCreateRequest(ctx context.Context // - parameters - Parameters that define the network watcher resource. // - options - WatchersClientCreateOrUpdateOptions contains the optional parameters for the WatchersClient.CreateOrUpdate method. func (client *WatchersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters Watcher, options *WatchersClientCreateOrUpdateOptions) (WatchersClientCreateOrUpdateResponse, error) { + var err error + const operationName = "WatchersClient.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, networkWatcherName, parameters, options) if err != nil { return WatchersClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WatchersClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return WatchersClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return WatchersClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -161,7 +177,10 @@ func (client *WatchersClient) createOrUpdateCreateRequest(ctx context.Context, r reqQP.Set("api-version", "2022-11-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. @@ -186,9 +205,10 @@ func (client *WatchersClient) BeginDelete(ctx context.Context, resourceGroupName if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -199,18 +219,24 @@ func (client *WatchersClient) BeginDelete(ctx context.Context, resourceGroupName // // Generated from API version 2022-11-01 func (client *WatchersClient) deleteOperation(ctx context.Context, resourceGroupName string, networkWatcherName string, options *WatchersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.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, networkWatcherName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -247,18 +273,25 @@ func (client *WatchersClient) deleteCreateRequest(ctx context.Context, resourceG // - networkWatcherName - The name of the network watcher. // - options - WatchersClientGetOptions contains the optional parameters for the WatchersClient.Get method. func (client *WatchersClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, options *WatchersClientGetOptions) (WatchersClientGetResponse, error) { + var err error + const operationName = "WatchersClient.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, networkWatcherName, options) if err != nil { return WatchersClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WatchersClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return WatchersClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return WatchersClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -312,9 +345,10 @@ func (client *WatchersClient) BeginGetAzureReachabilityReport(ctx context.Contex if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetAzureReachabilityReportResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetAzureReachabilityReportResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetAzureReachabilityReportResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -326,18 +360,24 @@ func (client *WatchersClient) BeginGetAzureReachabilityReport(ctx context.Contex // // Generated from API version 2022-11-01 func (client *WatchersClient) getAzureReachabilityReport(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters AzureReachabilityReportParameters, options *WatchersClientBeginGetAzureReachabilityReportOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetAzureReachabilityReport" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAzureReachabilityReportCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getAzureReachabilityReportCreateRequest creates the GetAzureReachabilityReport request. @@ -363,7 +403,10 @@ func (client *WatchersClient) getAzureReachabilityReportCreateRequest(ctx contex reqQP.Set("api-version", "2022-11-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 } // BeginGetFlowLogStatus - Queries status of flow log and traffic analytics (optional) on a specified resource. @@ -381,9 +424,10 @@ func (client *WatchersClient) BeginGetFlowLogStatus(ctx context.Context, resourc if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetFlowLogStatusResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetFlowLogStatusResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetFlowLogStatusResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -394,18 +438,24 @@ func (client *WatchersClient) BeginGetFlowLogStatus(ctx context.Context, resourc // // Generated from API version 2022-11-01 func (client *WatchersClient) getFlowLogStatus(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters FlowLogStatusParameters, options *WatchersClientBeginGetFlowLogStatusOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetFlowLogStatus" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getFlowLogStatusCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getFlowLogStatusCreateRequest creates the GetFlowLogStatus request. @@ -431,7 +481,10 @@ func (client *WatchersClient) getFlowLogStatusCreateRequest(ctx context.Context, reqQP.Set("api-version", "2022-11-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 } // BeginGetNetworkConfigurationDiagnostic - Gets Network Configuration Diagnostic data to help customers understand and debug @@ -453,9 +506,10 @@ func (client *WatchersClient) BeginGetNetworkConfigurationDiagnostic(ctx context if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetNetworkConfigurationDiagnosticResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetNetworkConfigurationDiagnosticResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetNetworkConfigurationDiagnosticResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -470,18 +524,24 @@ func (client *WatchersClient) BeginGetNetworkConfigurationDiagnostic(ctx context // // Generated from API version 2022-11-01 func (client *WatchersClient) getNetworkConfigurationDiagnostic(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters ConfigurationDiagnosticParameters, options *WatchersClientBeginGetNetworkConfigurationDiagnosticOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetNetworkConfigurationDiagnostic" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getNetworkConfigurationDiagnosticCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getNetworkConfigurationDiagnosticCreateRequest creates the GetNetworkConfigurationDiagnostic request. @@ -507,7 +567,10 @@ func (client *WatchersClient) getNetworkConfigurationDiagnosticCreateRequest(ctx reqQP.Set("api-version", "2022-11-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 } // BeginGetNextHop - Gets the next hop from the specified VM. @@ -525,9 +588,10 @@ func (client *WatchersClient) BeginGetNextHop(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetNextHopResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetNextHopResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetNextHopResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -538,18 +602,24 @@ func (client *WatchersClient) BeginGetNextHop(ctx context.Context, resourceGroup // // Generated from API version 2022-11-01 func (client *WatchersClient) getNextHop(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters NextHopParameters, options *WatchersClientBeginGetNextHopOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetNextHop" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getNextHopCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getNextHopCreateRequest creates the GetNextHop request. @@ -575,7 +645,10 @@ func (client *WatchersClient) getNextHopCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-11-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 } // GetTopology - Gets the current network topology by resource group. @@ -587,18 +660,25 @@ func (client *WatchersClient) getNextHopCreateRequest(ctx context.Context, resou // - parameters - Parameters that define the representation of topology. // - options - WatchersClientGetTopologyOptions contains the optional parameters for the WatchersClient.GetTopology method. func (client *WatchersClient) GetTopology(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TopologyParameters, options *WatchersClientGetTopologyOptions) (WatchersClientGetTopologyResponse, error) { + var err error + const operationName = "WatchersClient.GetTopology" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getTopologyCreateRequest(ctx, resourceGroupName, networkWatcherName, parameters, options) if err != nil { return WatchersClientGetTopologyResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WatchersClientGetTopologyResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return WatchersClientGetTopologyResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return WatchersClientGetTopologyResponse{}, err } - return client.getTopologyHandleResponse(resp) + resp, err := client.getTopologyHandleResponse(httpResp) + return resp, err } // getTopologyCreateRequest creates the GetTopology request. @@ -624,7 +704,10 @@ func (client *WatchersClient) getTopologyCreateRequest(ctx context.Context, reso reqQP.Set("api-version", "2022-11-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 } // getTopologyHandleResponse handles the GetTopology response. @@ -651,9 +734,10 @@ func (client *WatchersClient) BeginGetTroubleshooting(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetTroubleshootingResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetTroubleshootingResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetTroubleshootingResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -664,18 +748,24 @@ func (client *WatchersClient) BeginGetTroubleshooting(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *WatchersClient) getTroubleshooting(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TroubleshootingParameters, options *WatchersClientBeginGetTroubleshootingOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetTroubleshooting" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getTroubleshootingCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getTroubleshootingCreateRequest creates the GetTroubleshooting request. @@ -701,7 +791,10 @@ func (client *WatchersClient) getTroubleshootingCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-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 } // BeginGetTroubleshootingResult - Get the last completed troubleshooting result on a specified resource. @@ -719,9 +812,10 @@ func (client *WatchersClient) BeginGetTroubleshootingResult(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetTroubleshootingResultResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetTroubleshootingResultResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetTroubleshootingResultResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -732,18 +826,24 @@ func (client *WatchersClient) BeginGetTroubleshootingResult(ctx context.Context, // // Generated from API version 2022-11-01 func (client *WatchersClient) getTroubleshootingResult(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters QueryTroubleshootingParameters, options *WatchersClientBeginGetTroubleshootingResultOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetTroubleshootingResult" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getTroubleshootingResultCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getTroubleshootingResultCreateRequest creates the GetTroubleshootingResult request. @@ -769,7 +869,10 @@ func (client *WatchersClient) getTroubleshootingResultCreateRequest(ctx context. reqQP.Set("api-version", "2022-11-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 } // BeginGetVMSecurityRules - Gets the configured and effective security group rules on the specified VM. @@ -787,9 +890,10 @@ func (client *WatchersClient) BeginGetVMSecurityRules(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetVMSecurityRulesResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientGetVMSecurityRulesResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientGetVMSecurityRulesResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -800,18 +904,24 @@ func (client *WatchersClient) BeginGetVMSecurityRules(ctx context.Context, resou // // Generated from API version 2022-11-01 func (client *WatchersClient) getVMSecurityRules(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters SecurityGroupViewParameters, options *WatchersClientBeginGetVMSecurityRulesOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginGetVMSecurityRules" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getVMSecurityRulesCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // getVMSecurityRulesCreateRequest creates the GetVMSecurityRules request. @@ -837,7 +947,10 @@ func (client *WatchersClient) getVMSecurityRulesCreateRequest(ctx context.Contex reqQP.Set("api-version", "2022-11-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 } // NewListPager - Gets all network watchers by resource group. @@ -851,6 +964,7 @@ func (client *WatchersClient) NewListPager(resourceGroupName string, options *Wa return false }, Fetcher: func(ctx context.Context, page *WatchersClientListResponse) (WatchersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "WatchersClient.NewListPager") req, err := client.listCreateRequest(ctx, resourceGroupName, options) if err != nil { return WatchersClientListResponse{}, err @@ -864,6 +978,7 @@ func (client *WatchersClient) NewListPager(resourceGroupName string, options *Wa } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -908,6 +1023,7 @@ func (client *WatchersClient) NewListAllPager(options *WatchersClientListAllOpti return false }, Fetcher: func(ctx context.Context, page *WatchersClientListAllResponse) (WatchersClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "WatchersClient.NewListAllPager") req, err := client.listAllCreateRequest(ctx, options) if err != nil { return WatchersClientListAllResponse{}, err @@ -921,6 +1037,7 @@ func (client *WatchersClient) NewListAllPager(options *WatchersClientListAllOpti } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -967,9 +1084,10 @@ func (client *WatchersClient) BeginListAvailableProviders(ctx context.Context, r if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientListAvailableProvidersResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientListAvailableProvidersResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientListAvailableProvidersResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -981,18 +1099,24 @@ func (client *WatchersClient) BeginListAvailableProviders(ctx context.Context, r // // Generated from API version 2022-11-01 func (client *WatchersClient) listAvailableProviders(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters AvailableProvidersListParameters, options *WatchersClientBeginListAvailableProvidersOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginListAvailableProviders" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listAvailableProvidersCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // listAvailableProvidersCreateRequest creates the ListAvailableProviders request. @@ -1018,7 +1142,10 @@ func (client *WatchersClient) listAvailableProvidersCreateRequest(ctx context.Co reqQP.Set("api-version", "2022-11-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 } // BeginSetFlowLogConfiguration - Configures flow log and traffic analytics (optional) on a specified resource. @@ -1036,9 +1163,10 @@ func (client *WatchersClient) BeginSetFlowLogConfiguration(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientSetFlowLogConfigurationResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientSetFlowLogConfigurationResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientSetFlowLogConfigurationResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1049,18 +1177,24 @@ func (client *WatchersClient) BeginSetFlowLogConfiguration(ctx context.Context, // // Generated from API version 2022-11-01 func (client *WatchersClient) setFlowLogConfiguration(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters FlowLogInformation, options *WatchersClientBeginSetFlowLogConfigurationOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginSetFlowLogConfiguration" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.setFlowLogConfigurationCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // setFlowLogConfigurationCreateRequest creates the SetFlowLogConfiguration request. @@ -1086,7 +1220,10 @@ func (client *WatchersClient) setFlowLogConfigurationCreateRequest(ctx context.C reqQP.Set("api-version", "2022-11-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 } // UpdateTags - Updates a network watcher tags. @@ -1098,18 +1235,25 @@ func (client *WatchersClient) setFlowLogConfigurationCreateRequest(ctx context.C // - parameters - Parameters supplied to update network watcher tags. // - options - WatchersClientUpdateTagsOptions contains the optional parameters for the WatchersClient.UpdateTags method. func (client *WatchersClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TagsObject, options *WatchersClientUpdateTagsOptions) (WatchersClientUpdateTagsResponse, error) { + var err error + const operationName = "WatchersClient.UpdateTags" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkWatcherName, parameters, options) if err != nil { return WatchersClientUpdateTagsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WatchersClientUpdateTagsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return WatchersClientUpdateTagsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return WatchersClientUpdateTagsResponse{}, err } - return client.updateTagsHandleResponse(resp) + resp, err := client.updateTagsHandleResponse(httpResp) + return resp, err } // updateTagsCreateRequest creates the UpdateTags request. @@ -1135,7 +1279,10 @@ func (client *WatchersClient) updateTagsCreateRequest(ctx context.Context, resou reqQP.Set("api-version", "2022-11-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 } // updateTagsHandleResponse handles the UpdateTags response. @@ -1162,9 +1309,10 @@ func (client *WatchersClient) BeginVerifyIPFlow(ctx context.Context, resourceGro if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientVerifyIPFlowResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WatchersClientVerifyIPFlowResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WatchersClientVerifyIPFlowResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -1175,18 +1323,24 @@ func (client *WatchersClient) BeginVerifyIPFlow(ctx context.Context, resourceGro // // Generated from API version 2022-11-01 func (client *WatchersClient) verifyIPFlow(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters VerificationIPFlowParameters, options *WatchersClientBeginVerifyIPFlowOptions) (*http.Response, error) { + var err error + const operationName = "WatchersClient.BeginVerifyIPFlow" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.verifyIPFlowCreateRequest(ctx, resourceGroupName, networkWatcherName, 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 } // verifyIPFlowCreateRequest creates the VerifyIPFlow request. @@ -1212,5 +1366,8 @@ func (client *WatchersClient) verifyIPFlowCreateRequest(ctx context.Context, res reqQP.Set("api-version", "2022-11-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/network/armnetwork/webapplicationfirewallpolicies_client.go b/sdk/resourcemanager/network/armnetwork/webapplicationfirewallpolicies_client.go index 1a7335fdfe09..21b17018eff2 100644 --- a/sdk/resourcemanager/network/armnetwork/webapplicationfirewallpolicies_client.go +++ b/sdk/resourcemanager/network/armnetwork/webapplicationfirewallpolicies_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 armnetwork @@ -55,18 +54,25 @@ func NewWebApplicationFirewallPoliciesClient(subscriptionID string, credential a // - options - WebApplicationFirewallPoliciesClientCreateOrUpdateOptions contains the optional parameters for the WebApplicationFirewallPoliciesClient.CreateOrUpdate // method. func (client *WebApplicationFirewallPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, policyName string, parameters WebApplicationFirewallPolicy, options *WebApplicationFirewallPoliciesClientCreateOrUpdateOptions) (WebApplicationFirewallPoliciesClientCreateOrUpdateResponse, error) { + var err error + const operationName = "WebApplicationFirewallPoliciesClient.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, policyName, parameters, options) if err != nil { return WebApplicationFirewallPoliciesClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WebApplicationFirewallPoliciesClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return WebApplicationFirewallPoliciesClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return WebApplicationFirewallPoliciesClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -92,7 +98,10 @@ func (client *WebApplicationFirewallPoliciesClient) createOrUpdateCreateRequest( reqQP.Set("api-version", "2022-11-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. @@ -118,9 +127,10 @@ func (client *WebApplicationFirewallPoliciesClient) BeginDelete(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WebApplicationFirewallPoliciesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[WebApplicationFirewallPoliciesClientDeleteResponse]{ FinalStateVia: runtime.FinalStateViaLocation, }) + return poller, err } else { return runtime.NewPollerFromResumeToken[WebApplicationFirewallPoliciesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) } @@ -131,18 +141,24 @@ func (client *WebApplicationFirewallPoliciesClient) BeginDelete(ctx context.Cont // // Generated from API version 2022-11-01 func (client *WebApplicationFirewallPoliciesClient) deleteOperation(ctx context.Context, resourceGroupName string, policyName string, options *WebApplicationFirewallPoliciesClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "WebApplicationFirewallPoliciesClient.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, policyName, 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. @@ -180,18 +196,25 @@ func (client *WebApplicationFirewallPoliciesClient) deleteCreateRequest(ctx cont // - options - WebApplicationFirewallPoliciesClientGetOptions contains the optional parameters for the WebApplicationFirewallPoliciesClient.Get // method. func (client *WebApplicationFirewallPoliciesClient) Get(ctx context.Context, resourceGroupName string, policyName string, options *WebApplicationFirewallPoliciesClientGetOptions) (WebApplicationFirewallPoliciesClientGetResponse, error) { + var err error + const operationName = "WebApplicationFirewallPoliciesClient.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, policyName, options) if err != nil { return WebApplicationFirewallPoliciesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WebApplicationFirewallPoliciesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return WebApplicationFirewallPoliciesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return WebApplicationFirewallPoliciesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -241,6 +264,7 @@ func (client *WebApplicationFirewallPoliciesClient) NewListPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *WebApplicationFirewallPoliciesClientListResponse) (WebApplicationFirewallPoliciesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "WebApplicationFirewallPoliciesClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -260,6 +284,7 @@ func (client *WebApplicationFirewallPoliciesClient) NewListPager(resourceGroupNa } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -305,6 +330,7 @@ func (client *WebApplicationFirewallPoliciesClient) NewListAllPager(options *Web return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *WebApplicationFirewallPoliciesClientListAllResponse) (WebApplicationFirewallPoliciesClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "WebApplicationFirewallPoliciesClient.NewListAllPager") var req *policy.Request var err error if page == nil { @@ -324,6 +350,7 @@ func (client *WebApplicationFirewallPoliciesClient) NewListAllPager(options *Web } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/network/armnetwork/webcategories_client.go b/sdk/resourcemanager/network/armnetwork/webcategories_client.go index 5a93687b1560..e620c5fee7b9 100644 --- a/sdk/resourcemanager/network/armnetwork/webcategories_client.go +++ b/sdk/resourcemanager/network/armnetwork/webcategories_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 armnetwork @@ -52,18 +51,25 @@ func NewWebCategoriesClient(subscriptionID string, credential azcore.TokenCreden // - name - The name of the azureWebCategory. // - options - WebCategoriesClientGetOptions contains the optional parameters for the WebCategoriesClient.Get method. func (client *WebCategoriesClient) Get(ctx context.Context, name string, options *WebCategoriesClientGetOptions) (WebCategoriesClientGetResponse, error) { + var err error + const operationName = "WebCategoriesClient.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, name, options) if err != nil { return WebCategoriesClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return WebCategoriesClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return WebCategoriesClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return WebCategoriesClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -111,6 +117,7 @@ func (client *WebCategoriesClient) NewListBySubscriptionPager(options *WebCatego return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *WebCategoriesClientListBySubscriptionResponse) (WebCategoriesClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "WebCategoriesClient.NewListBySubscriptionPager") var req *policy.Request var err error if page == nil { @@ -130,6 +137,7 @@ func (client *WebCategoriesClient) NewListBySubscriptionPager(options *WebCatego } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) }