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