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