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