1package iothub 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/date" 25 "github.com/Azure/go-autorest/autorest/validation" 26 "github.com/Azure/go-autorest/tracing" 27 "net/http" 28) 29 30// DpsCertificateClient is the API for using the Azure IoT Hub Device Provisioning Service features. 31type DpsCertificateClient struct { 32 BaseClient 33} 34 35// NewDpsCertificateClient creates an instance of the DpsCertificateClient client. 36func NewDpsCertificateClient(subscriptionID string) DpsCertificateClient { 37 return NewDpsCertificateClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewDpsCertificateClientWithBaseURI creates an instance of the DpsCertificateClient client using a custom endpoint. 41// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 42func NewDpsCertificateClientWithBaseURI(baseURI string, subscriptionID string) DpsCertificateClient { 43 return DpsCertificateClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// CreateOrUpdate add new certificate or update an existing certificate. 47// Parameters: 48// resourceGroupName - resource group identifier. 49// provisioningServiceName - the name of the provisioning service. 50// certificateName - the name of the certificate create or update. 51// certificateDescription - the certificate body. 52// ifMatch - eTag of the certificate. This is required to update an existing certificate, and ignored while 53// creating a brand new certificate. 54func (client DpsCertificateClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, provisioningServiceName string, certificateName string, certificateDescription CertificateBodyDescription, ifMatch string) (result CertificateResponse, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/DpsCertificateClient.CreateOrUpdate") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 if err := validation.Validate([]validation.Validation{ 66 {TargetValue: certificateName, 67 Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 256, Chain: nil}}}}); err != nil { 68 return result, validation.NewError("iothub.DpsCertificateClient", "CreateOrUpdate", err.Error()) 69 } 70 71 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, provisioningServiceName, certificateName, certificateDescription, ifMatch) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "CreateOrUpdate", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.CreateOrUpdateSender(req) 78 if err != nil { 79 result.Response = autorest.Response{Response: resp} 80 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "CreateOrUpdate", resp, "Failure sending request") 81 return 82 } 83 84 result, err = client.CreateOrUpdateResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "CreateOrUpdate", resp, "Failure responding to request") 87 return 88 } 89 90 return 91} 92 93// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 94func (client DpsCertificateClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, provisioningServiceName string, certificateName string, certificateDescription CertificateBodyDescription, ifMatch string) (*http.Request, error) { 95 pathParameters := map[string]interface{}{ 96 "certificateName": autorest.Encode("path", certificateName), 97 "provisioningServiceName": autorest.Encode("path", provisioningServiceName), 98 "resourceGroupName": autorest.Encode("path", resourceGroupName), 99 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 100 } 101 102 const APIVersion = "2017-11-15" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 107 preparer := autorest.CreatePreparer( 108 autorest.AsContentType("application/json; charset=utf-8"), 109 autorest.AsPut(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}", pathParameters), 112 autorest.WithJSON(certificateDescription), 113 autorest.WithQueryParameters(queryParameters)) 114 if len(ifMatch) > 0 { 115 preparer = autorest.DecoratePreparer(preparer, 116 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 117 } 118 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 119} 120 121// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 122// http.Response Body if it receives an error. 123func (client DpsCertificateClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 124 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 125} 126 127// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 128// closes the http.Response Body. 129func (client DpsCertificateClient) CreateOrUpdateResponder(resp *http.Response) (result CertificateResponse, err error) { 130 err = autorest.Respond( 131 resp, 132 azure.WithErrorUnlessStatusCode(http.StatusOK), 133 autorest.ByUnmarshallingJSON(&result), 134 autorest.ByClosing()) 135 result.Response = autorest.Response{Response: resp} 136 return 137} 138 139// Delete deletes the specified certificate associated with the Provisioning Service 140// Parameters: 141// resourceGroupName - resource group identifier. 142// ifMatch - eTag of the certificate 143// provisioningServiceName - the name of the provisioning service. 144// certificateName - this is a mandatory field, and is the logical name of the certificate that the 145// provisioning service will access by. 146// certificatename - this is optional, and it is the Common Name of the certificate. 147// certificaterawBytes - raw data within the certificate. 148// certificateisVerified - indicates if certificate has been verified by owner of the private key. 149// certificatepurpose - a description that mentions the purpose of the certificate. 150// certificatecreated - time the certificate is created. 151// certificatelastUpdated - time the certificate is last updated. 152// certificatehasPrivateKey - indicates if the certificate contains a private key. 153// certificatenonce - random number generated to indicate Proof of Possession. 154func (client DpsCertificateClient) Delete(ctx context.Context, resourceGroupName string, ifMatch string, provisioningServiceName string, certificateName string, certificatename string, certificaterawBytes []byte, certificateisVerified *bool, certificatepurpose CertificatePurpose, certificatecreated *date.Time, certificatelastUpdated *date.Time, certificatehasPrivateKey *bool, certificatenonce string) (result autorest.Response, err error) { 155 if tracing.IsEnabled() { 156 ctx = tracing.StartSpan(ctx, fqdn+"/DpsCertificateClient.Delete") 157 defer func() { 158 sc := -1 159 if result.Response != nil { 160 sc = result.Response.StatusCode 161 } 162 tracing.EndSpan(ctx, sc, err) 163 }() 164 } 165 req, err := client.DeletePreparer(ctx, resourceGroupName, ifMatch, provisioningServiceName, certificateName, certificatename, certificaterawBytes, certificateisVerified, certificatepurpose, certificatecreated, certificatelastUpdated, certificatehasPrivateKey, certificatenonce) 166 if err != nil { 167 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "Delete", nil, "Failure preparing request") 168 return 169 } 170 171 resp, err := client.DeleteSender(req) 172 if err != nil { 173 result.Response = resp 174 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "Delete", resp, "Failure sending request") 175 return 176 } 177 178 result, err = client.DeleteResponder(resp) 179 if err != nil { 180 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "Delete", resp, "Failure responding to request") 181 return 182 } 183 184 return 185} 186 187// DeletePreparer prepares the Delete request. 188func (client DpsCertificateClient) DeletePreparer(ctx context.Context, resourceGroupName string, ifMatch string, provisioningServiceName string, certificateName string, certificatename string, certificaterawBytes []byte, certificateisVerified *bool, certificatepurpose CertificatePurpose, certificatecreated *date.Time, certificatelastUpdated *date.Time, certificatehasPrivateKey *bool, certificatenonce string) (*http.Request, error) { 189 pathParameters := map[string]interface{}{ 190 "certificateName": autorest.Encode("path", certificateName), 191 "provisioningServiceName": autorest.Encode("path", provisioningServiceName), 192 "resourceGroupName": autorest.Encode("path", resourceGroupName), 193 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 194 } 195 196 const APIVersion = "2017-11-15" 197 queryParameters := map[string]interface{}{ 198 "api-version": APIVersion, 199 } 200 if len(certificatename) > 0 { 201 queryParameters["certificate.name"] = autorest.Encode("query", certificatename) 202 } 203 if certificaterawBytes != nil && len(certificaterawBytes) > 0 { 204 queryParameters["certificate.rawBytes"] = autorest.Encode("query", certificaterawBytes) 205 } 206 if certificateisVerified != nil { 207 queryParameters["certificate.isVerified"] = autorest.Encode("query", *certificateisVerified) 208 } 209 if len(string(certificatepurpose)) > 0 { 210 queryParameters["certificate.purpose"] = autorest.Encode("query", certificatepurpose) 211 } 212 if certificatecreated != nil { 213 queryParameters["certificate.created"] = autorest.Encode("query", *certificatecreated) 214 } 215 if certificatelastUpdated != nil { 216 queryParameters["certificate.lastUpdated"] = autorest.Encode("query", *certificatelastUpdated) 217 } 218 if certificatehasPrivateKey != nil { 219 queryParameters["certificate.hasPrivateKey"] = autorest.Encode("query", *certificatehasPrivateKey) 220 } 221 if len(certificatenonce) > 0 { 222 queryParameters["certificate.nonce"] = autorest.Encode("query", certificatenonce) 223 } 224 225 preparer := autorest.CreatePreparer( 226 autorest.AsDelete(), 227 autorest.WithBaseURL(client.BaseURI), 228 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}", pathParameters), 229 autorest.WithQueryParameters(queryParameters), 230 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 231 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 232} 233 234// DeleteSender sends the Delete request. The method will close the 235// http.Response Body if it receives an error. 236func (client DpsCertificateClient) DeleteSender(req *http.Request) (*http.Response, error) { 237 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 238} 239 240// DeleteResponder handles the response to the Delete request. The method always 241// closes the http.Response Body. 242func (client DpsCertificateClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 243 err = autorest.Respond( 244 resp, 245 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 246 autorest.ByClosing()) 247 result.Response = resp 248 return 249} 250 251// GenerateVerificationCode generate verification code for Proof of Possession. 252// Parameters: 253// certificateName - the mandatory logical name of the certificate, that the provisioning service uses to 254// access. 255// ifMatch - eTag of the certificate. This is required to update an existing certificate, and ignored while 256// creating a brand new certificate. 257// resourceGroupName - name of resource group. 258// provisioningServiceName - name of provisioning service. 259// certificatename - common Name for the certificate. 260// certificaterawBytes - raw data of certificate. 261// certificateisVerified - indicates if the certificate has been verified by owner of the private key. 262// certificatepurpose - description mentioning the purpose of the certificate. 263// certificatecreated - certificate creation time. 264// certificatelastUpdated - certificate last updated time. 265// certificatehasPrivateKey - indicates if the certificate contains private key. 266// certificatenonce - random number generated to indicate Proof of Possession. 267func (client DpsCertificateClient) GenerateVerificationCode(ctx context.Context, certificateName string, ifMatch string, resourceGroupName string, provisioningServiceName string, certificatename string, certificaterawBytes []byte, certificateisVerified *bool, certificatepurpose CertificatePurpose, certificatecreated *date.Time, certificatelastUpdated *date.Time, certificatehasPrivateKey *bool, certificatenonce string) (result VerificationCodeResponse, err error) { 268 if tracing.IsEnabled() { 269 ctx = tracing.StartSpan(ctx, fqdn+"/DpsCertificateClient.GenerateVerificationCode") 270 defer func() { 271 sc := -1 272 if result.Response.Response != nil { 273 sc = result.Response.Response.StatusCode 274 } 275 tracing.EndSpan(ctx, sc, err) 276 }() 277 } 278 req, err := client.GenerateVerificationCodePreparer(ctx, certificateName, ifMatch, resourceGroupName, provisioningServiceName, certificatename, certificaterawBytes, certificateisVerified, certificatepurpose, certificatecreated, certificatelastUpdated, certificatehasPrivateKey, certificatenonce) 279 if err != nil { 280 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "GenerateVerificationCode", nil, "Failure preparing request") 281 return 282 } 283 284 resp, err := client.GenerateVerificationCodeSender(req) 285 if err != nil { 286 result.Response = autorest.Response{Response: resp} 287 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "GenerateVerificationCode", resp, "Failure sending request") 288 return 289 } 290 291 result, err = client.GenerateVerificationCodeResponder(resp) 292 if err != nil { 293 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "GenerateVerificationCode", resp, "Failure responding to request") 294 return 295 } 296 297 return 298} 299 300// GenerateVerificationCodePreparer prepares the GenerateVerificationCode request. 301func (client DpsCertificateClient) GenerateVerificationCodePreparer(ctx context.Context, certificateName string, ifMatch string, resourceGroupName string, provisioningServiceName string, certificatename string, certificaterawBytes []byte, certificateisVerified *bool, certificatepurpose CertificatePurpose, certificatecreated *date.Time, certificatelastUpdated *date.Time, certificatehasPrivateKey *bool, certificatenonce string) (*http.Request, error) { 302 pathParameters := map[string]interface{}{ 303 "certificateName": autorest.Encode("path", certificateName), 304 "provisioningServiceName": autorest.Encode("path", provisioningServiceName), 305 "resourceGroupName": autorest.Encode("path", resourceGroupName), 306 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 307 } 308 309 const APIVersion = "2017-11-15" 310 queryParameters := map[string]interface{}{ 311 "api-version": APIVersion, 312 } 313 if len(certificatename) > 0 { 314 queryParameters["certificate.name"] = autorest.Encode("query", certificatename) 315 } 316 if certificaterawBytes != nil && len(certificaterawBytes) > 0 { 317 queryParameters["certificate.rawBytes"] = autorest.Encode("query", certificaterawBytes) 318 } 319 if certificateisVerified != nil { 320 queryParameters["certificate.isVerified"] = autorest.Encode("query", *certificateisVerified) 321 } 322 if len(string(certificatepurpose)) > 0 { 323 queryParameters["certificate.purpose"] = autorest.Encode("query", certificatepurpose) 324 } 325 if certificatecreated != nil { 326 queryParameters["certificate.created"] = autorest.Encode("query", *certificatecreated) 327 } 328 if certificatelastUpdated != nil { 329 queryParameters["certificate.lastUpdated"] = autorest.Encode("query", *certificatelastUpdated) 330 } 331 if certificatehasPrivateKey != nil { 332 queryParameters["certificate.hasPrivateKey"] = autorest.Encode("query", *certificatehasPrivateKey) 333 } 334 if len(certificatenonce) > 0 { 335 queryParameters["certificate.nonce"] = autorest.Encode("query", certificatenonce) 336 } 337 338 preparer := autorest.CreatePreparer( 339 autorest.AsPost(), 340 autorest.WithBaseURL(client.BaseURI), 341 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}/generateVerificationCode", pathParameters), 342 autorest.WithQueryParameters(queryParameters), 343 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 344 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 345} 346 347// GenerateVerificationCodeSender sends the GenerateVerificationCode request. The method will close the 348// http.Response Body if it receives an error. 349func (client DpsCertificateClient) GenerateVerificationCodeSender(req *http.Request) (*http.Response, error) { 350 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 351} 352 353// GenerateVerificationCodeResponder handles the response to the GenerateVerificationCode request. The method always 354// closes the http.Response Body. 355func (client DpsCertificateClient) GenerateVerificationCodeResponder(resp *http.Response) (result VerificationCodeResponse, err error) { 356 err = autorest.Respond( 357 resp, 358 azure.WithErrorUnlessStatusCode(http.StatusOK), 359 autorest.ByUnmarshallingJSON(&result), 360 autorest.ByClosing()) 361 result.Response = autorest.Response{Response: resp} 362 return 363} 364 365// Get get the certificate from the provisioning service. 366// Parameters: 367// certificateName - name of the certificate to retrieve. 368// resourceGroupName - resource group identifier. 369// provisioningServiceName - name of the provisioning service the certificate is associated with. 370// ifMatch - eTag of the certificate. 371func (client DpsCertificateClient) Get(ctx context.Context, certificateName string, resourceGroupName string, provisioningServiceName string, ifMatch string) (result CertificateResponse, err error) { 372 if tracing.IsEnabled() { 373 ctx = tracing.StartSpan(ctx, fqdn+"/DpsCertificateClient.Get") 374 defer func() { 375 sc := -1 376 if result.Response.Response != nil { 377 sc = result.Response.Response.StatusCode 378 } 379 tracing.EndSpan(ctx, sc, err) 380 }() 381 } 382 req, err := client.GetPreparer(ctx, certificateName, resourceGroupName, provisioningServiceName, ifMatch) 383 if err != nil { 384 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "Get", nil, "Failure preparing request") 385 return 386 } 387 388 resp, err := client.GetSender(req) 389 if err != nil { 390 result.Response = autorest.Response{Response: resp} 391 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "Get", resp, "Failure sending request") 392 return 393 } 394 395 result, err = client.GetResponder(resp) 396 if err != nil { 397 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "Get", resp, "Failure responding to request") 398 return 399 } 400 401 return 402} 403 404// GetPreparer prepares the Get request. 405func (client DpsCertificateClient) GetPreparer(ctx context.Context, certificateName string, resourceGroupName string, provisioningServiceName string, ifMatch string) (*http.Request, error) { 406 pathParameters := map[string]interface{}{ 407 "certificateName": autorest.Encode("path", certificateName), 408 "provisioningServiceName": autorest.Encode("path", provisioningServiceName), 409 "resourceGroupName": autorest.Encode("path", resourceGroupName), 410 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 411 } 412 413 const APIVersion = "2017-11-15" 414 queryParameters := map[string]interface{}{ 415 "api-version": APIVersion, 416 } 417 418 preparer := autorest.CreatePreparer( 419 autorest.AsGet(), 420 autorest.WithBaseURL(client.BaseURI), 421 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}", pathParameters), 422 autorest.WithQueryParameters(queryParameters)) 423 if len(ifMatch) > 0 { 424 preparer = autorest.DecoratePreparer(preparer, 425 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 426 } 427 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 428} 429 430// GetSender sends the Get request. The method will close the 431// http.Response Body if it receives an error. 432func (client DpsCertificateClient) GetSender(req *http.Request) (*http.Response, error) { 433 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 434} 435 436// GetResponder handles the response to the Get request. The method always 437// closes the http.Response Body. 438func (client DpsCertificateClient) GetResponder(resp *http.Response) (result CertificateResponse, err error) { 439 err = autorest.Respond( 440 resp, 441 azure.WithErrorUnlessStatusCode(http.StatusOK), 442 autorest.ByUnmarshallingJSON(&result), 443 autorest.ByClosing()) 444 result.Response = autorest.Response{Response: resp} 445 return 446} 447 448// List get all the certificates tied to the provisioning service. 449// Parameters: 450// resourceGroupName - name of resource group. 451// provisioningServiceName - name of provisioning service to retrieve certificates for. 452func (client DpsCertificateClient) List(ctx context.Context, resourceGroupName string, provisioningServiceName string) (result CertificateListDescription, err error) { 453 if tracing.IsEnabled() { 454 ctx = tracing.StartSpan(ctx, fqdn+"/DpsCertificateClient.List") 455 defer func() { 456 sc := -1 457 if result.Response.Response != nil { 458 sc = result.Response.Response.StatusCode 459 } 460 tracing.EndSpan(ctx, sc, err) 461 }() 462 } 463 req, err := client.ListPreparer(ctx, resourceGroupName, provisioningServiceName) 464 if err != nil { 465 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "List", nil, "Failure preparing request") 466 return 467 } 468 469 resp, err := client.ListSender(req) 470 if err != nil { 471 result.Response = autorest.Response{Response: resp} 472 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "List", resp, "Failure sending request") 473 return 474 } 475 476 result, err = client.ListResponder(resp) 477 if err != nil { 478 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "List", resp, "Failure responding to request") 479 return 480 } 481 482 return 483} 484 485// ListPreparer prepares the List request. 486func (client DpsCertificateClient) ListPreparer(ctx context.Context, resourceGroupName string, provisioningServiceName string) (*http.Request, error) { 487 pathParameters := map[string]interface{}{ 488 "provisioningServiceName": autorest.Encode("path", provisioningServiceName), 489 "resourceGroupName": autorest.Encode("path", resourceGroupName), 490 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 491 } 492 493 const APIVersion = "2017-11-15" 494 queryParameters := map[string]interface{}{ 495 "api-version": APIVersion, 496 } 497 498 preparer := autorest.CreatePreparer( 499 autorest.AsGet(), 500 autorest.WithBaseURL(client.BaseURI), 501 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates", pathParameters), 502 autorest.WithQueryParameters(queryParameters)) 503 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 504} 505 506// ListSender sends the List request. The method will close the 507// http.Response Body if it receives an error. 508func (client DpsCertificateClient) ListSender(req *http.Request) (*http.Response, error) { 509 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 510} 511 512// ListResponder handles the response to the List request. The method always 513// closes the http.Response Body. 514func (client DpsCertificateClient) ListResponder(resp *http.Response) (result CertificateListDescription, 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// VerifyCertificate verifies the certificate's private key possession by providing the leaf cert issued by the 525// verifying pre uploaded certificate. 526// Parameters: 527// certificateName - the mandatory logical name of the certificate, that the provisioning service uses to 528// access. 529// ifMatch - eTag of the certificate. 530// request - the name of the certificate 531// resourceGroupName - resource group name. 532// provisioningServiceName - provisioning service name. 533// certificatename - common Name for the certificate. 534// certificaterawBytes - raw data of certificate. 535// certificateisVerified - indicates if the certificate has been verified by owner of the private key. 536// certificatepurpose - describe the purpose of the certificate. 537// certificatecreated - certificate creation time. 538// certificatelastUpdated - certificate last updated time. 539// certificatehasPrivateKey - indicates if the certificate contains private key. 540// certificatenonce - random number generated to indicate Proof of Possession. 541func (client DpsCertificateClient) VerifyCertificate(ctx context.Context, certificateName string, ifMatch string, request VerificationCodeRequest, resourceGroupName string, provisioningServiceName string, certificatename string, certificaterawBytes []byte, certificateisVerified *bool, certificatepurpose CertificatePurpose, certificatecreated *date.Time, certificatelastUpdated *date.Time, certificatehasPrivateKey *bool, certificatenonce string) (result CertificateResponse, err error) { 542 if tracing.IsEnabled() { 543 ctx = tracing.StartSpan(ctx, fqdn+"/DpsCertificateClient.VerifyCertificate") 544 defer func() { 545 sc := -1 546 if result.Response.Response != nil { 547 sc = result.Response.Response.StatusCode 548 } 549 tracing.EndSpan(ctx, sc, err) 550 }() 551 } 552 req, err := client.VerifyCertificatePreparer(ctx, certificateName, ifMatch, request, resourceGroupName, provisioningServiceName, certificatename, certificaterawBytes, certificateisVerified, certificatepurpose, certificatecreated, certificatelastUpdated, certificatehasPrivateKey, certificatenonce) 553 if err != nil { 554 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "VerifyCertificate", nil, "Failure preparing request") 555 return 556 } 557 558 resp, err := client.VerifyCertificateSender(req) 559 if err != nil { 560 result.Response = autorest.Response{Response: resp} 561 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "VerifyCertificate", resp, "Failure sending request") 562 return 563 } 564 565 result, err = client.VerifyCertificateResponder(resp) 566 if err != nil { 567 err = autorest.NewErrorWithError(err, "iothub.DpsCertificateClient", "VerifyCertificate", resp, "Failure responding to request") 568 return 569 } 570 571 return 572} 573 574// VerifyCertificatePreparer prepares the VerifyCertificate request. 575func (client DpsCertificateClient) VerifyCertificatePreparer(ctx context.Context, certificateName string, ifMatch string, request VerificationCodeRequest, resourceGroupName string, provisioningServiceName string, certificatename string, certificaterawBytes []byte, certificateisVerified *bool, certificatepurpose CertificatePurpose, certificatecreated *date.Time, certificatelastUpdated *date.Time, certificatehasPrivateKey *bool, certificatenonce string) (*http.Request, error) { 576 pathParameters := map[string]interface{}{ 577 "certificateName": autorest.Encode("path", certificateName), 578 "provisioningServiceName": autorest.Encode("path", provisioningServiceName), 579 "resourceGroupName": autorest.Encode("path", resourceGroupName), 580 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 581 } 582 583 const APIVersion = "2017-11-15" 584 queryParameters := map[string]interface{}{ 585 "api-version": APIVersion, 586 } 587 if len(certificatename) > 0 { 588 queryParameters["certificate.name"] = autorest.Encode("query", certificatename) 589 } 590 if certificaterawBytes != nil && len(certificaterawBytes) > 0 { 591 queryParameters["certificate.rawBytes"] = autorest.Encode("query", certificaterawBytes) 592 } 593 if certificateisVerified != nil { 594 queryParameters["certificate.isVerified"] = autorest.Encode("query", *certificateisVerified) 595 } 596 if len(string(certificatepurpose)) > 0 { 597 queryParameters["certificate.purpose"] = autorest.Encode("query", certificatepurpose) 598 } 599 if certificatecreated != nil { 600 queryParameters["certificate.created"] = autorest.Encode("query", *certificatecreated) 601 } 602 if certificatelastUpdated != nil { 603 queryParameters["certificate.lastUpdated"] = autorest.Encode("query", *certificatelastUpdated) 604 } 605 if certificatehasPrivateKey != nil { 606 queryParameters["certificate.hasPrivateKey"] = autorest.Encode("query", *certificatehasPrivateKey) 607 } 608 if len(certificatenonce) > 0 { 609 queryParameters["certificate.nonce"] = autorest.Encode("query", certificatenonce) 610 } 611 612 preparer := autorest.CreatePreparer( 613 autorest.AsContentType("application/json; charset=utf-8"), 614 autorest.AsPost(), 615 autorest.WithBaseURL(client.BaseURI), 616 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}/verify", pathParameters), 617 autorest.WithJSON(request), 618 autorest.WithQueryParameters(queryParameters), 619 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 620 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 621} 622 623// VerifyCertificateSender sends the VerifyCertificate request. The method will close the 624// http.Response Body if it receives an error. 625func (client DpsCertificateClient) VerifyCertificateSender(req *http.Request) (*http.Response, error) { 626 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 627} 628 629// VerifyCertificateResponder handles the response to the VerifyCertificate request. The method always 630// closes the http.Response Body. 631func (client DpsCertificateClient) VerifyCertificateResponder(resp *http.Response) (result CertificateResponse, err error) { 632 err = autorest.Respond( 633 resp, 634 azure.WithErrorUnlessStatusCode(http.StatusOK), 635 autorest.ByUnmarshallingJSON(&result), 636 autorest.ByClosing()) 637 result.Response = autorest.Response{Response: resp} 638 return 639} 640