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