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 client for the Property methods of the Apimanagement service. 19type PropertyClient struct { 20 BaseClient 21} 22 23// NewPropertyClient creates an instance of the PropertyClient client. 24func NewPropertyClient() PropertyClient { 25 return PropertyClient{New()} 26} 27 28// CreateOrUpdate creates or updates a property. 29// Parameters: 30// apimBaseURL - the management endpoint of the API Management service, for example 31// https://myapimservice.management.azure-api.net. 32// propID - identifier of the property. 33// parameters - create parameters. 34func (client PropertyClient) CreateOrUpdate(ctx context.Context, apimBaseURL string, propID string, parameters PropertyContract) (result PropertyContract, err error) { 35 if tracing.IsEnabled() { 36 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.CreateOrUpdate") 37 defer func() { 38 sc := -1 39 if result.Response.Response != nil { 40 sc = result.Response.Response.StatusCode 41 } 42 tracing.EndSpan(ctx, sc, err) 43 }() 44 } 45 if err := validation.Validate([]validation.Validation{ 46 {TargetValue: propID, 47 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 48 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 49 return result, validation.NewError("apimanagement.PropertyClient", "CreateOrUpdate", err.Error()) 50 } 51 52 req, err := client.CreateOrUpdatePreparer(ctx, apimBaseURL, propID, parameters) 53 if err != nil { 54 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "CreateOrUpdate", nil, "Failure preparing request") 55 return 56 } 57 58 resp, err := client.CreateOrUpdateSender(req) 59 if err != nil { 60 result.Response = autorest.Response{Response: resp} 61 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "CreateOrUpdate", resp, "Failure sending request") 62 return 63 } 64 65 result, err = client.CreateOrUpdateResponder(resp) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "CreateOrUpdate", resp, "Failure responding to request") 68 return 69 } 70 71 return 72} 73 74// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 75func (client PropertyClient) CreateOrUpdatePreparer(ctx context.Context, apimBaseURL string, propID string, parameters PropertyContract) (*http.Request, error) { 76 urlParameters := map[string]interface{}{ 77 "apimBaseUrl": apimBaseURL, 78 } 79 80 pathParameters := map[string]interface{}{ 81 "propId": autorest.Encode("path", propID), 82 } 83 84 const APIVersion = "2017-03-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPut(), 92 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 93 autorest.WithPathParameters("/properties/{propId}", pathParameters), 94 autorest.WithJSON(parameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 100// http.Response Body if it receives an error. 101func (client PropertyClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 103} 104 105// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 106// closes the http.Response Body. 107func (client PropertyClient) CreateOrUpdateResponder(resp *http.Response) (result PropertyContract, err error) { 108 err = autorest.Respond( 109 resp, 110 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116 117// Delete deletes specific property from the API Management service instance. 118// Parameters: 119// apimBaseURL - the management endpoint of the API Management service, for example 120// https://myapimservice.management.azure-api.net. 121// propID - identifier of the property. 122// ifMatch - the entity state (Etag) version of the property to delete. A value of "*" can be used for If-Match 123// to unconditionally apply the operation. 124func (client PropertyClient) Delete(ctx context.Context, apimBaseURL string, propID string, ifMatch string) (result autorest.Response, err error) { 125 if tracing.IsEnabled() { 126 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Delete") 127 defer func() { 128 sc := -1 129 if result.Response != nil { 130 sc = result.Response.StatusCode 131 } 132 tracing.EndSpan(ctx, sc, err) 133 }() 134 } 135 if err := validation.Validate([]validation.Validation{ 136 {TargetValue: propID, 137 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 138 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 139 return result, validation.NewError("apimanagement.PropertyClient", "Delete", err.Error()) 140 } 141 142 req, err := client.DeletePreparer(ctx, apimBaseURL, propID, ifMatch) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Delete", nil, "Failure preparing request") 145 return 146 } 147 148 resp, err := client.DeleteSender(req) 149 if err != nil { 150 result.Response = resp 151 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Delete", resp, "Failure sending request") 152 return 153 } 154 155 result, err = client.DeleteResponder(resp) 156 if err != nil { 157 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Delete", resp, "Failure responding to request") 158 return 159 } 160 161 return 162} 163 164// DeletePreparer prepares the Delete request. 165func (client PropertyClient) DeletePreparer(ctx context.Context, apimBaseURL string, propID string, ifMatch string) (*http.Request, error) { 166 urlParameters := map[string]interface{}{ 167 "apimBaseUrl": apimBaseURL, 168 } 169 170 pathParameters := map[string]interface{}{ 171 "propId": autorest.Encode("path", propID), 172 } 173 174 const APIVersion = "2017-03-01" 175 queryParameters := map[string]interface{}{ 176 "api-version": APIVersion, 177 } 178 179 preparer := autorest.CreatePreparer( 180 autorest.AsDelete(), 181 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 182 autorest.WithPathParameters("/properties/{propId}", pathParameters), 183 autorest.WithQueryParameters(queryParameters), 184 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 185 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 186} 187 188// DeleteSender sends the Delete request. The method will close the 189// http.Response Body if it receives an error. 190func (client PropertyClient) DeleteSender(req *http.Request) (*http.Response, error) { 191 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 192} 193 194// DeleteResponder handles the response to the Delete request. The method always 195// closes the http.Response Body. 196func (client PropertyClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 197 err = autorest.Respond( 198 resp, 199 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 200 autorest.ByClosing()) 201 result.Response = resp 202 return 203} 204 205// Get gets the details of the property specified by its identifier. 206// Parameters: 207// apimBaseURL - the management endpoint of the API Management service, for example 208// https://myapimservice.management.azure-api.net. 209// propID - identifier of the property. 210func (client PropertyClient) Get(ctx context.Context, apimBaseURL string, propID string) (result PropertyContract, err error) { 211 if tracing.IsEnabled() { 212 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Get") 213 defer func() { 214 sc := -1 215 if result.Response.Response != nil { 216 sc = result.Response.Response.StatusCode 217 } 218 tracing.EndSpan(ctx, sc, err) 219 }() 220 } 221 if err := validation.Validate([]validation.Validation{ 222 {TargetValue: propID, 223 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 224 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 225 return result, validation.NewError("apimanagement.PropertyClient", "Get", err.Error()) 226 } 227 228 req, err := client.GetPreparer(ctx, apimBaseURL, propID) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Get", nil, "Failure preparing request") 231 return 232 } 233 234 resp, err := client.GetSender(req) 235 if err != nil { 236 result.Response = autorest.Response{Response: resp} 237 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Get", resp, "Failure sending request") 238 return 239 } 240 241 result, err = client.GetResponder(resp) 242 if err != nil { 243 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Get", resp, "Failure responding to request") 244 return 245 } 246 247 return 248} 249 250// GetPreparer prepares the Get request. 251func (client PropertyClient) GetPreparer(ctx context.Context, apimBaseURL string, propID string) (*http.Request, error) { 252 urlParameters := map[string]interface{}{ 253 "apimBaseUrl": apimBaseURL, 254 } 255 256 pathParameters := map[string]interface{}{ 257 "propId": autorest.Encode("path", propID), 258 } 259 260 const APIVersion = "2017-03-01" 261 queryParameters := map[string]interface{}{ 262 "api-version": APIVersion, 263 } 264 265 preparer := autorest.CreatePreparer( 266 autorest.AsGet(), 267 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 268 autorest.WithPathParameters("/properties/{propId}", pathParameters), 269 autorest.WithQueryParameters(queryParameters)) 270 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 271} 272 273// GetSender sends the Get request. The method will close the 274// http.Response Body if it receives an error. 275func (client PropertyClient) GetSender(req *http.Request) (*http.Response, error) { 276 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 277} 278 279// GetResponder handles the response to the Get request. The method always 280// closes the http.Response Body. 281func (client PropertyClient) GetResponder(resp *http.Response) (result PropertyContract, err error) { 282 err = autorest.Respond( 283 resp, 284 azure.WithErrorUnlessStatusCode(http.StatusOK), 285 autorest.ByUnmarshallingJSON(&result), 286 autorest.ByClosing()) 287 result.Response = autorest.Response{Response: resp} 288 return 289} 290 291// List lists a collection of properties defined within a service instance. 292// Parameters: 293// apimBaseURL - the management endpoint of the API Management service, for example 294// https://myapimservice.management.azure-api.net. 295// filter - | Field | Supported operators | Supported functions | 296// |-------|------------------------|-------------------------------------------------------| 297// | tags | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith, any, all | 298// | name | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 299// top - number of records to return. 300// skip - number of records to skip. 301func (client PropertyClient) List(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result PropertyCollectionPage, err error) { 302 if tracing.IsEnabled() { 303 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.List") 304 defer func() { 305 sc := -1 306 if result.pc.Response.Response != nil { 307 sc = result.pc.Response.Response.StatusCode 308 } 309 tracing.EndSpan(ctx, sc, err) 310 }() 311 } 312 if err := validation.Validate([]validation.Validation{ 313 {TargetValue: top, 314 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 315 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 316 {TargetValue: skip, 317 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 318 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 319 return result, validation.NewError("apimanagement.PropertyClient", "List", err.Error()) 320 } 321 322 result.fn = client.listNextResults 323 req, err := client.ListPreparer(ctx, apimBaseURL, filter, top, skip) 324 if err != nil { 325 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "List", nil, "Failure preparing request") 326 return 327 } 328 329 resp, err := client.ListSender(req) 330 if err != nil { 331 result.pc.Response = autorest.Response{Response: resp} 332 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "List", resp, "Failure sending request") 333 return 334 } 335 336 result.pc, err = client.ListResponder(resp) 337 if err != nil { 338 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "List", resp, "Failure responding to request") 339 return 340 } 341 if result.pc.hasNextLink() && result.pc.IsEmpty() { 342 err = result.NextWithContext(ctx) 343 return 344 } 345 346 return 347} 348 349// ListPreparer prepares the List request. 350func (client PropertyClient) ListPreparer(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (*http.Request, error) { 351 urlParameters := map[string]interface{}{ 352 "apimBaseUrl": apimBaseURL, 353 } 354 355 const APIVersion = "2017-03-01" 356 queryParameters := map[string]interface{}{ 357 "api-version": APIVersion, 358 } 359 if len(filter) > 0 { 360 queryParameters["$filter"] = autorest.Encode("query", filter) 361 } 362 if top != nil { 363 queryParameters["$top"] = autorest.Encode("query", *top) 364 } 365 if skip != nil { 366 queryParameters["$skip"] = autorest.Encode("query", *skip) 367 } 368 369 preparer := autorest.CreatePreparer( 370 autorest.AsGet(), 371 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 372 autorest.WithPath("/properties"), 373 autorest.WithQueryParameters(queryParameters)) 374 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 375} 376 377// ListSender sends the List request. The method will close the 378// http.Response Body if it receives an error. 379func (client PropertyClient) ListSender(req *http.Request) (*http.Response, error) { 380 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 381} 382 383// ListResponder handles the response to the List request. The method always 384// closes the http.Response Body. 385func (client PropertyClient) ListResponder(resp *http.Response) (result PropertyCollection, err error) { 386 err = autorest.Respond( 387 resp, 388 azure.WithErrorUnlessStatusCode(http.StatusOK), 389 autorest.ByUnmarshallingJSON(&result), 390 autorest.ByClosing()) 391 result.Response = autorest.Response{Response: resp} 392 return 393} 394 395// listNextResults retrieves the next set of results, if any. 396func (client PropertyClient) listNextResults(ctx context.Context, lastResults PropertyCollection) (result PropertyCollection, err error) { 397 req, err := lastResults.propertyCollectionPreparer(ctx) 398 if err != nil { 399 return result, autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "listNextResults", nil, "Failure preparing next results request") 400 } 401 if req == nil { 402 return 403 } 404 resp, err := client.ListSender(req) 405 if err != nil { 406 result.Response = autorest.Response{Response: resp} 407 return result, autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "listNextResults", resp, "Failure sending next results request") 408 } 409 result, err = client.ListResponder(resp) 410 if err != nil { 411 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "listNextResults", resp, "Failure responding to next results request") 412 } 413 return 414} 415 416// ListComplete enumerates all values, automatically crossing page boundaries as required. 417func (client PropertyClient) ListComplete(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result PropertyCollectionIterator, err error) { 418 if tracing.IsEnabled() { 419 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.List") 420 defer func() { 421 sc := -1 422 if result.Response().Response.Response != nil { 423 sc = result.page.Response().Response.Response.StatusCode 424 } 425 tracing.EndSpan(ctx, sc, err) 426 }() 427 } 428 result.page, err = client.List(ctx, apimBaseURL, filter, top, skip) 429 return 430} 431 432// Update updates the specific property. 433// Parameters: 434// apimBaseURL - the management endpoint of the API Management service, for example 435// https://myapimservice.management.azure-api.net. 436// propID - identifier of the property. 437// parameters - update parameters. 438// ifMatch - the entity state (Etag) version of the property to update. A value of "*" can be used for If-Match 439// to unconditionally apply the operation. 440func (client PropertyClient) Update(ctx context.Context, apimBaseURL string, propID string, parameters PropertyUpdateParameters, ifMatch string) (result autorest.Response, err error) { 441 if tracing.IsEnabled() { 442 ctx = tracing.StartSpan(ctx, fqdn+"/PropertyClient.Update") 443 defer func() { 444 sc := -1 445 if result.Response != nil { 446 sc = result.Response.StatusCode 447 } 448 tracing.EndSpan(ctx, sc, err) 449 }() 450 } 451 if err := validation.Validate([]validation.Validation{ 452 {TargetValue: propID, 453 Constraints: []validation.Constraint{{Target: "propID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 454 {Target: "propID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 455 return result, validation.NewError("apimanagement.PropertyClient", "Update", err.Error()) 456 } 457 458 req, err := client.UpdatePreparer(ctx, apimBaseURL, propID, parameters, ifMatch) 459 if err != nil { 460 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Update", nil, "Failure preparing request") 461 return 462 } 463 464 resp, err := client.UpdateSender(req) 465 if err != nil { 466 result.Response = resp 467 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Update", resp, "Failure sending request") 468 return 469 } 470 471 result, err = client.UpdateResponder(resp) 472 if err != nil { 473 err = autorest.NewErrorWithError(err, "apimanagement.PropertyClient", "Update", resp, "Failure responding to request") 474 return 475 } 476 477 return 478} 479 480// UpdatePreparer prepares the Update request. 481func (client PropertyClient) UpdatePreparer(ctx context.Context, apimBaseURL string, propID string, parameters PropertyUpdateParameters, ifMatch string) (*http.Request, error) { 482 urlParameters := map[string]interface{}{ 483 "apimBaseUrl": apimBaseURL, 484 } 485 486 pathParameters := map[string]interface{}{ 487 "propId": autorest.Encode("path", propID), 488 } 489 490 const APIVersion = "2017-03-01" 491 queryParameters := map[string]interface{}{ 492 "api-version": APIVersion, 493 } 494 495 preparer := autorest.CreatePreparer( 496 autorest.AsContentType("application/json; charset=utf-8"), 497 autorest.AsPatch(), 498 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 499 autorest.WithPathParameters("/properties/{propId}", pathParameters), 500 autorest.WithJSON(parameters), 501 autorest.WithQueryParameters(queryParameters), 502 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 503 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 504} 505 506// UpdateSender sends the Update request. The method will close the 507// http.Response Body if it receives an error. 508func (client PropertyClient) UpdateSender(req *http.Request) (*http.Response, error) { 509 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 510} 511 512// UpdateResponder handles the response to the Update request. The method always 513// closes the http.Response Body. 514func (client PropertyClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 515 err = autorest.Respond( 516 resp, 517 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 518 autorest.ByClosing()) 519 result.Response = resp 520 return 521} 522