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