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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// InboundNatRulesClient is the network Client 19type InboundNatRulesClient struct { 20 BaseClient 21} 22 23// NewInboundNatRulesClient creates an instance of the InboundNatRulesClient client. 24func NewInboundNatRulesClient(subscriptionID string) InboundNatRulesClient { 25 return NewInboundNatRulesClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewInboundNatRulesClientWithBaseURI creates an instance of the InboundNatRulesClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewInboundNatRulesClientWithBaseURI(baseURI string, subscriptionID string) InboundNatRulesClient { 31 return InboundNatRulesClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates or updates a load balancer inbound nat rule. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// loadBalancerName - the name of the load balancer. 38// inboundNatRuleName - the name of the inbound nat rule. 39// inboundNatRuleParameters - parameters supplied to the create or update inbound nat rule operation. 40func (client InboundNatRulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, inboundNatRuleParameters InboundNatRule) (result InboundNatRulesCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.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 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: inboundNatRuleParameters, 53 Constraints: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat", Name: validation.Null, Rule: false, 54 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration", Name: validation.Null, Rule: false, 55 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat", Name: validation.Null, Rule: false, 56 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, 57 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat", Name: validation.Null, Rule: false, 58 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration", Name: validation.Null, Rule: false, 59 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat", Name: validation.Null, Rule: false, 60 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}}}, 61 }}, 62 {Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.ServicePublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}, 63 {Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.LinkedPublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}, 64 }}, 65 }}, 66 }}, 67 }}, 68 }}}}}); err != nil { 69 return result, validation.NewError("network.InboundNatRulesClient", "CreateOrUpdate", err.Error()) 70 } 71 72 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, loadBalancerName, inboundNatRuleName, inboundNatRuleParameters) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "CreateOrUpdate", nil, "Failure preparing request") 75 return 76 } 77 78 result, err = client.CreateOrUpdateSender(req) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "CreateOrUpdate", nil, "Failure sending request") 81 return 82 } 83 84 return 85} 86 87// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 88func (client InboundNatRulesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, inboundNatRuleParameters InboundNatRule) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "inboundNatRuleName": autorest.Encode("path", inboundNatRuleName), 91 "loadBalancerName": autorest.Encode("path", loadBalancerName), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 } 95 96 const APIVersion = "2021-02-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 inboundNatRuleParameters.Etag = nil 102 inboundNatRuleParameters.Type = nil 103 preparer := autorest.CreatePreparer( 104 autorest.AsContentType("application/json; charset=utf-8"), 105 autorest.AsPut(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules/{inboundNatRuleName}", pathParameters), 108 autorest.WithJSON(inboundNatRuleParameters), 109 autorest.WithQueryParameters(queryParameters)) 110 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 111} 112 113// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 114// http.Response Body if it receives an error. 115func (client InboundNatRulesClient) CreateOrUpdateSender(req *http.Request) (future InboundNatRulesCreateOrUpdateFuture, err error) { 116 var resp *http.Response 117 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 118 if err != nil { 119 return 120 } 121 var azf azure.Future 122 azf, err = azure.NewFutureFromResponse(resp) 123 future.FutureAPI = &azf 124 future.Result = future.result 125 return 126} 127 128// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 129// closes the http.Response Body. 130func (client InboundNatRulesClient) CreateOrUpdateResponder(resp *http.Response) (result InboundNatRule, err error) { 131 err = autorest.Respond( 132 resp, 133 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 134 autorest.ByUnmarshallingJSON(&result), 135 autorest.ByClosing()) 136 result.Response = autorest.Response{Response: resp} 137 return 138} 139 140// Delete deletes the specified load balancer inbound nat rule. 141// Parameters: 142// resourceGroupName - the name of the resource group. 143// loadBalancerName - the name of the load balancer. 144// inboundNatRuleName - the name of the inbound nat rule. 145func (client InboundNatRulesClient) Delete(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string) (result InboundNatRulesDeleteFuture, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.Delete") 148 defer func() { 149 sc := -1 150 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 151 sc = result.FutureAPI.Response().StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 req, err := client.DeletePreparer(ctx, resourceGroupName, loadBalancerName, inboundNatRuleName) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Delete", nil, "Failure preparing request") 159 return 160 } 161 162 result, err = client.DeleteSender(req) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Delete", nil, "Failure sending request") 165 return 166 } 167 168 return 169} 170 171// DeletePreparer prepares the Delete request. 172func (client InboundNatRulesClient) DeletePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string) (*http.Request, error) { 173 pathParameters := map[string]interface{}{ 174 "inboundNatRuleName": autorest.Encode("path", inboundNatRuleName), 175 "loadBalancerName": autorest.Encode("path", loadBalancerName), 176 "resourceGroupName": autorest.Encode("path", resourceGroupName), 177 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 178 } 179 180 const APIVersion = "2021-02-01" 181 queryParameters := map[string]interface{}{ 182 "api-version": APIVersion, 183 } 184 185 preparer := autorest.CreatePreparer( 186 autorest.AsDelete(), 187 autorest.WithBaseURL(client.BaseURI), 188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules/{inboundNatRuleName}", pathParameters), 189 autorest.WithQueryParameters(queryParameters)) 190 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 191} 192 193// DeleteSender sends the Delete request. The method will close the 194// http.Response Body if it receives an error. 195func (client InboundNatRulesClient) DeleteSender(req *http.Request) (future InboundNatRulesDeleteFuture, err error) { 196 var resp *http.Response 197 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 198 if err != nil { 199 return 200 } 201 var azf azure.Future 202 azf, err = azure.NewFutureFromResponse(resp) 203 future.FutureAPI = &azf 204 future.Result = future.result 205 return 206} 207 208// DeleteResponder handles the response to the Delete request. The method always 209// closes the http.Response Body. 210func (client InboundNatRulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 211 err = autorest.Respond( 212 resp, 213 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 214 autorest.ByClosing()) 215 result.Response = resp 216 return 217} 218 219// Get gets the specified load balancer inbound nat rule. 220// Parameters: 221// resourceGroupName - the name of the resource group. 222// loadBalancerName - the name of the load balancer. 223// inboundNatRuleName - the name of the inbound nat rule. 224// expand - expands referenced resources. 225func (client InboundNatRulesClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, expand string) (result InboundNatRule, err error) { 226 if tracing.IsEnabled() { 227 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.Get") 228 defer func() { 229 sc := -1 230 if result.Response.Response != nil { 231 sc = result.Response.Response.StatusCode 232 } 233 tracing.EndSpan(ctx, sc, err) 234 }() 235 } 236 req, err := client.GetPreparer(ctx, resourceGroupName, loadBalancerName, inboundNatRuleName, expand) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Get", nil, "Failure preparing request") 239 return 240 } 241 242 resp, err := client.GetSender(req) 243 if err != nil { 244 result.Response = autorest.Response{Response: resp} 245 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Get", resp, "Failure sending request") 246 return 247 } 248 249 result, err = client.GetResponder(resp) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Get", resp, "Failure responding to request") 252 return 253 } 254 255 return 256} 257 258// GetPreparer prepares the Get request. 259func (client InboundNatRulesClient) GetPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, expand string) (*http.Request, error) { 260 pathParameters := map[string]interface{}{ 261 "inboundNatRuleName": autorest.Encode("path", inboundNatRuleName), 262 "loadBalancerName": autorest.Encode("path", loadBalancerName), 263 "resourceGroupName": autorest.Encode("path", resourceGroupName), 264 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 265 } 266 267 const APIVersion = "2021-02-01" 268 queryParameters := map[string]interface{}{ 269 "api-version": APIVersion, 270 } 271 if len(expand) > 0 { 272 queryParameters["$expand"] = autorest.Encode("query", expand) 273 } 274 275 preparer := autorest.CreatePreparer( 276 autorest.AsGet(), 277 autorest.WithBaseURL(client.BaseURI), 278 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules/{inboundNatRuleName}", pathParameters), 279 autorest.WithQueryParameters(queryParameters)) 280 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 281} 282 283// GetSender sends the Get request. The method will close the 284// http.Response Body if it receives an error. 285func (client InboundNatRulesClient) GetSender(req *http.Request) (*http.Response, error) { 286 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 287} 288 289// GetResponder handles the response to the Get request. The method always 290// closes the http.Response Body. 291func (client InboundNatRulesClient) GetResponder(resp *http.Response) (result InboundNatRule, err error) { 292 err = autorest.Respond( 293 resp, 294 azure.WithErrorUnlessStatusCode(http.StatusOK), 295 autorest.ByUnmarshallingJSON(&result), 296 autorest.ByClosing()) 297 result.Response = autorest.Response{Response: resp} 298 return 299} 300 301// List gets all the inbound nat rules in a load balancer. 302// Parameters: 303// resourceGroupName - the name of the resource group. 304// loadBalancerName - the name of the load balancer. 305func (client InboundNatRulesClient) List(ctx context.Context, resourceGroupName string, loadBalancerName string) (result InboundNatRuleListResultPage, err error) { 306 if tracing.IsEnabled() { 307 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.List") 308 defer func() { 309 sc := -1 310 if result.inrlr.Response.Response != nil { 311 sc = result.inrlr.Response.Response.StatusCode 312 } 313 tracing.EndSpan(ctx, sc, err) 314 }() 315 } 316 result.fn = client.listNextResults 317 req, err := client.ListPreparer(ctx, resourceGroupName, loadBalancerName) 318 if err != nil { 319 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "List", nil, "Failure preparing request") 320 return 321 } 322 323 resp, err := client.ListSender(req) 324 if err != nil { 325 result.inrlr.Response = autorest.Response{Response: resp} 326 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "List", resp, "Failure sending request") 327 return 328 } 329 330 result.inrlr, err = client.ListResponder(resp) 331 if err != nil { 332 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "List", resp, "Failure responding to request") 333 return 334 } 335 if result.inrlr.hasNextLink() && result.inrlr.IsEmpty() { 336 err = result.NextWithContext(ctx) 337 return 338 } 339 340 return 341} 342 343// ListPreparer prepares the List request. 344func (client InboundNatRulesClient) ListPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string) (*http.Request, error) { 345 pathParameters := map[string]interface{}{ 346 "loadBalancerName": autorest.Encode("path", loadBalancerName), 347 "resourceGroupName": autorest.Encode("path", resourceGroupName), 348 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 349 } 350 351 const APIVersion = "2021-02-01" 352 queryParameters := map[string]interface{}{ 353 "api-version": APIVersion, 354 } 355 356 preparer := autorest.CreatePreparer( 357 autorest.AsGet(), 358 autorest.WithBaseURL(client.BaseURI), 359 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules", pathParameters), 360 autorest.WithQueryParameters(queryParameters)) 361 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 362} 363 364// ListSender sends the List request. The method will close the 365// http.Response Body if it receives an error. 366func (client InboundNatRulesClient) ListSender(req *http.Request) (*http.Response, error) { 367 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 368} 369 370// ListResponder handles the response to the List request. The method always 371// closes the http.Response Body. 372func (client InboundNatRulesClient) ListResponder(resp *http.Response) (result InboundNatRuleListResult, err error) { 373 err = autorest.Respond( 374 resp, 375 azure.WithErrorUnlessStatusCode(http.StatusOK), 376 autorest.ByUnmarshallingJSON(&result), 377 autorest.ByClosing()) 378 result.Response = autorest.Response{Response: resp} 379 return 380} 381 382// listNextResults retrieves the next set of results, if any. 383func (client InboundNatRulesClient) listNextResults(ctx context.Context, lastResults InboundNatRuleListResult) (result InboundNatRuleListResult, err error) { 384 req, err := lastResults.inboundNatRuleListResultPreparer(ctx) 385 if err != nil { 386 return result, autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "listNextResults", nil, "Failure preparing next results request") 387 } 388 if req == nil { 389 return 390 } 391 resp, err := client.ListSender(req) 392 if err != nil { 393 result.Response = autorest.Response{Response: resp} 394 return result, autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "listNextResults", resp, "Failure sending next results request") 395 } 396 result, err = client.ListResponder(resp) 397 if err != nil { 398 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "listNextResults", resp, "Failure responding to next results request") 399 } 400 return 401} 402 403// ListComplete enumerates all values, automatically crossing page boundaries as required. 404func (client InboundNatRulesClient) ListComplete(ctx context.Context, resourceGroupName string, loadBalancerName string) (result InboundNatRuleListResultIterator, err error) { 405 if tracing.IsEnabled() { 406 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.List") 407 defer func() { 408 sc := -1 409 if result.Response().Response.Response != nil { 410 sc = result.page.Response().Response.Response.StatusCode 411 } 412 tracing.EndSpan(ctx, sc, err) 413 }() 414 } 415 result.page, err = client.List(ctx, resourceGroupName, loadBalancerName) 416 return 417} 418