github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/firewallpolicydeployments_server.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package fake 10 11 import ( 12 "context" 13 "errors" 14 "fmt" 15 azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" 19 "net/http" 20 "net/url" 21 "regexp" 22 ) 23 24 // FirewallPolicyDeploymentsServer is a fake server for instances of the armnetwork.FirewallPolicyDeploymentsClient type. 25 type FirewallPolicyDeploymentsServer struct { 26 // BeginDeploy is the fake for method FirewallPolicyDeploymentsClient.BeginDeploy 27 // HTTP status codes to indicate success: http.StatusAccepted 28 BeginDeploy func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyDeploymentsClientBeginDeployOptions) (resp azfake.PollerResponder[armnetwork.FirewallPolicyDeploymentsClientDeployResponse], errResp azfake.ErrorResponder) 29 } 30 31 // NewFirewallPolicyDeploymentsServerTransport creates a new instance of FirewallPolicyDeploymentsServerTransport with the provided implementation. 32 // The returned FirewallPolicyDeploymentsServerTransport instance is connected to an instance of armnetwork.FirewallPolicyDeploymentsClient via the 33 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 34 func NewFirewallPolicyDeploymentsServerTransport(srv *FirewallPolicyDeploymentsServer) *FirewallPolicyDeploymentsServerTransport { 35 return &FirewallPolicyDeploymentsServerTransport{ 36 srv: srv, 37 beginDeploy: newTracker[azfake.PollerResponder[armnetwork.FirewallPolicyDeploymentsClientDeployResponse]](), 38 } 39 } 40 41 // FirewallPolicyDeploymentsServerTransport connects instances of armnetwork.FirewallPolicyDeploymentsClient to instances of FirewallPolicyDeploymentsServer. 42 // Don't use this type directly, use NewFirewallPolicyDeploymentsServerTransport instead. 43 type FirewallPolicyDeploymentsServerTransport struct { 44 srv *FirewallPolicyDeploymentsServer 45 beginDeploy *tracker[azfake.PollerResponder[armnetwork.FirewallPolicyDeploymentsClientDeployResponse]] 46 } 47 48 // Do implements the policy.Transporter interface for FirewallPolicyDeploymentsServerTransport. 49 func (f *FirewallPolicyDeploymentsServerTransport) Do(req *http.Request) (*http.Response, error) { 50 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 51 method, ok := rawMethod.(string) 52 if !ok { 53 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 54 } 55 56 var resp *http.Response 57 var err error 58 59 switch method { 60 case "FirewallPolicyDeploymentsClient.BeginDeploy": 61 resp, err = f.dispatchBeginDeploy(req) 62 default: 63 err = fmt.Errorf("unhandled API %s", method) 64 } 65 66 if err != nil { 67 return nil, err 68 } 69 70 return resp, nil 71 } 72 73 func (f *FirewallPolicyDeploymentsServerTransport) dispatchBeginDeploy(req *http.Request) (*http.Response, error) { 74 if f.srv.BeginDeploy == nil { 75 return nil, &nonRetriableError{errors.New("fake for method BeginDeploy not implemented")} 76 } 77 beginDeploy := f.beginDeploy.get(req) 78 if beginDeploy == nil { 79 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/firewallPolicies/(?P<firewallPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deploy` 80 regex := regexp.MustCompile(regexStr) 81 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 82 if matches == nil || len(matches) < 3 { 83 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 84 } 85 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 86 if err != nil { 87 return nil, err 88 } 89 firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) 90 if err != nil { 91 return nil, err 92 } 93 respr, errRespr := f.srv.BeginDeploy(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, nil) 94 if respErr := server.GetError(errRespr, req); respErr != nil { 95 return nil, respErr 96 } 97 beginDeploy = &respr 98 f.beginDeploy.add(req, beginDeploy) 99 } 100 101 resp, err := server.PollerResponderNext(beginDeploy, req) 102 if err != nil { 103 return nil, err 104 } 105 106 if !contains([]int{http.StatusAccepted}, resp.StatusCode) { 107 f.beginDeploy.remove(req) 108 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted", resp.StatusCode)} 109 } 110 if !server.PollerResponderMore(beginDeploy) { 111 f.beginDeploy.remove(req) 112 } 113 114 return resp, nil 115 }