...

Source file src/github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2018-01-22/devices/certificates.go

Documentation: github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2018-01-22/devices

     1  package devices
     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  
     9  import (
    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  // CertificatesClient is the use this API to manage the IoT hubs in your Azure subscription.
    19  type CertificatesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCertificatesClient creates an instance of the CertificatesClient client.
    24  func NewCertificatesClient(subscriptionID string) CertificatesClient {
    25  	return NewCertificatesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewCertificatesClientWithBaseURI creates an instance of the CertificatesClient 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).
    30  func NewCertificatesClientWithBaseURI(baseURI string, subscriptionID string) CertificatesClient {
    31  	return CertificatesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate adds new or replaces existing certificate.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group that contains the IoT hub.
    37  // resourceName - the name of the IoT hub.
    38  // certificateName - the name of the certificate
    39  // certificateDescription - the certificate body.
    40  // ifMatch - eTag of the Certificate. Do not specify for creating a brand new certificate. Required to update
    41  // an existing certificate.
    42  func (client CertificatesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, certificateDescription CertificateBodyDescription, ifMatch string) (result CertificateDescription, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/CertificatesClient.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: certificateName,
    55  			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]{1,64}$`, Chain: nil}}}}); err != nil {
    56  		return result, validation.NewError("devices.CertificatesClient", "CreateOrUpdate", err.Error())
    57  	}
    58  
    59  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, certificateName, certificateDescription, ifMatch)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "CreateOrUpdate", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	resp, err := client.CreateOrUpdateSender(req)
    66  	if err != nil {
    67  		result.Response = autorest.Response{Response: resp}
    68  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "CreateOrUpdate", resp, "Failure sending request")
    69  		return
    70  	}
    71  
    72  	result, err = client.CreateOrUpdateResponder(resp)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "CreateOrUpdate", resp, "Failure responding to request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    82  func (client CertificatesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, certificateDescription CertificateBodyDescription, ifMatch string) (*http.Request, error) {
    83  	pathParameters := map[string]interface{}{
    84  		"certificateName":   autorest.Encode("path", certificateName),
    85  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    86  		"resourceName":      autorest.Encode("path", resourceName),
    87  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    88  	}
    89  
    90  	const APIVersion = "2018-01-22"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsContentType("application/json; charset=utf-8"),
    97  		autorest.AsPut(),
    98  		autorest.WithBaseURL(client.BaseURI),
    99  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/certificates/{certificateName}", pathParameters),
   100  		autorest.WithJSON(certificateDescription),
   101  		autorest.WithQueryParameters(queryParameters))
   102  	if len(ifMatch) > 0 {
   103  		preparer = autorest.DecoratePreparer(preparer,
   104  			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   105  	}
   106  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   107  }
   108  
   109  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client CertificatesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   112  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   113  }
   114  
   115  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   116  // closes the http.Response Body.
   117  func (client CertificatesClient) CreateOrUpdateResponder(resp *http.Response) (result CertificateDescription, err error) {
   118  	err = autorest.Respond(
   119  		resp,
   120  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   121  		autorest.ByUnmarshallingJSON(&result),
   122  		autorest.ByClosing())
   123  	result.Response = autorest.Response{Response: resp}
   124  	return
   125  }
   126  
   127  // Delete deletes an existing X509 certificate or does nothing if it does not exist.
   128  // Parameters:
   129  // resourceGroupName - the name of the resource group that contains the IoT hub.
   130  // resourceName - the name of the IoT hub.
   131  // certificateName - the name of the certificate
   132  // ifMatch - eTag of the Certificate.
   133  func (client CertificatesClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, ifMatch string) (result autorest.Response, err error) {
   134  	if tracing.IsEnabled() {
   135  		ctx = tracing.StartSpan(ctx, fqdn+"/CertificatesClient.Delete")
   136  		defer func() {
   137  			sc := -1
   138  			if result.Response != nil {
   139  				sc = result.Response.StatusCode
   140  			}
   141  			tracing.EndSpan(ctx, sc, err)
   142  		}()
   143  	}
   144  	if err := validation.Validate([]validation.Validation{
   145  		{TargetValue: certificateName,
   146  			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]{1,64}$`, Chain: nil}}}}); err != nil {
   147  		return result, validation.NewError("devices.CertificatesClient", "Delete", err.Error())
   148  	}
   149  
   150  	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, certificateName, ifMatch)
   151  	if err != nil {
   152  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Delete", nil, "Failure preparing request")
   153  		return
   154  	}
   155  
   156  	resp, err := client.DeleteSender(req)
   157  	if err != nil {
   158  		result.Response = resp
   159  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Delete", resp, "Failure sending request")
   160  		return
   161  	}
   162  
   163  	result, err = client.DeleteResponder(resp)
   164  	if err != nil {
   165  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Delete", resp, "Failure responding to request")
   166  		return
   167  	}
   168  
   169  	return
   170  }
   171  
   172  // DeletePreparer prepares the Delete request.
   173  func (client CertificatesClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, ifMatch string) (*http.Request, error) {
   174  	pathParameters := map[string]interface{}{
   175  		"certificateName":   autorest.Encode("path", certificateName),
   176  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   177  		"resourceName":      autorest.Encode("path", resourceName),
   178  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   179  	}
   180  
   181  	const APIVersion = "2018-01-22"
   182  	queryParameters := map[string]interface{}{
   183  		"api-version": APIVersion,
   184  	}
   185  
   186  	preparer := autorest.CreatePreparer(
   187  		autorest.AsDelete(),
   188  		autorest.WithBaseURL(client.BaseURI),
   189  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/certificates/{certificateName}", pathParameters),
   190  		autorest.WithQueryParameters(queryParameters),
   191  		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   192  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   193  }
   194  
   195  // DeleteSender sends the Delete request. The method will close the
   196  // http.Response Body if it receives an error.
   197  func (client CertificatesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   198  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   199  }
   200  
   201  // DeleteResponder handles the response to the Delete request. The method always
   202  // closes the http.Response Body.
   203  func (client CertificatesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   204  	err = autorest.Respond(
   205  		resp,
   206  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   207  		autorest.ByClosing())
   208  	result.Response = resp
   209  	return
   210  }
   211  
   212  // GenerateVerificationCode generates verification code for proof of possession flow. The verification code will be
   213  // used to generate a leaf certificate.
   214  // Parameters:
   215  // resourceGroupName - the name of the resource group that contains the IoT hub.
   216  // resourceName - the name of the IoT hub.
   217  // certificateName - the name of the certificate
   218  // ifMatch - eTag of the Certificate.
   219  func (client CertificatesClient) GenerateVerificationCode(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, ifMatch string) (result CertificateWithNonceDescription, err error) {
   220  	if tracing.IsEnabled() {
   221  		ctx = tracing.StartSpan(ctx, fqdn+"/CertificatesClient.GenerateVerificationCode")
   222  		defer func() {
   223  			sc := -1
   224  			if result.Response.Response != nil {
   225  				sc = result.Response.Response.StatusCode
   226  			}
   227  			tracing.EndSpan(ctx, sc, err)
   228  		}()
   229  	}
   230  	if err := validation.Validate([]validation.Validation{
   231  		{TargetValue: certificateName,
   232  			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]{1,64}$`, Chain: nil}}}}); err != nil {
   233  		return result, validation.NewError("devices.CertificatesClient", "GenerateVerificationCode", err.Error())
   234  	}
   235  
   236  	req, err := client.GenerateVerificationCodePreparer(ctx, resourceGroupName, resourceName, certificateName, ifMatch)
   237  	if err != nil {
   238  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "GenerateVerificationCode", nil, "Failure preparing request")
   239  		return
   240  	}
   241  
   242  	resp, err := client.GenerateVerificationCodeSender(req)
   243  	if err != nil {
   244  		result.Response = autorest.Response{Response: resp}
   245  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "GenerateVerificationCode", resp, "Failure sending request")
   246  		return
   247  	}
   248  
   249  	result, err = client.GenerateVerificationCodeResponder(resp)
   250  	if err != nil {
   251  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "GenerateVerificationCode", resp, "Failure responding to request")
   252  		return
   253  	}
   254  
   255  	return
   256  }
   257  
   258  // GenerateVerificationCodePreparer prepares the GenerateVerificationCode request.
   259  func (client CertificatesClient) GenerateVerificationCodePreparer(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, ifMatch string) (*http.Request, error) {
   260  	pathParameters := map[string]interface{}{
   261  		"certificateName":   autorest.Encode("path", certificateName),
   262  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   263  		"resourceName":      autorest.Encode("path", resourceName),
   264  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   265  	}
   266  
   267  	const APIVersion = "2018-01-22"
   268  	queryParameters := map[string]interface{}{
   269  		"api-version": APIVersion,
   270  	}
   271  
   272  	preparer := autorest.CreatePreparer(
   273  		autorest.AsPost(),
   274  		autorest.WithBaseURL(client.BaseURI),
   275  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/certificates/{certificateName}/generateVerificationCode", pathParameters),
   276  		autorest.WithQueryParameters(queryParameters),
   277  		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   278  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   279  }
   280  
   281  // GenerateVerificationCodeSender sends the GenerateVerificationCode request. The method will close the
   282  // http.Response Body if it receives an error.
   283  func (client CertificatesClient) GenerateVerificationCodeSender(req *http.Request) (*http.Response, error) {
   284  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   285  }
   286  
   287  // GenerateVerificationCodeResponder handles the response to the GenerateVerificationCode request. The method always
   288  // closes the http.Response Body.
   289  func (client CertificatesClient) GenerateVerificationCodeResponder(resp *http.Response) (result CertificateWithNonceDescription, err error) {
   290  	err = autorest.Respond(
   291  		resp,
   292  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   293  		autorest.ByUnmarshallingJSON(&result),
   294  		autorest.ByClosing())
   295  	result.Response = autorest.Response{Response: resp}
   296  	return
   297  }
   298  
   299  // Get returns the certificate.
   300  // Parameters:
   301  // resourceGroupName - the name of the resource group that contains the IoT hub.
   302  // resourceName - the name of the IoT hub.
   303  // certificateName - the name of the certificate
   304  func (client CertificatesClient) Get(ctx context.Context, resourceGroupName string, resourceName string, certificateName string) (result CertificateDescription, err error) {
   305  	if tracing.IsEnabled() {
   306  		ctx = tracing.StartSpan(ctx, fqdn+"/CertificatesClient.Get")
   307  		defer func() {
   308  			sc := -1
   309  			if result.Response.Response != nil {
   310  				sc = result.Response.Response.StatusCode
   311  			}
   312  			tracing.EndSpan(ctx, sc, err)
   313  		}()
   314  	}
   315  	if err := validation.Validate([]validation.Validation{
   316  		{TargetValue: certificateName,
   317  			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]{1,64}$`, Chain: nil}}}}); err != nil {
   318  		return result, validation.NewError("devices.CertificatesClient", "Get", err.Error())
   319  	}
   320  
   321  	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, certificateName)
   322  	if err != nil {
   323  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Get", nil, "Failure preparing request")
   324  		return
   325  	}
   326  
   327  	resp, err := client.GetSender(req)
   328  	if err != nil {
   329  		result.Response = autorest.Response{Response: resp}
   330  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Get", resp, "Failure sending request")
   331  		return
   332  	}
   333  
   334  	result, err = client.GetResponder(resp)
   335  	if err != nil {
   336  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Get", resp, "Failure responding to request")
   337  		return
   338  	}
   339  
   340  	return
   341  }
   342  
   343  // GetPreparer prepares the Get request.
   344  func (client CertificatesClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, certificateName string) (*http.Request, error) {
   345  	pathParameters := map[string]interface{}{
   346  		"certificateName":   autorest.Encode("path", certificateName),
   347  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   348  		"resourceName":      autorest.Encode("path", resourceName),
   349  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   350  	}
   351  
   352  	const APIVersion = "2018-01-22"
   353  	queryParameters := map[string]interface{}{
   354  		"api-version": APIVersion,
   355  	}
   356  
   357  	preparer := autorest.CreatePreparer(
   358  		autorest.AsGet(),
   359  		autorest.WithBaseURL(client.BaseURI),
   360  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/certificates/{certificateName}", pathParameters),
   361  		autorest.WithQueryParameters(queryParameters))
   362  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   363  }
   364  
   365  // GetSender sends the Get request. The method will close the
   366  // http.Response Body if it receives an error.
   367  func (client CertificatesClient) GetSender(req *http.Request) (*http.Response, error) {
   368  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   369  }
   370  
   371  // GetResponder handles the response to the Get request. The method always
   372  // closes the http.Response Body.
   373  func (client CertificatesClient) GetResponder(resp *http.Response) (result CertificateDescription, err error) {
   374  	err = autorest.Respond(
   375  		resp,
   376  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   377  		autorest.ByUnmarshallingJSON(&result),
   378  		autorest.ByClosing())
   379  	result.Response = autorest.Response{Response: resp}
   380  	return
   381  }
   382  
   383  // ListByIotHub returns the list of certificates.
   384  // Parameters:
   385  // resourceGroupName - the name of the resource group that contains the IoT hub.
   386  // resourceName - the name of the IoT hub.
   387  func (client CertificatesClient) ListByIotHub(ctx context.Context, resourceGroupName string, resourceName string) (result CertificateListDescription, err error) {
   388  	if tracing.IsEnabled() {
   389  		ctx = tracing.StartSpan(ctx, fqdn+"/CertificatesClient.ListByIotHub")
   390  		defer func() {
   391  			sc := -1
   392  			if result.Response.Response != nil {
   393  				sc = result.Response.Response.StatusCode
   394  			}
   395  			tracing.EndSpan(ctx, sc, err)
   396  		}()
   397  	}
   398  	req, err := client.ListByIotHubPreparer(ctx, resourceGroupName, resourceName)
   399  	if err != nil {
   400  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "ListByIotHub", nil, "Failure preparing request")
   401  		return
   402  	}
   403  
   404  	resp, err := client.ListByIotHubSender(req)
   405  	if err != nil {
   406  		result.Response = autorest.Response{Response: resp}
   407  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "ListByIotHub", resp, "Failure sending request")
   408  		return
   409  	}
   410  
   411  	result, err = client.ListByIotHubResponder(resp)
   412  	if err != nil {
   413  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "ListByIotHub", resp, "Failure responding to request")
   414  		return
   415  	}
   416  
   417  	return
   418  }
   419  
   420  // ListByIotHubPreparer prepares the ListByIotHub request.
   421  func (client CertificatesClient) ListByIotHubPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
   422  	pathParameters := map[string]interface{}{
   423  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   424  		"resourceName":      autorest.Encode("path", resourceName),
   425  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   426  	}
   427  
   428  	const APIVersion = "2018-01-22"
   429  	queryParameters := map[string]interface{}{
   430  		"api-version": APIVersion,
   431  	}
   432  
   433  	preparer := autorest.CreatePreparer(
   434  		autorest.AsGet(),
   435  		autorest.WithBaseURL(client.BaseURI),
   436  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/certificates", pathParameters),
   437  		autorest.WithQueryParameters(queryParameters))
   438  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   439  }
   440  
   441  // ListByIotHubSender sends the ListByIotHub request. The method will close the
   442  // http.Response Body if it receives an error.
   443  func (client CertificatesClient) ListByIotHubSender(req *http.Request) (*http.Response, error) {
   444  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   445  }
   446  
   447  // ListByIotHubResponder handles the response to the ListByIotHub request. The method always
   448  // closes the http.Response Body.
   449  func (client CertificatesClient) ListByIotHubResponder(resp *http.Response) (result CertificateListDescription, err error) {
   450  	err = autorest.Respond(
   451  		resp,
   452  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   453  		autorest.ByUnmarshallingJSON(&result),
   454  		autorest.ByClosing())
   455  	result.Response = autorest.Response{Response: resp}
   456  	return
   457  }
   458  
   459  // Verify verifies the certificate's private key possession by providing the leaf cert issued by the verifying pre
   460  // uploaded certificate.
   461  // Parameters:
   462  // resourceGroupName - the name of the resource group that contains the IoT hub.
   463  // resourceName - the name of the IoT hub.
   464  // certificateName - the name of the certificate
   465  // certificateVerificationBody - the name of the certificate
   466  // ifMatch - eTag of the Certificate.
   467  func (client CertificatesClient) Verify(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, certificateVerificationBody CertificateVerificationDescription, ifMatch string) (result CertificateDescription, err error) {
   468  	if tracing.IsEnabled() {
   469  		ctx = tracing.StartSpan(ctx, fqdn+"/CertificatesClient.Verify")
   470  		defer func() {
   471  			sc := -1
   472  			if result.Response.Response != nil {
   473  				sc = result.Response.Response.StatusCode
   474  			}
   475  			tracing.EndSpan(ctx, sc, err)
   476  		}()
   477  	}
   478  	if err := validation.Validate([]validation.Validation{
   479  		{TargetValue: certificateName,
   480  			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.Pattern, Rule: `^[A-Za-z0-9-._]{1,64}$`, Chain: nil}}}}); err != nil {
   481  		return result, validation.NewError("devices.CertificatesClient", "Verify", err.Error())
   482  	}
   483  
   484  	req, err := client.VerifyPreparer(ctx, resourceGroupName, resourceName, certificateName, certificateVerificationBody, ifMatch)
   485  	if err != nil {
   486  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Verify", nil, "Failure preparing request")
   487  		return
   488  	}
   489  
   490  	resp, err := client.VerifySender(req)
   491  	if err != nil {
   492  		result.Response = autorest.Response{Response: resp}
   493  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Verify", resp, "Failure sending request")
   494  		return
   495  	}
   496  
   497  	result, err = client.VerifyResponder(resp)
   498  	if err != nil {
   499  		err = autorest.NewErrorWithError(err, "devices.CertificatesClient", "Verify", resp, "Failure responding to request")
   500  		return
   501  	}
   502  
   503  	return
   504  }
   505  
   506  // VerifyPreparer prepares the Verify request.
   507  func (client CertificatesClient) VerifyPreparer(ctx context.Context, resourceGroupName string, resourceName string, certificateName string, certificateVerificationBody CertificateVerificationDescription, ifMatch string) (*http.Request, error) {
   508  	pathParameters := map[string]interface{}{
   509  		"certificateName":   autorest.Encode("path", certificateName),
   510  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   511  		"resourceName":      autorest.Encode("path", resourceName),
   512  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   513  	}
   514  
   515  	const APIVersion = "2018-01-22"
   516  	queryParameters := map[string]interface{}{
   517  		"api-version": APIVersion,
   518  	}
   519  
   520  	preparer := autorest.CreatePreparer(
   521  		autorest.AsContentType("application/json; charset=utf-8"),
   522  		autorest.AsPost(),
   523  		autorest.WithBaseURL(client.BaseURI),
   524  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/certificates/{certificateName}/verify", pathParameters),
   525  		autorest.WithJSON(certificateVerificationBody),
   526  		autorest.WithQueryParameters(queryParameters),
   527  		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   528  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   529  }
   530  
   531  // VerifySender sends the Verify request. The method will close the
   532  // http.Response Body if it receives an error.
   533  func (client CertificatesClient) VerifySender(req *http.Request) (*http.Response, error) {
   534  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   535  }
   536  
   537  // VerifyResponder handles the response to the Verify request. The method always
   538  // closes the http.Response Body.
   539  func (client CertificatesClient) VerifyResponder(resp *http.Response) (result CertificateDescription, err error) {
   540  	err = autorest.Respond(
   541  		resp,
   542  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   543  		autorest.ByUnmarshallingJSON(&result),
   544  		autorest.ByClosing())
   545  	result.Response = autorest.Response{Response: resp}
   546  	return
   547  }
   548  

View as plain text