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