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