...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb/restorablesqlresources.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb

     1  package documentdb
     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  // RestorableSQLResourcesClient is the client for the RestorableSQLResources methods of the Documentdb service.
    19  type RestorableSQLResourcesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewRestorableSQLResourcesClient creates an instance of the RestorableSQLResourcesClient client.
    24  func NewRestorableSQLResourcesClient(subscriptionID string) RestorableSQLResourcesClient {
    25  	return NewRestorableSQLResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewRestorableSQLResourcesClientWithBaseURI creates an instance of the RestorableSQLResourcesClient client using a
    29  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    30  // Azure stack).
    31  func NewRestorableSQLResourcesClientWithBaseURI(baseURI string, subscriptionID string) RestorableSQLResourcesClient {
    32  	return RestorableSQLResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // List return a list of database and container combo that exist on the account at the given timestamp and location.
    36  // This helps in scenarios to validate what resources exist at given timestamp and location. This API requires
    37  // 'Microsoft.DocumentDB/locations/restorableDatabaseAccounts/.../read' permission.
    38  // Parameters:
    39  // location - cosmos DB region, with spaces between words and each word capitalized.
    40  // instanceID - the instanceId GUID of a restorable database account.
    41  // restoreLocation - the location where the restorable resources are located.
    42  // restoreTimestampInUtc - the timestamp when the restorable resources existed.
    43  func (client RestorableSQLResourcesClient) List(ctx context.Context, location string, instanceID string, restoreLocation string, restoreTimestampInUtc string) (result RestorableSQLResourcesListResult, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/RestorableSQLResourcesClient.List")
    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  	if err := validation.Validate([]validation.Validation{
    55  		{TargetValue: client.SubscriptionID,
    56  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    57  		return result, validation.NewError("documentdb.RestorableSQLResourcesClient", "List", err.Error())
    58  	}
    59  
    60  	req, err := client.ListPreparer(ctx, location, instanceID, restoreLocation, restoreTimestampInUtc)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "documentdb.RestorableSQLResourcesClient", "List", nil, "Failure preparing request")
    63  		return
    64  	}
    65  
    66  	resp, err := client.ListSender(req)
    67  	if err != nil {
    68  		result.Response = autorest.Response{Response: resp}
    69  		err = autorest.NewErrorWithError(err, "documentdb.RestorableSQLResourcesClient", "List", resp, "Failure sending request")
    70  		return
    71  	}
    72  
    73  	result, err = client.ListResponder(resp)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "documentdb.RestorableSQLResourcesClient", "List", resp, "Failure responding to request")
    76  		return
    77  	}
    78  
    79  	return
    80  }
    81  
    82  // ListPreparer prepares the List request.
    83  func (client RestorableSQLResourcesClient) ListPreparer(ctx context.Context, location string, instanceID string, restoreLocation string, restoreTimestampInUtc string) (*http.Request, error) {
    84  	pathParameters := map[string]interface{}{
    85  		"instanceId":     autorest.Encode("path", instanceID),
    86  		"location":       autorest.Encode("path", location),
    87  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    88  	}
    89  
    90  	const APIVersion = "2021-10-15"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  	if len(restoreLocation) > 0 {
    95  		queryParameters["restoreLocation"] = autorest.Encode("query", restoreLocation)
    96  	}
    97  	if len(restoreTimestampInUtc) > 0 {
    98  		queryParameters["restoreTimestampInUtc"] = autorest.Encode("query", restoreTimestampInUtc)
    99  	}
   100  
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsGet(),
   103  		autorest.WithBaseURL(client.BaseURI),
   104  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{instanceId}/restorableSqlResources", pathParameters),
   105  		autorest.WithQueryParameters(queryParameters))
   106  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   107  }
   108  
   109  // ListSender sends the List request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client RestorableSQLResourcesClient) ListSender(req *http.Request) (*http.Response, error) {
   112  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   113  }
   114  
   115  // ListResponder handles the response to the List request. The method always
   116  // closes the http.Response Body.
   117  func (client RestorableSQLResourcesClient) ListResponder(resp *http.Response) (result RestorableSQLResourcesListResult, err error) {
   118  	err = autorest.Respond(
   119  		resp,
   120  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   121  		autorest.ByUnmarshallingJSON(&result),
   122  		autorest.ByClosing())
   123  	result.Response = autorest.Response{Response: resp}
   124  	return
   125  }
   126  

View as plain text