...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-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  // PrivateEndpointConnectionsClient is the azure Cosmos DB Database Service Resource Provider REST API
    19  type PrivateEndpointConnectionsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPrivateEndpointConnectionsClient creates an instance of the PrivateEndpointConnectionsClient client.
    24  func NewPrivateEndpointConnectionsClient(subscriptionID string) PrivateEndpointConnectionsClient {
    25  	return NewPrivateEndpointConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPrivateEndpointConnectionsClientWithBaseURI creates an instance of the PrivateEndpointConnectionsClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewPrivateEndpointConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointConnectionsClient {
    32  	return PrivateEndpointConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate approve or reject a private endpoint connection with a given name.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // accountName - cosmos DB database account name.
    39  // privateEndpointConnectionName - the name of the private endpoint connection.
    40  func (client PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection) (result PrivateEndpointConnectionsCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.CreateOrUpdate")
    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}}}}); err != nil {
    62  		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "CreateOrUpdate", err.Error())
    63  	}
    64  
    65  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, accountName, privateEndpointConnectionName, parameters)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
    68  		return
    69  	}
    70  
    71  	result, err = client.CreateOrUpdateSender(req)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    81  func (client PrivateEndpointConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"accountName":                   autorest.Encode("path", accountName),
    84  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
    85  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
    86  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
    87  	}
    88  
    89  	const APIVersion = "2021-01-15"
    90  	queryParameters := map[string]interface{}{
    91  		"api-version": APIVersion,
    92  	}
    93  
    94  	preparer := autorest.CreatePreparer(
    95  		autorest.AsContentType("application/json; charset=utf-8"),
    96  		autorest.AsPut(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
    99  		autorest.WithJSON(parameters),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client PrivateEndpointConnectionsClient) CreateOrUpdateSender(req *http.Request) (future PrivateEndpointConnectionsCreateOrUpdateFuture, err error) {
   107  	var resp *http.Response
   108  	future.FutureAPI = &azure.Future{}
   109  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   110  	if err != nil {
   111  		return
   112  	}
   113  	var azf azure.Future
   114  	azf, err = azure.NewFutureFromResponse(resp)
   115  	future.FutureAPI = &azf
   116  	future.Result = future.result
   117  	return
   118  }
   119  
   120  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   121  // closes the http.Response Body.
   122  func (client PrivateEndpointConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  
   132  // Delete deletes a private endpoint connection with a given name.
   133  // Parameters:
   134  // resourceGroupName - the name of the resource group. The name is case insensitive.
   135  // accountName - cosmos DB database account name.
   136  // privateEndpointConnectionName - the name of the private endpoint connection.
   137  func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) {
   138  	if tracing.IsEnabled() {
   139  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete")
   140  		defer func() {
   141  			sc := -1
   142  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   143  				sc = result.FutureAPI.Response().StatusCode
   144  			}
   145  			tracing.EndSpan(ctx, sc, err)
   146  		}()
   147  	}
   148  	if err := validation.Validate([]validation.Validation{
   149  		{TargetValue: client.SubscriptionID,
   150  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   151  		{TargetValue: resourceGroupName,
   152  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   153  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   154  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   155  		{TargetValue: accountName,
   156  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   157  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   158  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   159  		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "Delete", err.Error())
   160  	}
   161  
   162  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, privateEndpointConnectionName)
   163  	if err != nil {
   164  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request")
   165  		return
   166  	}
   167  
   168  	result, err = client.DeleteSender(req)
   169  	if err != nil {
   170  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Delete", result.Response(), "Failure sending request")
   171  		return
   172  	}
   173  
   174  	return
   175  }
   176  
   177  // DeletePreparer prepares the Delete request.
   178  func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string) (*http.Request, error) {
   179  	pathParameters := map[string]interface{}{
   180  		"accountName":                   autorest.Encode("path", accountName),
   181  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
   182  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
   183  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
   184  	}
   185  
   186  	const APIVersion = "2021-01-15"
   187  	queryParameters := map[string]interface{}{
   188  		"api-version": APIVersion,
   189  	}
   190  
   191  	preparer := autorest.CreatePreparer(
   192  		autorest.AsDelete(),
   193  		autorest.WithBaseURL(client.BaseURI),
   194  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
   195  		autorest.WithQueryParameters(queryParameters))
   196  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   197  }
   198  
   199  // DeleteSender sends the Delete request. The method will close the
   200  // http.Response Body if it receives an error.
   201  func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) {
   202  	var resp *http.Response
   203  	future.FutureAPI = &azure.Future{}
   204  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   205  	if err != nil {
   206  		return
   207  	}
   208  	var azf azure.Future
   209  	azf, err = azure.NewFutureFromResponse(resp)
   210  	future.FutureAPI = &azf
   211  	future.Result = future.result
   212  	return
   213  }
   214  
   215  // DeleteResponder handles the response to the Delete request. The method always
   216  // closes the http.Response Body.
   217  func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   218  	err = autorest.Respond(
   219  		resp,
   220  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   221  		autorest.ByClosing())
   222  	result.Response = resp
   223  	return
   224  }
   225  
   226  // Get gets a private endpoint connection.
   227  // Parameters:
   228  // resourceGroupName - the name of the resource group. The name is case insensitive.
   229  // accountName - cosmos DB database account name.
   230  // privateEndpointConnectionName - the name of the private endpoint connection.
   231  func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) {
   232  	if tracing.IsEnabled() {
   233  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get")
   234  		defer func() {
   235  			sc := -1
   236  			if result.Response.Response != nil {
   237  				sc = result.Response.Response.StatusCode
   238  			}
   239  			tracing.EndSpan(ctx, sc, err)
   240  		}()
   241  	}
   242  	if err := validation.Validate([]validation.Validation{
   243  		{TargetValue: client.SubscriptionID,
   244  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   245  		{TargetValue: resourceGroupName,
   246  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   247  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   248  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   249  		{TargetValue: accountName,
   250  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   251  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   252  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   253  		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "Get", err.Error())
   254  	}
   255  
   256  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, privateEndpointConnectionName)
   257  	if err != nil {
   258  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request")
   259  		return
   260  	}
   261  
   262  	resp, err := client.GetSender(req)
   263  	if err != nil {
   264  		result.Response = autorest.Response{Response: resp}
   265  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request")
   266  		return
   267  	}
   268  
   269  	result, err = client.GetResponder(resp)
   270  	if err != nil {
   271  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request")
   272  		return
   273  	}
   274  
   275  	return
   276  }
   277  
   278  // GetPreparer prepares the Get request.
   279  func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string) (*http.Request, error) {
   280  	pathParameters := map[string]interface{}{
   281  		"accountName":                   autorest.Encode("path", accountName),
   282  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
   283  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
   284  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
   285  	}
   286  
   287  	const APIVersion = "2021-01-15"
   288  	queryParameters := map[string]interface{}{
   289  		"api-version": APIVersion,
   290  	}
   291  
   292  	preparer := autorest.CreatePreparer(
   293  		autorest.AsGet(),
   294  		autorest.WithBaseURL(client.BaseURI),
   295  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
   296  		autorest.WithQueryParameters(queryParameters))
   297  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   298  }
   299  
   300  // GetSender sends the Get request. The method will close the
   301  // http.Response Body if it receives an error.
   302  func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
   303  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   304  }
   305  
   306  // GetResponder handles the response to the Get request. The method always
   307  // closes the http.Response Body.
   308  func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   309  	err = autorest.Respond(
   310  		resp,
   311  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   312  		autorest.ByUnmarshallingJSON(&result),
   313  		autorest.ByClosing())
   314  	result.Response = autorest.Response{Response: resp}
   315  	return
   316  }
   317  
   318  // ListByDatabaseAccount list all private endpoint connections on a Cosmos DB account.
   319  // Parameters:
   320  // resourceGroupName - the name of the resource group. The name is case insensitive.
   321  // accountName - cosmos DB database account name.
   322  func (client PrivateEndpointConnectionsClient) ListByDatabaseAccount(ctx context.Context, resourceGroupName string, accountName string) (result PrivateEndpointConnectionListResult, err error) {
   323  	if tracing.IsEnabled() {
   324  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByDatabaseAccount")
   325  		defer func() {
   326  			sc := -1
   327  			if result.Response.Response != nil {
   328  				sc = result.Response.Response.StatusCode
   329  			}
   330  			tracing.EndSpan(ctx, sc, err)
   331  		}()
   332  	}
   333  	if err := validation.Validate([]validation.Validation{
   334  		{TargetValue: client.SubscriptionID,
   335  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   336  		{TargetValue: resourceGroupName,
   337  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   338  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   339  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   340  		{TargetValue: accountName,
   341  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   342  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   343  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   344  		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", err.Error())
   345  	}
   346  
   347  	req, err := client.ListByDatabaseAccountPreparer(ctx, resourceGroupName, accountName)
   348  	if err != nil {
   349  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", nil, "Failure preparing request")
   350  		return
   351  	}
   352  
   353  	resp, err := client.ListByDatabaseAccountSender(req)
   354  	if err != nil {
   355  		result.Response = autorest.Response{Response: resp}
   356  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", resp, "Failure sending request")
   357  		return
   358  	}
   359  
   360  	result, err = client.ListByDatabaseAccountResponder(resp)
   361  	if err != nil {
   362  		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", resp, "Failure responding to request")
   363  		return
   364  	}
   365  
   366  	return
   367  }
   368  
   369  // ListByDatabaseAccountPreparer prepares the ListByDatabaseAccount request.
   370  func (client PrivateEndpointConnectionsClient) ListByDatabaseAccountPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   371  	pathParameters := map[string]interface{}{
   372  		"accountName":       autorest.Encode("path", accountName),
   373  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   374  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   375  	}
   376  
   377  	const APIVersion = "2021-01-15"
   378  	queryParameters := map[string]interface{}{
   379  		"api-version": APIVersion,
   380  	}
   381  
   382  	preparer := autorest.CreatePreparer(
   383  		autorest.AsGet(),
   384  		autorest.WithBaseURL(client.BaseURI),
   385  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections", pathParameters),
   386  		autorest.WithQueryParameters(queryParameters))
   387  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   388  }
   389  
   390  // ListByDatabaseAccountSender sends the ListByDatabaseAccount request. The method will close the
   391  // http.Response Body if it receives an error.
   392  func (client PrivateEndpointConnectionsClient) ListByDatabaseAccountSender(req *http.Request) (*http.Response, error) {
   393  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   394  }
   395  
   396  // ListByDatabaseAccountResponder handles the response to the ListByDatabaseAccount request. The method always
   397  // closes the http.Response Body.
   398  func (client PrivateEndpointConnectionsClient) ListByDatabaseAccountResponder(resp *http.Response) (result PrivateEndpointConnectionListResult, err error) {
   399  	err = autorest.Respond(
   400  		resp,
   401  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   402  		autorest.ByUnmarshallingJSON(&result),
   403  		autorest.ByClosing())
   404  	result.Response = autorest.Response{Response: resp}
   405  	return
   406  }
   407  

View as plain text