1package 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 9import ( 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. 19type RestorableMongodbDatabasesClient struct { 20 BaseClient 21} 22 23// NewRestorableMongodbDatabasesClient creates an instance of the RestorableMongodbDatabasesClient client. 24func 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). 31func NewRestorableMongodbDatabasesClientWithBaseURI(baseURI string, subscriptionID string) RestorableMongodbDatabasesClient { 32 return RestorableMongodbDatabasesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// List lists all the restorable Azure Cosmos DB MongoDB databases available under the restorable account. 36// Parameters: 37// location - cosmos DB region, with spaces between words and each word capitalized. 38// instanceID - the instanceId GUID of a restorable database account. 39func (client RestorableMongodbDatabasesClient) List(ctx context.Context, location string, instanceID string) (result RestorableMongodbDatabasesListResult, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableMongodbDatabasesClient.List") 42 defer func() { 43 sc := -1 44 if result.Response.Response != nil { 45 sc = result.Response.Response.StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: client.SubscriptionID, 52 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 53 return result, validation.NewError("documentdb.RestorableMongodbDatabasesClient", "List", err.Error()) 54 } 55 56 req, err := client.ListPreparer(ctx, location, instanceID) 57 if err != nil { 58 err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbDatabasesClient", "List", nil, "Failure preparing request") 59 return 60 } 61 62 resp, err := client.ListSender(req) 63 if err != nil { 64 result.Response = autorest.Response{Response: resp} 65 err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbDatabasesClient", "List", resp, "Failure sending request") 66 return 67 } 68 69 result, err = client.ListResponder(resp) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "documentdb.RestorableMongodbDatabasesClient", "List", resp, "Failure responding to request") 72 return 73 } 74 75 return 76} 77 78// ListPreparer prepares the List request. 79func (client RestorableMongodbDatabasesClient) ListPreparer(ctx context.Context, location string, instanceID string) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "instanceId": autorest.Encode("path", instanceID), 82 "location": autorest.Encode("path", location), 83 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 84 } 85 86 const APIVersion = "2020-06-01-preview" 87 queryParameters := map[string]interface{}{ 88 "api-version": APIVersion, 89 } 90 91 preparer := autorest.CreatePreparer( 92 autorest.AsGet(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{instanceId}/restorableMongodbDatabases", pathParameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// ListSender sends the List request. The method will close the 100// http.Response Body if it receives an error. 101func (client RestorableMongodbDatabasesClient) ListSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103} 104 105// ListResponder handles the response to the List request. The method always 106// closes the http.Response Body. 107func (client RestorableMongodbDatabasesClient) ListResponder(resp *http.Response) (result RestorableMongodbDatabasesListResult, err error) { 108 err = autorest.Respond( 109 resp, 110 azure.WithErrorUnlessStatusCode(http.StatusOK), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116