...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-11-15-preview/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  // RestorableMongodbCollectionsClient is the client for the RestorableMongodbCollections methods of the Documentdb
    19  // service.
    20  type RestorableMongodbCollectionsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewRestorableMongodbCollectionsClient creates an instance of the RestorableMongodbCollectionsClient client.
    25  func NewRestorableMongodbCollectionsClient(subscriptionID string) RestorableMongodbCollectionsClient {
    26  	return NewRestorableMongodbCollectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewRestorableMongodbCollectionsClientWithBaseURI creates an instance of the RestorableMongodbCollectionsClient
    30  // client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
    31  // (sovereign clouds, Azure stack).
    32  func NewRestorableMongodbCollectionsClientWithBaseURI(baseURI string, subscriptionID string) RestorableMongodbCollectionsClient {
    33  	return RestorableMongodbCollectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    34  }
    35  
    36  // List show the event feed of all mutations done on all the Azure Cosmos DB MongoDB collections under a specific
    37  // database.  This helps in scenario where container was accidentally deleted.  This API requires
    38  // 'Microsoft.DocumentDB/locations/restorableDatabaseAccounts/.../read' permission
    39  // Parameters:
    40  // location - cosmos DB region, with spaces between words and each word capitalized.
    41  // instanceID - the instanceId GUID of a restorable database account.
    42  // restorableMongodbDatabaseRid - the resource ID of the MongoDB database.
    43  // startTime - restorable MongoDB collections event feed start time.
    44  // endTime - restorable MongoDB collections event feed end time.
    45  func (client RestorableMongodbCollectionsClient) List(ctx context.Context, location string, instanceID string, restorableMongodbDatabaseRid string, startTime string, endTime string) (result RestorableMongodbCollectionsListResult, err error) {
    46  	if tracing.IsEnabled() {
    47  		ctx = tracing.StartSpan(ctx, fqdn+"/RestorableMongodbCollectionsClient.List")
    48  		defer func() {
    49  			sc := -1
    50  			if result.Response.Response != nil {
    51  				sc = result.Response.Response.StatusCode
    52  			}
    53  			tracing.EndSpan(ctx, sc, err)
    54  		}()
    55  	}
    56  	if err := validation.Validate([]validation.Validation{
    57  		{TargetValue: client.SubscriptionID,
    58  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    59  		return result, validation.NewError("documentdb.RestorableMongodbCollectionsClient", "List", err.Error())
    60  	}
    61  
    62  	req, err := client.ListPreparer(ctx, location, instanceID, restorableMongodbDatabaseRid, startTime, endTime)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbCollectionsClient", "List", nil, "Failure preparing request")
    65  		return
    66  	}
    67  
    68  	resp, err := client.ListSender(req)
    69  	if err != nil {
    70  		result.Response = autorest.Response{Response: resp}
    71  		err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbCollectionsClient", "List", resp, "Failure sending request")
    72  		return
    73  	}
    74  
    75  	result, err = client.ListResponder(resp)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbCollectionsClient", "List", resp, "Failure responding to request")
    78  		return
    79  	}
    80  
    81  	return
    82  }
    83  
    84  // ListPreparer prepares the List request.
    85  func (client RestorableMongodbCollectionsClient) ListPreparer(ctx context.Context, location string, instanceID string, restorableMongodbDatabaseRid string, startTime string, endTime string) (*http.Request, error) {
    86  	pathParameters := map[string]interface{}{
    87  		"instanceId":     autorest.Encode("path", instanceID),
    88  		"location":       autorest.Encode("path", location),
    89  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    90  	}
    91  
    92  	const APIVersion = "2021-11-15-preview"
    93  	queryParameters := map[string]interface{}{
    94  		"api-version": APIVersion,
    95  	}
    96  	if len(restorableMongodbDatabaseRid) > 0 {
    97  		queryParameters["restorableMongodbDatabaseRid"] = autorest.Encode("query", restorableMongodbDatabaseRid)
    98  	}
    99  	if len(startTime) > 0 {
   100  		queryParameters["startTime"] = autorest.Encode("query", startTime)
   101  	}
   102  	if len(endTime) > 0 {
   103  		queryParameters["endTime"] = autorest.Encode("query", endTime)
   104  	}
   105  
   106  	preparer := autorest.CreatePreparer(
   107  		autorest.AsGet(),
   108  		autorest.WithBaseURL(client.BaseURI),
   109  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{instanceId}/restorableMongodbCollections", pathParameters),
   110  		autorest.WithQueryParameters(queryParameters))
   111  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   112  }
   113  
   114  // ListSender sends the List request. The method will close the
   115  // http.Response Body if it receives an error.
   116  func (client RestorableMongodbCollectionsClient) ListSender(req *http.Request) (*http.Response, error) {
   117  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   118  }
   119  
   120  // ListResponder handles the response to the List request. The method always
   121  // closes the http.Response Body.
   122  func (client RestorableMongodbCollectionsClient) ListResponder(resp *http.Response) (result RestorableMongodbCollectionsListResult, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  

View as plain text