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