...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb/restorablemongodbdatabases.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  // RestorableMongodbDatabasesClient is the client for the RestorableMongodbDatabases methods of the Documentdb service.
    19  type RestorableMongodbDatabasesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewRestorableMongodbDatabasesClient creates an instance of the RestorableMongodbDatabasesClient client.
    24  func NewRestorableMongodbDatabasesClient(subscriptionID string) RestorableMongodbDatabasesClient {
    25  	return NewRestorableMongodbDatabasesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewRestorableMongodbDatabasesClientWithBaseURI creates an instance of the RestorableMongodbDatabasesClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewRestorableMongodbDatabasesClientWithBaseURI(baseURI string, subscriptionID string) RestorableMongodbDatabasesClient {
    32  	return RestorableMongodbDatabasesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // List show the event feed of all mutations done on all the Azure Cosmos DB MongoDB databases under the restorable
    36  // account.  This helps in scenario where database was accidentally deleted to get the deletion time.  This API
    37  // requires  '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  func (client RestorableMongodbDatabasesClient) List(ctx context.Context, location string, instanceID string) (result RestorableMongodbDatabasesListResult, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/RestorableMongodbDatabasesClient.List")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: client.SubscriptionID,
    54  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    55  		return result, validation.NewError("documentdb.RestorableMongodbDatabasesClient", "List", err.Error())
    56  	}
    57  
    58  	req, err := client.ListPreparer(ctx, location, instanceID)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbDatabasesClient", "List", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	resp, err := client.ListSender(req)
    65  	if err != nil {
    66  		result.Response = autorest.Response{Response: resp}
    67  		err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbDatabasesClient", "List", resp, "Failure sending request")
    68  		return
    69  	}
    70  
    71  	result, err = client.ListResponder(resp)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbDatabasesClient", "List", resp, "Failure responding to request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // ListPreparer prepares the List request.
    81  func (client RestorableMongodbDatabasesClient) ListPreparer(ctx context.Context, location string, instanceID string) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"instanceId":     autorest.Encode("path", instanceID),
    84  		"location":       autorest.Encode("path", location),
    85  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    86  	}
    87  
    88  	const APIVersion = "2021-10-15"
    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}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{instanceId}/restorableMongodbDatabases", pathParameters),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // ListSender sends the List request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client RestorableMongodbDatabasesClient) ListSender(req *http.Request) (*http.Response, error) {
   104  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   105  }
   106  
   107  // ListResponder handles the response to the List request. The method always
   108  // closes the http.Response Body.
   109  func (client RestorableMongodbDatabasesClient) ListResponder(resp *http.Response) (result RestorableMongodbDatabasesListResult, 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  

View as plain text