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