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