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// GroupClient is the apiManagement Client
19type GroupClient struct {
20	BaseClient
21}
22
23// NewGroupClient creates an instance of the GroupClient client.
24func NewGroupClient(subscriptionID string) GroupClient {
25	return NewGroupClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewGroupClientWithBaseURI creates an instance of the GroupClient 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 NewGroupClientWithBaseURI(baseURI string, subscriptionID string) GroupClient {
31	return GroupClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or Updates a group.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// groupID - group identifier. Must be unique in the current API Management service instance.
39// parameters - create parameters.
40// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
41func (client GroupClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, groupID string, parameters GroupCreateParameters, ifMatch string) (result GroupContract, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.Response.Response != nil {
47				sc = result.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: serviceName,
54			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
57		{TargetValue: groupID,
58			Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil},
59				{Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
60		{TargetValue: parameters,
61			Constraints: []validation.Constraint{{Target: "parameters.GroupCreateParametersProperties", Name: validation.Null, Rule: false,
62				Chain: []validation.Constraint{{Target: "parameters.GroupCreateParametersProperties.DisplayName", Name: validation.Null, Rule: true,
63					Chain: []validation.Constraint{{Target: "parameters.GroupCreateParametersProperties.DisplayName", Name: validation.MaxLength, Rule: 300, Chain: nil},
64						{Target: "parameters.GroupCreateParametersProperties.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil},
65					}},
66				}}}}}); err != nil {
67		return result, validation.NewError("apimanagement.GroupClient", "CreateOrUpdate", err.Error())
68	}
69
70	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, groupID, parameters, ifMatch)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "CreateOrUpdate", nil, "Failure preparing request")
73		return
74	}
75
76	resp, err := client.CreateOrUpdateSender(req)
77	if err != nil {
78		result.Response = autorest.Response{Response: resp}
79		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "CreateOrUpdate", resp, "Failure sending request")
80		return
81	}
82
83	result, err = client.CreateOrUpdateResponder(resp)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "CreateOrUpdate", resp, "Failure responding to request")
86		return
87	}
88
89	return
90}
91
92// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
93func (client GroupClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, parameters GroupCreateParameters, ifMatch string) (*http.Request, error) {
94	pathParameters := map[string]interface{}{
95		"groupId":           autorest.Encode("path", groupID),
96		"resourceGroupName": autorest.Encode("path", resourceGroupName),
97		"serviceName":       autorest.Encode("path", serviceName),
98		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
99	}
100
101	const APIVersion = "2021-01-01-preview"
102	queryParameters := map[string]interface{}{
103		"api-version": APIVersion,
104	}
105
106	preparer := autorest.CreatePreparer(
107		autorest.AsContentType("application/json; charset=utf-8"),
108		autorest.AsPut(),
109		autorest.WithBaseURL(client.BaseURI),
110		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups/{groupId}", pathParameters),
111		autorest.WithJSON(parameters),
112		autorest.WithQueryParameters(queryParameters))
113	if len(ifMatch) > 0 {
114		preparer = autorest.DecoratePreparer(preparer,
115			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
116	}
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 GroupClient) 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 GroupClient) CreateOrUpdateResponder(resp *http.Response) (result GroupContract, 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 group of 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// groupID - group identifier. Must be unique in the current API Management service instance.
143// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
144// request or it should be * for unconditional update.
145func (client GroupClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, groupID string, ifMatch string) (result autorest.Response, err error) {
146	if tracing.IsEnabled() {
147		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.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: groupID,
162			Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil},
163				{Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
164		return result, validation.NewError("apimanagement.GroupClient", "Delete", err.Error())
165	}
166
167	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, groupID, ifMatch)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "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.GroupClient", "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.GroupClient", "Delete", resp, "Failure responding to request")
183		return
184	}
185
186	return
187}
188
189// DeletePreparer prepares the Delete request.
190func (client GroupClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, ifMatch string) (*http.Request, error) {
191	pathParameters := map[string]interface{}{
192		"groupId":           autorest.Encode("path", groupID),
193		"resourceGroupName": autorest.Encode("path", resourceGroupName),
194		"serviceName":       autorest.Encode("path", serviceName),
195		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
196	}
197
198	const APIVersion = "2021-01-01-preview"
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}/groups/{groupId}", 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 GroupClient) 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 GroupClient) 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 group specified by its identifier.
230// Parameters:
231// resourceGroupName - the name of the resource group.
232// serviceName - the name of the API Management service.
233// groupID - group identifier. Must be unique in the current API Management service instance.
234func (client GroupClient) Get(ctx context.Context, resourceGroupName string, serviceName string, groupID string) (result GroupContract, err error) {
235	if tracing.IsEnabled() {
236		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.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: groupID,
251			Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil},
252				{Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
253		return result, validation.NewError("apimanagement.GroupClient", "Get", err.Error())
254	}
255
256	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, groupID)
257	if err != nil {
258		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "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.GroupClient", "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.GroupClient", "Get", resp, "Failure responding to request")
272		return
273	}
274
275	return
276}
277
278// GetPreparer prepares the Get request.
279func (client GroupClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string) (*http.Request, error) {
280	pathParameters := map[string]interface{}{
281		"groupId":           autorest.Encode("path", groupID),
282		"resourceGroupName": autorest.Encode("path", resourceGroupName),
283		"serviceName":       autorest.Encode("path", serviceName),
284		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
285	}
286
287	const APIVersion = "2021-01-01-preview"
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}/groups/{groupId}", 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 GroupClient) 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 GroupClient) GetResponder(resp *http.Response) (result GroupContract, 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 group specified by its identifier.
319// Parameters:
320// resourceGroupName - the name of the resource group.
321// serviceName - the name of the API Management service.
322// groupID - group identifier. Must be unique in the current API Management service instance.
323func (client GroupClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, groupID string) (result autorest.Response, err error) {
324	if tracing.IsEnabled() {
325		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.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: groupID,
340			Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil},
341				{Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
342		return result, validation.NewError("apimanagement.GroupClient", "GetEntityTag", err.Error())
343	}
344
345	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, groupID)
346	if err != nil {
347		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "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.GroupClient", "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.GroupClient", "GetEntityTag", resp, "Failure responding to request")
361		return
362	}
363
364	return
365}
366
367// GetEntityTagPreparer prepares the GetEntityTag request.
368func (client GroupClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string) (*http.Request, error) {
369	pathParameters := map[string]interface{}{
370		"groupId":           autorest.Encode("path", groupID),
371		"resourceGroupName": autorest.Encode("path", resourceGroupName),
372		"serviceName":       autorest.Encode("path", serviceName),
373		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
374	}
375
376	const APIVersion = "2021-01-01-preview"
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}/groups/{groupId}", 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 GroupClient) 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 GroupClient) 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 groups 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     |     Usage     |     Supported operators     |     Supported functions
411// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
412// | substringof, contains, startswith, endswith |</br>| displayName | filter | ge, le, eq, ne, gt, lt |
413// substringof, contains, startswith, endswith |</br>| description | filter | ge, le, eq, ne, gt, lt |
414// substringof, contains, startswith, endswith |</br>| externalId | filter | eq |     |</br>
415// top - number of records to return.
416// skip - number of records to skip.
417func (client GroupClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result GroupCollectionPage, err error) {
418	if tracing.IsEnabled() {
419		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.ListByService")
420		defer func() {
421			sc := -1
422			if result.gc.Response.Response != nil {
423				sc = result.gc.Response.Response.StatusCode
424			}
425			tracing.EndSpan(ctx, sc, err)
426		}()
427	}
428	if err := validation.Validate([]validation.Validation{
429		{TargetValue: serviceName,
430			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
431				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
432				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
433		{TargetValue: top,
434			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
435				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
436		{TargetValue: skip,
437			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
438				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
439		return result, validation.NewError("apimanagement.GroupClient", "ListByService", err.Error())
440	}
441
442	result.fn = client.listByServiceNextResults
443	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
444	if err != nil {
445		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "ListByService", nil, "Failure preparing request")
446		return
447	}
448
449	resp, err := client.ListByServiceSender(req)
450	if err != nil {
451		result.gc.Response = autorest.Response{Response: resp}
452		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "ListByService", resp, "Failure sending request")
453		return
454	}
455
456	result.gc, err = client.ListByServiceResponder(resp)
457	if err != nil {
458		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "ListByService", resp, "Failure responding to request")
459		return
460	}
461	if result.gc.hasNextLink() && result.gc.IsEmpty() {
462		err = result.NextWithContext(ctx)
463		return
464	}
465
466	return
467}
468
469// ListByServicePreparer prepares the ListByService request.
470func (client GroupClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
471	pathParameters := map[string]interface{}{
472		"resourceGroupName": autorest.Encode("path", resourceGroupName),
473		"serviceName":       autorest.Encode("path", serviceName),
474		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
475	}
476
477	const APIVersion = "2021-01-01-preview"
478	queryParameters := map[string]interface{}{
479		"api-version": APIVersion,
480	}
481	if len(filter) > 0 {
482		queryParameters["$filter"] = autorest.Encode("query", filter)
483	}
484	if top != nil {
485		queryParameters["$top"] = autorest.Encode("query", *top)
486	}
487	if skip != nil {
488		queryParameters["$skip"] = autorest.Encode("query", *skip)
489	}
490
491	preparer := autorest.CreatePreparer(
492		autorest.AsGet(),
493		autorest.WithBaseURL(client.BaseURI),
494		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups", pathParameters),
495		autorest.WithQueryParameters(queryParameters))
496	return preparer.Prepare((&http.Request{}).WithContext(ctx))
497}
498
499// ListByServiceSender sends the ListByService request. The method will close the
500// http.Response Body if it receives an error.
501func (client GroupClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
502	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
503}
504
505// ListByServiceResponder handles the response to the ListByService request. The method always
506// closes the http.Response Body.
507func (client GroupClient) ListByServiceResponder(resp *http.Response) (result GroupCollection, err error) {
508	err = autorest.Respond(
509		resp,
510		azure.WithErrorUnlessStatusCode(http.StatusOK),
511		autorest.ByUnmarshallingJSON(&result),
512		autorest.ByClosing())
513	result.Response = autorest.Response{Response: resp}
514	return
515}
516
517// listByServiceNextResults retrieves the next set of results, if any.
518func (client GroupClient) listByServiceNextResults(ctx context.Context, lastResults GroupCollection) (result GroupCollection, err error) {
519	req, err := lastResults.groupCollectionPreparer(ctx)
520	if err != nil {
521		return result, autorest.NewErrorWithError(err, "apimanagement.GroupClient", "listByServiceNextResults", nil, "Failure preparing next results request")
522	}
523	if req == nil {
524		return
525	}
526	resp, err := client.ListByServiceSender(req)
527	if err != nil {
528		result.Response = autorest.Response{Response: resp}
529		return result, autorest.NewErrorWithError(err, "apimanagement.GroupClient", "listByServiceNextResults", resp, "Failure sending next results request")
530	}
531	result, err = client.ListByServiceResponder(resp)
532	if err != nil {
533		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "listByServiceNextResults", resp, "Failure responding to next results request")
534	}
535	return
536}
537
538// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
539func (client GroupClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result GroupCollectionIterator, err error) {
540	if tracing.IsEnabled() {
541		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.ListByService")
542		defer func() {
543			sc := -1
544			if result.Response().Response.Response != nil {
545				sc = result.page.Response().Response.Response.StatusCode
546			}
547			tracing.EndSpan(ctx, sc, err)
548		}()
549	}
550	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
551	return
552}
553
554// Update updates the details of the group specified by its identifier.
555// Parameters:
556// resourceGroupName - the name of the resource group.
557// serviceName - the name of the API Management service.
558// groupID - group identifier. Must be unique in the current API Management service instance.
559// parameters - update parameters.
560// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
561// request or it should be * for unconditional update.
562func (client GroupClient) Update(ctx context.Context, resourceGroupName string, serviceName string, groupID string, parameters GroupUpdateParameters, ifMatch string) (result GroupContract, err error) {
563	if tracing.IsEnabled() {
564		ctx = tracing.StartSpan(ctx, fqdn+"/GroupClient.Update")
565		defer func() {
566			sc := -1
567			if result.Response.Response != nil {
568				sc = result.Response.Response.StatusCode
569			}
570			tracing.EndSpan(ctx, sc, err)
571		}()
572	}
573	if err := validation.Validate([]validation.Validation{
574		{TargetValue: serviceName,
575			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
576				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
577				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
578		{TargetValue: groupID,
579			Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil},
580				{Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
581		return result, validation.NewError("apimanagement.GroupClient", "Update", err.Error())
582	}
583
584	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, groupID, parameters, ifMatch)
585	if err != nil {
586		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "Update", nil, "Failure preparing request")
587		return
588	}
589
590	resp, err := client.UpdateSender(req)
591	if err != nil {
592		result.Response = autorest.Response{Response: resp}
593		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "Update", resp, "Failure sending request")
594		return
595	}
596
597	result, err = client.UpdateResponder(resp)
598	if err != nil {
599		err = autorest.NewErrorWithError(err, "apimanagement.GroupClient", "Update", resp, "Failure responding to request")
600		return
601	}
602
603	return
604}
605
606// UpdatePreparer prepares the Update request.
607func (client GroupClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, parameters GroupUpdateParameters, ifMatch string) (*http.Request, error) {
608	pathParameters := map[string]interface{}{
609		"groupId":           autorest.Encode("path", groupID),
610		"resourceGroupName": autorest.Encode("path", resourceGroupName),
611		"serviceName":       autorest.Encode("path", serviceName),
612		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
613	}
614
615	const APIVersion = "2021-01-01-preview"
616	queryParameters := map[string]interface{}{
617		"api-version": APIVersion,
618	}
619
620	preparer := autorest.CreatePreparer(
621		autorest.AsContentType("application/json; charset=utf-8"),
622		autorest.AsPatch(),
623		autorest.WithBaseURL(client.BaseURI),
624		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups/{groupId}", pathParameters),
625		autorest.WithJSON(parameters),
626		autorest.WithQueryParameters(queryParameters),
627		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
628	return preparer.Prepare((&http.Request{}).WithContext(ctx))
629}
630
631// UpdateSender sends the Update request. The method will close the
632// http.Response Body if it receives an error.
633func (client GroupClient) UpdateSender(req *http.Request) (*http.Response, error) {
634	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
635}
636
637// UpdateResponder handles the response to the Update request. The method always
638// closes the http.Response Body.
639func (client GroupClient) UpdateResponder(resp *http.Response) (result GroupContract, err error) {
640	err = autorest.Respond(
641		resp,
642		azure.WithErrorUnlessStatusCode(http.StatusOK),
643		autorest.ByUnmarshallingJSON(&result),
644		autorest.ByClosing())
645	result.Response = autorest.Response{Response: resp}
646	return
647}
648