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// NatGatewaysClient is the network Client
29type NatGatewaysClient struct {
30	BaseClient
31}
32
33// NewNatGatewaysClient creates an instance of the NatGatewaysClient client.
34func NewNatGatewaysClient(subscriptionID string) NatGatewaysClient {
35	return NewNatGatewaysClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewNatGatewaysClientWithBaseURI creates an instance of the NatGatewaysClient client using a custom endpoint.  Use
39// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewNatGatewaysClientWithBaseURI(baseURI string, subscriptionID string) NatGatewaysClient {
41	return NatGatewaysClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or updates a nat gateway.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// natGatewayName - the name of the nat gateway.
48// parameters - parameters supplied to the create or update nat gateway operation.
49func (client NatGatewaysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, natGatewayName string, parameters NatGateway) (result NatGatewaysCreateOrUpdateFuture, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.CreateOrUpdate")
52		defer func() {
53			sc := -1
54			if result.Response() != nil {
55				sc = result.Response().StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, natGatewayName, parameters)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request")
63		return
64	}
65
66	result, err = client.CreateOrUpdateSender(req)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "CreateOrUpdate", result.Response(), "Failure sending request")
69		return
70	}
71
72	return
73}
74
75// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
76func (client NatGatewaysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, natGatewayName string, parameters NatGateway) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"natGatewayName":    autorest.Encode("path", natGatewayName),
79		"resourceGroupName": autorest.Encode("path", resourceGroupName),
80		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
81	}
82
83	const APIVersion = "2020-04-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	parameters.Etag = nil
89	preparer := autorest.CreatePreparer(
90		autorest.AsContentType("application/json; charset=utf-8"),
91		autorest.AsPut(),
92		autorest.WithBaseURL(client.BaseURI),
93		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters),
94		autorest.WithJSON(parameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
100// http.Response Body if it receives an error.
101func (client NatGatewaysClient) CreateOrUpdateSender(req *http.Request) (future NatGatewaysCreateOrUpdateFuture, err error) {
102	var resp *http.Response
103	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
104	if err != nil {
105		return
106	}
107	future.Future, err = azure.NewFutureFromResponse(resp)
108	return
109}
110
111// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
112// closes the http.Response Body.
113func (client NatGatewaysClient) CreateOrUpdateResponder(resp *http.Response) (result NatGateway, err error) {
114	err = autorest.Respond(
115		resp,
116		client.ByInspecting(),
117		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
118		autorest.ByUnmarshallingJSON(&result),
119		autorest.ByClosing())
120	result.Response = autorest.Response{Response: resp}
121	return
122}
123
124// Delete deletes the specified nat gateway.
125// Parameters:
126// resourceGroupName - the name of the resource group.
127// natGatewayName - the name of the nat gateway.
128func (client NatGatewaysClient) Delete(ctx context.Context, resourceGroupName string, natGatewayName string) (result NatGatewaysDeleteFuture, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.Delete")
131		defer func() {
132			sc := -1
133			if result.Response() != nil {
134				sc = result.Response().StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	req, err := client.DeletePreparer(ctx, resourceGroupName, natGatewayName)
140	if err != nil {
141		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Delete", nil, "Failure preparing request")
142		return
143	}
144
145	result, err = client.DeleteSender(req)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Delete", result.Response(), "Failure sending request")
148		return
149	}
150
151	return
152}
153
154// DeletePreparer prepares the Delete request.
155func (client NatGatewaysClient) DeletePreparer(ctx context.Context, resourceGroupName string, natGatewayName string) (*http.Request, error) {
156	pathParameters := map[string]interface{}{
157		"natGatewayName":    autorest.Encode("path", natGatewayName),
158		"resourceGroupName": autorest.Encode("path", resourceGroupName),
159		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
160	}
161
162	const APIVersion = "2020-04-01"
163	queryParameters := map[string]interface{}{
164		"api-version": APIVersion,
165	}
166
167	preparer := autorest.CreatePreparer(
168		autorest.AsDelete(),
169		autorest.WithBaseURL(client.BaseURI),
170		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters),
171		autorest.WithQueryParameters(queryParameters))
172	return preparer.Prepare((&http.Request{}).WithContext(ctx))
173}
174
175// DeleteSender sends the Delete request. The method will close the
176// http.Response Body if it receives an error.
177func (client NatGatewaysClient) DeleteSender(req *http.Request) (future NatGatewaysDeleteFuture, err error) {
178	var resp *http.Response
179	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
180	if err != nil {
181		return
182	}
183	future.Future, err = azure.NewFutureFromResponse(resp)
184	return
185}
186
187// DeleteResponder handles the response to the Delete request. The method always
188// closes the http.Response Body.
189func (client NatGatewaysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
190	err = autorest.Respond(
191		resp,
192		client.ByInspecting(),
193		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
194		autorest.ByClosing())
195	result.Response = resp
196	return
197}
198
199// Get gets the specified nat gateway in a specified resource group.
200// Parameters:
201// resourceGroupName - the name of the resource group.
202// natGatewayName - the name of the nat gateway.
203// expand - expands referenced resources.
204func (client NatGatewaysClient) Get(ctx context.Context, resourceGroupName string, natGatewayName string, expand string) (result NatGateway, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.Get")
207		defer func() {
208			sc := -1
209			if result.Response.Response != nil {
210				sc = result.Response.Response.StatusCode
211			}
212			tracing.EndSpan(ctx, sc, err)
213		}()
214	}
215	req, err := client.GetPreparer(ctx, resourceGroupName, natGatewayName, expand)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Get", nil, "Failure preparing request")
218		return
219	}
220
221	resp, err := client.GetSender(req)
222	if err != nil {
223		result.Response = autorest.Response{Response: resp}
224		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Get", resp, "Failure sending request")
225		return
226	}
227
228	result, err = client.GetResponder(resp)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Get", resp, "Failure responding to request")
231	}
232
233	return
234}
235
236// GetPreparer prepares the Get request.
237func (client NatGatewaysClient) GetPreparer(ctx context.Context, resourceGroupName string, natGatewayName string, expand string) (*http.Request, error) {
238	pathParameters := map[string]interface{}{
239		"natGatewayName":    autorest.Encode("path", natGatewayName),
240		"resourceGroupName": autorest.Encode("path", resourceGroupName),
241		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
242	}
243
244	const APIVersion = "2020-04-01"
245	queryParameters := map[string]interface{}{
246		"api-version": APIVersion,
247	}
248	if len(expand) > 0 {
249		queryParameters["$expand"] = autorest.Encode("query", expand)
250	}
251
252	preparer := autorest.CreatePreparer(
253		autorest.AsGet(),
254		autorest.WithBaseURL(client.BaseURI),
255		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters),
256		autorest.WithQueryParameters(queryParameters))
257	return preparer.Prepare((&http.Request{}).WithContext(ctx))
258}
259
260// GetSender sends the Get request. The method will close the
261// http.Response Body if it receives an error.
262func (client NatGatewaysClient) GetSender(req *http.Request) (*http.Response, error) {
263	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
264}
265
266// GetResponder handles the response to the Get request. The method always
267// closes the http.Response Body.
268func (client NatGatewaysClient) GetResponder(resp *http.Response) (result NatGateway, err error) {
269	err = autorest.Respond(
270		resp,
271		client.ByInspecting(),
272		azure.WithErrorUnlessStatusCode(http.StatusOK),
273		autorest.ByUnmarshallingJSON(&result),
274		autorest.ByClosing())
275	result.Response = autorest.Response{Response: resp}
276	return
277}
278
279// List gets all nat gateways in a resource group.
280// Parameters:
281// resourceGroupName - the name of the resource group.
282func (client NatGatewaysClient) List(ctx context.Context, resourceGroupName string) (result NatGatewayListResultPage, err error) {
283	if tracing.IsEnabled() {
284		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.List")
285		defer func() {
286			sc := -1
287			if result.nglr.Response.Response != nil {
288				sc = result.nglr.Response.Response.StatusCode
289			}
290			tracing.EndSpan(ctx, sc, err)
291		}()
292	}
293	result.fn = client.listNextResults
294	req, err := client.ListPreparer(ctx, resourceGroupName)
295	if err != nil {
296		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "List", nil, "Failure preparing request")
297		return
298	}
299
300	resp, err := client.ListSender(req)
301	if err != nil {
302		result.nglr.Response = autorest.Response{Response: resp}
303		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "List", resp, "Failure sending request")
304		return
305	}
306
307	result.nglr, err = client.ListResponder(resp)
308	if err != nil {
309		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "List", resp, "Failure responding to request")
310	}
311
312	return
313}
314
315// ListPreparer prepares the List request.
316func (client NatGatewaysClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
317	pathParameters := map[string]interface{}{
318		"resourceGroupName": autorest.Encode("path", resourceGroupName),
319		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
320	}
321
322	const APIVersion = "2020-04-01"
323	queryParameters := map[string]interface{}{
324		"api-version": APIVersion,
325	}
326
327	preparer := autorest.CreatePreparer(
328		autorest.AsGet(),
329		autorest.WithBaseURL(client.BaseURI),
330		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways", pathParameters),
331		autorest.WithQueryParameters(queryParameters))
332	return preparer.Prepare((&http.Request{}).WithContext(ctx))
333}
334
335// ListSender sends the List request. The method will close the
336// http.Response Body if it receives an error.
337func (client NatGatewaysClient) ListSender(req *http.Request) (*http.Response, error) {
338	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
339}
340
341// ListResponder handles the response to the List request. The method always
342// closes the http.Response Body.
343func (client NatGatewaysClient) ListResponder(resp *http.Response) (result NatGatewayListResult, err error) {
344	err = autorest.Respond(
345		resp,
346		client.ByInspecting(),
347		azure.WithErrorUnlessStatusCode(http.StatusOK),
348		autorest.ByUnmarshallingJSON(&result),
349		autorest.ByClosing())
350	result.Response = autorest.Response{Response: resp}
351	return
352}
353
354// listNextResults retrieves the next set of results, if any.
355func (client NatGatewaysClient) listNextResults(ctx context.Context, lastResults NatGatewayListResult) (result NatGatewayListResult, err error) {
356	req, err := lastResults.natGatewayListResultPreparer(ctx)
357	if err != nil {
358		return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listNextResults", nil, "Failure preparing next results request")
359	}
360	if req == nil {
361		return
362	}
363	resp, err := client.ListSender(req)
364	if err != nil {
365		result.Response = autorest.Response{Response: resp}
366		return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listNextResults", resp, "Failure sending next results request")
367	}
368	result, err = client.ListResponder(resp)
369	if err != nil {
370		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listNextResults", resp, "Failure responding to next results request")
371	}
372	return
373}
374
375// ListComplete enumerates all values, automatically crossing page boundaries as required.
376func (client NatGatewaysClient) ListComplete(ctx context.Context, resourceGroupName string) (result NatGatewayListResultIterator, err error) {
377	if tracing.IsEnabled() {
378		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.List")
379		defer func() {
380			sc := -1
381			if result.Response().Response.Response != nil {
382				sc = result.page.Response().Response.Response.StatusCode
383			}
384			tracing.EndSpan(ctx, sc, err)
385		}()
386	}
387	result.page, err = client.List(ctx, resourceGroupName)
388	return
389}
390
391// ListAll gets all the Nat Gateways in a subscription.
392func (client NatGatewaysClient) ListAll(ctx context.Context) (result NatGatewayListResultPage, err error) {
393	if tracing.IsEnabled() {
394		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.ListAll")
395		defer func() {
396			sc := -1
397			if result.nglr.Response.Response != nil {
398				sc = result.nglr.Response.Response.StatusCode
399			}
400			tracing.EndSpan(ctx, sc, err)
401		}()
402	}
403	result.fn = client.listAllNextResults
404	req, err := client.ListAllPreparer(ctx)
405	if err != nil {
406		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "ListAll", nil, "Failure preparing request")
407		return
408	}
409
410	resp, err := client.ListAllSender(req)
411	if err != nil {
412		result.nglr.Response = autorest.Response{Response: resp}
413		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "ListAll", resp, "Failure sending request")
414		return
415	}
416
417	result.nglr, err = client.ListAllResponder(resp)
418	if err != nil {
419		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "ListAll", resp, "Failure responding to request")
420	}
421
422	return
423}
424
425// ListAllPreparer prepares the ListAll request.
426func (client NatGatewaysClient) ListAllPreparer(ctx context.Context) (*http.Request, error) {
427	pathParameters := map[string]interface{}{
428		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
429	}
430
431	const APIVersion = "2020-04-01"
432	queryParameters := map[string]interface{}{
433		"api-version": APIVersion,
434	}
435
436	preparer := autorest.CreatePreparer(
437		autorest.AsGet(),
438		autorest.WithBaseURL(client.BaseURI),
439		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/natGateways", pathParameters),
440		autorest.WithQueryParameters(queryParameters))
441	return preparer.Prepare((&http.Request{}).WithContext(ctx))
442}
443
444// ListAllSender sends the ListAll request. The method will close the
445// http.Response Body if it receives an error.
446func (client NatGatewaysClient) ListAllSender(req *http.Request) (*http.Response, error) {
447	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
448}
449
450// ListAllResponder handles the response to the ListAll request. The method always
451// closes the http.Response Body.
452func (client NatGatewaysClient) ListAllResponder(resp *http.Response) (result NatGatewayListResult, err error) {
453	err = autorest.Respond(
454		resp,
455		client.ByInspecting(),
456		azure.WithErrorUnlessStatusCode(http.StatusOK),
457		autorest.ByUnmarshallingJSON(&result),
458		autorest.ByClosing())
459	result.Response = autorest.Response{Response: resp}
460	return
461}
462
463// listAllNextResults retrieves the next set of results, if any.
464func (client NatGatewaysClient) listAllNextResults(ctx context.Context, lastResults NatGatewayListResult) (result NatGatewayListResult, err error) {
465	req, err := lastResults.natGatewayListResultPreparer(ctx)
466	if err != nil {
467		return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listAllNextResults", nil, "Failure preparing next results request")
468	}
469	if req == nil {
470		return
471	}
472	resp, err := client.ListAllSender(req)
473	if err != nil {
474		result.Response = autorest.Response{Response: resp}
475		return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listAllNextResults", resp, "Failure sending next results request")
476	}
477	result, err = client.ListAllResponder(resp)
478	if err != nil {
479		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listAllNextResults", resp, "Failure responding to next results request")
480	}
481	return
482}
483
484// ListAllComplete enumerates all values, automatically crossing page boundaries as required.
485func (client NatGatewaysClient) ListAllComplete(ctx context.Context) (result NatGatewayListResultIterator, err error) {
486	if tracing.IsEnabled() {
487		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.ListAll")
488		defer func() {
489			sc := -1
490			if result.Response().Response.Response != nil {
491				sc = result.page.Response().Response.Response.StatusCode
492			}
493			tracing.EndSpan(ctx, sc, err)
494		}()
495	}
496	result.page, err = client.ListAll(ctx)
497	return
498}
499
500// UpdateTags updates nat gateway tags.
501// Parameters:
502// resourceGroupName - the name of the resource group.
503// natGatewayName - the name of the nat gateway.
504// parameters - parameters supplied to update nat gateway tags.
505func (client NatGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, natGatewayName string, parameters TagsObject) (result NatGateway, err error) {
506	if tracing.IsEnabled() {
507		ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.UpdateTags")
508		defer func() {
509			sc := -1
510			if result.Response.Response != nil {
511				sc = result.Response.Response.StatusCode
512			}
513			tracing.EndSpan(ctx, sc, err)
514		}()
515	}
516	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, natGatewayName, parameters)
517	if err != nil {
518		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "UpdateTags", nil, "Failure preparing request")
519		return
520	}
521
522	resp, err := client.UpdateTagsSender(req)
523	if err != nil {
524		result.Response = autorest.Response{Response: resp}
525		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "UpdateTags", resp, "Failure sending request")
526		return
527	}
528
529	result, err = client.UpdateTagsResponder(resp)
530	if err != nil {
531		err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "UpdateTags", resp, "Failure responding to request")
532	}
533
534	return
535}
536
537// UpdateTagsPreparer prepares the UpdateTags request.
538func (client NatGatewaysClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, natGatewayName string, parameters TagsObject) (*http.Request, error) {
539	pathParameters := map[string]interface{}{
540		"natGatewayName":    autorest.Encode("path", natGatewayName),
541		"resourceGroupName": autorest.Encode("path", resourceGroupName),
542		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
543	}
544
545	const APIVersion = "2020-04-01"
546	queryParameters := map[string]interface{}{
547		"api-version": APIVersion,
548	}
549
550	preparer := autorest.CreatePreparer(
551		autorest.AsContentType("application/json; charset=utf-8"),
552		autorest.AsPatch(),
553		autorest.WithBaseURL(client.BaseURI),
554		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters),
555		autorest.WithJSON(parameters),
556		autorest.WithQueryParameters(queryParameters))
557	return preparer.Prepare((&http.Request{}).WithContext(ctx))
558}
559
560// UpdateTagsSender sends the UpdateTags request. The method will close the
561// http.Response Body if it receives an error.
562func (client NatGatewaysClient) UpdateTagsSender(req *http.Request) (*http.Response, error) {
563	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
564}
565
566// UpdateTagsResponder handles the response to the UpdateTags request. The method always
567// closes the http.Response Body.
568func (client NatGatewaysClient) UpdateTagsResponder(resp *http.Response) (result NatGateway, err error) {
569	err = autorest.Respond(
570		resp,
571		client.ByInspecting(),
572		azure.WithErrorUnlessStatusCode(http.StatusOK),
573		autorest.ByUnmarshallingJSON(&result),
574		autorest.ByClosing())
575	result.Response = autorest.Response{Response: resp}
576	return
577}
578