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// PrivateLinkResourcesClient is the client for the PrivateLinkResources methods of the Documentdb service. 19type PrivateLinkResourcesClient struct { 20 BaseClient 21} 22 23// NewPrivateLinkResourcesClient creates an instance of the PrivateLinkResourcesClient client. 24func NewPrivateLinkResourcesClient(subscriptionID string) PrivateLinkResourcesClient { 25 return NewPrivateLinkResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewPrivateLinkResourcesClientWithBaseURI creates an instance of the PrivateLinkResourcesClient client using a custom 29// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 30// stack). 31func NewPrivateLinkResourcesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkResourcesClient { 32 return PrivateLinkResourcesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// Get gets the private link resources that need to be created for a Cosmos DB account. 36// Parameters: 37// resourceGroupName - the name of the resource group. The name is case insensitive. 38// accountName - cosmos DB database account name. 39// groupName - the name of the private link resource. 40func (client PrivateLinkResourcesClient) Get(ctx context.Context, resourceGroupName string, accountName string, groupName string) (result PrivateLinkResource, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.Get") 43 defer func() { 44 sc := -1 45 if result.Response.Response != nil { 46 sc = result.Response.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.PrivateLinkResourcesClient", "Get", err.Error()) 62 } 63 64 req, err := client.GetPreparer(ctx, resourceGroupName, accountName, groupName) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "documentdb.PrivateLinkResourcesClient", "Get", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.GetSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "documentdb.PrivateLinkResourcesClient", "Get", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.GetResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "documentdb.PrivateLinkResourcesClient", "Get", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// GetPreparer prepares the Get request. 87func (client PrivateLinkResourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, groupName string) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "accountName": autorest.Encode("path", accountName), 90 "groupName": autorest.Encode("path", groupName), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2021-03-01-preview" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateLinkResources/{groupName}", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// GetSender sends the Get request. The method will close the 109// http.Response Body if it receives an error. 110func (client PrivateLinkResourcesClient) GetSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// GetResponder handles the response to the Get request. The method always 115// closes the http.Response Body. 116func (client PrivateLinkResourcesClient) GetResponder(resp *http.Response) (result PrivateLinkResource, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// ListByDatabaseAccount gets the private link resources that need to be created for a Cosmos DB account. 127// Parameters: 128// resourceGroupName - the name of the resource group. The name is case insensitive. 129// accountName - cosmos DB database account name. 130func (client PrivateLinkResourcesClient) ListByDatabaseAccount(ctx context.Context, resourceGroupName string, accountName string) (result PrivateLinkResourceListResult, err error) { 131 if tracing.IsEnabled() { 132 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.ListByDatabaseAccount") 133 defer func() { 134 sc := -1 135 if result.Response.Response != nil { 136 sc = result.Response.Response.StatusCode 137 } 138 tracing.EndSpan(ctx, sc, err) 139 }() 140 } 141 if err := validation.Validate([]validation.Validation{ 142 {TargetValue: client.SubscriptionID, 143 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 144 {TargetValue: resourceGroupName, 145 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 146 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 147 {TargetValue: accountName, 148 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 149 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 150 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil { 151 return result, validation.NewError("documentdb.PrivateLinkResourcesClient", "ListByDatabaseAccount", err.Error()) 152 } 153 154 req, err := client.ListByDatabaseAccountPreparer(ctx, resourceGroupName, accountName) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "documentdb.PrivateLinkResourcesClient", "ListByDatabaseAccount", nil, "Failure preparing request") 157 return 158 } 159 160 resp, err := client.ListByDatabaseAccountSender(req) 161 if err != nil { 162 result.Response = autorest.Response{Response: resp} 163 err = autorest.NewErrorWithError(err, "documentdb.PrivateLinkResourcesClient", "ListByDatabaseAccount", resp, "Failure sending request") 164 return 165 } 166 167 result, err = client.ListByDatabaseAccountResponder(resp) 168 if err != nil { 169 err = autorest.NewErrorWithError(err, "documentdb.PrivateLinkResourcesClient", "ListByDatabaseAccount", resp, "Failure responding to request") 170 return 171 } 172 173 return 174} 175 176// ListByDatabaseAccountPreparer prepares the ListByDatabaseAccount request. 177func (client PrivateLinkResourcesClient) ListByDatabaseAccountPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 178 pathParameters := map[string]interface{}{ 179 "accountName": autorest.Encode("path", accountName), 180 "resourceGroupName": autorest.Encode("path", resourceGroupName), 181 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 182 } 183 184 const APIVersion = "2021-03-01-preview" 185 queryParameters := map[string]interface{}{ 186 "api-version": APIVersion, 187 } 188 189 preparer := autorest.CreatePreparer( 190 autorest.AsGet(), 191 autorest.WithBaseURL(client.BaseURI), 192 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/privateLinkResources", pathParameters), 193 autorest.WithQueryParameters(queryParameters)) 194 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 195} 196 197// ListByDatabaseAccountSender sends the ListByDatabaseAccount request. The method will close the 198// http.Response Body if it receives an error. 199func (client PrivateLinkResourcesClient) ListByDatabaseAccountSender(req *http.Request) (*http.Response, error) { 200 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 201} 202 203// ListByDatabaseAccountResponder handles the response to the ListByDatabaseAccount request. The method always 204// closes the http.Response Body. 205func (client PrivateLinkResourcesClient) ListByDatabaseAccountResponder(resp *http.Response) (result PrivateLinkResourceListResult, err error) { 206 err = autorest.Respond( 207 resp, 208 azure.WithErrorUnlessStatusCode(http.StatusOK), 209 autorest.ByUnmarshallingJSON(&result), 210 autorest.ByClosing()) 211 result.Response = autorest.Response{Response: resp} 212 return 213} 214