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// BackendClient is the apiManagement Client 30type BackendClient struct { 31 BaseClient 32} 33 34// NewBackendClient creates an instance of the BackendClient client. 35func NewBackendClient(subscriptionID string) BackendClient { 36 return NewBackendClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewBackendClientWithBaseURI creates an instance of the BackendClient 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 NewBackendClientWithBaseURI(baseURI string, subscriptionID string) BackendClient { 42 return BackendClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate creates or Updates a backend. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49// backendID - identifier of the Backend entity. 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 BackendClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, backendID string, parameters BackendContract, ifMatch string) (result BackendContract, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.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: backendID, 69 Constraints: []validation.Constraint{{Target: "backendID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 70 {Target: "backendID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 71 {TargetValue: parameters, 72 Constraints: []validation.Constraint{{Target: "parameters.BackendContractProperties", Name: validation.Null, Rule: false, 73 Chain: []validation.Constraint{{Target: "parameters.BackendContractProperties.URL", Name: validation.Null, Rule: true, 74 Chain: []validation.Constraint{{Target: "parameters.BackendContractProperties.URL", Name: validation.MaxLength, Rule: 2000, Chain: nil}, 75 {Target: "parameters.BackendContractProperties.URL", Name: validation.MinLength, Rule: 1, Chain: nil}, 76 }}, 77 }}}}}); err != nil { 78 return result, validation.NewError("apimanagement.BackendClient", "CreateOrUpdate", err.Error()) 79 } 80 81 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, backendID, parameters, ifMatch) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "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.BackendClient", "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.BackendClient", "CreateOrUpdate", resp, "Failure responding to request") 97 } 98 99 return 100} 101 102// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 103func (client BackendClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendID string, parameters BackendContract, ifMatch string) (*http.Request, error) { 104 pathParameters := map[string]interface{}{ 105 "backendId": autorest.Encode("path", backendID), 106 "resourceGroupName": autorest.Encode("path", resourceGroupName), 107 "serviceName": autorest.Encode("path", serviceName), 108 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 109 } 110 111 const APIVersion = "2019-12-01" 112 queryParameters := map[string]interface{}{ 113 "api-version": APIVersion, 114 } 115 116 preparer := autorest.CreatePreparer( 117 autorest.AsContentType("application/json; charset=utf-8"), 118 autorest.AsPut(), 119 autorest.WithBaseURL(client.BaseURI), 120 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}", pathParameters), 121 autorest.WithJSON(parameters), 122 autorest.WithQueryParameters(queryParameters)) 123 if len(ifMatch) > 0 { 124 preparer = autorest.DecoratePreparer(preparer, 125 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 126 } 127 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 128} 129 130// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 131// http.Response Body if it receives an error. 132func (client BackendClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 133 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 134} 135 136// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 137// closes the http.Response Body. 138func (client BackendClient) CreateOrUpdateResponder(resp *http.Response) (result BackendContract, err error) { 139 err = autorest.Respond( 140 resp, 141 client.ByInspecting(), 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 the specified backend. 150// Parameters: 151// resourceGroupName - the name of the resource group. 152// serviceName - the name of the API Management service. 153// backendID - identifier of the Backend entity. 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 BackendClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, backendID string, ifMatch string) (result autorest.Response, err error) { 157 if tracing.IsEnabled() { 158 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.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: backendID, 173 Constraints: []validation.Constraint{{Target: "backendID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 174 {Target: "backendID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 175 return result, validation.NewError("apimanagement.BackendClient", "Delete", err.Error()) 176 } 177 178 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, backendID, ifMatch) 179 if err != nil { 180 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "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.BackendClient", "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.BackendClient", "Delete", resp, "Failure responding to request") 194 } 195 196 return 197} 198 199// DeletePreparer prepares the Delete request. 200func (client BackendClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendID string, ifMatch string) (*http.Request, error) { 201 pathParameters := map[string]interface{}{ 202 "backendId": autorest.Encode("path", backendID), 203 "resourceGroupName": autorest.Encode("path", resourceGroupName), 204 "serviceName": autorest.Encode("path", serviceName), 205 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 206 } 207 208 const APIVersion = "2019-12-01" 209 queryParameters := map[string]interface{}{ 210 "api-version": APIVersion, 211 } 212 213 preparer := autorest.CreatePreparer( 214 autorest.AsDelete(), 215 autorest.WithBaseURL(client.BaseURI), 216 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}", pathParameters), 217 autorest.WithQueryParameters(queryParameters), 218 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 219 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 220} 221 222// DeleteSender sends the Delete request. The method will close the 223// http.Response Body if it receives an error. 224func (client BackendClient) DeleteSender(req *http.Request) (*http.Response, error) { 225 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 226} 227 228// DeleteResponder handles the response to the Delete request. The method always 229// closes the http.Response Body. 230func (client BackendClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 231 err = autorest.Respond( 232 resp, 233 client.ByInspecting(), 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 backend specified by its identifier. 241// Parameters: 242// resourceGroupName - the name of the resource group. 243// serviceName - the name of the API Management service. 244// backendID - identifier of the Backend entity. Must be unique in the current API Management service instance. 245func (client BackendClient) Get(ctx context.Context, resourceGroupName string, serviceName string, backendID string) (result BackendContract, err error) { 246 if tracing.IsEnabled() { 247 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.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: backendID, 262 Constraints: []validation.Constraint{{Target: "backendID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 263 {Target: "backendID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 264 return result, validation.NewError("apimanagement.BackendClient", "Get", err.Error()) 265 } 266 267 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, backendID) 268 if err != nil { 269 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "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.BackendClient", "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.BackendClient", "Get", resp, "Failure responding to request") 283 } 284 285 return 286} 287 288// GetPreparer prepares the Get request. 289func (client BackendClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendID string) (*http.Request, error) { 290 pathParameters := map[string]interface{}{ 291 "backendId": autorest.Encode("path", backendID), 292 "resourceGroupName": autorest.Encode("path", resourceGroupName), 293 "serviceName": autorest.Encode("path", serviceName), 294 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 295 } 296 297 const APIVersion = "2019-12-01" 298 queryParameters := map[string]interface{}{ 299 "api-version": APIVersion, 300 } 301 302 preparer := autorest.CreatePreparer( 303 autorest.AsGet(), 304 autorest.WithBaseURL(client.BaseURI), 305 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}", pathParameters), 306 autorest.WithQueryParameters(queryParameters)) 307 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 308} 309 310// GetSender sends the Get request. The method will close the 311// http.Response Body if it receives an error. 312func (client BackendClient) GetSender(req *http.Request) (*http.Response, error) { 313 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 314} 315 316// GetResponder handles the response to the Get request. The method always 317// closes the http.Response Body. 318func (client BackendClient) GetResponder(resp *http.Response) (result BackendContract, err error) { 319 err = autorest.Respond( 320 resp, 321 client.ByInspecting(), 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 backend specified by its identifier. 330// Parameters: 331// resourceGroupName - the name of the resource group. 332// serviceName - the name of the API Management service. 333// backendID - identifier of the Backend entity. Must be unique in the current API Management service instance. 334func (client BackendClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, backendID string) (result autorest.Response, err error) { 335 if tracing.IsEnabled() { 336 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.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: backendID, 351 Constraints: []validation.Constraint{{Target: "backendID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 352 {Target: "backendID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 353 return result, validation.NewError("apimanagement.BackendClient", "GetEntityTag", err.Error()) 354 } 355 356 req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, backendID) 357 if err != nil { 358 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "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.BackendClient", "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.BackendClient", "GetEntityTag", resp, "Failure responding to request") 372 } 373 374 return 375} 376 377// GetEntityTagPreparer prepares the GetEntityTag request. 378func (client BackendClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendID string) (*http.Request, error) { 379 pathParameters := map[string]interface{}{ 380 "backendId": autorest.Encode("path", backendID), 381 "resourceGroupName": autorest.Encode("path", resourceGroupName), 382 "serviceName": autorest.Encode("path", serviceName), 383 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 384 } 385 386 const APIVersion = "2019-12-01" 387 queryParameters := map[string]interface{}{ 388 "api-version": APIVersion, 389 } 390 391 preparer := autorest.CreatePreparer( 392 autorest.AsHead(), 393 autorest.WithBaseURL(client.BaseURI), 394 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}", pathParameters), 395 autorest.WithQueryParameters(queryParameters)) 396 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 397} 398 399// GetEntityTagSender sends the GetEntityTag request. The method will close the 400// http.Response Body if it receives an error. 401func (client BackendClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { 402 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 403} 404 405// GetEntityTagResponder handles the response to the GetEntityTag request. The method always 406// closes the http.Response Body. 407func (client BackendClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { 408 err = autorest.Respond( 409 resp, 410 client.ByInspecting(), 411 azure.WithErrorUnlessStatusCode(http.StatusOK), 412 autorest.ByClosing()) 413 result.Response = resp 414 return 415} 416 417// ListByService lists a collection of backends in the specified 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>| title | filter | ge, le, eq, ne, gt, lt | 424// substringof, contains, startswith, endswith | </br>| url | filter | ge, le, eq, ne, gt, lt | substringof, 425// contains, startswith, endswith | </br> 426// top - number of records to return. 427// skip - number of records to skip. 428func (client BackendClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result BackendCollectionPage, err error) { 429 if tracing.IsEnabled() { 430 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.ListByService") 431 defer func() { 432 sc := -1 433 if result.bc.Response.Response != nil { 434 sc = result.bc.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.BackendClient", "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.BackendClient", "ListByService", nil, "Failure preparing request") 457 return 458 } 459 460 resp, err := client.ListByServiceSender(req) 461 if err != nil { 462 result.bc.Response = autorest.Response{Response: resp} 463 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "ListByService", resp, "Failure sending request") 464 return 465 } 466 467 result.bc, err = client.ListByServiceResponder(resp) 468 if err != nil { 469 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "ListByService", resp, "Failure responding to request") 470 } 471 472 return 473} 474 475// ListByServicePreparer prepares the ListByService request. 476func (client BackendClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) { 477 pathParameters := map[string]interface{}{ 478 "resourceGroupName": autorest.Encode("path", resourceGroupName), 479 "serviceName": autorest.Encode("path", serviceName), 480 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 481 } 482 483 const APIVersion = "2019-12-01" 484 queryParameters := map[string]interface{}{ 485 "api-version": APIVersion, 486 } 487 if len(filter) > 0 { 488 queryParameters["$filter"] = autorest.Encode("query", filter) 489 } 490 if top != nil { 491 queryParameters["$top"] = autorest.Encode("query", *top) 492 } 493 if skip != nil { 494 queryParameters["$skip"] = autorest.Encode("query", *skip) 495 } 496 497 preparer := autorest.CreatePreparer( 498 autorest.AsGet(), 499 autorest.WithBaseURL(client.BaseURI), 500 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends", pathParameters), 501 autorest.WithQueryParameters(queryParameters)) 502 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 503} 504 505// ListByServiceSender sends the ListByService request. The method will close the 506// http.Response Body if it receives an error. 507func (client BackendClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 508 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 509} 510 511// ListByServiceResponder handles the response to the ListByService request. The method always 512// closes the http.Response Body. 513func (client BackendClient) ListByServiceResponder(resp *http.Response) (result BackendCollection, err error) { 514 err = autorest.Respond( 515 resp, 516 client.ByInspecting(), 517 azure.WithErrorUnlessStatusCode(http.StatusOK), 518 autorest.ByUnmarshallingJSON(&result), 519 autorest.ByClosing()) 520 result.Response = autorest.Response{Response: resp} 521 return 522} 523 524// listByServiceNextResults retrieves the next set of results, if any. 525func (client BackendClient) listByServiceNextResults(ctx context.Context, lastResults BackendCollection) (result BackendCollection, err error) { 526 req, err := lastResults.backendCollectionPreparer(ctx) 527 if err != nil { 528 return result, autorest.NewErrorWithError(err, "apimanagement.BackendClient", "listByServiceNextResults", nil, "Failure preparing next results request") 529 } 530 if req == nil { 531 return 532 } 533 resp, err := client.ListByServiceSender(req) 534 if err != nil { 535 result.Response = autorest.Response{Response: resp} 536 return result, autorest.NewErrorWithError(err, "apimanagement.BackendClient", "listByServiceNextResults", resp, "Failure sending next results request") 537 } 538 result, err = client.ListByServiceResponder(resp) 539 if err != nil { 540 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "listByServiceNextResults", resp, "Failure responding to next results request") 541 } 542 return 543} 544 545// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 546func (client BackendClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result BackendCollectionIterator, err error) { 547 if tracing.IsEnabled() { 548 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.ListByService") 549 defer func() { 550 sc := -1 551 if result.Response().Response.Response != nil { 552 sc = result.page.Response().Response.Response.StatusCode 553 } 554 tracing.EndSpan(ctx, sc, err) 555 }() 556 } 557 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip) 558 return 559} 560 561// Reconnect notifies the APIM proxy to create a new connection to the backend after the specified timeout. If no 562// timeout was specified, timeout of 2 minutes is used. 563// Parameters: 564// resourceGroupName - the name of the resource group. 565// serviceName - the name of the API Management service. 566// backendID - identifier of the Backend entity. Must be unique in the current API Management service instance. 567// parameters - reconnect request parameters. 568func (client BackendClient) Reconnect(ctx context.Context, resourceGroupName string, serviceName string, backendID string, parameters *BackendReconnectContract) (result autorest.Response, err error) { 569 if tracing.IsEnabled() { 570 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.Reconnect") 571 defer func() { 572 sc := -1 573 if result.Response != nil { 574 sc = result.Response.StatusCode 575 } 576 tracing.EndSpan(ctx, sc, err) 577 }() 578 } 579 if err := validation.Validate([]validation.Validation{ 580 {TargetValue: serviceName, 581 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 582 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 583 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 584 {TargetValue: backendID, 585 Constraints: []validation.Constraint{{Target: "backendID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 586 {Target: "backendID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 587 return result, validation.NewError("apimanagement.BackendClient", "Reconnect", err.Error()) 588 } 589 590 req, err := client.ReconnectPreparer(ctx, resourceGroupName, serviceName, backendID, parameters) 591 if err != nil { 592 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Reconnect", nil, "Failure preparing request") 593 return 594 } 595 596 resp, err := client.ReconnectSender(req) 597 if err != nil { 598 result.Response = resp 599 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Reconnect", resp, "Failure sending request") 600 return 601 } 602 603 result, err = client.ReconnectResponder(resp) 604 if err != nil { 605 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Reconnect", resp, "Failure responding to request") 606 } 607 608 return 609} 610 611// ReconnectPreparer prepares the Reconnect request. 612func (client BackendClient) ReconnectPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendID string, parameters *BackendReconnectContract) (*http.Request, error) { 613 pathParameters := map[string]interface{}{ 614 "backendId": autorest.Encode("path", backendID), 615 "resourceGroupName": autorest.Encode("path", resourceGroupName), 616 "serviceName": autorest.Encode("path", serviceName), 617 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 618 } 619 620 const APIVersion = "2019-12-01" 621 queryParameters := map[string]interface{}{ 622 "api-version": APIVersion, 623 } 624 625 preparer := autorest.CreatePreparer( 626 autorest.AsContentType("application/json; charset=utf-8"), 627 autorest.AsPost(), 628 autorest.WithBaseURL(client.BaseURI), 629 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}/reconnect", pathParameters), 630 autorest.WithQueryParameters(queryParameters)) 631 if parameters != nil { 632 preparer = autorest.DecoratePreparer(preparer, 633 autorest.WithJSON(parameters)) 634 } 635 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 636} 637 638// ReconnectSender sends the Reconnect request. The method will close the 639// http.Response Body if it receives an error. 640func (client BackendClient) ReconnectSender(req *http.Request) (*http.Response, error) { 641 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 642} 643 644// ReconnectResponder handles the response to the Reconnect request. The method always 645// closes the http.Response Body. 646func (client BackendClient) ReconnectResponder(resp *http.Response) (result autorest.Response, err error) { 647 err = autorest.Respond( 648 resp, 649 client.ByInspecting(), 650 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 651 autorest.ByClosing()) 652 result.Response = resp 653 return 654} 655 656// Update updates an existing backend. 657// Parameters: 658// resourceGroupName - the name of the resource group. 659// serviceName - the name of the API Management service. 660// backendID - identifier of the Backend entity. Must be unique in the current API Management service instance. 661// parameters - update parameters. 662// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 663// request or it should be * for unconditional update. 664func (client BackendClient) Update(ctx context.Context, resourceGroupName string, serviceName string, backendID string, parameters BackendUpdateParameters, ifMatch string) (result autorest.Response, err error) { 665 if tracing.IsEnabled() { 666 ctx = tracing.StartSpan(ctx, fqdn+"/BackendClient.Update") 667 defer func() { 668 sc := -1 669 if result.Response != nil { 670 sc = result.Response.StatusCode 671 } 672 tracing.EndSpan(ctx, sc, err) 673 }() 674 } 675 if err := validation.Validate([]validation.Validation{ 676 {TargetValue: serviceName, 677 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 678 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 679 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 680 {TargetValue: backendID, 681 Constraints: []validation.Constraint{{Target: "backendID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 682 {Target: "backendID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 683 return result, validation.NewError("apimanagement.BackendClient", "Update", err.Error()) 684 } 685 686 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, backendID, parameters, ifMatch) 687 if err != nil { 688 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Update", nil, "Failure preparing request") 689 return 690 } 691 692 resp, err := client.UpdateSender(req) 693 if err != nil { 694 result.Response = resp 695 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Update", resp, "Failure sending request") 696 return 697 } 698 699 result, err = client.UpdateResponder(resp) 700 if err != nil { 701 err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Update", resp, "Failure responding to request") 702 } 703 704 return 705} 706 707// UpdatePreparer prepares the Update request. 708func (client BackendClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendID string, parameters BackendUpdateParameters, ifMatch string) (*http.Request, error) { 709 pathParameters := map[string]interface{}{ 710 "backendId": autorest.Encode("path", backendID), 711 "resourceGroupName": autorest.Encode("path", resourceGroupName), 712 "serviceName": autorest.Encode("path", serviceName), 713 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 714 } 715 716 const APIVersion = "2019-12-01" 717 queryParameters := map[string]interface{}{ 718 "api-version": APIVersion, 719 } 720 721 preparer := autorest.CreatePreparer( 722 autorest.AsContentType("application/json; charset=utf-8"), 723 autorest.AsPatch(), 724 autorest.WithBaseURL(client.BaseURI), 725 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}", pathParameters), 726 autorest.WithJSON(parameters), 727 autorest.WithQueryParameters(queryParameters), 728 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 729 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 730} 731 732// UpdateSender sends the Update request. The method will close the 733// http.Response Body if it receives an error. 734func (client BackendClient) UpdateSender(req *http.Request) (*http.Response, error) { 735 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 736} 737 738// UpdateResponder handles the response to the Update request. The method always 739// closes the http.Response Body. 740func (client BackendClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 741 err = autorest.Respond( 742 resp, 743 client.ByInspecting(), 744 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 745 autorest.ByClosing()) 746 result.Response = resp 747 return 748} 749