...

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

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

View as plain text