...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb/tableresources.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  // TableResourcesClient is the client for the TableResources methods of the Documentdb service.
    19  type TableResourcesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewTableResourcesClient creates an instance of the TableResourcesClient client.
    24  func NewTableResourcesClient(subscriptionID string) TableResourcesClient {
    25  	return NewTableResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewTableResourcesClientWithBaseURI creates an instance of the TableResourcesClient client using a custom endpoint.
    29  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewTableResourcesClientWithBaseURI(baseURI string, subscriptionID string) TableResourcesClient {
    31  	return TableResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateUpdateTable create or update an Azure Cosmos DB Table
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group. The name is case insensitive.
    37  // accountName - cosmos DB database account name.
    38  // tableName - cosmos DB table name.
    39  // createUpdateTableParameters - the parameters to provide for the current Table.
    40  func (client TableResourcesClient) CreateUpdateTable(ctx context.Context, resourceGroupName string, accountName string, tableName string, createUpdateTableParameters TableCreateUpdateParameters) (result TableResourcesCreateUpdateTableFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.CreateUpdateTable")
    43  		defer func() {
    44  			sc := -1
    45  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    46  				sc = result.FutureAPI.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}}},
    54  		{TargetValue: resourceGroupName,
    55  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    57  		{TargetValue: accountName,
    58  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    59  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    60  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}},
    61  		{TargetValue: createUpdateTableParameters,
    62  			Constraints: []validation.Constraint{{Target: "createUpdateTableParameters.TableCreateUpdateProperties", Name: validation.Null, Rule: true,
    63  				Chain: []validation.Constraint{{Target: "createUpdateTableParameters.TableCreateUpdateProperties.Resource", Name: validation.Null, Rule: true,
    64  					Chain: []validation.Constraint{{Target: "createUpdateTableParameters.TableCreateUpdateProperties.Resource.ID", Name: validation.Null, Rule: true, Chain: nil}}},
    65  				}}}}}); err != nil {
    66  		return result, validation.NewError("documentdb.TableResourcesClient", "CreateUpdateTable", err.Error())
    67  	}
    68  
    69  	req, err := client.CreateUpdateTablePreparer(ctx, resourceGroupName, accountName, tableName, createUpdateTableParameters)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "CreateUpdateTable", nil, "Failure preparing request")
    72  		return
    73  	}
    74  
    75  	result, err = client.CreateUpdateTableSender(req)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "CreateUpdateTable", result.Response(), "Failure sending request")
    78  		return
    79  	}
    80  
    81  	return
    82  }
    83  
    84  // CreateUpdateTablePreparer prepares the CreateUpdateTable request.
    85  func (client TableResourcesClient) CreateUpdateTablePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string, createUpdateTableParameters TableCreateUpdateParameters) (*http.Request, error) {
    86  	pathParameters := map[string]interface{}{
    87  		"accountName":       autorest.Encode("path", accountName),
    88  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    89  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    90  		"tableName":         autorest.Encode("path", tableName),
    91  	}
    92  
    93  	const APIVersion = "2021-10-15"
    94  	queryParameters := map[string]interface{}{
    95  		"api-version": APIVersion,
    96  	}
    97  
    98  	preparer := autorest.CreatePreparer(
    99  		autorest.AsContentType("application/json; charset=utf-8"),
   100  		autorest.AsPut(),
   101  		autorest.WithBaseURL(client.BaseURI),
   102  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}", pathParameters),
   103  		autorest.WithJSON(createUpdateTableParameters),
   104  		autorest.WithQueryParameters(queryParameters))
   105  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   106  }
   107  
   108  // CreateUpdateTableSender sends the CreateUpdateTable request. The method will close the
   109  // http.Response Body if it receives an error.
   110  func (client TableResourcesClient) CreateUpdateTableSender(req *http.Request) (future TableResourcesCreateUpdateTableFuture, err error) {
   111  	var resp *http.Response
   112  	future.FutureAPI = &azure.Future{}
   113  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   114  	if err != nil {
   115  		return
   116  	}
   117  	var azf azure.Future
   118  	azf, err = azure.NewFutureFromResponse(resp)
   119  	future.FutureAPI = &azf
   120  	future.Result = future.result
   121  	return
   122  }
   123  
   124  // CreateUpdateTableResponder handles the response to the CreateUpdateTable request. The method always
   125  // closes the http.Response Body.
   126  func (client TableResourcesClient) CreateUpdateTableResponder(resp *http.Response) (result TableGetResults, err error) {
   127  	err = autorest.Respond(
   128  		resp,
   129  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   130  		autorest.ByUnmarshallingJSON(&result),
   131  		autorest.ByClosing())
   132  	result.Response = autorest.Response{Response: resp}
   133  	return
   134  }
   135  
   136  // DeleteTable deletes an existing Azure Cosmos DB Table.
   137  // Parameters:
   138  // resourceGroupName - the name of the resource group. The name is case insensitive.
   139  // accountName - cosmos DB database account name.
   140  // tableName - cosmos DB table name.
   141  func (client TableResourcesClient) DeleteTable(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result TableResourcesDeleteTableFuture, err error) {
   142  	if tracing.IsEnabled() {
   143  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.DeleteTable")
   144  		defer func() {
   145  			sc := -1
   146  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   147  				sc = result.FutureAPI.Response().StatusCode
   148  			}
   149  			tracing.EndSpan(ctx, sc, err)
   150  		}()
   151  	}
   152  	if err := validation.Validate([]validation.Validation{
   153  		{TargetValue: client.SubscriptionID,
   154  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   155  		{TargetValue: resourceGroupName,
   156  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   157  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   158  		{TargetValue: accountName,
   159  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   160  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   161  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   162  		return result, validation.NewError("documentdb.TableResourcesClient", "DeleteTable", err.Error())
   163  	}
   164  
   165  	req, err := client.DeleteTablePreparer(ctx, resourceGroupName, accountName, tableName)
   166  	if err != nil {
   167  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "DeleteTable", nil, "Failure preparing request")
   168  		return
   169  	}
   170  
   171  	result, err = client.DeleteTableSender(req)
   172  	if err != nil {
   173  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "DeleteTable", result.Response(), "Failure sending request")
   174  		return
   175  	}
   176  
   177  	return
   178  }
   179  
   180  // DeleteTablePreparer prepares the DeleteTable request.
   181  func (client TableResourcesClient) DeleteTablePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   182  	pathParameters := map[string]interface{}{
   183  		"accountName":       autorest.Encode("path", accountName),
   184  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   185  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   186  		"tableName":         autorest.Encode("path", tableName),
   187  	}
   188  
   189  	const APIVersion = "2021-10-15"
   190  	queryParameters := map[string]interface{}{
   191  		"api-version": APIVersion,
   192  	}
   193  
   194  	preparer := autorest.CreatePreparer(
   195  		autorest.AsDelete(),
   196  		autorest.WithBaseURL(client.BaseURI),
   197  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}", pathParameters),
   198  		autorest.WithQueryParameters(queryParameters))
   199  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   200  }
   201  
   202  // DeleteTableSender sends the DeleteTable request. The method will close the
   203  // http.Response Body if it receives an error.
   204  func (client TableResourcesClient) DeleteTableSender(req *http.Request) (future TableResourcesDeleteTableFuture, err error) {
   205  	var resp *http.Response
   206  	future.FutureAPI = &azure.Future{}
   207  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   208  	if err != nil {
   209  		return
   210  	}
   211  	var azf azure.Future
   212  	azf, err = azure.NewFutureFromResponse(resp)
   213  	future.FutureAPI = &azf
   214  	future.Result = future.result
   215  	return
   216  }
   217  
   218  // DeleteTableResponder handles the response to the DeleteTable request. The method always
   219  // closes the http.Response Body.
   220  func (client TableResourcesClient) DeleteTableResponder(resp *http.Response) (result autorest.Response, err error) {
   221  	err = autorest.Respond(
   222  		resp,
   223  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   224  		autorest.ByClosing())
   225  	result.Response = resp
   226  	return
   227  }
   228  
   229  // GetTable gets the Tables under an existing Azure Cosmos DB database account with the provided name.
   230  // Parameters:
   231  // resourceGroupName - the name of the resource group. The name is case insensitive.
   232  // accountName - cosmos DB database account name.
   233  // tableName - cosmos DB table name.
   234  func (client TableResourcesClient) GetTable(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result TableGetResults, err error) {
   235  	if tracing.IsEnabled() {
   236  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.GetTable")
   237  		defer func() {
   238  			sc := -1
   239  			if result.Response.Response != nil {
   240  				sc = result.Response.Response.StatusCode
   241  			}
   242  			tracing.EndSpan(ctx, sc, err)
   243  		}()
   244  	}
   245  	if err := validation.Validate([]validation.Validation{
   246  		{TargetValue: client.SubscriptionID,
   247  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   248  		{TargetValue: resourceGroupName,
   249  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   250  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   251  		{TargetValue: accountName,
   252  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   253  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   254  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   255  		return result, validation.NewError("documentdb.TableResourcesClient", "GetTable", err.Error())
   256  	}
   257  
   258  	req, err := client.GetTablePreparer(ctx, resourceGroupName, accountName, tableName)
   259  	if err != nil {
   260  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTable", nil, "Failure preparing request")
   261  		return
   262  	}
   263  
   264  	resp, err := client.GetTableSender(req)
   265  	if err != nil {
   266  		result.Response = autorest.Response{Response: resp}
   267  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTable", resp, "Failure sending request")
   268  		return
   269  	}
   270  
   271  	result, err = client.GetTableResponder(resp)
   272  	if err != nil {
   273  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTable", resp, "Failure responding to request")
   274  		return
   275  	}
   276  
   277  	return
   278  }
   279  
   280  // GetTablePreparer prepares the GetTable request.
   281  func (client TableResourcesClient) GetTablePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   282  	pathParameters := map[string]interface{}{
   283  		"accountName":       autorest.Encode("path", accountName),
   284  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   285  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   286  		"tableName":         autorest.Encode("path", tableName),
   287  	}
   288  
   289  	const APIVersion = "2021-10-15"
   290  	queryParameters := map[string]interface{}{
   291  		"api-version": APIVersion,
   292  	}
   293  
   294  	preparer := autorest.CreatePreparer(
   295  		autorest.AsGet(),
   296  		autorest.WithBaseURL(client.BaseURI),
   297  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}", pathParameters),
   298  		autorest.WithQueryParameters(queryParameters))
   299  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   300  }
   301  
   302  // GetTableSender sends the GetTable request. The method will close the
   303  // http.Response Body if it receives an error.
   304  func (client TableResourcesClient) GetTableSender(req *http.Request) (*http.Response, error) {
   305  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   306  }
   307  
   308  // GetTableResponder handles the response to the GetTable request. The method always
   309  // closes the http.Response Body.
   310  func (client TableResourcesClient) GetTableResponder(resp *http.Response) (result TableGetResults, err error) {
   311  	err = autorest.Respond(
   312  		resp,
   313  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   314  		autorest.ByUnmarshallingJSON(&result),
   315  		autorest.ByClosing())
   316  	result.Response = autorest.Response{Response: resp}
   317  	return
   318  }
   319  
   320  // GetTableThroughput gets the RUs per second of the Table under an existing Azure Cosmos DB database account with the
   321  // provided name.
   322  // Parameters:
   323  // resourceGroupName - the name of the resource group. The name is case insensitive.
   324  // accountName - cosmos DB database account name.
   325  // tableName - cosmos DB table name.
   326  func (client TableResourcesClient) GetTableThroughput(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result ThroughputSettingsGetResults, err error) {
   327  	if tracing.IsEnabled() {
   328  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.GetTableThroughput")
   329  		defer func() {
   330  			sc := -1
   331  			if result.Response.Response != nil {
   332  				sc = result.Response.Response.StatusCode
   333  			}
   334  			tracing.EndSpan(ctx, sc, err)
   335  		}()
   336  	}
   337  	if err := validation.Validate([]validation.Validation{
   338  		{TargetValue: client.SubscriptionID,
   339  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   340  		{TargetValue: resourceGroupName,
   341  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   342  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   343  		{TargetValue: accountName,
   344  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   345  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   346  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   347  		return result, validation.NewError("documentdb.TableResourcesClient", "GetTableThroughput", err.Error())
   348  	}
   349  
   350  	req, err := client.GetTableThroughputPreparer(ctx, resourceGroupName, accountName, tableName)
   351  	if err != nil {
   352  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTableThroughput", nil, "Failure preparing request")
   353  		return
   354  	}
   355  
   356  	resp, err := client.GetTableThroughputSender(req)
   357  	if err != nil {
   358  		result.Response = autorest.Response{Response: resp}
   359  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTableThroughput", resp, "Failure sending request")
   360  		return
   361  	}
   362  
   363  	result, err = client.GetTableThroughputResponder(resp)
   364  	if err != nil {
   365  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTableThroughput", resp, "Failure responding to request")
   366  		return
   367  	}
   368  
   369  	return
   370  }
   371  
   372  // GetTableThroughputPreparer prepares the GetTableThroughput request.
   373  func (client TableResourcesClient) GetTableThroughputPreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   374  	pathParameters := map[string]interface{}{
   375  		"accountName":       autorest.Encode("path", accountName),
   376  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   377  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   378  		"tableName":         autorest.Encode("path", tableName),
   379  	}
   380  
   381  	const APIVersion = "2021-10-15"
   382  	queryParameters := map[string]interface{}{
   383  		"api-version": APIVersion,
   384  	}
   385  
   386  	preparer := autorest.CreatePreparer(
   387  		autorest.AsGet(),
   388  		autorest.WithBaseURL(client.BaseURI),
   389  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}/throughputSettings/default", pathParameters),
   390  		autorest.WithQueryParameters(queryParameters))
   391  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   392  }
   393  
   394  // GetTableThroughputSender sends the GetTableThroughput request. The method will close the
   395  // http.Response Body if it receives an error.
   396  func (client TableResourcesClient) GetTableThroughputSender(req *http.Request) (*http.Response, error) {
   397  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   398  }
   399  
   400  // GetTableThroughputResponder handles the response to the GetTableThroughput request. The method always
   401  // closes the http.Response Body.
   402  func (client TableResourcesClient) GetTableThroughputResponder(resp *http.Response) (result ThroughputSettingsGetResults, err error) {
   403  	err = autorest.Respond(
   404  		resp,
   405  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   406  		autorest.ByUnmarshallingJSON(&result),
   407  		autorest.ByClosing())
   408  	result.Response = autorest.Response{Response: resp}
   409  	return
   410  }
   411  
   412  // ListTables lists the Tables under an existing Azure Cosmos DB database account.
   413  // Parameters:
   414  // resourceGroupName - the name of the resource group. The name is case insensitive.
   415  // accountName - cosmos DB database account name.
   416  func (client TableResourcesClient) ListTables(ctx context.Context, resourceGroupName string, accountName string) (result TableListResult, err error) {
   417  	if tracing.IsEnabled() {
   418  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.ListTables")
   419  		defer func() {
   420  			sc := -1
   421  			if result.Response.Response != nil {
   422  				sc = result.Response.Response.StatusCode
   423  			}
   424  			tracing.EndSpan(ctx, sc, err)
   425  		}()
   426  	}
   427  	if err := validation.Validate([]validation.Validation{
   428  		{TargetValue: client.SubscriptionID,
   429  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   430  		{TargetValue: resourceGroupName,
   431  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   432  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   433  		{TargetValue: accountName,
   434  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   435  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   436  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   437  		return result, validation.NewError("documentdb.TableResourcesClient", "ListTables", err.Error())
   438  	}
   439  
   440  	req, err := client.ListTablesPreparer(ctx, resourceGroupName, accountName)
   441  	if err != nil {
   442  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "ListTables", nil, "Failure preparing request")
   443  		return
   444  	}
   445  
   446  	resp, err := client.ListTablesSender(req)
   447  	if err != nil {
   448  		result.Response = autorest.Response{Response: resp}
   449  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "ListTables", resp, "Failure sending request")
   450  		return
   451  	}
   452  
   453  	result, err = client.ListTablesResponder(resp)
   454  	if err != nil {
   455  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "ListTables", resp, "Failure responding to request")
   456  		return
   457  	}
   458  
   459  	return
   460  }
   461  
   462  // ListTablesPreparer prepares the ListTables request.
   463  func (client TableResourcesClient) ListTablesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   464  	pathParameters := map[string]interface{}{
   465  		"accountName":       autorest.Encode("path", accountName),
   466  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   467  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   468  	}
   469  
   470  	const APIVersion = "2021-10-15"
   471  	queryParameters := map[string]interface{}{
   472  		"api-version": APIVersion,
   473  	}
   474  
   475  	preparer := autorest.CreatePreparer(
   476  		autorest.AsGet(),
   477  		autorest.WithBaseURL(client.BaseURI),
   478  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables", pathParameters),
   479  		autorest.WithQueryParameters(queryParameters))
   480  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   481  }
   482  
   483  // ListTablesSender sends the ListTables request. The method will close the
   484  // http.Response Body if it receives an error.
   485  func (client TableResourcesClient) ListTablesSender(req *http.Request) (*http.Response, error) {
   486  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   487  }
   488  
   489  // ListTablesResponder handles the response to the ListTables request. The method always
   490  // closes the http.Response Body.
   491  func (client TableResourcesClient) ListTablesResponder(resp *http.Response) (result TableListResult, err error) {
   492  	err = autorest.Respond(
   493  		resp,
   494  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   495  		autorest.ByUnmarshallingJSON(&result),
   496  		autorest.ByClosing())
   497  	result.Response = autorest.Response{Response: resp}
   498  	return
   499  }
   500  
   501  // MigrateTableToAutoscale migrate an Azure Cosmos DB Table from manual throughput to autoscale
   502  // Parameters:
   503  // resourceGroupName - the name of the resource group. The name is case insensitive.
   504  // accountName - cosmos DB database account name.
   505  // tableName - cosmos DB table name.
   506  func (client TableResourcesClient) MigrateTableToAutoscale(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result TableResourcesMigrateTableToAutoscaleFuture, err error) {
   507  	if tracing.IsEnabled() {
   508  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.MigrateTableToAutoscale")
   509  		defer func() {
   510  			sc := -1
   511  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   512  				sc = result.FutureAPI.Response().StatusCode
   513  			}
   514  			tracing.EndSpan(ctx, sc, err)
   515  		}()
   516  	}
   517  	if err := validation.Validate([]validation.Validation{
   518  		{TargetValue: client.SubscriptionID,
   519  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   520  		{TargetValue: resourceGroupName,
   521  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   522  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   523  		{TargetValue: accountName,
   524  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   525  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   526  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   527  		return result, validation.NewError("documentdb.TableResourcesClient", "MigrateTableToAutoscale", err.Error())
   528  	}
   529  
   530  	req, err := client.MigrateTableToAutoscalePreparer(ctx, resourceGroupName, accountName, tableName)
   531  	if err != nil {
   532  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "MigrateTableToAutoscale", nil, "Failure preparing request")
   533  		return
   534  	}
   535  
   536  	result, err = client.MigrateTableToAutoscaleSender(req)
   537  	if err != nil {
   538  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "MigrateTableToAutoscale", result.Response(), "Failure sending request")
   539  		return
   540  	}
   541  
   542  	return
   543  }
   544  
   545  // MigrateTableToAutoscalePreparer prepares the MigrateTableToAutoscale request.
   546  func (client TableResourcesClient) MigrateTableToAutoscalePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   547  	pathParameters := map[string]interface{}{
   548  		"accountName":       autorest.Encode("path", accountName),
   549  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   550  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   551  		"tableName":         autorest.Encode("path", tableName),
   552  	}
   553  
   554  	const APIVersion = "2021-10-15"
   555  	queryParameters := map[string]interface{}{
   556  		"api-version": APIVersion,
   557  	}
   558  
   559  	preparer := autorest.CreatePreparer(
   560  		autorest.AsPost(),
   561  		autorest.WithBaseURL(client.BaseURI),
   562  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}/throughputSettings/default/migrateToAutoscale", pathParameters),
   563  		autorest.WithQueryParameters(queryParameters))
   564  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   565  }
   566  
   567  // MigrateTableToAutoscaleSender sends the MigrateTableToAutoscale request. The method will close the
   568  // http.Response Body if it receives an error.
   569  func (client TableResourcesClient) MigrateTableToAutoscaleSender(req *http.Request) (future TableResourcesMigrateTableToAutoscaleFuture, err error) {
   570  	var resp *http.Response
   571  	future.FutureAPI = &azure.Future{}
   572  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   573  	if err != nil {
   574  		return
   575  	}
   576  	var azf azure.Future
   577  	azf, err = azure.NewFutureFromResponse(resp)
   578  	future.FutureAPI = &azf
   579  	future.Result = future.result
   580  	return
   581  }
   582  
   583  // MigrateTableToAutoscaleResponder handles the response to the MigrateTableToAutoscale request. The method always
   584  // closes the http.Response Body.
   585  func (client TableResourcesClient) MigrateTableToAutoscaleResponder(resp *http.Response) (result ThroughputSettingsGetResults, err error) {
   586  	err = autorest.Respond(
   587  		resp,
   588  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   589  		autorest.ByUnmarshallingJSON(&result),
   590  		autorest.ByClosing())
   591  	result.Response = autorest.Response{Response: resp}
   592  	return
   593  }
   594  
   595  // MigrateTableToManualThroughput migrate an Azure Cosmos DB Table from autoscale to manual throughput
   596  // Parameters:
   597  // resourceGroupName - the name of the resource group. The name is case insensitive.
   598  // accountName - cosmos DB database account name.
   599  // tableName - cosmos DB table name.
   600  func (client TableResourcesClient) MigrateTableToManualThroughput(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result TableResourcesMigrateTableToManualThroughputFuture, err error) {
   601  	if tracing.IsEnabled() {
   602  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.MigrateTableToManualThroughput")
   603  		defer func() {
   604  			sc := -1
   605  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   606  				sc = result.FutureAPI.Response().StatusCode
   607  			}
   608  			tracing.EndSpan(ctx, sc, err)
   609  		}()
   610  	}
   611  	if err := validation.Validate([]validation.Validation{
   612  		{TargetValue: client.SubscriptionID,
   613  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   614  		{TargetValue: resourceGroupName,
   615  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   616  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   617  		{TargetValue: accountName,
   618  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   619  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   620  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   621  		return result, validation.NewError("documentdb.TableResourcesClient", "MigrateTableToManualThroughput", err.Error())
   622  	}
   623  
   624  	req, err := client.MigrateTableToManualThroughputPreparer(ctx, resourceGroupName, accountName, tableName)
   625  	if err != nil {
   626  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "MigrateTableToManualThroughput", nil, "Failure preparing request")
   627  		return
   628  	}
   629  
   630  	result, err = client.MigrateTableToManualThroughputSender(req)
   631  	if err != nil {
   632  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "MigrateTableToManualThroughput", result.Response(), "Failure sending request")
   633  		return
   634  	}
   635  
   636  	return
   637  }
   638  
   639  // MigrateTableToManualThroughputPreparer prepares the MigrateTableToManualThroughput request.
   640  func (client TableResourcesClient) MigrateTableToManualThroughputPreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   641  	pathParameters := map[string]interface{}{
   642  		"accountName":       autorest.Encode("path", accountName),
   643  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   644  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   645  		"tableName":         autorest.Encode("path", tableName),
   646  	}
   647  
   648  	const APIVersion = "2021-10-15"
   649  	queryParameters := map[string]interface{}{
   650  		"api-version": APIVersion,
   651  	}
   652  
   653  	preparer := autorest.CreatePreparer(
   654  		autorest.AsPost(),
   655  		autorest.WithBaseURL(client.BaseURI),
   656  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}/throughputSettings/default/migrateToManualThroughput", pathParameters),
   657  		autorest.WithQueryParameters(queryParameters))
   658  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   659  }
   660  
   661  // MigrateTableToManualThroughputSender sends the MigrateTableToManualThroughput request. The method will close the
   662  // http.Response Body if it receives an error.
   663  func (client TableResourcesClient) MigrateTableToManualThroughputSender(req *http.Request) (future TableResourcesMigrateTableToManualThroughputFuture, err error) {
   664  	var resp *http.Response
   665  	future.FutureAPI = &azure.Future{}
   666  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   667  	if err != nil {
   668  		return
   669  	}
   670  	var azf azure.Future
   671  	azf, err = azure.NewFutureFromResponse(resp)
   672  	future.FutureAPI = &azf
   673  	future.Result = future.result
   674  	return
   675  }
   676  
   677  // MigrateTableToManualThroughputResponder handles the response to the MigrateTableToManualThroughput request. The method always
   678  // closes the http.Response Body.
   679  func (client TableResourcesClient) MigrateTableToManualThroughputResponder(resp *http.Response) (result ThroughputSettingsGetResults, err error) {
   680  	err = autorest.Respond(
   681  		resp,
   682  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   683  		autorest.ByUnmarshallingJSON(&result),
   684  		autorest.ByClosing())
   685  	result.Response = autorest.Response{Response: resp}
   686  	return
   687  }
   688  
   689  // UpdateTableThroughput update RUs per second of an Azure Cosmos DB Table
   690  // Parameters:
   691  // resourceGroupName - the name of the resource group. The name is case insensitive.
   692  // accountName - cosmos DB database account name.
   693  // tableName - cosmos DB table name.
   694  // updateThroughputParameters - the parameters to provide for the RUs per second of the current Table.
   695  func (client TableResourcesClient) UpdateTableThroughput(ctx context.Context, resourceGroupName string, accountName string, tableName string, updateThroughputParameters ThroughputSettingsUpdateParameters) (result TableResourcesUpdateTableThroughputFuture, err error) {
   696  	if tracing.IsEnabled() {
   697  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.UpdateTableThroughput")
   698  		defer func() {
   699  			sc := -1
   700  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   701  				sc = result.FutureAPI.Response().StatusCode
   702  			}
   703  			tracing.EndSpan(ctx, sc, err)
   704  		}()
   705  	}
   706  	if err := validation.Validate([]validation.Validation{
   707  		{TargetValue: client.SubscriptionID,
   708  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   709  		{TargetValue: resourceGroupName,
   710  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   711  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   712  		{TargetValue: accountName,
   713  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   714  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   715  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}},
   716  		{TargetValue: updateThroughputParameters,
   717  			Constraints: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties", Name: validation.Null, Rule: true,
   718  				Chain: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties.Resource", Name: validation.Null, Rule: true,
   719  					Chain: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties.Resource.AutoscaleSettings", Name: validation.Null, Rule: false,
   720  						Chain: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties.Resource.AutoscaleSettings.MaxThroughput", Name: validation.Null, Rule: true, Chain: nil}}},
   721  					}},
   722  				}}}}}); err != nil {
   723  		return result, validation.NewError("documentdb.TableResourcesClient", "UpdateTableThroughput", err.Error())
   724  	}
   725  
   726  	req, err := client.UpdateTableThroughputPreparer(ctx, resourceGroupName, accountName, tableName, updateThroughputParameters)
   727  	if err != nil {
   728  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "UpdateTableThroughput", nil, "Failure preparing request")
   729  		return
   730  	}
   731  
   732  	result, err = client.UpdateTableThroughputSender(req)
   733  	if err != nil {
   734  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "UpdateTableThroughput", result.Response(), "Failure sending request")
   735  		return
   736  	}
   737  
   738  	return
   739  }
   740  
   741  // UpdateTableThroughputPreparer prepares the UpdateTableThroughput request.
   742  func (client TableResourcesClient) UpdateTableThroughputPreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string, updateThroughputParameters ThroughputSettingsUpdateParameters) (*http.Request, error) {
   743  	pathParameters := map[string]interface{}{
   744  		"accountName":       autorest.Encode("path", accountName),
   745  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   746  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   747  		"tableName":         autorest.Encode("path", tableName),
   748  	}
   749  
   750  	const APIVersion = "2021-10-15"
   751  	queryParameters := map[string]interface{}{
   752  		"api-version": APIVersion,
   753  	}
   754  
   755  	preparer := autorest.CreatePreparer(
   756  		autorest.AsContentType("application/json; charset=utf-8"),
   757  		autorest.AsPut(),
   758  		autorest.WithBaseURL(client.BaseURI),
   759  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}/throughputSettings/default", pathParameters),
   760  		autorest.WithJSON(updateThroughputParameters),
   761  		autorest.WithQueryParameters(queryParameters))
   762  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   763  }
   764  
   765  // UpdateTableThroughputSender sends the UpdateTableThroughput request. The method will close the
   766  // http.Response Body if it receives an error.
   767  func (client TableResourcesClient) UpdateTableThroughputSender(req *http.Request) (future TableResourcesUpdateTableThroughputFuture, err error) {
   768  	var resp *http.Response
   769  	future.FutureAPI = &azure.Future{}
   770  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   771  	if err != nil {
   772  		return
   773  	}
   774  	var azf azure.Future
   775  	azf, err = azure.NewFutureFromResponse(resp)
   776  	future.FutureAPI = &azf
   777  	future.Result = future.result
   778  	return
   779  }
   780  
   781  // UpdateTableThroughputResponder handles the response to the UpdateTableThroughput request. The method always
   782  // closes the http.Response Body.
   783  func (client TableResourcesClient) UpdateTableThroughputResponder(resp *http.Response) (result ThroughputSettingsGetResults, err error) {
   784  	err = autorest.Respond(
   785  		resp,
   786  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   787  		autorest.ByUnmarshallingJSON(&result),
   788  		autorest.ByClosing())
   789  	result.Response = autorest.Response{Response: resp}
   790  	return
   791  }
   792  

View as plain text