1package storagesync
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/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// ServicesClient is the microsoft Storage Sync Service API
19type ServicesClient struct {
20	BaseClient
21}
22
23// NewServicesClient creates an instance of the ServicesClient client.
24func NewServicesClient(subscriptionID string) ServicesClient {
25	return NewServicesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewServicesClientWithBaseURI creates an instance of the ServicesClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewServicesClientWithBaseURI(baseURI string, subscriptionID string) ServicesClient {
31	return ServicesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CheckNameAvailability check the give namespace name availability.
35// Parameters:
36// locationName - the desired region for the name check.
37// parameters - parameters to check availability of the given namespace name
38func (client ServicesClient) CheckNameAvailability(ctx context.Context, locationName string, parameters CheckNameAvailabilityParameters) (result CheckNameAvailabilityResult, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.CheckNameAvailability")
41		defer func() {
42			sc := -1
43			if result.Response.Response != nil {
44				sc = result.Response.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: client.SubscriptionID,
51			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
52		{TargetValue: parameters,
53			Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil},
54				{Target: "parameters.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
55		return result, validation.NewError("storagesync.ServicesClient", "CheckNameAvailability", err.Error())
56	}
57
58	req, err := client.CheckNameAvailabilityPreparer(ctx, locationName, parameters)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "CheckNameAvailability", nil, "Failure preparing request")
61		return
62	}
63
64	resp, err := client.CheckNameAvailabilitySender(req)
65	if err != nil {
66		result.Response = autorest.Response{Response: resp}
67		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "CheckNameAvailability", resp, "Failure sending request")
68		return
69	}
70
71	result, err = client.CheckNameAvailabilityResponder(resp)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "CheckNameAvailability", resp, "Failure responding to request")
74		return
75	}
76
77	return
78}
79
80// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
81func (client ServicesClient) CheckNameAvailabilityPreparer(ctx context.Context, locationName string, parameters CheckNameAvailabilityParameters) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"locationName":   autorest.Encode("path", locationName),
84		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
85	}
86
87	const APIVersion = "2020-03-01"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	preparer := autorest.CreatePreparer(
93		autorest.AsContentType("application/json; charset=utf-8"),
94		autorest.AsPost(),
95		autorest.WithBaseURL(client.BaseURI),
96		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.StorageSync/locations/{locationName}/checkNameAvailability", pathParameters),
97		autorest.WithJSON(parameters),
98		autorest.WithQueryParameters(queryParameters))
99	return preparer.Prepare((&http.Request{}).WithContext(ctx))
100}
101
102// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
103// http.Response Body if it receives an error.
104func (client ServicesClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
105	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
106}
107
108// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
109// closes the http.Response Body.
110func (client ServicesClient) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameAvailabilityResult, err error) {
111	err = autorest.Respond(
112		resp,
113		azure.WithErrorUnlessStatusCode(http.StatusOK),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// Create create a new StorageSyncService.
121// Parameters:
122// resourceGroupName - the name of the resource group. The name is case insensitive.
123// storageSyncServiceName - name of Storage Sync Service resource.
124// parameters - storage Sync Service resource name.
125func (client ServicesClient) Create(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters ServiceCreateParameters) (result ServicesCreateFuture, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Create")
128		defer func() {
129			sc := -1
130			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
131				sc = result.FutureAPI.Response().StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	if err := validation.Validate([]validation.Validation{
137		{TargetValue: client.SubscriptionID,
138			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
139		{TargetValue: resourceGroupName,
140			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
141				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
142				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
143		{TargetValue: parameters,
144			Constraints: []validation.Constraint{{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
145		return result, validation.NewError("storagesync.ServicesClient", "Create", err.Error())
146	}
147
148	req, err := client.CreatePreparer(ctx, resourceGroupName, storageSyncServiceName, parameters)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Create", nil, "Failure preparing request")
151		return
152	}
153
154	result, err = client.CreateSender(req)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Create", nil, "Failure sending request")
157		return
158	}
159
160	return
161}
162
163// CreatePreparer prepares the Create request.
164func (client ServicesClient) CreatePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters ServiceCreateParameters) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
167		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
168		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
169	}
170
171	const APIVersion = "2020-03-01"
172	queryParameters := map[string]interface{}{
173		"api-version": APIVersion,
174	}
175
176	preparer := autorest.CreatePreparer(
177		autorest.AsContentType("application/json; charset=utf-8"),
178		autorest.AsPut(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
181		autorest.WithJSON(parameters),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// CreateSender sends the Create request. The method will close the
187// http.Response Body if it receives an error.
188func (client ServicesClient) CreateSender(req *http.Request) (future ServicesCreateFuture, err error) {
189	var resp *http.Response
190	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
191	if err != nil {
192		return
193	}
194	var azf azure.Future
195	azf, err = azure.NewFutureFromResponse(resp)
196	future.FutureAPI = &azf
197	future.Result = future.result
198	return
199}
200
201// CreateResponder handles the response to the Create request. The method always
202// closes the http.Response Body.
203func (client ServicesClient) CreateResponder(resp *http.Response) (result Service, err error) {
204	err = autorest.Respond(
205		resp,
206		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
207		autorest.ByUnmarshallingJSON(&result),
208		autorest.ByClosing())
209	result.Response = autorest.Response{Response: resp}
210	return
211}
212
213// Delete delete a given StorageSyncService.
214// Parameters:
215// resourceGroupName - the name of the resource group. The name is case insensitive.
216// storageSyncServiceName - name of Storage Sync Service resource.
217func (client ServicesClient) Delete(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (result ServicesDeleteFuture, err error) {
218	if tracing.IsEnabled() {
219		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Delete")
220		defer func() {
221			sc := -1
222			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
223				sc = result.FutureAPI.Response().StatusCode
224			}
225			tracing.EndSpan(ctx, sc, err)
226		}()
227	}
228	if err := validation.Validate([]validation.Validation{
229		{TargetValue: client.SubscriptionID,
230			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
231		{TargetValue: resourceGroupName,
232			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
233				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
234				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
235		return result, validation.NewError("storagesync.ServicesClient", "Delete", err.Error())
236	}
237
238	req, err := client.DeletePreparer(ctx, resourceGroupName, storageSyncServiceName)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Delete", nil, "Failure preparing request")
241		return
242	}
243
244	result, err = client.DeleteSender(req)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Delete", nil, "Failure sending request")
247		return
248	}
249
250	return
251}
252
253// DeletePreparer prepares the Delete request.
254func (client ServicesClient) DeletePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (*http.Request, error) {
255	pathParameters := map[string]interface{}{
256		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
257		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
258		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
259	}
260
261	const APIVersion = "2020-03-01"
262	queryParameters := map[string]interface{}{
263		"api-version": APIVersion,
264	}
265
266	preparer := autorest.CreatePreparer(
267		autorest.AsDelete(),
268		autorest.WithBaseURL(client.BaseURI),
269		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
270		autorest.WithQueryParameters(queryParameters))
271	return preparer.Prepare((&http.Request{}).WithContext(ctx))
272}
273
274// DeleteSender sends the Delete request. The method will close the
275// http.Response Body if it receives an error.
276func (client ServicesClient) DeleteSender(req *http.Request) (future ServicesDeleteFuture, err error) {
277	var resp *http.Response
278	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
279	if err != nil {
280		return
281	}
282	var azf azure.Future
283	azf, err = azure.NewFutureFromResponse(resp)
284	future.FutureAPI = &azf
285	future.Result = future.result
286	return
287}
288
289// DeleteResponder handles the response to the Delete request. The method always
290// closes the http.Response Body.
291func (client ServicesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
292	err = autorest.Respond(
293		resp,
294		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
295		autorest.ByClosing())
296	result.Response = resp
297	return
298}
299
300// Get get a given StorageSyncService.
301// Parameters:
302// resourceGroupName - the name of the resource group. The name is case insensitive.
303// storageSyncServiceName - name of Storage Sync Service resource.
304func (client ServicesClient) Get(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (result Service, err error) {
305	if tracing.IsEnabled() {
306		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get")
307		defer func() {
308			sc := -1
309			if result.Response.Response != nil {
310				sc = result.Response.Response.StatusCode
311			}
312			tracing.EndSpan(ctx, sc, err)
313		}()
314	}
315	if err := validation.Validate([]validation.Validation{
316		{TargetValue: client.SubscriptionID,
317			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
318		{TargetValue: resourceGroupName,
319			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
320				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
321				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
322		return result, validation.NewError("storagesync.ServicesClient", "Get", err.Error())
323	}
324
325	req, err := client.GetPreparer(ctx, resourceGroupName, storageSyncServiceName)
326	if err != nil {
327		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Get", nil, "Failure preparing request")
328		return
329	}
330
331	resp, err := client.GetSender(req)
332	if err != nil {
333		result.Response = autorest.Response{Response: resp}
334		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Get", resp, "Failure sending request")
335		return
336	}
337
338	result, err = client.GetResponder(resp)
339	if err != nil {
340		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Get", resp, "Failure responding to request")
341		return
342	}
343
344	return
345}
346
347// GetPreparer prepares the Get request.
348func (client ServicesClient) GetPreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (*http.Request, error) {
349	pathParameters := map[string]interface{}{
350		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
351		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
352		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
353	}
354
355	const APIVersion = "2020-03-01"
356	queryParameters := map[string]interface{}{
357		"api-version": APIVersion,
358	}
359
360	preparer := autorest.CreatePreparer(
361		autorest.AsGet(),
362		autorest.WithBaseURL(client.BaseURI),
363		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
364		autorest.WithQueryParameters(queryParameters))
365	return preparer.Prepare((&http.Request{}).WithContext(ctx))
366}
367
368// GetSender sends the Get request. The method will close the
369// http.Response Body if it receives an error.
370func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) {
371	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
372}
373
374// GetResponder handles the response to the Get request. The method always
375// closes the http.Response Body.
376func (client ServicesClient) GetResponder(resp *http.Response) (result Service, err error) {
377	err = autorest.Respond(
378		resp,
379		azure.WithErrorUnlessStatusCode(http.StatusOK),
380		autorest.ByUnmarshallingJSON(&result),
381		autorest.ByClosing())
382	result.Response = autorest.Response{Response: resp}
383	return
384}
385
386// ListByResourceGroup get a StorageSyncService list by Resource group name.
387// Parameters:
388// resourceGroupName - the name of the resource group. The name is case insensitive.
389func (client ServicesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ServiceArray, err error) {
390	if tracing.IsEnabled() {
391		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListByResourceGroup")
392		defer func() {
393			sc := -1
394			if result.Response.Response != nil {
395				sc = result.Response.Response.StatusCode
396			}
397			tracing.EndSpan(ctx, sc, err)
398		}()
399	}
400	if err := validation.Validate([]validation.Validation{
401		{TargetValue: client.SubscriptionID,
402			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
403		{TargetValue: resourceGroupName,
404			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
405				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
406				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
407		return result, validation.NewError("storagesync.ServicesClient", "ListByResourceGroup", err.Error())
408	}
409
410	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
411	if err != nil {
412		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListByResourceGroup", nil, "Failure preparing request")
413		return
414	}
415
416	resp, err := client.ListByResourceGroupSender(req)
417	if err != nil {
418		result.Response = autorest.Response{Response: resp}
419		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListByResourceGroup", resp, "Failure sending request")
420		return
421	}
422
423	result, err = client.ListByResourceGroupResponder(resp)
424	if err != nil {
425		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListByResourceGroup", resp, "Failure responding to request")
426		return
427	}
428
429	return
430}
431
432// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
433func (client ServicesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
434	pathParameters := map[string]interface{}{
435		"resourceGroupName": autorest.Encode("path", resourceGroupName),
436		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
437	}
438
439	const APIVersion = "2020-03-01"
440	queryParameters := map[string]interface{}{
441		"api-version": APIVersion,
442	}
443
444	preparer := autorest.CreatePreparer(
445		autorest.AsGet(),
446		autorest.WithBaseURL(client.BaseURI),
447		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices", pathParameters),
448		autorest.WithQueryParameters(queryParameters))
449	return preparer.Prepare((&http.Request{}).WithContext(ctx))
450}
451
452// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
453// http.Response Body if it receives an error.
454func (client ServicesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
455	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
456}
457
458// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
459// closes the http.Response Body.
460func (client ServicesClient) ListByResourceGroupResponder(resp *http.Response) (result ServiceArray, err error) {
461	err = autorest.Respond(
462		resp,
463		azure.WithErrorUnlessStatusCode(http.StatusOK),
464		autorest.ByUnmarshallingJSON(&result),
465		autorest.ByClosing())
466	result.Response = autorest.Response{Response: resp}
467	return
468}
469
470// ListBySubscription get a StorageSyncService list by subscription.
471func (client ServicesClient) ListBySubscription(ctx context.Context) (result ServiceArray, err error) {
472	if tracing.IsEnabled() {
473		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListBySubscription")
474		defer func() {
475			sc := -1
476			if result.Response.Response != nil {
477				sc = result.Response.Response.StatusCode
478			}
479			tracing.EndSpan(ctx, sc, err)
480		}()
481	}
482	if err := validation.Validate([]validation.Validation{
483		{TargetValue: client.SubscriptionID,
484			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
485		return result, validation.NewError("storagesync.ServicesClient", "ListBySubscription", err.Error())
486	}
487
488	req, err := client.ListBySubscriptionPreparer(ctx)
489	if err != nil {
490		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListBySubscription", nil, "Failure preparing request")
491		return
492	}
493
494	resp, err := client.ListBySubscriptionSender(req)
495	if err != nil {
496		result.Response = autorest.Response{Response: resp}
497		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListBySubscription", resp, "Failure sending request")
498		return
499	}
500
501	result, err = client.ListBySubscriptionResponder(resp)
502	if err != nil {
503		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListBySubscription", resp, "Failure responding to request")
504		return
505	}
506
507	return
508}
509
510// ListBySubscriptionPreparer prepares the ListBySubscription request.
511func (client ServicesClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
512	pathParameters := map[string]interface{}{
513		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
514	}
515
516	const APIVersion = "2020-03-01"
517	queryParameters := map[string]interface{}{
518		"api-version": APIVersion,
519	}
520
521	preparer := autorest.CreatePreparer(
522		autorest.AsGet(),
523		autorest.WithBaseURL(client.BaseURI),
524		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.StorageSync/storageSyncServices", pathParameters),
525		autorest.WithQueryParameters(queryParameters))
526	return preparer.Prepare((&http.Request{}).WithContext(ctx))
527}
528
529// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
530// http.Response Body if it receives an error.
531func (client ServicesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
532	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
533}
534
535// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
536// closes the http.Response Body.
537func (client ServicesClient) ListBySubscriptionResponder(resp *http.Response) (result ServiceArray, err error) {
538	err = autorest.Respond(
539		resp,
540		azure.WithErrorUnlessStatusCode(http.StatusOK),
541		autorest.ByUnmarshallingJSON(&result),
542		autorest.ByClosing())
543	result.Response = autorest.Response{Response: resp}
544	return
545}
546
547// Update patch a given StorageSyncService.
548// Parameters:
549// resourceGroupName - the name of the resource group. The name is case insensitive.
550// storageSyncServiceName - name of Storage Sync Service resource.
551// parameters - storage Sync Service resource.
552func (client ServicesClient) Update(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters *ServiceUpdateParameters) (result ServicesUpdateFuture, err error) {
553	if tracing.IsEnabled() {
554		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Update")
555		defer func() {
556			sc := -1
557			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
558				sc = result.FutureAPI.Response().StatusCode
559			}
560			tracing.EndSpan(ctx, sc, err)
561		}()
562	}
563	if err := validation.Validate([]validation.Validation{
564		{TargetValue: client.SubscriptionID,
565			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
566		{TargetValue: resourceGroupName,
567			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
568				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
569				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
570		return result, validation.NewError("storagesync.ServicesClient", "Update", err.Error())
571	}
572
573	req, err := client.UpdatePreparer(ctx, resourceGroupName, storageSyncServiceName, parameters)
574	if err != nil {
575		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Update", nil, "Failure preparing request")
576		return
577	}
578
579	result, err = client.UpdateSender(req)
580	if err != nil {
581		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Update", nil, "Failure sending request")
582		return
583	}
584
585	return
586}
587
588// UpdatePreparer prepares the Update request.
589func (client ServicesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters *ServiceUpdateParameters) (*http.Request, error) {
590	pathParameters := map[string]interface{}{
591		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
592		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
593		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
594	}
595
596	const APIVersion = "2020-03-01"
597	queryParameters := map[string]interface{}{
598		"api-version": APIVersion,
599	}
600
601	preparer := autorest.CreatePreparer(
602		autorest.AsContentType("application/json; charset=utf-8"),
603		autorest.AsPatch(),
604		autorest.WithBaseURL(client.BaseURI),
605		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
606		autorest.WithQueryParameters(queryParameters))
607	if parameters != nil {
608		preparer = autorest.DecoratePreparer(preparer,
609			autorest.WithJSON(parameters))
610	}
611	return preparer.Prepare((&http.Request{}).WithContext(ctx))
612}
613
614// UpdateSender sends the Update request. The method will close the
615// http.Response Body if it receives an error.
616func (client ServicesClient) UpdateSender(req *http.Request) (future ServicesUpdateFuture, err error) {
617	var resp *http.Response
618	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
619	if err != nil {
620		return
621	}
622	var azf azure.Future
623	azf, err = azure.NewFutureFromResponse(resp)
624	future.FutureAPI = &azf
625	future.Result = future.result
626	return
627}
628
629// UpdateResponder handles the response to the Update request. The method always
630// closes the http.Response Body.
631func (client ServicesClient) UpdateResponder(resp *http.Response) (result Service, err error) {
632	err = autorest.Respond(
633		resp,
634		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
635		autorest.ByUnmarshallingJSON(&result),
636		autorest.ByClosing())
637	result.Response = autorest.Response{Response: resp}
638	return
639}
640