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