github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/vpngateways_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 // VPNGatewaysClient contains the methods for the VPNGateways group. 24 // Don't use this type directly, use NewVPNGatewaysClient() instead. 25 type VPNGatewaysClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewVPNGatewaysClient creates a new instance of VPNGatewaysClient 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 NewVPNGatewaysClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VPNGatewaysClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &VPNGatewaysClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates a virtual wan vpn gateway if it doesn't exist else updates the existing gateway. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The resource group name of the VpnGateway. 52 // - gatewayName - The name of the gateway. 53 // - vpnGatewayParameters - Parameters supplied to create or Update a virtual wan vpn gateway. 54 // - options - VPNGatewaysClientBeginCreateOrUpdateOptions contains the optional parameters for the VPNGatewaysClient.BeginCreateOrUpdate 55 // method. 56 func (client *VPNGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters VPNGateway, options *VPNGatewaysClientBeginCreateOrUpdateOptions) (*runtime.Poller[VPNGatewaysClientCreateOrUpdateResponse], error) { 57 if options == nil || options.ResumeToken == "" { 58 resp, err := client.createOrUpdate(ctx, resourceGroupName, gatewayName, vpnGatewayParameters, options) 59 if err != nil { 60 return nil, err 61 } 62 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientCreateOrUpdateResponse]{ 63 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 64 Tracer: client.internal.Tracer(), 65 }) 66 return poller, err 67 } else { 68 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNGatewaysClientCreateOrUpdateResponse]{ 69 Tracer: client.internal.Tracer(), 70 }) 71 } 72 } 73 74 // CreateOrUpdate - Creates a virtual wan vpn gateway if it doesn't exist else updates the existing gateway. 75 // If the operation fails it returns an *azcore.ResponseError type. 76 // 77 // Generated from API version 2024-05-01 78 func (client *VPNGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters VPNGateway, options *VPNGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) { 79 var err error 80 const operationName = "VPNGatewaysClient.BeginCreateOrUpdate" 81 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 82 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 83 defer func() { endSpan(err) }() 84 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, gatewayName, vpnGatewayParameters, options) 85 if err != nil { 86 return nil, err 87 } 88 httpResp, err := client.internal.Pipeline().Do(req) 89 if err != nil { 90 return nil, err 91 } 92 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 93 err = runtime.NewResponseError(httpResp) 94 return nil, err 95 } 96 return httpResp, nil 97 } 98 99 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 100 func (client *VPNGatewaysClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters VPNGateway, options *VPNGatewaysClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}" 102 if client.subscriptionID == "" { 103 return nil, errors.New("parameter client.subscriptionID cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 106 if resourceGroupName == "" { 107 return nil, errors.New("parameter resourceGroupName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 110 if gatewayName == "" { 111 return nil, errors.New("parameter gatewayName cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 114 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 115 if err != nil { 116 return nil, err 117 } 118 reqQP := req.Raw().URL.Query() 119 reqQP.Set("api-version", "2024-05-01") 120 req.Raw().URL.RawQuery = reqQP.Encode() 121 req.Raw().Header["Accept"] = []string{"application/json"} 122 if err := runtime.MarshalAsJSON(req, vpnGatewayParameters); err != nil { 123 return nil, err 124 } 125 return req, nil 126 } 127 128 // BeginDelete - Deletes a virtual wan vpn gateway. 129 // If the operation fails it returns an *azcore.ResponseError type. 130 // 131 // Generated from API version 2024-05-01 132 // - resourceGroupName - The resource group name of the VpnGateway. 133 // - gatewayName - The name of the gateway. 134 // - options - VPNGatewaysClientBeginDeleteOptions contains the optional parameters for the VPNGatewaysClient.BeginDelete method. 135 func (client *VPNGatewaysClient) BeginDelete(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginDeleteOptions) (*runtime.Poller[VPNGatewaysClientDeleteResponse], error) { 136 if options == nil || options.ResumeToken == "" { 137 resp, err := client.deleteOperation(ctx, resourceGroupName, gatewayName, options) 138 if err != nil { 139 return nil, err 140 } 141 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientDeleteResponse]{ 142 FinalStateVia: runtime.FinalStateViaLocation, 143 Tracer: client.internal.Tracer(), 144 }) 145 return poller, err 146 } else { 147 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNGatewaysClientDeleteResponse]{ 148 Tracer: client.internal.Tracer(), 149 }) 150 } 151 } 152 153 // Delete - Deletes a virtual wan vpn gateway. 154 // If the operation fails it returns an *azcore.ResponseError type. 155 // 156 // Generated from API version 2024-05-01 157 func (client *VPNGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginDeleteOptions) (*http.Response, error) { 158 var err error 159 const operationName = "VPNGatewaysClient.BeginDelete" 160 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 161 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 162 defer func() { endSpan(err) }() 163 req, err := client.deleteCreateRequest(ctx, resourceGroupName, gatewayName, options) 164 if err != nil { 165 return nil, err 166 } 167 httpResp, err := client.internal.Pipeline().Do(req) 168 if err != nil { 169 return nil, err 170 } 171 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 172 err = runtime.NewResponseError(httpResp) 173 return nil, err 174 } 175 return httpResp, nil 176 } 177 178 // deleteCreateRequest creates the Delete request. 179 func (client *VPNGatewaysClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginDeleteOptions) (*policy.Request, error) { 180 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}" 181 if client.subscriptionID == "" { 182 return nil, errors.New("parameter client.subscriptionID cannot be empty") 183 } 184 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 185 if resourceGroupName == "" { 186 return nil, errors.New("parameter resourceGroupName cannot be empty") 187 } 188 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 189 if gatewayName == "" { 190 return nil, errors.New("parameter gatewayName cannot be empty") 191 } 192 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 193 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 194 if err != nil { 195 return nil, err 196 } 197 reqQP := req.Raw().URL.Query() 198 reqQP.Set("api-version", "2024-05-01") 199 req.Raw().URL.RawQuery = reqQP.Encode() 200 req.Raw().Header["Accept"] = []string{"application/json"} 201 return req, nil 202 } 203 204 // Get - Retrieves the details of a virtual wan vpn gateway. 205 // If the operation fails it returns an *azcore.ResponseError type. 206 // 207 // Generated from API version 2024-05-01 208 // - resourceGroupName - The resource group name of the VpnGateway. 209 // - gatewayName - The name of the gateway. 210 // - options - VPNGatewaysClientGetOptions contains the optional parameters for the VPNGatewaysClient.Get method. 211 func (client *VPNGatewaysClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientGetOptions) (VPNGatewaysClientGetResponse, error) { 212 var err error 213 const operationName = "VPNGatewaysClient.Get" 214 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 215 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 216 defer func() { endSpan(err) }() 217 req, err := client.getCreateRequest(ctx, resourceGroupName, gatewayName, options) 218 if err != nil { 219 return VPNGatewaysClientGetResponse{}, err 220 } 221 httpResp, err := client.internal.Pipeline().Do(req) 222 if err != nil { 223 return VPNGatewaysClientGetResponse{}, err 224 } 225 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 226 err = runtime.NewResponseError(httpResp) 227 return VPNGatewaysClientGetResponse{}, err 228 } 229 resp, err := client.getHandleResponse(httpResp) 230 return resp, err 231 } 232 233 // getCreateRequest creates the Get request. 234 func (client *VPNGatewaysClient) getCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientGetOptions) (*policy.Request, error) { 235 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}" 236 if client.subscriptionID == "" { 237 return nil, errors.New("parameter client.subscriptionID cannot be empty") 238 } 239 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 240 if resourceGroupName == "" { 241 return nil, errors.New("parameter resourceGroupName cannot be empty") 242 } 243 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 244 if gatewayName == "" { 245 return nil, errors.New("parameter gatewayName cannot be empty") 246 } 247 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 248 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 249 if err != nil { 250 return nil, err 251 } 252 reqQP := req.Raw().URL.Query() 253 reqQP.Set("api-version", "2024-05-01") 254 req.Raw().URL.RawQuery = reqQP.Encode() 255 req.Raw().Header["Accept"] = []string{"application/json"} 256 return req, nil 257 } 258 259 // getHandleResponse handles the Get response. 260 func (client *VPNGatewaysClient) getHandleResponse(resp *http.Response) (VPNGatewaysClientGetResponse, error) { 261 result := VPNGatewaysClientGetResponse{} 262 if err := runtime.UnmarshalAsJSON(resp, &result.VPNGateway); err != nil { 263 return VPNGatewaysClientGetResponse{}, err 264 } 265 return result, nil 266 } 267 268 // NewListPager - Lists all the VpnGateways in a subscription. 269 // 270 // Generated from API version 2024-05-01 271 // - options - VPNGatewaysClientListOptions contains the optional parameters for the VPNGatewaysClient.NewListPager method. 272 func (client *VPNGatewaysClient) NewListPager(options *VPNGatewaysClientListOptions) *runtime.Pager[VPNGatewaysClientListResponse] { 273 return runtime.NewPager(runtime.PagingHandler[VPNGatewaysClientListResponse]{ 274 More: func(page VPNGatewaysClientListResponse) bool { 275 return page.NextLink != nil && len(*page.NextLink) > 0 276 }, 277 Fetcher: func(ctx context.Context, page *VPNGatewaysClientListResponse) (VPNGatewaysClientListResponse, error) { 278 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNGatewaysClient.NewListPager") 279 nextLink := "" 280 if page != nil { 281 nextLink = *page.NextLink 282 } 283 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 284 return client.listCreateRequest(ctx, options) 285 }, nil) 286 if err != nil { 287 return VPNGatewaysClientListResponse{}, err 288 } 289 return client.listHandleResponse(resp) 290 }, 291 Tracer: client.internal.Tracer(), 292 }) 293 } 294 295 // listCreateRequest creates the List request. 296 func (client *VPNGatewaysClient) listCreateRequest(ctx context.Context, options *VPNGatewaysClientListOptions) (*policy.Request, error) { 297 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/vpnGateways" 298 if client.subscriptionID == "" { 299 return nil, errors.New("parameter client.subscriptionID cannot be empty") 300 } 301 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 302 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 303 if err != nil { 304 return nil, err 305 } 306 reqQP := req.Raw().URL.Query() 307 reqQP.Set("api-version", "2024-05-01") 308 req.Raw().URL.RawQuery = reqQP.Encode() 309 req.Raw().Header["Accept"] = []string{"application/json"} 310 return req, nil 311 } 312 313 // listHandleResponse handles the List response. 314 func (client *VPNGatewaysClient) listHandleResponse(resp *http.Response) (VPNGatewaysClientListResponse, error) { 315 result := VPNGatewaysClientListResponse{} 316 if err := runtime.UnmarshalAsJSON(resp, &result.ListVPNGatewaysResult); err != nil { 317 return VPNGatewaysClientListResponse{}, err 318 } 319 return result, nil 320 } 321 322 // NewListByResourceGroupPager - Lists all the VpnGateways in a resource group. 323 // 324 // Generated from API version 2024-05-01 325 // - resourceGroupName - The resource group name of the VpnGateway. 326 // - options - VPNGatewaysClientListByResourceGroupOptions contains the optional parameters for the VPNGatewaysClient.NewListByResourceGroupPager 327 // method. 328 func (client *VPNGatewaysClient) NewListByResourceGroupPager(resourceGroupName string, options *VPNGatewaysClientListByResourceGroupOptions) *runtime.Pager[VPNGatewaysClientListByResourceGroupResponse] { 329 return runtime.NewPager(runtime.PagingHandler[VPNGatewaysClientListByResourceGroupResponse]{ 330 More: func(page VPNGatewaysClientListByResourceGroupResponse) bool { 331 return page.NextLink != nil && len(*page.NextLink) > 0 332 }, 333 Fetcher: func(ctx context.Context, page *VPNGatewaysClientListByResourceGroupResponse) (VPNGatewaysClientListByResourceGroupResponse, error) { 334 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VPNGatewaysClient.NewListByResourceGroupPager") 335 nextLink := "" 336 if page != nil { 337 nextLink = *page.NextLink 338 } 339 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 340 return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) 341 }, nil) 342 if err != nil { 343 return VPNGatewaysClientListByResourceGroupResponse{}, err 344 } 345 return client.listByResourceGroupHandleResponse(resp) 346 }, 347 Tracer: client.internal.Tracer(), 348 }) 349 } 350 351 // listByResourceGroupCreateRequest creates the ListByResourceGroup request. 352 func (client *VPNGatewaysClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *VPNGatewaysClientListByResourceGroupOptions) (*policy.Request, error) { 353 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways" 354 if client.subscriptionID == "" { 355 return nil, errors.New("parameter client.subscriptionID cannot be empty") 356 } 357 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 358 if resourceGroupName == "" { 359 return nil, errors.New("parameter resourceGroupName cannot be empty") 360 } 361 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 362 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 363 if err != nil { 364 return nil, err 365 } 366 reqQP := req.Raw().URL.Query() 367 reqQP.Set("api-version", "2024-05-01") 368 req.Raw().URL.RawQuery = reqQP.Encode() 369 req.Raw().Header["Accept"] = []string{"application/json"} 370 return req, nil 371 } 372 373 // listByResourceGroupHandleResponse handles the ListByResourceGroup response. 374 func (client *VPNGatewaysClient) listByResourceGroupHandleResponse(resp *http.Response) (VPNGatewaysClientListByResourceGroupResponse, error) { 375 result := VPNGatewaysClientListByResourceGroupResponse{} 376 if err := runtime.UnmarshalAsJSON(resp, &result.ListVPNGatewaysResult); err != nil { 377 return VPNGatewaysClientListByResourceGroupResponse{}, err 378 } 379 return result, nil 380 } 381 382 // BeginReset - Resets the primary of the vpn gateway in the specified resource group. 383 // If the operation fails it returns an *azcore.ResponseError type. 384 // 385 // Generated from API version 2024-05-01 386 // - resourceGroupName - The resource group name of the VpnGateway. 387 // - gatewayName - The name of the gateway. 388 // - options - VPNGatewaysClientBeginResetOptions contains the optional parameters for the VPNGatewaysClient.BeginReset method. 389 func (client *VPNGatewaysClient) BeginReset(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginResetOptions) (*runtime.Poller[VPNGatewaysClientResetResponse], error) { 390 if options == nil || options.ResumeToken == "" { 391 resp, err := client.reset(ctx, resourceGroupName, gatewayName, options) 392 if err != nil { 393 return nil, err 394 } 395 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientResetResponse]{ 396 FinalStateVia: runtime.FinalStateViaLocation, 397 Tracer: client.internal.Tracer(), 398 }) 399 return poller, err 400 } else { 401 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNGatewaysClientResetResponse]{ 402 Tracer: client.internal.Tracer(), 403 }) 404 } 405 } 406 407 // Reset - Resets the primary of the vpn gateway in the specified resource group. 408 // If the operation fails it returns an *azcore.ResponseError type. 409 // 410 // Generated from API version 2024-05-01 411 func (client *VPNGatewaysClient) reset(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginResetOptions) (*http.Response, error) { 412 var err error 413 const operationName = "VPNGatewaysClient.BeginReset" 414 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 415 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 416 defer func() { endSpan(err) }() 417 req, err := client.resetCreateRequest(ctx, resourceGroupName, gatewayName, options) 418 if err != nil { 419 return nil, err 420 } 421 httpResp, err := client.internal.Pipeline().Do(req) 422 if err != nil { 423 return nil, err 424 } 425 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 426 err = runtime.NewResponseError(httpResp) 427 return nil, err 428 } 429 return httpResp, nil 430 } 431 432 // resetCreateRequest creates the Reset request. 433 func (client *VPNGatewaysClient) resetCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginResetOptions) (*policy.Request, error) { 434 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/reset" 435 if resourceGroupName == "" { 436 return nil, errors.New("parameter resourceGroupName cannot be empty") 437 } 438 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 439 if gatewayName == "" { 440 return nil, errors.New("parameter gatewayName cannot be empty") 441 } 442 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 443 if client.subscriptionID == "" { 444 return nil, errors.New("parameter client.subscriptionID cannot be empty") 445 } 446 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 447 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 448 if err != nil { 449 return nil, err 450 } 451 reqQP := req.Raw().URL.Query() 452 reqQP.Set("api-version", "2024-05-01") 453 if options != nil && options.IPConfigurationID != nil { 454 reqQP.Set("ipConfigurationId", *options.IPConfigurationID) 455 } 456 req.Raw().URL.RawQuery = reqQP.Encode() 457 req.Raw().Header["Accept"] = []string{"application/json"} 458 return req, nil 459 } 460 461 // BeginStartPacketCapture - Starts packet capture on vpn gateway in the specified resource group. 462 // If the operation fails it returns an *azcore.ResponseError type. 463 // 464 // Generated from API version 2024-05-01 465 // - resourceGroupName - The resource group name of the VpnGateway. 466 // - gatewayName - The name of the gateway. 467 // - options - VPNGatewaysClientBeginStartPacketCaptureOptions contains the optional parameters for the VPNGatewaysClient.BeginStartPacketCapture 468 // method. 469 func (client *VPNGatewaysClient) BeginStartPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStartPacketCaptureOptions) (*runtime.Poller[VPNGatewaysClientStartPacketCaptureResponse], error) { 470 if options == nil || options.ResumeToken == "" { 471 resp, err := client.startPacketCapture(ctx, resourceGroupName, gatewayName, options) 472 if err != nil { 473 return nil, err 474 } 475 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientStartPacketCaptureResponse]{ 476 FinalStateVia: runtime.FinalStateViaLocation, 477 Tracer: client.internal.Tracer(), 478 }) 479 return poller, err 480 } else { 481 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNGatewaysClientStartPacketCaptureResponse]{ 482 Tracer: client.internal.Tracer(), 483 }) 484 } 485 } 486 487 // StartPacketCapture - Starts packet capture on vpn gateway in the specified resource group. 488 // If the operation fails it returns an *azcore.ResponseError type. 489 // 490 // Generated from API version 2024-05-01 491 func (client *VPNGatewaysClient) startPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStartPacketCaptureOptions) (*http.Response, error) { 492 var err error 493 const operationName = "VPNGatewaysClient.BeginStartPacketCapture" 494 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 495 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 496 defer func() { endSpan(err) }() 497 req, err := client.startPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, options) 498 if err != nil { 499 return nil, err 500 } 501 httpResp, err := client.internal.Pipeline().Do(req) 502 if err != nil { 503 return nil, err 504 } 505 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 506 err = runtime.NewResponseError(httpResp) 507 return nil, err 508 } 509 return httpResp, nil 510 } 511 512 // startPacketCaptureCreateRequest creates the StartPacketCapture request. 513 func (client *VPNGatewaysClient) startPacketCaptureCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStartPacketCaptureOptions) (*policy.Request, error) { 514 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/startpacketcapture" 515 if resourceGroupName == "" { 516 return nil, errors.New("parameter resourceGroupName cannot be empty") 517 } 518 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 519 if gatewayName == "" { 520 return nil, errors.New("parameter gatewayName cannot be empty") 521 } 522 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 523 if client.subscriptionID == "" { 524 return nil, errors.New("parameter client.subscriptionID cannot be empty") 525 } 526 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 527 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 528 if err != nil { 529 return nil, err 530 } 531 reqQP := req.Raw().URL.Query() 532 reqQP.Set("api-version", "2024-05-01") 533 req.Raw().URL.RawQuery = reqQP.Encode() 534 req.Raw().Header["Accept"] = []string{"application/json"} 535 if options != nil && options.Parameters != nil { 536 if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { 537 return nil, err 538 } 539 return req, nil 540 } 541 return req, nil 542 } 543 544 // BeginStopPacketCapture - Stops packet capture on vpn gateway in the specified resource group. 545 // If the operation fails it returns an *azcore.ResponseError type. 546 // 547 // Generated from API version 2024-05-01 548 // - resourceGroupName - The resource group name of the VpnGateway. 549 // - gatewayName - The name of the gateway. 550 // - options - VPNGatewaysClientBeginStopPacketCaptureOptions contains the optional parameters for the VPNGatewaysClient.BeginStopPacketCapture 551 // method. 552 func (client *VPNGatewaysClient) BeginStopPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStopPacketCaptureOptions) (*runtime.Poller[VPNGatewaysClientStopPacketCaptureResponse], error) { 553 if options == nil || options.ResumeToken == "" { 554 resp, err := client.stopPacketCapture(ctx, resourceGroupName, gatewayName, options) 555 if err != nil { 556 return nil, err 557 } 558 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientStopPacketCaptureResponse]{ 559 FinalStateVia: runtime.FinalStateViaLocation, 560 Tracer: client.internal.Tracer(), 561 }) 562 return poller, err 563 } else { 564 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNGatewaysClientStopPacketCaptureResponse]{ 565 Tracer: client.internal.Tracer(), 566 }) 567 } 568 } 569 570 // StopPacketCapture - Stops packet capture on vpn gateway in the specified resource group. 571 // If the operation fails it returns an *azcore.ResponseError type. 572 // 573 // Generated from API version 2024-05-01 574 func (client *VPNGatewaysClient) stopPacketCapture(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStopPacketCaptureOptions) (*http.Response, error) { 575 var err error 576 const operationName = "VPNGatewaysClient.BeginStopPacketCapture" 577 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 578 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 579 defer func() { endSpan(err) }() 580 req, err := client.stopPacketCaptureCreateRequest(ctx, resourceGroupName, gatewayName, options) 581 if err != nil { 582 return nil, err 583 } 584 httpResp, err := client.internal.Pipeline().Do(req) 585 if err != nil { 586 return nil, err 587 } 588 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 589 err = runtime.NewResponseError(httpResp) 590 return nil, err 591 } 592 return httpResp, nil 593 } 594 595 // stopPacketCaptureCreateRequest creates the StopPacketCapture request. 596 func (client *VPNGatewaysClient) stopPacketCaptureCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, options *VPNGatewaysClientBeginStopPacketCaptureOptions) (*policy.Request, error) { 597 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/stoppacketcapture" 598 if resourceGroupName == "" { 599 return nil, errors.New("parameter resourceGroupName cannot be empty") 600 } 601 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 602 if gatewayName == "" { 603 return nil, errors.New("parameter gatewayName cannot be empty") 604 } 605 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 606 if client.subscriptionID == "" { 607 return nil, errors.New("parameter client.subscriptionID cannot be empty") 608 } 609 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 610 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 611 if err != nil { 612 return nil, err 613 } 614 reqQP := req.Raw().URL.Query() 615 reqQP.Set("api-version", "2024-05-01") 616 req.Raw().URL.RawQuery = reqQP.Encode() 617 req.Raw().Header["Accept"] = []string{"application/json"} 618 if options != nil && options.Parameters != nil { 619 if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { 620 return nil, err 621 } 622 return req, nil 623 } 624 return req, nil 625 } 626 627 // BeginUpdateTags - Updates virtual wan vpn gateway tags. 628 // If the operation fails it returns an *azcore.ResponseError type. 629 // 630 // Generated from API version 2024-05-01 631 // - resourceGroupName - The resource group name of the VpnGateway. 632 // - gatewayName - The name of the gateway. 633 // - vpnGatewayParameters - Parameters supplied to update a virtual wan vpn gateway tags. 634 // - options - VPNGatewaysClientBeginUpdateTagsOptions contains the optional parameters for the VPNGatewaysClient.BeginUpdateTags 635 // method. 636 func (client *VPNGatewaysClient) BeginUpdateTags(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters TagsObject, options *VPNGatewaysClientBeginUpdateTagsOptions) (*runtime.Poller[VPNGatewaysClientUpdateTagsResponse], error) { 637 if options == nil || options.ResumeToken == "" { 638 resp, err := client.updateTags(ctx, resourceGroupName, gatewayName, vpnGatewayParameters, options) 639 if err != nil { 640 return nil, err 641 } 642 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VPNGatewaysClientUpdateTagsResponse]{ 643 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 644 Tracer: client.internal.Tracer(), 645 }) 646 return poller, err 647 } else { 648 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VPNGatewaysClientUpdateTagsResponse]{ 649 Tracer: client.internal.Tracer(), 650 }) 651 } 652 } 653 654 // UpdateTags - Updates virtual wan vpn gateway tags. 655 // If the operation fails it returns an *azcore.ResponseError type. 656 // 657 // Generated from API version 2024-05-01 658 func (client *VPNGatewaysClient) updateTags(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters TagsObject, options *VPNGatewaysClientBeginUpdateTagsOptions) (*http.Response, error) { 659 var err error 660 const operationName = "VPNGatewaysClient.BeginUpdateTags" 661 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 662 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 663 defer func() { endSpan(err) }() 664 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, gatewayName, vpnGatewayParameters, options) 665 if err != nil { 666 return nil, err 667 } 668 httpResp, err := client.internal.Pipeline().Do(req) 669 if err != nil { 670 return nil, err 671 } 672 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 673 err = runtime.NewResponseError(httpResp) 674 return nil, err 675 } 676 return httpResp, nil 677 } 678 679 // updateTagsCreateRequest creates the UpdateTags request. 680 func (client *VPNGatewaysClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, vpnGatewayParameters TagsObject, options *VPNGatewaysClientBeginUpdateTagsOptions) (*policy.Request, error) { 681 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}" 682 if client.subscriptionID == "" { 683 return nil, errors.New("parameter client.subscriptionID cannot be empty") 684 } 685 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 686 if resourceGroupName == "" { 687 return nil, errors.New("parameter resourceGroupName cannot be empty") 688 } 689 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 690 if gatewayName == "" { 691 return nil, errors.New("parameter gatewayName cannot be empty") 692 } 693 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 694 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 695 if err != nil { 696 return nil, err 697 } 698 reqQP := req.Raw().URL.Query() 699 reqQP.Set("api-version", "2024-05-01") 700 req.Raw().URL.RawQuery = reqQP.Encode() 701 req.Raw().Header["Accept"] = []string{"application/json"} 702 if err := runtime.MarshalAsJSON(req, vpnGatewayParameters); err != nil { 703 return nil, err 704 } 705 return req, nil 706 }