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// DefaultSecurityRulesClient is the network Client 18type DefaultSecurityRulesClient struct { 19 BaseClient 20} 21 22// NewDefaultSecurityRulesClient creates an instance of the DefaultSecurityRulesClient client. 23func NewDefaultSecurityRulesClient(subscriptionID string) DefaultSecurityRulesClient { 24 return NewDefaultSecurityRulesClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewDefaultSecurityRulesClientWithBaseURI creates an instance of the DefaultSecurityRulesClient 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 NewDefaultSecurityRulesClientWithBaseURI(baseURI string, subscriptionID string) DefaultSecurityRulesClient { 31 return DefaultSecurityRulesClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// Get get the specified default network security rule. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// networkSecurityGroupName - the name of the network security group. 38// defaultSecurityRuleName - the name of the default security rule. 39func (client DefaultSecurityRulesClient) Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, defaultSecurityRuleName string) (result SecurityRule, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultSecurityRulesClient.Get") 42 defer func() { 43 sc := -1 44 if result.Response.Response != nil { 45 sc = result.Response.Response.StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 req, err := client.GetPreparer(ctx, resourceGroupName, networkSecurityGroupName, defaultSecurityRuleName) 51 if err != nil { 52 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "Get", nil, "Failure preparing request") 53 return 54 } 55 56 resp, err := client.GetSender(req) 57 if err != nil { 58 result.Response = autorest.Response{Response: resp} 59 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "Get", resp, "Failure sending request") 60 return 61 } 62 63 result, err = client.GetResponder(resp) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "Get", resp, "Failure responding to request") 66 return 67 } 68 69 return 70} 71 72// GetPreparer prepares the Get request. 73func (client DefaultSecurityRulesClient) GetPreparer(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, defaultSecurityRuleName string) (*http.Request, error) { 74 pathParameters := map[string]interface{}{ 75 "defaultSecurityRuleName": autorest.Encode("path", defaultSecurityRuleName), 76 "networkSecurityGroupName": autorest.Encode("path", networkSecurityGroupName), 77 "resourceGroupName": autorest.Encode("path", resourceGroupName), 78 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 79 } 80 81 const APIVersion = "2019-04-01" 82 queryParameters := map[string]interface{}{ 83 "api-version": APIVersion, 84 } 85 86 preparer := autorest.CreatePreparer( 87 autorest.AsGet(), 88 autorest.WithBaseURL(client.BaseURI), 89 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{networkSecurityGroupName}/defaultSecurityRules/{defaultSecurityRuleName}", pathParameters), 90 autorest.WithQueryParameters(queryParameters)) 91 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 92} 93 94// GetSender sends the Get request. The method will close the 95// http.Response Body if it receives an error. 96func (client DefaultSecurityRulesClient) GetSender(req *http.Request) (*http.Response, error) { 97 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 98} 99 100// GetResponder handles the response to the Get request. The method always 101// closes the http.Response Body. 102func (client DefaultSecurityRulesClient) GetResponder(resp *http.Response) (result SecurityRule, err error) { 103 err = autorest.Respond( 104 resp, 105 azure.WithErrorUnlessStatusCode(http.StatusOK), 106 autorest.ByUnmarshallingJSON(&result), 107 autorest.ByClosing()) 108 result.Response = autorest.Response{Response: resp} 109 return 110} 111 112// List gets all default security rules in a network security group. 113// Parameters: 114// resourceGroupName - the name of the resource group. 115// networkSecurityGroupName - the name of the network security group. 116func (client DefaultSecurityRulesClient) List(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) (result SecurityRuleListResultPage, err error) { 117 if tracing.IsEnabled() { 118 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultSecurityRulesClient.List") 119 defer func() { 120 sc := -1 121 if result.srlr.Response.Response != nil { 122 sc = result.srlr.Response.Response.StatusCode 123 } 124 tracing.EndSpan(ctx, sc, err) 125 }() 126 } 127 result.fn = client.listNextResults 128 req, err := client.ListPreparer(ctx, resourceGroupName, networkSecurityGroupName) 129 if err != nil { 130 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "List", nil, "Failure preparing request") 131 return 132 } 133 134 resp, err := client.ListSender(req) 135 if err != nil { 136 result.srlr.Response = autorest.Response{Response: resp} 137 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "List", resp, "Failure sending request") 138 return 139 } 140 141 result.srlr, err = client.ListResponder(resp) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "List", resp, "Failure responding to request") 144 return 145 } 146 if result.srlr.hasNextLink() && result.srlr.IsEmpty() { 147 err = result.NextWithContext(ctx) 148 return 149 } 150 151 return 152} 153 154// ListPreparer prepares the List request. 155func (client DefaultSecurityRulesClient) ListPreparer(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) (*http.Request, error) { 156 pathParameters := map[string]interface{}{ 157 "networkSecurityGroupName": autorest.Encode("path", networkSecurityGroupName), 158 "resourceGroupName": autorest.Encode("path", resourceGroupName), 159 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 160 } 161 162 const APIVersion = "2019-04-01" 163 queryParameters := map[string]interface{}{ 164 "api-version": APIVersion, 165 } 166 167 preparer := autorest.CreatePreparer( 168 autorest.AsGet(), 169 autorest.WithBaseURL(client.BaseURI), 170 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{networkSecurityGroupName}/defaultSecurityRules", pathParameters), 171 autorest.WithQueryParameters(queryParameters)) 172 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 173} 174 175// ListSender sends the List request. The method will close the 176// http.Response Body if it receives an error. 177func (client DefaultSecurityRulesClient) ListSender(req *http.Request) (*http.Response, error) { 178 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 179} 180 181// ListResponder handles the response to the List request. The method always 182// closes the http.Response Body. 183func (client DefaultSecurityRulesClient) ListResponder(resp *http.Response) (result SecurityRuleListResult, err error) { 184 err = autorest.Respond( 185 resp, 186 azure.WithErrorUnlessStatusCode(http.StatusOK), 187 autorest.ByUnmarshallingJSON(&result), 188 autorest.ByClosing()) 189 result.Response = autorest.Response{Response: resp} 190 return 191} 192 193// listNextResults retrieves the next set of results, if any. 194func (client DefaultSecurityRulesClient) listNextResults(ctx context.Context, lastResults SecurityRuleListResult) (result SecurityRuleListResult, err error) { 195 req, err := lastResults.securityRuleListResultPreparer(ctx) 196 if err != nil { 197 return result, autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "listNextResults", nil, "Failure preparing next results request") 198 } 199 if req == nil { 200 return 201 } 202 resp, err := client.ListSender(req) 203 if err != nil { 204 result.Response = autorest.Response{Response: resp} 205 return result, autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "listNextResults", resp, "Failure sending next results request") 206 } 207 result, err = client.ListResponder(resp) 208 if err != nil { 209 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "listNextResults", resp, "Failure responding to next results request") 210 } 211 return 212} 213 214// ListComplete enumerates all values, automatically crossing page boundaries as required. 215func (client DefaultSecurityRulesClient) ListComplete(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) (result SecurityRuleListResultIterator, err error) { 216 if tracing.IsEnabled() { 217 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultSecurityRulesClient.List") 218 defer func() { 219 sc := -1 220 if result.Response().Response.Response != nil { 221 sc = result.page.Response().Response.Response.StatusCode 222 } 223 tracing.EndSpan(ctx, sc, err) 224 }() 225 } 226 result.page, err = client.List(ctx, resourceGroupName, networkSecurityGroupName) 227 return 228} 229