github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/vpnconnections_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/azcore/to" 19 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" 20 "net/http" 21 "net/url" 22 "reflect" 23 "regexp" 24 ) 25 26 // VPNConnectionsServer is a fake server for instances of the armnetwork.VPNConnectionsClient type. 27 type VPNConnectionsServer struct { 28 // BeginCreateOrUpdate is the fake for method VPNConnectionsClient.BeginCreateOrUpdate 29 // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated 30 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) 31 32 // BeginDelete is the fake for method VPNConnectionsClient.BeginDelete 33 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent 34 BeginDelete func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *armnetwork.VPNConnectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientDeleteResponse], errResp azfake.ErrorResponder) 35 36 // Get is the fake for method VPNConnectionsClient.Get 37 // HTTP status codes to indicate success: http.StatusOK 38 Get func(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *armnetwork.VPNConnectionsClientGetOptions) (resp azfake.Responder[armnetwork.VPNConnectionsClientGetResponse], errResp azfake.ErrorResponder) 39 40 // NewListByVPNGatewayPager is the fake for method VPNConnectionsClient.NewListByVPNGatewayPager 41 // HTTP status codes to indicate success: http.StatusOK 42 NewListByVPNGatewayPager func(resourceGroupName string, gatewayName string, options *armnetwork.VPNConnectionsClientListByVPNGatewayOptions) (resp azfake.PagerResponder[armnetwork.VPNConnectionsClientListByVPNGatewayResponse]) 43 44 // BeginStartPacketCapture is the fake for method VPNConnectionsClient.BeginStartPacketCapture 45 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted 46 BeginStartPacketCapture func(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *armnetwork.VPNConnectionsClientBeginStartPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientStartPacketCaptureResponse], errResp azfake.ErrorResponder) 47 48 // BeginStopPacketCapture is the fake for method VPNConnectionsClient.BeginStopPacketCapture 49 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted 50 BeginStopPacketCapture func(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *armnetwork.VPNConnectionsClientBeginStopPacketCaptureOptions) (resp azfake.PollerResponder[armnetwork.VPNConnectionsClientStopPacketCaptureResponse], errResp azfake.ErrorResponder) 51 } 52 53 // NewVPNConnectionsServerTransport creates a new instance of VPNConnectionsServerTransport with the provided implementation. 54 // The returned VPNConnectionsServerTransport instance is connected to an instance of armnetwork.VPNConnectionsClient via the 55 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 56 func NewVPNConnectionsServerTransport(srv *VPNConnectionsServer) *VPNConnectionsServerTransport { 57 return &VPNConnectionsServerTransport{ 58 srv: srv, 59 beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientCreateOrUpdateResponse]](), 60 beginDelete: newTracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientDeleteResponse]](), 61 newListByVPNGatewayPager: newTracker[azfake.PagerResponder[armnetwork.VPNConnectionsClientListByVPNGatewayResponse]](), 62 beginStartPacketCapture: newTracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientStartPacketCaptureResponse]](), 63 beginStopPacketCapture: newTracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientStopPacketCaptureResponse]](), 64 } 65 } 66 67 // VPNConnectionsServerTransport connects instances of armnetwork.VPNConnectionsClient to instances of VPNConnectionsServer. 68 // Don't use this type directly, use NewVPNConnectionsServerTransport instead. 69 type VPNConnectionsServerTransport struct { 70 srv *VPNConnectionsServer 71 beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientCreateOrUpdateResponse]] 72 beginDelete *tracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientDeleteResponse]] 73 newListByVPNGatewayPager *tracker[azfake.PagerResponder[armnetwork.VPNConnectionsClientListByVPNGatewayResponse]] 74 beginStartPacketCapture *tracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientStartPacketCaptureResponse]] 75 beginStopPacketCapture *tracker[azfake.PollerResponder[armnetwork.VPNConnectionsClientStopPacketCaptureResponse]] 76 } 77 78 // Do implements the policy.Transporter interface for VPNConnectionsServerTransport. 79 func (v *VPNConnectionsServerTransport) Do(req *http.Request) (*http.Response, error) { 80 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 81 method, ok := rawMethod.(string) 82 if !ok { 83 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 84 } 85 86 var resp *http.Response 87 var err error 88 89 switch method { 90 case "VPNConnectionsClient.BeginCreateOrUpdate": 91 resp, err = v.dispatchBeginCreateOrUpdate(req) 92 case "VPNConnectionsClient.BeginDelete": 93 resp, err = v.dispatchBeginDelete(req) 94 case "VPNConnectionsClient.Get": 95 resp, err = v.dispatchGet(req) 96 case "VPNConnectionsClient.NewListByVPNGatewayPager": 97 resp, err = v.dispatchNewListByVPNGatewayPager(req) 98 case "VPNConnectionsClient.BeginStartPacketCapture": 99 resp, err = v.dispatchBeginStartPacketCapture(req) 100 case "VPNConnectionsClient.BeginStopPacketCapture": 101 resp, err = v.dispatchBeginStopPacketCapture(req) 102 default: 103 err = fmt.Errorf("unhandled API %s", method) 104 } 105 106 if err != nil { 107 return nil, err 108 } 109 110 return resp, nil 111 } 112 113 func (v *VPNConnectionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { 114 if v.srv.BeginCreateOrUpdate == nil { 115 return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} 116 } 117 beginCreateOrUpdate := v.beginCreateOrUpdate.get(req) 118 if beginCreateOrUpdate == nil { 119 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/vpnGateways/(?P<gatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 120 regex := regexp.MustCompile(regexStr) 121 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 122 if matches == nil || len(matches) < 4 { 123 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 124 } 125 body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNConnection](req) 126 if err != nil { 127 return nil, err 128 } 129 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 130 if err != nil { 131 return nil, err 132 } 133 gatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) 134 if err != nil { 135 return nil, err 136 } 137 connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) 138 if err != nil { 139 return nil, err 140 } 141 respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, gatewayNameParam, connectionNameParam, body, nil) 142 if respErr := server.GetError(errRespr, req); respErr != nil { 143 return nil, respErr 144 } 145 beginCreateOrUpdate = &respr 146 v.beginCreateOrUpdate.add(req, beginCreateOrUpdate) 147 } 148 149 resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) 150 if err != nil { 151 return nil, err 152 } 153 154 if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { 155 v.beginCreateOrUpdate.remove(req) 156 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} 157 } 158 if !server.PollerResponderMore(beginCreateOrUpdate) { 159 v.beginCreateOrUpdate.remove(req) 160 } 161 162 return resp, nil 163 } 164 165 func (v *VPNConnectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { 166 if v.srv.BeginDelete == nil { 167 return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} 168 } 169 beginDelete := v.beginDelete.get(req) 170 if beginDelete == nil { 171 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/vpnGateways/(?P<gatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 172 regex := regexp.MustCompile(regexStr) 173 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 174 if matches == nil || len(matches) < 4 { 175 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 176 } 177 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 178 if err != nil { 179 return nil, err 180 } 181 gatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) 182 if err != nil { 183 return nil, err 184 } 185 connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) 186 if err != nil { 187 return nil, err 188 } 189 respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameParam, gatewayNameParam, connectionNameParam, nil) 190 if respErr := server.GetError(errRespr, req); respErr != nil { 191 return nil, respErr 192 } 193 beginDelete = &respr 194 v.beginDelete.add(req, beginDelete) 195 } 196 197 resp, err := server.PollerResponderNext(beginDelete, req) 198 if err != nil { 199 return nil, err 200 } 201 202 if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { 203 v.beginDelete.remove(req) 204 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} 205 } 206 if !server.PollerResponderMore(beginDelete) { 207 v.beginDelete.remove(req) 208 } 209 210 return resp, nil 211 } 212 213 func (v *VPNConnectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 214 if v.srv.Get == nil { 215 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 216 } 217 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/vpnGateways/(?P<gatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 218 regex := regexp.MustCompile(regexStr) 219 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 220 if matches == nil || len(matches) < 4 { 221 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 222 } 223 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 224 if err != nil { 225 return nil, err 226 } 227 gatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) 228 if err != nil { 229 return nil, err 230 } 231 connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) 232 if err != nil { 233 return nil, err 234 } 235 respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameParam, gatewayNameParam, connectionNameParam, nil) 236 if respErr := server.GetError(errRespr, req); respErr != nil { 237 return nil, respErr 238 } 239 respContent := server.GetResponseContent(respr) 240 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 241 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 242 } 243 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).VPNConnection, req) 244 if err != nil { 245 return nil, err 246 } 247 return resp, nil 248 } 249 250 func (v *VPNConnectionsServerTransport) dispatchNewListByVPNGatewayPager(req *http.Request) (*http.Response, error) { 251 if v.srv.NewListByVPNGatewayPager == nil { 252 return nil, &nonRetriableError{errors.New("fake for method NewListByVPNGatewayPager not implemented")} 253 } 254 newListByVPNGatewayPager := v.newListByVPNGatewayPager.get(req) 255 if newListByVPNGatewayPager == nil { 256 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/vpnGateways/(?P<gatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections` 257 regex := regexp.MustCompile(regexStr) 258 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 259 if matches == nil || len(matches) < 3 { 260 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 261 } 262 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 263 if err != nil { 264 return nil, err 265 } 266 gatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) 267 if err != nil { 268 return nil, err 269 } 270 resp := v.srv.NewListByVPNGatewayPager(resourceGroupNameParam, gatewayNameParam, nil) 271 newListByVPNGatewayPager = &resp 272 v.newListByVPNGatewayPager.add(req, newListByVPNGatewayPager) 273 server.PagerResponderInjectNextLinks(newListByVPNGatewayPager, req, func(page *armnetwork.VPNConnectionsClientListByVPNGatewayResponse, createLink func() string) { 274 page.NextLink = to.Ptr(createLink()) 275 }) 276 } 277 resp, err := server.PagerResponderNext(newListByVPNGatewayPager, req) 278 if err != nil { 279 return nil, err 280 } 281 if !contains([]int{http.StatusOK}, resp.StatusCode) { 282 v.newListByVPNGatewayPager.remove(req) 283 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 284 } 285 if !server.PagerResponderMore(newListByVPNGatewayPager) { 286 v.newListByVPNGatewayPager.remove(req) 287 } 288 return resp, nil 289 } 290 291 func (v *VPNConnectionsServerTransport) dispatchBeginStartPacketCapture(req *http.Request) (*http.Response, error) { 292 if v.srv.BeginStartPacketCapture == nil { 293 return nil, &nonRetriableError{errors.New("fake for method BeginStartPacketCapture not implemented")} 294 } 295 beginStartPacketCapture := v.beginStartPacketCapture.get(req) 296 if beginStartPacketCapture == nil { 297 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/vpnGateways/(?P<gatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P<vpnConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/startpacketcapture` 298 regex := regexp.MustCompile(regexStr) 299 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 300 if matches == nil || len(matches) < 4 { 301 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 302 } 303 body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNConnectionPacketCaptureStartParameters](req) 304 if err != nil { 305 return nil, err 306 } 307 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 308 if err != nil { 309 return nil, err 310 } 311 gatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) 312 if err != nil { 313 return nil, err 314 } 315 vpnConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("vpnConnectionName")]) 316 if err != nil { 317 return nil, err 318 } 319 var options *armnetwork.VPNConnectionsClientBeginStartPacketCaptureOptions 320 if !reflect.ValueOf(body).IsZero() { 321 options = &armnetwork.VPNConnectionsClientBeginStartPacketCaptureOptions{ 322 Parameters: &body, 323 } 324 } 325 respr, errRespr := v.srv.BeginStartPacketCapture(req.Context(), resourceGroupNameParam, gatewayNameParam, vpnConnectionNameParam, options) 326 if respErr := server.GetError(errRespr, req); respErr != nil { 327 return nil, respErr 328 } 329 beginStartPacketCapture = &respr 330 v.beginStartPacketCapture.add(req, beginStartPacketCapture) 331 } 332 333 resp, err := server.PollerResponderNext(beginStartPacketCapture, req) 334 if err != nil { 335 return nil, err 336 } 337 338 if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { 339 v.beginStartPacketCapture.remove(req) 340 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} 341 } 342 if !server.PollerResponderMore(beginStartPacketCapture) { 343 v.beginStartPacketCapture.remove(req) 344 } 345 346 return resp, nil 347 } 348 349 func (v *VPNConnectionsServerTransport) dispatchBeginStopPacketCapture(req *http.Request) (*http.Response, error) { 350 if v.srv.BeginStopPacketCapture == nil { 351 return nil, &nonRetriableError{errors.New("fake for method BeginStopPacketCapture not implemented")} 352 } 353 beginStopPacketCapture := v.beginStopPacketCapture.get(req) 354 if beginStopPacketCapture == nil { 355 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/vpnGateways/(?P<gatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConnections/(?P<vpnConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stoppacketcapture` 356 regex := regexp.MustCompile(regexStr) 357 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 358 if matches == nil || len(matches) < 4 { 359 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 360 } 361 body, err := server.UnmarshalRequestAsJSON[armnetwork.VPNConnectionPacketCaptureStopParameters](req) 362 if err != nil { 363 return nil, err 364 } 365 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 366 if err != nil { 367 return nil, err 368 } 369 gatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("gatewayName")]) 370 if err != nil { 371 return nil, err 372 } 373 vpnConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("vpnConnectionName")]) 374 if err != nil { 375 return nil, err 376 } 377 var options *armnetwork.VPNConnectionsClientBeginStopPacketCaptureOptions 378 if !reflect.ValueOf(body).IsZero() { 379 options = &armnetwork.VPNConnectionsClientBeginStopPacketCaptureOptions{ 380 Parameters: &body, 381 } 382 } 383 respr, errRespr := v.srv.BeginStopPacketCapture(req.Context(), resourceGroupNameParam, gatewayNameParam, vpnConnectionNameParam, options) 384 if respErr := server.GetError(errRespr, req); respErr != nil { 385 return nil, respErr 386 } 387 beginStopPacketCapture = &respr 388 v.beginStopPacketCapture.add(req, beginStopPacketCapture) 389 } 390 391 resp, err := server.PollerResponderNext(beginStopPacketCapture, req) 392 if err != nil { 393 return nil, err 394 } 395 396 if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { 397 v.beginStopPacketCapture.remove(req) 398 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} 399 } 400 if !server.PollerResponderMore(beginStopPacketCapture) { 401 v.beginStopPacketCapture.remove(req) 402 } 403 404 return resp, nil 405 }