...

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

View as plain text