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 = "2018-04-02"
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 Service, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Create")
128		defer func() {
129			sc := -1
130			if result.Response.Response != nil {
131				sc = result.Response.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}}}}); err != nil {
143		return result, validation.NewError("storagesync.ServicesClient", "Create", err.Error())
144	}
145
146	req, err := client.CreatePreparer(ctx, resourceGroupName, storageSyncServiceName, parameters)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Create", nil, "Failure preparing request")
149		return
150	}
151
152	resp, err := client.CreateSender(req)
153	if err != nil {
154		result.Response = autorest.Response{Response: resp}
155		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Create", resp, "Failure sending request")
156		return
157	}
158
159	result, err = client.CreateResponder(resp)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Create", resp, "Failure responding to request")
162		return
163	}
164
165	return
166}
167
168// CreatePreparer prepares the Create request.
169func (client ServicesClient) CreatePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters ServiceCreateParameters) (*http.Request, error) {
170	pathParameters := map[string]interface{}{
171		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
172		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
173		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
174	}
175
176	const APIVersion = "2018-04-02"
177	queryParameters := map[string]interface{}{
178		"api-version": APIVersion,
179	}
180
181	preparer := autorest.CreatePreparer(
182		autorest.AsContentType("application/json; charset=utf-8"),
183		autorest.AsPut(),
184		autorest.WithBaseURL(client.BaseURI),
185		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
186		autorest.WithJSON(parameters),
187		autorest.WithQueryParameters(queryParameters))
188	return preparer.Prepare((&http.Request{}).WithContext(ctx))
189}
190
191// CreateSender sends the Create request. The method will close the
192// http.Response Body if it receives an error.
193func (client ServicesClient) CreateSender(req *http.Request) (*http.Response, error) {
194	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
195}
196
197// CreateResponder handles the response to the Create request. The method always
198// closes the http.Response Body.
199func (client ServicesClient) CreateResponder(resp *http.Response) (result Service, err error) {
200	err = autorest.Respond(
201		resp,
202		azure.WithErrorUnlessStatusCode(http.StatusOK),
203		autorest.ByUnmarshallingJSON(&result),
204		autorest.ByClosing())
205	result.Response = autorest.Response{Response: resp}
206	return
207}
208
209// Delete delete a given StorageSyncService.
210// Parameters:
211// resourceGroupName - the name of the resource group. The name is case insensitive.
212// storageSyncServiceName - name of Storage Sync Service resource.
213func (client ServicesClient) Delete(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (result autorest.Response, err error) {
214	if tracing.IsEnabled() {
215		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Delete")
216		defer func() {
217			sc := -1
218			if result.Response != nil {
219				sc = result.Response.StatusCode
220			}
221			tracing.EndSpan(ctx, sc, err)
222		}()
223	}
224	if err := validation.Validate([]validation.Validation{
225		{TargetValue: client.SubscriptionID,
226			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
227		{TargetValue: resourceGroupName,
228			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
229				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
230				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
231		return result, validation.NewError("storagesync.ServicesClient", "Delete", err.Error())
232	}
233
234	req, err := client.DeletePreparer(ctx, resourceGroupName, storageSyncServiceName)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Delete", nil, "Failure preparing request")
237		return
238	}
239
240	resp, err := client.DeleteSender(req)
241	if err != nil {
242		result.Response = resp
243		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Delete", resp, "Failure sending request")
244		return
245	}
246
247	result, err = client.DeleteResponder(resp)
248	if err != nil {
249		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Delete", resp, "Failure responding to request")
250		return
251	}
252
253	return
254}
255
256// DeletePreparer prepares the Delete request.
257func (client ServicesClient) DeletePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (*http.Request, error) {
258	pathParameters := map[string]interface{}{
259		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
260		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
261		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
262	}
263
264	const APIVersion = "2018-04-02"
265	queryParameters := map[string]interface{}{
266		"api-version": APIVersion,
267	}
268
269	preparer := autorest.CreatePreparer(
270		autorest.AsDelete(),
271		autorest.WithBaseURL(client.BaseURI),
272		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
273		autorest.WithQueryParameters(queryParameters))
274	return preparer.Prepare((&http.Request{}).WithContext(ctx))
275}
276
277// DeleteSender sends the Delete request. The method will close the
278// http.Response Body if it receives an error.
279func (client ServicesClient) DeleteSender(req *http.Request) (*http.Response, error) {
280	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
281}
282
283// DeleteResponder handles the response to the Delete request. The method always
284// closes the http.Response Body.
285func (client ServicesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
286	err = autorest.Respond(
287		resp,
288		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
289		autorest.ByClosing())
290	result.Response = resp
291	return
292}
293
294// Get get a given StorageSyncService.
295// Parameters:
296// resourceGroupName - the name of the resource group. The name is case insensitive.
297// storageSyncServiceName - name of Storage Sync Service resource.
298func (client ServicesClient) Get(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (result Service, err error) {
299	if tracing.IsEnabled() {
300		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get")
301		defer func() {
302			sc := -1
303			if result.Response.Response != nil {
304				sc = result.Response.Response.StatusCode
305			}
306			tracing.EndSpan(ctx, sc, err)
307		}()
308	}
309	if err := validation.Validate([]validation.Validation{
310		{TargetValue: client.SubscriptionID,
311			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
312		{TargetValue: resourceGroupName,
313			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
314				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
315				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
316		return result, validation.NewError("storagesync.ServicesClient", "Get", err.Error())
317	}
318
319	req, err := client.GetPreparer(ctx, resourceGroupName, storageSyncServiceName)
320	if err != nil {
321		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Get", nil, "Failure preparing request")
322		return
323	}
324
325	resp, err := client.GetSender(req)
326	if err != nil {
327		result.Response = autorest.Response{Response: resp}
328		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Get", resp, "Failure sending request")
329		return
330	}
331
332	result, err = client.GetResponder(resp)
333	if err != nil {
334		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Get", resp, "Failure responding to request")
335		return
336	}
337
338	return
339}
340
341// GetPreparer prepares the Get request.
342func (client ServicesClient) GetPreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (*http.Request, error) {
343	pathParameters := map[string]interface{}{
344		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
345		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
346		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
347	}
348
349	const APIVersion = "2018-04-02"
350	queryParameters := map[string]interface{}{
351		"api-version": APIVersion,
352	}
353
354	preparer := autorest.CreatePreparer(
355		autorest.AsGet(),
356		autorest.WithBaseURL(client.BaseURI),
357		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
358		autorest.WithQueryParameters(queryParameters))
359	return preparer.Prepare((&http.Request{}).WithContext(ctx))
360}
361
362// GetSender sends the Get request. The method will close the
363// http.Response Body if it receives an error.
364func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) {
365	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
366}
367
368// GetResponder handles the response to the Get request. The method always
369// closes the http.Response Body.
370func (client ServicesClient) GetResponder(resp *http.Response) (result Service, err error) {
371	err = autorest.Respond(
372		resp,
373		azure.WithErrorUnlessStatusCode(http.StatusOK),
374		autorest.ByUnmarshallingJSON(&result),
375		autorest.ByClosing())
376	result.Response = autorest.Response{Response: resp}
377	return
378}
379
380// ListByResourceGroup get a StorageSyncService list by Resource group name.
381// Parameters:
382// resourceGroupName - the name of the resource group. The name is case insensitive.
383func (client ServicesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ServiceArray, err error) {
384	if tracing.IsEnabled() {
385		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListByResourceGroup")
386		defer func() {
387			sc := -1
388			if result.Response.Response != nil {
389				sc = result.Response.Response.StatusCode
390			}
391			tracing.EndSpan(ctx, sc, err)
392		}()
393	}
394	if err := validation.Validate([]validation.Validation{
395		{TargetValue: client.SubscriptionID,
396			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
397		{TargetValue: resourceGroupName,
398			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
399				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
400				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
401		return result, validation.NewError("storagesync.ServicesClient", "ListByResourceGroup", err.Error())
402	}
403
404	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
405	if err != nil {
406		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListByResourceGroup", nil, "Failure preparing request")
407		return
408	}
409
410	resp, err := client.ListByResourceGroupSender(req)
411	if err != nil {
412		result.Response = autorest.Response{Response: resp}
413		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListByResourceGroup", resp, "Failure sending request")
414		return
415	}
416
417	result, err = client.ListByResourceGroupResponder(resp)
418	if err != nil {
419		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListByResourceGroup", resp, "Failure responding to request")
420		return
421	}
422
423	return
424}
425
426// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
427func (client ServicesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
428	pathParameters := map[string]interface{}{
429		"resourceGroupName": autorest.Encode("path", resourceGroupName),
430		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
431	}
432
433	const APIVersion = "2018-04-02"
434	queryParameters := map[string]interface{}{
435		"api-version": APIVersion,
436	}
437
438	preparer := autorest.CreatePreparer(
439		autorest.AsGet(),
440		autorest.WithBaseURL(client.BaseURI),
441		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices", pathParameters),
442		autorest.WithQueryParameters(queryParameters))
443	return preparer.Prepare((&http.Request{}).WithContext(ctx))
444}
445
446// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
447// http.Response Body if it receives an error.
448func (client ServicesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
449	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
450}
451
452// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
453// closes the http.Response Body.
454func (client ServicesClient) ListByResourceGroupResponder(resp *http.Response) (result ServiceArray, err error) {
455	err = autorest.Respond(
456		resp,
457		azure.WithErrorUnlessStatusCode(http.StatusOK),
458		autorest.ByUnmarshallingJSON(&result),
459		autorest.ByClosing())
460	result.Response = autorest.Response{Response: resp}
461	return
462}
463
464// ListBySubscription get a StorageSyncService list by subscription.
465func (client ServicesClient) ListBySubscription(ctx context.Context) (result ServiceArray, err error) {
466	if tracing.IsEnabled() {
467		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListBySubscription")
468		defer func() {
469			sc := -1
470			if result.Response.Response != nil {
471				sc = result.Response.Response.StatusCode
472			}
473			tracing.EndSpan(ctx, sc, err)
474		}()
475	}
476	if err := validation.Validate([]validation.Validation{
477		{TargetValue: client.SubscriptionID,
478			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
479		return result, validation.NewError("storagesync.ServicesClient", "ListBySubscription", err.Error())
480	}
481
482	req, err := client.ListBySubscriptionPreparer(ctx)
483	if err != nil {
484		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListBySubscription", nil, "Failure preparing request")
485		return
486	}
487
488	resp, err := client.ListBySubscriptionSender(req)
489	if err != nil {
490		result.Response = autorest.Response{Response: resp}
491		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListBySubscription", resp, "Failure sending request")
492		return
493	}
494
495	result, err = client.ListBySubscriptionResponder(resp)
496	if err != nil {
497		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "ListBySubscription", resp, "Failure responding to request")
498		return
499	}
500
501	return
502}
503
504// ListBySubscriptionPreparer prepares the ListBySubscription request.
505func (client ServicesClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
506	pathParameters := map[string]interface{}{
507		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
508	}
509
510	const APIVersion = "2018-04-02"
511	queryParameters := map[string]interface{}{
512		"api-version": APIVersion,
513	}
514
515	preparer := autorest.CreatePreparer(
516		autorest.AsGet(),
517		autorest.WithBaseURL(client.BaseURI),
518		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.StorageSync/storageSyncServices", pathParameters),
519		autorest.WithQueryParameters(queryParameters))
520	return preparer.Prepare((&http.Request{}).WithContext(ctx))
521}
522
523// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
524// http.Response Body if it receives an error.
525func (client ServicesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
526	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
527}
528
529// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
530// closes the http.Response Body.
531func (client ServicesClient) ListBySubscriptionResponder(resp *http.Response) (result ServiceArray, err error) {
532	err = autorest.Respond(
533		resp,
534		azure.WithErrorUnlessStatusCode(http.StatusOK),
535		autorest.ByUnmarshallingJSON(&result),
536		autorest.ByClosing())
537	result.Response = autorest.Response{Response: resp}
538	return
539}
540
541// Update patch a given StorageSyncService.
542// Parameters:
543// resourceGroupName - the name of the resource group. The name is case insensitive.
544// storageSyncServiceName - name of Storage Sync Service resource.
545// parameters - storage Sync Service resource.
546func (client ServicesClient) Update(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters *ServiceUpdateParameters) (result Service, err error) {
547	if tracing.IsEnabled() {
548		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Update")
549		defer func() {
550			sc := -1
551			if result.Response.Response != nil {
552				sc = result.Response.Response.StatusCode
553			}
554			tracing.EndSpan(ctx, sc, err)
555		}()
556	}
557	if err := validation.Validate([]validation.Validation{
558		{TargetValue: client.SubscriptionID,
559			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
560		{TargetValue: resourceGroupName,
561			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
562				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
563				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
564		return result, validation.NewError("storagesync.ServicesClient", "Update", err.Error())
565	}
566
567	req, err := client.UpdatePreparer(ctx, resourceGroupName, storageSyncServiceName, parameters)
568	if err != nil {
569		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Update", nil, "Failure preparing request")
570		return
571	}
572
573	resp, err := client.UpdateSender(req)
574	if err != nil {
575		result.Response = autorest.Response{Response: resp}
576		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Update", resp, "Failure sending request")
577		return
578	}
579
580	result, err = client.UpdateResponder(resp)
581	if err != nil {
582		err = autorest.NewErrorWithError(err, "storagesync.ServicesClient", "Update", resp, "Failure responding to request")
583		return
584	}
585
586	return
587}
588
589// UpdatePreparer prepares the Update request.
590func (client ServicesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, parameters *ServiceUpdateParameters) (*http.Request, error) {
591	pathParameters := map[string]interface{}{
592		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
593		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
594		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
595	}
596
597	const APIVersion = "2018-04-02"
598	queryParameters := map[string]interface{}{
599		"api-version": APIVersion,
600	}
601
602	preparer := autorest.CreatePreparer(
603		autorest.AsContentType("application/json; charset=utf-8"),
604		autorest.AsPatch(),
605		autorest.WithBaseURL(client.BaseURI),
606		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}", pathParameters),
607		autorest.WithQueryParameters(queryParameters))
608	if parameters != nil {
609		preparer = autorest.DecoratePreparer(preparer,
610			autorest.WithJSON(parameters))
611	}
612	return preparer.Prepare((&http.Request{}).WithContext(ctx))
613}
614
615// UpdateSender sends the Update request. The method will close the
616// http.Response Body if it receives an error.
617func (client ServicesClient) UpdateSender(req *http.Request) (*http.Response, error) {
618	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
619}
620
621// UpdateResponder handles the response to the Update request. The method always
622// closes the http.Response Body.
623func (client ServicesClient) UpdateResponder(resp *http.Response) (result Service, err error) {
624	err = autorest.Respond(
625		resp,
626		azure.WithErrorUnlessStatusCode(http.StatusOK),
627		autorest.ByUnmarshallingJSON(&result),
628		autorest.ByClosing())
629	result.Response = autorest.Response{Response: resp}
630	return
631}
632