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/tracing" 14 "net/http" 15) 16 17// InboundSecurityRuleClient is the network Client 18type InboundSecurityRuleClient struct { 19 BaseClient 20} 21 22// NewInboundSecurityRuleClient creates an instance of the InboundSecurityRuleClient client. 23func 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). 30func 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. 41func (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", nil, "Failure sending request") 61 return 62 } 63 64 return 65} 66 67// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 68func (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 = "2020-06-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. 95func (client InboundSecurityRuleClient) CreateOrUpdateSender(req *http.Request) (future InboundSecurityRuleCreateOrUpdateFuture, err error) { 96 var resp *http.Response 97 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 98 if err != nil { 99 return 100 } 101 var azf azure.Future 102 azf, err = azure.NewFutureFromResponse(resp) 103 future.FutureAPI = &azf 104 future.Result = future.result 105 return 106} 107 108// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 109// closes the http.Response Body. 110func (client InboundSecurityRuleClient) CreateOrUpdateResponder(resp *http.Response) (result InboundSecurityRule, err error) { 111 err = autorest.Respond( 112 resp, 113 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 114 autorest.ByUnmarshallingJSON(&result), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119