...

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

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

View as plain text