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