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// RestorableDatabaseAccountsClient is the client for the RestorableDatabaseAccounts methods of the Documentdb service. 19type RestorableDatabaseAccountsClient struct { 20 BaseClient 21} 22 23// NewRestorableDatabaseAccountsClient creates an instance of the RestorableDatabaseAccountsClient client. 24func NewRestorableDatabaseAccountsClient(subscriptionID string) RestorableDatabaseAccountsClient { 25 return NewRestorableDatabaseAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewRestorableDatabaseAccountsClientWithBaseURI creates an instance of the RestorableDatabaseAccountsClient 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 NewRestorableDatabaseAccountsClientWithBaseURI(baseURI string, subscriptionID string) RestorableDatabaseAccountsClient { 32 return RestorableDatabaseAccountsClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// GetByLocation retrieves the properties of an existing Azure Cosmos DB restorable database 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 RestorableDatabaseAccountsClient) GetByLocation(ctx context.Context, location string, instanceID string) (result RestorableDatabaseAccountGetResult, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDatabaseAccountsClient.GetByLocation") 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.RestorableDatabaseAccountsClient", "GetByLocation", err.Error()) 54 } 55 56 req, err := client.GetByLocationPreparer(ctx, location, instanceID) 57 if err != nil { 58 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "GetByLocation", nil, "Failure preparing request") 59 return 60 } 61 62 resp, err := client.GetByLocationSender(req) 63 if err != nil { 64 result.Response = autorest.Response{Response: resp} 65 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "GetByLocation", resp, "Failure sending request") 66 return 67 } 68 69 result, err = client.GetByLocationResponder(resp) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "GetByLocation", resp, "Failure responding to request") 72 return 73 } 74 75 return 76} 77 78// GetByLocationPreparer prepares the GetByLocation request. 79func (client RestorableDatabaseAccountsClient) GetByLocationPreparer(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}", pathParameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// GetByLocationSender sends the GetByLocation request. The method will close the 100// http.Response Body if it receives an error. 101func (client RestorableDatabaseAccountsClient) GetByLocationSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103} 104 105// GetByLocationResponder handles the response to the GetByLocation request. The method always 106// closes the http.Response Body. 107func (client RestorableDatabaseAccountsClient) GetByLocationResponder(resp *http.Response) (result RestorableDatabaseAccountGetResult, 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 117// List lists all the restorable Azure Cosmos DB database accounts available under the subscription. 118func (client RestorableDatabaseAccountsClient) List(ctx context.Context) (result RestorableDatabaseAccountsListResult, err error) { 119 if tracing.IsEnabled() { 120 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDatabaseAccountsClient.List") 121 defer func() { 122 sc := -1 123 if result.Response.Response != nil { 124 sc = result.Response.Response.StatusCode 125 } 126 tracing.EndSpan(ctx, sc, err) 127 }() 128 } 129 if err := validation.Validate([]validation.Validation{ 130 {TargetValue: client.SubscriptionID, 131 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 132 return result, validation.NewError("documentdb.RestorableDatabaseAccountsClient", "List", err.Error()) 133 } 134 135 req, err := client.ListPreparer(ctx) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "List", nil, "Failure preparing request") 138 return 139 } 140 141 resp, err := client.ListSender(req) 142 if err != nil { 143 result.Response = autorest.Response{Response: resp} 144 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "List", resp, "Failure sending request") 145 return 146 } 147 148 result, err = client.ListResponder(resp) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "List", resp, "Failure responding to request") 151 return 152 } 153 154 return 155} 156 157// ListPreparer prepares the List request. 158func (client RestorableDatabaseAccountsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 159 pathParameters := map[string]interface{}{ 160 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 161 } 162 163 const APIVersion = "2020-06-01-preview" 164 queryParameters := map[string]interface{}{ 165 "api-version": APIVersion, 166 } 167 168 preparer := autorest.CreatePreparer( 169 autorest.AsGet(), 170 autorest.WithBaseURL(client.BaseURI), 171 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/restorableDatabaseAccounts", pathParameters), 172 autorest.WithQueryParameters(queryParameters)) 173 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 174} 175 176// ListSender sends the List request. The method will close the 177// http.Response Body if it receives an error. 178func (client RestorableDatabaseAccountsClient) ListSender(req *http.Request) (*http.Response, error) { 179 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 180} 181 182// ListResponder handles the response to the List request. The method always 183// closes the http.Response Body. 184func (client RestorableDatabaseAccountsClient) ListResponder(resp *http.Response) (result RestorableDatabaseAccountsListResult, err error) { 185 err = autorest.Respond( 186 resp, 187 azure.WithErrorUnlessStatusCode(http.StatusOK), 188 autorest.ByUnmarshallingJSON(&result), 189 autorest.ByClosing()) 190 result.Response = autorest.Response{Response: resp} 191 return 192} 193 194// ListByLocation lists all the restorable Azure Cosmos DB database accounts available under the subscription and in a 195// region. 196// Parameters: 197// location - cosmos DB region, with spaces between words and each word capitalized. 198func (client RestorableDatabaseAccountsClient) ListByLocation(ctx context.Context, location string) (result RestorableDatabaseAccountsListResult, err error) { 199 if tracing.IsEnabled() { 200 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDatabaseAccountsClient.ListByLocation") 201 defer func() { 202 sc := -1 203 if result.Response.Response != nil { 204 sc = result.Response.Response.StatusCode 205 } 206 tracing.EndSpan(ctx, sc, err) 207 }() 208 } 209 if err := validation.Validate([]validation.Validation{ 210 {TargetValue: client.SubscriptionID, 211 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 212 return result, validation.NewError("documentdb.RestorableDatabaseAccountsClient", "ListByLocation", err.Error()) 213 } 214 215 req, err := client.ListByLocationPreparer(ctx, location) 216 if err != nil { 217 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "ListByLocation", nil, "Failure preparing request") 218 return 219 } 220 221 resp, err := client.ListByLocationSender(req) 222 if err != nil { 223 result.Response = autorest.Response{Response: resp} 224 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "ListByLocation", resp, "Failure sending request") 225 return 226 } 227 228 result, err = client.ListByLocationResponder(resp) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "documentdb.RestorableDatabaseAccountsClient", "ListByLocation", resp, "Failure responding to request") 231 return 232 } 233 234 return 235} 236 237// ListByLocationPreparer prepares the ListByLocation request. 238func (client RestorableDatabaseAccountsClient) ListByLocationPreparer(ctx context.Context, location string) (*http.Request, error) { 239 pathParameters := map[string]interface{}{ 240 "location": autorest.Encode("path", location), 241 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 242 } 243 244 const APIVersion = "2020-06-01-preview" 245 queryParameters := map[string]interface{}{ 246 "api-version": APIVersion, 247 } 248 249 preparer := autorest.CreatePreparer( 250 autorest.AsGet(), 251 autorest.WithBaseURL(client.BaseURI), 252 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts", pathParameters), 253 autorest.WithQueryParameters(queryParameters)) 254 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 255} 256 257// ListByLocationSender sends the ListByLocation request. The method will close the 258// http.Response Body if it receives an error. 259func (client RestorableDatabaseAccountsClient) ListByLocationSender(req *http.Request) (*http.Response, error) { 260 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 261} 262 263// ListByLocationResponder handles the response to the ListByLocation request. The method always 264// closes the http.Response Body. 265func (client RestorableDatabaseAccountsClient) ListByLocationResponder(resp *http.Response) (result RestorableDatabaseAccountsListResult, err error) { 266 err = autorest.Respond( 267 resp, 268 azure.WithErrorUnlessStatusCode(http.StatusOK), 269 autorest.ByUnmarshallingJSON(&result), 270 autorest.ByClosing()) 271 result.Response = autorest.Response{Response: resp} 272 return 273} 274