github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/vpnconnections_client.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 armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // VPNConnectionsClient contains the methods for the VPNConnections group. 24 // Don't use this type directly, use NewVPNConnectionsClient() instead. 25 type VPNConnectionsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewVPNConnectionsClient creates a new instance of VPNConnectionsClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewVPNConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VPNConnectionsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &VPNConnectionsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates a vpn connection to a scalable vpn gateway if it doesn't exist else updates the existing 48 // connection. 49 // If the operation fails it returns an *azcore.ResponseError type. 50 // 51 // Generated from API version 2024-05-01 52 // - resourceGroupName - The resource group name of the VpnGateway. 53 // - gatewayName - The name of the gateway. 54 // - connectionName - The name of the connection. 55 // - vpnConnectionParameters - Parameters supplied to create or Update a VPN Connection. 56 // - options - VPNConnectionsClientBeginCreateOrUpdateOptions contains the optional parameters for the VPNConnectionsClient.BeginCreateOrUpdate 57 // method. 58 func (client *VPNConnectionsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VPNConnection, options *VPNConnectionsClientBeginCreateOrUpdateOptions) (*runtime.Poller[VPNConnectionsClientCreateOrUpdateResponse], error) { 59 if options == nil || options.ResumeToken == "" { 60 resp, err := client.createOrUpdate(ctx, resourceGroupName, gatewayName, connectionName, vpnConnectionParameters, options) 61 if err != nil { 62 return nil, err 63 } 64 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientCreateOrUpdateResponse]{ 65 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 66 Tracer: client.internal.Tracer(), 67 }) 68 return poller, err 69 } else { 70 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNConnectionsClientCreateOrUpdateResponse]{ 71 Tracer: client.internal.Tracer(), 72 }) 73 } 74 } 75 76 // CreateOrUpdate - Creates a vpn connection to a scalable vpn gateway if it doesn't exist else updates the existing connection. 77 // If the operation fails it returns an *azcore.ResponseError type. 78 // 79 // Generated from API version 2024-05-01 80 func (client *VPNConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VPNConnection, options *VPNConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { 81 var err error 82 const operationName = "VPNConnectionsClient.BeginCreateOrUpdate" 83 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 84 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 85 defer func() { endSpan(err) }() 86 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, vpnConnectionParameters, options) 87 if err != nil { 88 return nil, err 89 } 90 httpResp, err := client.internal.Pipeline().Do(req) 91 if err != nil { 92 return nil, err 93 } 94 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 95 err = runtime.NewResponseError(httpResp) 96 return nil, err 97 } 98 return httpResp, nil 99 } 100 101 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 102 func (client *VPNConnectionsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VPNConnection, options *VPNConnectionsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 103 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}" 104 if client.subscriptionID == "" { 105 return nil, errors.New("parameter client.subscriptionID cannot be empty") 106 } 107 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 108 if resourceGroupName == "" { 109 return nil, errors.New("parameter resourceGroupName cannot be empty") 110 } 111 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 112 if gatewayName == "" { 113 return nil, errors.New("parameter gatewayName cannot be empty") 114 } 115 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 116 if connectionName == "" { 117 return nil, errors.New("parameter connectionName cannot be empty") 118 } 119 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 120 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 121 if err != nil { 122 return nil, err 123 } 124 reqQP := req.Raw().URL.Query() 125 reqQP.Set("api-version", "2024-05-01") 126 req.Raw().URL.RawQuery = reqQP.Encode() 127 req.Raw().Header["Accept"] = []string{"application/json"} 128 if err := runtime.MarshalAsJSON(req, vpnConnectionParameters); err != nil { 129 return nil, err 130 } 131 return req, nil 132 } 133 134 // BeginDelete - Deletes a vpn connection. 135 // If the operation fails it returns an *azcore.ResponseError type. 136 // 137 // Generated from API version 2024-05-01 138 // - resourceGroupName - The resource group name of the VpnGateway. 139 // - gatewayName - The name of the gateway. 140 // - connectionName - The name of the connection. 141 // - options - VPNConnectionsClientBeginDeleteOptions contains the optional parameters for the VPNConnectionsClient.BeginDelete 142 // method. 143 func (client *VPNConnectionsClient) BeginDelete(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientBeginDeleteOptions) (*runtime.Poller[VPNConnectionsClientDeleteResponse], error) { 144 if options == nil || options.ResumeToken == "" { 145 resp, err := client.deleteOperation(ctx, resourceGroupName, gatewayName, connectionName, options) 146 if err != nil { 147 return nil, err 148 } 149 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientDeleteResponse]{ 150 FinalStateVia: runtime.FinalStateViaLocation, 151 Tracer: client.internal.Tracer(), 152 }) 153 return poller, err 154 } else { 155 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNConnectionsClientDeleteResponse]{ 156 Tracer: client.internal.Tracer(), 157 }) 158 } 159 } 160 161 // Delete - Deletes a vpn connection. 162 // If the operation fails it returns an *azcore.ResponseError type. 163 // 164 // Generated from API version 2024-05-01 165 func (client *VPNConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientBeginDeleteOptions) (*http.Response, error) { 166 var err error 167 const operationName = "VPNConnectionsClient.BeginDelete" 168 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 169 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 170 defer func() { endSpan(err) }() 171 req, err := client.deleteCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, options) 172 if err != nil { 173 return nil, err 174 } 175 httpResp, err := client.internal.Pipeline().Do(req) 176 if err != nil { 177 return nil, err 178 } 179 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 180 err = runtime.NewResponseError(httpResp) 181 return nil, err 182 } 183 return httpResp, nil 184 } 185 186 // deleteCreateRequest creates the Delete request. 187 func (client *VPNConnectionsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientBeginDeleteOptions) (*policy.Request, error) { 188 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}" 189 if client.subscriptionID == "" { 190 return nil, errors.New("parameter client.subscriptionID cannot be empty") 191 } 192 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 193 if resourceGroupName == "" { 194 return nil, errors.New("parameter resourceGroupName cannot be empty") 195 } 196 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 197 if gatewayName == "" { 198 return nil, errors.New("parameter gatewayName cannot be empty") 199 } 200 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 201 if connectionName == "" { 202 return nil, errors.New("parameter connectionName cannot be empty") 203 } 204 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 205 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 206 if err != nil { 207 return nil, err 208 } 209 reqQP := req.Raw().URL.Query() 210 reqQP.Set("api-version", "2024-05-01") 211 req.Raw().URL.RawQuery = reqQP.Encode() 212 req.Raw().Header["Accept"] = []string{"application/json"} 213 return req, nil 214 } 215 216 // Get - Retrieves the details of a vpn connection. 217 // If the operation fails it returns an *azcore.ResponseError type. 218 // 219 // Generated from API version 2024-05-01 220 // - resourceGroupName - The resource group name of the VpnGateway. 221 // - gatewayName - The name of the gateway. 222 // - connectionName - The name of the vpn connection. 223 // - options - VPNConnectionsClientGetOptions contains the optional parameters for the VPNConnectionsClient.Get method. 224 func (client *VPNConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientGetOptions) (VPNConnectionsClientGetResponse, error) { 225 var err error 226 const operationName = "VPNConnectionsClient.Get" 227 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 228 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 229 defer func() { endSpan(err) }() 230 req, err := client.getCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, options) 231 if err != nil { 232 return VPNConnectionsClientGetResponse{}, err 233 } 234 httpResp, err := client.internal.Pipeline().Do(req) 235 if err != nil { 236 return VPNConnectionsClientGetResponse{}, err 237 } 238 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 239 err = runtime.NewResponseError(httpResp) 240 return VPNConnectionsClientGetResponse{}, err 241 } 242 resp, err := client.getHandleResponse(httpResp) 243 return resp, err 244 } 245 246 // getCreateRequest creates the Get request. 247 func (client *VPNConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VPNConnectionsClientGetOptions) (*policy.Request, error) { 248 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}" 249 if client.subscriptionID == "" { 250 return nil, errors.New("parameter client.subscriptionID cannot be empty") 251 } 252 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 253 if resourceGroupName == "" { 254 return nil, errors.New("parameter resourceGroupName cannot be empty") 255 } 256 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 257 if gatewayName == "" { 258 return nil, errors.New("parameter gatewayName cannot be empty") 259 } 260 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 261 if connectionName == "" { 262 return nil, errors.New("parameter connectionName cannot be empty") 263 } 264 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 265 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 266 if err != nil { 267 return nil, err 268 } 269 reqQP := req.Raw().URL.Query() 270 reqQP.Set("api-version", "2024-05-01") 271 req.Raw().URL.RawQuery = reqQP.Encode() 272 req.Raw().Header["Accept"] = []string{"application/json"} 273 return req, nil 274 } 275 276 // getHandleResponse handles the Get response. 277 func (client *VPNConnectionsClient) getHandleResponse(resp *http.Response) (VPNConnectionsClientGetResponse, error) { 278 result := VPNConnectionsClientGetResponse{} 279 if err := runtime.UnmarshalAsJSON(resp, &result.VPNConnection); err != nil { 280 return VPNConnectionsClientGetResponse{}, err 281 } 282 return result, nil 283 } 284 285 // NewListByVPNGatewayPager - Retrieves all vpn connections for a particular virtual wan vpn gateway. 286 // 287 // Generated from API version 2024-05-01 288 // - resourceGroupName - The resource group name of the VpnGateway. 289 // - gatewayName - The name of the gateway. 290 // - options - VPNConnectionsClientListByVPNGatewayOptions contains the optional parameters for the VPNConnectionsClient.NewListByVPNGatewayPager 291 // method. 292 func (client *VPNConnectionsClient) NewListByVPNGatewayPager(resourceGroupName string, gatewayName string, options *VPNConnectionsClientListByVPNGatewayOptions) *runtime.Pager[VPNConnectionsClientListByVPNGatewayResponse] { 293 return runtime.NewPager(runtime.PagingHandler[VPNConnectionsClientListByVPNGatewayResponse]{ 294 More: func(page VPNConnectionsClientListByVPNGatewayResponse) bool { 295 return page.NextLink != nil && len(*page.NextLink) > 0 296 }, 297 Fetcher: func(ctx context.Context, page *VPNConnectionsClientListByVPNGatewayResponse) (VPNConnectionsClientListByVPNGatewayResponse, error) { 298 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNConnectionsClient.NewListByVPNGatewayPager") 299 nextLink := "" 300 if page != nil { 301 nextLink = *page.NextLink 302 } 303 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 304 return client.listByVPNGatewayCreateRequest(ctx, resourceGroupName, gatewayName, options) 305 }, nil) 306 if err != nil { 307 return VPNConnectionsClientListByVPNGatewayResponse{}, err 308 } 309 return client.listByVPNGatewayHandleResponse(resp) 310 }, 311 Tracer: client.internal.Tracer(), 312 }) 313 } 314 315 // listByVPNGatewayCreateRequest creates the ListByVPNGateway request. 316 func (client *VPNConnectionsClient) listByVPNGatewayCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNConnectionsClientListByVPNGatewayOptions) (*policy.Request, error) { 317 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections" 318 if client.subscriptionID == "" { 319 return nil, errors.New("parameter client.subscriptionID cannot be empty") 320 } 321 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 322 if resourceGroupName == "" { 323 return nil, errors.New("parameter resourceGroupName cannot be empty") 324 } 325 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 326 if gatewayName == "" { 327 return nil, errors.New("parameter gatewayName cannot be empty") 328 } 329 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 330 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 331 if err != nil { 332 return nil, err 333 } 334 reqQP := req.Raw().URL.Query() 335 reqQP.Set("api-version", "2024-05-01") 336 req.Raw().URL.RawQuery = reqQP.Encode() 337 req.Raw().Header["Accept"] = []string{"application/json"} 338 return req, nil 339 } 340 341 // listByVPNGatewayHandleResponse handles the ListByVPNGateway response. 342 func (client *VPNConnectionsClient) listByVPNGatewayHandleResponse(resp *http.Response) (VPNConnectionsClientListByVPNGatewayResponse, error) { 343 result := VPNConnectionsClientListByVPNGatewayResponse{} 344 if err := runtime.UnmarshalAsJSON(resp, &result.ListVPNConnectionsResult); err != nil { 345 return VPNConnectionsClientListByVPNGatewayResponse{}, err 346 } 347 return result, nil 348 } 349 350 // BeginStartPacketCapture - Starts packet capture on Vpn connection in the specified resource group. 351 // If the operation fails it returns an *azcore.ResponseError type. 352 // 353 // Generated from API version 2024-05-01 354 // - resourceGroupName - The name of the resource group. 355 // - gatewayName - The name of the gateway. 356 // - vpnConnectionName - The name of the vpn connection. 357 // - options - VPNConnectionsClientBeginStartPacketCaptureOptions contains the optional parameters for the VPNConnectionsClient.BeginStartPacketCapture 358 // method. 359 func (client *VPNConnectionsClient) BeginStartPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStartPacketCaptureOptions) (*runtime.Poller[VPNConnectionsClientStartPacketCaptureResponse], error) { 360 if options == nil || options.ResumeToken == "" { 361 resp, err := client.startPacketCapture(ctx, resourceGroupName, gatewayName, vpnConnectionName, options) 362 if err != nil { 363 return nil, err 364 } 365 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientStartPacketCaptureResponse]{ 366 FinalStateVia: runtime.FinalStateViaLocation, 367 Tracer: client.internal.Tracer(), 368 }) 369 return poller, err 370 } else { 371 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNConnectionsClientStartPacketCaptureResponse]{ 372 Tracer: client.internal.Tracer(), 373 }) 374 } 375 } 376 377 // StartPacketCapture - Starts packet capture on Vpn connection in the specified resource group. 378 // If the operation fails it returns an *azcore.ResponseError type. 379 // 380 // Generated from API version 2024-05-01 381 func (client *VPNConnectionsClient) startPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStartPacketCaptureOptions) (*http.Response, error) { 382 var err error 383 const operationName = "VPNConnectionsClient.BeginStartPacketCapture" 384 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 385 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 386 defer func() { endSpan(err) }() 387 req, err := client.startPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, vpnConnectionName, options) 388 if err != nil { 389 return nil, err 390 } 391 httpResp, err := client.internal.Pipeline().Do(req) 392 if err != nil { 393 return nil, err 394 } 395 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 396 err = runtime.NewResponseError(httpResp) 397 return nil, err 398 } 399 return httpResp, nil 400 } 401 402 // startPacketCaptureCreateRequest creates the StartPacketCapture request. 403 func (client *VPNConnectionsClient) startPacketCaptureCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStartPacketCaptureOptions) (*policy.Request, error) { 404 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{vpnConnectionName}/startpacketcapture" 405 if resourceGroupName == "" { 406 return nil, errors.New("parameter resourceGroupName cannot be empty") 407 } 408 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 409 if gatewayName == "" { 410 return nil, errors.New("parameter gatewayName cannot be empty") 411 } 412 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 413 if vpnConnectionName == "" { 414 return nil, errors.New("parameter vpnConnectionName cannot be empty") 415 } 416 urlPath = strings.ReplaceAll(urlPath, "{vpnConnectionName}", url.PathEscape(vpnConnectionName)) 417 if client.subscriptionID == "" { 418 return nil, errors.New("parameter client.subscriptionID cannot be empty") 419 } 420 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 421 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 422 if err != nil { 423 return nil, err 424 } 425 reqQP := req.Raw().URL.Query() 426 reqQP.Set("api-version", "2024-05-01") 427 req.Raw().URL.RawQuery = reqQP.Encode() 428 req.Raw().Header["Accept"] = []string{"application/json"} 429 if options != nil && options.Parameters != nil { 430 if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { 431 return nil, err 432 } 433 return req, nil 434 } 435 return req, nil 436 } 437 438 // BeginStopPacketCapture - Stops packet capture on Vpn connection in the specified resource group. 439 // If the operation fails it returns an *azcore.ResponseError type. 440 // 441 // Generated from API version 2024-05-01 442 // - resourceGroupName - The name of the resource group. 443 // - gatewayName - The name of the gateway. 444 // - vpnConnectionName - The name of the vpn connection. 445 // - options - VPNConnectionsClientBeginStopPacketCaptureOptions contains the optional parameters for the VPNConnectionsClient.BeginStopPacketCapture 446 // method. 447 func (client *VPNConnectionsClient) BeginStopPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStopPacketCaptureOptions) (*runtime.Poller[VPNConnectionsClientStopPacketCaptureResponse], error) { 448 if options == nil || options.ResumeToken == "" { 449 resp, err := client.stopPacketCapture(ctx, resourceGroupName, gatewayName, vpnConnectionName, options) 450 if err != nil { 451 return nil, err 452 } 453 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNConnectionsClientStopPacketCaptureResponse]{ 454 FinalStateVia: runtime.FinalStateViaLocation, 455 Tracer: client.internal.Tracer(), 456 }) 457 return poller, err 458 } else { 459 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNConnectionsClientStopPacketCaptureResponse]{ 460 Tracer: client.internal.Tracer(), 461 }) 462 } 463 } 464 465 // StopPacketCapture - Stops packet capture on Vpn connection in the specified resource group. 466 // If the operation fails it returns an *azcore.ResponseError type. 467 // 468 // Generated from API version 2024-05-01 469 func (client *VPNConnectionsClient) stopPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStopPacketCaptureOptions) (*http.Response, error) { 470 var err error 471 const operationName = "VPNConnectionsClient.BeginStopPacketCapture" 472 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 473 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 474 defer func() { endSpan(err) }() 475 req, err := client.stopPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, vpnConnectionName, options) 476 if err != nil { 477 return nil, err 478 } 479 httpResp, err := client.internal.Pipeline().Do(req) 480 if err != nil { 481 return nil, err 482 } 483 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 484 err = runtime.NewResponseError(httpResp) 485 return nil, err 486 } 487 return httpResp, nil 488 } 489 490 // stopPacketCaptureCreateRequest creates the StopPacketCapture request. 491 func (client *VPNConnectionsClient) stopPacketCaptureCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, vpnConnectionName string, options *VPNConnectionsClientBeginStopPacketCaptureOptions) (*policy.Request, error) { 492 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{vpnConnectionName}/stoppacketcapture" 493 if resourceGroupName == "" { 494 return nil, errors.New("parameter resourceGroupName cannot be empty") 495 } 496 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 497 if gatewayName == "" { 498 return nil, errors.New("parameter gatewayName cannot be empty") 499 } 500 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 501 if vpnConnectionName == "" { 502 return nil, errors.New("parameter vpnConnectionName cannot be empty") 503 } 504 urlPath = strings.ReplaceAll(urlPath, "{vpnConnectionName}", url.PathEscape(vpnConnectionName)) 505 if client.subscriptionID == "" { 506 return nil, errors.New("parameter client.subscriptionID cannot be empty") 507 } 508 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 509 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 510 if err != nil { 511 return nil, err 512 } 513 reqQP := req.Raw().URL.Query() 514 reqQP.Set("api-version", "2024-05-01") 515 req.Raw().URL.RawQuery = reqQP.Encode() 516 req.Raw().Header["Accept"] = []string{"application/json"} 517 if options != nil && options.Parameters != nil { 518 if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { 519 return nil, err 520 } 521 return req, nil 522 } 523 return req, nil 524 }