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