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