1package appplatform
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 REST API for Azure Spring Cloud
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 checks that the resource name is valid and is not already in use.
35// Parameters:
36// location - the region
37// availabilityParameters - parameters supplied to the operation.
38func (client ServicesClient) CheckNameAvailability(ctx context.Context, location string, availabilityParameters NameAvailabilityParameters) (result NameAvailability, 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: availabilityParameters,
51			Constraints: []validation.Constraint{{Target: "availabilityParameters.Type", Name: validation.Null, Rule: true, Chain: nil},
52				{Target: "availabilityParameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
53		return result, validation.NewError("appplatform.ServicesClient", "CheckNameAvailability", err.Error())
54	}
55
56	req, err := client.CheckNameAvailabilityPreparer(ctx, location, availabilityParameters)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "CheckNameAvailability", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.CheckNameAvailabilitySender(req)
63	if err != nil {
64		result.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "CheckNameAvailability", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.CheckNameAvailabilityResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "CheckNameAvailability", resp, "Failure responding to request")
72		return
73	}
74
75	return
76}
77
78// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
79func (client ServicesClient) CheckNameAvailabilityPreparer(ctx context.Context, location string, availabilityParameters NameAvailabilityParameters) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"location":       autorest.Encode("path", location),
82		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
83	}
84
85	const APIVersion = "2019-05-01-preview"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89
90	preparer := autorest.CreatePreparer(
91		autorest.AsContentType("application/json; charset=utf-8"),
92		autorest.AsPost(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.AppPlatform/locations/{location}/checkNameAvailability", pathParameters),
95		autorest.WithJSON(availabilityParameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
101// http.Response Body if it receives an error.
102func (client ServicesClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
103	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
104}
105
106// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
107// closes the http.Response Body.
108func (client ServicesClient) CheckNameAvailabilityResponder(resp *http.Response) (result NameAvailability, err error) {
109	err = autorest.Respond(
110		resp,
111		azure.WithErrorUnlessStatusCode(http.StatusOK),
112		autorest.ByUnmarshallingJSON(&result),
113		autorest.ByClosing())
114	result.Response = autorest.Response{Response: resp}
115	return
116}
117
118// CreateOrUpdate create a new Service or update an exiting Service.
119// Parameters:
120// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
121// from the Azure Resource Manager API or the portal.
122// serviceName - the name of the Service resource.
123// resource - parameters for the create or update operation
124func (client ServicesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, resource ServiceResource) (result ServicesCreateOrUpdateFuture, err error) {
125	if tracing.IsEnabled() {
126		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.CreateOrUpdate")
127		defer func() {
128			sc := -1
129			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
130				sc = result.FutureAPI.Response().StatusCode
131			}
132			tracing.EndSpan(ctx, sc, err)
133		}()
134	}
135	if err := validation.Validate([]validation.Validation{
136		{TargetValue: resource,
137			Constraints: []validation.Constraint{{Target: "resource.Properties", Name: validation.Null, Rule: false,
138				Chain: []validation.Constraint{{Target: "resource.Properties.ConfigServerProperties", Name: validation.Null, Rule: false,
139					Chain: []validation.Constraint{{Target: "resource.Properties.ConfigServerProperties.ConfigServer", Name: validation.Null, Rule: false,
140						Chain: []validation.Constraint{{Target: "resource.Properties.ConfigServerProperties.ConfigServer.GitProperty", Name: validation.Null, Rule: false,
141							Chain: []validation.Constraint{{Target: "resource.Properties.ConfigServerProperties.ConfigServer.GitProperty.URI", Name: validation.Null, Rule: true, Chain: nil}}},
142						}},
143					}},
144				}}}}}); err != nil {
145		return result, validation.NewError("appplatform.ServicesClient", "CreateOrUpdate", err.Error())
146	}
147
148	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, resource)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "CreateOrUpdate", nil, "Failure preparing request")
151		return
152	}
153
154	result, err = client.CreateOrUpdateSender(req)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "CreateOrUpdate", nil, "Failure sending request")
157		return
158	}
159
160	return
161}
162
163// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
164func (client ServicesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, resource ServiceResource) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"resourceGroupName": autorest.Encode("path", resourceGroupName),
167		"serviceName":       autorest.Encode("path", serviceName),
168		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
169	}
170
171	const APIVersion = "2019-05-01-preview"
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.AppPlatform/Spring/{serviceName}", pathParameters),
181		autorest.WithJSON(resource),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
187// http.Response Body if it receives an error.
188func (client ServicesClient) CreateOrUpdateSender(req *http.Request) (future ServicesCreateOrUpdateFuture, 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// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
202// closes the http.Response Body.
203func (client ServicesClient) CreateOrUpdateResponder(resp *http.Response) (result ServiceResource, err error) {
204	err = autorest.Respond(
205		resp,
206		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
207		autorest.ByUnmarshallingJSON(&result),
208		autorest.ByClosing())
209	result.Response = autorest.Response{Response: resp}
210	return
211}
212
213// Delete operation to delete a Service.
214// Parameters:
215// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
216// from the Azure Resource Manager API or the portal.
217// serviceName - the name of the Service resource.
218func (client ServicesClient) Delete(ctx context.Context, resourceGroupName string, serviceName string) (result ServicesDeleteFuture, err error) {
219	if tracing.IsEnabled() {
220		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Delete")
221		defer func() {
222			sc := -1
223			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
224				sc = result.FutureAPI.Response().StatusCode
225			}
226			tracing.EndSpan(ctx, sc, err)
227		}()
228	}
229	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName)
230	if err != nil {
231		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Delete", nil, "Failure preparing request")
232		return
233	}
234
235	result, err = client.DeleteSender(req)
236	if err != nil {
237		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Delete", nil, "Failure sending request")
238		return
239	}
240
241	return
242}
243
244// DeletePreparer prepares the Delete request.
245func (client ServicesClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
246	pathParameters := map[string]interface{}{
247		"resourceGroupName": autorest.Encode("path", resourceGroupName),
248		"serviceName":       autorest.Encode("path", serviceName),
249		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
250	}
251
252	const APIVersion = "2019-05-01-preview"
253	queryParameters := map[string]interface{}{
254		"api-version": APIVersion,
255	}
256
257	preparer := autorest.CreatePreparer(
258		autorest.AsDelete(),
259		autorest.WithBaseURL(client.BaseURI),
260		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}", pathParameters),
261		autorest.WithQueryParameters(queryParameters))
262	return preparer.Prepare((&http.Request{}).WithContext(ctx))
263}
264
265// DeleteSender sends the Delete request. The method will close the
266// http.Response Body if it receives an error.
267func (client ServicesClient) DeleteSender(req *http.Request) (future ServicesDeleteFuture, err error) {
268	var resp *http.Response
269	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
270	if err != nil {
271		return
272	}
273	var azf azure.Future
274	azf, err = azure.NewFutureFromResponse(resp)
275	future.FutureAPI = &azf
276	future.Result = future.result
277	return
278}
279
280// DeleteResponder handles the response to the Delete request. The method always
281// closes the http.Response Body.
282func (client ServicesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
283	err = autorest.Respond(
284		resp,
285		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
286		autorest.ByClosing())
287	result.Response = resp
288	return
289}
290
291// DisableTestEndpoint sends the disable test endpoint request.
292// Parameters:
293// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
294// from the Azure Resource Manager API or the portal.
295// serviceName - the name of the Service resource.
296func (client ServicesClient) DisableTestEndpoint(ctx context.Context, resourceGroupName string, serviceName string) (result autorest.Response, err error) {
297	if tracing.IsEnabled() {
298		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.DisableTestEndpoint")
299		defer func() {
300			sc := -1
301			if result.Response != nil {
302				sc = result.Response.StatusCode
303			}
304			tracing.EndSpan(ctx, sc, err)
305		}()
306	}
307	req, err := client.DisableTestEndpointPreparer(ctx, resourceGroupName, serviceName)
308	if err != nil {
309		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "DisableTestEndpoint", nil, "Failure preparing request")
310		return
311	}
312
313	resp, err := client.DisableTestEndpointSender(req)
314	if err != nil {
315		result.Response = resp
316		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "DisableTestEndpoint", resp, "Failure sending request")
317		return
318	}
319
320	result, err = client.DisableTestEndpointResponder(resp)
321	if err != nil {
322		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "DisableTestEndpoint", resp, "Failure responding to request")
323		return
324	}
325
326	return
327}
328
329// DisableTestEndpointPreparer prepares the DisableTestEndpoint request.
330func (client ServicesClient) DisableTestEndpointPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
331	pathParameters := map[string]interface{}{
332		"resourceGroupName": autorest.Encode("path", resourceGroupName),
333		"serviceName":       autorest.Encode("path", serviceName),
334		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
335	}
336
337	const APIVersion = "2019-05-01-preview"
338	queryParameters := map[string]interface{}{
339		"api-version": APIVersion,
340	}
341
342	preparer := autorest.CreatePreparer(
343		autorest.AsPost(),
344		autorest.WithBaseURL(client.BaseURI),
345		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}/disableTestEndpoint", pathParameters),
346		autorest.WithQueryParameters(queryParameters))
347	return preparer.Prepare((&http.Request{}).WithContext(ctx))
348}
349
350// DisableTestEndpointSender sends the DisableTestEndpoint request. The method will close the
351// http.Response Body if it receives an error.
352func (client ServicesClient) DisableTestEndpointSender(req *http.Request) (*http.Response, error) {
353	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
354}
355
356// DisableTestEndpointResponder handles the response to the DisableTestEndpoint request. The method always
357// closes the http.Response Body.
358func (client ServicesClient) DisableTestEndpointResponder(resp *http.Response) (result autorest.Response, err error) {
359	err = autorest.Respond(
360		resp,
361		azure.WithErrorUnlessStatusCode(http.StatusOK),
362		autorest.ByClosing())
363	result.Response = resp
364	return
365}
366
367// EnableTestEndpoint sends the enable test endpoint request.
368// Parameters:
369// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
370// from the Azure Resource Manager API or the portal.
371// serviceName - the name of the Service resource.
372func (client ServicesClient) EnableTestEndpoint(ctx context.Context, resourceGroupName string, serviceName string) (result TestKeys, err error) {
373	if tracing.IsEnabled() {
374		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.EnableTestEndpoint")
375		defer func() {
376			sc := -1
377			if result.Response.Response != nil {
378				sc = result.Response.Response.StatusCode
379			}
380			tracing.EndSpan(ctx, sc, err)
381		}()
382	}
383	req, err := client.EnableTestEndpointPreparer(ctx, resourceGroupName, serviceName)
384	if err != nil {
385		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "EnableTestEndpoint", nil, "Failure preparing request")
386		return
387	}
388
389	resp, err := client.EnableTestEndpointSender(req)
390	if err != nil {
391		result.Response = autorest.Response{Response: resp}
392		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "EnableTestEndpoint", resp, "Failure sending request")
393		return
394	}
395
396	result, err = client.EnableTestEndpointResponder(resp)
397	if err != nil {
398		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "EnableTestEndpoint", resp, "Failure responding to request")
399		return
400	}
401
402	return
403}
404
405// EnableTestEndpointPreparer prepares the EnableTestEndpoint request.
406func (client ServicesClient) EnableTestEndpointPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
407	pathParameters := map[string]interface{}{
408		"resourceGroupName": autorest.Encode("path", resourceGroupName),
409		"serviceName":       autorest.Encode("path", serviceName),
410		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
411	}
412
413	const APIVersion = "2019-05-01-preview"
414	queryParameters := map[string]interface{}{
415		"api-version": APIVersion,
416	}
417
418	preparer := autorest.CreatePreparer(
419		autorest.AsPost(),
420		autorest.WithBaseURL(client.BaseURI),
421		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}/enableTestEndpoint", pathParameters),
422		autorest.WithQueryParameters(queryParameters))
423	return preparer.Prepare((&http.Request{}).WithContext(ctx))
424}
425
426// EnableTestEndpointSender sends the EnableTestEndpoint request. The method will close the
427// http.Response Body if it receives an error.
428func (client ServicesClient) EnableTestEndpointSender(req *http.Request) (*http.Response, error) {
429	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
430}
431
432// EnableTestEndpointResponder handles the response to the EnableTestEndpoint request. The method always
433// closes the http.Response Body.
434func (client ServicesClient) EnableTestEndpointResponder(resp *http.Response) (result TestKeys, err error) {
435	err = autorest.Respond(
436		resp,
437		azure.WithErrorUnlessStatusCode(http.StatusOK),
438		autorest.ByUnmarshallingJSON(&result),
439		autorest.ByClosing())
440	result.Response = autorest.Response{Response: resp}
441	return
442}
443
444// Get get a Service and its properties.
445// Parameters:
446// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
447// from the Azure Resource Manager API or the portal.
448// serviceName - the name of the Service resource.
449func (client ServicesClient) Get(ctx context.Context, resourceGroupName string, serviceName string) (result ServiceResource, err error) {
450	if tracing.IsEnabled() {
451		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get")
452		defer func() {
453			sc := -1
454			if result.Response.Response != nil {
455				sc = result.Response.Response.StatusCode
456			}
457			tracing.EndSpan(ctx, sc, err)
458		}()
459	}
460	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName)
461	if err != nil {
462		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Get", nil, "Failure preparing request")
463		return
464	}
465
466	resp, err := client.GetSender(req)
467	if err != nil {
468		result.Response = autorest.Response{Response: resp}
469		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Get", resp, "Failure sending request")
470		return
471	}
472
473	result, err = client.GetResponder(resp)
474	if err != nil {
475		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Get", resp, "Failure responding to request")
476		return
477	}
478
479	return
480}
481
482// GetPreparer prepares the Get request.
483func (client ServicesClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
484	pathParameters := map[string]interface{}{
485		"resourceGroupName": autorest.Encode("path", resourceGroupName),
486		"serviceName":       autorest.Encode("path", serviceName),
487		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
488	}
489
490	const APIVersion = "2019-05-01-preview"
491	queryParameters := map[string]interface{}{
492		"api-version": APIVersion,
493	}
494
495	preparer := autorest.CreatePreparer(
496		autorest.AsGet(),
497		autorest.WithBaseURL(client.BaseURI),
498		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}", pathParameters),
499		autorest.WithQueryParameters(queryParameters))
500	return preparer.Prepare((&http.Request{}).WithContext(ctx))
501}
502
503// GetSender sends the Get request. The method will close the
504// http.Response Body if it receives an error.
505func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) {
506	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
507}
508
509// GetResponder handles the response to the Get request. The method always
510// closes the http.Response Body.
511func (client ServicesClient) GetResponder(resp *http.Response) (result ServiceResource, err error) {
512	err = autorest.Respond(
513		resp,
514		azure.WithErrorUnlessStatusCode(http.StatusOK),
515		autorest.ByUnmarshallingJSON(&result),
516		autorest.ByClosing())
517	result.Response = autorest.Response{Response: resp}
518	return
519}
520
521// List handles requests to list all resources in a resource group.
522// Parameters:
523// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
524// from the Azure Resource Manager API or the portal.
525func (client ServicesClient) List(ctx context.Context, resourceGroupName string) (result ServiceResourceListPage, err error) {
526	if tracing.IsEnabled() {
527		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.List")
528		defer func() {
529			sc := -1
530			if result.srl.Response.Response != nil {
531				sc = result.srl.Response.Response.StatusCode
532			}
533			tracing.EndSpan(ctx, sc, err)
534		}()
535	}
536	result.fn = client.listNextResults
537	req, err := client.ListPreparer(ctx, resourceGroupName)
538	if err != nil {
539		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "List", nil, "Failure preparing request")
540		return
541	}
542
543	resp, err := client.ListSender(req)
544	if err != nil {
545		result.srl.Response = autorest.Response{Response: resp}
546		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "List", resp, "Failure sending request")
547		return
548	}
549
550	result.srl, err = client.ListResponder(resp)
551	if err != nil {
552		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "List", resp, "Failure responding to request")
553		return
554	}
555	if result.srl.hasNextLink() && result.srl.IsEmpty() {
556		err = result.NextWithContext(ctx)
557		return
558	}
559
560	return
561}
562
563// ListPreparer prepares the List request.
564func (client ServicesClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
565	pathParameters := map[string]interface{}{
566		"resourceGroupName": autorest.Encode("path", resourceGroupName),
567		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
568	}
569
570	const APIVersion = "2019-05-01-preview"
571	queryParameters := map[string]interface{}{
572		"api-version": APIVersion,
573	}
574
575	preparer := autorest.CreatePreparer(
576		autorest.AsGet(),
577		autorest.WithBaseURL(client.BaseURI),
578		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring", pathParameters),
579		autorest.WithQueryParameters(queryParameters))
580	return preparer.Prepare((&http.Request{}).WithContext(ctx))
581}
582
583// ListSender sends the List request. The method will close the
584// http.Response Body if it receives an error.
585func (client ServicesClient) ListSender(req *http.Request) (*http.Response, error) {
586	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
587}
588
589// ListResponder handles the response to the List request. The method always
590// closes the http.Response Body.
591func (client ServicesClient) ListResponder(resp *http.Response) (result ServiceResourceList, err error) {
592	err = autorest.Respond(
593		resp,
594		azure.WithErrorUnlessStatusCode(http.StatusOK),
595		autorest.ByUnmarshallingJSON(&result),
596		autorest.ByClosing())
597	result.Response = autorest.Response{Response: resp}
598	return
599}
600
601// listNextResults retrieves the next set of results, if any.
602func (client ServicesClient) listNextResults(ctx context.Context, lastResults ServiceResourceList) (result ServiceResourceList, err error) {
603	req, err := lastResults.serviceResourceListPreparer(ctx)
604	if err != nil {
605		return result, autorest.NewErrorWithError(err, "appplatform.ServicesClient", "listNextResults", nil, "Failure preparing next results request")
606	}
607	if req == nil {
608		return
609	}
610	resp, err := client.ListSender(req)
611	if err != nil {
612		result.Response = autorest.Response{Response: resp}
613		return result, autorest.NewErrorWithError(err, "appplatform.ServicesClient", "listNextResults", resp, "Failure sending next results request")
614	}
615	result, err = client.ListResponder(resp)
616	if err != nil {
617		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "listNextResults", resp, "Failure responding to next results request")
618	}
619	return
620}
621
622// ListComplete enumerates all values, automatically crossing page boundaries as required.
623func (client ServicesClient) ListComplete(ctx context.Context, resourceGroupName string) (result ServiceResourceListIterator, err error) {
624	if tracing.IsEnabled() {
625		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.List")
626		defer func() {
627			sc := -1
628			if result.Response().Response.Response != nil {
629				sc = result.page.Response().Response.Response.StatusCode
630			}
631			tracing.EndSpan(ctx, sc, err)
632		}()
633	}
634	result.page, err = client.List(ctx, resourceGroupName)
635	return
636}
637
638// ListBySubscription handles requests to list all resources in a subscription.
639func (client ServicesClient) ListBySubscription(ctx context.Context) (result ServiceResourceListPage, err error) {
640	if tracing.IsEnabled() {
641		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListBySubscription")
642		defer func() {
643			sc := -1
644			if result.srl.Response.Response != nil {
645				sc = result.srl.Response.Response.StatusCode
646			}
647			tracing.EndSpan(ctx, sc, err)
648		}()
649	}
650	result.fn = client.listBySubscriptionNextResults
651	req, err := client.ListBySubscriptionPreparer(ctx)
652	if err != nil {
653		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "ListBySubscription", nil, "Failure preparing request")
654		return
655	}
656
657	resp, err := client.ListBySubscriptionSender(req)
658	if err != nil {
659		result.srl.Response = autorest.Response{Response: resp}
660		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "ListBySubscription", resp, "Failure sending request")
661		return
662	}
663
664	result.srl, err = client.ListBySubscriptionResponder(resp)
665	if err != nil {
666		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "ListBySubscription", resp, "Failure responding to request")
667		return
668	}
669	if result.srl.hasNextLink() && result.srl.IsEmpty() {
670		err = result.NextWithContext(ctx)
671		return
672	}
673
674	return
675}
676
677// ListBySubscriptionPreparer prepares the ListBySubscription request.
678func (client ServicesClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
679	pathParameters := map[string]interface{}{
680		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
681	}
682
683	const APIVersion = "2019-05-01-preview"
684	queryParameters := map[string]interface{}{
685		"api-version": APIVersion,
686	}
687
688	preparer := autorest.CreatePreparer(
689		autorest.AsGet(),
690		autorest.WithBaseURL(client.BaseURI),
691		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.AppPlatform/Spring", pathParameters),
692		autorest.WithQueryParameters(queryParameters))
693	return preparer.Prepare((&http.Request{}).WithContext(ctx))
694}
695
696// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
697// http.Response Body if it receives an error.
698func (client ServicesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
699	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
700}
701
702// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
703// closes the http.Response Body.
704func (client ServicesClient) ListBySubscriptionResponder(resp *http.Response) (result ServiceResourceList, err error) {
705	err = autorest.Respond(
706		resp,
707		azure.WithErrorUnlessStatusCode(http.StatusOK),
708		autorest.ByUnmarshallingJSON(&result),
709		autorest.ByClosing())
710	result.Response = autorest.Response{Response: resp}
711	return
712}
713
714// listBySubscriptionNextResults retrieves the next set of results, if any.
715func (client ServicesClient) listBySubscriptionNextResults(ctx context.Context, lastResults ServiceResourceList) (result ServiceResourceList, err error) {
716	req, err := lastResults.serviceResourceListPreparer(ctx)
717	if err != nil {
718		return result, autorest.NewErrorWithError(err, "appplatform.ServicesClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
719	}
720	if req == nil {
721		return
722	}
723	resp, err := client.ListBySubscriptionSender(req)
724	if err != nil {
725		result.Response = autorest.Response{Response: resp}
726		return result, autorest.NewErrorWithError(err, "appplatform.ServicesClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
727	}
728	result, err = client.ListBySubscriptionResponder(resp)
729	if err != nil {
730		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
731	}
732	return
733}
734
735// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
736func (client ServicesClient) ListBySubscriptionComplete(ctx context.Context) (result ServiceResourceListIterator, err error) {
737	if tracing.IsEnabled() {
738		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListBySubscription")
739		defer func() {
740			sc := -1
741			if result.Response().Response.Response != nil {
742				sc = result.page.Response().Response.Response.StatusCode
743			}
744			tracing.EndSpan(ctx, sc, err)
745		}()
746	}
747	result.page, err = client.ListBySubscription(ctx)
748	return
749}
750
751// ListTestKeys list test keys for a Service.
752// Parameters:
753// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
754// from the Azure Resource Manager API or the portal.
755// serviceName - the name of the Service resource.
756func (client ServicesClient) ListTestKeys(ctx context.Context, resourceGroupName string, serviceName string) (result TestKeys, err error) {
757	if tracing.IsEnabled() {
758		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListTestKeys")
759		defer func() {
760			sc := -1
761			if result.Response.Response != nil {
762				sc = result.Response.Response.StatusCode
763			}
764			tracing.EndSpan(ctx, sc, err)
765		}()
766	}
767	req, err := client.ListTestKeysPreparer(ctx, resourceGroupName, serviceName)
768	if err != nil {
769		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "ListTestKeys", nil, "Failure preparing request")
770		return
771	}
772
773	resp, err := client.ListTestKeysSender(req)
774	if err != nil {
775		result.Response = autorest.Response{Response: resp}
776		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "ListTestKeys", resp, "Failure sending request")
777		return
778	}
779
780	result, err = client.ListTestKeysResponder(resp)
781	if err != nil {
782		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "ListTestKeys", resp, "Failure responding to request")
783		return
784	}
785
786	return
787}
788
789// ListTestKeysPreparer prepares the ListTestKeys request.
790func (client ServicesClient) ListTestKeysPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) {
791	pathParameters := map[string]interface{}{
792		"resourceGroupName": autorest.Encode("path", resourceGroupName),
793		"serviceName":       autorest.Encode("path", serviceName),
794		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
795	}
796
797	const APIVersion = "2019-05-01-preview"
798	queryParameters := map[string]interface{}{
799		"api-version": APIVersion,
800	}
801
802	preparer := autorest.CreatePreparer(
803		autorest.AsPost(),
804		autorest.WithBaseURL(client.BaseURI),
805		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}/listTestKeys", pathParameters),
806		autorest.WithQueryParameters(queryParameters))
807	return preparer.Prepare((&http.Request{}).WithContext(ctx))
808}
809
810// ListTestKeysSender sends the ListTestKeys request. The method will close the
811// http.Response Body if it receives an error.
812func (client ServicesClient) ListTestKeysSender(req *http.Request) (*http.Response, error) {
813	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
814}
815
816// ListTestKeysResponder handles the response to the ListTestKeys request. The method always
817// closes the http.Response Body.
818func (client ServicesClient) ListTestKeysResponder(resp *http.Response) (result TestKeys, err error) {
819	err = autorest.Respond(
820		resp,
821		azure.WithErrorUnlessStatusCode(http.StatusOK),
822		autorest.ByUnmarshallingJSON(&result),
823		autorest.ByClosing())
824	result.Response = autorest.Response{Response: resp}
825	return
826}
827
828// RegenerateTestKey regenerate a test key for a Service.
829// Parameters:
830// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
831// from the Azure Resource Manager API or the portal.
832// serviceName - the name of the Service resource.
833// regenerateTestKeyRequest - parameters for the operation
834func (client ServicesClient) RegenerateTestKey(ctx context.Context, resourceGroupName string, serviceName string, regenerateTestKeyRequest RegenerateTestKeyRequestPayload) (result TestKeys, err error) {
835	if tracing.IsEnabled() {
836		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.RegenerateTestKey")
837		defer func() {
838			sc := -1
839			if result.Response.Response != nil {
840				sc = result.Response.Response.StatusCode
841			}
842			tracing.EndSpan(ctx, sc, err)
843		}()
844	}
845	req, err := client.RegenerateTestKeyPreparer(ctx, resourceGroupName, serviceName, regenerateTestKeyRequest)
846	if err != nil {
847		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "RegenerateTestKey", nil, "Failure preparing request")
848		return
849	}
850
851	resp, err := client.RegenerateTestKeySender(req)
852	if err != nil {
853		result.Response = autorest.Response{Response: resp}
854		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "RegenerateTestKey", resp, "Failure sending request")
855		return
856	}
857
858	result, err = client.RegenerateTestKeyResponder(resp)
859	if err != nil {
860		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "RegenerateTestKey", resp, "Failure responding to request")
861		return
862	}
863
864	return
865}
866
867// RegenerateTestKeyPreparer prepares the RegenerateTestKey request.
868func (client ServicesClient) RegenerateTestKeyPreparer(ctx context.Context, resourceGroupName string, serviceName string, regenerateTestKeyRequest RegenerateTestKeyRequestPayload) (*http.Request, error) {
869	pathParameters := map[string]interface{}{
870		"resourceGroupName": autorest.Encode("path", resourceGroupName),
871		"serviceName":       autorest.Encode("path", serviceName),
872		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
873	}
874
875	const APIVersion = "2019-05-01-preview"
876	queryParameters := map[string]interface{}{
877		"api-version": APIVersion,
878	}
879
880	preparer := autorest.CreatePreparer(
881		autorest.AsContentType("application/json; charset=utf-8"),
882		autorest.AsPost(),
883		autorest.WithBaseURL(client.BaseURI),
884		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}/regenerateTestKey", pathParameters),
885		autorest.WithJSON(regenerateTestKeyRequest),
886		autorest.WithQueryParameters(queryParameters))
887	return preparer.Prepare((&http.Request{}).WithContext(ctx))
888}
889
890// RegenerateTestKeySender sends the RegenerateTestKey request. The method will close the
891// http.Response Body if it receives an error.
892func (client ServicesClient) RegenerateTestKeySender(req *http.Request) (*http.Response, error) {
893	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
894}
895
896// RegenerateTestKeyResponder handles the response to the RegenerateTestKey request. The method always
897// closes the http.Response Body.
898func (client ServicesClient) RegenerateTestKeyResponder(resp *http.Response) (result TestKeys, err error) {
899	err = autorest.Respond(
900		resp,
901		azure.WithErrorUnlessStatusCode(http.StatusOK),
902		autorest.ByUnmarshallingJSON(&result),
903		autorest.ByClosing())
904	result.Response = autorest.Response{Response: resp}
905	return
906}
907
908// Update operation to update an exiting Service.
909// Parameters:
910// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
911// from the Azure Resource Manager API or the portal.
912// serviceName - the name of the Service resource.
913// resource - parameters for the update operation
914func (client ServicesClient) Update(ctx context.Context, resourceGroupName string, serviceName string, resource ServiceResource) (result ServicesUpdateFuture, err error) {
915	if tracing.IsEnabled() {
916		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Update")
917		defer func() {
918			sc := -1
919			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
920				sc = result.FutureAPI.Response().StatusCode
921			}
922			tracing.EndSpan(ctx, sc, err)
923		}()
924	}
925	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, resource)
926	if err != nil {
927		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Update", nil, "Failure preparing request")
928		return
929	}
930
931	result, err = client.UpdateSender(req)
932	if err != nil {
933		err = autorest.NewErrorWithError(err, "appplatform.ServicesClient", "Update", nil, "Failure sending request")
934		return
935	}
936
937	return
938}
939
940// UpdatePreparer prepares the Update request.
941func (client ServicesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, resource ServiceResource) (*http.Request, error) {
942	pathParameters := map[string]interface{}{
943		"resourceGroupName": autorest.Encode("path", resourceGroupName),
944		"serviceName":       autorest.Encode("path", serviceName),
945		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
946	}
947
948	const APIVersion = "2019-05-01-preview"
949	queryParameters := map[string]interface{}{
950		"api-version": APIVersion,
951	}
952
953	preparer := autorest.CreatePreparer(
954		autorest.AsContentType("application/json; charset=utf-8"),
955		autorest.AsPatch(),
956		autorest.WithBaseURL(client.BaseURI),
957		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Spring/{serviceName}", pathParameters),
958		autorest.WithJSON(resource),
959		autorest.WithQueryParameters(queryParameters))
960	return preparer.Prepare((&http.Request{}).WithContext(ctx))
961}
962
963// UpdateSender sends the Update request. The method will close the
964// http.Response Body if it receives an error.
965func (client ServicesClient) UpdateSender(req *http.Request) (future ServicesUpdateFuture, err error) {
966	var resp *http.Response
967	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
968	if err != nil {
969		return
970	}
971	var azf azure.Future
972	azf, err = azure.NewFutureFromResponse(resp)
973	future.FutureAPI = &azf
974	future.Result = future.result
975	return
976}
977
978// UpdateResponder handles the response to the Update request. The method always
979// closes the http.Response Body.
980func (client ServicesClient) UpdateResponder(resp *http.Response) (result ServiceResource, err error) {
981	err = autorest.Respond(
982		resp,
983		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
984		autorest.ByUnmarshallingJSON(&result),
985		autorest.ByClosing())
986	result.Response = autorest.Response{Response: resp}
987	return
988}
989