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