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// PropertyClient is the apiManagement Client 19type PropertyClient struct { 20 BaseClient 21} 22 23// NewPropertyClient creates an instance of the PropertyClient client. 24func NewPropertyClient(subscriptionID string) PropertyClient { 25 return NewPropertyClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewPropertyClientWithBaseURI creates an instance of the PropertyClient client using a custom endpoint. Use this 29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewPropertyClientWithBaseURI(baseURI string, subscriptionID string) PropertyClient { 31 return PropertyClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates or updates a property. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// serviceName - the name of the API Management service. 38// propID - identifier of the property. 39// parameters - create parameters. 40// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity. 41func (client PropertyClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, propID string, parameters PropertyContract, ifMatch string) (result PropertyContract, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.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: propID, 58 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 59 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 60 {TargetValue: parameters, 61 Constraints: []validation.Constraint{{Target: "parameters.PropertyContractProperties", Name: validation.Null, Rule: false, 62 Chain: []validation.Constraint{{Target: "parameters.PropertyContractProperties.DisplayName", Name: validation.Null, Rule: true, 63 Chain: []validation.Constraint{{Target: "parameters.PropertyContractProperties.DisplayName", Name: validation.MaxLength, Rule: 256, Chain: nil}, 64 {Target: "parameters.PropertyContractProperties.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil}, 65 {Target: "parameters.PropertyContractProperties.DisplayName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]+$`, Chain: nil}, 66 }}, 67 {Target: "parameters.PropertyContractProperties.Value", Name: validation.Null, Rule: true, 68 Chain: []validation.Constraint{{Target: "parameters.PropertyContractProperties.Value", Name: validation.MaxLength, Rule: 4096, Chain: nil}, 69 {Target: "parameters.PropertyContractProperties.Value", Name: validation.MinLength, Rule: 1, Chain: nil}, 70 }}, 71 }}}}}); err != nil { 72 return result, validation.NewError("apimanagement.PropertyClient", "CreateOrUpdate", err.Error()) 73 } 74 75 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, propID, parameters, ifMatch) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "CreateOrUpdate", nil, "Failure preparing request") 78 return 79 } 80 81 resp, err := client.CreateOrUpdateSender(req) 82 if err != nil { 83 result.Response = autorest.Response{Response: resp} 84 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "CreateOrUpdate", resp, "Failure sending request") 85 return 86 } 87 88 result, err = client.CreateOrUpdateResponder(resp) 89 if err != nil { 90 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "CreateOrUpdate", resp, "Failure responding to request") 91 return 92 } 93 94 return 95} 96 97// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 98func (client PropertyClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, propID string, parameters PropertyContract, ifMatch string) (*http.Request, error) { 99 pathParameters := map[string]interface{}{ 100 "propId": autorest.Encode("path", propID), 101 "resourceGroupName": autorest.Encode("path", resourceGroupName), 102 "serviceName": autorest.Encode("path", serviceName), 103 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 104 } 105 106 const APIVersion = "2018-06-01-preview" 107 queryParameters := map[string]interface{}{ 108 "api-version": APIVersion, 109 } 110 111 preparer := autorest.CreatePreparer( 112 autorest.AsContentType("application/json; charset=utf-8"), 113 autorest.AsPut(), 114 autorest.WithBaseURL(client.BaseURI), 115 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/properties/{propId}", pathParameters), 116 autorest.WithJSON(parameters), 117 autorest.WithQueryParameters(queryParameters)) 118 if len(ifMatch) > 0 { 119 preparer = autorest.DecoratePreparer(preparer, 120 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 121 } 122 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 123} 124 125// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 126// http.Response Body if it receives an error. 127func (client PropertyClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 128 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 129} 130 131// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 132// closes the http.Response Body. 133func (client PropertyClient) CreateOrUpdateResponder(resp *http.Response) (result PropertyContract, err error) { 134 err = autorest.Respond( 135 resp, 136 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 137 autorest.ByUnmarshallingJSON(&result), 138 autorest.ByClosing()) 139 result.Response = autorest.Response{Response: resp} 140 return 141} 142 143// Delete deletes specific property from the API Management service instance. 144// Parameters: 145// resourceGroupName - the name of the resource group. 146// serviceName - the name of the API Management service. 147// propID - identifier of the property. 148// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 149// request or it should be * for unconditional update. 150func (client PropertyClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, propID string, ifMatch string) (result autorest.Response, err error) { 151 if tracing.IsEnabled() { 152 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Delete") 153 defer func() { 154 sc := -1 155 if result.Response != nil { 156 sc = result.Response.StatusCode 157 } 158 tracing.EndSpan(ctx, sc, err) 159 }() 160 } 161 if err := validation.Validate([]validation.Validation{ 162 {TargetValue: serviceName, 163 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 164 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 165 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 166 {TargetValue: propID, 167 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 168 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 169 return result, validation.NewError("apimanagement.PropertyClient", "Delete", err.Error()) 170 } 171 172 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, propID, ifMatch) 173 if err != nil { 174 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Delete", nil, "Failure preparing request") 175 return 176 } 177 178 resp, err := client.DeleteSender(req) 179 if err != nil { 180 result.Response = resp 181 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Delete", resp, "Failure sending request") 182 return 183 } 184 185 result, err = client.DeleteResponder(resp) 186 if err != nil { 187 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Delete", resp, "Failure responding to request") 188 return 189 } 190 191 return 192} 193 194// DeletePreparer prepares the Delete request. 195func (client PropertyClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, propID string, ifMatch string) (*http.Request, error) { 196 pathParameters := map[string]interface{}{ 197 "propId": autorest.Encode("path", propID), 198 "resourceGroupName": autorest.Encode("path", resourceGroupName), 199 "serviceName": autorest.Encode("path", serviceName), 200 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 201 } 202 203 const APIVersion = "2018-06-01-preview" 204 queryParameters := map[string]interface{}{ 205 "api-version": APIVersion, 206 } 207 208 preparer := autorest.CreatePreparer( 209 autorest.AsDelete(), 210 autorest.WithBaseURL(client.BaseURI), 211 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/properties/{propId}", pathParameters), 212 autorest.WithQueryParameters(queryParameters), 213 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 214 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 215} 216 217// DeleteSender sends the Delete request. The method will close the 218// http.Response Body if it receives an error. 219func (client PropertyClient) DeleteSender(req *http.Request) (*http.Response, error) { 220 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 221} 222 223// DeleteResponder handles the response to the Delete request. The method always 224// closes the http.Response Body. 225func (client PropertyClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 226 err = autorest.Respond( 227 resp, 228 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 229 autorest.ByClosing()) 230 result.Response = resp 231 return 232} 233 234// Get gets the details of the property specified by its identifier. 235// Parameters: 236// resourceGroupName - the name of the resource group. 237// serviceName - the name of the API Management service. 238// propID - identifier of the property. 239func (client PropertyClient) Get(ctx context.Context, resourceGroupName string, serviceName string, propID string) (result PropertyContract, err error) { 240 if tracing.IsEnabled() { 241 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Get") 242 defer func() { 243 sc := -1 244 if result.Response.Response != nil { 245 sc = result.Response.Response.StatusCode 246 } 247 tracing.EndSpan(ctx, sc, err) 248 }() 249 } 250 if err := validation.Validate([]validation.Validation{ 251 {TargetValue: serviceName, 252 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 253 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 254 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 255 {TargetValue: propID, 256 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 257 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 258 return result, validation.NewError("apimanagement.PropertyClient", "Get", err.Error()) 259 } 260 261 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, propID) 262 if err != nil { 263 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Get", nil, "Failure preparing request") 264 return 265 } 266 267 resp, err := client.GetSender(req) 268 if err != nil { 269 result.Response = autorest.Response{Response: resp} 270 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Get", resp, "Failure sending request") 271 return 272 } 273 274 result, err = client.GetResponder(resp) 275 if err != nil { 276 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Get", resp, "Failure responding to request") 277 return 278 } 279 280 return 281} 282 283// GetPreparer prepares the Get request. 284func (client PropertyClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, propID string) (*http.Request, error) { 285 pathParameters := map[string]interface{}{ 286 "propId": autorest.Encode("path", propID), 287 "resourceGroupName": autorest.Encode("path", resourceGroupName), 288 "serviceName": autorest.Encode("path", serviceName), 289 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 290 } 291 292 const APIVersion = "2018-06-01-preview" 293 queryParameters := map[string]interface{}{ 294 "api-version": APIVersion, 295 } 296 297 preparer := autorest.CreatePreparer( 298 autorest.AsGet(), 299 autorest.WithBaseURL(client.BaseURI), 300 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/properties/{propId}", pathParameters), 301 autorest.WithQueryParameters(queryParameters)) 302 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 303} 304 305// GetSender sends the Get request. The method will close the 306// http.Response Body if it receives an error. 307func (client PropertyClient) GetSender(req *http.Request) (*http.Response, error) { 308 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 309} 310 311// GetResponder handles the response to the Get request. The method always 312// closes the http.Response Body. 313func (client PropertyClient) GetResponder(resp *http.Response) (result PropertyContract, err error) { 314 err = autorest.Respond( 315 resp, 316 azure.WithErrorUnlessStatusCode(http.StatusOK), 317 autorest.ByUnmarshallingJSON(&result), 318 autorest.ByClosing()) 319 result.Response = autorest.Response{Response: resp} 320 return 321} 322 323// GetEntityTag gets the entity state (Etag) version of the property specified by its identifier. 324// Parameters: 325// resourceGroupName - the name of the resource group. 326// serviceName - the name of the API Management service. 327// propID - identifier of the property. 328func (client PropertyClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, propID string) (result autorest.Response, err error) { 329 if tracing.IsEnabled() { 330 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.GetEntityTag") 331 defer func() { 332 sc := -1 333 if result.Response != nil { 334 sc = result.Response.StatusCode 335 } 336 tracing.EndSpan(ctx, sc, err) 337 }() 338 } 339 if err := validation.Validate([]validation.Validation{ 340 {TargetValue: serviceName, 341 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 342 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 343 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 344 {TargetValue: propID, 345 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 346 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 347 return result, validation.NewError("apimanagement.PropertyClient", "GetEntityTag", err.Error()) 348 } 349 350 req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, propID) 351 if err != nil { 352 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "GetEntityTag", nil, "Failure preparing request") 353 return 354 } 355 356 resp, err := client.GetEntityTagSender(req) 357 if err != nil { 358 result.Response = resp 359 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "GetEntityTag", resp, "Failure sending request") 360 return 361 } 362 363 result, err = client.GetEntityTagResponder(resp) 364 if err != nil { 365 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "GetEntityTag", resp, "Failure responding to request") 366 return 367 } 368 369 return 370} 371 372// GetEntityTagPreparer prepares the GetEntityTag request. 373func (client PropertyClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, propID string) (*http.Request, error) { 374 pathParameters := map[string]interface{}{ 375 "propId": autorest.Encode("path", propID), 376 "resourceGroupName": autorest.Encode("path", resourceGroupName), 377 "serviceName": autorest.Encode("path", serviceName), 378 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 379 } 380 381 const APIVersion = "2018-06-01-preview" 382 queryParameters := map[string]interface{}{ 383 "api-version": APIVersion, 384 } 385 386 preparer := autorest.CreatePreparer( 387 autorest.AsHead(), 388 autorest.WithBaseURL(client.BaseURI), 389 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/properties/{propId}", pathParameters), 390 autorest.WithQueryParameters(queryParameters)) 391 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 392} 393 394// GetEntityTagSender sends the GetEntityTag request. The method will close the 395// http.Response Body if it receives an error. 396func (client PropertyClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { 397 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 398} 399 400// GetEntityTagResponder handles the response to the GetEntityTag request. The method always 401// closes the http.Response Body. 402func (client PropertyClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { 403 err = autorest.Respond( 404 resp, 405 azure.WithErrorUnlessStatusCode(http.StatusOK), 406 autorest.ByClosing()) 407 result.Response = resp 408 return 409} 410 411// ListByService lists a collection of properties defined within a service instance. 412// Parameters: 413// resourceGroupName - the name of the resource group. 414// serviceName - the name of the API Management service. 415// filter - | Field | Supported operators | Supported functions | 416// |-------------|------------------------|-----------------------------------| 417// 418// |tags | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith, any, all| 419// |displayName | 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 PropertyClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result PropertyCollectionPage, err error) { 423 if tracing.IsEnabled() { 424 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.ListByService") 425 defer func() { 426 sc := -1 427 if result.pc.Response.Response != nil { 428 sc = result.pc.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.PropertyClient", "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.PropertyClient", "ListByService", nil, "Failure preparing request") 451 return 452 } 453 454 resp, err := client.ListByServiceSender(req) 455 if err != nil { 456 result.pc.Response = autorest.Response{Response: resp} 457 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "ListByService", resp, "Failure sending request") 458 return 459 } 460 461 result.pc, err = client.ListByServiceResponder(resp) 462 if err != nil { 463 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "ListByService", resp, "Failure responding to request") 464 return 465 } 466 if result.pc.hasNextLink() && result.pc.IsEmpty() { 467 err = result.NextWithContext(ctx) 468 return 469 } 470 471 return 472} 473 474// ListByServicePreparer prepares the ListByService request. 475func (client PropertyClient) 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}/properties", 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 PropertyClient) 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 PropertyClient) ListByServiceResponder(resp *http.Response) (result PropertyCollection, 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 PropertyClient) listByServiceNextResults(ctx context.Context, lastResults PropertyCollection) (result PropertyCollection, err error) { 524 req, err := lastResults.propertyCollectionPreparer(ctx) 525 if err != nil { 526 return result, autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "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.PropertyClient", "listByServiceNextResults", resp, "Failure sending next results request") 535 } 536 result, err = client.ListByServiceResponder(resp) 537 if err != nil { 538 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "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 PropertyClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result PropertyCollectionIterator, err error) { 545 if tracing.IsEnabled() { 546 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.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// Update updates the specific property. 560// Parameters: 561// resourceGroupName - the name of the resource group. 562// serviceName - the name of the API Management service. 563// propID - identifier of the property. 564// parameters - update parameters. 565// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 566// request or it should be * for unconditional update. 567func (client PropertyClient) Update(ctx context.Context, resourceGroupName string, serviceName string, propID string, parameters PropertyUpdateParameters, ifMatch string) (result autorest.Response, err error) { 568 if tracing.IsEnabled() { 569 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Update") 570 defer func() { 571 sc := -1 572 if result.Response != nil { 573 sc = result.Response.StatusCode 574 } 575 tracing.EndSpan(ctx, sc, err) 576 }() 577 } 578 if err := validation.Validate([]validation.Validation{ 579 {TargetValue: serviceName, 580 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 581 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 582 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 583 {TargetValue: propID, 584 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 585 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 586 return result, validation.NewError("apimanagement.PropertyClient", "Update", err.Error()) 587 } 588 589 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, propID, parameters, ifMatch) 590 if err != nil { 591 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Update", nil, "Failure preparing request") 592 return 593 } 594 595 resp, err := client.UpdateSender(req) 596 if err != nil { 597 result.Response = resp 598 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Update", resp, "Failure sending request") 599 return 600 } 601 602 result, err = client.UpdateResponder(resp) 603 if err != nil { 604 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Update", resp, "Failure responding to request") 605 return 606 } 607 608 return 609} 610 611// UpdatePreparer prepares the Update request. 612func (client PropertyClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, propID string, parameters PropertyUpdateParameters, ifMatch string) (*http.Request, error) { 613 pathParameters := map[string]interface{}{ 614 "propId": autorest.Encode("path", propID), 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.AsPatch(), 628 autorest.WithBaseURL(client.BaseURI), 629 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/properties/{propId}", pathParameters), 630 autorest.WithJSON(parameters), 631 autorest.WithQueryParameters(queryParameters), 632 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 633 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 634} 635 636// UpdateSender sends the Update request. The method will close the 637// http.Response Body if it receives an error. 638func (client PropertyClient) UpdateSender(req *http.Request) (*http.Response, error) { 639 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 640} 641 642// UpdateResponder handles the response to the Update request. The method always 643// closes the http.Response Body. 644func (client PropertyClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 645 err = autorest.Respond( 646 resp, 647 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 648 autorest.ByClosing()) 649 result.Response = resp 650 return 651} 652