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// UserClient is the apiManagement Client 19type UserClient struct { 20 BaseClient 21} 22 23// NewUserClient creates an instance of the UserClient client. 24func NewUserClient(subscriptionID string) UserClient { 25 return NewUserClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewUserClientWithBaseURI creates an instance of the UserClient 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 NewUserClientWithBaseURI(baseURI string, subscriptionID string) UserClient { 31 return UserClient{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. 40// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity. 41func (client UserClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, UID string, parameters UserCreateParameters, ifMatch string) (result UserContract, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.CreateOrUpdate") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: serviceName, 54 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 55 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 56 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 57 {TargetValue: UID, 58 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 59 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 60 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 61 {TargetValue: parameters, 62 Constraints: []validation.Constraint{{Target: "parameters.UserCreateParameterProperties", Name: validation.Null, Rule: false, 63 Chain: []validation.Constraint{{Target: "parameters.UserCreateParameterProperties.Email", Name: validation.Null, Rule: true, 64 Chain: []validation.Constraint{{Target: "parameters.UserCreateParameterProperties.Email", Name: validation.MaxLength, Rule: 254, Chain: nil}, 65 {Target: "parameters.UserCreateParameterProperties.Email", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 }}, 67 {Target: "parameters.UserCreateParameterProperties.FirstName", Name: validation.Null, Rule: true, 68 Chain: []validation.Constraint{{Target: "parameters.UserCreateParameterProperties.FirstName", Name: validation.MaxLength, Rule: 100, Chain: nil}, 69 {Target: "parameters.UserCreateParameterProperties.FirstName", Name: validation.MinLength, Rule: 1, Chain: nil}, 70 }}, 71 {Target: "parameters.UserCreateParameterProperties.LastName", Name: validation.Null, Rule: true, 72 Chain: []validation.Constraint{{Target: "parameters.UserCreateParameterProperties.LastName", Name: validation.MaxLength, Rule: 100, Chain: nil}, 73 {Target: "parameters.UserCreateParameterProperties.LastName", Name: validation.MinLength, Rule: 1, Chain: nil}, 74 }}, 75 }}}}}); err != nil { 76 return result, validation.NewError("apimanagement.UserClient", "CreateOrUpdate", err.Error()) 77 } 78 79 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, UID, parameters, ifMatch) 80 if err != nil { 81 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "CreateOrUpdate", nil, "Failure preparing request") 82 return 83 } 84 85 resp, err := client.CreateOrUpdateSender(req) 86 if err != nil { 87 result.Response = autorest.Response{Response: resp} 88 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "CreateOrUpdate", resp, "Failure sending request") 89 return 90 } 91 92 result, err = client.CreateOrUpdateResponder(resp) 93 if err != nil { 94 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "CreateOrUpdate", resp, "Failure responding to request") 95 return 96 } 97 98 return 99} 100 101// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 102func (client UserClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string, parameters UserCreateParameters, ifMatch string) (*http.Request, error) { 103 pathParameters := map[string]interface{}{ 104 "resourceGroupName": autorest.Encode("path", resourceGroupName), 105 "serviceName": autorest.Encode("path", serviceName), 106 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 107 "uid": autorest.Encode("path", UID), 108 } 109 110 const APIVersion = "2018-01-01" 111 queryParameters := map[string]interface{}{ 112 "api-version": APIVersion, 113 } 114 115 preparer := autorest.CreatePreparer( 116 autorest.AsContentType("application/json; charset=utf-8"), 117 autorest.AsPut(), 118 autorest.WithBaseURL(client.BaseURI), 119 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}", pathParameters), 120 autorest.WithJSON(parameters), 121 autorest.WithQueryParameters(queryParameters)) 122 if len(ifMatch) > 0 { 123 preparer = autorest.DecoratePreparer(preparer, 124 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 125 } 126 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 127} 128 129// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 130// http.Response Body if it receives an error. 131func (client UserClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 132 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 133} 134 135// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 136// closes the http.Response Body. 137func (client UserClient) CreateOrUpdateResponder(resp *http.Response) (result UserContract, err error) { 138 err = autorest.Respond( 139 resp, 140 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 141 autorest.ByUnmarshallingJSON(&result), 142 autorest.ByClosing()) 143 result.Response = autorest.Response{Response: resp} 144 return 145} 146 147// Delete deletes specific user. 148// Parameters: 149// resourceGroupName - the name of the resource group. 150// serviceName - the name of the API Management service. 151// UID - user identifier. Must be unique in the current API Management service instance. 152// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 153// request or it should be * for unconditional update. 154// deleteSubscriptions - whether to delete user's subscription or not. 155// notify - send an Account Closed Email notification to the User. 156func (client UserClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, UID string, ifMatch string, deleteSubscriptions *bool, notify *bool) (result autorest.Response, err error) { 157 if tracing.IsEnabled() { 158 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.Delete") 159 defer func() { 160 sc := -1 161 if result.Response != nil { 162 sc = result.Response.StatusCode 163 } 164 tracing.EndSpan(ctx, sc, err) 165 }() 166 } 167 if err := validation.Validate([]validation.Validation{ 168 {TargetValue: serviceName, 169 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 170 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 171 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 172 {TargetValue: UID, 173 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 174 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 175 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 176 return result, validation.NewError("apimanagement.UserClient", "Delete", err.Error()) 177 } 178 179 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, UID, ifMatch, deleteSubscriptions, notify) 180 if err != nil { 181 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Delete", nil, "Failure preparing request") 182 return 183 } 184 185 resp, err := client.DeleteSender(req) 186 if err != nil { 187 result.Response = resp 188 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Delete", resp, "Failure sending request") 189 return 190 } 191 192 result, err = client.DeleteResponder(resp) 193 if err != nil { 194 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Delete", resp, "Failure responding to request") 195 return 196 } 197 198 return 199} 200 201// DeletePreparer prepares the Delete request. 202func (client UserClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string, ifMatch string, deleteSubscriptions *bool, notify *bool) (*http.Request, error) { 203 pathParameters := map[string]interface{}{ 204 "resourceGroupName": autorest.Encode("path", resourceGroupName), 205 "serviceName": autorest.Encode("path", serviceName), 206 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 207 "uid": autorest.Encode("path", UID), 208 } 209 210 const APIVersion = "2018-01-01" 211 queryParameters := map[string]interface{}{ 212 "api-version": APIVersion, 213 } 214 if deleteSubscriptions != nil { 215 queryParameters["deleteSubscriptions"] = autorest.Encode("query", *deleteSubscriptions) 216 } 217 if notify != nil { 218 queryParameters["notify"] = autorest.Encode("query", *notify) 219 } 220 221 preparer := autorest.CreatePreparer( 222 autorest.AsDelete(), 223 autorest.WithBaseURL(client.BaseURI), 224 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}", pathParameters), 225 autorest.WithQueryParameters(queryParameters), 226 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 227 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 228} 229 230// DeleteSender sends the Delete request. The method will close the 231// http.Response Body if it receives an error. 232func (client UserClient) DeleteSender(req *http.Request) (*http.Response, error) { 233 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 234} 235 236// DeleteResponder handles the response to the Delete request. The method always 237// closes the http.Response Body. 238func (client UserClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 239 err = autorest.Respond( 240 resp, 241 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 242 autorest.ByClosing()) 243 result.Response = resp 244 return 245} 246 247// GenerateSsoURL retrieves a redirection URL containing an authentication token for signing a given user into the 248// developer portal. 249// Parameters: 250// resourceGroupName - the name of the resource group. 251// serviceName - the name of the API Management service. 252// UID - user identifier. Must be unique in the current API Management service instance. 253func (client UserClient) GenerateSsoURL(ctx context.Context, resourceGroupName string, serviceName string, UID string) (result GenerateSsoURLResult, err error) { 254 if tracing.IsEnabled() { 255 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.GenerateSsoURL") 256 defer func() { 257 sc := -1 258 if result.Response.Response != nil { 259 sc = result.Response.Response.StatusCode 260 } 261 tracing.EndSpan(ctx, sc, err) 262 }() 263 } 264 if err := validation.Validate([]validation.Validation{ 265 {TargetValue: serviceName, 266 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 267 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 268 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 269 {TargetValue: UID, 270 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 271 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 272 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 273 return result, validation.NewError("apimanagement.UserClient", "GenerateSsoURL", err.Error()) 274 } 275 276 req, err := client.GenerateSsoURLPreparer(ctx, resourceGroupName, serviceName, UID) 277 if err != nil { 278 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GenerateSsoURL", nil, "Failure preparing request") 279 return 280 } 281 282 resp, err := client.GenerateSsoURLSender(req) 283 if err != nil { 284 result.Response = autorest.Response{Response: resp} 285 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GenerateSsoURL", resp, "Failure sending request") 286 return 287 } 288 289 result, err = client.GenerateSsoURLResponder(resp) 290 if err != nil { 291 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GenerateSsoURL", resp, "Failure responding to request") 292 return 293 } 294 295 return 296} 297 298// GenerateSsoURLPreparer prepares the GenerateSsoURL request. 299func (client UserClient) GenerateSsoURLPreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string) (*http.Request, error) { 300 pathParameters := map[string]interface{}{ 301 "resourceGroupName": autorest.Encode("path", resourceGroupName), 302 "serviceName": autorest.Encode("path", serviceName), 303 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 304 "uid": autorest.Encode("path", UID), 305 } 306 307 const APIVersion = "2018-01-01" 308 queryParameters := map[string]interface{}{ 309 "api-version": APIVersion, 310 } 311 312 preparer := autorest.CreatePreparer( 313 autorest.AsPost(), 314 autorest.WithBaseURL(client.BaseURI), 315 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}/generateSsoUrl", pathParameters), 316 autorest.WithQueryParameters(queryParameters)) 317 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 318} 319 320// GenerateSsoURLSender sends the GenerateSsoURL request. The method will close the 321// http.Response Body if it receives an error. 322func (client UserClient) GenerateSsoURLSender(req *http.Request) (*http.Response, error) { 323 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 324} 325 326// GenerateSsoURLResponder handles the response to the GenerateSsoURL request. The method always 327// closes the http.Response Body. 328func (client UserClient) GenerateSsoURLResponder(resp *http.Response) (result GenerateSsoURLResult, err error) { 329 err = autorest.Respond( 330 resp, 331 azure.WithErrorUnlessStatusCode(http.StatusOK), 332 autorest.ByUnmarshallingJSON(&result), 333 autorest.ByClosing()) 334 result.Response = autorest.Response{Response: resp} 335 return 336} 337 338// Get gets the details of the user specified by its identifier. 339// Parameters: 340// resourceGroupName - the name of the resource group. 341// serviceName - the name of the API Management service. 342// UID - user identifier. Must be unique in the current API Management service instance. 343func (client UserClient) Get(ctx context.Context, resourceGroupName string, serviceName string, UID string) (result UserContract, err error) { 344 if tracing.IsEnabled() { 345 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.Get") 346 defer func() { 347 sc := -1 348 if result.Response.Response != nil { 349 sc = result.Response.Response.StatusCode 350 } 351 tracing.EndSpan(ctx, sc, err) 352 }() 353 } 354 if err := validation.Validate([]validation.Validation{ 355 {TargetValue: serviceName, 356 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 357 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 358 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 359 {TargetValue: UID, 360 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 361 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 362 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 363 return result, validation.NewError("apimanagement.UserClient", "Get", err.Error()) 364 } 365 366 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, UID) 367 if err != nil { 368 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Get", nil, "Failure preparing request") 369 return 370 } 371 372 resp, err := client.GetSender(req) 373 if err != nil { 374 result.Response = autorest.Response{Response: resp} 375 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Get", resp, "Failure sending request") 376 return 377 } 378 379 result, err = client.GetResponder(resp) 380 if err != nil { 381 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Get", resp, "Failure responding to request") 382 return 383 } 384 385 return 386} 387 388// GetPreparer prepares the Get request. 389func (client UserClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string) (*http.Request, error) { 390 pathParameters := map[string]interface{}{ 391 "resourceGroupName": autorest.Encode("path", resourceGroupName), 392 "serviceName": autorest.Encode("path", serviceName), 393 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 394 "uid": autorest.Encode("path", UID), 395 } 396 397 const APIVersion = "2018-01-01" 398 queryParameters := map[string]interface{}{ 399 "api-version": APIVersion, 400 } 401 402 preparer := autorest.CreatePreparer( 403 autorest.AsGet(), 404 autorest.WithBaseURL(client.BaseURI), 405 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}", pathParameters), 406 autorest.WithQueryParameters(queryParameters)) 407 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 408} 409 410// GetSender sends the Get request. The method will close the 411// http.Response Body if it receives an error. 412func (client UserClient) GetSender(req *http.Request) (*http.Response, error) { 413 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 414} 415 416// GetResponder handles the response to the Get request. The method always 417// closes the http.Response Body. 418func (client UserClient) GetResponder(resp *http.Response) (result UserContract, err error) { 419 err = autorest.Respond( 420 resp, 421 azure.WithErrorUnlessStatusCode(http.StatusOK), 422 autorest.ByUnmarshallingJSON(&result), 423 autorest.ByClosing()) 424 result.Response = autorest.Response{Response: resp} 425 return 426} 427 428// GetEntityTag gets the entity state (Etag) version of the user specified by its identifier. 429// Parameters: 430// resourceGroupName - the name of the resource group. 431// serviceName - the name of the API Management service. 432// UID - user identifier. Must be unique in the current API Management service instance. 433func (client UserClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, UID string) (result autorest.Response, err error) { 434 if tracing.IsEnabled() { 435 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.GetEntityTag") 436 defer func() { 437 sc := -1 438 if result.Response != nil { 439 sc = result.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: UID, 450 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 451 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 452 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 453 return result, validation.NewError("apimanagement.UserClient", "GetEntityTag", err.Error()) 454 } 455 456 req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, UID) 457 if err != nil { 458 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetEntityTag", nil, "Failure preparing request") 459 return 460 } 461 462 resp, err := client.GetEntityTagSender(req) 463 if err != nil { 464 result.Response = resp 465 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetEntityTag", resp, "Failure sending request") 466 return 467 } 468 469 result, err = client.GetEntityTagResponder(resp) 470 if err != nil { 471 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetEntityTag", resp, "Failure responding to request") 472 return 473 } 474 475 return 476} 477 478// GetEntityTagPreparer prepares the GetEntityTag request. 479func (client UserClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string) (*http.Request, error) { 480 pathParameters := map[string]interface{}{ 481 "resourceGroupName": autorest.Encode("path", resourceGroupName), 482 "serviceName": autorest.Encode("path", serviceName), 483 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 484 "uid": autorest.Encode("path", UID), 485 } 486 487 const APIVersion = "2018-01-01" 488 queryParameters := map[string]interface{}{ 489 "api-version": APIVersion, 490 } 491 492 preparer := autorest.CreatePreparer( 493 autorest.AsHead(), 494 autorest.WithBaseURL(client.BaseURI), 495 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}", pathParameters), 496 autorest.WithQueryParameters(queryParameters)) 497 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 498} 499 500// GetEntityTagSender sends the GetEntityTag request. The method will close the 501// http.Response Body if it receives an error. 502func (client UserClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { 503 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 504} 505 506// GetEntityTagResponder handles the response to the GetEntityTag request. The method always 507// closes the http.Response Body. 508func (client UserClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { 509 err = autorest.Respond( 510 resp, 511 azure.WithErrorUnlessStatusCode(http.StatusOK), 512 autorest.ByClosing()) 513 result.Response = resp 514 return 515} 516 517// GetIdentity returns calling user identity information. 518// Parameters: 519// resourceGroupName - the name of the resource group. 520// serviceName - the name of the API Management service. 521func (client UserClient) GetIdentity(ctx context.Context, resourceGroupName string, serviceName string) (result CurrentUserIdentity, err error) { 522 if tracing.IsEnabled() { 523 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.GetIdentity") 524 defer func() { 525 sc := -1 526 if result.Response.Response != nil { 527 sc = result.Response.Response.StatusCode 528 } 529 tracing.EndSpan(ctx, sc, err) 530 }() 531 } 532 if err := validation.Validate([]validation.Validation{ 533 {TargetValue: serviceName, 534 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 535 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 536 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 537 return result, validation.NewError("apimanagement.UserClient", "GetIdentity", err.Error()) 538 } 539 540 req, err := client.GetIdentityPreparer(ctx, resourceGroupName, serviceName) 541 if err != nil { 542 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetIdentity", nil, "Failure preparing request") 543 return 544 } 545 546 resp, err := client.GetIdentitySender(req) 547 if err != nil { 548 result.Response = autorest.Response{Response: resp} 549 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetIdentity", resp, "Failure sending request") 550 return 551 } 552 553 result, err = client.GetIdentityResponder(resp) 554 if err != nil { 555 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetIdentity", resp, "Failure responding to request") 556 return 557 } 558 559 return 560} 561 562// GetIdentityPreparer prepares the GetIdentity request. 563func (client UserClient) GetIdentityPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 564 pathParameters := map[string]interface{}{ 565 "resourceGroupName": autorest.Encode("path", resourceGroupName), 566 "serviceName": autorest.Encode("path", serviceName), 567 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 568 } 569 570 const APIVersion = "2018-01-01" 571 queryParameters := map[string]interface{}{ 572 "api-version": APIVersion, 573 } 574 575 preparer := autorest.CreatePreparer( 576 autorest.AsGet(), 577 autorest.WithBaseURL(client.BaseURI), 578 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identity", pathParameters), 579 autorest.WithQueryParameters(queryParameters)) 580 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 581} 582 583// GetIdentitySender sends the GetIdentity request. The method will close the 584// http.Response Body if it receives an error. 585func (client UserClient) GetIdentitySender(req *http.Request) (*http.Response, error) { 586 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 587} 588 589// GetIdentityResponder handles the response to the GetIdentity request. The method always 590// closes the http.Response Body. 591func (client UserClient) GetIdentityResponder(resp *http.Response) (result CurrentUserIdentity, err error) { 592 err = autorest.Respond( 593 resp, 594 azure.WithErrorUnlessStatusCode(http.StatusOK), 595 autorest.ByUnmarshallingJSON(&result), 596 autorest.ByClosing()) 597 result.Response = autorest.Response{Response: resp} 598 return 599} 600 601// GetSharedAccessToken gets the Shared Access Authorization Token for the User. 602// Parameters: 603// resourceGroupName - the name of the resource group. 604// serviceName - the name of the API Management service. 605// UID - user identifier. Must be unique in the current API Management service instance. 606// parameters - create Authorization Token parameters. 607func (client UserClient) GetSharedAccessToken(ctx context.Context, resourceGroupName string, serviceName string, UID string, parameters UserTokenParameters) (result UserTokenResult, err error) { 608 if tracing.IsEnabled() { 609 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.GetSharedAccessToken") 610 defer func() { 611 sc := -1 612 if result.Response.Response != nil { 613 sc = result.Response.Response.StatusCode 614 } 615 tracing.EndSpan(ctx, sc, err) 616 }() 617 } 618 if err := validation.Validate([]validation.Validation{ 619 {TargetValue: serviceName, 620 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 621 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 622 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 623 {TargetValue: UID, 624 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 625 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 626 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 627 {TargetValue: parameters, 628 Constraints: []validation.Constraint{{Target: "parameters.Expiry", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 629 return result, validation.NewError("apimanagement.UserClient", "GetSharedAccessToken", err.Error()) 630 } 631 632 req, err := client.GetSharedAccessTokenPreparer(ctx, resourceGroupName, serviceName, UID, parameters) 633 if err != nil { 634 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetSharedAccessToken", nil, "Failure preparing request") 635 return 636 } 637 638 resp, err := client.GetSharedAccessTokenSender(req) 639 if err != nil { 640 result.Response = autorest.Response{Response: resp} 641 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetSharedAccessToken", resp, "Failure sending request") 642 return 643 } 644 645 result, err = client.GetSharedAccessTokenResponder(resp) 646 if err != nil { 647 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "GetSharedAccessToken", resp, "Failure responding to request") 648 return 649 } 650 651 return 652} 653 654// GetSharedAccessTokenPreparer prepares the GetSharedAccessToken request. 655func (client UserClient) GetSharedAccessTokenPreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string, parameters UserTokenParameters) (*http.Request, error) { 656 pathParameters := map[string]interface{}{ 657 "resourceGroupName": autorest.Encode("path", resourceGroupName), 658 "serviceName": autorest.Encode("path", serviceName), 659 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 660 "uid": autorest.Encode("path", UID), 661 } 662 663 const APIVersion = "2018-01-01" 664 queryParameters := map[string]interface{}{ 665 "api-version": APIVersion, 666 } 667 668 preparer := autorest.CreatePreparer( 669 autorest.AsContentType("application/json; charset=utf-8"), 670 autorest.AsPost(), 671 autorest.WithBaseURL(client.BaseURI), 672 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}/token", pathParameters), 673 autorest.WithJSON(parameters), 674 autorest.WithQueryParameters(queryParameters)) 675 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 676} 677 678// GetSharedAccessTokenSender sends the GetSharedAccessToken request. The method will close the 679// http.Response Body if it receives an error. 680func (client UserClient) GetSharedAccessTokenSender(req *http.Request) (*http.Response, error) { 681 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 682} 683 684// GetSharedAccessTokenResponder handles the response to the GetSharedAccessToken request. The method always 685// closes the http.Response Body. 686func (client UserClient) GetSharedAccessTokenResponder(resp *http.Response) (result UserTokenResult, err error) { 687 err = autorest.Respond( 688 resp, 689 azure.WithErrorUnlessStatusCode(http.StatusOK), 690 autorest.ByUnmarshallingJSON(&result), 691 autorest.ByClosing()) 692 result.Response = autorest.Response{Response: resp} 693 return 694} 695 696// ListByService lists a collection of registered users in the specified service instance. 697// Parameters: 698// resourceGroupName - the name of the resource group. 699// serviceName - the name of the API Management service. 700// filter - | Field | Supported operators | Supported functions | 701// |------------------|------------------------|-----------------------------------| 702// | id | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 703// | firstName | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 704// | lastName | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 705// | email | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 706// | state | eq | N/A | 707// | registrationDate | ge, le, eq, ne, gt, lt | N/A | 708// | note | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 709// top - number of records to return. 710// skip - number of records to skip. 711func (client UserClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result UserCollectionPage, err error) { 712 if tracing.IsEnabled() { 713 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.ListByService") 714 defer func() { 715 sc := -1 716 if result.uc.Response.Response != nil { 717 sc = result.uc.Response.Response.StatusCode 718 } 719 tracing.EndSpan(ctx, sc, err) 720 }() 721 } 722 if err := validation.Validate([]validation.Validation{ 723 {TargetValue: serviceName, 724 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 725 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 726 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 727 {TargetValue: top, 728 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 729 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 730 {TargetValue: skip, 731 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 732 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 733 return result, validation.NewError("apimanagement.UserClient", "ListByService", err.Error()) 734 } 735 736 result.fn = client.listByServiceNextResults 737 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip) 738 if err != nil { 739 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "ListByService", nil, "Failure preparing request") 740 return 741 } 742 743 resp, err := client.ListByServiceSender(req) 744 if err != nil { 745 result.uc.Response = autorest.Response{Response: resp} 746 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "ListByService", resp, "Failure sending request") 747 return 748 } 749 750 result.uc, err = client.ListByServiceResponder(resp) 751 if err != nil { 752 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "ListByService", resp, "Failure responding to request") 753 return 754 } 755 if result.uc.hasNextLink() && result.uc.IsEmpty() { 756 err = result.NextWithContext(ctx) 757 return 758 } 759 760 return 761} 762 763// ListByServicePreparer prepares the ListByService request. 764func (client UserClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) { 765 pathParameters := map[string]interface{}{ 766 "resourceGroupName": autorest.Encode("path", resourceGroupName), 767 "serviceName": autorest.Encode("path", serviceName), 768 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 769 } 770 771 const APIVersion = "2018-01-01" 772 queryParameters := map[string]interface{}{ 773 "api-version": APIVersion, 774 } 775 if len(filter) > 0 { 776 queryParameters["$filter"] = autorest.Encode("query", filter) 777 } 778 if top != nil { 779 queryParameters["$top"] = autorest.Encode("query", *top) 780 } 781 if skip != nil { 782 queryParameters["$skip"] = autorest.Encode("query", *skip) 783 } 784 785 preparer := autorest.CreatePreparer( 786 autorest.AsGet(), 787 autorest.WithBaseURL(client.BaseURI), 788 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users", pathParameters), 789 autorest.WithQueryParameters(queryParameters)) 790 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 791} 792 793// ListByServiceSender sends the ListByService request. The method will close the 794// http.Response Body if it receives an error. 795func (client UserClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 796 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 797} 798 799// ListByServiceResponder handles the response to the ListByService request. The method always 800// closes the http.Response Body. 801func (client UserClient) ListByServiceResponder(resp *http.Response) (result UserCollection, err error) { 802 err = autorest.Respond( 803 resp, 804 azure.WithErrorUnlessStatusCode(http.StatusOK), 805 autorest.ByUnmarshallingJSON(&result), 806 autorest.ByClosing()) 807 result.Response = autorest.Response{Response: resp} 808 return 809} 810 811// listByServiceNextResults retrieves the next set of results, if any. 812func (client UserClient) listByServiceNextResults(ctx context.Context, lastResults UserCollection) (result UserCollection, err error) { 813 req, err := lastResults.userCollectionPreparer(ctx) 814 if err != nil { 815 return result, autorest.NewErrorWithError(err, "apimanagement.UserClient", "listByServiceNextResults", nil, "Failure preparing next results request") 816 } 817 if req == nil { 818 return 819 } 820 resp, err := client.ListByServiceSender(req) 821 if err != nil { 822 result.Response = autorest.Response{Response: resp} 823 return result, autorest.NewErrorWithError(err, "apimanagement.UserClient", "listByServiceNextResults", resp, "Failure sending next results request") 824 } 825 result, err = client.ListByServiceResponder(resp) 826 if err != nil { 827 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "listByServiceNextResults", resp, "Failure responding to next results request") 828 } 829 return 830} 831 832// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 833func (client UserClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result UserCollectionIterator, err error) { 834 if tracing.IsEnabled() { 835 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.ListByService") 836 defer func() { 837 sc := -1 838 if result.Response().Response.Response != nil { 839 sc = result.page.Response().Response.Response.StatusCode 840 } 841 tracing.EndSpan(ctx, sc, err) 842 }() 843 } 844 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip) 845 return 846} 847 848// Update updates the details of the user specified by its identifier. 849// Parameters: 850// resourceGroupName - the name of the resource group. 851// serviceName - the name of the API Management service. 852// UID - user identifier. Must be unique in the current API Management service instance. 853// parameters - update parameters. 854// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 855// request or it should be * for unconditional update. 856func (client UserClient) Update(ctx context.Context, resourceGroupName string, serviceName string, UID string, parameters UserUpdateParameters, ifMatch string) (result autorest.Response, err error) { 857 if tracing.IsEnabled() { 858 ctx = tracing.StartSpan(ctx, fqdn+"/UserClient.Update") 859 defer func() { 860 sc := -1 861 if result.Response != nil { 862 sc = result.Response.StatusCode 863 } 864 tracing.EndSpan(ctx, sc, err) 865 }() 866 } 867 if err := validation.Validate([]validation.Validation{ 868 {TargetValue: serviceName, 869 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 870 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 871 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 872 {TargetValue: UID, 873 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 874 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 875 {Target: "UID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 876 return result, validation.NewError("apimanagement.UserClient", "Update", err.Error()) 877 } 878 879 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, UID, parameters, ifMatch) 880 if err != nil { 881 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Update", nil, "Failure preparing request") 882 return 883 } 884 885 resp, err := client.UpdateSender(req) 886 if err != nil { 887 result.Response = resp 888 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Update", resp, "Failure sending request") 889 return 890 } 891 892 result, err = client.UpdateResponder(resp) 893 if err != nil { 894 err = autorest.NewErrorWithError(err, "apimanagement.UserClient", "Update", resp, "Failure responding to request") 895 return 896 } 897 898 return 899} 900 901// UpdatePreparer prepares the Update request. 902func (client UserClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, UID string, parameters UserUpdateParameters, ifMatch string) (*http.Request, error) { 903 pathParameters := map[string]interface{}{ 904 "resourceGroupName": autorest.Encode("path", resourceGroupName), 905 "serviceName": autorest.Encode("path", serviceName), 906 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 907 "uid": autorest.Encode("path", UID), 908 } 909 910 const APIVersion = "2018-01-01" 911 queryParameters := map[string]interface{}{ 912 "api-version": APIVersion, 913 } 914 915 preparer := autorest.CreatePreparer( 916 autorest.AsContentType("application/json; charset=utf-8"), 917 autorest.AsPatch(), 918 autorest.WithBaseURL(client.BaseURI), 919 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{uid}", pathParameters), 920 autorest.WithJSON(parameters), 921 autorest.WithQueryParameters(queryParameters), 922 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 923 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 924} 925 926// UpdateSender sends the Update request. The method will close the 927// http.Response Body if it receives an error. 928func (client UserClient) UpdateSender(req *http.Request) (*http.Response, error) { 929 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 930} 931 932// UpdateResponder handles the response to the Update request. The method always 933// closes the http.Response Body. 934func (client UserClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 935 err = autorest.Respond( 936 resp, 937 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 938 autorest.ByClosing()) 939 result.Response = resp 940 return 941} 942