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/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// FirewallPolicyRuleGroupsClient is the network Client 30type FirewallPolicyRuleGroupsClient struct { 31 BaseClient 32} 33 34// NewFirewallPolicyRuleGroupsClient creates an instance of the FirewallPolicyRuleGroupsClient client. 35func NewFirewallPolicyRuleGroupsClient(subscriptionID string) FirewallPolicyRuleGroupsClient { 36 return NewFirewallPolicyRuleGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewFirewallPolicyRuleGroupsClientWithBaseURI creates an instance of the FirewallPolicyRuleGroupsClient client using 40// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 41// clouds, Azure stack). 42func NewFirewallPolicyRuleGroupsClientWithBaseURI(baseURI string, subscriptionID string) FirewallPolicyRuleGroupsClient { 43 return FirewallPolicyRuleGroupsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// CreateOrUpdate creates or updates the specified FirewallPolicyRuleGroup. 47// Parameters: 48// resourceGroupName - the name of the resource group. 49// firewallPolicyName - the name of the Firewall Policy. 50// ruleGroupName - the name of the FirewallPolicyRuleGroup. 51// parameters - parameters supplied to the create or update FirewallPolicyRuleGroup operation. 52func (client FirewallPolicyRuleGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleGroupName string, parameters FirewallPolicyRuleGroup) (result FirewallPolicyRuleGroupsCreateOrUpdateFuture, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/FirewallPolicyRuleGroupsClient.CreateOrUpdate") 55 defer func() { 56 sc := -1 57 if result.Response() != nil { 58 sc = result.Response().StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: parameters, 65 Constraints: []validation.Constraint{{Target: "parameters.FirewallPolicyRuleGroupProperties", Name: validation.Null, Rule: false, 66 Chain: []validation.Constraint{{Target: "parameters.FirewallPolicyRuleGroupProperties.Priority", Name: validation.Null, Rule: false, 67 Chain: []validation.Constraint{{Target: "parameters.FirewallPolicyRuleGroupProperties.Priority", Name: validation.InclusiveMaximum, Rule: int64(65000), Chain: nil}, 68 {Target: "parameters.FirewallPolicyRuleGroupProperties.Priority", Name: validation.InclusiveMinimum, Rule: int64(100), Chain: nil}, 69 }}, 70 }}}}}); err != nil { 71 return result, validation.NewError("network.FirewallPolicyRuleGroupsClient", "CreateOrUpdate", err.Error()) 72 } 73 74 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, firewallPolicyName, ruleGroupName, parameters) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "CreateOrUpdate", nil, "Failure preparing request") 77 return 78 } 79 80 result, err = client.CreateOrUpdateSender(req) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 83 return 84 } 85 86 return 87} 88 89// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 90func (client FirewallPolicyRuleGroupsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleGroupName string, parameters FirewallPolicyRuleGroup) (*http.Request, error) { 91 pathParameters := map[string]interface{}{ 92 "firewallPolicyName": autorest.Encode("path", firewallPolicyName), 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "ruleGroupName": autorest.Encode("path", ruleGroupName), 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2020-04-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 parameters.Etag = nil 104 parameters.Type = nil 105 preparer := autorest.CreatePreparer( 106 autorest.AsContentType("application/json; charset=utf-8"), 107 autorest.AsPut(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/ruleGroups/{ruleGroupName}", pathParameters), 110 autorest.WithJSON(parameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 116// http.Response Body if it receives an error. 117func (client FirewallPolicyRuleGroupsClient) CreateOrUpdateSender(req *http.Request) (future FirewallPolicyRuleGroupsCreateOrUpdateFuture, err error) { 118 var resp *http.Response 119 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 120 if err != nil { 121 return 122 } 123 future.Future, err = azure.NewFutureFromResponse(resp) 124 return 125} 126 127// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 128// closes the http.Response Body. 129func (client FirewallPolicyRuleGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result FirewallPolicyRuleGroup, err error) { 130 err = autorest.Respond( 131 resp, 132 client.ByInspecting(), 133 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 134 autorest.ByUnmarshallingJSON(&result), 135 autorest.ByClosing()) 136 result.Response = autorest.Response{Response: resp} 137 return 138} 139 140// Delete deletes the specified FirewallPolicyRuleGroup. 141// Parameters: 142// resourceGroupName - the name of the resource group. 143// firewallPolicyName - the name of the Firewall Policy. 144// ruleGroupName - the name of the FirewallPolicyRuleGroup. 145func (client FirewallPolicyRuleGroupsClient) Delete(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleGroupName string) (result FirewallPolicyRuleGroupsDeleteFuture, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/FirewallPolicyRuleGroupsClient.Delete") 148 defer func() { 149 sc := -1 150 if result.Response() != nil { 151 sc = result.Response().StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 req, err := client.DeletePreparer(ctx, resourceGroupName, firewallPolicyName, ruleGroupName) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "Delete", nil, "Failure preparing request") 159 return 160 } 161 162 result, err = client.DeleteSender(req) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "Delete", result.Response(), "Failure sending request") 165 return 166 } 167 168 return 169} 170 171// DeletePreparer prepares the Delete request. 172func (client FirewallPolicyRuleGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleGroupName string) (*http.Request, error) { 173 pathParameters := map[string]interface{}{ 174 "firewallPolicyName": autorest.Encode("path", firewallPolicyName), 175 "resourceGroupName": autorest.Encode("path", resourceGroupName), 176 "ruleGroupName": autorest.Encode("path", ruleGroupName), 177 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 178 } 179 180 const APIVersion = "2020-04-01" 181 queryParameters := map[string]interface{}{ 182 "api-version": APIVersion, 183 } 184 185 preparer := autorest.CreatePreparer( 186 autorest.AsDelete(), 187 autorest.WithBaseURL(client.BaseURI), 188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/ruleGroups/{ruleGroupName}", pathParameters), 189 autorest.WithQueryParameters(queryParameters)) 190 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 191} 192 193// DeleteSender sends the Delete request. The method will close the 194// http.Response Body if it receives an error. 195func (client FirewallPolicyRuleGroupsClient) DeleteSender(req *http.Request) (future FirewallPolicyRuleGroupsDeleteFuture, err error) { 196 var resp *http.Response 197 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 198 if err != nil { 199 return 200 } 201 future.Future, err = azure.NewFutureFromResponse(resp) 202 return 203} 204 205// DeleteResponder handles the response to the Delete request. The method always 206// closes the http.Response Body. 207func (client FirewallPolicyRuleGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 208 err = autorest.Respond( 209 resp, 210 client.ByInspecting(), 211 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 212 autorest.ByClosing()) 213 result.Response = resp 214 return 215} 216 217// Get gets the specified FirewallPolicyRuleGroup. 218// Parameters: 219// resourceGroupName - the name of the resource group. 220// firewallPolicyName - the name of the Firewall Policy. 221// ruleGroupName - the name of the FirewallPolicyRuleGroup. 222func (client FirewallPolicyRuleGroupsClient) Get(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleGroupName string) (result FirewallPolicyRuleGroup, err error) { 223 if tracing.IsEnabled() { 224 ctx = tracing.StartSpan(ctx, fqdn+"/FirewallPolicyRuleGroupsClient.Get") 225 defer func() { 226 sc := -1 227 if result.Response.Response != nil { 228 sc = result.Response.Response.StatusCode 229 } 230 tracing.EndSpan(ctx, sc, err) 231 }() 232 } 233 req, err := client.GetPreparer(ctx, resourceGroupName, firewallPolicyName, ruleGroupName) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "Get", nil, "Failure preparing request") 236 return 237 } 238 239 resp, err := client.GetSender(req) 240 if err != nil { 241 result.Response = autorest.Response{Response: resp} 242 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "Get", resp, "Failure sending request") 243 return 244 } 245 246 result, err = client.GetResponder(resp) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "Get", resp, "Failure responding to request") 249 } 250 251 return 252} 253 254// GetPreparer prepares the Get request. 255func (client FirewallPolicyRuleGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleGroupName string) (*http.Request, error) { 256 pathParameters := map[string]interface{}{ 257 "firewallPolicyName": autorest.Encode("path", firewallPolicyName), 258 "resourceGroupName": autorest.Encode("path", resourceGroupName), 259 "ruleGroupName": autorest.Encode("path", ruleGroupName), 260 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 261 } 262 263 const APIVersion = "2020-04-01" 264 queryParameters := map[string]interface{}{ 265 "api-version": APIVersion, 266 } 267 268 preparer := autorest.CreatePreparer( 269 autorest.AsGet(), 270 autorest.WithBaseURL(client.BaseURI), 271 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/ruleGroups/{ruleGroupName}", pathParameters), 272 autorest.WithQueryParameters(queryParameters)) 273 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 274} 275 276// GetSender sends the Get request. The method will close the 277// http.Response Body if it receives an error. 278func (client FirewallPolicyRuleGroupsClient) GetSender(req *http.Request) (*http.Response, error) { 279 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 280} 281 282// GetResponder handles the response to the Get request. The method always 283// closes the http.Response Body. 284func (client FirewallPolicyRuleGroupsClient) GetResponder(resp *http.Response) (result FirewallPolicyRuleGroup, err error) { 285 err = autorest.Respond( 286 resp, 287 client.ByInspecting(), 288 azure.WithErrorUnlessStatusCode(http.StatusOK), 289 autorest.ByUnmarshallingJSON(&result), 290 autorest.ByClosing()) 291 result.Response = autorest.Response{Response: resp} 292 return 293} 294 295// List lists all FirewallPolicyRuleGroups in a FirewallPolicy resource. 296// Parameters: 297// resourceGroupName - the name of the resource group. 298// firewallPolicyName - the name of the Firewall Policy. 299func (client FirewallPolicyRuleGroupsClient) List(ctx context.Context, resourceGroupName string, firewallPolicyName string) (result FirewallPolicyRuleGroupListResultPage, err error) { 300 if tracing.IsEnabled() { 301 ctx = tracing.StartSpan(ctx, fqdn+"/FirewallPolicyRuleGroupsClient.List") 302 defer func() { 303 sc := -1 304 if result.fprglr.Response.Response != nil { 305 sc = result.fprglr.Response.Response.StatusCode 306 } 307 tracing.EndSpan(ctx, sc, err) 308 }() 309 } 310 result.fn = client.listNextResults 311 req, err := client.ListPreparer(ctx, resourceGroupName, firewallPolicyName) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "List", nil, "Failure preparing request") 314 return 315 } 316 317 resp, err := client.ListSender(req) 318 if err != nil { 319 result.fprglr.Response = autorest.Response{Response: resp} 320 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "List", resp, "Failure sending request") 321 return 322 } 323 324 result.fprglr, err = client.ListResponder(resp) 325 if err != nil { 326 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "List", resp, "Failure responding to request") 327 } 328 329 return 330} 331 332// ListPreparer prepares the List request. 333func (client FirewallPolicyRuleGroupsClient) ListPreparer(ctx context.Context, resourceGroupName string, firewallPolicyName string) (*http.Request, error) { 334 pathParameters := map[string]interface{}{ 335 "firewallPolicyName": autorest.Encode("path", firewallPolicyName), 336 "resourceGroupName": autorest.Encode("path", resourceGroupName), 337 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 338 } 339 340 const APIVersion = "2020-04-01" 341 queryParameters := map[string]interface{}{ 342 "api-version": APIVersion, 343 } 344 345 preparer := autorest.CreatePreparer( 346 autorest.AsGet(), 347 autorest.WithBaseURL(client.BaseURI), 348 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/ruleGroups", pathParameters), 349 autorest.WithQueryParameters(queryParameters)) 350 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 351} 352 353// ListSender sends the List request. The method will close the 354// http.Response Body if it receives an error. 355func (client FirewallPolicyRuleGroupsClient) ListSender(req *http.Request) (*http.Response, error) { 356 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 357} 358 359// ListResponder handles the response to the List request. The method always 360// closes the http.Response Body. 361func (client FirewallPolicyRuleGroupsClient) ListResponder(resp *http.Response) (result FirewallPolicyRuleGroupListResult, err error) { 362 err = autorest.Respond( 363 resp, 364 client.ByInspecting(), 365 azure.WithErrorUnlessStatusCode(http.StatusOK), 366 autorest.ByUnmarshallingJSON(&result), 367 autorest.ByClosing()) 368 result.Response = autorest.Response{Response: resp} 369 return 370} 371 372// listNextResults retrieves the next set of results, if any. 373func (client FirewallPolicyRuleGroupsClient) listNextResults(ctx context.Context, lastResults FirewallPolicyRuleGroupListResult) (result FirewallPolicyRuleGroupListResult, err error) { 374 req, err := lastResults.firewallPolicyRuleGroupListResultPreparer(ctx) 375 if err != nil { 376 return result, autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "listNextResults", nil, "Failure preparing next results request") 377 } 378 if req == nil { 379 return 380 } 381 resp, err := client.ListSender(req) 382 if err != nil { 383 result.Response = autorest.Response{Response: resp} 384 return result, autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "listNextResults", resp, "Failure sending next results request") 385 } 386 result, err = client.ListResponder(resp) 387 if err != nil { 388 err = autorest.NewErrorWithError(err, "network.FirewallPolicyRuleGroupsClient", "listNextResults", resp, "Failure responding to next results request") 389 } 390 return 391} 392 393// ListComplete enumerates all values, automatically crossing page boundaries as required. 394func (client FirewallPolicyRuleGroupsClient) ListComplete(ctx context.Context, resourceGroupName string, firewallPolicyName string) (result FirewallPolicyRuleGroupListResultIterator, err error) { 395 if tracing.IsEnabled() { 396 ctx = tracing.StartSpan(ctx, fqdn+"/FirewallPolicyRuleGroupsClient.List") 397 defer func() { 398 sc := -1 399 if result.Response().Response.Response != nil { 400 sc = result.page.Response().Response.Response.StatusCode 401 } 402 tracing.EndSpan(ctx, sc, err) 403 }() 404 } 405 result.page, err = client.List(ctx, resourceGroupName, firewallPolicyName) 406 return 407} 408