1package network 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// DefaultSecurityRulesClient is the network Client 29type DefaultSecurityRulesClient struct { 30 BaseClient 31} 32 33// NewDefaultSecurityRulesClient creates an instance of the DefaultSecurityRulesClient client. 34func NewDefaultSecurityRulesClient(subscriptionID string) DefaultSecurityRulesClient { 35 return NewDefaultSecurityRulesClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewDefaultSecurityRulesClientWithBaseURI creates an instance of the DefaultSecurityRulesClient client. 39func NewDefaultSecurityRulesClientWithBaseURI(baseURI string, subscriptionID string) DefaultSecurityRulesClient { 40 return DefaultSecurityRulesClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// Get get the specified default network security rule. 44// Parameters: 45// resourceGroupName - the name of the resource group. 46// networkSecurityGroupName - the name of the network security group. 47// defaultSecurityRuleName - the name of the default security rule. 48func (client DefaultSecurityRulesClient) Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, defaultSecurityRuleName string) (result SecurityRule, err error) { 49 if tracing.IsEnabled() { 50 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultSecurityRulesClient.Get") 51 defer func() { 52 sc := -1 53 if result.Response.Response != nil { 54 sc = result.Response.Response.StatusCode 55 } 56 tracing.EndSpan(ctx, sc, err) 57 }() 58 } 59 req, err := client.GetPreparer(ctx, resourceGroupName, networkSecurityGroupName, defaultSecurityRuleName) 60 if err != nil { 61 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "Get", nil, "Failure preparing request") 62 return 63 } 64 65 resp, err := client.GetSender(req) 66 if err != nil { 67 result.Response = autorest.Response{Response: resp} 68 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "Get", resp, "Failure sending request") 69 return 70 } 71 72 result, err = client.GetResponder(resp) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "Get", resp, "Failure responding to request") 75 } 76 77 return 78} 79 80// GetPreparer prepares the Get request. 81func (client DefaultSecurityRulesClient) GetPreparer(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, defaultSecurityRuleName string) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "defaultSecurityRuleName": autorest.Encode("path", defaultSecurityRuleName), 84 "networkSecurityGroupName": autorest.Encode("path", networkSecurityGroupName), 85 "resourceGroupName": autorest.Encode("path", resourceGroupName), 86 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 87 } 88 89 const APIVersion = "2018-10-01" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsGet(), 96 autorest.WithBaseURL(client.BaseURI), 97 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{networkSecurityGroupName}/defaultSecurityRules/{defaultSecurityRuleName}", pathParameters), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// GetSender sends the Get request. The method will close the 103// http.Response Body if it receives an error. 104func (client DefaultSecurityRulesClient) GetSender(req *http.Request) (*http.Response, error) { 105 return autorest.SendWithSender(client, req, 106 azure.DoRetryWithRegistration(client.Client)) 107} 108 109// GetResponder handles the response to the Get request. The method always 110// closes the http.Response Body. 111func (client DefaultSecurityRulesClient) GetResponder(resp *http.Response) (result SecurityRule, err error) { 112 err = autorest.Respond( 113 resp, 114 client.ByInspecting(), 115 azure.WithErrorUnlessStatusCode(http.StatusOK), 116 autorest.ByUnmarshallingJSON(&result), 117 autorest.ByClosing()) 118 result.Response = autorest.Response{Response: resp} 119 return 120} 121 122// List gets all default security rules in a network security group. 123// Parameters: 124// resourceGroupName - the name of the resource group. 125// networkSecurityGroupName - the name of the network security group. 126func (client DefaultSecurityRulesClient) List(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) (result SecurityRuleListResultPage, err error) { 127 if tracing.IsEnabled() { 128 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultSecurityRulesClient.List") 129 defer func() { 130 sc := -1 131 if result.srlr.Response.Response != nil { 132 sc = result.srlr.Response.Response.StatusCode 133 } 134 tracing.EndSpan(ctx, sc, err) 135 }() 136 } 137 result.fn = client.listNextResults 138 req, err := client.ListPreparer(ctx, resourceGroupName, networkSecurityGroupName) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "List", nil, "Failure preparing request") 141 return 142 } 143 144 resp, err := client.ListSender(req) 145 if err != nil { 146 result.srlr.Response = autorest.Response{Response: resp} 147 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "List", resp, "Failure sending request") 148 return 149 } 150 151 result.srlr, err = client.ListResponder(resp) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "List", resp, "Failure responding to request") 154 } 155 156 return 157} 158 159// ListPreparer prepares the List request. 160func (client DefaultSecurityRulesClient) ListPreparer(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) (*http.Request, error) { 161 pathParameters := map[string]interface{}{ 162 "networkSecurityGroupName": autorest.Encode("path", networkSecurityGroupName), 163 "resourceGroupName": autorest.Encode("path", resourceGroupName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 } 166 167 const APIVersion = "2018-10-01" 168 queryParameters := map[string]interface{}{ 169 "api-version": APIVersion, 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsGet(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{networkSecurityGroupName}/defaultSecurityRules", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// ListSender sends the List request. The method will close the 181// http.Response Body if it receives an error. 182func (client DefaultSecurityRulesClient) ListSender(req *http.Request) (*http.Response, error) { 183 return autorest.SendWithSender(client, req, 184 azure.DoRetryWithRegistration(client.Client)) 185} 186 187// ListResponder handles the response to the List request. The method always 188// closes the http.Response Body. 189func (client DefaultSecurityRulesClient) ListResponder(resp *http.Response) (result SecurityRuleListResult, err error) { 190 err = autorest.Respond( 191 resp, 192 client.ByInspecting(), 193 azure.WithErrorUnlessStatusCode(http.StatusOK), 194 autorest.ByUnmarshallingJSON(&result), 195 autorest.ByClosing()) 196 result.Response = autorest.Response{Response: resp} 197 return 198} 199 200// listNextResults retrieves the next set of results, if any. 201func (client DefaultSecurityRulesClient) listNextResults(ctx context.Context, lastResults SecurityRuleListResult) (result SecurityRuleListResult, err error) { 202 req, err := lastResults.securityRuleListResultPreparer(ctx) 203 if err != nil { 204 return result, autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "listNextResults", nil, "Failure preparing next results request") 205 } 206 if req == nil { 207 return 208 } 209 resp, err := client.ListSender(req) 210 if err != nil { 211 result.Response = autorest.Response{Response: resp} 212 return result, autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "listNextResults", resp, "Failure sending next results request") 213 } 214 result, err = client.ListResponder(resp) 215 if err != nil { 216 err = autorest.NewErrorWithError(err, "network.DefaultSecurityRulesClient", "listNextResults", resp, "Failure responding to next results request") 217 } 218 return 219} 220 221// ListComplete enumerates all values, automatically crossing page boundaries as required. 222func (client DefaultSecurityRulesClient) ListComplete(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) (result SecurityRuleListResultIterator, err error) { 223 if tracing.IsEnabled() { 224 ctx = tracing.StartSpan(ctx, fqdn+"/DefaultSecurityRulesClient.List") 225 defer func() { 226 sc := -1 227 if result.Response().Response.Response != nil { 228 sc = result.page.Response().Response.Response.StatusCode 229 } 230 tracing.EndSpan(ctx, sc, err) 231 }() 232 } 233 result.page, err = client.List(ctx, resourceGroupName, networkSecurityGroupName) 234 return 235} 236