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// GroupUserClient is the apiManagement Client 30type GroupUserClient struct { 31 BaseClient 32} 33 34// NewGroupUserClient creates an instance of the GroupUserClient client. 35func NewGroupUserClient(subscriptionID string) GroupUserClient { 36 return NewGroupUserClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewGroupUserClientWithBaseURI creates an instance of the GroupUserClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewGroupUserClientWithBaseURI(baseURI string, subscriptionID string) GroupUserClient { 42 return GroupUserClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CheckEntityExists checks that user entity specified by identifier is associated with the group entity. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49// groupID - group identifier. Must be unique in the current API Management service instance. 50// userID - user identifier. Must be unique in the current API Management service instance. 51func (client GroupUserClient) CheckEntityExists(ctx context.Context, resourceGroupName string, serviceName string, groupID string, userID string) (result autorest.Response, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/GroupUserClient.CheckEntityExists") 54 defer func() { 55 sc := -1 56 if result.Response != nil { 57 sc = result.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: serviceName, 64 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 65 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 67 {TargetValue: groupID, 68 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 69 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 70 {TargetValue: userID, 71 Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 72 {Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 73 return result, validation.NewError("apimanagement.GroupUserClient", "CheckEntityExists", err.Error()) 74 } 75 76 req, err := client.CheckEntityExistsPreparer(ctx, resourceGroupName, serviceName, groupID, userID) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "CheckEntityExists", nil, "Failure preparing request") 79 return 80 } 81 82 resp, err := client.CheckEntityExistsSender(req) 83 if err != nil { 84 result.Response = resp 85 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "CheckEntityExists", resp, "Failure sending request") 86 return 87 } 88 89 result, err = client.CheckEntityExistsResponder(resp) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "CheckEntityExists", resp, "Failure responding to request") 92 return 93 } 94 95 return 96} 97 98// CheckEntityExistsPreparer prepares the CheckEntityExists request. 99func (client GroupUserClient) CheckEntityExistsPreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, userID string) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "groupId": autorest.Encode("path", groupID), 102 "resourceGroupName": autorest.Encode("path", resourceGroupName), 103 "serviceName": autorest.Encode("path", serviceName), 104 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 105 "userId": autorest.Encode("path", userID), 106 } 107 108 const APIVersion = "2019-12-01" 109 queryParameters := map[string]interface{}{ 110 "api-version": APIVersion, 111 } 112 113 preparer := autorest.CreatePreparer( 114 autorest.AsHead(), 115 autorest.WithBaseURL(client.BaseURI), 116 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups/{groupId}/users/{userId}", pathParameters), 117 autorest.WithQueryParameters(queryParameters)) 118 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 119} 120 121// CheckEntityExistsSender sends the CheckEntityExists request. The method will close the 122// http.Response Body if it receives an error. 123func (client GroupUserClient) CheckEntityExistsSender(req *http.Request) (*http.Response, error) { 124 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 125} 126 127// CheckEntityExistsResponder handles the response to the CheckEntityExists request. The method always 128// closes the http.Response Body. 129func (client GroupUserClient) CheckEntityExistsResponder(resp *http.Response) (result autorest.Response, err error) { 130 err = autorest.Respond( 131 resp, 132 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusNotFound), 133 autorest.ByClosing()) 134 result.Response = resp 135 return 136} 137 138// Create add existing user to existing group 139// Parameters: 140// resourceGroupName - the name of the resource group. 141// serviceName - the name of the API Management service. 142// groupID - group identifier. Must be unique in the current API Management service instance. 143// userID - user identifier. Must be unique in the current API Management service instance. 144func (client GroupUserClient) Create(ctx context.Context, resourceGroupName string, serviceName string, groupID string, userID string) (result UserContract, err error) { 145 if tracing.IsEnabled() { 146 ctx = tracing.StartSpan(ctx, fqdn+"/GroupUserClient.Create") 147 defer func() { 148 sc := -1 149 if result.Response.Response != nil { 150 sc = result.Response.Response.StatusCode 151 } 152 tracing.EndSpan(ctx, sc, err) 153 }() 154 } 155 if err := validation.Validate([]validation.Validation{ 156 {TargetValue: serviceName, 157 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 158 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 159 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 160 {TargetValue: groupID, 161 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 162 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 163 {TargetValue: userID, 164 Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 165 {Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 166 return result, validation.NewError("apimanagement.GroupUserClient", "Create", err.Error()) 167 } 168 169 req, err := client.CreatePreparer(ctx, resourceGroupName, serviceName, groupID, userID) 170 if err != nil { 171 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "Create", nil, "Failure preparing request") 172 return 173 } 174 175 resp, err := client.CreateSender(req) 176 if err != nil { 177 result.Response = autorest.Response{Response: resp} 178 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "Create", resp, "Failure sending request") 179 return 180 } 181 182 result, err = client.CreateResponder(resp) 183 if err != nil { 184 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "Create", resp, "Failure responding to request") 185 return 186 } 187 188 return 189} 190 191// CreatePreparer prepares the Create request. 192func (client GroupUserClient) CreatePreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, userID string) (*http.Request, error) { 193 pathParameters := map[string]interface{}{ 194 "groupId": autorest.Encode("path", groupID), 195 "resourceGroupName": autorest.Encode("path", resourceGroupName), 196 "serviceName": autorest.Encode("path", serviceName), 197 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 198 "userId": autorest.Encode("path", userID), 199 } 200 201 const APIVersion = "2019-12-01" 202 queryParameters := map[string]interface{}{ 203 "api-version": APIVersion, 204 } 205 206 preparer := autorest.CreatePreparer( 207 autorest.AsPut(), 208 autorest.WithBaseURL(client.BaseURI), 209 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups/{groupId}/users/{userId}", pathParameters), 210 autorest.WithQueryParameters(queryParameters)) 211 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 212} 213 214// CreateSender sends the Create request. The method will close the 215// http.Response Body if it receives an error. 216func (client GroupUserClient) CreateSender(req *http.Request) (*http.Response, error) { 217 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 218} 219 220// CreateResponder handles the response to the Create request. The method always 221// closes the http.Response Body. 222func (client GroupUserClient) CreateResponder(resp *http.Response) (result UserContract, err error) { 223 err = autorest.Respond( 224 resp, 225 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 226 autorest.ByUnmarshallingJSON(&result), 227 autorest.ByClosing()) 228 result.Response = autorest.Response{Response: resp} 229 return 230} 231 232// Delete remove existing user from existing group. 233// Parameters: 234// resourceGroupName - the name of the resource group. 235// serviceName - the name of the API Management service. 236// groupID - group identifier. Must be unique in the current API Management service instance. 237// userID - user identifier. Must be unique in the current API Management service instance. 238func (client GroupUserClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, groupID string, userID string) (result autorest.Response, err error) { 239 if tracing.IsEnabled() { 240 ctx = tracing.StartSpan(ctx, fqdn+"/GroupUserClient.Delete") 241 defer func() { 242 sc := -1 243 if result.Response != nil { 244 sc = result.Response.StatusCode 245 } 246 tracing.EndSpan(ctx, sc, err) 247 }() 248 } 249 if err := validation.Validate([]validation.Validation{ 250 {TargetValue: serviceName, 251 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 252 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 253 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 254 {TargetValue: groupID, 255 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 256 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 257 {TargetValue: userID, 258 Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 259 {Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 260 return result, validation.NewError("apimanagement.GroupUserClient", "Delete", err.Error()) 261 } 262 263 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, groupID, userID) 264 if err != nil { 265 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "Delete", nil, "Failure preparing request") 266 return 267 } 268 269 resp, err := client.DeleteSender(req) 270 if err != nil { 271 result.Response = resp 272 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "Delete", resp, "Failure sending request") 273 return 274 } 275 276 result, err = client.DeleteResponder(resp) 277 if err != nil { 278 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "Delete", resp, "Failure responding to request") 279 return 280 } 281 282 return 283} 284 285// DeletePreparer prepares the Delete request. 286func (client GroupUserClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, userID string) (*http.Request, error) { 287 pathParameters := map[string]interface{}{ 288 "groupId": autorest.Encode("path", groupID), 289 "resourceGroupName": autorest.Encode("path", resourceGroupName), 290 "serviceName": autorest.Encode("path", serviceName), 291 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 292 "userId": autorest.Encode("path", userID), 293 } 294 295 const APIVersion = "2019-12-01" 296 queryParameters := map[string]interface{}{ 297 "api-version": APIVersion, 298 } 299 300 preparer := autorest.CreatePreparer( 301 autorest.AsDelete(), 302 autorest.WithBaseURL(client.BaseURI), 303 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups/{groupId}/users/{userId}", pathParameters), 304 autorest.WithQueryParameters(queryParameters)) 305 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 306} 307 308// DeleteSender sends the Delete request. The method will close the 309// http.Response Body if it receives an error. 310func (client GroupUserClient) DeleteSender(req *http.Request) (*http.Response, error) { 311 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 312} 313 314// DeleteResponder handles the response to the Delete request. The method always 315// closes the http.Response Body. 316func (client GroupUserClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 317 err = autorest.Respond( 318 resp, 319 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 320 autorest.ByClosing()) 321 result.Response = resp 322 return 323} 324 325// List lists a collection of user entities associated with the group. 326// Parameters: 327// resourceGroupName - the name of the resource group. 328// serviceName - the name of the API Management service. 329// groupID - group identifier. Must be unique in the current API Management service instance. 330// filter - | Field | Usage | Supported operators | Supported functions 331// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt 332// | substringof, contains, startswith, endswith | </br>| firstName | filter | ge, le, eq, ne, gt, lt | 333// substringof, contains, startswith, endswith | </br>| lastName | filter | ge, le, eq, ne, gt, lt | 334// substringof, contains, startswith, endswith | </br>| email | filter | ge, le, eq, ne, gt, lt | substringof, 335// contains, startswith, endswith | </br>| registrationDate | filter | ge, le, eq, ne, gt, lt | | </br>| 336// note | filter | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | </br> 337// top - number of records to return. 338// skip - number of records to skip. 339func (client GroupUserClient) List(ctx context.Context, resourceGroupName string, serviceName string, groupID string, filter string, top *int32, skip *int32) (result UserCollectionPage, err error) { 340 if tracing.IsEnabled() { 341 ctx = tracing.StartSpan(ctx, fqdn+"/GroupUserClient.List") 342 defer func() { 343 sc := -1 344 if result.uc.Response.Response != nil { 345 sc = result.uc.Response.Response.StatusCode 346 } 347 tracing.EndSpan(ctx, sc, err) 348 }() 349 } 350 if err := validation.Validate([]validation.Validation{ 351 {TargetValue: serviceName, 352 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 353 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 354 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 355 {TargetValue: groupID, 356 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 357 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 358 {TargetValue: top, 359 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 360 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 361 {TargetValue: skip, 362 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 363 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 364 return result, validation.NewError("apimanagement.GroupUserClient", "List", err.Error()) 365 } 366 367 result.fn = client.listNextResults 368 req, err := client.ListPreparer(ctx, resourceGroupName, serviceName, groupID, filter, top, skip) 369 if err != nil { 370 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "List", nil, "Failure preparing request") 371 return 372 } 373 374 resp, err := client.ListSender(req) 375 if err != nil { 376 result.uc.Response = autorest.Response{Response: resp} 377 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "List", resp, "Failure sending request") 378 return 379 } 380 381 result.uc, err = client.ListResponder(resp) 382 if err != nil { 383 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "List", resp, "Failure responding to request") 384 return 385 } 386 if result.uc.hasNextLink() && result.uc.IsEmpty() { 387 err = result.NextWithContext(ctx) 388 return 389 } 390 391 return 392} 393 394// ListPreparer prepares the List request. 395func (client GroupUserClient) ListPreparer(ctx context.Context, resourceGroupName string, serviceName string, groupID string, filter string, top *int32, skip *int32) (*http.Request, error) { 396 pathParameters := map[string]interface{}{ 397 "groupId": autorest.Encode("path", groupID), 398 "resourceGroupName": autorest.Encode("path", resourceGroupName), 399 "serviceName": autorest.Encode("path", serviceName), 400 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 401 } 402 403 const APIVersion = "2019-12-01" 404 queryParameters := map[string]interface{}{ 405 "api-version": APIVersion, 406 } 407 if len(filter) > 0 { 408 queryParameters["$filter"] = autorest.Encode("query", filter) 409 } 410 if top != nil { 411 queryParameters["$top"] = autorest.Encode("query", *top) 412 } 413 if skip != nil { 414 queryParameters["$skip"] = autorest.Encode("query", *skip) 415 } 416 417 preparer := autorest.CreatePreparer( 418 autorest.AsGet(), 419 autorest.WithBaseURL(client.BaseURI), 420 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/groups/{groupId}/users", pathParameters), 421 autorest.WithQueryParameters(queryParameters)) 422 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 423} 424 425// ListSender sends the List request. The method will close the 426// http.Response Body if it receives an error. 427func (client GroupUserClient) ListSender(req *http.Request) (*http.Response, error) { 428 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 429} 430 431// ListResponder handles the response to the List request. The method always 432// closes the http.Response Body. 433func (client GroupUserClient) ListResponder(resp *http.Response) (result UserCollection, err error) { 434 err = autorest.Respond( 435 resp, 436 azure.WithErrorUnlessStatusCode(http.StatusOK), 437 autorest.ByUnmarshallingJSON(&result), 438 autorest.ByClosing()) 439 result.Response = autorest.Response{Response: resp} 440 return 441} 442 443// listNextResults retrieves the next set of results, if any. 444func (client GroupUserClient) listNextResults(ctx context.Context, lastResults UserCollection) (result UserCollection, err error) { 445 req, err := lastResults.userCollectionPreparer(ctx) 446 if err != nil { 447 return result, autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "listNextResults", nil, "Failure preparing next results request") 448 } 449 if req == nil { 450 return 451 } 452 resp, err := client.ListSender(req) 453 if err != nil { 454 result.Response = autorest.Response{Response: resp} 455 return result, autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "listNextResults", resp, "Failure sending next results request") 456 } 457 result, err = client.ListResponder(resp) 458 if err != nil { 459 err = autorest.NewErrorWithError(err, "apimanagement.GroupUserClient", "listNextResults", resp, "Failure responding to next results request") 460 } 461 return 462} 463 464// ListComplete enumerates all values, automatically crossing page boundaries as required. 465func (client GroupUserClient) ListComplete(ctx context.Context, resourceGroupName string, serviceName string, groupID string, filter string, top *int32, skip *int32) (result UserCollectionIterator, err error) { 466 if tracing.IsEnabled() { 467 ctx = tracing.StartSpan(ctx, fqdn+"/GroupUserClient.List") 468 defer func() { 469 sc := -1 470 if result.Response().Response.Response != nil { 471 sc = result.page.Response().Response.Response.StatusCode 472 } 473 tracing.EndSpan(ctx, sc, err) 474 }() 475 } 476 result.page, err = client.List(ctx, resourceGroupName, serviceName, groupID, filter, top, skip) 477 return 478} 479