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