1package sql 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 the Azure SQL Database management API provides a RESTful set of web services 19// that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, 20// update, and delete databases. 21type PrivateEndpointConnectionsClient struct { 22 BaseClient 23} 24 25// NewPrivateEndpointConnectionsClient creates an instance of the PrivateEndpointConnectionsClient client. 26func NewPrivateEndpointConnectionsClient(subscriptionID string) PrivateEndpointConnectionsClient { 27 return NewPrivateEndpointConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewPrivateEndpointConnectionsClientWithBaseURI creates an instance of the PrivateEndpointConnectionsClient client 31// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 32// clouds, Azure stack). 33func NewPrivateEndpointConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointConnectionsClient { 34 return PrivateEndpointConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)} 35} 36 37// CreateOrUpdate approve or reject a private endpoint connection with a given name. 38// Parameters: 39// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 40// from the Azure Resource Manager API or the portal. 41// serverName - the name of the server. 42func (client PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection) (result PrivateEndpointConnectionsCreateOrUpdateFuture, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.CreateOrUpdate") 45 defer func() { 46 sc := -1 47 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 48 sc = result.FutureAPI.Response().StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 if err := validation.Validate([]validation.Validation{ 54 {TargetValue: parameters, 55 Constraints: []validation.Constraint{{Target: "parameters.PrivateEndpointConnectionProperties", Name: validation.Null, Rule: false, 56 Chain: []validation.Constraint{{Target: "parameters.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState", Name: validation.Null, Rule: false, 57 Chain: []validation.Constraint{{Target: "parameters.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState.Status", Name: validation.Null, Rule: true, Chain: nil}, 58 {Target: "parameters.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState.Description", Name: validation.Null, Rule: true, Chain: nil}, 59 }}, 60 }}}}}); err != nil { 61 return result, validation.NewError("sql.PrivateEndpointConnectionsClient", "CreateOrUpdate", err.Error()) 62 } 63 64 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, privateEndpointConnectionName, parameters) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "sql.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, "sql.PrivateEndpointConnectionsClient", "CreateOrUpdate", nil, "Failure sending request") 73 return 74 } 75 76 return 77} 78 79// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 80func (client PrivateEndpointConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "serverName": autorest.Encode("path", serverName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2018-06-01-preview" 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.Sql/servers/{serverName}/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. 105func (client PrivateEndpointConnectionsClient) CreateOrUpdateSender(req *http.Request) (future PrivateEndpointConnectionsCreateOrUpdateFuture, err error) { 106 var resp *http.Response 107 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 108 if err != nil { 109 return 110 } 111 var azf azure.Future 112 azf, err = azure.NewFutureFromResponse(resp) 113 future.FutureAPI = &azf 114 future.Result = future.result 115 return 116} 117 118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 119// closes the http.Response Body. 120func (client PrivateEndpointConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 121 err = autorest.Respond( 122 resp, 123 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Delete deletes a private endpoint connection with a given name. 131// Parameters: 132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 133// from the Azure Resource Manager API or the portal. 134// serverName - the name of the server. 135func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, serverName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) { 136 if tracing.IsEnabled() { 137 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete") 138 defer func() { 139 sc := -1 140 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 141 sc = result.FutureAPI.Response().StatusCode 142 } 143 tracing.EndSpan(ctx, sc, err) 144 }() 145 } 146 req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, privateEndpointConnectionName) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request") 149 return 150 } 151 152 result, err = client.DeleteSender(req) 153 if err != nil { 154 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "Delete", nil, "Failure sending request") 155 return 156 } 157 158 return 159} 160 161// DeletePreparer prepares the Delete request. 162func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, privateEndpointConnectionName string) (*http.Request, error) { 163 pathParameters := map[string]interface{}{ 164 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 165 "resourceGroupName": autorest.Encode("path", resourceGroupName), 166 "serverName": autorest.Encode("path", serverName), 167 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 168 } 169 170 const APIVersion = "2018-06-01-preview" 171 queryParameters := map[string]interface{}{ 172 "api-version": APIVersion, 173 } 174 175 preparer := autorest.CreatePreparer( 176 autorest.AsDelete(), 177 autorest.WithBaseURL(client.BaseURI), 178 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 179 autorest.WithQueryParameters(queryParameters)) 180 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 181} 182 183// DeleteSender sends the Delete request. The method will close the 184// http.Response Body if it receives an error. 185func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) { 186 var resp *http.Response 187 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 188 if err != nil { 189 return 190 } 191 var azf azure.Future 192 azf, err = azure.NewFutureFromResponse(resp) 193 future.FutureAPI = &azf 194 future.Result = future.result 195 return 196} 197 198// DeleteResponder handles the response to the Delete request. The method always 199// closes the http.Response Body. 200func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 201 err = autorest.Respond( 202 resp, 203 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 204 autorest.ByClosing()) 205 result.Response = resp 206 return 207} 208 209// Get gets a private endpoint connection. 210// Parameters: 211// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 212// from the Azure Resource Manager API or the portal. 213// serverName - the name of the server. 214// privateEndpointConnectionName - the name of the private endpoint connection. 215func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, serverName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) { 216 if tracing.IsEnabled() { 217 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get") 218 defer func() { 219 sc := -1 220 if result.Response.Response != nil { 221 sc = result.Response.Response.StatusCode 222 } 223 tracing.EndSpan(ctx, sc, err) 224 }() 225 } 226 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, privateEndpointConnectionName) 227 if err != nil { 228 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request") 229 return 230 } 231 232 resp, err := client.GetSender(req) 233 if err != nil { 234 result.Response = autorest.Response{Response: resp} 235 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request") 236 return 237 } 238 239 result, err = client.GetResponder(resp) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request") 242 return 243 } 244 245 return 246} 247 248// GetPreparer prepares the Get request. 249func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, privateEndpointConnectionName string) (*http.Request, error) { 250 pathParameters := map[string]interface{}{ 251 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 252 "resourceGroupName": autorest.Encode("path", resourceGroupName), 253 "serverName": autorest.Encode("path", serverName), 254 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 255 } 256 257 const APIVersion = "2018-06-01-preview" 258 queryParameters := map[string]interface{}{ 259 "api-version": APIVersion, 260 } 261 262 preparer := autorest.CreatePreparer( 263 autorest.AsGet(), 264 autorest.WithBaseURL(client.BaseURI), 265 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 266 autorest.WithQueryParameters(queryParameters)) 267 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 268} 269 270// GetSender sends the Get request. The method will close the 271// http.Response Body if it receives an error. 272func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) { 273 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 274} 275 276// GetResponder handles the response to the Get request. The method always 277// closes the http.Response Body. 278func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 279 err = autorest.Respond( 280 resp, 281 azure.WithErrorUnlessStatusCode(http.StatusOK), 282 autorest.ByUnmarshallingJSON(&result), 283 autorest.ByClosing()) 284 result.Response = autorest.Response{Response: resp} 285 return 286} 287 288// ListByServer gets all private endpoint connections on a server. 289// Parameters: 290// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 291// from the Azure Resource Manager API or the portal. 292// serverName - the name of the server. 293func (client PrivateEndpointConnectionsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result PrivateEndpointConnectionListResultPage, err error) { 294 if tracing.IsEnabled() { 295 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByServer") 296 defer func() { 297 sc := -1 298 if result.peclr.Response.Response != nil { 299 sc = result.peclr.Response.Response.StatusCode 300 } 301 tracing.EndSpan(ctx, sc, err) 302 }() 303 } 304 result.fn = client.listByServerNextResults 305 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 306 if err != nil { 307 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "ListByServer", nil, "Failure preparing request") 308 return 309 } 310 311 resp, err := client.ListByServerSender(req) 312 if err != nil { 313 result.peclr.Response = autorest.Response{Response: resp} 314 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "ListByServer", resp, "Failure sending request") 315 return 316 } 317 318 result.peclr, err = client.ListByServerResponder(resp) 319 if err != nil { 320 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "ListByServer", resp, "Failure responding to request") 321 return 322 } 323 if result.peclr.hasNextLink() && result.peclr.IsEmpty() { 324 err = result.NextWithContext(ctx) 325 return 326 } 327 328 return 329} 330 331// ListByServerPreparer prepares the ListByServer request. 332func (client PrivateEndpointConnectionsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 333 pathParameters := map[string]interface{}{ 334 "resourceGroupName": autorest.Encode("path", resourceGroupName), 335 "serverName": autorest.Encode("path", serverName), 336 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 337 } 338 339 const APIVersion = "2018-06-01-preview" 340 queryParameters := map[string]interface{}{ 341 "api-version": APIVersion, 342 } 343 344 preparer := autorest.CreatePreparer( 345 autorest.AsGet(), 346 autorest.WithBaseURL(client.BaseURI), 347 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections", pathParameters), 348 autorest.WithQueryParameters(queryParameters)) 349 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 350} 351 352// ListByServerSender sends the ListByServer request. The method will close the 353// http.Response Body if it receives an error. 354func (client PrivateEndpointConnectionsClient) ListByServerSender(req *http.Request) (*http.Response, error) { 355 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 356} 357 358// ListByServerResponder handles the response to the ListByServer request. The method always 359// closes the http.Response Body. 360func (client PrivateEndpointConnectionsClient) ListByServerResponder(resp *http.Response) (result PrivateEndpointConnectionListResult, err error) { 361 err = autorest.Respond( 362 resp, 363 azure.WithErrorUnlessStatusCode(http.StatusOK), 364 autorest.ByUnmarshallingJSON(&result), 365 autorest.ByClosing()) 366 result.Response = autorest.Response{Response: resp} 367 return 368} 369 370// listByServerNextResults retrieves the next set of results, if any. 371func (client PrivateEndpointConnectionsClient) listByServerNextResults(ctx context.Context, lastResults PrivateEndpointConnectionListResult) (result PrivateEndpointConnectionListResult, err error) { 372 req, err := lastResults.privateEndpointConnectionListResultPreparer(ctx) 373 if err != nil { 374 return result, autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "listByServerNextResults", nil, "Failure preparing next results request") 375 } 376 if req == nil { 377 return 378 } 379 resp, err := client.ListByServerSender(req) 380 if err != nil { 381 result.Response = autorest.Response{Response: resp} 382 return result, autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "listByServerNextResults", resp, "Failure sending next results request") 383 } 384 result, err = client.ListByServerResponder(resp) 385 if err != nil { 386 err = autorest.NewErrorWithError(err, "sql.PrivateEndpointConnectionsClient", "listByServerNextResults", resp, "Failure responding to next results request") 387 } 388 return 389} 390 391// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 392func (client PrivateEndpointConnectionsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result PrivateEndpointConnectionListResultIterator, err error) { 393 if tracing.IsEnabled() { 394 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByServer") 395 defer func() { 396 sc := -1 397 if result.Response().Response.Response != nil { 398 sc = result.page.Response().Response.Response.StatusCode 399 } 400 tracing.EndSpan(ctx, sc, err) 401 }() 402 } 403 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName) 404 return 405} 406