github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/inboundsecurityrule_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // InboundSecurityRuleClient contains the methods for the InboundSecurityRule group. 24 // Don't use this type directly, use NewInboundSecurityRuleClient() instead. 25 type InboundSecurityRuleClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewInboundSecurityRuleClient creates a new instance of InboundSecurityRuleClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewInboundSecurityRuleClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*InboundSecurityRuleClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &InboundSecurityRuleClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates or updates the specified Network Virtual Appliance Inbound Security Rules. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - networkVirtualApplianceName - The name of the Network Virtual Appliance. 53 // - ruleCollectionName - The name of security rule collection. 54 // - parameters - Parameters supplied to the create or update Network Virtual Appliance Inbound Security Rules operation. 55 // - options - InboundSecurityRuleClientBeginCreateOrUpdateOptions contains the optional parameters for the InboundSecurityRuleClient.BeginCreateOrUpdate 56 // method. 57 func (client *InboundSecurityRuleClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters InboundSecurityRule, options *InboundSecurityRuleClientBeginCreateOrUpdateOptions) (*runtime.Poller[InboundSecurityRuleClientCreateOrUpdateResponse], error) { 58 if options == nil || options.ResumeToken == "" { 59 resp, err := client.createOrUpdate(ctx, resourceGroupName, networkVirtualApplianceName, ruleCollectionName, parameters, options) 60 if err != nil { 61 return nil, err 62 } 63 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[InboundSecurityRuleClientCreateOrUpdateResponse]{ 64 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 65 Tracer: client.internal.Tracer(), 66 }) 67 return poller, err 68 } else { 69 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[InboundSecurityRuleClientCreateOrUpdateResponse]{ 70 Tracer: client.internal.Tracer(), 71 }) 72 } 73 } 74 75 // CreateOrUpdate - Creates or updates the specified Network Virtual Appliance Inbound Security Rules. 76 // If the operation fails it returns an *azcore.ResponseError type. 77 // 78 // Generated from API version 2024-05-01 79 func (client *InboundSecurityRuleClient) createOrUpdate(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters InboundSecurityRule, options *InboundSecurityRuleClientBeginCreateOrUpdateOptions) (*http.Response, error) { 80 var err error 81 const operationName = "InboundSecurityRuleClient.BeginCreateOrUpdate" 82 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 83 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 84 defer func() { endSpan(err) }() 85 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, networkVirtualApplianceName, ruleCollectionName, parameters, options) 86 if err != nil { 87 return nil, err 88 } 89 httpResp, err := client.internal.Pipeline().Do(req) 90 if err != nil { 91 return nil, err 92 } 93 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 94 err = runtime.NewResponseError(httpResp) 95 return nil, err 96 } 97 return httpResp, nil 98 } 99 100 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 101 func (client *InboundSecurityRuleClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, parameters InboundSecurityRule, options *InboundSecurityRuleClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 102 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkVirtualAppliances/{networkVirtualApplianceName}/inboundSecurityRules/{ruleCollectionName}" 103 if resourceGroupName == "" { 104 return nil, errors.New("parameter resourceGroupName cannot be empty") 105 } 106 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 107 if networkVirtualApplianceName == "" { 108 return nil, errors.New("parameter networkVirtualApplianceName cannot be empty") 109 } 110 urlPath = strings.ReplaceAll(urlPath, "{networkVirtualApplianceName}", url.PathEscape(networkVirtualApplianceName)) 111 if ruleCollectionName == "" { 112 return nil, errors.New("parameter ruleCollectionName cannot be empty") 113 } 114 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 115 if client.subscriptionID == "" { 116 return nil, errors.New("parameter client.subscriptionID cannot be empty") 117 } 118 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 119 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 120 if err != nil { 121 return nil, err 122 } 123 reqQP := req.Raw().URL.Query() 124 reqQP.Set("api-version", "2024-05-01") 125 req.Raw().URL.RawQuery = reqQP.Encode() 126 req.Raw().Header["Accept"] = []string{"application/json"} 127 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 128 return nil, err 129 } 130 return req, nil 131 } 132 133 // Get - Retrieves the available specified Network Virtual Appliance Inbound Security Rules Collection. 134 // If the operation fails it returns an *azcore.ResponseError type. 135 // 136 // Generated from API version 2024-05-01 137 // - resourceGroupName - The name of the resource group. 138 // - networkVirtualApplianceName - The name of the Network Virtual Appliance. 139 // - ruleCollectionName - The name of security rule collection. 140 // - options - InboundSecurityRuleClientGetOptions contains the optional parameters for the InboundSecurityRuleClient.Get method. 141 func (client *InboundSecurityRuleClient) Get(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, options *InboundSecurityRuleClientGetOptions) (InboundSecurityRuleClientGetResponse, error) { 142 var err error 143 const operationName = "InboundSecurityRuleClient.Get" 144 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 145 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 146 defer func() { endSpan(err) }() 147 req, err := client.getCreateRequest(ctx, resourceGroupName, networkVirtualApplianceName, ruleCollectionName, options) 148 if err != nil { 149 return InboundSecurityRuleClientGetResponse{}, err 150 } 151 httpResp, err := client.internal.Pipeline().Do(req) 152 if err != nil { 153 return InboundSecurityRuleClientGetResponse{}, err 154 } 155 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 156 err = runtime.NewResponseError(httpResp) 157 return InboundSecurityRuleClientGetResponse{}, err 158 } 159 resp, err := client.getHandleResponse(httpResp) 160 return resp, err 161 } 162 163 // getCreateRequest creates the Get request. 164 func (client *InboundSecurityRuleClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, ruleCollectionName string, options *InboundSecurityRuleClientGetOptions) (*policy.Request, error) { 165 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkVirtualAppliances/{networkVirtualApplianceName}/inboundSecurityRules/{ruleCollectionName}" 166 if resourceGroupName == "" { 167 return nil, errors.New("parameter resourceGroupName cannot be empty") 168 } 169 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 170 if networkVirtualApplianceName == "" { 171 return nil, errors.New("parameter networkVirtualApplianceName cannot be empty") 172 } 173 urlPath = strings.ReplaceAll(urlPath, "{networkVirtualApplianceName}", url.PathEscape(networkVirtualApplianceName)) 174 if ruleCollectionName == "" { 175 return nil, errors.New("parameter ruleCollectionName cannot be empty") 176 } 177 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 178 if client.subscriptionID == "" { 179 return nil, errors.New("parameter client.subscriptionID cannot be empty") 180 } 181 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 182 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 183 if err != nil { 184 return nil, err 185 } 186 reqQP := req.Raw().URL.Query() 187 reqQP.Set("api-version", "2024-05-01") 188 req.Raw().URL.RawQuery = reqQP.Encode() 189 req.Raw().Header["Accept"] = []string{"application/json"} 190 return req, nil 191 } 192 193 // getHandleResponse handles the Get response. 194 func (client *InboundSecurityRuleClient) getHandleResponse(resp *http.Response) (InboundSecurityRuleClientGetResponse, error) { 195 result := InboundSecurityRuleClientGetResponse{} 196 if err := runtime.UnmarshalAsJSON(resp, &result.InboundSecurityRule); err != nil { 197 return InboundSecurityRuleClientGetResponse{}, err 198 } 199 return result, nil 200 }