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