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