...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb/service.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb

     1  package documentdb
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // ServiceClient is the client for the Service methods of the Documentdb service.
    19  type ServiceClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewServiceClient creates an instance of the ServiceClient client.
    24  func NewServiceClient(subscriptionID string) ServiceClient {
    25  	return NewServiceClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewServiceClientWithBaseURI creates an instance of the ServiceClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewServiceClientWithBaseURI(baseURI string, subscriptionID string) ServiceClient {
    31  	return ServiceClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Create creates a service.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group. The name is case insensitive.
    37  // accountName - cosmos DB database account name.
    38  // serviceName - cosmos DB service name.
    39  // createUpdateParameters - the Service resource parameters.
    40  func (client ServiceClient) Create(ctx context.Context, resourceGroupName string, accountName string, serviceName string, createUpdateParameters ServiceResource) (result ServiceCreateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.Create")
    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: serviceName,
    63  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    64  				{Target: "serviceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
    65  		return result, validation.NewError("documentdb.ServiceClient", "Create", err.Error())
    66  	}
    67  
    68  	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, serviceName, createUpdateParameters)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Create", nil, "Failure preparing request")
    71  		return
    72  	}
    73  
    74  	result, err = client.CreateSender(req)
    75  	if err != nil {
    76  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Create", result.Response(), "Failure sending request")
    77  		return
    78  	}
    79  
    80  	return
    81  }
    82  
    83  // CreatePreparer prepares the Create request.
    84  func (client ServiceClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, serviceName string, createUpdateParameters ServiceResource) (*http.Request, error) {
    85  	pathParameters := map[string]interface{}{
    86  		"accountName":       autorest.Encode("path", accountName),
    87  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    88  		"serviceName":       autorest.Encode("path", serviceName),
    89  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    90  	}
    91  
    92  	const APIVersion = "2021-04-01-preview"
    93  	queryParameters := map[string]interface{}{
    94  		"api-version": APIVersion,
    95  	}
    96  
    97  	preparer := autorest.CreatePreparer(
    98  		autorest.AsContentType("application/json; charset=utf-8"),
    99  		autorest.AsPut(),
   100  		autorest.WithBaseURL(client.BaseURI),
   101  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/services/{serviceName}", pathParameters),
   102  		autorest.WithJSON(createUpdateParameters),
   103  		autorest.WithQueryParameters(queryParameters))
   104  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   105  }
   106  
   107  // CreateSender sends the Create request. The method will close the
   108  // http.Response Body if it receives an error.
   109  func (client ServiceClient) CreateSender(req *http.Request) (future ServiceCreateFuture, err error) {
   110  	var resp *http.Response
   111  	future.FutureAPI = &azure.Future{}
   112  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   113  	if err != nil {
   114  		return
   115  	}
   116  	var azf azure.Future
   117  	azf, err = azure.NewFutureFromResponse(resp)
   118  	future.FutureAPI = &azf
   119  	future.Result = future.result
   120  	return
   121  }
   122  
   123  // CreateResponder handles the response to the Create request. The method always
   124  // closes the http.Response Body.
   125  func (client ServiceClient) CreateResponder(resp *http.Response) (result ServiceResource, err error) {
   126  	err = autorest.Respond(
   127  		resp,
   128  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   129  		autorest.ByUnmarshallingJSON(&result),
   130  		autorest.ByClosing())
   131  	result.Response = autorest.Response{Response: resp}
   132  	return
   133  }
   134  
   135  // Delete deletes service with the given serviceName.
   136  // Parameters:
   137  // resourceGroupName - the name of the resource group. The name is case insensitive.
   138  // accountName - cosmos DB database account name.
   139  // serviceName - cosmos DB service name.
   140  func (client ServiceClient) Delete(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (result ServiceDeleteFuture, err error) {
   141  	if tracing.IsEnabled() {
   142  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.Delete")
   143  		defer func() {
   144  			sc := -1
   145  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   146  				sc = result.FutureAPI.Response().StatusCode
   147  			}
   148  			tracing.EndSpan(ctx, sc, err)
   149  		}()
   150  	}
   151  	if err := validation.Validate([]validation.Validation{
   152  		{TargetValue: client.SubscriptionID,
   153  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   154  		{TargetValue: resourceGroupName,
   155  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   156  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   157  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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}}},
   162  		{TargetValue: serviceName,
   163  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   164  				{Target: "serviceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   165  		return result, validation.NewError("documentdb.ServiceClient", "Delete", err.Error())
   166  	}
   167  
   168  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, serviceName)
   169  	if err != nil {
   170  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Delete", nil, "Failure preparing request")
   171  		return
   172  	}
   173  
   174  	result, err = client.DeleteSender(req)
   175  	if err != nil {
   176  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Delete", result.Response(), "Failure sending request")
   177  		return
   178  	}
   179  
   180  	return
   181  }
   182  
   183  // DeletePreparer prepares the Delete request.
   184  func (client ServiceClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (*http.Request, error) {
   185  	pathParameters := map[string]interface{}{
   186  		"accountName":       autorest.Encode("path", accountName),
   187  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   188  		"serviceName":       autorest.Encode("path", serviceName),
   189  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   190  	}
   191  
   192  	const APIVersion = "2021-04-01-preview"
   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}/services/{serviceName}", pathParameters),
   201  		autorest.WithQueryParameters(queryParameters))
   202  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   203  }
   204  
   205  // DeleteSender sends the Delete request. The method will close the
   206  // http.Response Body if it receives an error.
   207  func (client ServiceClient) DeleteSender(req *http.Request) (future ServiceDeleteFuture, 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  // DeleteResponder handles the response to the Delete request. The method always
   222  // closes the http.Response Body.
   223  func (client ServiceClient) DeleteResponder(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  // Get gets the status of service.
   233  // Parameters:
   234  // resourceGroupName - the name of the resource group. The name is case insensitive.
   235  // accountName - cosmos DB database account name.
   236  // serviceName - cosmos DB service name.
   237  func (client ServiceClient) Get(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (result ServiceResource, err error) {
   238  	if tracing.IsEnabled() {
   239  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.Get")
   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}}},
   259  		{TargetValue: serviceName,
   260  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   261  				{Target: "serviceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   262  		return result, validation.NewError("documentdb.ServiceClient", "Get", err.Error())
   263  	}
   264  
   265  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, serviceName)
   266  	if err != nil {
   267  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Get", nil, "Failure preparing request")
   268  		return
   269  	}
   270  
   271  	resp, err := client.GetSender(req)
   272  	if err != nil {
   273  		result.Response = autorest.Response{Response: resp}
   274  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Get", resp, "Failure sending request")
   275  		return
   276  	}
   277  
   278  	result, err = client.GetResponder(resp)
   279  	if err != nil {
   280  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Get", resp, "Failure responding to request")
   281  		return
   282  	}
   283  
   284  	return
   285  }
   286  
   287  // GetPreparer prepares the Get request.
   288  func (client ServiceClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (*http.Request, error) {
   289  	pathParameters := map[string]interface{}{
   290  		"accountName":       autorest.Encode("path", accountName),
   291  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   292  		"serviceName":       autorest.Encode("path", serviceName),
   293  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   294  	}
   295  
   296  	const APIVersion = "2021-04-01-preview"
   297  	queryParameters := map[string]interface{}{
   298  		"api-version": APIVersion,
   299  	}
   300  
   301  	preparer := autorest.CreatePreparer(
   302  		autorest.AsGet(),
   303  		autorest.WithBaseURL(client.BaseURI),
   304  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/services/{serviceName}", pathParameters),
   305  		autorest.WithQueryParameters(queryParameters))
   306  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   307  }
   308  
   309  // GetSender sends the Get request. The method will close the
   310  // http.Response Body if it receives an error.
   311  func (client ServiceClient) GetSender(req *http.Request) (*http.Response, error) {
   312  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   313  }
   314  
   315  // GetResponder handles the response to the Get request. The method always
   316  // closes the http.Response Body.
   317  func (client ServiceClient) GetResponder(resp *http.Response) (result ServiceResource, err error) {
   318  	err = autorest.Respond(
   319  		resp,
   320  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   321  		autorest.ByUnmarshallingJSON(&result),
   322  		autorest.ByClosing())
   323  	result.Response = autorest.Response{Response: resp}
   324  	return
   325  }
   326  
   327  // List gets the status of service.
   328  // Parameters:
   329  // resourceGroupName - the name of the resource group. The name is case insensitive.
   330  // accountName - cosmos DB database account name.
   331  func (client ServiceClient) List(ctx context.Context, resourceGroupName string, accountName string) (result ServiceResourceListResult, err error) {
   332  	if tracing.IsEnabled() {
   333  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.List")
   334  		defer func() {
   335  			sc := -1
   336  			if result.Response.Response != nil {
   337  				sc = result.Response.Response.StatusCode
   338  			}
   339  			tracing.EndSpan(ctx, sc, err)
   340  		}()
   341  	}
   342  	if err := validation.Validate([]validation.Validation{
   343  		{TargetValue: client.SubscriptionID,
   344  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   345  		{TargetValue: resourceGroupName,
   346  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   347  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   348  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   349  		{TargetValue: accountName,
   350  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   351  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   352  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   353  		return result, validation.NewError("documentdb.ServiceClient", "List", err.Error())
   354  	}
   355  
   356  	req, err := client.ListPreparer(ctx, resourceGroupName, accountName)
   357  	if err != nil {
   358  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "List", nil, "Failure preparing request")
   359  		return
   360  	}
   361  
   362  	resp, err := client.ListSender(req)
   363  	if err != nil {
   364  		result.Response = autorest.Response{Response: resp}
   365  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "List", resp, "Failure sending request")
   366  		return
   367  	}
   368  
   369  	result, err = client.ListResponder(resp)
   370  	if err != nil {
   371  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "List", resp, "Failure responding to request")
   372  		return
   373  	}
   374  
   375  	return
   376  }
   377  
   378  // ListPreparer prepares the List request.
   379  func (client ServiceClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   380  	pathParameters := map[string]interface{}{
   381  		"accountName":       autorest.Encode("path", accountName),
   382  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   383  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   384  	}
   385  
   386  	const APIVersion = "2021-04-01-preview"
   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}/services", pathParameters),
   395  		autorest.WithQueryParameters(queryParameters))
   396  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   397  }
   398  
   399  // ListSender sends the List request. The method will close the
   400  // http.Response Body if it receives an error.
   401  func (client ServiceClient) ListSender(req *http.Request) (*http.Response, error) {
   402  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   403  }
   404  
   405  // ListResponder handles the response to the List request. The method always
   406  // closes the http.Response Body.
   407  func (client ServiceClient) ListResponder(resp *http.Response) (result ServiceResourceListResult, 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  

View as plain text