1package network 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/tracing" 25 "net/http" 26) 27 28// PrivateEndpointsClient is the network Client 29type PrivateEndpointsClient struct { 30 BaseClient 31} 32 33// NewPrivateEndpointsClient creates an instance of the PrivateEndpointsClient client. 34func NewPrivateEndpointsClient(subscriptionID string) PrivateEndpointsClient { 35 return NewPrivateEndpointsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewPrivateEndpointsClientWithBaseURI creates an instance of the PrivateEndpointsClient client using a custom 39// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 40// stack). 41func NewPrivateEndpointsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointsClient { 42 return PrivateEndpointsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate creates or updates an private endpoint in the specified resource group. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// privateEndpointName - the name of the private endpoint. 49// parameters - parameters supplied to the create or update private endpoint operation. 50func (client PrivateEndpointsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, privateEndpointName string, parameters PrivateEndpoint) (result PrivateEndpointsCreateOrUpdateFuture, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.CreateOrUpdate") 53 defer func() { 54 sc := -1 55 if result.Response() != nil { 56 sc = result.Response().StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, privateEndpointName, parameters) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "CreateOrUpdate", nil, "Failure preparing request") 64 return 65 } 66 67 result, err = client.CreateOrUpdateSender(req) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "CreateOrUpdate", nil, "Failure sending request") 70 return 71 } 72 73 return 74} 75 76// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 77func (client PrivateEndpointsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, privateEndpointName string, parameters PrivateEndpoint) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "privateEndpointName": autorest.Encode("path", privateEndpointName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2019-07-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPut(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateEndpoints/{privateEndpointName}", pathParameters), 94 autorest.WithJSON(parameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 100// http.Response Body if it receives an error. 101func (client PrivateEndpointsClient) CreateOrUpdateSender(req *http.Request) (future PrivateEndpointsCreateOrUpdateFuture, err error) { 102 var resp *http.Response 103 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104 if err != nil { 105 return 106 } 107 var azf azure.Future 108 azf, err = azure.NewFutureFromResponse(resp) 109 future.FutureAPI = &azf 110 future.Result = func(client PrivateEndpointsClient) (peVar PrivateEndpoint, err error) { 111 var done bool 112 done, err = future.DoneWithContext(context.Background(), client) 113 if err != nil { 114 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 115 return 116 } 117 if !done { 118 err = azure.NewAsyncOpIncompleteError("network.PrivateEndpointsCreateOrUpdateFuture") 119 return 120 } 121 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 122 if peVar.Response.Response, err = future.GetResult(sender); err == nil && peVar.Response.Response.StatusCode != http.StatusNoContent { 123 peVar, err = client.CreateOrUpdateResponder(peVar.Response.Response) 124 if err != nil { 125 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsCreateOrUpdateFuture", "Result", peVar.Response.Response, "Failure responding to request") 126 } 127 } 128 return 129 } 130 return 131} 132 133// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 134// closes the http.Response Body. 135func (client PrivateEndpointsClient) CreateOrUpdateResponder(resp *http.Response) (result PrivateEndpoint, err error) { 136 err = autorest.Respond( 137 resp, 138 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 139 autorest.ByUnmarshallingJSON(&result), 140 autorest.ByClosing()) 141 result.Response = autorest.Response{Response: resp} 142 return 143} 144 145// Delete deletes the specified private endpoint. 146// Parameters: 147// resourceGroupName - the name of the resource group. 148// privateEndpointName - the name of the private endpoint. 149func (client PrivateEndpointsClient) Delete(ctx context.Context, resourceGroupName string, privateEndpointName string) (result PrivateEndpointsDeleteFuture, err error) { 150 if tracing.IsEnabled() { 151 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.Delete") 152 defer func() { 153 sc := -1 154 if result.Response() != nil { 155 sc = result.Response().StatusCode 156 } 157 tracing.EndSpan(ctx, sc, err) 158 }() 159 } 160 req, err := client.DeletePreparer(ctx, resourceGroupName, privateEndpointName) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "Delete", nil, "Failure preparing request") 163 return 164 } 165 166 result, err = client.DeleteSender(req) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "Delete", nil, "Failure sending request") 169 return 170 } 171 172 return 173} 174 175// DeletePreparer prepares the Delete request. 176func (client PrivateEndpointsClient) DeletePreparer(ctx context.Context, resourceGroupName string, privateEndpointName string) (*http.Request, error) { 177 pathParameters := map[string]interface{}{ 178 "privateEndpointName": autorest.Encode("path", privateEndpointName), 179 "resourceGroupName": autorest.Encode("path", resourceGroupName), 180 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 181 } 182 183 const APIVersion = "2019-07-01" 184 queryParameters := map[string]interface{}{ 185 "api-version": APIVersion, 186 } 187 188 preparer := autorest.CreatePreparer( 189 autorest.AsDelete(), 190 autorest.WithBaseURL(client.BaseURI), 191 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateEndpoints/{privateEndpointName}", pathParameters), 192 autorest.WithQueryParameters(queryParameters)) 193 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 194} 195 196// DeleteSender sends the Delete request. The method will close the 197// http.Response Body if it receives an error. 198func (client PrivateEndpointsClient) DeleteSender(req *http.Request) (future PrivateEndpointsDeleteFuture, err error) { 199 var resp *http.Response 200 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 201 if err != nil { 202 return 203 } 204 var azf azure.Future 205 azf, err = azure.NewFutureFromResponse(resp) 206 future.FutureAPI = &azf 207 future.Result = func(client PrivateEndpointsClient) (ar autorest.Response, err error) { 208 var done bool 209 done, err = future.DoneWithContext(context.Background(), client) 210 if err != nil { 211 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsDeleteFuture", "Result", future.Response(), "Polling failure") 212 return 213 } 214 if !done { 215 err = azure.NewAsyncOpIncompleteError("network.PrivateEndpointsDeleteFuture") 216 return 217 } 218 ar.Response = future.Response() 219 return 220 } 221 return 222} 223 224// DeleteResponder handles the response to the Delete request. The method always 225// closes the http.Response Body. 226func (client PrivateEndpointsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 227 err = autorest.Respond( 228 resp, 229 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 230 autorest.ByClosing()) 231 result.Response = resp 232 return 233} 234 235// Get gets the specified private endpoint by resource group. 236// Parameters: 237// resourceGroupName - the name of the resource group. 238// privateEndpointName - the name of the private endpoint. 239// expand - expands referenced resources. 240func (client PrivateEndpointsClient) Get(ctx context.Context, resourceGroupName string, privateEndpointName string, expand string) (result PrivateEndpoint, err error) { 241 if tracing.IsEnabled() { 242 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.Get") 243 defer func() { 244 sc := -1 245 if result.Response.Response != nil { 246 sc = result.Response.Response.StatusCode 247 } 248 tracing.EndSpan(ctx, sc, err) 249 }() 250 } 251 req, err := client.GetPreparer(ctx, resourceGroupName, privateEndpointName, expand) 252 if err != nil { 253 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "Get", nil, "Failure preparing request") 254 return 255 } 256 257 resp, err := client.GetSender(req) 258 if err != nil { 259 result.Response = autorest.Response{Response: resp} 260 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "Get", resp, "Failure sending request") 261 return 262 } 263 264 result, err = client.GetResponder(resp) 265 if err != nil { 266 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "Get", resp, "Failure responding to request") 267 return 268 } 269 270 return 271} 272 273// GetPreparer prepares the Get request. 274func (client PrivateEndpointsClient) GetPreparer(ctx context.Context, resourceGroupName string, privateEndpointName string, expand string) (*http.Request, error) { 275 pathParameters := map[string]interface{}{ 276 "privateEndpointName": autorest.Encode("path", privateEndpointName), 277 "resourceGroupName": autorest.Encode("path", resourceGroupName), 278 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 279 } 280 281 const APIVersion = "2019-07-01" 282 queryParameters := map[string]interface{}{ 283 "api-version": APIVersion, 284 } 285 if len(expand) > 0 { 286 queryParameters["$expand"] = autorest.Encode("query", expand) 287 } 288 289 preparer := autorest.CreatePreparer( 290 autorest.AsGet(), 291 autorest.WithBaseURL(client.BaseURI), 292 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateEndpoints/{privateEndpointName}", pathParameters), 293 autorest.WithQueryParameters(queryParameters)) 294 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 295} 296 297// GetSender sends the Get request. The method will close the 298// http.Response Body if it receives an error. 299func (client PrivateEndpointsClient) GetSender(req *http.Request) (*http.Response, error) { 300 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 301} 302 303// GetResponder handles the response to the Get request. The method always 304// closes the http.Response Body. 305func (client PrivateEndpointsClient) GetResponder(resp *http.Response) (result PrivateEndpoint, err error) { 306 err = autorest.Respond( 307 resp, 308 azure.WithErrorUnlessStatusCode(http.StatusOK), 309 autorest.ByUnmarshallingJSON(&result), 310 autorest.ByClosing()) 311 result.Response = autorest.Response{Response: resp} 312 return 313} 314 315// List gets all private endpoints in a resource group. 316// Parameters: 317// resourceGroupName - the name of the resource group. 318func (client PrivateEndpointsClient) List(ctx context.Context, resourceGroupName string) (result PrivateEndpointListResultPage, err error) { 319 if tracing.IsEnabled() { 320 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.List") 321 defer func() { 322 sc := -1 323 if result.pelr.Response.Response != nil { 324 sc = result.pelr.Response.Response.StatusCode 325 } 326 tracing.EndSpan(ctx, sc, err) 327 }() 328 } 329 result.fn = client.listNextResults 330 req, err := client.ListPreparer(ctx, resourceGroupName) 331 if err != nil { 332 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "List", nil, "Failure preparing request") 333 return 334 } 335 336 resp, err := client.ListSender(req) 337 if err != nil { 338 result.pelr.Response = autorest.Response{Response: resp} 339 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "List", resp, "Failure sending request") 340 return 341 } 342 343 result.pelr, err = client.ListResponder(resp) 344 if err != nil { 345 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "List", resp, "Failure responding to request") 346 return 347 } 348 if result.pelr.hasNextLink() && result.pelr.IsEmpty() { 349 err = result.NextWithContext(ctx) 350 return 351 } 352 353 return 354} 355 356// ListPreparer prepares the List request. 357func (client PrivateEndpointsClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 358 pathParameters := map[string]interface{}{ 359 "resourceGroupName": autorest.Encode("path", resourceGroupName), 360 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 361 } 362 363 const APIVersion = "2019-07-01" 364 queryParameters := map[string]interface{}{ 365 "api-version": APIVersion, 366 } 367 368 preparer := autorest.CreatePreparer( 369 autorest.AsGet(), 370 autorest.WithBaseURL(client.BaseURI), 371 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateEndpoints", pathParameters), 372 autorest.WithQueryParameters(queryParameters)) 373 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 374} 375 376// ListSender sends the List request. The method will close the 377// http.Response Body if it receives an error. 378func (client PrivateEndpointsClient) ListSender(req *http.Request) (*http.Response, error) { 379 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 380} 381 382// ListResponder handles the response to the List request. The method always 383// closes the http.Response Body. 384func (client PrivateEndpointsClient) ListResponder(resp *http.Response) (result PrivateEndpointListResult, err error) { 385 err = autorest.Respond( 386 resp, 387 azure.WithErrorUnlessStatusCode(http.StatusOK), 388 autorest.ByUnmarshallingJSON(&result), 389 autorest.ByClosing()) 390 result.Response = autorest.Response{Response: resp} 391 return 392} 393 394// listNextResults retrieves the next set of results, if any. 395func (client PrivateEndpointsClient) listNextResults(ctx context.Context, lastResults PrivateEndpointListResult) (result PrivateEndpointListResult, err error) { 396 req, err := lastResults.privateEndpointListResultPreparer(ctx) 397 if err != nil { 398 return result, autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "listNextResults", nil, "Failure preparing next results request") 399 } 400 if req == nil { 401 return 402 } 403 resp, err := client.ListSender(req) 404 if err != nil { 405 result.Response = autorest.Response{Response: resp} 406 return result, autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "listNextResults", resp, "Failure sending next results request") 407 } 408 result, err = client.ListResponder(resp) 409 if err != nil { 410 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "listNextResults", resp, "Failure responding to next results request") 411 } 412 return 413} 414 415// ListComplete enumerates all values, automatically crossing page boundaries as required. 416func (client PrivateEndpointsClient) ListComplete(ctx context.Context, resourceGroupName string) (result PrivateEndpointListResultIterator, err error) { 417 if tracing.IsEnabled() { 418 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.List") 419 defer func() { 420 sc := -1 421 if result.Response().Response.Response != nil { 422 sc = result.page.Response().Response.Response.StatusCode 423 } 424 tracing.EndSpan(ctx, sc, err) 425 }() 426 } 427 result.page, err = client.List(ctx, resourceGroupName) 428 return 429} 430 431// ListBySubscription gets all private endpoints in a subscription. 432func (client PrivateEndpointsClient) ListBySubscription(ctx context.Context) (result PrivateEndpointListResultPage, err error) { 433 if tracing.IsEnabled() { 434 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.ListBySubscription") 435 defer func() { 436 sc := -1 437 if result.pelr.Response.Response != nil { 438 sc = result.pelr.Response.Response.StatusCode 439 } 440 tracing.EndSpan(ctx, sc, err) 441 }() 442 } 443 result.fn = client.listBySubscriptionNextResults 444 req, err := client.ListBySubscriptionPreparer(ctx) 445 if err != nil { 446 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "ListBySubscription", nil, "Failure preparing request") 447 return 448 } 449 450 resp, err := client.ListBySubscriptionSender(req) 451 if err != nil { 452 result.pelr.Response = autorest.Response{Response: resp} 453 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "ListBySubscription", resp, "Failure sending request") 454 return 455 } 456 457 result.pelr, err = client.ListBySubscriptionResponder(resp) 458 if err != nil { 459 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "ListBySubscription", resp, "Failure responding to request") 460 return 461 } 462 if result.pelr.hasNextLink() && result.pelr.IsEmpty() { 463 err = result.NextWithContext(ctx) 464 return 465 } 466 467 return 468} 469 470// ListBySubscriptionPreparer prepares the ListBySubscription request. 471func (client PrivateEndpointsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { 472 pathParameters := map[string]interface{}{ 473 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 474 } 475 476 const APIVersion = "2019-07-01" 477 queryParameters := map[string]interface{}{ 478 "api-version": APIVersion, 479 } 480 481 preparer := autorest.CreatePreparer( 482 autorest.AsGet(), 483 autorest.WithBaseURL(client.BaseURI), 484 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/privateEndpoints", pathParameters), 485 autorest.WithQueryParameters(queryParameters)) 486 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 487} 488 489// ListBySubscriptionSender sends the ListBySubscription request. The method will close the 490// http.Response Body if it receives an error. 491func (client PrivateEndpointsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { 492 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 493} 494 495// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always 496// closes the http.Response Body. 497func (client PrivateEndpointsClient) ListBySubscriptionResponder(resp *http.Response) (result PrivateEndpointListResult, err error) { 498 err = autorest.Respond( 499 resp, 500 azure.WithErrorUnlessStatusCode(http.StatusOK), 501 autorest.ByUnmarshallingJSON(&result), 502 autorest.ByClosing()) 503 result.Response = autorest.Response{Response: resp} 504 return 505} 506 507// listBySubscriptionNextResults retrieves the next set of results, if any. 508func (client PrivateEndpointsClient) listBySubscriptionNextResults(ctx context.Context, lastResults PrivateEndpointListResult) (result PrivateEndpointListResult, err error) { 509 req, err := lastResults.privateEndpointListResultPreparer(ctx) 510 if err != nil { 511 return result, autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request") 512 } 513 if req == nil { 514 return 515 } 516 resp, err := client.ListBySubscriptionSender(req) 517 if err != nil { 518 result.Response = autorest.Response{Response: resp} 519 return result, autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "listBySubscriptionNextResults", resp, "Failure sending next results request") 520 } 521 result, err = client.ListBySubscriptionResponder(resp) 522 if err != nil { 523 err = autorest.NewErrorWithError(err, "network.PrivateEndpointsClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request") 524 } 525 return 526} 527 528// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required. 529func (client PrivateEndpointsClient) ListBySubscriptionComplete(ctx context.Context) (result PrivateEndpointListResultIterator, err error) { 530 if tracing.IsEnabled() { 531 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointsClient.ListBySubscription") 532 defer func() { 533 sc := -1 534 if result.Response().Response.Response != nil { 535 sc = result.page.Response().Response.Response.StatusCode 536 } 537 tracing.EndSpan(ctx, sc, err) 538 }() 539 } 540 result.page, err = client.ListBySubscription(ctx) 541 return 542} 543