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