...

Source file src/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute/sshpublickeys.go

Documentation: github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute

     1  package compute
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // SSHPublicKeysClient is the compute Client
    18  type SSHPublicKeysClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewSSHPublicKeysClient creates an instance of the SSHPublicKeysClient client.
    23  func NewSSHPublicKeysClient(subscriptionID string) SSHPublicKeysClient {
    24  	return NewSSHPublicKeysClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewSSHPublicKeysClientWithBaseURI creates an instance of the SSHPublicKeysClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewSSHPublicKeysClientWithBaseURI(baseURI string, subscriptionID string) SSHPublicKeysClient {
    30  	return SSHPublicKeysClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Create creates a new SSH public key resource.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // SSHPublicKeyName - the name of the SSH public key.
    37  // parameters - parameters supplied to create the SSH public key.
    38  func (client SSHPublicKeysClient) Create(ctx context.Context, resourceGroupName string, SSHPublicKeyName string, parameters SSHPublicKeyResource) (result SSHPublicKeyResource, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.Create")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response.Response != nil {
    44  				sc = result.Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.CreatePreparer(ctx, resourceGroupName, SSHPublicKeyName, parameters)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Create", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.CreateSender(req)
    56  	if err != nil {
    57  		result.Response = autorest.Response{Response: resp}
    58  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Create", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.CreateResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Create", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // CreatePreparer prepares the Create request.
    72  func (client SSHPublicKeysClient) CreatePreparer(ctx context.Context, resourceGroupName string, SSHPublicKeyName string, parameters SSHPublicKeyResource) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    75  		"sshPublicKeyName":  autorest.Encode("path", SSHPublicKeyName),
    76  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    77  	}
    78  
    79  	const APIVersion = "2021-11-01"
    80  	queryParameters := map[string]interface{}{
    81  		"api-version": APIVersion,
    82  	}
    83  
    84  	preparer := autorest.CreatePreparer(
    85  		autorest.AsContentType("application/json; charset=utf-8"),
    86  		autorest.AsPut(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}", pathParameters),
    89  		autorest.WithJSON(parameters),
    90  		autorest.WithQueryParameters(queryParameters))
    91  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    92  }
    93  
    94  // CreateSender sends the Create request. The method will close the
    95  // http.Response Body if it receives an error.
    96  func (client SSHPublicKeysClient) CreateSender(req *http.Request) (*http.Response, error) {
    97  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    98  }
    99  
   100  // CreateResponder handles the response to the Create request. The method always
   101  // closes the http.Response Body.
   102  func (client SSHPublicKeysClient) CreateResponder(resp *http.Response) (result SSHPublicKeyResource, err error) {
   103  	err = autorest.Respond(
   104  		resp,
   105  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   106  		autorest.ByUnmarshallingJSON(&result),
   107  		autorest.ByClosing())
   108  	result.Response = autorest.Response{Response: resp}
   109  	return
   110  }
   111  
   112  // Delete delete an SSH public key.
   113  // Parameters:
   114  // resourceGroupName - the name of the resource group.
   115  // SSHPublicKeyName - the name of the SSH public key.
   116  func (client SSHPublicKeysClient) Delete(ctx context.Context, resourceGroupName string, SSHPublicKeyName string) (result autorest.Response, err error) {
   117  	if tracing.IsEnabled() {
   118  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.Delete")
   119  		defer func() {
   120  			sc := -1
   121  			if result.Response != nil {
   122  				sc = result.Response.StatusCode
   123  			}
   124  			tracing.EndSpan(ctx, sc, err)
   125  		}()
   126  	}
   127  	req, err := client.DeletePreparer(ctx, resourceGroupName, SSHPublicKeyName)
   128  	if err != nil {
   129  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Delete", nil, "Failure preparing request")
   130  		return
   131  	}
   132  
   133  	resp, err := client.DeleteSender(req)
   134  	if err != nil {
   135  		result.Response = resp
   136  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Delete", resp, "Failure sending request")
   137  		return
   138  	}
   139  
   140  	result, err = client.DeleteResponder(resp)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Delete", resp, "Failure responding to request")
   143  		return
   144  	}
   145  
   146  	return
   147  }
   148  
   149  // DeletePreparer prepares the Delete request.
   150  func (client SSHPublicKeysClient) DeletePreparer(ctx context.Context, resourceGroupName string, SSHPublicKeyName string) (*http.Request, error) {
   151  	pathParameters := map[string]interface{}{
   152  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   153  		"sshPublicKeyName":  autorest.Encode("path", SSHPublicKeyName),
   154  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   155  	}
   156  
   157  	const APIVersion = "2021-11-01"
   158  	queryParameters := map[string]interface{}{
   159  		"api-version": APIVersion,
   160  	}
   161  
   162  	preparer := autorest.CreatePreparer(
   163  		autorest.AsDelete(),
   164  		autorest.WithBaseURL(client.BaseURI),
   165  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}", pathParameters),
   166  		autorest.WithQueryParameters(queryParameters))
   167  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   168  }
   169  
   170  // DeleteSender sends the Delete request. The method will close the
   171  // http.Response Body if it receives an error.
   172  func (client SSHPublicKeysClient) DeleteSender(req *http.Request) (*http.Response, error) {
   173  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   174  }
   175  
   176  // DeleteResponder handles the response to the Delete request. The method always
   177  // closes the http.Response Body.
   178  func (client SSHPublicKeysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   179  	err = autorest.Respond(
   180  		resp,
   181  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   182  		autorest.ByClosing())
   183  	result.Response = resp
   184  	return
   185  }
   186  
   187  // GenerateKeyPair generates and returns a public/private key pair and populates the SSH public key resource with the
   188  // public key. The length of the key will be 3072 bits. This operation can only be performed once per SSH public key
   189  // resource.
   190  // Parameters:
   191  // resourceGroupName - the name of the resource group.
   192  // SSHPublicKeyName - the name of the SSH public key.
   193  func (client SSHPublicKeysClient) GenerateKeyPair(ctx context.Context, resourceGroupName string, SSHPublicKeyName string) (result SSHPublicKeyGenerateKeyPairResult, err error) {
   194  	if tracing.IsEnabled() {
   195  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.GenerateKeyPair")
   196  		defer func() {
   197  			sc := -1
   198  			if result.Response.Response != nil {
   199  				sc = result.Response.Response.StatusCode
   200  			}
   201  			tracing.EndSpan(ctx, sc, err)
   202  		}()
   203  	}
   204  	req, err := client.GenerateKeyPairPreparer(ctx, resourceGroupName, SSHPublicKeyName)
   205  	if err != nil {
   206  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "GenerateKeyPair", nil, "Failure preparing request")
   207  		return
   208  	}
   209  
   210  	resp, err := client.GenerateKeyPairSender(req)
   211  	if err != nil {
   212  		result.Response = autorest.Response{Response: resp}
   213  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "GenerateKeyPair", resp, "Failure sending request")
   214  		return
   215  	}
   216  
   217  	result, err = client.GenerateKeyPairResponder(resp)
   218  	if err != nil {
   219  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "GenerateKeyPair", resp, "Failure responding to request")
   220  		return
   221  	}
   222  
   223  	return
   224  }
   225  
   226  // GenerateKeyPairPreparer prepares the GenerateKeyPair request.
   227  func (client SSHPublicKeysClient) GenerateKeyPairPreparer(ctx context.Context, resourceGroupName string, SSHPublicKeyName string) (*http.Request, error) {
   228  	pathParameters := map[string]interface{}{
   229  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   230  		"sshPublicKeyName":  autorest.Encode("path", SSHPublicKeyName),
   231  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   232  	}
   233  
   234  	const APIVersion = "2021-11-01"
   235  	queryParameters := map[string]interface{}{
   236  		"api-version": APIVersion,
   237  	}
   238  
   239  	preparer := autorest.CreatePreparer(
   240  		autorest.AsPost(),
   241  		autorest.WithBaseURL(client.BaseURI),
   242  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}/generateKeyPair", pathParameters),
   243  		autorest.WithQueryParameters(queryParameters))
   244  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   245  }
   246  
   247  // GenerateKeyPairSender sends the GenerateKeyPair request. The method will close the
   248  // http.Response Body if it receives an error.
   249  func (client SSHPublicKeysClient) GenerateKeyPairSender(req *http.Request) (*http.Response, error) {
   250  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   251  }
   252  
   253  // GenerateKeyPairResponder handles the response to the GenerateKeyPair request. The method always
   254  // closes the http.Response Body.
   255  func (client SSHPublicKeysClient) GenerateKeyPairResponder(resp *http.Response) (result SSHPublicKeyGenerateKeyPairResult, err error) {
   256  	err = autorest.Respond(
   257  		resp,
   258  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   259  		autorest.ByUnmarshallingJSON(&result),
   260  		autorest.ByClosing())
   261  	result.Response = autorest.Response{Response: resp}
   262  	return
   263  }
   264  
   265  // Get retrieves information about an SSH public key.
   266  // Parameters:
   267  // resourceGroupName - the name of the resource group.
   268  // SSHPublicKeyName - the name of the SSH public key.
   269  func (client SSHPublicKeysClient) Get(ctx context.Context, resourceGroupName string, SSHPublicKeyName string) (result SSHPublicKeyResource, err error) {
   270  	if tracing.IsEnabled() {
   271  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.Get")
   272  		defer func() {
   273  			sc := -1
   274  			if result.Response.Response != nil {
   275  				sc = result.Response.Response.StatusCode
   276  			}
   277  			tracing.EndSpan(ctx, sc, err)
   278  		}()
   279  	}
   280  	req, err := client.GetPreparer(ctx, resourceGroupName, SSHPublicKeyName)
   281  	if err != nil {
   282  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Get", nil, "Failure preparing request")
   283  		return
   284  	}
   285  
   286  	resp, err := client.GetSender(req)
   287  	if err != nil {
   288  		result.Response = autorest.Response{Response: resp}
   289  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Get", resp, "Failure sending request")
   290  		return
   291  	}
   292  
   293  	result, err = client.GetResponder(resp)
   294  	if err != nil {
   295  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Get", resp, "Failure responding to request")
   296  		return
   297  	}
   298  
   299  	return
   300  }
   301  
   302  // GetPreparer prepares the Get request.
   303  func (client SSHPublicKeysClient) GetPreparer(ctx context.Context, resourceGroupName string, SSHPublicKeyName string) (*http.Request, error) {
   304  	pathParameters := map[string]interface{}{
   305  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   306  		"sshPublicKeyName":  autorest.Encode("path", SSHPublicKeyName),
   307  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   308  	}
   309  
   310  	const APIVersion = "2021-11-01"
   311  	queryParameters := map[string]interface{}{
   312  		"api-version": APIVersion,
   313  	}
   314  
   315  	preparer := autorest.CreatePreparer(
   316  		autorest.AsGet(),
   317  		autorest.WithBaseURL(client.BaseURI),
   318  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}", pathParameters),
   319  		autorest.WithQueryParameters(queryParameters))
   320  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   321  }
   322  
   323  // GetSender sends the Get request. The method will close the
   324  // http.Response Body if it receives an error.
   325  func (client SSHPublicKeysClient) GetSender(req *http.Request) (*http.Response, error) {
   326  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   327  }
   328  
   329  // GetResponder handles the response to the Get request. The method always
   330  // closes the http.Response Body.
   331  func (client SSHPublicKeysClient) GetResponder(resp *http.Response) (result SSHPublicKeyResource, err error) {
   332  	err = autorest.Respond(
   333  		resp,
   334  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   335  		autorest.ByUnmarshallingJSON(&result),
   336  		autorest.ByClosing())
   337  	result.Response = autorest.Response{Response: resp}
   338  	return
   339  }
   340  
   341  // ListByResourceGroup lists all of the SSH public keys in the specified resource group. Use the nextLink property in
   342  // the response to get the next page of SSH public keys.
   343  // Parameters:
   344  // resourceGroupName - the name of the resource group.
   345  func (client SSHPublicKeysClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result SSHPublicKeysGroupListResultPage, err error) {
   346  	if tracing.IsEnabled() {
   347  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.ListByResourceGroup")
   348  		defer func() {
   349  			sc := -1
   350  			if result.spkglr.Response.Response != nil {
   351  				sc = result.spkglr.Response.Response.StatusCode
   352  			}
   353  			tracing.EndSpan(ctx, sc, err)
   354  		}()
   355  	}
   356  	result.fn = client.listByResourceGroupNextResults
   357  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   358  	if err != nil {
   359  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "ListByResourceGroup", nil, "Failure preparing request")
   360  		return
   361  	}
   362  
   363  	resp, err := client.ListByResourceGroupSender(req)
   364  	if err != nil {
   365  		result.spkglr.Response = autorest.Response{Response: resp}
   366  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "ListByResourceGroup", resp, "Failure sending request")
   367  		return
   368  	}
   369  
   370  	result.spkglr, err = client.ListByResourceGroupResponder(resp)
   371  	if err != nil {
   372  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "ListByResourceGroup", resp, "Failure responding to request")
   373  		return
   374  	}
   375  	if result.spkglr.hasNextLink() && result.spkglr.IsEmpty() {
   376  		err = result.NextWithContext(ctx)
   377  		return
   378  	}
   379  
   380  	return
   381  }
   382  
   383  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   384  func (client SSHPublicKeysClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   385  	pathParameters := map[string]interface{}{
   386  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   387  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   388  	}
   389  
   390  	const APIVersion = "2021-11-01"
   391  	queryParameters := map[string]interface{}{
   392  		"api-version": APIVersion,
   393  	}
   394  
   395  	preparer := autorest.CreatePreparer(
   396  		autorest.AsGet(),
   397  		autorest.WithBaseURL(client.BaseURI),
   398  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys", pathParameters),
   399  		autorest.WithQueryParameters(queryParameters))
   400  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   401  }
   402  
   403  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   404  // http.Response Body if it receives an error.
   405  func (client SSHPublicKeysClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   406  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   407  }
   408  
   409  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   410  // closes the http.Response Body.
   411  func (client SSHPublicKeysClient) ListByResourceGroupResponder(resp *http.Response) (result SSHPublicKeysGroupListResult, err error) {
   412  	err = autorest.Respond(
   413  		resp,
   414  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   415  		autorest.ByUnmarshallingJSON(&result),
   416  		autorest.ByClosing())
   417  	result.Response = autorest.Response{Response: resp}
   418  	return
   419  }
   420  
   421  // listByResourceGroupNextResults retrieves the next set of results, if any.
   422  func (client SSHPublicKeysClient) listByResourceGroupNextResults(ctx context.Context, lastResults SSHPublicKeysGroupListResult) (result SSHPublicKeysGroupListResult, err error) {
   423  	req, err := lastResults.sSHPublicKeysGroupListResultPreparer(ctx)
   424  	if err != nil {
   425  		return result, autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   426  	}
   427  	if req == nil {
   428  		return
   429  	}
   430  	resp, err := client.ListByResourceGroupSender(req)
   431  	if err != nil {
   432  		result.Response = autorest.Response{Response: resp}
   433  		return result, autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   434  	}
   435  	result, err = client.ListByResourceGroupResponder(resp)
   436  	if err != nil {
   437  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   438  	}
   439  	return
   440  }
   441  
   442  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   443  func (client SSHPublicKeysClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result SSHPublicKeysGroupListResultIterator, err error) {
   444  	if tracing.IsEnabled() {
   445  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.ListByResourceGroup")
   446  		defer func() {
   447  			sc := -1
   448  			if result.Response().Response.Response != nil {
   449  				sc = result.page.Response().Response.Response.StatusCode
   450  			}
   451  			tracing.EndSpan(ctx, sc, err)
   452  		}()
   453  	}
   454  	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
   455  	return
   456  }
   457  
   458  // ListBySubscription lists all of the SSH public keys in the subscription. Use the nextLink property in the response
   459  // to get the next page of SSH public keys.
   460  func (client SSHPublicKeysClient) ListBySubscription(ctx context.Context) (result SSHPublicKeysGroupListResultPage, err error) {
   461  	if tracing.IsEnabled() {
   462  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.ListBySubscription")
   463  		defer func() {
   464  			sc := -1
   465  			if result.spkglr.Response.Response != nil {
   466  				sc = result.spkglr.Response.Response.StatusCode
   467  			}
   468  			tracing.EndSpan(ctx, sc, err)
   469  		}()
   470  	}
   471  	result.fn = client.listBySubscriptionNextResults
   472  	req, err := client.ListBySubscriptionPreparer(ctx)
   473  	if err != nil {
   474  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "ListBySubscription", nil, "Failure preparing request")
   475  		return
   476  	}
   477  
   478  	resp, err := client.ListBySubscriptionSender(req)
   479  	if err != nil {
   480  		result.spkglr.Response = autorest.Response{Response: resp}
   481  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "ListBySubscription", resp, "Failure sending request")
   482  		return
   483  	}
   484  
   485  	result.spkglr, err = client.ListBySubscriptionResponder(resp)
   486  	if err != nil {
   487  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "ListBySubscription", resp, "Failure responding to request")
   488  		return
   489  	}
   490  	if result.spkglr.hasNextLink() && result.spkglr.IsEmpty() {
   491  		err = result.NextWithContext(ctx)
   492  		return
   493  	}
   494  
   495  	return
   496  }
   497  
   498  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   499  func (client SSHPublicKeysClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
   500  	pathParameters := map[string]interface{}{
   501  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   502  	}
   503  
   504  	const APIVersion = "2021-11-01"
   505  	queryParameters := map[string]interface{}{
   506  		"api-version": APIVersion,
   507  	}
   508  
   509  	preparer := autorest.CreatePreparer(
   510  		autorest.AsGet(),
   511  		autorest.WithBaseURL(client.BaseURI),
   512  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/sshPublicKeys", pathParameters),
   513  		autorest.WithQueryParameters(queryParameters))
   514  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   515  }
   516  
   517  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   518  // http.Response Body if it receives an error.
   519  func (client SSHPublicKeysClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   520  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   521  }
   522  
   523  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   524  // closes the http.Response Body.
   525  func (client SSHPublicKeysClient) ListBySubscriptionResponder(resp *http.Response) (result SSHPublicKeysGroupListResult, 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  // listBySubscriptionNextResults retrieves the next set of results, if any.
   536  func (client SSHPublicKeysClient) listBySubscriptionNextResults(ctx context.Context, lastResults SSHPublicKeysGroupListResult) (result SSHPublicKeysGroupListResult, err error) {
   537  	req, err := lastResults.sSHPublicKeysGroupListResultPreparer(ctx)
   538  	if err != nil {
   539  		return result, autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
   540  	}
   541  	if req == nil {
   542  		return
   543  	}
   544  	resp, err := client.ListBySubscriptionSender(req)
   545  	if err != nil {
   546  		result.Response = autorest.Response{Response: resp}
   547  		return result, autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
   548  	}
   549  	result, err = client.ListBySubscriptionResponder(resp)
   550  	if err != nil {
   551  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
   552  	}
   553  	return
   554  }
   555  
   556  // ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
   557  func (client SSHPublicKeysClient) ListBySubscriptionComplete(ctx context.Context) (result SSHPublicKeysGroupListResultIterator, err error) {
   558  	if tracing.IsEnabled() {
   559  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.ListBySubscription")
   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.ListBySubscription(ctx)
   569  	return
   570  }
   571  
   572  // Update updates a new SSH public key resource.
   573  // Parameters:
   574  // resourceGroupName - the name of the resource group.
   575  // SSHPublicKeyName - the name of the SSH public key.
   576  // parameters - parameters supplied to update the SSH public key.
   577  func (client SSHPublicKeysClient) Update(ctx context.Context, resourceGroupName string, SSHPublicKeyName string, parameters SSHPublicKeyUpdateResource) (result SSHPublicKeyResource, err error) {
   578  	if tracing.IsEnabled() {
   579  		ctx = tracing.StartSpan(ctx, fqdn+"/SSHPublicKeysClient.Update")
   580  		defer func() {
   581  			sc := -1
   582  			if result.Response.Response != nil {
   583  				sc = result.Response.Response.StatusCode
   584  			}
   585  			tracing.EndSpan(ctx, sc, err)
   586  		}()
   587  	}
   588  	req, err := client.UpdatePreparer(ctx, resourceGroupName, SSHPublicKeyName, parameters)
   589  	if err != nil {
   590  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Update", nil, "Failure preparing request")
   591  		return
   592  	}
   593  
   594  	resp, err := client.UpdateSender(req)
   595  	if err != nil {
   596  		result.Response = autorest.Response{Response: resp}
   597  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Update", resp, "Failure sending request")
   598  		return
   599  	}
   600  
   601  	result, err = client.UpdateResponder(resp)
   602  	if err != nil {
   603  		err = autorest.NewErrorWithError(err, "compute.SSHPublicKeysClient", "Update", resp, "Failure responding to request")
   604  		return
   605  	}
   606  
   607  	return
   608  }
   609  
   610  // UpdatePreparer prepares the Update request.
   611  func (client SSHPublicKeysClient) UpdatePreparer(ctx context.Context, resourceGroupName string, SSHPublicKeyName string, parameters SSHPublicKeyUpdateResource) (*http.Request, error) {
   612  	pathParameters := map[string]interface{}{
   613  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   614  		"sshPublicKeyName":  autorest.Encode("path", SSHPublicKeyName),
   615  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   616  	}
   617  
   618  	const APIVersion = "2021-11-01"
   619  	queryParameters := map[string]interface{}{
   620  		"api-version": APIVersion,
   621  	}
   622  
   623  	preparer := autorest.CreatePreparer(
   624  		autorest.AsContentType("application/json; charset=utf-8"),
   625  		autorest.AsPatch(),
   626  		autorest.WithBaseURL(client.BaseURI),
   627  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}", pathParameters),
   628  		autorest.WithJSON(parameters),
   629  		autorest.WithQueryParameters(queryParameters))
   630  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   631  }
   632  
   633  // UpdateSender sends the Update request. The method will close the
   634  // http.Response Body if it receives an error.
   635  func (client SSHPublicKeysClient) UpdateSender(req *http.Request) (*http.Response, error) {
   636  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   637  }
   638  
   639  // UpdateResponder handles the response to the Update request. The method always
   640  // closes the http.Response Body.
   641  func (client SSHPublicKeysClient) UpdateResponder(resp *http.Response) (result SSHPublicKeyResource, err error) {
   642  	err = autorest.Respond(
   643  		resp,
   644  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   645  		autorest.ByUnmarshallingJSON(&result),
   646  		autorest.ByClosing())
   647  	result.Response = autorest.Response{Response: resp}
   648  	return
   649  }
   650  

View as plain text