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// UserClient is the client for the User methods of the Apimanagement service.
30type UserClient struct {
31	BaseClient
32}
33
34// NewUserClient creates an instance of the UserClient client.
35func NewUserClient() UserClient {
36	return UserClient{New()}
37}
38
39// CreateOrUpdate creates or Updates a user.
40// Parameters:
41// apimBaseURL - the management endpoint of the API Management service, for example
42// https://myapimservice.management.azure-api.net.
43// UID - user identifier. Must be unique in the current API Management service instance.
44// parameters - create or update parameters.
45func (client UserClient) CreateOrUpdate(ctx context.Context, apimBaseURL string, UID string, parameters UserCreateParameters) (result UserContract, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.CreateOrUpdate")
48		defer func() {
49			sc := -1
50			if result.Response.Response != nil {
51				sc = result.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	if err := validation.Validate([]validation.Validation{
57		{TargetValue: UID,
58			Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil},
59				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
60				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
61		{TargetValue: parameters,
62			Constraints: []validation.Constraint{{Target: "parameters.Email", Name: validation.Null, Rule: true,
63				Chain: []validation.Constraint{{Target: "parameters.Email", Name: validation.MaxLength, Rule: 254, Chain: nil},
64					{Target: "parameters.Email", Name: validation.MinLength, Rule: 1, Chain: nil},
65				}},
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.UserClient", "CreateOrUpdate", err.Error())
75	}
76
77	req, err := client.CreateOrUpdatePreparer(ctx, apimBaseURL, UID, parameters)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "CreateOrUpdate", nil, "Failure preparing request")
80		return
81	}
82
83	resp, err := client.CreateOrUpdateSender(req)
84	if err != nil {
85		result.Response = autorest.Response{Response: resp}
86		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "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.UserClient", "CreateOrUpdate", resp, "Failure responding to request")
93	}
94
95	return
96}
97
98// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
99func (client UserClient) CreateOrUpdatePreparer(ctx context.Context, apimBaseURL string, UID string, parameters UserCreateParameters) (*http.Request, error) {
100	urlParameters := map[string]interface{}{
101		"apimBaseUrl": apimBaseURL,
102	}
103
104	pathParameters := map[string]interface{}{
105		"uid": autorest.Encode("path", UID),
106	}
107
108	const APIVersion = "2017-03-01"
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.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
117		autorest.WithPathParameters("/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 UserClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
126	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
127	return autorest.SendWithSender(client, req, sd...)
128}
129
130// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
131// closes the http.Response Body.
132func (client UserClient) CreateOrUpdateResponder(resp *http.Response) (result UserContract, err error) {
133	err = autorest.Respond(
134		resp,
135		client.ByInspecting(),
136		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
137		autorest.ByUnmarshallingJSON(&result),
138		autorest.ByClosing())
139	result.Response = autorest.Response{Response: resp}
140	return
141}
142
143// Delete deletes specific user.
144// Parameters:
145// apimBaseURL - the management endpoint of the API Management service, for example
146// https://myapimservice.management.azure-api.net.
147// UID - user identifier. Must be unique in the current API Management service instance.
148// ifMatch - the entity state (Etag) version of the user to delete. A value of "*" can be used for If-Match to
149// unconditionally apply the operation.
150// deleteSubscriptions - whether to delete user's subscription or not.
151// notify - send an Account Closed Email notification to the User.
152func (client UserClient) Delete(ctx context.Context, apimBaseURL string, UID string, ifMatch string, deleteSubscriptions string, notify string) (result autorest.Response, err error) {
153	if tracing.IsEnabled() {
154		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.Delete")
155		defer func() {
156			sc := -1
157			if result.Response != nil {
158				sc = result.Response.StatusCode
159			}
160			tracing.EndSpan(ctx, sc, err)
161		}()
162	}
163	if err := validation.Validate([]validation.Validation{
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.UserClient", "Delete", err.Error())
169	}
170
171	req, err := client.DeletePreparer(ctx, apimBaseURL, UID, ifMatch, deleteSubscriptions, notify)
172	if err != nil {
173		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Delete", nil, "Failure preparing request")
174		return
175	}
176
177	resp, err := client.DeleteSender(req)
178	if err != nil {
179		result.Response = resp
180		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "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.UserClient", "Delete", resp, "Failure responding to request")
187	}
188
189	return
190}
191
192// DeletePreparer prepares the Delete request.
193func (client UserClient) DeletePreparer(ctx context.Context, apimBaseURL string, UID string, ifMatch string, deleteSubscriptions string, notify string) (*http.Request, error) {
194	urlParameters := map[string]interface{}{
195		"apimBaseUrl": apimBaseURL,
196	}
197
198	pathParameters := map[string]interface{}{
199		"uid": autorest.Encode("path", UID),
200	}
201
202	const APIVersion = "2017-03-01"
203	queryParameters := map[string]interface{}{
204		"api-version": APIVersion,
205	}
206	if len(string(deleteSubscriptions)) > 0 {
207		queryParameters["deleteSubscriptions"] = autorest.Encode("query", deleteSubscriptions)
208	} else {
209		queryParameters["deleteSubscriptions"] = autorest.Encode("query", "False")
210	}
211	if len(string(notify)) > 0 {
212		queryParameters["notify"] = autorest.Encode("query", notify)
213	} else {
214		queryParameters["notify"] = autorest.Encode("query", "False")
215	}
216
217	preparer := autorest.CreatePreparer(
218		autorest.AsDelete(),
219		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
220		autorest.WithPathParameters("/users/{uid}", pathParameters),
221		autorest.WithQueryParameters(queryParameters),
222		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
223	return preparer.Prepare((&http.Request{}).WithContext(ctx))
224}
225
226// DeleteSender sends the Delete request. The method will close the
227// http.Response Body if it receives an error.
228func (client UserClient) DeleteSender(req *http.Request) (*http.Response, error) {
229	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
230	return autorest.SendWithSender(client, req, sd...)
231}
232
233// DeleteResponder handles the response to the Delete request. The method always
234// closes the http.Response Body.
235func (client UserClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
236	err = autorest.Respond(
237		resp,
238		client.ByInspecting(),
239		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
240		autorest.ByClosing())
241	result.Response = resp
242	return
243}
244
245// GenerateSsoURL retrieves a redirection URL containing an authentication token for signing a given user into the
246// developer portal.
247// Parameters:
248// apimBaseURL - the management endpoint of the API Management service, for example
249// https://myapimservice.management.azure-api.net.
250// UID - user identifier. Must be unique in the current API Management service instance.
251func (client UserClient) GenerateSsoURL(ctx context.Context, apimBaseURL string, UID string) (result GenerateSsoURLResult, err error) {
252	if tracing.IsEnabled() {
253		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.GenerateSsoURL")
254		defer func() {
255			sc := -1
256			if result.Response.Response != nil {
257				sc = result.Response.Response.StatusCode
258			}
259			tracing.EndSpan(ctx, sc, err)
260		}()
261	}
262	if err := validation.Validate([]validation.Validation{
263		{TargetValue: UID,
264			Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil},
265				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
266				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
267		return result, validation.NewError("apimanagement.UserClient", "GenerateSsoURL", err.Error())
268	}
269
270	req, err := client.GenerateSsoURLPreparer(ctx, apimBaseURL, UID)
271	if err != nil {
272		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GenerateSsoURL", nil, "Failure preparing request")
273		return
274	}
275
276	resp, err := client.GenerateSsoURLSender(req)
277	if err != nil {
278		result.Response = autorest.Response{Response: resp}
279		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GenerateSsoURL", resp, "Failure sending request")
280		return
281	}
282
283	result, err = client.GenerateSsoURLResponder(resp)
284	if err != nil {
285		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GenerateSsoURL", resp, "Failure responding to request")
286	}
287
288	return
289}
290
291// GenerateSsoURLPreparer prepares the GenerateSsoURL request.
292func (client UserClient) GenerateSsoURLPreparer(ctx context.Context, apimBaseURL string, UID string) (*http.Request, error) {
293	urlParameters := map[string]interface{}{
294		"apimBaseUrl": apimBaseURL,
295	}
296
297	pathParameters := map[string]interface{}{
298		"uid": autorest.Encode("path", UID),
299	}
300
301	const APIVersion = "2017-03-01"
302	queryParameters := map[string]interface{}{
303		"api-version": APIVersion,
304	}
305
306	preparer := autorest.CreatePreparer(
307		autorest.AsPost(),
308		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
309		autorest.WithPathParameters("/users/{uid}/generateSsoUrl", pathParameters),
310		autorest.WithQueryParameters(queryParameters))
311	return preparer.Prepare((&http.Request{}).WithContext(ctx))
312}
313
314// GenerateSsoURLSender sends the GenerateSsoURL request. The method will close the
315// http.Response Body if it receives an error.
316func (client UserClient) GenerateSsoURLSender(req *http.Request) (*http.Response, error) {
317	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
318	return autorest.SendWithSender(client, req, sd...)
319}
320
321// GenerateSsoURLResponder handles the response to the GenerateSsoURL request. The method always
322// closes the http.Response Body.
323func (client UserClient) GenerateSsoURLResponder(resp *http.Response) (result GenerateSsoURLResult, err error) {
324	err = autorest.Respond(
325		resp,
326		client.ByInspecting(),
327		azure.WithErrorUnlessStatusCode(http.StatusOK),
328		autorest.ByUnmarshallingJSON(&result),
329		autorest.ByClosing())
330	result.Response = autorest.Response{Response: resp}
331	return
332}
333
334// Get gets the details of the user specified by its identifier.
335// Parameters:
336// apimBaseURL - the management endpoint of the API Management service, for example
337// https://myapimservice.management.azure-api.net.
338// UID - user identifier. Must be unique in the current API Management service instance.
339func (client UserClient) Get(ctx context.Context, apimBaseURL string, UID string) (result UserContract, err error) {
340	if tracing.IsEnabled() {
341		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.Get")
342		defer func() {
343			sc := -1
344			if result.Response.Response != nil {
345				sc = result.Response.Response.StatusCode
346			}
347			tracing.EndSpan(ctx, sc, err)
348		}()
349	}
350	if err := validation.Validate([]validation.Validation{
351		{TargetValue: UID,
352			Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil},
353				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
354				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
355		return result, validation.NewError("apimanagement.UserClient", "Get", err.Error())
356	}
357
358	req, err := client.GetPreparer(ctx, apimBaseURL, UID)
359	if err != nil {
360		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Get", nil, "Failure preparing request")
361		return
362	}
363
364	resp, err := client.GetSender(req)
365	if err != nil {
366		result.Response = autorest.Response{Response: resp}
367		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Get", resp, "Failure sending request")
368		return
369	}
370
371	result, err = client.GetResponder(resp)
372	if err != nil {
373		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Get", resp, "Failure responding to request")
374	}
375
376	return
377}
378
379// GetPreparer prepares the Get request.
380func (client UserClient) GetPreparer(ctx context.Context, apimBaseURL string, UID string) (*http.Request, error) {
381	urlParameters := map[string]interface{}{
382		"apimBaseUrl": apimBaseURL,
383	}
384
385	pathParameters := map[string]interface{}{
386		"uid": autorest.Encode("path", UID),
387	}
388
389	const APIVersion = "2017-03-01"
390	queryParameters := map[string]interface{}{
391		"api-version": APIVersion,
392	}
393
394	preparer := autorest.CreatePreparer(
395		autorest.AsGet(),
396		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
397		autorest.WithPathParameters("/users/{uid}", pathParameters),
398		autorest.WithQueryParameters(queryParameters))
399	return preparer.Prepare((&http.Request{}).WithContext(ctx))
400}
401
402// GetSender sends the Get request. The method will close the
403// http.Response Body if it receives an error.
404func (client UserClient) GetSender(req *http.Request) (*http.Response, error) {
405	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
406	return autorest.SendWithSender(client, req, sd...)
407}
408
409// GetResponder handles the response to the Get request. The method always
410// closes the http.Response Body.
411func (client UserClient) GetResponder(resp *http.Response) (result UserContract, err error) {
412	err = autorest.Respond(
413		resp,
414		client.ByInspecting(),
415		azure.WithErrorUnlessStatusCode(http.StatusOK),
416		autorest.ByUnmarshallingJSON(&result),
417		autorest.ByClosing())
418	result.Response = autorest.Response{Response: resp}
419	return
420}
421
422// GetSharedAccessToken gets the Shared Access Authorization Token for the User.
423// Parameters:
424// apimBaseURL - the management endpoint of the API Management service, for example
425// https://myapimservice.management.azure-api.net.
426// UID - user identifier. Must be unique in the current API Management service instance.
427// parameters - create Authorization Token parameters.
428func (client UserClient) GetSharedAccessToken(ctx context.Context, apimBaseURL string, UID string, parameters UserTokenParameters) (result UserTokenResult, err error) {
429	if tracing.IsEnabled() {
430		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.GetSharedAccessToken")
431		defer func() {
432			sc := -1
433			if result.Response.Response != nil {
434				sc = result.Response.Response.StatusCode
435			}
436			tracing.EndSpan(ctx, sc, err)
437		}()
438	}
439	if err := validation.Validate([]validation.Validation{
440		{TargetValue: UID,
441			Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil},
442				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
443				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
444		{TargetValue: parameters,
445			Constraints: []validation.Constraint{{Target: "parameters.Expiry", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
446		return result, validation.NewError("apimanagement.UserClient", "GetSharedAccessToken", err.Error())
447	}
448
449	req, err := client.GetSharedAccessTokenPreparer(ctx, apimBaseURL, UID, parameters)
450	if err != nil {
451		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetSharedAccessToken", nil, "Failure preparing request")
452		return
453	}
454
455	resp, err := client.GetSharedAccessTokenSender(req)
456	if err != nil {
457		result.Response = autorest.Response{Response: resp}
458		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetSharedAccessToken", resp, "Failure sending request")
459		return
460	}
461
462	result, err = client.GetSharedAccessTokenResponder(resp)
463	if err != nil {
464		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetSharedAccessToken", resp, "Failure responding to request")
465	}
466
467	return
468}
469
470// GetSharedAccessTokenPreparer prepares the GetSharedAccessToken request.
471func (client UserClient) GetSharedAccessTokenPreparer(ctx context.Context, apimBaseURL string, UID string, parameters UserTokenParameters) (*http.Request, error) {
472	urlParameters := map[string]interface{}{
473		"apimBaseUrl": apimBaseURL,
474	}
475
476	pathParameters := map[string]interface{}{
477		"uid": autorest.Encode("path", UID),
478	}
479
480	const APIVersion = "2017-03-01"
481	queryParameters := map[string]interface{}{
482		"api-version": APIVersion,
483	}
484
485	preparer := autorest.CreatePreparer(
486		autorest.AsContentType("application/json; charset=utf-8"),
487		autorest.AsPost(),
488		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
489		autorest.WithPathParameters("/users/{uid}/token", pathParameters),
490		autorest.WithJSON(parameters),
491		autorest.WithQueryParameters(queryParameters))
492	return preparer.Prepare((&http.Request{}).WithContext(ctx))
493}
494
495// GetSharedAccessTokenSender sends the GetSharedAccessToken request. The method will close the
496// http.Response Body if it receives an error.
497func (client UserClient) GetSharedAccessTokenSender(req *http.Request) (*http.Response, error) {
498	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
499	return autorest.SendWithSender(client, req, sd...)
500}
501
502// GetSharedAccessTokenResponder handles the response to the GetSharedAccessToken request. The method always
503// closes the http.Response Body.
504func (client UserClient) GetSharedAccessTokenResponder(resp *http.Response) (result UserTokenResult, err error) {
505	err = autorest.Respond(
506		resp,
507		client.ByInspecting(),
508		azure.WithErrorUnlessStatusCode(http.StatusOK),
509		autorest.ByUnmarshallingJSON(&result),
510		autorest.ByClosing())
511	result.Response = autorest.Response{Response: resp}
512	return
513}
514
515// List lists a collection of registered users in the specified service instance.
516// Parameters:
517// apimBaseURL - the management endpoint of the API Management service, for example
518// https://myapimservice.management.azure-api.net.
519// filter - | Field            | Supported operators    | Supported functions               |
520// |------------------|------------------------|-----------------------------------|
521// | id               | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
522// | firstName        | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
523// | lastName         | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
524// | email            | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
525// | state            | eq                     | N/A                               |
526// | registrationDate | ge, le, eq, ne, gt, lt | N/A                               |
527// | note             | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
528// top - number of records to return.
529// skip - number of records to skip.
530func (client UserClient) List(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result UserCollectionPage, err error) {
531	if tracing.IsEnabled() {
532		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.List")
533		defer func() {
534			sc := -1
535			if result.uc.Response.Response != nil {
536				sc = result.uc.Response.Response.StatusCode
537			}
538			tracing.EndSpan(ctx, sc, err)
539		}()
540	}
541	if err := validation.Validate([]validation.Validation{
542		{TargetValue: top,
543			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
544				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
545		{TargetValue: skip,
546			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
547				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
548		return result, validation.NewError("apimanagement.UserClient", "List", err.Error())
549	}
550
551	result.fn = client.listNextResults
552	req, err := client.ListPreparer(ctx, apimBaseURL, filter, top, skip)
553	if err != nil {
554		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "List", nil, "Failure preparing request")
555		return
556	}
557
558	resp, err := client.ListSender(req)
559	if err != nil {
560		result.uc.Response = autorest.Response{Response: resp}
561		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "List", resp, "Failure sending request")
562		return
563	}
564
565	result.uc, err = client.ListResponder(resp)
566	if err != nil {
567		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "List", resp, "Failure responding to request")
568	}
569
570	return
571}
572
573// ListPreparer prepares the List request.
574func (client UserClient) ListPreparer(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (*http.Request, error) {
575	urlParameters := map[string]interface{}{
576		"apimBaseUrl": apimBaseURL,
577	}
578
579	const APIVersion = "2017-03-01"
580	queryParameters := map[string]interface{}{
581		"api-version": APIVersion,
582	}
583	if len(filter) > 0 {
584		queryParameters["$filter"] = autorest.Encode("query", filter)
585	}
586	if top != nil {
587		queryParameters["$top"] = autorest.Encode("query", *top)
588	}
589	if skip != nil {
590		queryParameters["$skip"] = autorest.Encode("query", *skip)
591	}
592
593	preparer := autorest.CreatePreparer(
594		autorest.AsGet(),
595		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
596		autorest.WithPath("/users"),
597		autorest.WithQueryParameters(queryParameters))
598	return preparer.Prepare((&http.Request{}).WithContext(ctx))
599}
600
601// ListSender sends the List request. The method will close the
602// http.Response Body if it receives an error.
603func (client UserClient) ListSender(req *http.Request) (*http.Response, error) {
604	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
605	return autorest.SendWithSender(client, req, sd...)
606}
607
608// ListResponder handles the response to the List request. The method always
609// closes the http.Response Body.
610func (client UserClient) ListResponder(resp *http.Response) (result UserCollection, err error) {
611	err = autorest.Respond(
612		resp,
613		client.ByInspecting(),
614		azure.WithErrorUnlessStatusCode(http.StatusOK),
615		autorest.ByUnmarshallingJSON(&result),
616		autorest.ByClosing())
617	result.Response = autorest.Response{Response: resp}
618	return
619}
620
621// listNextResults retrieves the next set of results, if any.
622func (client UserClient) listNextResults(ctx context.Context, lastResults UserCollection) (result UserCollection, err error) {
623	req, err := lastResults.userCollectionPreparer(ctx)
624	if err != nil {
625		return result, autorest.NewErrorWithError(err, "apimanagement.UserClient", "listNextResults", nil, "Failure preparing next results request")
626	}
627	if req == nil {
628		return
629	}
630	resp, err := client.ListSender(req)
631	if err != nil {
632		result.Response = autorest.Response{Response: resp}
633		return result, autorest.NewErrorWithError(err, "apimanagement.UserClient", "listNextResults", resp, "Failure sending next results request")
634	}
635	result, err = client.ListResponder(resp)
636	if err != nil {
637		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "listNextResults", resp, "Failure responding to next results request")
638	}
639	return
640}
641
642// ListComplete enumerates all values, automatically crossing page boundaries as required.
643func (client UserClient) ListComplete(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result UserCollectionIterator, err error) {
644	if tracing.IsEnabled() {
645		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.List")
646		defer func() {
647			sc := -1
648			if result.Response().Response.Response != nil {
649				sc = result.page.Response().Response.Response.StatusCode
650			}
651			tracing.EndSpan(ctx, sc, err)
652		}()
653	}
654	result.page, err = client.List(ctx, apimBaseURL, filter, top, skip)
655	return
656}
657
658// Update updates the details of the user specified by its identifier.
659// Parameters:
660// apimBaseURL - the management endpoint of the API Management service, for example
661// https://myapimservice.management.azure-api.net.
662// UID - user identifier. Must be unique in the current API Management service instance.
663// parameters - update parameters.
664// ifMatch - the entity state (Etag) version of the user to update. A value of "*" can be used for If-Match to
665// unconditionally apply the operation.
666func (client UserClient) Update(ctx context.Context, apimBaseURL string, UID string, parameters UserUpdateParameters, ifMatch string) (result autorest.Response, err error) {
667	if tracing.IsEnabled() {
668		ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.Update")
669		defer func() {
670			sc := -1
671			if result.Response != nil {
672				sc = result.Response.StatusCode
673			}
674			tracing.EndSpan(ctx, sc, err)
675		}()
676	}
677	if err := validation.Validate([]validation.Validation{
678		{TargetValue: UID,
679			Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil},
680				{Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil},
681				{Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
682		return result, validation.NewError("apimanagement.UserClient", "Update", err.Error())
683	}
684
685	req, err := client.UpdatePreparer(ctx, apimBaseURL, UID, parameters, ifMatch)
686	if err != nil {
687		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Update", nil, "Failure preparing request")
688		return
689	}
690
691	resp, err := client.UpdateSender(req)
692	if err != nil {
693		result.Response = resp
694		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Update", resp, "Failure sending request")
695		return
696	}
697
698	result, err = client.UpdateResponder(resp)
699	if err != nil {
700		err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Update", resp, "Failure responding to request")
701	}
702
703	return
704}
705
706// UpdatePreparer prepares the Update request.
707func (client UserClient) UpdatePreparer(ctx context.Context, apimBaseURL string, UID string, parameters UserUpdateParameters, ifMatch string) (*http.Request, error) {
708	urlParameters := map[string]interface{}{
709		"apimBaseUrl": apimBaseURL,
710	}
711
712	pathParameters := map[string]interface{}{
713		"uid": autorest.Encode("path", UID),
714	}
715
716	const APIVersion = "2017-03-01"
717	queryParameters := map[string]interface{}{
718		"api-version": APIVersion,
719	}
720
721	preparer := autorest.CreatePreparer(
722		autorest.AsContentType("application/json; charset=utf-8"),
723		autorest.AsPatch(),
724		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
725		autorest.WithPathParameters("/users/{uid}", pathParameters),
726		autorest.WithJSON(parameters),
727		autorest.WithQueryParameters(queryParameters),
728		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
729	return preparer.Prepare((&http.Request{}).WithContext(ctx))
730}
731
732// UpdateSender sends the Update request. The method will close the
733// http.Response Body if it receives an error.
734func (client UserClient) UpdateSender(req *http.Request) (*http.Response, error) {
735	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
736	return autorest.SendWithSender(client, req, sd...)
737}
738
739// UpdateResponder handles the response to the Update request. The method always
740// closes the http.Response Body.
741func (client UserClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
742	err = autorest.Respond(
743		resp,
744		client.ByInspecting(),
745		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
746		autorest.ByClosing())
747	result.Response = resp
748	return
749}
750