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