...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-01-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  // InboundSecurityRuleClient is the network Client
    18  type InboundSecurityRuleClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewInboundSecurityRuleClient creates an instance of the InboundSecurityRuleClient client.
    23  func NewInboundSecurityRuleClient(subscriptionID string) InboundSecurityRuleClient {
    24  	return NewInboundSecurityRuleClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewInboundSecurityRuleClientWithBaseURI creates an instance of the InboundSecurityRuleClient client using a custom
    28  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    29  // stack).
    30  func NewInboundSecurityRuleClientWithBaseURI(baseURI string, subscriptionID string) InboundSecurityRuleClient {
    31  	return InboundSecurityRuleClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates the specified Network Virtual Appliance Inbound Security Rules.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // networkVirtualApplianceName - the name of the Network Virtual Appliance.
    38  // ruleCollectionName - the name of security rule collection.
    39  // parameters - parameters supplied to the create or update Network Virtual Appliance Inbound Security Rules
    40  // operation.
    41  func (client InboundSecurityRuleClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters InboundSecurityRule) (result InboundSecurityRuleCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/InboundSecurityRuleClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, networkVirtualApplianceName, ruleCollectionName, parameters)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "network.InboundSecurityRuleClient", "CreateOrUpdate", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	result, err = client.CreateOrUpdateSender(req)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "network.InboundSecurityRuleClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    68  func (client InboundSecurityRuleClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters InboundSecurityRule) (*http.Request, error) {
    69  	pathParameters := map[string]interface{}{
    70  		"networkVirtualApplianceName": autorest.Encode("path", networkVirtualApplianceName),
    71  		"resourceGroupName":           autorest.Encode("path", resourceGroupName),
    72  		"ruleCollectionName":          autorest.Encode("path", ruleCollectionName),
    73  		"subscriptionId":              autorest.Encode("path", client.SubscriptionID),
    74  	}
    75  
    76  	const APIVersion = "2022-01-01"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	parameters.Etag = nil
    82  	parameters.Type = nil
    83  	preparer := autorest.CreatePreparer(
    84  		autorest.AsContentType("application/json; charset=utf-8"),
    85  		autorest.AsPut(),
    86  		autorest.WithBaseURL(client.BaseURI),
    87  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkVirtualAppliances/{networkVirtualApplianceName}/inboundSecurityRules/{ruleCollectionName}", pathParameters),
    88  		autorest.WithJSON(parameters),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    91  }
    92  
    93  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    94  // http.Response Body if it receives an error.
    95  func (client InboundSecurityRuleClient) CreateOrUpdateSender(req *http.Request) (future InboundSecurityRuleCreateOrUpdateFuture, err error) {
    96  	var resp *http.Response
    97  	future.FutureAPI = &azure.Future{}
    98  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    99  	if err != nil {
   100  		return
   101  	}
   102  	var azf azure.Future
   103  	azf, err = azure.NewFutureFromResponse(resp)
   104  	future.FutureAPI = &azf
   105  	future.Result = future.result
   106  	return
   107  }
   108  
   109  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   110  // closes the http.Response Body.
   111  func (client InboundSecurityRuleClient) CreateOrUpdateResponder(resp *http.Response) (result InboundSecurityRule, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  

View as plain text