github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/firewallpolicyidpssignaturesoverrides_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 // FirewallPolicyIdpsSignaturesOverridesServer is a fake server for instances of the armnetwork.FirewallPolicyIdpsSignaturesOverridesClient type. 25 type FirewallPolicyIdpsSignaturesOverridesServer struct { 26 // Get is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.Get 27 // HTTP status codes to indicate success: http.StatusOK 28 Get func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientGetOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientGetResponse], errResp azfake.ErrorResponder) 29 30 // List is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.List 31 // HTTP status codes to indicate success: http.StatusOK 32 List func(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientListOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientListResponse], errResp azfake.ErrorResponder) 33 34 // Patch is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.Patch 35 // HTTP status codes to indicate success: http.StatusOK 36 Patch func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.SignaturesOverrides, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPatchOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPatchResponse], errResp azfake.ErrorResponder) 37 38 // Put is the fake for method FirewallPolicyIdpsSignaturesOverridesClient.Put 39 // HTTP status codes to indicate success: http.StatusOK 40 Put func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.SignaturesOverrides, options *armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPutOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesOverridesClientPutResponse], errResp azfake.ErrorResponder) 41 } 42 43 // NewFirewallPolicyIdpsSignaturesOverridesServerTransport creates a new instance of FirewallPolicyIdpsSignaturesOverridesServerTransport with the provided implementation. 44 // The returned FirewallPolicyIdpsSignaturesOverridesServerTransport instance is connected to an instance of armnetwork.FirewallPolicyIdpsSignaturesOverridesClient via the 45 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 46 func NewFirewallPolicyIdpsSignaturesOverridesServerTransport(srv *FirewallPolicyIdpsSignaturesOverridesServer) *FirewallPolicyIdpsSignaturesOverridesServerTransport { 47 return &FirewallPolicyIdpsSignaturesOverridesServerTransport{srv: srv} 48 } 49 50 // FirewallPolicyIdpsSignaturesOverridesServerTransport connects instances of armnetwork.FirewallPolicyIdpsSignaturesOverridesClient to instances of FirewallPolicyIdpsSignaturesOverridesServer. 51 // Don't use this type directly, use NewFirewallPolicyIdpsSignaturesOverridesServerTransport instead. 52 type FirewallPolicyIdpsSignaturesOverridesServerTransport struct { 53 srv *FirewallPolicyIdpsSignaturesOverridesServer 54 } 55 56 // Do implements the policy.Transporter interface for FirewallPolicyIdpsSignaturesOverridesServerTransport. 57 func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) Do(req *http.Request) (*http.Response, error) { 58 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 59 method, ok := rawMethod.(string) 60 if !ok { 61 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 62 } 63 64 var resp *http.Response 65 var err error 66 67 switch method { 68 case "FirewallPolicyIdpsSignaturesOverridesClient.Get": 69 resp, err = f.dispatchGet(req) 70 case "FirewallPolicyIdpsSignaturesOverridesClient.List": 71 resp, err = f.dispatchList(req) 72 case "FirewallPolicyIdpsSignaturesOverridesClient.Patch": 73 resp, err = f.dispatchPatch(req) 74 case "FirewallPolicyIdpsSignaturesOverridesClient.Put": 75 resp, err = f.dispatchPut(req) 76 default: 77 err = fmt.Errorf("unhandled API %s", method) 78 } 79 80 if err != nil { 81 return nil, err 82 } 83 84 return resp, nil 85 } 86 87 func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 88 if f.srv.Get == nil { 89 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 90 } 91 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~%@]+)/signatureOverrides/default` 92 regex := regexp.MustCompile(regexStr) 93 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 94 if matches == nil || len(matches) < 3 { 95 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 96 } 97 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 98 if err != nil { 99 return nil, err 100 } 101 firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) 102 if err != nil { 103 return nil, err 104 } 105 respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, nil) 106 if respErr := server.GetError(errRespr, req); respErr != nil { 107 return nil, respErr 108 } 109 respContent := server.GetResponseContent(respr) 110 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 111 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 112 } 113 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SignaturesOverrides, req) 114 if err != nil { 115 return nil, err 116 } 117 return resp, nil 118 } 119 120 func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchList(req *http.Request) (*http.Response, error) { 121 if f.srv.List == nil { 122 return nil, &nonRetriableError{errors.New("fake for method List not implemented")} 123 } 124 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~%@]+)/signatureOverrides` 125 regex := regexp.MustCompile(regexStr) 126 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 127 if matches == nil || len(matches) < 3 { 128 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 129 } 130 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 131 if err != nil { 132 return nil, err 133 } 134 firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) 135 if err != nil { 136 return nil, err 137 } 138 respr, errRespr := f.srv.List(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, nil) 139 if respErr := server.GetError(errRespr, req); respErr != nil { 140 return nil, respErr 141 } 142 respContent := server.GetResponseContent(respr) 143 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 144 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 145 } 146 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SignaturesOverridesList, req) 147 if err != nil { 148 return nil, err 149 } 150 return resp, nil 151 } 152 153 func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchPatch(req *http.Request) (*http.Response, error) { 154 if f.srv.Patch == nil { 155 return nil, &nonRetriableError{errors.New("fake for method Patch not implemented")} 156 } 157 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~%@]+)/signatureOverrides/default` 158 regex := regexp.MustCompile(regexStr) 159 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 160 if matches == nil || len(matches) < 3 { 161 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 162 } 163 body, err := server.UnmarshalRequestAsJSON[armnetwork.SignaturesOverrides](req) 164 if err != nil { 165 return nil, err 166 } 167 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 168 if err != nil { 169 return nil, err 170 } 171 firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) 172 if err != nil { 173 return nil, err 174 } 175 respr, errRespr := f.srv.Patch(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, body, nil) 176 if respErr := server.GetError(errRespr, req); respErr != nil { 177 return nil, respErr 178 } 179 respContent := server.GetResponseContent(respr) 180 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 181 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 182 } 183 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SignaturesOverrides, req) 184 if err != nil { 185 return nil, err 186 } 187 return resp, nil 188 } 189 190 func (f *FirewallPolicyIdpsSignaturesOverridesServerTransport) dispatchPut(req *http.Request) (*http.Response, error) { 191 if f.srv.Put == nil { 192 return nil, &nonRetriableError{errors.New("fake for method Put not implemented")} 193 } 194 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~%@]+)/signatureOverrides/default` 195 regex := regexp.MustCompile(regexStr) 196 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 197 if matches == nil || len(matches) < 3 { 198 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 199 } 200 body, err := server.UnmarshalRequestAsJSON[armnetwork.SignaturesOverrides](req) 201 if err != nil { 202 return nil, err 203 } 204 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 205 if err != nil { 206 return nil, err 207 } 208 firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")]) 209 if err != nil { 210 return nil, err 211 } 212 respr, errRespr := f.srv.Put(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, body, nil) 213 if respErr := server.GetError(errRespr, req); respErr != nil { 214 return nil, respErr 215 } 216 respContent := server.GetResponseContent(respr) 217 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 218 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 219 } 220 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SignaturesOverrides, req) 221 if err != nil { 222 return nil, err 223 } 224 return resp, nil 225 }