1package network 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15) 16 17// VpnConnectionsClient is the network Client 18type VpnConnectionsClient struct { 19 BaseClient 20} 21 22// NewVpnConnectionsClient creates an instance of the VpnConnectionsClient client. 23func NewVpnConnectionsClient(subscriptionID string) VpnConnectionsClient { 24 return NewVpnConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewVpnConnectionsClientWithBaseURI creates an instance of the VpnConnectionsClient client using a custom endpoint. 28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewVpnConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VpnConnectionsClient { 30 return VpnConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// CreateOrUpdate creates a vpn connection to a scalable vpn gateway if it doesn't exist else updates the existing 34// connection. 35// Parameters: 36// resourceGroupName - the resource group name of the VpnGateway. 37// gatewayName - the name of the gateway. 38// connectionName - the name of the connection. 39// vpnConnectionParameters - parameters supplied to create or Update a VPN Connection. 40func (client VpnConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VpnConnection) (result VpnConnectionsCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, gatewayName, connectionName, vpnConnectionParameters) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request") 54 return 55 } 56 57 result, err = client.CreateOrUpdateSender(req) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "CreateOrUpdate", nil, "Failure sending request") 60 return 61 } 62 63 return 64} 65 66// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 67func (client VpnConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VpnConnection) (*http.Request, error) { 68 pathParameters := map[string]interface{}{ 69 "connectionName": autorest.Encode("path", connectionName), 70 "gatewayName": autorest.Encode("path", gatewayName), 71 "resourceGroupName": autorest.Encode("path", resourceGroupName), 72 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 73 } 74 75 const APIVersion = "2019-09-01" 76 queryParameters := map[string]interface{}{ 77 "api-version": APIVersion, 78 } 79 80 vpnConnectionParameters.Etag = nil 81 preparer := autorest.CreatePreparer( 82 autorest.AsContentType("application/json; charset=utf-8"), 83 autorest.AsPut(), 84 autorest.WithBaseURL(client.BaseURI), 85 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters), 86 autorest.WithJSON(vpnConnectionParameters), 87 autorest.WithQueryParameters(queryParameters)) 88 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 89} 90 91// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 92// http.Response Body if it receives an error. 93func (client VpnConnectionsClient) CreateOrUpdateSender(req *http.Request) (future VpnConnectionsCreateOrUpdateFuture, err error) { 94 var resp *http.Response 95 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 96 if err != nil { 97 return 98 } 99 var azf azure.Future 100 azf, err = azure.NewFutureFromResponse(resp) 101 future.FutureAPI = &azf 102 future.Result = future.result 103 return 104} 105 106// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 107// closes the http.Response Body. 108func (client VpnConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result VpnConnection, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117 118// Delete deletes a vpn connection. 119// Parameters: 120// resourceGroupName - the resource group name of the VpnGateway. 121// gatewayName - the name of the gateway. 122// connectionName - the name of the connection. 123func (client VpnConnectionsClient) Delete(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result VpnConnectionsDeleteFuture, err error) { 124 if tracing.IsEnabled() { 125 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.Delete") 126 defer func() { 127 sc := -1 128 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 129 sc = result.FutureAPI.Response().StatusCode 130 } 131 tracing.EndSpan(ctx, sc, err) 132 }() 133 } 134 req, err := client.DeletePreparer(ctx, resourceGroupName, gatewayName, connectionName) 135 if err != nil { 136 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Delete", nil, "Failure preparing request") 137 return 138 } 139 140 result, err = client.DeleteSender(req) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Delete", nil, "Failure sending request") 143 return 144 } 145 146 return 147} 148 149// DeletePreparer prepares the Delete request. 150func (client VpnConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) { 151 pathParameters := map[string]interface{}{ 152 "connectionName": autorest.Encode("path", connectionName), 153 "gatewayName": autorest.Encode("path", gatewayName), 154 "resourceGroupName": autorest.Encode("path", resourceGroupName), 155 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 156 } 157 158 const APIVersion = "2019-09-01" 159 queryParameters := map[string]interface{}{ 160 "api-version": APIVersion, 161 } 162 163 preparer := autorest.CreatePreparer( 164 autorest.AsDelete(), 165 autorest.WithBaseURL(client.BaseURI), 166 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters), 167 autorest.WithQueryParameters(queryParameters)) 168 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 169} 170 171// DeleteSender sends the Delete request. The method will close the 172// http.Response Body if it receives an error. 173func (client VpnConnectionsClient) DeleteSender(req *http.Request) (future VpnConnectionsDeleteFuture, err error) { 174 var resp *http.Response 175 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 176 if err != nil { 177 return 178 } 179 var azf azure.Future 180 azf, err = azure.NewFutureFromResponse(resp) 181 future.FutureAPI = &azf 182 future.Result = future.result 183 return 184} 185 186// DeleteResponder handles the response to the Delete request. The method always 187// closes the http.Response Body. 188func (client VpnConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 189 err = autorest.Respond( 190 resp, 191 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 192 autorest.ByClosing()) 193 result.Response = resp 194 return 195} 196 197// Get retrieves the details of a vpn connection. 198// Parameters: 199// resourceGroupName - the resource group name of the VpnGateway. 200// gatewayName - the name of the gateway. 201// connectionName - the name of the vpn connection. 202func (client VpnConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result VpnConnection, err error) { 203 if tracing.IsEnabled() { 204 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.Get") 205 defer func() { 206 sc := -1 207 if result.Response.Response != nil { 208 sc = result.Response.Response.StatusCode 209 } 210 tracing.EndSpan(ctx, sc, err) 211 }() 212 } 213 req, err := client.GetPreparer(ctx, resourceGroupName, gatewayName, connectionName) 214 if err != nil { 215 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Get", nil, "Failure preparing request") 216 return 217 } 218 219 resp, err := client.GetSender(req) 220 if err != nil { 221 result.Response = autorest.Response{Response: resp} 222 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Get", resp, "Failure sending request") 223 return 224 } 225 226 result, err = client.GetResponder(resp) 227 if err != nil { 228 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Get", resp, "Failure responding to request") 229 return 230 } 231 232 return 233} 234 235// GetPreparer prepares the Get request. 236func (client VpnConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) { 237 pathParameters := map[string]interface{}{ 238 "connectionName": autorest.Encode("path", connectionName), 239 "gatewayName": autorest.Encode("path", gatewayName), 240 "resourceGroupName": autorest.Encode("path", resourceGroupName), 241 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 242 } 243 244 const APIVersion = "2019-09-01" 245 queryParameters := map[string]interface{}{ 246 "api-version": APIVersion, 247 } 248 249 preparer := autorest.CreatePreparer( 250 autorest.AsGet(), 251 autorest.WithBaseURL(client.BaseURI), 252 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters), 253 autorest.WithQueryParameters(queryParameters)) 254 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 255} 256 257// GetSender sends the Get request. The method will close the 258// http.Response Body if it receives an error. 259func (client VpnConnectionsClient) GetSender(req *http.Request) (*http.Response, error) { 260 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 261} 262 263// GetResponder handles the response to the Get request. The method always 264// closes the http.Response Body. 265func (client VpnConnectionsClient) GetResponder(resp *http.Response) (result VpnConnection, err error) { 266 err = autorest.Respond( 267 resp, 268 azure.WithErrorUnlessStatusCode(http.StatusOK), 269 autorest.ByUnmarshallingJSON(&result), 270 autorest.ByClosing()) 271 result.Response = autorest.Response{Response: resp} 272 return 273} 274 275// ListByVpnGateway retrieves all vpn connections for a particular virtual wan vpn gateway. 276// Parameters: 277// resourceGroupName - the resource group name of the VpnGateway. 278// gatewayName - the name of the gateway. 279func (client VpnConnectionsClient) ListByVpnGateway(ctx context.Context, resourceGroupName string, gatewayName string) (result ListVpnConnectionsResultPage, err error) { 280 if tracing.IsEnabled() { 281 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.ListByVpnGateway") 282 defer func() { 283 sc := -1 284 if result.lvcr.Response.Response != nil { 285 sc = result.lvcr.Response.Response.StatusCode 286 } 287 tracing.EndSpan(ctx, sc, err) 288 }() 289 } 290 result.fn = client.listByVpnGatewayNextResults 291 req, err := client.ListByVpnGatewayPreparer(ctx, resourceGroupName, gatewayName) 292 if err != nil { 293 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", nil, "Failure preparing request") 294 return 295 } 296 297 resp, err := client.ListByVpnGatewaySender(req) 298 if err != nil { 299 result.lvcr.Response = autorest.Response{Response: resp} 300 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", resp, "Failure sending request") 301 return 302 } 303 304 result.lvcr, err = client.ListByVpnGatewayResponder(resp) 305 if err != nil { 306 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", resp, "Failure responding to request") 307 return 308 } 309 if result.lvcr.hasNextLink() && result.lvcr.IsEmpty() { 310 err = result.NextWithContext(ctx) 311 return 312 } 313 314 return 315} 316 317// ListByVpnGatewayPreparer prepares the ListByVpnGateway request. 318func (client VpnConnectionsClient) ListByVpnGatewayPreparer(ctx context.Context, resourceGroupName string, gatewayName string) (*http.Request, error) { 319 pathParameters := map[string]interface{}{ 320 "gatewayName": autorest.Encode("path", gatewayName), 321 "resourceGroupName": autorest.Encode("path", resourceGroupName), 322 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 323 } 324 325 const APIVersion = "2019-09-01" 326 queryParameters := map[string]interface{}{ 327 "api-version": APIVersion, 328 } 329 330 preparer := autorest.CreatePreparer( 331 autorest.AsGet(), 332 autorest.WithBaseURL(client.BaseURI), 333 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections", pathParameters), 334 autorest.WithQueryParameters(queryParameters)) 335 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 336} 337 338// ListByVpnGatewaySender sends the ListByVpnGateway request. The method will close the 339// http.Response Body if it receives an error. 340func (client VpnConnectionsClient) ListByVpnGatewaySender(req *http.Request) (*http.Response, error) { 341 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 342} 343 344// ListByVpnGatewayResponder handles the response to the ListByVpnGateway request. The method always 345// closes the http.Response Body. 346func (client VpnConnectionsClient) ListByVpnGatewayResponder(resp *http.Response) (result ListVpnConnectionsResult, err error) { 347 err = autorest.Respond( 348 resp, 349 azure.WithErrorUnlessStatusCode(http.StatusOK), 350 autorest.ByUnmarshallingJSON(&result), 351 autorest.ByClosing()) 352 result.Response = autorest.Response{Response: resp} 353 return 354} 355 356// listByVpnGatewayNextResults retrieves the next set of results, if any. 357func (client VpnConnectionsClient) listByVpnGatewayNextResults(ctx context.Context, lastResults ListVpnConnectionsResult) (result ListVpnConnectionsResult, err error) { 358 req, err := lastResults.listVpnConnectionsResultPreparer(ctx) 359 if err != nil { 360 return result, autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", nil, "Failure preparing next results request") 361 } 362 if req == nil { 363 return 364 } 365 resp, err := client.ListByVpnGatewaySender(req) 366 if err != nil { 367 result.Response = autorest.Response{Response: resp} 368 return result, autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", resp, "Failure sending next results request") 369 } 370 result, err = client.ListByVpnGatewayResponder(resp) 371 if err != nil { 372 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", resp, "Failure responding to next results request") 373 } 374 return 375} 376 377// ListByVpnGatewayComplete enumerates all values, automatically crossing page boundaries as required. 378func (client VpnConnectionsClient) ListByVpnGatewayComplete(ctx context.Context, resourceGroupName string, gatewayName string) (result ListVpnConnectionsResultIterator, err error) { 379 if tracing.IsEnabled() { 380 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.ListByVpnGateway") 381 defer func() { 382 sc := -1 383 if result.Response().Response.Response != nil { 384 sc = result.page.Response().Response.Response.StatusCode 385 } 386 tracing.EndSpan(ctx, sc, err) 387 }() 388 } 389 result.page, err = client.ListByVpnGateway(ctx, resourceGroupName, gatewayName) 390 return 391} 392