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