...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-05-15/documentdb/service.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-05-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  // 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 ServiceResourceCreateUpdateParameters) (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  		{TargetValue: accountName,
    58  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    59  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    60  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}},
    61  		{TargetValue: serviceName,
    62  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    63  				{Target: "serviceName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
    64  		{TargetValue: createUpdateParameters,
    65  			Constraints: []validation.Constraint{{Target: "createUpdateParameters.ServiceResourceCreateUpdateProperties", Name: validation.Null, Rule: false,
    66  				Chain: []validation.Constraint{{Target: "createUpdateParameters.ServiceResourceCreateUpdateProperties.InstanceCount", Name: validation.Null, Rule: false,
    67  					Chain: []validation.Constraint{{Target: "createUpdateParameters.ServiceResourceCreateUpdateProperties.InstanceCount", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}},
    68  				}}}}}); err != nil {
    69  		return result, validation.NewError("documentdb.ServiceClient", "Create", err.Error())
    70  	}
    71  
    72  	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, serviceName, createUpdateParameters)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Create", nil, "Failure preparing request")
    75  		return
    76  	}
    77  
    78  	result, err = client.CreateSender(req)
    79  	if err != nil {
    80  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Create", result.Response(), "Failure sending request")
    81  		return
    82  	}
    83  
    84  	return
    85  }
    86  
    87  // CreatePreparer prepares the Create request.
    88  func (client ServiceClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, serviceName string, createUpdateParameters ServiceResourceCreateUpdateParameters) (*http.Request, error) {
    89  	pathParameters := map[string]interface{}{
    90  		"accountName":       autorest.Encode("path", accountName),
    91  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    92  		"serviceName":       autorest.Encode("path", serviceName),
    93  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    94  	}
    95  
    96  	const APIVersion = "2022-05-15"
    97  	queryParameters := map[string]interface{}{
    98  		"api-version": APIVersion,
    99  	}
   100  
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsContentType("application/json; charset=utf-8"),
   103  		autorest.AsPut(),
   104  		autorest.WithBaseURL(client.BaseURI),
   105  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/services/{serviceName}", pathParameters),
   106  		autorest.WithJSON(createUpdateParameters),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // CreateSender sends the Create request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client ServiceClient) CreateSender(req *http.Request) (future ServiceCreateFuture, err error) {
   114  	var resp *http.Response
   115  	future.FutureAPI = &azure.Future{}
   116  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   117  	if err != nil {
   118  		return
   119  	}
   120  	var azf azure.Future
   121  	azf, err = azure.NewFutureFromResponse(resp)
   122  	future.FutureAPI = &azf
   123  	future.Result = future.result
   124  	return
   125  }
   126  
   127  // CreateResponder handles the response to the Create request. The method always
   128  // closes the http.Response Body.
   129  func (client ServiceClient) CreateResponder(resp *http.Response) (result ServiceResource, err error) {
   130  	err = autorest.Respond(
   131  		resp,
   132  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   133  		autorest.ByUnmarshallingJSON(&result),
   134  		autorest.ByClosing())
   135  	result.Response = autorest.Response{Response: resp}
   136  	return
   137  }
   138  
   139  // Delete deletes service with the given serviceName.
   140  // Parameters:
   141  // resourceGroupName - the name of the resource group. The name is case insensitive.
   142  // accountName - cosmos DB database account name.
   143  // serviceName - cosmos DB service name.
   144  func (client ServiceClient) Delete(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (result ServiceDeleteFuture, err error) {
   145  	if tracing.IsEnabled() {
   146  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.Delete")
   147  		defer func() {
   148  			sc := -1
   149  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   150  				sc = result.FutureAPI.Response().StatusCode
   151  			}
   152  			tracing.EndSpan(ctx, sc, err)
   153  		}()
   154  	}
   155  	if err := validation.Validate([]validation.Validation{
   156  		{TargetValue: client.SubscriptionID,
   157  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   158  		{TargetValue: resourceGroupName,
   159  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   160  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, 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}}},
   165  		{TargetValue: serviceName,
   166  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   167  				{Target: "serviceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   168  		return result, validation.NewError("documentdb.ServiceClient", "Delete", err.Error())
   169  	}
   170  
   171  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, serviceName)
   172  	if err != nil {
   173  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Delete", nil, "Failure preparing request")
   174  		return
   175  	}
   176  
   177  	result, err = client.DeleteSender(req)
   178  	if err != nil {
   179  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Delete", result.Response(), "Failure sending request")
   180  		return
   181  	}
   182  
   183  	return
   184  }
   185  
   186  // DeletePreparer prepares the Delete request.
   187  func (client ServiceClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (*http.Request, error) {
   188  	pathParameters := map[string]interface{}{
   189  		"accountName":       autorest.Encode("path", accountName),
   190  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   191  		"serviceName":       autorest.Encode("path", serviceName),
   192  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   193  	}
   194  
   195  	const APIVersion = "2022-05-15"
   196  	queryParameters := map[string]interface{}{
   197  		"api-version": APIVersion,
   198  	}
   199  
   200  	preparer := autorest.CreatePreparer(
   201  		autorest.AsDelete(),
   202  		autorest.WithBaseURL(client.BaseURI),
   203  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/services/{serviceName}", pathParameters),
   204  		autorest.WithQueryParameters(queryParameters))
   205  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   206  }
   207  
   208  // DeleteSender sends the Delete request. The method will close the
   209  // http.Response Body if it receives an error.
   210  func (client ServiceClient) DeleteSender(req *http.Request) (future ServiceDeleteFuture, err error) {
   211  	var resp *http.Response
   212  	future.FutureAPI = &azure.Future{}
   213  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   214  	if err != nil {
   215  		return
   216  	}
   217  	var azf azure.Future
   218  	azf, err = azure.NewFutureFromResponse(resp)
   219  	future.FutureAPI = &azf
   220  	future.Result = future.result
   221  	return
   222  }
   223  
   224  // DeleteResponder handles the response to the Delete request. The method always
   225  // closes the http.Response Body.
   226  func (client ServiceClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   227  	err = autorest.Respond(
   228  		resp,
   229  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   230  		autorest.ByClosing())
   231  	result.Response = resp
   232  	return
   233  }
   234  
   235  // Get gets the status of service.
   236  // Parameters:
   237  // resourceGroupName - the name of the resource group. The name is case insensitive.
   238  // accountName - cosmos DB database account name.
   239  // serviceName - cosmos DB service name.
   240  func (client ServiceClient) Get(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (result ServiceResource, err error) {
   241  	if tracing.IsEnabled() {
   242  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.Get")
   243  		defer func() {
   244  			sc := -1
   245  			if result.Response.Response != nil {
   246  				sc = result.Response.Response.StatusCode
   247  			}
   248  			tracing.EndSpan(ctx, sc, err)
   249  		}()
   250  	}
   251  	if err := validation.Validate([]validation.Validation{
   252  		{TargetValue: client.SubscriptionID,
   253  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   254  		{TargetValue: resourceGroupName,
   255  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   256  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   257  		{TargetValue: accountName,
   258  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   259  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   260  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}},
   261  		{TargetValue: serviceName,
   262  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   263  				{Target: "serviceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   264  		return result, validation.NewError("documentdb.ServiceClient", "Get", err.Error())
   265  	}
   266  
   267  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, serviceName)
   268  	if err != nil {
   269  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Get", nil, "Failure preparing request")
   270  		return
   271  	}
   272  
   273  	resp, err := client.GetSender(req)
   274  	if err != nil {
   275  		result.Response = autorest.Response{Response: resp}
   276  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Get", resp, "Failure sending request")
   277  		return
   278  	}
   279  
   280  	result, err = client.GetResponder(resp)
   281  	if err != nil {
   282  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "Get", resp, "Failure responding to request")
   283  		return
   284  	}
   285  
   286  	return
   287  }
   288  
   289  // GetPreparer prepares the Get request.
   290  func (client ServiceClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, serviceName string) (*http.Request, error) {
   291  	pathParameters := map[string]interface{}{
   292  		"accountName":       autorest.Encode("path", accountName),
   293  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   294  		"serviceName":       autorest.Encode("path", serviceName),
   295  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   296  	}
   297  
   298  	const APIVersion = "2022-05-15"
   299  	queryParameters := map[string]interface{}{
   300  		"api-version": APIVersion,
   301  	}
   302  
   303  	preparer := autorest.CreatePreparer(
   304  		autorest.AsGet(),
   305  		autorest.WithBaseURL(client.BaseURI),
   306  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/services/{serviceName}", pathParameters),
   307  		autorest.WithQueryParameters(queryParameters))
   308  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   309  }
   310  
   311  // GetSender sends the Get request. The method will close the
   312  // http.Response Body if it receives an error.
   313  func (client ServiceClient) GetSender(req *http.Request) (*http.Response, error) {
   314  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   315  }
   316  
   317  // GetResponder handles the response to the Get request. The method always
   318  // closes the http.Response Body.
   319  func (client ServiceClient) GetResponder(resp *http.Response) (result ServiceResource, err error) {
   320  	err = autorest.Respond(
   321  		resp,
   322  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   323  		autorest.ByUnmarshallingJSON(&result),
   324  		autorest.ByClosing())
   325  	result.Response = autorest.Response{Response: resp}
   326  	return
   327  }
   328  
   329  // List gets the status of service.
   330  // Parameters:
   331  // resourceGroupName - the name of the resource group. The name is case insensitive.
   332  // accountName - cosmos DB database account name.
   333  func (client ServiceClient) List(ctx context.Context, resourceGroupName string, accountName string) (result ServiceResourceListResult, err error) {
   334  	if tracing.IsEnabled() {
   335  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.List")
   336  		defer func() {
   337  			sc := -1
   338  			if result.Response.Response != nil {
   339  				sc = result.Response.Response.StatusCode
   340  			}
   341  			tracing.EndSpan(ctx, sc, err)
   342  		}()
   343  	}
   344  	if err := validation.Validate([]validation.Validation{
   345  		{TargetValue: client.SubscriptionID,
   346  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   347  		{TargetValue: resourceGroupName,
   348  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   349  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   350  		{TargetValue: accountName,
   351  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   352  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   353  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   354  		return result, validation.NewError("documentdb.ServiceClient", "List", err.Error())
   355  	}
   356  
   357  	req, err := client.ListPreparer(ctx, resourceGroupName, accountName)
   358  	if err != nil {
   359  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "List", nil, "Failure preparing request")
   360  		return
   361  	}
   362  
   363  	resp, err := client.ListSender(req)
   364  	if err != nil {
   365  		result.Response = autorest.Response{Response: resp}
   366  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "List", resp, "Failure sending request")
   367  		return
   368  	}
   369  
   370  	result, err = client.ListResponder(resp)
   371  	if err != nil {
   372  		err = autorest.NewErrorWithError(err, "documentdb.ServiceClient", "List", resp, "Failure responding to request")
   373  		return
   374  	}
   375  
   376  	return
   377  }
   378  
   379  // ListPreparer prepares the List request.
   380  func (client ServiceClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   381  	pathParameters := map[string]interface{}{
   382  		"accountName":       autorest.Encode("path", accountName),
   383  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   384  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   385  	}
   386  
   387  	const APIVersion = "2022-05-15"
   388  	queryParameters := map[string]interface{}{
   389  		"api-version": APIVersion,
   390  	}
   391  
   392  	preparer := autorest.CreatePreparer(
   393  		autorest.AsGet(),
   394  		autorest.WithBaseURL(client.BaseURI),
   395  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/services", pathParameters),
   396  		autorest.WithQueryParameters(queryParameters))
   397  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   398  }
   399  
   400  // ListSender sends the List request. The method will close the
   401  // http.Response Body if it receives an error.
   402  func (client ServiceClient) ListSender(req *http.Request) (*http.Response, error) {
   403  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   404  }
   405  
   406  // ListResponder handles the response to the List request. The method always
   407  // closes the http.Response Body.
   408  func (client ServiceClient) ListResponder(resp *http.Response) (result ServiceResourceListResult, err error) {
   409  	err = autorest.Respond(
   410  		resp,
   411  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   412  		autorest.ByUnmarshallingJSON(&result),
   413  		autorest.ByClosing())
   414  	result.Response = autorest.Response{Response: resp}
   415  	return
   416  }
   417  

View as plain text