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// APIClient is the apiManagement Client 19type APIClient struct { 20 BaseClient 21} 22 23// NewAPIClient creates an instance of the APIClient client. 24func NewAPIClient(subscriptionID string) APIClient { 25 return NewAPIClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewAPIClientWithBaseURI creates an instance of the APIClient 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 NewAPIClientWithBaseURI(baseURI string, subscriptionID string) APIClient { 31 return APIClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates new or updates existing specified API of the API Management service instance. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// serviceName - the name of the API Management service. 38// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current 39// revision has ;rev=n as a suffix where n is the revision number. 40// parameters - create or update parameters. 41// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity. 42func (client APIClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APICreateOrUpdateParameter, ifMatch string) (result APICreateOrUpdateFuture, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.CreateOrUpdate") 45 defer func() { 46 sc := -1 47 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 48 sc = result.FutureAPI.Response().StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 if err := validation.Validate([]validation.Validation{ 54 {TargetValue: serviceName, 55 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 56 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 57 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 58 {TargetValue: apiid, 59 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 60 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 61 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 62 return result, validation.NewError("apimanagement.APIClient", "CreateOrUpdate", err.Error()) 63 } 64 65 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, parameters, ifMatch) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "CreateOrUpdate", nil, "Failure preparing request") 68 return 69 } 70 71 result, err = client.CreateOrUpdateSender(req) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "CreateOrUpdate", nil, "Failure sending request") 74 return 75 } 76 77 return 78} 79 80// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 81func (client APIClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APICreateOrUpdateParameter, ifMatch string) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "apiId": autorest.Encode("path", apiid), 84 "resourceGroupName": autorest.Encode("path", resourceGroupName), 85 "serviceName": autorest.Encode("path", serviceName), 86 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 87 } 88 89 const APIVersion = "2019-12-01-preview" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsContentType("application/json; charset=utf-8"), 96 autorest.AsPut(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters), 99 autorest.WithJSON(parameters), 100 autorest.WithQueryParameters(queryParameters)) 101 if len(ifMatch) > 0 { 102 preparer = autorest.DecoratePreparer(preparer, 103 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 104 } 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 109// http.Response Body if it receives an error. 110func (client APIClient) CreateOrUpdateSender(req *http.Request) (future APICreateOrUpdateFuture, err error) { 111 var resp *http.Response 112 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113 if err != nil { 114 return 115 } 116 var azf azure.Future 117 azf, err = azure.NewFutureFromResponse(resp) 118 future.FutureAPI = &azf 119 future.Result = future.result 120 return 121} 122 123// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 124// closes the http.Response Body. 125func (client APIClient) CreateOrUpdateResponder(resp *http.Response) (result APIContract, err error) { 126 err = autorest.Respond( 127 resp, 128 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// Delete deletes the specified API of the API Management service instance. 136// Parameters: 137// resourceGroupName - the name of the resource group. 138// serviceName - the name of the API Management service. 139// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current 140// revision has ;rev=n as a suffix where n is the revision number. 141// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 142// request or it should be * for unconditional update. 143// deleteRevisions - delete all revisions of the Api. 144func (client APIClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, ifMatch string, deleteRevisions *bool) (result autorest.Response, err error) { 145 if tracing.IsEnabled() { 146 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.Delete") 147 defer func() { 148 sc := -1 149 if result.Response != nil { 150 sc = result.Response.StatusCode 151 } 152 tracing.EndSpan(ctx, sc, err) 153 }() 154 } 155 if err := validation.Validate([]validation.Validation{ 156 {TargetValue: serviceName, 157 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 158 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 159 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 160 {TargetValue: apiid, 161 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 162 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 163 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 164 return result, validation.NewError("apimanagement.APIClient", "Delete", err.Error()) 165 } 166 167 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, ifMatch, deleteRevisions) 168 if err != nil { 169 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Delete", nil, "Failure preparing request") 170 return 171 } 172 173 resp, err := client.DeleteSender(req) 174 if err != nil { 175 result.Response = resp 176 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Delete", resp, "Failure sending request") 177 return 178 } 179 180 result, err = client.DeleteResponder(resp) 181 if err != nil { 182 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Delete", resp, "Failure responding to request") 183 return 184 } 185 186 return 187} 188 189// DeletePreparer prepares the Delete request. 190func (client APIClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, ifMatch string, deleteRevisions *bool) (*http.Request, error) { 191 pathParameters := map[string]interface{}{ 192 "apiId": autorest.Encode("path", apiid), 193 "resourceGroupName": autorest.Encode("path", resourceGroupName), 194 "serviceName": autorest.Encode("path", serviceName), 195 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 196 } 197 198 const APIVersion = "2019-12-01-preview" 199 queryParameters := map[string]interface{}{ 200 "api-version": APIVersion, 201 } 202 if deleteRevisions != nil { 203 queryParameters["deleteRevisions"] = autorest.Encode("query", *deleteRevisions) 204 } 205 206 preparer := autorest.CreatePreparer( 207 autorest.AsDelete(), 208 autorest.WithBaseURL(client.BaseURI), 209 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters), 210 autorest.WithQueryParameters(queryParameters), 211 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 212 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 213} 214 215// DeleteSender sends the Delete request. The method will close the 216// http.Response Body if it receives an error. 217func (client APIClient) DeleteSender(req *http.Request) (*http.Response, error) { 218 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 219} 220 221// DeleteResponder handles the response to the Delete request. The method always 222// closes the http.Response Body. 223func (client APIClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 224 err = autorest.Respond( 225 resp, 226 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 227 autorest.ByClosing()) 228 result.Response = resp 229 return 230} 231 232// Get gets the details of the API specified by its identifier. 233// Parameters: 234// resourceGroupName - the name of the resource group. 235// serviceName - the name of the API Management service. 236// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current 237// revision has ;rev=n as a suffix where n is the revision number. 238func (client APIClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (result APIContract, err error) { 239 if tracing.IsEnabled() { 240 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.Get") 241 defer func() { 242 sc := -1 243 if result.Response.Response != nil { 244 sc = result.Response.Response.StatusCode 245 } 246 tracing.EndSpan(ctx, sc, err) 247 }() 248 } 249 if err := validation.Validate([]validation.Validation{ 250 {TargetValue: serviceName, 251 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 252 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 253 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 254 {TargetValue: apiid, 255 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 256 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 257 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 258 return result, validation.NewError("apimanagement.APIClient", "Get", err.Error()) 259 } 260 261 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid) 262 if err != nil { 263 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "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.APIClient", "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.APIClient", "Get", resp, "Failure responding to request") 277 return 278 } 279 280 return 281} 282 283// GetPreparer prepares the Get request. 284func (client APIClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (*http.Request, error) { 285 pathParameters := map[string]interface{}{ 286 "apiId": autorest.Encode("path", apiid), 287 "resourceGroupName": autorest.Encode("path", resourceGroupName), 288 "serviceName": autorest.Encode("path", serviceName), 289 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 290 } 291 292 const APIVersion = "2019-12-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}/apis/{apiId}", 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 APIClient) 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 APIClient) GetResponder(resp *http.Response) (result APIContract, 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 API specified by its identifier. 324// Parameters: 325// resourceGroupName - the name of the resource group. 326// serviceName - the name of the API Management service. 327// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current 328// revision has ;rev=n as a suffix where n is the revision number. 329func (client APIClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (result autorest.Response, err error) { 330 if tracing.IsEnabled() { 331 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.GetEntityTag") 332 defer func() { 333 sc := -1 334 if result.Response != nil { 335 sc = result.Response.StatusCode 336 } 337 tracing.EndSpan(ctx, sc, err) 338 }() 339 } 340 if err := validation.Validate([]validation.Validation{ 341 {TargetValue: serviceName, 342 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 343 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 344 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 345 {TargetValue: apiid, 346 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 347 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 348 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 349 return result, validation.NewError("apimanagement.APIClient", "GetEntityTag", err.Error()) 350 } 351 352 req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid) 353 if err != nil { 354 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "GetEntityTag", nil, "Failure preparing request") 355 return 356 } 357 358 resp, err := client.GetEntityTagSender(req) 359 if err != nil { 360 result.Response = resp 361 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "GetEntityTag", resp, "Failure sending request") 362 return 363 } 364 365 result, err = client.GetEntityTagResponder(resp) 366 if err != nil { 367 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "GetEntityTag", resp, "Failure responding to request") 368 return 369 } 370 371 return 372} 373 374// GetEntityTagPreparer prepares the GetEntityTag request. 375func (client APIClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (*http.Request, error) { 376 pathParameters := map[string]interface{}{ 377 "apiId": autorest.Encode("path", apiid), 378 "resourceGroupName": autorest.Encode("path", resourceGroupName), 379 "serviceName": autorest.Encode("path", serviceName), 380 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 381 } 382 383 const APIVersion = "2019-12-01-preview" 384 queryParameters := map[string]interface{}{ 385 "api-version": APIVersion, 386 } 387 388 preparer := autorest.CreatePreparer( 389 autorest.AsHead(), 390 autorest.WithBaseURL(client.BaseURI), 391 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters), 392 autorest.WithQueryParameters(queryParameters)) 393 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 394} 395 396// GetEntityTagSender sends the GetEntityTag request. The method will close the 397// http.Response Body if it receives an error. 398func (client APIClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { 399 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 400} 401 402// GetEntityTagResponder handles the response to the GetEntityTag request. The method always 403// closes the http.Response Body. 404func (client APIClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { 405 err = autorest.Respond( 406 resp, 407 azure.WithErrorUnlessStatusCode(http.StatusOK), 408 autorest.ByClosing()) 409 result.Response = resp 410 return 411} 412 413// ListByService lists all APIs of the API Management service instance. 414// Parameters: 415// resourceGroupName - the name of the resource group. 416// serviceName - the name of the API Management service. 417// filter - | Field | Usage | Supported operators | Supported functions 418// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt 419// | substringof, contains, startswith, endswith | </br>| displayName | filter | ge, le, eq, ne, gt, lt | 420// substringof, contains, startswith, endswith | </br>| description | filter | ge, le, eq, ne, gt, lt | 421// substringof, contains, startswith, endswith | </br>| serviceUrl | filter | ge, le, eq, ne, gt, lt | 422// substringof, contains, startswith, endswith | </br>| path | filter | ge, le, eq, ne, gt, lt | substringof, 423// contains, startswith, endswith | </br> 424// top - number of records to return. 425// skip - number of records to skip. 426// tags - include tags in the response. 427// expandAPIVersionSet - include full ApiVersionSet resource in response 428func (client APIClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, tags string, expandAPIVersionSet *bool) (result APICollectionPage, err error) { 429 if tracing.IsEnabled() { 430 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByService") 431 defer func() { 432 sc := -1 433 if result.ac.Response.Response != nil { 434 sc = result.ac.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.APIClient", "ListByService", err.Error()) 451 } 452 453 result.fn = client.listByServiceNextResults 454 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip, tags, expandAPIVersionSet) 455 if err != nil { 456 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByService", nil, "Failure preparing request") 457 return 458 } 459 460 resp, err := client.ListByServiceSender(req) 461 if err != nil { 462 result.ac.Response = autorest.Response{Response: resp} 463 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByService", resp, "Failure sending request") 464 return 465 } 466 467 result.ac, err = client.ListByServiceResponder(resp) 468 if err != nil { 469 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByService", resp, "Failure responding to request") 470 return 471 } 472 if result.ac.hasNextLink() && result.ac.IsEmpty() { 473 err = result.NextWithContext(ctx) 474 return 475 } 476 477 return 478} 479 480// ListByServicePreparer prepares the ListByService request. 481func (client APIClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, tags string, expandAPIVersionSet *bool) (*http.Request, error) { 482 pathParameters := map[string]interface{}{ 483 "resourceGroupName": autorest.Encode("path", resourceGroupName), 484 "serviceName": autorest.Encode("path", serviceName), 485 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 486 } 487 488 const APIVersion = "2019-12-01-preview" 489 queryParameters := map[string]interface{}{ 490 "api-version": APIVersion, 491 } 492 if len(filter) > 0 { 493 queryParameters["$filter"] = autorest.Encode("query", filter) 494 } 495 if top != nil { 496 queryParameters["$top"] = autorest.Encode("query", *top) 497 } 498 if skip != nil { 499 queryParameters["$skip"] = autorest.Encode("query", *skip) 500 } 501 if len(tags) > 0 { 502 queryParameters["tags"] = autorest.Encode("query", tags) 503 } 504 if expandAPIVersionSet != nil { 505 queryParameters["expandApiVersionSet"] = autorest.Encode("query", *expandAPIVersionSet) 506 } 507 508 preparer := autorest.CreatePreparer( 509 autorest.AsGet(), 510 autorest.WithBaseURL(client.BaseURI), 511 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis", pathParameters), 512 autorest.WithQueryParameters(queryParameters)) 513 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 514} 515 516// ListByServiceSender sends the ListByService request. The method will close the 517// http.Response Body if it receives an error. 518func (client APIClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 519 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 520} 521 522// ListByServiceResponder handles the response to the ListByService request. The method always 523// closes the http.Response Body. 524func (client APIClient) ListByServiceResponder(resp *http.Response) (result APICollection, err error) { 525 err = autorest.Respond( 526 resp, 527 azure.WithErrorUnlessStatusCode(http.StatusOK), 528 autorest.ByUnmarshallingJSON(&result), 529 autorest.ByClosing()) 530 result.Response = autorest.Response{Response: resp} 531 return 532} 533 534// listByServiceNextResults retrieves the next set of results, if any. 535func (client APIClient) listByServiceNextResults(ctx context.Context, lastResults APICollection) (result APICollection, err error) { 536 req, err := lastResults.aPICollectionPreparer(ctx) 537 if err != nil { 538 return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByServiceNextResults", nil, "Failure preparing next results request") 539 } 540 if req == nil { 541 return 542 } 543 resp, err := client.ListByServiceSender(req) 544 if err != nil { 545 result.Response = autorest.Response{Response: resp} 546 return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByServiceNextResults", resp, "Failure sending next results request") 547 } 548 result, err = client.ListByServiceResponder(resp) 549 if err != nil { 550 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByServiceNextResults", resp, "Failure responding to next results request") 551 } 552 return 553} 554 555// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 556func (client APIClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, tags string, expandAPIVersionSet *bool) (result APICollectionIterator, err error) { 557 if tracing.IsEnabled() { 558 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByService") 559 defer func() { 560 sc := -1 561 if result.Response().Response.Response != nil { 562 sc = result.page.Response().Response.Response.StatusCode 563 } 564 tracing.EndSpan(ctx, sc, err) 565 }() 566 } 567 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip, tags, expandAPIVersionSet) 568 return 569} 570 571// ListByTags lists a collection of apis associated with tags. 572// Parameters: 573// resourceGroupName - the name of the resource group. 574// serviceName - the name of the API Management service. 575// filter - | Field | Supported operators | Supported functions | 576// |-------------|------------------------|-----------------------------------| 577// 578// |name | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 579// |displayName | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 580// |apiRevision | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 581// |path | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 582// |description | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 583// |serviceUrl | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 584// |isCurrent | eq | | 585// top - number of records to return. 586// skip - number of records to skip. 587// includeNotTaggedApis - include not tagged APIs. 588func (client APIClient) ListByTags(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, includeNotTaggedApis *bool) (result TagResourceCollectionPage, err error) { 589 if tracing.IsEnabled() { 590 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByTags") 591 defer func() { 592 sc := -1 593 if result.trc.Response.Response != nil { 594 sc = result.trc.Response.Response.StatusCode 595 } 596 tracing.EndSpan(ctx, sc, err) 597 }() 598 } 599 if err := validation.Validate([]validation.Validation{ 600 {TargetValue: serviceName, 601 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 602 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 603 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 604 {TargetValue: top, 605 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 606 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 607 {TargetValue: skip, 608 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 609 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 610 return result, validation.NewError("apimanagement.APIClient", "ListByTags", err.Error()) 611 } 612 613 result.fn = client.listByTagsNextResults 614 req, err := client.ListByTagsPreparer(ctx, resourceGroupName, serviceName, filter, top, skip, includeNotTaggedApis) 615 if err != nil { 616 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByTags", nil, "Failure preparing request") 617 return 618 } 619 620 resp, err := client.ListByTagsSender(req) 621 if err != nil { 622 result.trc.Response = autorest.Response{Response: resp} 623 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByTags", resp, "Failure sending request") 624 return 625 } 626 627 result.trc, err = client.ListByTagsResponder(resp) 628 if err != nil { 629 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByTags", resp, "Failure responding to request") 630 return 631 } 632 if result.trc.hasNextLink() && result.trc.IsEmpty() { 633 err = result.NextWithContext(ctx) 634 return 635 } 636 637 return 638} 639 640// ListByTagsPreparer prepares the ListByTags request. 641func (client APIClient) ListByTagsPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, includeNotTaggedApis *bool) (*http.Request, error) { 642 pathParameters := map[string]interface{}{ 643 "resourceGroupName": autorest.Encode("path", resourceGroupName), 644 "serviceName": autorest.Encode("path", serviceName), 645 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 646 } 647 648 const APIVersion = "2019-12-01-preview" 649 queryParameters := map[string]interface{}{ 650 "api-version": APIVersion, 651 } 652 if len(filter) > 0 { 653 queryParameters["$filter"] = autorest.Encode("query", filter) 654 } 655 if top != nil { 656 queryParameters["$top"] = autorest.Encode("query", *top) 657 } 658 if skip != nil { 659 queryParameters["$skip"] = autorest.Encode("query", *skip) 660 } 661 if includeNotTaggedApis != nil { 662 queryParameters["includeNotTaggedApis"] = autorest.Encode("query", *includeNotTaggedApis) 663 } 664 665 preparer := autorest.CreatePreparer( 666 autorest.AsGet(), 667 autorest.WithBaseURL(client.BaseURI), 668 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apisByTags", pathParameters), 669 autorest.WithQueryParameters(queryParameters)) 670 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 671} 672 673// ListByTagsSender sends the ListByTags request. The method will close the 674// http.Response Body if it receives an error. 675func (client APIClient) ListByTagsSender(req *http.Request) (*http.Response, error) { 676 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 677} 678 679// ListByTagsResponder handles the response to the ListByTags request. The method always 680// closes the http.Response Body. 681func (client APIClient) ListByTagsResponder(resp *http.Response) (result TagResourceCollection, err error) { 682 err = autorest.Respond( 683 resp, 684 azure.WithErrorUnlessStatusCode(http.StatusOK), 685 autorest.ByUnmarshallingJSON(&result), 686 autorest.ByClosing()) 687 result.Response = autorest.Response{Response: resp} 688 return 689} 690 691// listByTagsNextResults retrieves the next set of results, if any. 692func (client APIClient) listByTagsNextResults(ctx context.Context, lastResults TagResourceCollection) (result TagResourceCollection, err error) { 693 req, err := lastResults.tagResourceCollectionPreparer(ctx) 694 if err != nil { 695 return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByTagsNextResults", nil, "Failure preparing next results request") 696 } 697 if req == nil { 698 return 699 } 700 resp, err := client.ListByTagsSender(req) 701 if err != nil { 702 result.Response = autorest.Response{Response: resp} 703 return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByTagsNextResults", resp, "Failure sending next results request") 704 } 705 result, err = client.ListByTagsResponder(resp) 706 if err != nil { 707 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByTagsNextResults", resp, "Failure responding to next results request") 708 } 709 return 710} 711 712// ListByTagsComplete enumerates all values, automatically crossing page boundaries as required. 713func (client APIClient) ListByTagsComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, includeNotTaggedApis *bool) (result TagResourceCollectionIterator, err error) { 714 if tracing.IsEnabled() { 715 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByTags") 716 defer func() { 717 sc := -1 718 if result.Response().Response.Response != nil { 719 sc = result.page.Response().Response.Response.StatusCode 720 } 721 tracing.EndSpan(ctx, sc, err) 722 }() 723 } 724 result.page, err = client.ListByTags(ctx, resourceGroupName, serviceName, filter, top, skip, includeNotTaggedApis) 725 return 726} 727 728// Update updates the specified API of the API Management service instance. 729// Parameters: 730// resourceGroupName - the name of the resource group. 731// serviceName - the name of the API Management service. 732// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current 733// revision has ;rev=n as a suffix where n is the revision number. 734// parameters - API Update Contract parameters. 735// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 736// request or it should be * for unconditional update. 737func (client APIClient) Update(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APIUpdateContract, ifMatch string) (result autorest.Response, err error) { 738 if tracing.IsEnabled() { 739 ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.Update") 740 defer func() { 741 sc := -1 742 if result.Response != nil { 743 sc = result.Response.StatusCode 744 } 745 tracing.EndSpan(ctx, sc, err) 746 }() 747 } 748 if err := validation.Validate([]validation.Validation{ 749 {TargetValue: serviceName, 750 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 751 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 752 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 753 {TargetValue: apiid, 754 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 755 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 756 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 757 return result, validation.NewError("apimanagement.APIClient", "Update", err.Error()) 758 } 759 760 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, apiid, parameters, ifMatch) 761 if err != nil { 762 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Update", nil, "Failure preparing request") 763 return 764 } 765 766 resp, err := client.UpdateSender(req) 767 if err != nil { 768 result.Response = resp 769 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Update", resp, "Failure sending request") 770 return 771 } 772 773 result, err = client.UpdateResponder(resp) 774 if err != nil { 775 err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Update", resp, "Failure responding to request") 776 return 777 } 778 779 return 780} 781 782// UpdatePreparer prepares the Update request. 783func (client APIClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APIUpdateContract, ifMatch string) (*http.Request, error) { 784 pathParameters := map[string]interface{}{ 785 "apiId": autorest.Encode("path", apiid), 786 "resourceGroupName": autorest.Encode("path", resourceGroupName), 787 "serviceName": autorest.Encode("path", serviceName), 788 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 789 } 790 791 const APIVersion = "2019-12-01-preview" 792 queryParameters := map[string]interface{}{ 793 "api-version": APIVersion, 794 } 795 796 preparer := autorest.CreatePreparer( 797 autorest.AsContentType("application/json; charset=utf-8"), 798 autorest.AsPatch(), 799 autorest.WithBaseURL(client.BaseURI), 800 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters), 801 autorest.WithJSON(parameters), 802 autorest.WithQueryParameters(queryParameters), 803 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 804 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 805} 806 807// UpdateSender sends the Update request. The method will close the 808// http.Response Body if it receives an error. 809func (client APIClient) UpdateSender(req *http.Request) (*http.Response, error) { 810 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 811} 812 813// UpdateResponder handles the response to the Update request. The method always 814// closes the http.Response Body. 815func (client APIClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 816 err = autorest.Respond( 817 resp, 818 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 819 autorest.ByClosing()) 820 result.Response = resp 821 return 822} 823