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