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// DdosCustomPoliciesClient is the network Client
18type DdosCustomPoliciesClient struct {
19	BaseClient
20}
21
22// NewDdosCustomPoliciesClient creates an instance of the DdosCustomPoliciesClient client.
23func NewDdosCustomPoliciesClient(subscriptionID string) DdosCustomPoliciesClient {
24	return NewDdosCustomPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewDdosCustomPoliciesClientWithBaseURI creates an instance of the DdosCustomPoliciesClient 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 NewDdosCustomPoliciesClientWithBaseURI(baseURI string, subscriptionID string) DdosCustomPoliciesClient {
31	return DdosCustomPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or updates a DDoS custom policy.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// ddosCustomPolicyName - the name of the DDoS custom policy.
38// parameters - parameters supplied to the create or update operation.
39func (client DdosCustomPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters DdosCustomPolicy) (result DdosCustomPoliciesCreateOrUpdateFuture, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.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, ddosCustomPolicyName, parameters)
51	if err != nil {
52		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "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.DdosCustomPoliciesClient", "CreateOrUpdate", nil, "Failure sending request")
59		return
60	}
61
62	return
63}
64
65// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
66func (client DdosCustomPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters DdosCustomPolicy) (*http.Request, error) {
67	pathParameters := map[string]interface{}{
68		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
69		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
70		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
71	}
72
73	const APIVersion = "2020-03-01"
74	queryParameters := map[string]interface{}{
75		"api-version": APIVersion,
76	}
77
78	parameters.Etag = nil
79	preparer := autorest.CreatePreparer(
80		autorest.AsContentType("application/json; charset=utf-8"),
81		autorest.AsPut(),
82		autorest.WithBaseURL(client.BaseURI),
83		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
84		autorest.WithJSON(parameters),
85		autorest.WithQueryParameters(queryParameters))
86	return preparer.Prepare((&http.Request{}).WithContext(ctx))
87}
88
89// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
90// http.Response Body if it receives an error.
91func (client DdosCustomPoliciesClient) CreateOrUpdateSender(req *http.Request) (future DdosCustomPoliciesCreateOrUpdateFuture, err error) {
92	var resp *http.Response
93	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
94	if err != nil {
95		return
96	}
97	var azf azure.Future
98	azf, err = azure.NewFutureFromResponse(resp)
99	future.FutureAPI = &azf
100	future.Result = future.result
101	return
102}
103
104// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
105// closes the http.Response Body.
106func (client DdosCustomPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result DdosCustomPolicy, err error) {
107	err = autorest.Respond(
108		resp,
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 custom policy.
117// Parameters:
118// resourceGroupName - the name of the resource group.
119// ddosCustomPolicyName - the name of the DDoS custom policy.
120func (client DdosCustomPoliciesClient) Delete(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (result DdosCustomPoliciesDeleteFuture, err error) {
121	if tracing.IsEnabled() {
122		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.Delete")
123		defer func() {
124			sc := -1
125			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
126				sc = result.FutureAPI.Response().StatusCode
127			}
128			tracing.EndSpan(ctx, sc, err)
129		}()
130	}
131	req, err := client.DeletePreparer(ctx, resourceGroupName, ddosCustomPolicyName)
132	if err != nil {
133		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Delete", nil, "Failure preparing request")
134		return
135	}
136
137	result, err = client.DeleteSender(req)
138	if err != nil {
139		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Delete", nil, "Failure sending request")
140		return
141	}
142
143	return
144}
145
146// DeletePreparer prepares the Delete request.
147func (client DdosCustomPoliciesClient) DeletePreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (*http.Request, error) {
148	pathParameters := map[string]interface{}{
149		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
150		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
151		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
152	}
153
154	const APIVersion = "2020-03-01"
155	queryParameters := map[string]interface{}{
156		"api-version": APIVersion,
157	}
158
159	preparer := autorest.CreatePreparer(
160		autorest.AsDelete(),
161		autorest.WithBaseURL(client.BaseURI),
162		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
163		autorest.WithQueryParameters(queryParameters))
164	return preparer.Prepare((&http.Request{}).WithContext(ctx))
165}
166
167// DeleteSender sends the Delete request. The method will close the
168// http.Response Body if it receives an error.
169func (client DdosCustomPoliciesClient) DeleteSender(req *http.Request) (future DdosCustomPoliciesDeleteFuture, err error) {
170	var resp *http.Response
171	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
172	if err != nil {
173		return
174	}
175	var azf azure.Future
176	azf, err = azure.NewFutureFromResponse(resp)
177	future.FutureAPI = &azf
178	future.Result = future.result
179	return
180}
181
182// DeleteResponder handles the response to the Delete request. The method always
183// closes the http.Response Body.
184func (client DdosCustomPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
185	err = autorest.Respond(
186		resp,
187		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
188		autorest.ByClosing())
189	result.Response = resp
190	return
191}
192
193// Get gets information about the specified DDoS custom policy.
194// Parameters:
195// resourceGroupName - the name of the resource group.
196// ddosCustomPolicyName - the name of the DDoS custom policy.
197func (client DdosCustomPoliciesClient) Get(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (result DdosCustomPolicy, err error) {
198	if tracing.IsEnabled() {
199		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.Get")
200		defer func() {
201			sc := -1
202			if result.Response.Response != nil {
203				sc = result.Response.Response.StatusCode
204			}
205			tracing.EndSpan(ctx, sc, err)
206		}()
207	}
208	req, err := client.GetPreparer(ctx, resourceGroupName, ddosCustomPolicyName)
209	if err != nil {
210		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Get", nil, "Failure preparing request")
211		return
212	}
213
214	resp, err := client.GetSender(req)
215	if err != nil {
216		result.Response = autorest.Response{Response: resp}
217		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Get", resp, "Failure sending request")
218		return
219	}
220
221	result, err = client.GetResponder(resp)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Get", resp, "Failure responding to request")
224		return
225	}
226
227	return
228}
229
230// GetPreparer prepares the Get request.
231func (client DdosCustomPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (*http.Request, error) {
232	pathParameters := map[string]interface{}{
233		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
234		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
235		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
236	}
237
238	const APIVersion = "2020-03-01"
239	queryParameters := map[string]interface{}{
240		"api-version": APIVersion,
241	}
242
243	preparer := autorest.CreatePreparer(
244		autorest.AsGet(),
245		autorest.WithBaseURL(client.BaseURI),
246		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
247		autorest.WithQueryParameters(queryParameters))
248	return preparer.Prepare((&http.Request{}).WithContext(ctx))
249}
250
251// GetSender sends the Get request. The method will close the
252// http.Response Body if it receives an error.
253func (client DdosCustomPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
254	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
255}
256
257// GetResponder handles the response to the Get request. The method always
258// closes the http.Response Body.
259func (client DdosCustomPoliciesClient) GetResponder(resp *http.Response) (result DdosCustomPolicy, err error) {
260	err = autorest.Respond(
261		resp,
262		azure.WithErrorUnlessStatusCode(http.StatusOK),
263		autorest.ByUnmarshallingJSON(&result),
264		autorest.ByClosing())
265	result.Response = autorest.Response{Response: resp}
266	return
267}
268
269// UpdateTags update a DDoS custom policy tags.
270// Parameters:
271// resourceGroupName - the name of the resource group.
272// ddosCustomPolicyName - the name of the DDoS custom policy.
273// parameters - parameters supplied to update DDoS custom policy resource tags.
274func (client DdosCustomPoliciesClient) UpdateTags(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters TagsObject) (result DdosCustomPolicy, err error) {
275	if tracing.IsEnabled() {
276		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.UpdateTags")
277		defer func() {
278			sc := -1
279			if result.Response.Response != nil {
280				sc = result.Response.Response.StatusCode
281			}
282			tracing.EndSpan(ctx, sc, err)
283		}()
284	}
285	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, ddosCustomPolicyName, parameters)
286	if err != nil {
287		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "UpdateTags", nil, "Failure preparing request")
288		return
289	}
290
291	resp, err := client.UpdateTagsSender(req)
292	if err != nil {
293		result.Response = autorest.Response{Response: resp}
294		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "UpdateTags", resp, "Failure sending request")
295		return
296	}
297
298	result, err = client.UpdateTagsResponder(resp)
299	if err != nil {
300		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "UpdateTags", resp, "Failure responding to request")
301		return
302	}
303
304	return
305}
306
307// UpdateTagsPreparer prepares the UpdateTags request.
308func (client DdosCustomPoliciesClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters TagsObject) (*http.Request, error) {
309	pathParameters := map[string]interface{}{
310		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
311		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
312		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
313	}
314
315	const APIVersion = "2020-03-01"
316	queryParameters := map[string]interface{}{
317		"api-version": APIVersion,
318	}
319
320	preparer := autorest.CreatePreparer(
321		autorest.AsContentType("application/json; charset=utf-8"),
322		autorest.AsPatch(),
323		autorest.WithBaseURL(client.BaseURI),
324		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
325		autorest.WithJSON(parameters),
326		autorest.WithQueryParameters(queryParameters))
327	return preparer.Prepare((&http.Request{}).WithContext(ctx))
328}
329
330// UpdateTagsSender sends the UpdateTags request. The method will close the
331// http.Response Body if it receives an error.
332func (client DdosCustomPoliciesClient) UpdateTagsSender(req *http.Request) (*http.Response, error) {
333	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
334}
335
336// UpdateTagsResponder handles the response to the UpdateTags request. The method always
337// closes the http.Response Body.
338func (client DdosCustomPoliciesClient) UpdateTagsResponder(resp *http.Response) (result DdosCustomPolicy, 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