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// APIDiagnosticClient is the apiManagement Client 19type APIDiagnosticClient struct { 20 BaseClient 21} 22 23// NewAPIDiagnosticClient creates an instance of the APIDiagnosticClient client. 24func NewAPIDiagnosticClient(subscriptionID string) APIDiagnosticClient { 25 return NewAPIDiagnosticClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewAPIDiagnosticClientWithBaseURI creates an instance of the APIDiagnosticClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewAPIDiagnosticClientWithBaseURI(baseURI string, subscriptionID string) APIDiagnosticClient { 31 return APIDiagnosticClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates a new Diagnostic for an API or updates an existing one. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// serviceName - the name of the API Management service. 38// apiid - API identifier. Must be unique in the current API Management service instance. 39// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance. 40// parameters - create parameters. 41// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity. 42func (client APIDiagnosticClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string, parameters DiagnosticContract, ifMatch string) (result DiagnosticContract, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.CreateOrUpdate") 45 defer func() { 46 sc := -1 47 if result.Response.Response != nil { 48 sc = result.Response.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: 80, Chain: nil}, 60 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 61 {Target: "apiid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 62 {TargetValue: diagnosticID, 63 Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 64 {Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil}, 65 {Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 66 {TargetValue: parameters, 67 Constraints: []validation.Constraint{{Target: "parameters.DiagnosticContractProperties", Name: validation.Null, Rule: false, 68 Chain: []validation.Constraint{{Target: "parameters.DiagnosticContractProperties.Enabled", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 69 return result, validation.NewError("apimanagement.APIDiagnosticClient", "CreateOrUpdate", err.Error()) 70 } 71 72 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, diagnosticID, parameters, ifMatch) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "CreateOrUpdate", nil, "Failure preparing request") 75 return 76 } 77 78 resp, err := client.CreateOrUpdateSender(req) 79 if err != nil { 80 result.Response = autorest.Response{Response: resp} 81 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "CreateOrUpdate", resp, "Failure sending request") 82 return 83 } 84 85 result, err = client.CreateOrUpdateResponder(resp) 86 if err != nil { 87 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "CreateOrUpdate", resp, "Failure responding to request") 88 return 89 } 90 91 return 92} 93 94// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 95func (client APIDiagnosticClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string, parameters DiagnosticContract, ifMatch string) (*http.Request, error) { 96 pathParameters := map[string]interface{}{ 97 "apiId": autorest.Encode("path", apiid), 98 "diagnosticId": autorest.Encode("path", diagnosticID), 99 "resourceGroupName": autorest.Encode("path", resourceGroupName), 100 "serviceName": autorest.Encode("path", serviceName), 101 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 102 } 103 104 const APIVersion = "2018-01-01" 105 queryParameters := map[string]interface{}{ 106 "api-version": APIVersion, 107 } 108 109 preparer := autorest.CreatePreparer( 110 autorest.AsContentType("application/json; charset=utf-8"), 111 autorest.AsPut(), 112 autorest.WithBaseURL(client.BaseURI), 113 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics/{diagnosticId}", pathParameters), 114 autorest.WithJSON(parameters), 115 autorest.WithQueryParameters(queryParameters)) 116 if len(ifMatch) > 0 { 117 preparer = autorest.DecoratePreparer(preparer, 118 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 119 } 120 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 121} 122 123// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 124// http.Response Body if it receives an error. 125func (client APIDiagnosticClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 126 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 127} 128 129// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 130// closes the http.Response Body. 131func (client APIDiagnosticClient) CreateOrUpdateResponder(resp *http.Response) (result DiagnosticContract, err error) { 132 err = autorest.Respond( 133 resp, 134 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 135 autorest.ByUnmarshallingJSON(&result), 136 autorest.ByClosing()) 137 result.Response = autorest.Response{Response: resp} 138 return 139} 140 141// Delete deletes the specified Diagnostic from an API. 142// Parameters: 143// resourceGroupName - the name of the resource group. 144// serviceName - the name of the API Management service. 145// apiid - API identifier. Must be unique in the current API Management service instance. 146// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance. 147// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 148// request or it should be * for unconditional update. 149func (client APIDiagnosticClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string, ifMatch string) (result autorest.Response, err error) { 150 if tracing.IsEnabled() { 151 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.Delete") 152 defer func() { 153 sc := -1 154 if result.Response != nil { 155 sc = result.Response.StatusCode 156 } 157 tracing.EndSpan(ctx, sc, err) 158 }() 159 } 160 if err := validation.Validate([]validation.Validation{ 161 {TargetValue: serviceName, 162 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 163 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 164 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 165 {TargetValue: apiid, 166 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil}, 167 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 168 {Target: "apiid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 169 {TargetValue: diagnosticID, 170 Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 171 {Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil}, 172 {Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 173 return result, validation.NewError("apimanagement.APIDiagnosticClient", "Delete", err.Error()) 174 } 175 176 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, diagnosticID, ifMatch) 177 if err != nil { 178 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Delete", nil, "Failure preparing request") 179 return 180 } 181 182 resp, err := client.DeleteSender(req) 183 if err != nil { 184 result.Response = resp 185 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Delete", resp, "Failure sending request") 186 return 187 } 188 189 result, err = client.DeleteResponder(resp) 190 if err != nil { 191 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Delete", resp, "Failure responding to request") 192 return 193 } 194 195 return 196} 197 198// DeletePreparer prepares the Delete request. 199func (client APIDiagnosticClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string, ifMatch string) (*http.Request, error) { 200 pathParameters := map[string]interface{}{ 201 "apiId": autorest.Encode("path", apiid), 202 "diagnosticId": autorest.Encode("path", diagnosticID), 203 "resourceGroupName": autorest.Encode("path", resourceGroupName), 204 "serviceName": autorest.Encode("path", serviceName), 205 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 206 } 207 208 const APIVersion = "2018-01-01" 209 queryParameters := map[string]interface{}{ 210 "api-version": APIVersion, 211 } 212 213 preparer := autorest.CreatePreparer( 214 autorest.AsDelete(), 215 autorest.WithBaseURL(client.BaseURI), 216 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics/{diagnosticId}", pathParameters), 217 autorest.WithQueryParameters(queryParameters), 218 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 219 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 220} 221 222// DeleteSender sends the Delete request. The method will close the 223// http.Response Body if it receives an error. 224func (client APIDiagnosticClient) DeleteSender(req *http.Request) (*http.Response, error) { 225 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 226} 227 228// DeleteResponder handles the response to the Delete request. The method always 229// closes the http.Response Body. 230func (client APIDiagnosticClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 231 err = autorest.Respond( 232 resp, 233 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 234 autorest.ByClosing()) 235 result.Response = resp 236 return 237} 238 239// Get gets the details of the Diagnostic for an API specified by its identifier. 240// Parameters: 241// resourceGroupName - the name of the resource group. 242// serviceName - the name of the API Management service. 243// apiid - API identifier. Must be unique in the current API Management service instance. 244// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance. 245func (client APIDiagnosticClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string) (result DiagnosticContract, err error) { 246 if tracing.IsEnabled() { 247 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.Get") 248 defer func() { 249 sc := -1 250 if result.Response.Response != nil { 251 sc = result.Response.Response.StatusCode 252 } 253 tracing.EndSpan(ctx, sc, err) 254 }() 255 } 256 if err := validation.Validate([]validation.Validation{ 257 {TargetValue: serviceName, 258 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 259 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 260 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 261 {TargetValue: apiid, 262 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil}, 263 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 264 {Target: "apiid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 265 {TargetValue: diagnosticID, 266 Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 267 {Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil}, 268 {Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 269 return result, validation.NewError("apimanagement.APIDiagnosticClient", "Get", err.Error()) 270 } 271 272 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, diagnosticID) 273 if err != nil { 274 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Get", nil, "Failure preparing request") 275 return 276 } 277 278 resp, err := client.GetSender(req) 279 if err != nil { 280 result.Response = autorest.Response{Response: resp} 281 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Get", resp, "Failure sending request") 282 return 283 } 284 285 result, err = client.GetResponder(resp) 286 if err != nil { 287 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Get", resp, "Failure responding to request") 288 return 289 } 290 291 return 292} 293 294// GetPreparer prepares the Get request. 295func (client APIDiagnosticClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string) (*http.Request, error) { 296 pathParameters := map[string]interface{}{ 297 "apiId": autorest.Encode("path", apiid), 298 "diagnosticId": autorest.Encode("path", diagnosticID), 299 "resourceGroupName": autorest.Encode("path", resourceGroupName), 300 "serviceName": autorest.Encode("path", serviceName), 301 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 302 } 303 304 const APIVersion = "2018-01-01" 305 queryParameters := map[string]interface{}{ 306 "api-version": APIVersion, 307 } 308 309 preparer := autorest.CreatePreparer( 310 autorest.AsGet(), 311 autorest.WithBaseURL(client.BaseURI), 312 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics/{diagnosticId}", pathParameters), 313 autorest.WithQueryParameters(queryParameters)) 314 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 315} 316 317// GetSender sends the Get request. The method will close the 318// http.Response Body if it receives an error. 319func (client APIDiagnosticClient) GetSender(req *http.Request) (*http.Response, error) { 320 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 321} 322 323// GetResponder handles the response to the Get request. The method always 324// closes the http.Response Body. 325func (client APIDiagnosticClient) GetResponder(resp *http.Response) (result DiagnosticContract, err error) { 326 err = autorest.Respond( 327 resp, 328 azure.WithErrorUnlessStatusCode(http.StatusOK), 329 autorest.ByUnmarshallingJSON(&result), 330 autorest.ByClosing()) 331 result.Response = autorest.Response{Response: resp} 332 return 333} 334 335// GetEntityTag gets the entity state (Etag) version of the Diagnostic for an API specified by its identifier. 336// Parameters: 337// resourceGroupName - the name of the resource group. 338// serviceName - the name of the API Management service. 339// apiid - API identifier. Must be unique in the current API Management service instance. 340// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance. 341func (client APIDiagnosticClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string) (result autorest.Response, err error) { 342 if tracing.IsEnabled() { 343 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.GetEntityTag") 344 defer func() { 345 sc := -1 346 if result.Response != nil { 347 sc = result.Response.StatusCode 348 } 349 tracing.EndSpan(ctx, sc, err) 350 }() 351 } 352 if err := validation.Validate([]validation.Validation{ 353 {TargetValue: serviceName, 354 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 355 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 356 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 357 {TargetValue: apiid, 358 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil}, 359 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 360 {Target: "apiid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 361 {TargetValue: diagnosticID, 362 Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 363 {Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil}, 364 {Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 365 return result, validation.NewError("apimanagement.APIDiagnosticClient", "GetEntityTag", err.Error()) 366 } 367 368 req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, diagnosticID) 369 if err != nil { 370 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "GetEntityTag", nil, "Failure preparing request") 371 return 372 } 373 374 resp, err := client.GetEntityTagSender(req) 375 if err != nil { 376 result.Response = resp 377 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "GetEntityTag", resp, "Failure sending request") 378 return 379 } 380 381 result, err = client.GetEntityTagResponder(resp) 382 if err != nil { 383 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "GetEntityTag", resp, "Failure responding to request") 384 return 385 } 386 387 return 388} 389 390// GetEntityTagPreparer prepares the GetEntityTag request. 391func (client APIDiagnosticClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string) (*http.Request, error) { 392 pathParameters := map[string]interface{}{ 393 "apiId": autorest.Encode("path", apiid), 394 "diagnosticId": autorest.Encode("path", diagnosticID), 395 "resourceGroupName": autorest.Encode("path", resourceGroupName), 396 "serviceName": autorest.Encode("path", serviceName), 397 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 398 } 399 400 const APIVersion = "2018-01-01" 401 queryParameters := map[string]interface{}{ 402 "api-version": APIVersion, 403 } 404 405 preparer := autorest.CreatePreparer( 406 autorest.AsHead(), 407 autorest.WithBaseURL(client.BaseURI), 408 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics/{diagnosticId}", pathParameters), 409 autorest.WithQueryParameters(queryParameters)) 410 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 411} 412 413// GetEntityTagSender sends the GetEntityTag request. The method will close the 414// http.Response Body if it receives an error. 415func (client APIDiagnosticClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { 416 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 417} 418 419// GetEntityTagResponder handles the response to the GetEntityTag request. The method always 420// closes the http.Response Body. 421func (client APIDiagnosticClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { 422 err = autorest.Respond( 423 resp, 424 azure.WithErrorUnlessStatusCode(http.StatusOK), 425 autorest.ByClosing()) 426 result.Response = resp 427 return 428} 429 430// ListByService lists all diagnostics of an API. 431// Parameters: 432// resourceGroupName - the name of the resource group. 433// serviceName - the name of the API Management service. 434// apiid - API identifier. Must be unique in the current API Management service instance. 435// filter - | Field | Supported operators | Supported functions | 436// |-------------|------------------------|-----------------------------------| 437// | id | ge, le, eq, ne, gt, lt | substringof, startswith, endswith | 438// top - number of records to return. 439// skip - number of records to skip. 440func (client APIDiagnosticClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result DiagnosticCollectionPage, err error) { 441 if tracing.IsEnabled() { 442 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.ListByService") 443 defer func() { 444 sc := -1 445 if result.dc.Response.Response != nil { 446 sc = result.dc.Response.Response.StatusCode 447 } 448 tracing.EndSpan(ctx, sc, err) 449 }() 450 } 451 if err := validation.Validate([]validation.Validation{ 452 {TargetValue: serviceName, 453 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 454 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 455 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 456 {TargetValue: apiid, 457 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil}, 458 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 459 {Target: "apiid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 460 {TargetValue: top, 461 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 462 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 463 {TargetValue: skip, 464 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 465 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 466 return result, validation.NewError("apimanagement.APIDiagnosticClient", "ListByService", err.Error()) 467 } 468 469 result.fn = client.listByServiceNextResults 470 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip) 471 if err != nil { 472 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "ListByService", nil, "Failure preparing request") 473 return 474 } 475 476 resp, err := client.ListByServiceSender(req) 477 if err != nil { 478 result.dc.Response = autorest.Response{Response: resp} 479 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "ListByService", resp, "Failure sending request") 480 return 481 } 482 483 result.dc, err = client.ListByServiceResponder(resp) 484 if err != nil { 485 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "ListByService", resp, "Failure responding to request") 486 return 487 } 488 if result.dc.hasNextLink() && result.dc.IsEmpty() { 489 err = result.NextWithContext(ctx) 490 return 491 } 492 493 return 494} 495 496// ListByServicePreparer prepares the ListByService request. 497func (client APIDiagnosticClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) { 498 pathParameters := map[string]interface{}{ 499 "apiId": autorest.Encode("path", apiid), 500 "resourceGroupName": autorest.Encode("path", resourceGroupName), 501 "serviceName": autorest.Encode("path", serviceName), 502 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 503 } 504 505 const APIVersion = "2018-01-01" 506 queryParameters := map[string]interface{}{ 507 "api-version": APIVersion, 508 } 509 if len(filter) > 0 { 510 queryParameters["$filter"] = autorest.Encode("query", filter) 511 } 512 if top != nil { 513 queryParameters["$top"] = autorest.Encode("query", *top) 514 } 515 if skip != nil { 516 queryParameters["$skip"] = autorest.Encode("query", *skip) 517 } 518 519 preparer := autorest.CreatePreparer( 520 autorest.AsGet(), 521 autorest.WithBaseURL(client.BaseURI), 522 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics", pathParameters), 523 autorest.WithQueryParameters(queryParameters)) 524 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 525} 526 527// ListByServiceSender sends the ListByService request. The method will close the 528// http.Response Body if it receives an error. 529func (client APIDiagnosticClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 530 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 531} 532 533// ListByServiceResponder handles the response to the ListByService request. The method always 534// closes the http.Response Body. 535func (client APIDiagnosticClient) ListByServiceResponder(resp *http.Response) (result DiagnosticCollection, err error) { 536 err = autorest.Respond( 537 resp, 538 azure.WithErrorUnlessStatusCode(http.StatusOK), 539 autorest.ByUnmarshallingJSON(&result), 540 autorest.ByClosing()) 541 result.Response = autorest.Response{Response: resp} 542 return 543} 544 545// listByServiceNextResults retrieves the next set of results, if any. 546func (client APIDiagnosticClient) listByServiceNextResults(ctx context.Context, lastResults DiagnosticCollection) (result DiagnosticCollection, err error) { 547 req, err := lastResults.diagnosticCollectionPreparer(ctx) 548 if err != nil { 549 return result, autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "listByServiceNextResults", nil, "Failure preparing next results request") 550 } 551 if req == nil { 552 return 553 } 554 resp, err := client.ListByServiceSender(req) 555 if err != nil { 556 result.Response = autorest.Response{Response: resp} 557 return result, autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "listByServiceNextResults", resp, "Failure sending next results request") 558 } 559 result, err = client.ListByServiceResponder(resp) 560 if err != nil { 561 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "listByServiceNextResults", resp, "Failure responding to next results request") 562 } 563 return 564} 565 566// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 567func (client APIDiagnosticClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result DiagnosticCollectionIterator, err error) { 568 if tracing.IsEnabled() { 569 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.ListByService") 570 defer func() { 571 sc := -1 572 if result.Response().Response.Response != nil { 573 sc = result.page.Response().Response.Response.StatusCode 574 } 575 tracing.EndSpan(ctx, sc, err) 576 }() 577 } 578 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, filter, top, skip) 579 return 580} 581 582// Update updates the details of the Diagnostic for an API specified by its identifier. 583// Parameters: 584// resourceGroupName - the name of the resource group. 585// serviceName - the name of the API Management service. 586// apiid - API identifier. Must be unique in the current API Management service instance. 587// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance. 588// parameters - diagnostic Update parameters. 589// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 590// request or it should be * for unconditional update. 591func (client APIDiagnosticClient) Update(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string, parameters DiagnosticContract, ifMatch string) (result autorest.Response, err error) { 592 if tracing.IsEnabled() { 593 ctx = tracing.StartSpan(ctx, fqdn+"/APIDiagnosticClient.Update") 594 defer func() { 595 sc := -1 596 if result.Response != nil { 597 sc = result.Response.StatusCode 598 } 599 tracing.EndSpan(ctx, sc, err) 600 }() 601 } 602 if err := validation.Validate([]validation.Validation{ 603 {TargetValue: serviceName, 604 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 605 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 606 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 607 {TargetValue: apiid, 608 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil}, 609 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 610 {Target: "apiid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}, 611 {TargetValue: diagnosticID, 612 Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 613 {Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil}, 614 {Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil { 615 return result, validation.NewError("apimanagement.APIDiagnosticClient", "Update", err.Error()) 616 } 617 618 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, apiid, diagnosticID, parameters, ifMatch) 619 if err != nil { 620 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Update", nil, "Failure preparing request") 621 return 622 } 623 624 resp, err := client.UpdateSender(req) 625 if err != nil { 626 result.Response = resp 627 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Update", resp, "Failure sending request") 628 return 629 } 630 631 result, err = client.UpdateResponder(resp) 632 if err != nil { 633 err = autorest.NewErrorWithError(err, "apimanagement.APIDiagnosticClient", "Update", resp, "Failure responding to request") 634 return 635 } 636 637 return 638} 639 640// UpdatePreparer prepares the Update request. 641func (client APIDiagnosticClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, diagnosticID string, parameters DiagnosticContract, ifMatch string) (*http.Request, error) { 642 pathParameters := map[string]interface{}{ 643 "apiId": autorest.Encode("path", apiid), 644 "diagnosticId": autorest.Encode("path", diagnosticID), 645 "resourceGroupName": autorest.Encode("path", resourceGroupName), 646 "serviceName": autorest.Encode("path", serviceName), 647 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 648 } 649 650 const APIVersion = "2018-01-01" 651 queryParameters := map[string]interface{}{ 652 "api-version": APIVersion, 653 } 654 655 preparer := autorest.CreatePreparer( 656 autorest.AsContentType("application/json; charset=utf-8"), 657 autorest.AsPatch(), 658 autorest.WithBaseURL(client.BaseURI), 659 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics/{diagnosticId}", pathParameters), 660 autorest.WithJSON(parameters), 661 autorest.WithQueryParameters(queryParameters), 662 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 663 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 664} 665 666// UpdateSender sends the Update request. The method will close the 667// http.Response Body if it receives an error. 668func (client APIDiagnosticClient) UpdateSender(req *http.Request) (*http.Response, error) { 669 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 670} 671 672// UpdateResponder handles the response to the Update request. The method always 673// closes the http.Response Body. 674func (client APIDiagnosticClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 675 err = autorest.Respond( 676 resp, 677 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 678 autorest.ByClosing()) 679 result.Response = resp 680 return 681} 682