1package cdn
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// ProfilesClient is the cdn Management Client
30type ProfilesClient struct {
31	BaseClient
32}
33
34// NewProfilesClient creates an instance of the ProfilesClient client.
35func NewProfilesClient(subscriptionID string, subscriptionID1 string) ProfilesClient {
36	return NewProfilesClientWithBaseURI(DefaultBaseURI, subscriptionID, subscriptionID1)
37}
38
39// NewProfilesClientWithBaseURI creates an instance of the ProfilesClient client using a custom endpoint.  Use this
40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewProfilesClientWithBaseURI(baseURI string, subscriptionID string, subscriptionID1 string) ProfilesClient {
42	return ProfilesClient{NewWithBaseURI(baseURI, subscriptionID, subscriptionID1)}
43}
44
45// Create creates a new CDN profile with a profile name under the specified subscription and resource group.
46// Parameters:
47// resourceGroupName - name of the Resource group within the Azure subscription.
48// profileName - name of the CDN profile which is unique within the resource group.
49// profile - profile properties needed to create a new profile.
50func (client ProfilesClient) Create(ctx context.Context, resourceGroupName string, profileName string, profile Profile) (result ProfilesCreateFuture, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.Create")
53		defer func() {
54			sc := -1
55			if result.Response() != nil {
56				sc = result.Response().StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: resourceGroupName,
63			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
64				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
65				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
66		{TargetValue: profile,
67			Constraints: []validation.Constraint{{Target: "profile.Sku", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
68		return result, validation.NewError("cdn.ProfilesClient", "Create", err.Error())
69	}
70
71	req, err := client.CreatePreparer(ctx, resourceGroupName, profileName, profile)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Create", nil, "Failure preparing request")
74		return
75	}
76
77	result, err = client.CreateSender(req)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Create", result.Response(), "Failure sending request")
80		return
81	}
82
83	return
84}
85
86// CreatePreparer prepares the Create request.
87func (client ProfilesClient) CreatePreparer(ctx context.Context, resourceGroupName string, profileName string, profile Profile) (*http.Request, error) {
88	pathParameters := map[string]interface{}{
89		"profileName":       autorest.Encode("path", profileName),
90		"resourceGroupName": autorest.Encode("path", resourceGroupName),
91		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
92	}
93
94	const APIVersion = "2019-06-15"
95	queryParameters := map[string]interface{}{
96		"api-version": APIVersion,
97	}
98
99	preparer := autorest.CreatePreparer(
100		autorest.AsContentType("application/json; charset=utf-8"),
101		autorest.AsPut(),
102		autorest.WithBaseURL(client.BaseURI),
103		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}", pathParameters),
104		autorest.WithJSON(profile),
105		autorest.WithQueryParameters(queryParameters))
106	return preparer.Prepare((&http.Request{}).WithContext(ctx))
107}
108
109// CreateSender sends the Create request. The method will close the
110// http.Response Body if it receives an error.
111func (client ProfilesClient) CreateSender(req *http.Request) (future ProfilesCreateFuture, err error) {
112	var resp *http.Response
113	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
114	if err != nil {
115		return
116	}
117	future.Future, err = azure.NewFutureFromResponse(resp)
118	return
119}
120
121// CreateResponder handles the response to the Create request. The method always
122// closes the http.Response Body.
123func (client ProfilesClient) CreateResponder(resp *http.Response) (result Profile, err error) {
124	err = autorest.Respond(
125		resp,
126		client.ByInspecting(),
127		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
128		autorest.ByUnmarshallingJSON(&result),
129		autorest.ByClosing())
130	result.Response = autorest.Response{Response: resp}
131	return
132}
133
134// Delete deletes an existing CDN profile with the specified parameters. Deleting a profile will result in the deletion
135// of all of the sub-resources including endpoints, origins and custom domains.
136// Parameters:
137// resourceGroupName - name of the Resource group within the Azure subscription.
138// profileName - name of the CDN profile which is unique within the resource group.
139func (client ProfilesClient) Delete(ctx context.Context, resourceGroupName string, profileName string) (result ProfilesDeleteFuture, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.Delete")
142		defer func() {
143			sc := -1
144			if result.Response() != nil {
145				sc = result.Response().StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	if err := validation.Validate([]validation.Validation{
151		{TargetValue: resourceGroupName,
152			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
153				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
154				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
155		return result, validation.NewError("cdn.ProfilesClient", "Delete", err.Error())
156	}
157
158	req, err := client.DeletePreparer(ctx, resourceGroupName, profileName)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Delete", nil, "Failure preparing request")
161		return
162	}
163
164	result, err = client.DeleteSender(req)
165	if err != nil {
166		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Delete", result.Response(), "Failure sending request")
167		return
168	}
169
170	return
171}
172
173// DeletePreparer prepares the Delete request.
174func (client ProfilesClient) DeletePreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
175	pathParameters := map[string]interface{}{
176		"profileName":       autorest.Encode("path", profileName),
177		"resourceGroupName": autorest.Encode("path", resourceGroupName),
178		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
179	}
180
181	const APIVersion = "2019-06-15"
182	queryParameters := map[string]interface{}{
183		"api-version": APIVersion,
184	}
185
186	preparer := autorest.CreatePreparer(
187		autorest.AsDelete(),
188		autorest.WithBaseURL(client.BaseURI),
189		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}", pathParameters),
190		autorest.WithQueryParameters(queryParameters))
191	return preparer.Prepare((&http.Request{}).WithContext(ctx))
192}
193
194// DeleteSender sends the Delete request. The method will close the
195// http.Response Body if it receives an error.
196func (client ProfilesClient) DeleteSender(req *http.Request) (future ProfilesDeleteFuture, err error) {
197	var resp *http.Response
198	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
199	if err != nil {
200		return
201	}
202	future.Future, err = azure.NewFutureFromResponse(resp)
203	return
204}
205
206// DeleteResponder handles the response to the Delete request. The method always
207// closes the http.Response Body.
208func (client ProfilesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
209	err = autorest.Respond(
210		resp,
211		client.ByInspecting(),
212		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
213		autorest.ByClosing())
214	result.Response = resp
215	return
216}
217
218// GenerateSsoURI generates a dynamic SSO URI used to sign in to the CDN supplemental portal. Supplemental portal is
219// used to configure advanced feature capabilities that are not yet available in the Azure portal, such as core reports
220// in a standard profile; rules engine, advanced HTTP reports, and real-time stats and alerts in a premium profile. The
221// SSO URI changes approximately every 10 minutes.
222// Parameters:
223// resourceGroupName - name of the Resource group within the Azure subscription.
224// profileName - name of the CDN profile which is unique within the resource group.
225func (client ProfilesClient) GenerateSsoURI(ctx context.Context, resourceGroupName string, profileName string) (result SsoURI, err error) {
226	if tracing.IsEnabled() {
227		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.GenerateSsoURI")
228		defer func() {
229			sc := -1
230			if result.Response.Response != nil {
231				sc = result.Response.Response.StatusCode
232			}
233			tracing.EndSpan(ctx, sc, err)
234		}()
235	}
236	if err := validation.Validate([]validation.Validation{
237		{TargetValue: resourceGroupName,
238			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
239				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
240				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
241		return result, validation.NewError("cdn.ProfilesClient", "GenerateSsoURI", err.Error())
242	}
243
244	req, err := client.GenerateSsoURIPreparer(ctx, resourceGroupName, profileName)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "GenerateSsoURI", nil, "Failure preparing request")
247		return
248	}
249
250	resp, err := client.GenerateSsoURISender(req)
251	if err != nil {
252		result.Response = autorest.Response{Response: resp}
253		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "GenerateSsoURI", resp, "Failure sending request")
254		return
255	}
256
257	result, err = client.GenerateSsoURIResponder(resp)
258	if err != nil {
259		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "GenerateSsoURI", resp, "Failure responding to request")
260	}
261
262	return
263}
264
265// GenerateSsoURIPreparer prepares the GenerateSsoURI request.
266func (client ProfilesClient) GenerateSsoURIPreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
267	pathParameters := map[string]interface{}{
268		"profileName":       autorest.Encode("path", profileName),
269		"resourceGroupName": autorest.Encode("path", resourceGroupName),
270		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
271	}
272
273	const APIVersion = "2019-06-15"
274	queryParameters := map[string]interface{}{
275		"api-version": APIVersion,
276	}
277
278	preparer := autorest.CreatePreparer(
279		autorest.AsPost(),
280		autorest.WithBaseURL(client.BaseURI),
281		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/generateSsoUri", pathParameters),
282		autorest.WithQueryParameters(queryParameters))
283	return preparer.Prepare((&http.Request{}).WithContext(ctx))
284}
285
286// GenerateSsoURISender sends the GenerateSsoURI request. The method will close the
287// http.Response Body if it receives an error.
288func (client ProfilesClient) GenerateSsoURISender(req *http.Request) (*http.Response, error) {
289	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
290}
291
292// GenerateSsoURIResponder handles the response to the GenerateSsoURI request. The method always
293// closes the http.Response Body.
294func (client ProfilesClient) GenerateSsoURIResponder(resp *http.Response) (result SsoURI, err error) {
295	err = autorest.Respond(
296		resp,
297		client.ByInspecting(),
298		azure.WithErrorUnlessStatusCode(http.StatusOK),
299		autorest.ByUnmarshallingJSON(&result),
300		autorest.ByClosing())
301	result.Response = autorest.Response{Response: resp}
302	return
303}
304
305// Get gets a CDN profile with the specified profile name under the specified subscription and resource group.
306// Parameters:
307// resourceGroupName - name of the Resource group within the Azure subscription.
308// profileName - name of the CDN profile which is unique within the resource group.
309func (client ProfilesClient) Get(ctx context.Context, resourceGroupName string, profileName string) (result Profile, err error) {
310	if tracing.IsEnabled() {
311		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.Get")
312		defer func() {
313			sc := -1
314			if result.Response.Response != nil {
315				sc = result.Response.Response.StatusCode
316			}
317			tracing.EndSpan(ctx, sc, err)
318		}()
319	}
320	if err := validation.Validate([]validation.Validation{
321		{TargetValue: resourceGroupName,
322			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
323				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
324				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
325		return result, validation.NewError("cdn.ProfilesClient", "Get", err.Error())
326	}
327
328	req, err := client.GetPreparer(ctx, resourceGroupName, profileName)
329	if err != nil {
330		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Get", nil, "Failure preparing request")
331		return
332	}
333
334	resp, err := client.GetSender(req)
335	if err != nil {
336		result.Response = autorest.Response{Response: resp}
337		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Get", resp, "Failure sending request")
338		return
339	}
340
341	result, err = client.GetResponder(resp)
342	if err != nil {
343		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Get", resp, "Failure responding to request")
344	}
345
346	return
347}
348
349// GetPreparer prepares the Get request.
350func (client ProfilesClient) GetPreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
351	pathParameters := map[string]interface{}{
352		"profileName":       autorest.Encode("path", profileName),
353		"resourceGroupName": autorest.Encode("path", resourceGroupName),
354		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
355	}
356
357	const APIVersion = "2019-06-15"
358	queryParameters := map[string]interface{}{
359		"api-version": APIVersion,
360	}
361
362	preparer := autorest.CreatePreparer(
363		autorest.AsGet(),
364		autorest.WithBaseURL(client.BaseURI),
365		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}", pathParameters),
366		autorest.WithQueryParameters(queryParameters))
367	return preparer.Prepare((&http.Request{}).WithContext(ctx))
368}
369
370// GetSender sends the Get request. The method will close the
371// http.Response Body if it receives an error.
372func (client ProfilesClient) GetSender(req *http.Request) (*http.Response, error) {
373	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
374}
375
376// GetResponder handles the response to the Get request. The method always
377// closes the http.Response Body.
378func (client ProfilesClient) GetResponder(resp *http.Response) (result Profile, err error) {
379	err = autorest.Respond(
380		resp,
381		client.ByInspecting(),
382		azure.WithErrorUnlessStatusCode(http.StatusOK),
383		autorest.ByUnmarshallingJSON(&result),
384		autorest.ByClosing())
385	result.Response = autorest.Response{Response: resp}
386	return
387}
388
389// List lists all of the CDN profiles within an Azure subscription.
390func (client ProfilesClient) List(ctx context.Context) (result ProfileListResultPage, err error) {
391	if tracing.IsEnabled() {
392		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.List")
393		defer func() {
394			sc := -1
395			if result.plr.Response.Response != nil {
396				sc = result.plr.Response.Response.StatusCode
397			}
398			tracing.EndSpan(ctx, sc, err)
399		}()
400	}
401	result.fn = client.listNextResults
402	req, err := client.ListPreparer(ctx)
403	if err != nil {
404		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "List", nil, "Failure preparing request")
405		return
406	}
407
408	resp, err := client.ListSender(req)
409	if err != nil {
410		result.plr.Response = autorest.Response{Response: resp}
411		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "List", resp, "Failure sending request")
412		return
413	}
414
415	result.plr, err = client.ListResponder(resp)
416	if err != nil {
417		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "List", resp, "Failure responding to request")
418	}
419
420	return
421}
422
423// ListPreparer prepares the List request.
424func (client ProfilesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
425	pathParameters := map[string]interface{}{
426		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
427	}
428
429	const APIVersion = "2019-06-15"
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}/providers/Microsoft.Cdn/profiles", pathParameters),
438		autorest.WithQueryParameters(queryParameters))
439	return preparer.Prepare((&http.Request{}).WithContext(ctx))
440}
441
442// ListSender sends the List request. The method will close the
443// http.Response Body if it receives an error.
444func (client ProfilesClient) ListSender(req *http.Request) (*http.Response, error) {
445	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
446}
447
448// ListResponder handles the response to the List request. The method always
449// closes the http.Response Body.
450func (client ProfilesClient) ListResponder(resp *http.Response) (result ProfileListResult, err error) {
451	err = autorest.Respond(
452		resp,
453		client.ByInspecting(),
454		azure.WithErrorUnlessStatusCode(http.StatusOK),
455		autorest.ByUnmarshallingJSON(&result),
456		autorest.ByClosing())
457	result.Response = autorest.Response{Response: resp}
458	return
459}
460
461// listNextResults retrieves the next set of results, if any.
462func (client ProfilesClient) listNextResults(ctx context.Context, lastResults ProfileListResult) (result ProfileListResult, err error) {
463	req, err := lastResults.profileListResultPreparer(ctx)
464	if err != nil {
465		return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listNextResults", nil, "Failure preparing next results request")
466	}
467	if req == nil {
468		return
469	}
470	resp, err := client.ListSender(req)
471	if err != nil {
472		result.Response = autorest.Response{Response: resp}
473		return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listNextResults", resp, "Failure sending next results request")
474	}
475	result, err = client.ListResponder(resp)
476	if err != nil {
477		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listNextResults", resp, "Failure responding to next results request")
478	}
479	return
480}
481
482// ListComplete enumerates all values, automatically crossing page boundaries as required.
483func (client ProfilesClient) ListComplete(ctx context.Context) (result ProfileListResultIterator, err error) {
484	if tracing.IsEnabled() {
485		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.List")
486		defer func() {
487			sc := -1
488			if result.Response().Response.Response != nil {
489				sc = result.page.Response().Response.Response.StatusCode
490			}
491			tracing.EndSpan(ctx, sc, err)
492		}()
493	}
494	result.page, err = client.List(ctx)
495	return
496}
497
498// ListByResourceGroup lists all of the CDN profiles within a resource group.
499// Parameters:
500// resourceGroupName - name of the Resource group within the Azure subscription.
501func (client ProfilesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ProfileListResultPage, err error) {
502	if tracing.IsEnabled() {
503		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListByResourceGroup")
504		defer func() {
505			sc := -1
506			if result.plr.Response.Response != nil {
507				sc = result.plr.Response.Response.StatusCode
508			}
509			tracing.EndSpan(ctx, sc, err)
510		}()
511	}
512	if err := validation.Validate([]validation.Validation{
513		{TargetValue: resourceGroupName,
514			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
515				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
516				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
517		return result, validation.NewError("cdn.ProfilesClient", "ListByResourceGroup", err.Error())
518	}
519
520	result.fn = client.listByResourceGroupNextResults
521	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
522	if err != nil {
523		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListByResourceGroup", nil, "Failure preparing request")
524		return
525	}
526
527	resp, err := client.ListByResourceGroupSender(req)
528	if err != nil {
529		result.plr.Response = autorest.Response{Response: resp}
530		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListByResourceGroup", resp, "Failure sending request")
531		return
532	}
533
534	result.plr, err = client.ListByResourceGroupResponder(resp)
535	if err != nil {
536		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListByResourceGroup", resp, "Failure responding to request")
537	}
538
539	return
540}
541
542// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
543func (client ProfilesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
544	pathParameters := map[string]interface{}{
545		"resourceGroupName": autorest.Encode("path", resourceGroupName),
546		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
547	}
548
549	const APIVersion = "2019-06-15"
550	queryParameters := map[string]interface{}{
551		"api-version": APIVersion,
552	}
553
554	preparer := autorest.CreatePreparer(
555		autorest.AsGet(),
556		autorest.WithBaseURL(client.BaseURI),
557		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles", pathParameters),
558		autorest.WithQueryParameters(queryParameters))
559	return preparer.Prepare((&http.Request{}).WithContext(ctx))
560}
561
562// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
563// http.Response Body if it receives an error.
564func (client ProfilesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
565	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
566}
567
568// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
569// closes the http.Response Body.
570func (client ProfilesClient) ListByResourceGroupResponder(resp *http.Response) (result ProfileListResult, err error) {
571	err = autorest.Respond(
572		resp,
573		client.ByInspecting(),
574		azure.WithErrorUnlessStatusCode(http.StatusOK),
575		autorest.ByUnmarshallingJSON(&result),
576		autorest.ByClosing())
577	result.Response = autorest.Response{Response: resp}
578	return
579}
580
581// listByResourceGroupNextResults retrieves the next set of results, if any.
582func (client ProfilesClient) listByResourceGroupNextResults(ctx context.Context, lastResults ProfileListResult) (result ProfileListResult, err error) {
583	req, err := lastResults.profileListResultPreparer(ctx)
584	if err != nil {
585		return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
586	}
587	if req == nil {
588		return
589	}
590	resp, err := client.ListByResourceGroupSender(req)
591	if err != nil {
592		result.Response = autorest.Response{Response: resp}
593		return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
594	}
595	result, err = client.ListByResourceGroupResponder(resp)
596	if err != nil {
597		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
598	}
599	return
600}
601
602// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
603func (client ProfilesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ProfileListResultIterator, err error) {
604	if tracing.IsEnabled() {
605		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListByResourceGroup")
606		defer func() {
607			sc := -1
608			if result.Response().Response.Response != nil {
609				sc = result.page.Response().Response.Response.StatusCode
610			}
611			tracing.EndSpan(ctx, sc, err)
612		}()
613	}
614	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
615	return
616}
617
618// ListResourceUsage checks the quota and actual usage of endpoints under the given CDN profile.
619// Parameters:
620// resourceGroupName - name of the Resource group within the Azure subscription.
621// profileName - name of the CDN profile which is unique within the resource group.
622func (client ProfilesClient) ListResourceUsage(ctx context.Context, resourceGroupName string, profileName string) (result ResourceUsageListResultPage, err error) {
623	if tracing.IsEnabled() {
624		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListResourceUsage")
625		defer func() {
626			sc := -1
627			if result.rulr.Response.Response != nil {
628				sc = result.rulr.Response.Response.StatusCode
629			}
630			tracing.EndSpan(ctx, sc, err)
631		}()
632	}
633	if err := validation.Validate([]validation.Validation{
634		{TargetValue: resourceGroupName,
635			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
636				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
637				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
638		return result, validation.NewError("cdn.ProfilesClient", "ListResourceUsage", err.Error())
639	}
640
641	result.fn = client.listResourceUsageNextResults
642	req, err := client.ListResourceUsagePreparer(ctx, resourceGroupName, profileName)
643	if err != nil {
644		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListResourceUsage", nil, "Failure preparing request")
645		return
646	}
647
648	resp, err := client.ListResourceUsageSender(req)
649	if err != nil {
650		result.rulr.Response = autorest.Response{Response: resp}
651		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListResourceUsage", resp, "Failure sending request")
652		return
653	}
654
655	result.rulr, err = client.ListResourceUsageResponder(resp)
656	if err != nil {
657		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListResourceUsage", resp, "Failure responding to request")
658	}
659
660	return
661}
662
663// ListResourceUsagePreparer prepares the ListResourceUsage request.
664func (client ProfilesClient) ListResourceUsagePreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
665	pathParameters := map[string]interface{}{
666		"profileName":       autorest.Encode("path", profileName),
667		"resourceGroupName": autorest.Encode("path", resourceGroupName),
668		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
669	}
670
671	const APIVersion = "2019-06-15"
672	queryParameters := map[string]interface{}{
673		"api-version": APIVersion,
674	}
675
676	preparer := autorest.CreatePreparer(
677		autorest.AsPost(),
678		autorest.WithBaseURL(client.BaseURI),
679		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/checkResourceUsage", pathParameters),
680		autorest.WithQueryParameters(queryParameters))
681	return preparer.Prepare((&http.Request{}).WithContext(ctx))
682}
683
684// ListResourceUsageSender sends the ListResourceUsage request. The method will close the
685// http.Response Body if it receives an error.
686func (client ProfilesClient) ListResourceUsageSender(req *http.Request) (*http.Response, error) {
687	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
688}
689
690// ListResourceUsageResponder handles the response to the ListResourceUsage request. The method always
691// closes the http.Response Body.
692func (client ProfilesClient) ListResourceUsageResponder(resp *http.Response) (result ResourceUsageListResult, err error) {
693	err = autorest.Respond(
694		resp,
695		client.ByInspecting(),
696		azure.WithErrorUnlessStatusCode(http.StatusOK),
697		autorest.ByUnmarshallingJSON(&result),
698		autorest.ByClosing())
699	result.Response = autorest.Response{Response: resp}
700	return
701}
702
703// listResourceUsageNextResults retrieves the next set of results, if any.
704func (client ProfilesClient) listResourceUsageNextResults(ctx context.Context, lastResults ResourceUsageListResult) (result ResourceUsageListResult, err error) {
705	req, err := lastResults.resourceUsageListResultPreparer(ctx)
706	if err != nil {
707		return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listResourceUsageNextResults", nil, "Failure preparing next results request")
708	}
709	if req == nil {
710		return
711	}
712	resp, err := client.ListResourceUsageSender(req)
713	if err != nil {
714		result.Response = autorest.Response{Response: resp}
715		return result, autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listResourceUsageNextResults", resp, "Failure sending next results request")
716	}
717	result, err = client.ListResourceUsageResponder(resp)
718	if err != nil {
719		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "listResourceUsageNextResults", resp, "Failure responding to next results request")
720	}
721	return
722}
723
724// ListResourceUsageComplete enumerates all values, automatically crossing page boundaries as required.
725func (client ProfilesClient) ListResourceUsageComplete(ctx context.Context, resourceGroupName string, profileName string) (result ResourceUsageListResultIterator, err error) {
726	if tracing.IsEnabled() {
727		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListResourceUsage")
728		defer func() {
729			sc := -1
730			if result.Response().Response.Response != nil {
731				sc = result.page.Response().Response.Response.StatusCode
732			}
733			tracing.EndSpan(ctx, sc, err)
734		}()
735	}
736	result.page, err = client.ListResourceUsage(ctx, resourceGroupName, profileName)
737	return
738}
739
740// ListSupportedOptimizationTypes gets the supported optimization types for the current profile. A user can create an
741// endpoint with an optimization type from the listed values.
742// Parameters:
743// resourceGroupName - name of the Resource group within the Azure subscription.
744// profileName - name of the CDN profile which is unique within the resource group.
745func (client ProfilesClient) ListSupportedOptimizationTypes(ctx context.Context, resourceGroupName string, profileName string) (result SupportedOptimizationTypesListResult, err error) {
746	if tracing.IsEnabled() {
747		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.ListSupportedOptimizationTypes")
748		defer func() {
749			sc := -1
750			if result.Response.Response != nil {
751				sc = result.Response.Response.StatusCode
752			}
753			tracing.EndSpan(ctx, sc, err)
754		}()
755	}
756	if err := validation.Validate([]validation.Validation{
757		{TargetValue: resourceGroupName,
758			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
759				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
760				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
761		return result, validation.NewError("cdn.ProfilesClient", "ListSupportedOptimizationTypes", err.Error())
762	}
763
764	req, err := client.ListSupportedOptimizationTypesPreparer(ctx, resourceGroupName, profileName)
765	if err != nil {
766		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListSupportedOptimizationTypes", nil, "Failure preparing request")
767		return
768	}
769
770	resp, err := client.ListSupportedOptimizationTypesSender(req)
771	if err != nil {
772		result.Response = autorest.Response{Response: resp}
773		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListSupportedOptimizationTypes", resp, "Failure sending request")
774		return
775	}
776
777	result, err = client.ListSupportedOptimizationTypesResponder(resp)
778	if err != nil {
779		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "ListSupportedOptimizationTypes", resp, "Failure responding to request")
780	}
781
782	return
783}
784
785// ListSupportedOptimizationTypesPreparer prepares the ListSupportedOptimizationTypes request.
786func (client ProfilesClient) ListSupportedOptimizationTypesPreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
787	pathParameters := map[string]interface{}{
788		"profileName":       autorest.Encode("path", profileName),
789		"resourceGroupName": autorest.Encode("path", resourceGroupName),
790		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
791	}
792
793	const APIVersion = "2019-06-15"
794	queryParameters := map[string]interface{}{
795		"api-version": APIVersion,
796	}
797
798	preparer := autorest.CreatePreparer(
799		autorest.AsPost(),
800		autorest.WithBaseURL(client.BaseURI),
801		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/getSupportedOptimizationTypes", pathParameters),
802		autorest.WithQueryParameters(queryParameters))
803	return preparer.Prepare((&http.Request{}).WithContext(ctx))
804}
805
806// ListSupportedOptimizationTypesSender sends the ListSupportedOptimizationTypes request. The method will close the
807// http.Response Body if it receives an error.
808func (client ProfilesClient) ListSupportedOptimizationTypesSender(req *http.Request) (*http.Response, error) {
809	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
810}
811
812// ListSupportedOptimizationTypesResponder handles the response to the ListSupportedOptimizationTypes request. The method always
813// closes the http.Response Body.
814func (client ProfilesClient) ListSupportedOptimizationTypesResponder(resp *http.Response) (result SupportedOptimizationTypesListResult, err error) {
815	err = autorest.Respond(
816		resp,
817		client.ByInspecting(),
818		azure.WithErrorUnlessStatusCode(http.StatusOK),
819		autorest.ByUnmarshallingJSON(&result),
820		autorest.ByClosing())
821	result.Response = autorest.Response{Response: resp}
822	return
823}
824
825// Update updates an existing CDN profile with the specified profile name under the specified subscription and resource
826// group.
827// Parameters:
828// resourceGroupName - name of the Resource group within the Azure subscription.
829// profileName - name of the CDN profile which is unique within the resource group.
830// profileUpdateParameters - profile properties needed to update an existing profile.
831func (client ProfilesClient) Update(ctx context.Context, resourceGroupName string, profileName string, profileUpdateParameters ProfileUpdateParameters) (result ProfilesUpdateFuture, err error) {
832	if tracing.IsEnabled() {
833		ctx = tracing.StartSpan(ctx, fqdn+"/ProfilesClient.Update")
834		defer func() {
835			sc := -1
836			if result.Response() != nil {
837				sc = result.Response().StatusCode
838			}
839			tracing.EndSpan(ctx, sc, err)
840		}()
841	}
842	if err := validation.Validate([]validation.Validation{
843		{TargetValue: resourceGroupName,
844			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
845				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
846				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
847		return result, validation.NewError("cdn.ProfilesClient", "Update", err.Error())
848	}
849
850	req, err := client.UpdatePreparer(ctx, resourceGroupName, profileName, profileUpdateParameters)
851	if err != nil {
852		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Update", nil, "Failure preparing request")
853		return
854	}
855
856	result, err = client.UpdateSender(req)
857	if err != nil {
858		err = autorest.NewErrorWithError(err, "cdn.ProfilesClient", "Update", result.Response(), "Failure sending request")
859		return
860	}
861
862	return
863}
864
865// UpdatePreparer prepares the Update request.
866func (client ProfilesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, profileUpdateParameters ProfileUpdateParameters) (*http.Request, error) {
867	pathParameters := map[string]interface{}{
868		"profileName":       autorest.Encode("path", profileName),
869		"resourceGroupName": autorest.Encode("path", resourceGroupName),
870		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
871	}
872
873	const APIVersion = "2019-06-15"
874	queryParameters := map[string]interface{}{
875		"api-version": APIVersion,
876	}
877
878	preparer := autorest.CreatePreparer(
879		autorest.AsContentType("application/json; charset=utf-8"),
880		autorest.AsPatch(),
881		autorest.WithBaseURL(client.BaseURI),
882		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}", pathParameters),
883		autorest.WithJSON(profileUpdateParameters),
884		autorest.WithQueryParameters(queryParameters))
885	return preparer.Prepare((&http.Request{}).WithContext(ctx))
886}
887
888// UpdateSender sends the Update request. The method will close the
889// http.Response Body if it receives an error.
890func (client ProfilesClient) UpdateSender(req *http.Request) (future ProfilesUpdateFuture, err error) {
891	var resp *http.Response
892	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
893	if err != nil {
894		return
895	}
896	future.Future, err = azure.NewFutureFromResponse(resp)
897	return
898}
899
900// UpdateResponder handles the response to the Update request. The method always
901// closes the http.Response Body.
902func (client ProfilesClient) UpdateResponder(resp *http.Response) (result Profile, err error) {
903	err = autorest.Respond(
904		resp,
905		client.ByInspecting(),
906		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
907		autorest.ByUnmarshallingJSON(&result),
908		autorest.ByClosing())
909	result.Response = autorest.Response{Response: resp}
910	return
911}
912