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