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// AFDOriginsClient is the cdn Management Client
30type AFDOriginsClient struct {
31	BaseClient
32}
33
34// NewAFDOriginsClient creates an instance of the AFDOriginsClient client.
35func NewAFDOriginsClient(subscriptionID string) AFDOriginsClient {
36	return NewAFDOriginsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAFDOriginsClientWithBaseURI creates an instance of the AFDOriginsClient 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 NewAFDOriginsClientWithBaseURI(baseURI string, subscriptionID string) AFDOriginsClient {
42	return AFDOriginsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Create creates a new origin within the specified origin 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// originGroupName - name of the origin group which is unique within the profile.
50// originName - name of the origin that is unique within the profile.
51// origin - origin properties
52func (client AFDOriginsClient) Create(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string, origin AFDOrigin) (result AFDOriginsCreateFuture, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/AFDOriginsClient.Create")
55		defer func() {
56			sc := -1
57			if result.Response() != nil {
58				sc = result.Response().StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: resourceGroupName,
65			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
66				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
67				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
68		{TargetValue: origin,
69			Constraints: []validation.Constraint{{Target: "origin.AFDOriginProperties", Name: validation.Null, Rule: false,
70				Chain: []validation.Constraint{{Target: "origin.AFDOriginProperties.HostName", Name: validation.Null, Rule: true, Chain: nil},
71					{Target: "origin.AFDOriginProperties.HTTPPort", Name: validation.Null, Rule: false,
72						Chain: []validation.Constraint{{Target: "origin.AFDOriginProperties.HTTPPort", Name: validation.InclusiveMaximum, Rule: int64(65535), Chain: nil},
73							{Target: "origin.AFDOriginProperties.HTTPPort", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
74						}},
75					{Target: "origin.AFDOriginProperties.HTTPSPort", Name: validation.Null, Rule: false,
76						Chain: []validation.Constraint{{Target: "origin.AFDOriginProperties.HTTPSPort", Name: validation.InclusiveMaximum, Rule: int64(65535), Chain: nil},
77							{Target: "origin.AFDOriginProperties.HTTPSPort", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
78						}},
79					{Target: "origin.AFDOriginProperties.Priority", Name: validation.Null, Rule: false,
80						Chain: []validation.Constraint{{Target: "origin.AFDOriginProperties.Priority", Name: validation.InclusiveMaximum, Rule: int64(5), Chain: nil},
81							{Target: "origin.AFDOriginProperties.Priority", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
82						}},
83					{Target: "origin.AFDOriginProperties.Weight", Name: validation.Null, Rule: false,
84						Chain: []validation.Constraint{{Target: "origin.AFDOriginProperties.Weight", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
85							{Target: "origin.AFDOriginProperties.Weight", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
86						}},
87				}}}}}); err != nil {
88		return result, validation.NewError("cdn.AFDOriginsClient", "Create", err.Error())
89	}
90
91	req, err := client.CreatePreparer(ctx, resourceGroupName, profileName, originGroupName, originName, origin)
92	if err != nil {
93		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Create", nil, "Failure preparing request")
94		return
95	}
96
97	result, err = client.CreateSender(req)
98	if err != nil {
99		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Create", nil, "Failure sending request")
100		return
101	}
102
103	return
104}
105
106// CreatePreparer prepares the Create request.
107func (client AFDOriginsClient) CreatePreparer(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string, origin AFDOrigin) (*http.Request, error) {
108	pathParameters := map[string]interface{}{
109		"originGroupName":   autorest.Encode("path", originGroupName),
110		"originName":        autorest.Encode("path", originName),
111		"profileName":       autorest.Encode("path", profileName),
112		"resourceGroupName": autorest.Encode("path", resourceGroupName),
113		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
114	}
115
116	const APIVersion = "2020-09-01"
117	queryParameters := map[string]interface{}{
118		"api-version": APIVersion,
119	}
120
121	preparer := autorest.CreatePreparer(
122		autorest.AsContentType("application/json; charset=utf-8"),
123		autorest.AsPut(),
124		autorest.WithBaseURL(client.BaseURI),
125		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/originGroups/{originGroupName}/origins/{originName}", pathParameters),
126		autorest.WithJSON(origin),
127		autorest.WithQueryParameters(queryParameters))
128	return preparer.Prepare((&http.Request{}).WithContext(ctx))
129}
130
131// CreateSender sends the Create request. The method will close the
132// http.Response Body if it receives an error.
133func (client AFDOriginsClient) CreateSender(req *http.Request) (future AFDOriginsCreateFuture, err error) {
134	var resp *http.Response
135	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
136	if err != nil {
137		return
138	}
139	var azf azure.Future
140	azf, err = azure.NewFutureFromResponse(resp)
141	future.FutureAPI = &azf
142	future.Result = func(client AFDOriginsClient) (ao AFDOrigin, err error) {
143		var done bool
144		done, err = future.DoneWithContext(context.Background(), client)
145		if err != nil {
146			err = autorest.NewErrorWithError(err, "cdn.AFDOriginsCreateFuture", "Result", future.Response(), "Polling failure")
147			return
148		}
149		if !done {
150			err = azure.NewAsyncOpIncompleteError("cdn.AFDOriginsCreateFuture")
151			return
152		}
153		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
154		if ao.Response.Response, err = future.GetResult(sender); err == nil && ao.Response.Response.StatusCode != http.StatusNoContent {
155			ao, err = client.CreateResponder(ao.Response.Response)
156			if err != nil {
157				err = autorest.NewErrorWithError(err, "cdn.AFDOriginsCreateFuture", "Result", ao.Response.Response, "Failure responding to request")
158			}
159		}
160		return
161	}
162	return
163}
164
165// CreateResponder handles the response to the Create request. The method always
166// closes the http.Response Body.
167func (client AFDOriginsClient) CreateResponder(resp *http.Response) (result AFDOrigin, err error) {
168	err = autorest.Respond(
169		resp,
170		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
171		autorest.ByUnmarshallingJSON(&result),
172		autorest.ByClosing())
173	result.Response = autorest.Response{Response: resp}
174	return
175}
176
177// Delete deletes an existing origin within an origin group.
178// Parameters:
179// resourceGroupName - name of the Resource group within the Azure subscription.
180// profileName - name of the CDN profile which is unique within the resource group.
181// originGroupName - name of the origin group which is unique within the profile.
182// originName - name of the origin which is unique within the profile.
183func (client AFDOriginsClient) Delete(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string) (result AFDOriginsDeleteFuture, err error) {
184	if tracing.IsEnabled() {
185		ctx = tracing.StartSpan(ctx, fqdn+"/AFDOriginsClient.Delete")
186		defer func() {
187			sc := -1
188			if result.Response() != nil {
189				sc = result.Response().StatusCode
190			}
191			tracing.EndSpan(ctx, sc, err)
192		}()
193	}
194	if err := validation.Validate([]validation.Validation{
195		{TargetValue: resourceGroupName,
196			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
197				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
198				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
199		return result, validation.NewError("cdn.AFDOriginsClient", "Delete", err.Error())
200	}
201
202	req, err := client.DeletePreparer(ctx, resourceGroupName, profileName, originGroupName, originName)
203	if err != nil {
204		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Delete", nil, "Failure preparing request")
205		return
206	}
207
208	result, err = client.DeleteSender(req)
209	if err != nil {
210		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Delete", nil, "Failure sending request")
211		return
212	}
213
214	return
215}
216
217// DeletePreparer prepares the Delete request.
218func (client AFDOriginsClient) DeletePreparer(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string) (*http.Request, error) {
219	pathParameters := map[string]interface{}{
220		"originGroupName":   autorest.Encode("path", originGroupName),
221		"originName":        autorest.Encode("path", originName),
222		"profileName":       autorest.Encode("path", profileName),
223		"resourceGroupName": autorest.Encode("path", resourceGroupName),
224		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
225	}
226
227	const APIVersion = "2020-09-01"
228	queryParameters := map[string]interface{}{
229		"api-version": APIVersion,
230	}
231
232	preparer := autorest.CreatePreparer(
233		autorest.AsDelete(),
234		autorest.WithBaseURL(client.BaseURI),
235		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/originGroups/{originGroupName}/origins/{originName}", pathParameters),
236		autorest.WithQueryParameters(queryParameters))
237	return preparer.Prepare((&http.Request{}).WithContext(ctx))
238}
239
240// DeleteSender sends the Delete request. The method will close the
241// http.Response Body if it receives an error.
242func (client AFDOriginsClient) DeleteSender(req *http.Request) (future AFDOriginsDeleteFuture, err error) {
243	var resp *http.Response
244	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
245	if err != nil {
246		return
247	}
248	var azf azure.Future
249	azf, err = azure.NewFutureFromResponse(resp)
250	future.FutureAPI = &azf
251	future.Result = func(client AFDOriginsClient) (ar autorest.Response, err error) {
252		var done bool
253		done, err = future.DoneWithContext(context.Background(), client)
254		if err != nil {
255			err = autorest.NewErrorWithError(err, "cdn.AFDOriginsDeleteFuture", "Result", future.Response(), "Polling failure")
256			return
257		}
258		if !done {
259			err = azure.NewAsyncOpIncompleteError("cdn.AFDOriginsDeleteFuture")
260			return
261		}
262		ar.Response = future.Response()
263		return
264	}
265	return
266}
267
268// DeleteResponder handles the response to the Delete request. The method always
269// closes the http.Response Body.
270func (client AFDOriginsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
271	err = autorest.Respond(
272		resp,
273		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
274		autorest.ByClosing())
275	result.Response = resp
276	return
277}
278
279// Get gets an existing origin within an origin group.
280// Parameters:
281// resourceGroupName - name of the Resource group within the Azure subscription.
282// profileName - name of the CDN profile which is unique within the resource group.
283// originGroupName - name of the origin group which is unique within the profile.
284// originName - name of the origin which is unique within the profile.
285func (client AFDOriginsClient) Get(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string) (result AFDOrigin, err error) {
286	if tracing.IsEnabled() {
287		ctx = tracing.StartSpan(ctx, fqdn+"/AFDOriginsClient.Get")
288		defer func() {
289			sc := -1
290			if result.Response.Response != nil {
291				sc = result.Response.Response.StatusCode
292			}
293			tracing.EndSpan(ctx, sc, err)
294		}()
295	}
296	if err := validation.Validate([]validation.Validation{
297		{TargetValue: resourceGroupName,
298			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
299				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
300				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
301		return result, validation.NewError("cdn.AFDOriginsClient", "Get", err.Error())
302	}
303
304	req, err := client.GetPreparer(ctx, resourceGroupName, profileName, originGroupName, originName)
305	if err != nil {
306		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Get", nil, "Failure preparing request")
307		return
308	}
309
310	resp, err := client.GetSender(req)
311	if err != nil {
312		result.Response = autorest.Response{Response: resp}
313		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Get", resp, "Failure sending request")
314		return
315	}
316
317	result, err = client.GetResponder(resp)
318	if err != nil {
319		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Get", resp, "Failure responding to request")
320		return
321	}
322
323	return
324}
325
326// GetPreparer prepares the Get request.
327func (client AFDOriginsClient) GetPreparer(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string) (*http.Request, error) {
328	pathParameters := map[string]interface{}{
329		"originGroupName":   autorest.Encode("path", originGroupName),
330		"originName":        autorest.Encode("path", originName),
331		"profileName":       autorest.Encode("path", profileName),
332		"resourceGroupName": autorest.Encode("path", resourceGroupName),
333		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
334	}
335
336	const APIVersion = "2020-09-01"
337	queryParameters := map[string]interface{}{
338		"api-version": APIVersion,
339	}
340
341	preparer := autorest.CreatePreparer(
342		autorest.AsGet(),
343		autorest.WithBaseURL(client.BaseURI),
344		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/originGroups/{originGroupName}/origins/{originName}", pathParameters),
345		autorest.WithQueryParameters(queryParameters))
346	return preparer.Prepare((&http.Request{}).WithContext(ctx))
347}
348
349// GetSender sends the Get request. The method will close the
350// http.Response Body if it receives an error.
351func (client AFDOriginsClient) GetSender(req *http.Request) (*http.Response, error) {
352	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
353}
354
355// GetResponder handles the response to the Get request. The method always
356// closes the http.Response Body.
357func (client AFDOriginsClient) GetResponder(resp *http.Response) (result AFDOrigin, err error) {
358	err = autorest.Respond(
359		resp,
360		azure.WithErrorUnlessStatusCode(http.StatusOK),
361		autorest.ByUnmarshallingJSON(&result),
362		autorest.ByClosing())
363	result.Response = autorest.Response{Response: resp}
364	return
365}
366
367// ListByOriginGroup lists all of the existing origins within an origin group.
368// Parameters:
369// resourceGroupName - name of the Resource group within the Azure subscription.
370// profileName - name of the CDN profile which is unique within the resource group.
371// originGroupName - name of the origin group which is unique within the profile.
372func (client AFDOriginsClient) ListByOriginGroup(ctx context.Context, resourceGroupName string, profileName string, originGroupName string) (result AFDOriginListResultPage, err error) {
373	if tracing.IsEnabled() {
374		ctx = tracing.StartSpan(ctx, fqdn+"/AFDOriginsClient.ListByOriginGroup")
375		defer func() {
376			sc := -1
377			if result.aolr.Response.Response != nil {
378				sc = result.aolr.Response.Response.StatusCode
379			}
380			tracing.EndSpan(ctx, sc, err)
381		}()
382	}
383	if err := validation.Validate([]validation.Validation{
384		{TargetValue: resourceGroupName,
385			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
386				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
387				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
388		return result, validation.NewError("cdn.AFDOriginsClient", "ListByOriginGroup", err.Error())
389	}
390
391	result.fn = client.listByOriginGroupNextResults
392	req, err := client.ListByOriginGroupPreparer(ctx, resourceGroupName, profileName, originGroupName)
393	if err != nil {
394		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "ListByOriginGroup", nil, "Failure preparing request")
395		return
396	}
397
398	resp, err := client.ListByOriginGroupSender(req)
399	if err != nil {
400		result.aolr.Response = autorest.Response{Response: resp}
401		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "ListByOriginGroup", resp, "Failure sending request")
402		return
403	}
404
405	result.aolr, err = client.ListByOriginGroupResponder(resp)
406	if err != nil {
407		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "ListByOriginGroup", resp, "Failure responding to request")
408		return
409	}
410	if result.aolr.hasNextLink() && result.aolr.IsEmpty() {
411		err = result.NextWithContext(ctx)
412		return
413	}
414
415	return
416}
417
418// ListByOriginGroupPreparer prepares the ListByOriginGroup request.
419func (client AFDOriginsClient) ListByOriginGroupPreparer(ctx context.Context, resourceGroupName string, profileName string, originGroupName string) (*http.Request, error) {
420	pathParameters := map[string]interface{}{
421		"originGroupName":   autorest.Encode("path", originGroupName),
422		"profileName":       autorest.Encode("path", profileName),
423		"resourceGroupName": autorest.Encode("path", resourceGroupName),
424		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
425	}
426
427	const APIVersion = "2020-09-01"
428	queryParameters := map[string]interface{}{
429		"api-version": APIVersion,
430	}
431
432	preparer := autorest.CreatePreparer(
433		autorest.AsGet(),
434		autorest.WithBaseURL(client.BaseURI),
435		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/originGroups/{originGroupName}/origins", pathParameters),
436		autorest.WithQueryParameters(queryParameters))
437	return preparer.Prepare((&http.Request{}).WithContext(ctx))
438}
439
440// ListByOriginGroupSender sends the ListByOriginGroup request. The method will close the
441// http.Response Body if it receives an error.
442func (client AFDOriginsClient) ListByOriginGroupSender(req *http.Request) (*http.Response, error) {
443	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
444}
445
446// ListByOriginGroupResponder handles the response to the ListByOriginGroup request. The method always
447// closes the http.Response Body.
448func (client AFDOriginsClient) ListByOriginGroupResponder(resp *http.Response) (result AFDOriginListResult, err error) {
449	err = autorest.Respond(
450		resp,
451		azure.WithErrorUnlessStatusCode(http.StatusOK),
452		autorest.ByUnmarshallingJSON(&result),
453		autorest.ByClosing())
454	result.Response = autorest.Response{Response: resp}
455	return
456}
457
458// listByOriginGroupNextResults retrieves the next set of results, if any.
459func (client AFDOriginsClient) listByOriginGroupNextResults(ctx context.Context, lastResults AFDOriginListResult) (result AFDOriginListResult, err error) {
460	req, err := lastResults.aFDOriginListResultPreparer(ctx)
461	if err != nil {
462		return result, autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "listByOriginGroupNextResults", nil, "Failure preparing next results request")
463	}
464	if req == nil {
465		return
466	}
467	resp, err := client.ListByOriginGroupSender(req)
468	if err != nil {
469		result.Response = autorest.Response{Response: resp}
470		return result, autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "listByOriginGroupNextResults", resp, "Failure sending next results request")
471	}
472	result, err = client.ListByOriginGroupResponder(resp)
473	if err != nil {
474		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "listByOriginGroupNextResults", resp, "Failure responding to next results request")
475	}
476	return
477}
478
479// ListByOriginGroupComplete enumerates all values, automatically crossing page boundaries as required.
480func (client AFDOriginsClient) ListByOriginGroupComplete(ctx context.Context, resourceGroupName string, profileName string, originGroupName string) (result AFDOriginListResultIterator, err error) {
481	if tracing.IsEnabled() {
482		ctx = tracing.StartSpan(ctx, fqdn+"/AFDOriginsClient.ListByOriginGroup")
483		defer func() {
484			sc := -1
485			if result.Response().Response.Response != nil {
486				sc = result.page.Response().Response.Response.StatusCode
487			}
488			tracing.EndSpan(ctx, sc, err)
489		}()
490	}
491	result.page, err = client.ListByOriginGroup(ctx, resourceGroupName, profileName, originGroupName)
492	return
493}
494
495// Update updates an existing origin within an origin group.
496// Parameters:
497// resourceGroupName - name of the Resource group within the Azure subscription.
498// profileName - name of the CDN profile which is unique within the resource group.
499// originGroupName - name of the origin group which is unique within the profile.
500// originName - name of the origin which is unique within the profile.
501// originUpdateProperties - origin properties
502func (client AFDOriginsClient) Update(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string, originUpdateProperties AFDOriginUpdateParameters) (result AFDOriginsUpdateFuture, err error) {
503	if tracing.IsEnabled() {
504		ctx = tracing.StartSpan(ctx, fqdn+"/AFDOriginsClient.Update")
505		defer func() {
506			sc := -1
507			if result.Response() != nil {
508				sc = result.Response().StatusCode
509			}
510			tracing.EndSpan(ctx, sc, err)
511		}()
512	}
513	if err := validation.Validate([]validation.Validation{
514		{TargetValue: resourceGroupName,
515			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
516				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
517				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
518		return result, validation.NewError("cdn.AFDOriginsClient", "Update", err.Error())
519	}
520
521	req, err := client.UpdatePreparer(ctx, resourceGroupName, profileName, originGroupName, originName, originUpdateProperties)
522	if err != nil {
523		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Update", nil, "Failure preparing request")
524		return
525	}
526
527	result, err = client.UpdateSender(req)
528	if err != nil {
529		err = autorest.NewErrorWithError(err, "cdn.AFDOriginsClient", "Update", nil, "Failure sending request")
530		return
531	}
532
533	return
534}
535
536// UpdatePreparer prepares the Update request.
537func (client AFDOriginsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, originGroupName string, originName string, originUpdateProperties AFDOriginUpdateParameters) (*http.Request, error) {
538	pathParameters := map[string]interface{}{
539		"originGroupName":   autorest.Encode("path", originGroupName),
540		"originName":        autorest.Encode("path", originName),
541		"profileName":       autorest.Encode("path", profileName),
542		"resourceGroupName": autorest.Encode("path", resourceGroupName),
543		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
544	}
545
546	const APIVersion = "2020-09-01"
547	queryParameters := map[string]interface{}{
548		"api-version": APIVersion,
549	}
550
551	preparer := autorest.CreatePreparer(
552		autorest.AsContentType("application/json; charset=utf-8"),
553		autorest.AsPatch(),
554		autorest.WithBaseURL(client.BaseURI),
555		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/originGroups/{originGroupName}/origins/{originName}", pathParameters),
556		autorest.WithJSON(originUpdateProperties),
557		autorest.WithQueryParameters(queryParameters))
558	return preparer.Prepare((&http.Request{}).WithContext(ctx))
559}
560
561// UpdateSender sends the Update request. The method will close the
562// http.Response Body if it receives an error.
563func (client AFDOriginsClient) UpdateSender(req *http.Request) (future AFDOriginsUpdateFuture, err error) {
564	var resp *http.Response
565	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
566	if err != nil {
567		return
568	}
569	var azf azure.Future
570	azf, err = azure.NewFutureFromResponse(resp)
571	future.FutureAPI = &azf
572	future.Result = func(client AFDOriginsClient) (ao AFDOrigin, err error) {
573		var done bool
574		done, err = future.DoneWithContext(context.Background(), client)
575		if err != nil {
576			err = autorest.NewErrorWithError(err, "cdn.AFDOriginsUpdateFuture", "Result", future.Response(), "Polling failure")
577			return
578		}
579		if !done {
580			err = azure.NewAsyncOpIncompleteError("cdn.AFDOriginsUpdateFuture")
581			return
582		}
583		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
584		if ao.Response.Response, err = future.GetResult(sender); err == nil && ao.Response.Response.StatusCode != http.StatusNoContent {
585			ao, err = client.UpdateResponder(ao.Response.Response)
586			if err != nil {
587				err = autorest.NewErrorWithError(err, "cdn.AFDOriginsUpdateFuture", "Result", ao.Response.Response, "Failure responding to request")
588			}
589		}
590		return
591	}
592	return
593}
594
595// UpdateResponder handles the response to the Update request. The method always
596// closes the http.Response Body.
597func (client AFDOriginsClient) UpdateResponder(resp *http.Response) (result AFDOrigin, err error) {
598	err = autorest.Respond(
599		resp,
600		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
601		autorest.ByUnmarshallingJSON(&result),
602		autorest.ByClosing())
603	result.Response = autorest.Response{Response: resp}
604	return
605}
606