1package 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
9import (
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.
19type PrivateEndpointConnectionsClient struct {
20	BaseClient
21}
22
23// NewPrivateEndpointConnectionsClient creates an instance of the PrivateEndpointConnectionsClient client.
24func 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).
31func 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.
40func (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", nil, "Failure sending request")
74		return
75	}
76
77	return
78}
79
80// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
81func (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-04-01-preview"
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.
106func (client PrivateEndpointConnectionsClient) CreateOrUpdateSender(req *http.Request) (future PrivateEndpointConnectionsCreateOrUpdateFuture, err error) {
107	var resp *http.Response
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.
121func (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.
136func (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				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
154		{TargetValue: accountName,
155			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
156				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
157				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
158		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "Delete", err.Error())
159	}
160
161	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, privateEndpointConnectionName)
162	if err != nil {
163		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request")
164		return
165	}
166
167	result, err = client.DeleteSender(req)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Delete", nil, "Failure sending request")
170		return
171	}
172
173	return
174}
175
176// DeletePreparer prepares the Delete request.
177func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string) (*http.Request, error) {
178	pathParameters := map[string]interface{}{
179		"accountName":                   autorest.Encode("path", accountName),
180		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
181		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
182		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
183	}
184
185	const APIVersion = "2021-04-01-preview"
186	queryParameters := map[string]interface{}{
187		"api-version": APIVersion,
188	}
189
190	preparer := autorest.CreatePreparer(
191		autorest.AsDelete(),
192		autorest.WithBaseURL(client.BaseURI),
193		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
194		autorest.WithQueryParameters(queryParameters))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// DeleteSender sends the Delete request. The method will close the
199// http.Response Body if it receives an error.
200func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) {
201	var resp *http.Response
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.
215func (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.
229func (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				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
247		{TargetValue: accountName,
248			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
249				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
250				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
251		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "Get", err.Error())
252	}
253
254	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, privateEndpointConnectionName)
255	if err != nil {
256		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request")
257		return
258	}
259
260	resp, err := client.GetSender(req)
261	if err != nil {
262		result.Response = autorest.Response{Response: resp}
263		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request")
264		return
265	}
266
267	result, err = client.GetResponder(resp)
268	if err != nil {
269		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request")
270		return
271	}
272
273	return
274}
275
276// GetPreparer prepares the Get request.
277func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, privateEndpointConnectionName string) (*http.Request, error) {
278	pathParameters := map[string]interface{}{
279		"accountName":                   autorest.Encode("path", accountName),
280		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
281		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
282		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
283	}
284
285	const APIVersion = "2021-04-01-preview"
286	queryParameters := map[string]interface{}{
287		"api-version": APIVersion,
288	}
289
290	preparer := autorest.CreatePreparer(
291		autorest.AsGet(),
292		autorest.WithBaseURL(client.BaseURI),
293		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
294		autorest.WithQueryParameters(queryParameters))
295	return preparer.Prepare((&http.Request{}).WithContext(ctx))
296}
297
298// GetSender sends the Get request. The method will close the
299// http.Response Body if it receives an error.
300func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
301	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
302}
303
304// GetResponder handles the response to the Get request. The method always
305// closes the http.Response Body.
306func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
307	err = autorest.Respond(
308		resp,
309		azure.WithErrorUnlessStatusCode(http.StatusOK),
310		autorest.ByUnmarshallingJSON(&result),
311		autorest.ByClosing())
312	result.Response = autorest.Response{Response: resp}
313	return
314}
315
316// ListByDatabaseAccount list all private endpoint connections on a Cosmos DB account.
317// Parameters:
318// resourceGroupName - the name of the resource group. The name is case insensitive.
319// accountName - cosmos DB database account name.
320func (client PrivateEndpointConnectionsClient) ListByDatabaseAccount(ctx context.Context, resourceGroupName string, accountName string) (result PrivateEndpointConnectionListResult, err error) {
321	if tracing.IsEnabled() {
322		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByDatabaseAccount")
323		defer func() {
324			sc := -1
325			if result.Response.Response != nil {
326				sc = result.Response.Response.StatusCode
327			}
328			tracing.EndSpan(ctx, sc, err)
329		}()
330	}
331	if err := validation.Validate([]validation.Validation{
332		{TargetValue: client.SubscriptionID,
333			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
334		{TargetValue: resourceGroupName,
335			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
336				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
337				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
338		{TargetValue: accountName,
339			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
340				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
341				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
342		return result, validation.NewError("documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", err.Error())
343	}
344
345	req, err := client.ListByDatabaseAccountPreparer(ctx, resourceGroupName, accountName)
346	if err != nil {
347		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", nil, "Failure preparing request")
348		return
349	}
350
351	resp, err := client.ListByDatabaseAccountSender(req)
352	if err != nil {
353		result.Response = autorest.Response{Response: resp}
354		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", resp, "Failure sending request")
355		return
356	}
357
358	result, err = client.ListByDatabaseAccountResponder(resp)
359	if err != nil {
360		err = autorest.NewErrorWithError(err, "documentdb.PrivateEndpointConnectionsClient", "ListByDatabaseAccount", resp, "Failure responding to request")
361		return
362	}
363
364	return
365}
366
367// ListByDatabaseAccountPreparer prepares the ListByDatabaseAccount request.
368func (client PrivateEndpointConnectionsClient) ListByDatabaseAccountPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
369	pathParameters := map[string]interface{}{
370		"accountName":       autorest.Encode("path", accountName),
371		"resourceGroupName": autorest.Encode("path", resourceGroupName),
372		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
373	}
374
375	const APIVersion = "2021-04-01-preview"
376	queryParameters := map[string]interface{}{
377		"api-version": APIVersion,
378	}
379
380	preparer := autorest.CreatePreparer(
381		autorest.AsGet(),
382		autorest.WithBaseURL(client.BaseURI),
383		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections", pathParameters),
384		autorest.WithQueryParameters(queryParameters))
385	return preparer.Prepare((&http.Request{}).WithContext(ctx))
386}
387
388// ListByDatabaseAccountSender sends the ListByDatabaseAccount request. The method will close the
389// http.Response Body if it receives an error.
390func (client PrivateEndpointConnectionsClient) ListByDatabaseAccountSender(req *http.Request) (*http.Response, error) {
391	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
392}
393
394// ListByDatabaseAccountResponder handles the response to the ListByDatabaseAccount request. The method always
395// closes the http.Response Body.
396func (client PrivateEndpointConnectionsClient) ListByDatabaseAccountResponder(resp *http.Response) (result PrivateEndpointConnectionListResult, err error) {
397	err = autorest.Respond(
398		resp,
399		azure.WithErrorUnlessStatusCode(http.StatusOK),
400		autorest.ByUnmarshallingJSON(&result),
401		autorest.ByClosing())
402	result.Response = autorest.Response{Response: resp}
403	return
404}
405