...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-05-01/network/securitygroups.go

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-05-01/network

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

View as plain text