1package apimanagement
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// CacheClient is the apiManagement Client
19type CacheClient struct {
20	BaseClient
21}
22
23// NewCacheClient creates an instance of the CacheClient client.
24func NewCacheClient(subscriptionID string) CacheClient {
25	return NewCacheClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewCacheClientWithBaseURI creates an instance of the CacheClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewCacheClientWithBaseURI(baseURI string, subscriptionID string) CacheClient {
31	return CacheClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or updates an External Cache to be used in Api Management instance.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
39// identifier).
40// parameters - create or Update parameters.
41// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
42func (client CacheClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheContract, ifMatch string) (result CacheContract, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.CreateOrUpdate")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: serviceName,
55			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
56				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
57				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
58		{TargetValue: cacheID,
59			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
60				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
61				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
62		{TargetValue: parameters,
63			Constraints: []validation.Constraint{{Target: "parameters.CacheContractProperties", Name: validation.Null, Rule: false,
64				Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.Description", Name: validation.Null, Rule: false,
65					Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.Description", Name: validation.MaxLength, Rule: 2000, Chain: nil}}},
66					{Target: "parameters.CacheContractProperties.ConnectionString", Name: validation.Null, Rule: true,
67						Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.ConnectionString", Name: validation.MaxLength, Rule: 300, Chain: nil}}},
68					{Target: "parameters.CacheContractProperties.ResourceID", Name: validation.Null, Rule: false,
69						Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.ResourceID", Name: validation.MaxLength, Rule: 2000, Chain: nil}}},
70				}}}}}); err != nil {
71		return result, validation.NewError("apimanagement.CacheClient", "CreateOrUpdate", err.Error())
72	}
73
74	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, cacheID, parameters, ifMatch)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "CreateOrUpdate", nil, "Failure preparing request")
77		return
78	}
79
80	resp, err := client.CreateOrUpdateSender(req)
81	if err != nil {
82		result.Response = autorest.Response{Response: resp}
83		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "CreateOrUpdate", resp, "Failure sending request")
84		return
85	}
86
87	result, err = client.CreateOrUpdateResponder(resp)
88	if err != nil {
89		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "CreateOrUpdate", resp, "Failure responding to request")
90		return
91	}
92
93	return
94}
95
96// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
97func (client CacheClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheContract, ifMatch string) (*http.Request, error) {
98	pathParameters := map[string]interface{}{
99		"cacheId":           autorest.Encode("path", cacheID),
100		"resourceGroupName": autorest.Encode("path", resourceGroupName),
101		"serviceName":       autorest.Encode("path", serviceName),
102		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
103	}
104
105	const APIVersion = "2019-12-01-preview"
106	queryParameters := map[string]interface{}{
107		"api-version": APIVersion,
108	}
109
110	preparer := autorest.CreatePreparer(
111		autorest.AsContentType("application/json; charset=utf-8"),
112		autorest.AsPut(),
113		autorest.WithBaseURL(client.BaseURI),
114		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
115		autorest.WithJSON(parameters),
116		autorest.WithQueryParameters(queryParameters))
117	if len(ifMatch) > 0 {
118		preparer = autorest.DecoratePreparer(preparer,
119			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
120	}
121	return preparer.Prepare((&http.Request{}).WithContext(ctx))
122}
123
124// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
125// http.Response Body if it receives an error.
126func (client CacheClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
127	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
128}
129
130// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
131// closes the http.Response Body.
132func (client CacheClient) CreateOrUpdateResponder(resp *http.Response) (result CacheContract, err error) {
133	err = autorest.Respond(
134		resp,
135		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
136		autorest.ByUnmarshallingJSON(&result),
137		autorest.ByClosing())
138	result.Response = autorest.Response{Response: resp}
139	return
140}
141
142// Delete deletes specific Cache.
143// Parameters:
144// resourceGroupName - the name of the resource group.
145// serviceName - the name of the API Management service.
146// cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
147// identifier).
148// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
149// request or it should be * for unconditional update.
150func (client CacheClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, ifMatch string) (result autorest.Response, err error) {
151	if tracing.IsEnabled() {
152		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.Delete")
153		defer func() {
154			sc := -1
155			if result.Response != nil {
156				sc = result.Response.StatusCode
157			}
158			tracing.EndSpan(ctx, sc, err)
159		}()
160	}
161	if err := validation.Validate([]validation.Validation{
162		{TargetValue: serviceName,
163			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
164				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
165				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
166		{TargetValue: cacheID,
167			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
168				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
169				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
170		return result, validation.NewError("apimanagement.CacheClient", "Delete", err.Error())
171	}
172
173	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, cacheID, ifMatch)
174	if err != nil {
175		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Delete", nil, "Failure preparing request")
176		return
177	}
178
179	resp, err := client.DeleteSender(req)
180	if err != nil {
181		result.Response = resp
182		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Delete", resp, "Failure sending request")
183		return
184	}
185
186	result, err = client.DeleteResponder(resp)
187	if err != nil {
188		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Delete", resp, "Failure responding to request")
189		return
190	}
191
192	return
193}
194
195// DeletePreparer prepares the Delete request.
196func (client CacheClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, ifMatch string) (*http.Request, error) {
197	pathParameters := map[string]interface{}{
198		"cacheId":           autorest.Encode("path", cacheID),
199		"resourceGroupName": autorest.Encode("path", resourceGroupName),
200		"serviceName":       autorest.Encode("path", serviceName),
201		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
202	}
203
204	const APIVersion = "2019-12-01-preview"
205	queryParameters := map[string]interface{}{
206		"api-version": APIVersion,
207	}
208
209	preparer := autorest.CreatePreparer(
210		autorest.AsDelete(),
211		autorest.WithBaseURL(client.BaseURI),
212		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
213		autorest.WithQueryParameters(queryParameters),
214		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
215	return preparer.Prepare((&http.Request{}).WithContext(ctx))
216}
217
218// DeleteSender sends the Delete request. The method will close the
219// http.Response Body if it receives an error.
220func (client CacheClient) DeleteSender(req *http.Request) (*http.Response, error) {
221	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
222}
223
224// DeleteResponder handles the response to the Delete request. The method always
225// closes the http.Response Body.
226func (client CacheClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
227	err = autorest.Respond(
228		resp,
229		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
230		autorest.ByClosing())
231	result.Response = resp
232	return
233}
234
235// Get gets the details of the Cache specified by its identifier.
236// Parameters:
237// resourceGroupName - the name of the resource group.
238// serviceName - the name of the API Management service.
239// cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
240// identifier).
241func (client CacheClient) Get(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (result CacheContract, err error) {
242	if tracing.IsEnabled() {
243		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.Get")
244		defer func() {
245			sc := -1
246			if result.Response.Response != nil {
247				sc = result.Response.Response.StatusCode
248			}
249			tracing.EndSpan(ctx, sc, err)
250		}()
251	}
252	if err := validation.Validate([]validation.Validation{
253		{TargetValue: serviceName,
254			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
255				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
256				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
257		{TargetValue: cacheID,
258			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
259				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
260				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
261		return result, validation.NewError("apimanagement.CacheClient", "Get", err.Error())
262	}
263
264	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, cacheID)
265	if err != nil {
266		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Get", nil, "Failure preparing request")
267		return
268	}
269
270	resp, err := client.GetSender(req)
271	if err != nil {
272		result.Response = autorest.Response{Response: resp}
273		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Get", resp, "Failure sending request")
274		return
275	}
276
277	result, err = client.GetResponder(resp)
278	if err != nil {
279		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Get", resp, "Failure responding to request")
280		return
281	}
282
283	return
284}
285
286// GetPreparer prepares the Get request.
287func (client CacheClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (*http.Request, error) {
288	pathParameters := map[string]interface{}{
289		"cacheId":           autorest.Encode("path", cacheID),
290		"resourceGroupName": autorest.Encode("path", resourceGroupName),
291		"serviceName":       autorest.Encode("path", serviceName),
292		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
293	}
294
295	const APIVersion = "2019-12-01-preview"
296	queryParameters := map[string]interface{}{
297		"api-version": APIVersion,
298	}
299
300	preparer := autorest.CreatePreparer(
301		autorest.AsGet(),
302		autorest.WithBaseURL(client.BaseURI),
303		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
304		autorest.WithQueryParameters(queryParameters))
305	return preparer.Prepare((&http.Request{}).WithContext(ctx))
306}
307
308// GetSender sends the Get request. The method will close the
309// http.Response Body if it receives an error.
310func (client CacheClient) GetSender(req *http.Request) (*http.Response, error) {
311	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
312}
313
314// GetResponder handles the response to the Get request. The method always
315// closes the http.Response Body.
316func (client CacheClient) GetResponder(resp *http.Response) (result CacheContract, err error) {
317	err = autorest.Respond(
318		resp,
319		azure.WithErrorUnlessStatusCode(http.StatusOK),
320		autorest.ByUnmarshallingJSON(&result),
321		autorest.ByClosing())
322	result.Response = autorest.Response{Response: resp}
323	return
324}
325
326// GetEntityTag gets the entity state (Etag) version of the Cache specified by its identifier.
327// Parameters:
328// resourceGroupName - the name of the resource group.
329// serviceName - the name of the API Management service.
330// cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
331// identifier).
332func (client CacheClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (result autorest.Response, err error) {
333	if tracing.IsEnabled() {
334		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.GetEntityTag")
335		defer func() {
336			sc := -1
337			if result.Response != nil {
338				sc = result.Response.StatusCode
339			}
340			tracing.EndSpan(ctx, sc, err)
341		}()
342	}
343	if err := validation.Validate([]validation.Validation{
344		{TargetValue: serviceName,
345			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
346				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
347				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
348		{TargetValue: cacheID,
349			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
350				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
351				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
352		return result, validation.NewError("apimanagement.CacheClient", "GetEntityTag", err.Error())
353	}
354
355	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, cacheID)
356	if err != nil {
357		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "GetEntityTag", nil, "Failure preparing request")
358		return
359	}
360
361	resp, err := client.GetEntityTagSender(req)
362	if err != nil {
363		result.Response = resp
364		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "GetEntityTag", resp, "Failure sending request")
365		return
366	}
367
368	result, err = client.GetEntityTagResponder(resp)
369	if err != nil {
370		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "GetEntityTag", resp, "Failure responding to request")
371		return
372	}
373
374	return
375}
376
377// GetEntityTagPreparer prepares the GetEntityTag request.
378func (client CacheClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (*http.Request, error) {
379	pathParameters := map[string]interface{}{
380		"cacheId":           autorest.Encode("path", cacheID),
381		"resourceGroupName": autorest.Encode("path", resourceGroupName),
382		"serviceName":       autorest.Encode("path", serviceName),
383		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
384	}
385
386	const APIVersion = "2019-12-01-preview"
387	queryParameters := map[string]interface{}{
388		"api-version": APIVersion,
389	}
390
391	preparer := autorest.CreatePreparer(
392		autorest.AsHead(),
393		autorest.WithBaseURL(client.BaseURI),
394		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
395		autorest.WithQueryParameters(queryParameters))
396	return preparer.Prepare((&http.Request{}).WithContext(ctx))
397}
398
399// GetEntityTagSender sends the GetEntityTag request. The method will close the
400// http.Response Body if it receives an error.
401func (client CacheClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
402	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
403}
404
405// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
406// closes the http.Response Body.
407func (client CacheClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
408	err = autorest.Respond(
409		resp,
410		azure.WithErrorUnlessStatusCode(http.StatusOK),
411		autorest.ByClosing())
412	result.Response = resp
413	return
414}
415
416// ListByService lists a collection of all external Caches in the specified service instance.
417// Parameters:
418// resourceGroupName - the name of the resource group.
419// serviceName - the name of the API Management service.
420// top - number of records to return.
421// skip - number of records to skip.
422func (client CacheClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result CacheCollectionPage, err error) {
423	if tracing.IsEnabled() {
424		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.ListByService")
425		defer func() {
426			sc := -1
427			if result.cc.Response.Response != nil {
428				sc = result.cc.Response.Response.StatusCode
429			}
430			tracing.EndSpan(ctx, sc, err)
431		}()
432	}
433	if err := validation.Validate([]validation.Validation{
434		{TargetValue: serviceName,
435			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
436				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
437				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
438		{TargetValue: top,
439			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
440				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
441		{TargetValue: skip,
442			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
443				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
444		return result, validation.NewError("apimanagement.CacheClient", "ListByService", err.Error())
445	}
446
447	result.fn = client.listByServiceNextResults
448	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, top, skip)
449	if err != nil {
450		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "ListByService", nil, "Failure preparing request")
451		return
452	}
453
454	resp, err := client.ListByServiceSender(req)
455	if err != nil {
456		result.cc.Response = autorest.Response{Response: resp}
457		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "ListByService", resp, "Failure sending request")
458		return
459	}
460
461	result.cc, err = client.ListByServiceResponder(resp)
462	if err != nil {
463		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "ListByService", resp, "Failure responding to request")
464		return
465	}
466	if result.cc.hasNextLink() && result.cc.IsEmpty() {
467		err = result.NextWithContext(ctx)
468		return
469	}
470
471	return
472}
473
474// ListByServicePreparer prepares the ListByService request.
475func (client CacheClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (*http.Request, error) {
476	pathParameters := map[string]interface{}{
477		"resourceGroupName": autorest.Encode("path", resourceGroupName),
478		"serviceName":       autorest.Encode("path", serviceName),
479		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
480	}
481
482	const APIVersion = "2019-12-01-preview"
483	queryParameters := map[string]interface{}{
484		"api-version": APIVersion,
485	}
486	if top != nil {
487		queryParameters["$top"] = autorest.Encode("query", *top)
488	}
489	if skip != nil {
490		queryParameters["$skip"] = autorest.Encode("query", *skip)
491	}
492
493	preparer := autorest.CreatePreparer(
494		autorest.AsGet(),
495		autorest.WithBaseURL(client.BaseURI),
496		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches", pathParameters),
497		autorest.WithQueryParameters(queryParameters))
498	return preparer.Prepare((&http.Request{}).WithContext(ctx))
499}
500
501// ListByServiceSender sends the ListByService request. The method will close the
502// http.Response Body if it receives an error.
503func (client CacheClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
504	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
505}
506
507// ListByServiceResponder handles the response to the ListByService request. The method always
508// closes the http.Response Body.
509func (client CacheClient) ListByServiceResponder(resp *http.Response) (result CacheCollection, err error) {
510	err = autorest.Respond(
511		resp,
512		azure.WithErrorUnlessStatusCode(http.StatusOK),
513		autorest.ByUnmarshallingJSON(&result),
514		autorest.ByClosing())
515	result.Response = autorest.Response{Response: resp}
516	return
517}
518
519// listByServiceNextResults retrieves the next set of results, if any.
520func (client CacheClient) listByServiceNextResults(ctx context.Context, lastResults CacheCollection) (result CacheCollection, err error) {
521	req, err := lastResults.cacheCollectionPreparer(ctx)
522	if err != nil {
523		return result, autorest.NewErrorWithError(err, "apimanagement.CacheClient", "listByServiceNextResults", nil, "Failure preparing next results request")
524	}
525	if req == nil {
526		return
527	}
528	resp, err := client.ListByServiceSender(req)
529	if err != nil {
530		result.Response = autorest.Response{Response: resp}
531		return result, autorest.NewErrorWithError(err, "apimanagement.CacheClient", "listByServiceNextResults", resp, "Failure sending next results request")
532	}
533	result, err = client.ListByServiceResponder(resp)
534	if err != nil {
535		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "listByServiceNextResults", resp, "Failure responding to next results request")
536	}
537	return
538}
539
540// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
541func (client CacheClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result CacheCollectionIterator, err error) {
542	if tracing.IsEnabled() {
543		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.ListByService")
544		defer func() {
545			sc := -1
546			if result.Response().Response.Response != nil {
547				sc = result.page.Response().Response.Response.StatusCode
548			}
549			tracing.EndSpan(ctx, sc, err)
550		}()
551	}
552	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, top, skip)
553	return
554}
555
556// Update updates the details of the cache specified by its identifier.
557// Parameters:
558// resourceGroupName - the name of the resource group.
559// serviceName - the name of the API Management service.
560// cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
561// identifier).
562// parameters - update parameters.
563// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
564// request or it should be * for unconditional update.
565func (client CacheClient) Update(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheUpdateParameters, ifMatch string) (result autorest.Response, err error) {
566	if tracing.IsEnabled() {
567		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.Update")
568		defer func() {
569			sc := -1
570			if result.Response != nil {
571				sc = result.Response.StatusCode
572			}
573			tracing.EndSpan(ctx, sc, err)
574		}()
575	}
576	if err := validation.Validate([]validation.Validation{
577		{TargetValue: serviceName,
578			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
579				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
580				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
581		{TargetValue: cacheID,
582			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
583				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
584				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
585		return result, validation.NewError("apimanagement.CacheClient", "Update", err.Error())
586	}
587
588	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, cacheID, parameters, ifMatch)
589	if err != nil {
590		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Update", nil, "Failure preparing request")
591		return
592	}
593
594	resp, err := client.UpdateSender(req)
595	if err != nil {
596		result.Response = resp
597		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Update", resp, "Failure sending request")
598		return
599	}
600
601	result, err = client.UpdateResponder(resp)
602	if err != nil {
603		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Update", resp, "Failure responding to request")
604		return
605	}
606
607	return
608}
609
610// UpdatePreparer prepares the Update request.
611func (client CacheClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheUpdateParameters, ifMatch string) (*http.Request, error) {
612	pathParameters := map[string]interface{}{
613		"cacheId":           autorest.Encode("path", cacheID),
614		"resourceGroupName": autorest.Encode("path", resourceGroupName),
615		"serviceName":       autorest.Encode("path", serviceName),
616		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
617	}
618
619	const APIVersion = "2019-12-01-preview"
620	queryParameters := map[string]interface{}{
621		"api-version": APIVersion,
622	}
623
624	preparer := autorest.CreatePreparer(
625		autorest.AsContentType("application/json; charset=utf-8"),
626		autorest.AsPatch(),
627		autorest.WithBaseURL(client.BaseURI),
628		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
629		autorest.WithJSON(parameters),
630		autorest.WithQueryParameters(queryParameters),
631		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
632	return preparer.Prepare((&http.Request{}).WithContext(ctx))
633}
634
635// UpdateSender sends the Update request. The method will close the
636// http.Response Body if it receives an error.
637func (client CacheClient) UpdateSender(req *http.Request) (*http.Response, error) {
638	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
639}
640
641// UpdateResponder handles the response to the Update request. The method always
642// closes the http.Response Body.
643func (client CacheClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
644	err = autorest.Respond(
645		resp,
646		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
647		autorest.ByClosing())
648	result.Response = resp
649	return
650}
651