...

Source file src/github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2021-07-02/devices/certificates.go

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

View as plain text