...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-07-01/backup/recoverypoints.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-07-01/backup

     1  package backup
     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  // RecoveryPointsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type RecoveryPointsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewRecoveryPointsClient creates an instance of the RecoveryPointsClient client.
    23  func NewRecoveryPointsClient(subscriptionID string) RecoveryPointsClient {
    24  	return NewRecoveryPointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewRecoveryPointsClientWithBaseURI creates an instance of the RecoveryPointsClient 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 NewRecoveryPointsClientWithBaseURI(baseURI string, subscriptionID string) RecoveryPointsClient {
    30  	return RecoveryPointsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Get provides the information of the backed up data identified using RecoveryPointID. This is an asynchronous
    34  // operation.
    35  // To know the status of the operation, call the GetProtectedItemOperationResult API.
    36  // Parameters:
    37  // vaultName - the name of the recovery services vault.
    38  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    39  // fabricName - fabric name associated with backed up item.
    40  // containerName - container name associated with backed up item.
    41  // protectedItemName - backed up item name whose backup data needs to be fetched.
    42  // recoveryPointID - recoveryPointID represents the backed up data to be fetched.
    43  func (client RecoveryPointsClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (result RecoveryPointResource, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.Get")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response.Response != nil {
    49  				sc = result.Response.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", nil, "Failure preparing request")
    57  		return
    58  	}
    59  
    60  	resp, err := client.GetSender(req)
    61  	if err != nil {
    62  		result.Response = autorest.Response{Response: resp}
    63  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", resp, "Failure sending request")
    64  		return
    65  	}
    66  
    67  	result, err = client.GetResponder(resp)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", resp, "Failure responding to request")
    70  		return
    71  	}
    72  
    73  	return
    74  }
    75  
    76  // GetPreparer prepares the Get request.
    77  func (client RecoveryPointsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (*http.Request, error) {
    78  	pathParameters := map[string]interface{}{
    79  		"containerName":     autorest.Encode("path", containerName),
    80  		"fabricName":        autorest.Encode("path", fabricName),
    81  		"protectedItemName": autorest.Encode("path", protectedItemName),
    82  		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
    83  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    84  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    85  		"vaultName":         autorest.Encode("path", vaultName),
    86  	}
    87  
    88  	const APIVersion = "2021-07-01"
    89  	queryParameters := map[string]interface{}{
    90  		"api-version": APIVersion,
    91  	}
    92  
    93  	preparer := autorest.CreatePreparer(
    94  		autorest.AsGet(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}", pathParameters),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // GetSender sends the Get request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client RecoveryPointsClient) GetSender(req *http.Request) (*http.Response, error) {
   104  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   105  }
   106  
   107  // GetResponder handles the response to the Get request. The method always
   108  // closes the http.Response Body.
   109  func (client RecoveryPointsClient) GetResponder(resp *http.Response) (result RecoveryPointResource, err error) {
   110  	err = autorest.Respond(
   111  		resp,
   112  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   113  		autorest.ByUnmarshallingJSON(&result),
   114  		autorest.ByClosing())
   115  	result.Response = autorest.Response{Response: resp}
   116  	return
   117  }
   118  
   119  // GetAccessToken sends the get access token request.
   120  // Parameters:
   121  // vaultName - the name of the recovery services vault.
   122  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   123  // fabricName - fabric name associated with the container.
   124  // containerName - name of the container.
   125  // protectedItemName - name of the Protected Item.
   126  // recoveryPointID - recovery Point Id
   127  // parameters - get Access Token request
   128  func (client RecoveryPointsClient) GetAccessToken(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string, parameters AADPropertiesResource) (result CrrAccessTokenResource, err error) {
   129  	if tracing.IsEnabled() {
   130  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.GetAccessToken")
   131  		defer func() {
   132  			sc := -1
   133  			if result.Response.Response != nil {
   134  				sc = result.Response.Response.StatusCode
   135  			}
   136  			tracing.EndSpan(ctx, sc, err)
   137  		}()
   138  	}
   139  	req, err := client.GetAccessTokenPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID, parameters)
   140  	if err != nil {
   141  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "GetAccessToken", nil, "Failure preparing request")
   142  		return
   143  	}
   144  
   145  	resp, err := client.GetAccessTokenSender(req)
   146  	if err != nil {
   147  		result.Response = autorest.Response{Response: resp}
   148  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "GetAccessToken", resp, "Failure sending request")
   149  		return
   150  	}
   151  
   152  	result, err = client.GetAccessTokenResponder(resp)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "GetAccessToken", resp, "Failure responding to request")
   155  		return
   156  	}
   157  
   158  	return
   159  }
   160  
   161  // GetAccessTokenPreparer prepares the GetAccessToken request.
   162  func (client RecoveryPointsClient) GetAccessTokenPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string, parameters AADPropertiesResource) (*http.Request, error) {
   163  	pathParameters := map[string]interface{}{
   164  		"containerName":     autorest.Encode("path", containerName),
   165  		"fabricName":        autorest.Encode("path", fabricName),
   166  		"protectedItemName": autorest.Encode("path", protectedItemName),
   167  		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
   168  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   169  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   170  		"vaultName":         autorest.Encode("path", vaultName),
   171  	}
   172  
   173  	const APIVersion = "2018-12-20"
   174  	queryParameters := map[string]interface{}{
   175  		"api-version": APIVersion,
   176  	}
   177  
   178  	preparer := autorest.CreatePreparer(
   179  		autorest.AsContentType("application/json; charset=utf-8"),
   180  		autorest.AsPost(),
   181  		autorest.WithBaseURL(client.BaseURI),
   182  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/accessToken", pathParameters),
   183  		autorest.WithJSON(parameters),
   184  		autorest.WithQueryParameters(queryParameters))
   185  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   186  }
   187  
   188  // GetAccessTokenSender sends the GetAccessToken request. The method will close the
   189  // http.Response Body if it receives an error.
   190  func (client RecoveryPointsClient) GetAccessTokenSender(req *http.Request) (*http.Response, error) {
   191  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   192  }
   193  
   194  // GetAccessTokenResponder handles the response to the GetAccessToken request. The method always
   195  // closes the http.Response Body.
   196  func (client RecoveryPointsClient) GetAccessTokenResponder(resp *http.Response) (result CrrAccessTokenResource, err error) {
   197  	err = autorest.Respond(
   198  		resp,
   199  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusBadRequest),
   200  		autorest.ByUnmarshallingJSON(&result),
   201  		autorest.ByClosing())
   202  	result.Response = autorest.Response{Response: resp}
   203  	return
   204  }
   205  
   206  // List lists the backup copies for the backed up item.
   207  // Parameters:
   208  // vaultName - the name of the recovery services vault.
   209  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   210  // fabricName - fabric name associated with the backed up item.
   211  // containerName - container name associated with the backed up item.
   212  // protectedItemName - backed up item whose backup copies are to be fetched.
   213  // filter - oData filter options.
   214  func (client RecoveryPointsClient) List(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result RecoveryPointResourceListPage, err error) {
   215  	if tracing.IsEnabled() {
   216  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.List")
   217  		defer func() {
   218  			sc := -1
   219  			if result.rprl.Response.Response != nil {
   220  				sc = result.rprl.Response.Response.StatusCode
   221  			}
   222  			tracing.EndSpan(ctx, sc, err)
   223  		}()
   224  	}
   225  	result.fn = client.listNextResults
   226  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", nil, "Failure preparing request")
   229  		return
   230  	}
   231  
   232  	resp, err := client.ListSender(req)
   233  	if err != nil {
   234  		result.rprl.Response = autorest.Response{Response: resp}
   235  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", resp, "Failure sending request")
   236  		return
   237  	}
   238  
   239  	result.rprl, err = client.ListResponder(resp)
   240  	if err != nil {
   241  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", resp, "Failure responding to request")
   242  		return
   243  	}
   244  	if result.rprl.hasNextLink() && result.rprl.IsEmpty() {
   245  		err = result.NextWithContext(ctx)
   246  		return
   247  	}
   248  
   249  	return
   250  }
   251  
   252  // ListPreparer prepares the List request.
   253  func (client RecoveryPointsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (*http.Request, error) {
   254  	pathParameters := map[string]interface{}{
   255  		"containerName":     autorest.Encode("path", containerName),
   256  		"fabricName":        autorest.Encode("path", fabricName),
   257  		"protectedItemName": autorest.Encode("path", protectedItemName),
   258  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   259  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   260  		"vaultName":         autorest.Encode("path", vaultName),
   261  	}
   262  
   263  	const APIVersion = "2021-07-01"
   264  	queryParameters := map[string]interface{}{
   265  		"api-version": APIVersion,
   266  	}
   267  	if len(filter) > 0 {
   268  		queryParameters["$filter"] = autorest.Encode("query", filter)
   269  	}
   270  
   271  	preparer := autorest.CreatePreparer(
   272  		autorest.AsGet(),
   273  		autorest.WithBaseURL(client.BaseURI),
   274  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints", pathParameters),
   275  		autorest.WithQueryParameters(queryParameters))
   276  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   277  }
   278  
   279  // ListSender sends the List request. The method will close the
   280  // http.Response Body if it receives an error.
   281  func (client RecoveryPointsClient) ListSender(req *http.Request) (*http.Response, error) {
   282  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   283  }
   284  
   285  // ListResponder handles the response to the List request. The method always
   286  // closes the http.Response Body.
   287  func (client RecoveryPointsClient) ListResponder(resp *http.Response) (result RecoveryPointResourceList, err error) {
   288  	err = autorest.Respond(
   289  		resp,
   290  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   291  		autorest.ByUnmarshallingJSON(&result),
   292  		autorest.ByClosing())
   293  	result.Response = autorest.Response{Response: resp}
   294  	return
   295  }
   296  
   297  // listNextResults retrieves the next set of results, if any.
   298  func (client RecoveryPointsClient) listNextResults(ctx context.Context, lastResults RecoveryPointResourceList) (result RecoveryPointResourceList, err error) {
   299  	req, err := lastResults.recoveryPointResourceListPreparer(ctx)
   300  	if err != nil {
   301  		return result, autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", nil, "Failure preparing next results request")
   302  	}
   303  	if req == nil {
   304  		return
   305  	}
   306  	resp, err := client.ListSender(req)
   307  	if err != nil {
   308  		result.Response = autorest.Response{Response: resp}
   309  		return result, autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", resp, "Failure sending next results request")
   310  	}
   311  	result, err = client.ListResponder(resp)
   312  	if err != nil {
   313  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", resp, "Failure responding to next results request")
   314  	}
   315  	return
   316  }
   317  
   318  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   319  func (client RecoveryPointsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result RecoveryPointResourceListIterator, err error) {
   320  	if tracing.IsEnabled() {
   321  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.List")
   322  		defer func() {
   323  			sc := -1
   324  			if result.Response().Response.Response != nil {
   325  				sc = result.page.Response().Response.Response.StatusCode
   326  			}
   327  			tracing.EndSpan(ctx, sc, err)
   328  		}()
   329  	}
   330  	result.page, err = client.List(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
   331  	return
   332  }
   333  

View as plain text