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