...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2019-08-01/documentdb/tableresources.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2019-08-01/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 - name of an Azure resource group.
    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  					{Target: "createUpdateTableParameters.TableCreateUpdateProperties.Options", Name: validation.Null, Rule: true, Chain: nil},
    67  				}}}}}); err != nil {
    68  		return result, validation.NewError("documentdb.TableResourcesClient", "CreateUpdateTable", err.Error())
    69  	}
    70  
    71  	req, err := client.CreateUpdateTablePreparer(ctx, resourceGroupName, accountName, tableName, createUpdateTableParameters)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "CreateUpdateTable", nil, "Failure preparing request")
    74  		return
    75  	}
    76  
    77  	result, err = client.CreateUpdateTableSender(req)
    78  	if err != nil {
    79  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "CreateUpdateTable", result.Response(), "Failure sending request")
    80  		return
    81  	}
    82  
    83  	return
    84  }
    85  
    86  // CreateUpdateTablePreparer prepares the CreateUpdateTable request.
    87  func (client TableResourcesClient) CreateUpdateTablePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string, createUpdateTableParameters TableCreateUpdateParameters) (*http.Request, error) {
    88  	pathParameters := map[string]interface{}{
    89  		"accountName":       autorest.Encode("path", accountName),
    90  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    91  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    92  		"tableName":         autorest.Encode("path", tableName),
    93  	}
    94  
    95  	const APIVersion = "2019-08-01"
    96  	queryParameters := map[string]interface{}{
    97  		"api-version": APIVersion,
    98  	}
    99  
   100  	preparer := autorest.CreatePreparer(
   101  		autorest.AsContentType("application/json; charset=utf-8"),
   102  		autorest.AsPut(),
   103  		autorest.WithBaseURL(client.BaseURI),
   104  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}", pathParameters),
   105  		autorest.WithJSON(createUpdateTableParameters),
   106  		autorest.WithQueryParameters(queryParameters))
   107  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   108  }
   109  
   110  // CreateUpdateTableSender sends the CreateUpdateTable request. The method will close the
   111  // http.Response Body if it receives an error.
   112  func (client TableResourcesClient) CreateUpdateTableSender(req *http.Request) (future TableResourcesCreateUpdateTableFuture, err error) {
   113  	var resp *http.Response
   114  	future.FutureAPI = &azure.Future{}
   115  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   116  	if err != nil {
   117  		return
   118  	}
   119  	var azf azure.Future
   120  	azf, err = azure.NewFutureFromResponse(resp)
   121  	future.FutureAPI = &azf
   122  	future.Result = future.result
   123  	return
   124  }
   125  
   126  // CreateUpdateTableResponder handles the response to the CreateUpdateTable request. The method always
   127  // closes the http.Response Body.
   128  func (client TableResourcesClient) CreateUpdateTableResponder(resp *http.Response) (result TableGetResults, err error) {
   129  	err = autorest.Respond(
   130  		resp,
   131  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   132  		autorest.ByUnmarshallingJSON(&result),
   133  		autorest.ByClosing())
   134  	result.Response = autorest.Response{Response: resp}
   135  	return
   136  }
   137  
   138  // DeleteTable deletes an existing Azure Cosmos DB Table.
   139  // Parameters:
   140  // resourceGroupName - name of an Azure resource group.
   141  // accountName - cosmos DB database account name.
   142  // tableName - cosmos DB table name.
   143  func (client TableResourcesClient) DeleteTable(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result TableResourcesDeleteTableFuture, err error) {
   144  	if tracing.IsEnabled() {
   145  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.DeleteTable")
   146  		defer func() {
   147  			sc := -1
   148  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   149  				sc = result.FutureAPI.Response().StatusCode
   150  			}
   151  			tracing.EndSpan(ctx, sc, err)
   152  		}()
   153  	}
   154  	if err := validation.Validate([]validation.Validation{
   155  		{TargetValue: client.SubscriptionID,
   156  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   157  		{TargetValue: resourceGroupName,
   158  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   159  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   160  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   161  		{TargetValue: accountName,
   162  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   163  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   164  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   165  		return result, validation.NewError("documentdb.TableResourcesClient", "DeleteTable", err.Error())
   166  	}
   167  
   168  	req, err := client.DeleteTablePreparer(ctx, resourceGroupName, accountName, tableName)
   169  	if err != nil {
   170  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "DeleteTable", nil, "Failure preparing request")
   171  		return
   172  	}
   173  
   174  	result, err = client.DeleteTableSender(req)
   175  	if err != nil {
   176  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "DeleteTable", result.Response(), "Failure sending request")
   177  		return
   178  	}
   179  
   180  	return
   181  }
   182  
   183  // DeleteTablePreparer prepares the DeleteTable request.
   184  func (client TableResourcesClient) DeleteTablePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   185  	pathParameters := map[string]interface{}{
   186  		"accountName":       autorest.Encode("path", accountName),
   187  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   188  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   189  		"tableName":         autorest.Encode("path", tableName),
   190  	}
   191  
   192  	const APIVersion = "2019-08-01"
   193  	queryParameters := map[string]interface{}{
   194  		"api-version": APIVersion,
   195  	}
   196  
   197  	preparer := autorest.CreatePreparer(
   198  		autorest.AsDelete(),
   199  		autorest.WithBaseURL(client.BaseURI),
   200  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}", pathParameters),
   201  		autorest.WithQueryParameters(queryParameters))
   202  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   203  }
   204  
   205  // DeleteTableSender sends the DeleteTable request. The method will close the
   206  // http.Response Body if it receives an error.
   207  func (client TableResourcesClient) DeleteTableSender(req *http.Request) (future TableResourcesDeleteTableFuture, err error) {
   208  	var resp *http.Response
   209  	future.FutureAPI = &azure.Future{}
   210  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   211  	if err != nil {
   212  		return
   213  	}
   214  	var azf azure.Future
   215  	azf, err = azure.NewFutureFromResponse(resp)
   216  	future.FutureAPI = &azf
   217  	future.Result = future.result
   218  	return
   219  }
   220  
   221  // DeleteTableResponder handles the response to the DeleteTable request. The method always
   222  // closes the http.Response Body.
   223  func (client TableResourcesClient) DeleteTableResponder(resp *http.Response) (result autorest.Response, err error) {
   224  	err = autorest.Respond(
   225  		resp,
   226  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   227  		autorest.ByClosing())
   228  	result.Response = resp
   229  	return
   230  }
   231  
   232  // GetTable gets the Tables under an existing Azure Cosmos DB database account with the provided name.
   233  // Parameters:
   234  // resourceGroupName - name of an Azure resource group.
   235  // accountName - cosmos DB database account name.
   236  // tableName - cosmos DB table name.
   237  func (client TableResourcesClient) GetTable(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result TableGetResults, err error) {
   238  	if tracing.IsEnabled() {
   239  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.GetTable")
   240  		defer func() {
   241  			sc := -1
   242  			if result.Response.Response != nil {
   243  				sc = result.Response.Response.StatusCode
   244  			}
   245  			tracing.EndSpan(ctx, sc, err)
   246  		}()
   247  	}
   248  	if err := validation.Validate([]validation.Validation{
   249  		{TargetValue: client.SubscriptionID,
   250  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   251  		{TargetValue: resourceGroupName,
   252  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   253  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   254  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   255  		{TargetValue: accountName,
   256  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   257  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   258  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   259  		return result, validation.NewError("documentdb.TableResourcesClient", "GetTable", err.Error())
   260  	}
   261  
   262  	req, err := client.GetTablePreparer(ctx, resourceGroupName, accountName, tableName)
   263  	if err != nil {
   264  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTable", nil, "Failure preparing request")
   265  		return
   266  	}
   267  
   268  	resp, err := client.GetTableSender(req)
   269  	if err != nil {
   270  		result.Response = autorest.Response{Response: resp}
   271  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTable", resp, "Failure sending request")
   272  		return
   273  	}
   274  
   275  	result, err = client.GetTableResponder(resp)
   276  	if err != nil {
   277  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTable", resp, "Failure responding to request")
   278  		return
   279  	}
   280  
   281  	return
   282  }
   283  
   284  // GetTablePreparer prepares the GetTable request.
   285  func (client TableResourcesClient) GetTablePreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   286  	pathParameters := map[string]interface{}{
   287  		"accountName":       autorest.Encode("path", accountName),
   288  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   289  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   290  		"tableName":         autorest.Encode("path", tableName),
   291  	}
   292  
   293  	const APIVersion = "2019-08-01"
   294  	queryParameters := map[string]interface{}{
   295  		"api-version": APIVersion,
   296  	}
   297  
   298  	preparer := autorest.CreatePreparer(
   299  		autorest.AsGet(),
   300  		autorest.WithBaseURL(client.BaseURI),
   301  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}", pathParameters),
   302  		autorest.WithQueryParameters(queryParameters))
   303  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   304  }
   305  
   306  // GetTableSender sends the GetTable request. The method will close the
   307  // http.Response Body if it receives an error.
   308  func (client TableResourcesClient) GetTableSender(req *http.Request) (*http.Response, error) {
   309  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   310  }
   311  
   312  // GetTableResponder handles the response to the GetTable request. The method always
   313  // closes the http.Response Body.
   314  func (client TableResourcesClient) GetTableResponder(resp *http.Response) (result TableGetResults, err error) {
   315  	err = autorest.Respond(
   316  		resp,
   317  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   318  		autorest.ByUnmarshallingJSON(&result),
   319  		autorest.ByClosing())
   320  	result.Response = autorest.Response{Response: resp}
   321  	return
   322  }
   323  
   324  // GetTableThroughput gets the RUs per second of the Table under an existing Azure Cosmos DB database account with the
   325  // provided name.
   326  // Parameters:
   327  // resourceGroupName - name of an Azure resource group.
   328  // accountName - cosmos DB database account name.
   329  // tableName - cosmos DB table name.
   330  func (client TableResourcesClient) GetTableThroughput(ctx context.Context, resourceGroupName string, accountName string, tableName string) (result ThroughputSettingsGetResults, err error) {
   331  	if tracing.IsEnabled() {
   332  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.GetTableThroughput")
   333  		defer func() {
   334  			sc := -1
   335  			if result.Response.Response != nil {
   336  				sc = result.Response.Response.StatusCode
   337  			}
   338  			tracing.EndSpan(ctx, sc, err)
   339  		}()
   340  	}
   341  	if err := validation.Validate([]validation.Validation{
   342  		{TargetValue: client.SubscriptionID,
   343  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   344  		{TargetValue: resourceGroupName,
   345  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   346  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   347  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   348  		{TargetValue: accountName,
   349  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   350  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   351  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   352  		return result, validation.NewError("documentdb.TableResourcesClient", "GetTableThroughput", err.Error())
   353  	}
   354  
   355  	req, err := client.GetTableThroughputPreparer(ctx, resourceGroupName, accountName, tableName)
   356  	if err != nil {
   357  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTableThroughput", nil, "Failure preparing request")
   358  		return
   359  	}
   360  
   361  	resp, err := client.GetTableThroughputSender(req)
   362  	if err != nil {
   363  		result.Response = autorest.Response{Response: resp}
   364  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTableThroughput", resp, "Failure sending request")
   365  		return
   366  	}
   367  
   368  	result, err = client.GetTableThroughputResponder(resp)
   369  	if err != nil {
   370  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "GetTableThroughput", resp, "Failure responding to request")
   371  		return
   372  	}
   373  
   374  	return
   375  }
   376  
   377  // GetTableThroughputPreparer prepares the GetTableThroughput request.
   378  func (client TableResourcesClient) GetTableThroughputPreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string) (*http.Request, error) {
   379  	pathParameters := map[string]interface{}{
   380  		"accountName":       autorest.Encode("path", accountName),
   381  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   382  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   383  		"tableName":         autorest.Encode("path", tableName),
   384  	}
   385  
   386  	const APIVersion = "2019-08-01"
   387  	queryParameters := map[string]interface{}{
   388  		"api-version": APIVersion,
   389  	}
   390  
   391  	preparer := autorest.CreatePreparer(
   392  		autorest.AsGet(),
   393  		autorest.WithBaseURL(client.BaseURI),
   394  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}/throughputSettings/default", pathParameters),
   395  		autorest.WithQueryParameters(queryParameters))
   396  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   397  }
   398  
   399  // GetTableThroughputSender sends the GetTableThroughput request. The method will close the
   400  // http.Response Body if it receives an error.
   401  func (client TableResourcesClient) GetTableThroughputSender(req *http.Request) (*http.Response, error) {
   402  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   403  }
   404  
   405  // GetTableThroughputResponder handles the response to the GetTableThroughput request. The method always
   406  // closes the http.Response Body.
   407  func (client TableResourcesClient) GetTableThroughputResponder(resp *http.Response) (result ThroughputSettingsGetResults, err error) {
   408  	err = autorest.Respond(
   409  		resp,
   410  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   411  		autorest.ByUnmarshallingJSON(&result),
   412  		autorest.ByClosing())
   413  	result.Response = autorest.Response{Response: resp}
   414  	return
   415  }
   416  
   417  // ListTables lists the Tables under an existing Azure Cosmos DB database account.
   418  // Parameters:
   419  // resourceGroupName - name of an Azure resource group.
   420  // accountName - cosmos DB database account name.
   421  func (client TableResourcesClient) ListTables(ctx context.Context, resourceGroupName string, accountName string) (result TableListResult, err error) {
   422  	if tracing.IsEnabled() {
   423  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.ListTables")
   424  		defer func() {
   425  			sc := -1
   426  			if result.Response.Response != nil {
   427  				sc = result.Response.Response.StatusCode
   428  			}
   429  			tracing.EndSpan(ctx, sc, err)
   430  		}()
   431  	}
   432  	if err := validation.Validate([]validation.Validation{
   433  		{TargetValue: client.SubscriptionID,
   434  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   435  		{TargetValue: resourceGroupName,
   436  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   437  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   438  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   439  		{TargetValue: accountName,
   440  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   441  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   442  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   443  		return result, validation.NewError("documentdb.TableResourcesClient", "ListTables", err.Error())
   444  	}
   445  
   446  	req, err := client.ListTablesPreparer(ctx, resourceGroupName, accountName)
   447  	if err != nil {
   448  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "ListTables", nil, "Failure preparing request")
   449  		return
   450  	}
   451  
   452  	resp, err := client.ListTablesSender(req)
   453  	if err != nil {
   454  		result.Response = autorest.Response{Response: resp}
   455  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "ListTables", resp, "Failure sending request")
   456  		return
   457  	}
   458  
   459  	result, err = client.ListTablesResponder(resp)
   460  	if err != nil {
   461  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "ListTables", resp, "Failure responding to request")
   462  		return
   463  	}
   464  
   465  	return
   466  }
   467  
   468  // ListTablesPreparer prepares the ListTables request.
   469  func (client TableResourcesClient) ListTablesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   470  	pathParameters := map[string]interface{}{
   471  		"accountName":       autorest.Encode("path", accountName),
   472  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   473  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   474  	}
   475  
   476  	const APIVersion = "2019-08-01"
   477  	queryParameters := map[string]interface{}{
   478  		"api-version": APIVersion,
   479  	}
   480  
   481  	preparer := autorest.CreatePreparer(
   482  		autorest.AsGet(),
   483  		autorest.WithBaseURL(client.BaseURI),
   484  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables", pathParameters),
   485  		autorest.WithQueryParameters(queryParameters))
   486  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   487  }
   488  
   489  // ListTablesSender sends the ListTables request. The method will close the
   490  // http.Response Body if it receives an error.
   491  func (client TableResourcesClient) ListTablesSender(req *http.Request) (*http.Response, error) {
   492  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   493  }
   494  
   495  // ListTablesResponder handles the response to the ListTables request. The method always
   496  // closes the http.Response Body.
   497  func (client TableResourcesClient) ListTablesResponder(resp *http.Response) (result TableListResult, err error) {
   498  	err = autorest.Respond(
   499  		resp,
   500  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   501  		autorest.ByUnmarshallingJSON(&result),
   502  		autorest.ByClosing())
   503  	result.Response = autorest.Response{Response: resp}
   504  	return
   505  }
   506  
   507  // UpdateTableThroughput update RUs per second of an Azure Cosmos DB Table
   508  // Parameters:
   509  // resourceGroupName - name of an Azure resource group.
   510  // accountName - cosmos DB database account name.
   511  // tableName - cosmos DB table name.
   512  // updateThroughputParameters - the parameters to provide for the RUs per second of the current Table.
   513  func (client TableResourcesClient) UpdateTableThroughput(ctx context.Context, resourceGroupName string, accountName string, tableName string, updateThroughputParameters ThroughputSettingsUpdateParameters) (result TableResourcesUpdateTableThroughputFuture, err error) {
   514  	if tracing.IsEnabled() {
   515  		ctx = tracing.StartSpan(ctx, fqdn+"/TableResourcesClient.UpdateTableThroughput")
   516  		defer func() {
   517  			sc := -1
   518  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   519  				sc = result.FutureAPI.Response().StatusCode
   520  			}
   521  			tracing.EndSpan(ctx, sc, err)
   522  		}()
   523  	}
   524  	if err := validation.Validate([]validation.Validation{
   525  		{TargetValue: client.SubscriptionID,
   526  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   527  		{TargetValue: resourceGroupName,
   528  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   529  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   530  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   531  		{TargetValue: accountName,
   532  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   533  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   534  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}},
   535  		{TargetValue: updateThroughputParameters,
   536  			Constraints: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties", Name: validation.Null, Rule: true,
   537  				Chain: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties.Resource", Name: validation.Null, Rule: true,
   538  					Chain: []validation.Constraint{{Target: "updateThroughputParameters.ThroughputSettingsUpdateProperties.Resource.Throughput", Name: validation.Null, Rule: true, Chain: nil}}},
   539  				}}}}}); err != nil {
   540  		return result, validation.NewError("documentdb.TableResourcesClient", "UpdateTableThroughput", err.Error())
   541  	}
   542  
   543  	req, err := client.UpdateTableThroughputPreparer(ctx, resourceGroupName, accountName, tableName, updateThroughputParameters)
   544  	if err != nil {
   545  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "UpdateTableThroughput", nil, "Failure preparing request")
   546  		return
   547  	}
   548  
   549  	result, err = client.UpdateTableThroughputSender(req)
   550  	if err != nil {
   551  		err = autorest.NewErrorWithError(err, "documentdb.TableResourcesClient", "UpdateTableThroughput", result.Response(), "Failure sending request")
   552  		return
   553  	}
   554  
   555  	return
   556  }
   557  
   558  // UpdateTableThroughputPreparer prepares the UpdateTableThroughput request.
   559  func (client TableResourcesClient) UpdateTableThroughputPreparer(ctx context.Context, resourceGroupName string, accountName string, tableName string, updateThroughputParameters ThroughputSettingsUpdateParameters) (*http.Request, error) {
   560  	pathParameters := map[string]interface{}{
   561  		"accountName":       autorest.Encode("path", accountName),
   562  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   563  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   564  		"tableName":         autorest.Encode("path", tableName),
   565  	}
   566  
   567  	const APIVersion = "2019-08-01"
   568  	queryParameters := map[string]interface{}{
   569  		"api-version": APIVersion,
   570  	}
   571  
   572  	preparer := autorest.CreatePreparer(
   573  		autorest.AsContentType("application/json; charset=utf-8"),
   574  		autorest.AsPut(),
   575  		autorest.WithBaseURL(client.BaseURI),
   576  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName}/throughputSettings/default", pathParameters),
   577  		autorest.WithJSON(updateThroughputParameters),
   578  		autorest.WithQueryParameters(queryParameters))
   579  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   580  }
   581  
   582  // UpdateTableThroughputSender sends the UpdateTableThroughput request. The method will close the
   583  // http.Response Body if it receives an error.
   584  func (client TableResourcesClient) UpdateTableThroughputSender(req *http.Request) (future TableResourcesUpdateTableThroughputFuture, err error) {
   585  	var resp *http.Response
   586  	future.FutureAPI = &azure.Future{}
   587  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   588  	if err != nil {
   589  		return
   590  	}
   591  	var azf azure.Future
   592  	azf, err = azure.NewFutureFromResponse(resp)
   593  	future.FutureAPI = &azf
   594  	future.Result = future.result
   595  	return
   596  }
   597  
   598  // UpdateTableThroughputResponder handles the response to the UpdateTableThroughput request. The method always
   599  // closes the http.Response Body.
   600  func (client TableResourcesClient) UpdateTableThroughputResponder(resp *http.Response) (result ThroughputSettingsGetResults, err error) {
   601  	err = autorest.Respond(
   602  		resp,
   603  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   604  		autorest.ByUnmarshallingJSON(&result),
   605  		autorest.ByClosing())
   606  	result.Response = autorest.Response{Response: resp}
   607  	return
   608  }
   609  

View as plain text