1// +build go1.13 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// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armnetwork 9 10import ( 11 "context" 12 "errors" 13 "fmt" 14 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 16 "net/http" 17 "net/url" 18 "strings" 19 "time" 20) 21 22// NetworkManagementClient contains the methods for the NetworkManagementClient group. 23// Don't use this type directly, use NewNetworkManagementClient() instead. 24type NetworkManagementClient struct { 25 con *armcore.Connection 26 subscriptionID string 27} 28 29// NewNetworkManagementClient creates a new instance of NetworkManagementClient with the specified values. 30func NewNetworkManagementClient(con *armcore.Connection, subscriptionID string) *NetworkManagementClient { 31 return &NetworkManagementClient{con: con, subscriptionID: subscriptionID} 32} 33 34// CheckDNSNameAvailability - Checks whether a domain name in the cloudapp.azure.com zone is available for use. 35// If the operation fails it returns the *CloudError error type. 36func (client *NetworkManagementClient) CheckDNSNameAvailability(ctx context.Context, location string, domainNameLabel string, options *NetworkManagementClientCheckDNSNameAvailabilityOptions) (DNSNameAvailabilityResultResponse, error) { 37 req, err := client.checkDNSNameAvailabilityCreateRequest(ctx, location, domainNameLabel, options) 38 if err != nil { 39 return DNSNameAvailabilityResultResponse{}, err 40 } 41 resp, err := client.con.Pipeline().Do(req) 42 if err != nil { 43 return DNSNameAvailabilityResultResponse{}, err 44 } 45 if !resp.HasStatusCode(http.StatusOK) { 46 return DNSNameAvailabilityResultResponse{}, client.checkDNSNameAvailabilityHandleError(resp) 47 } 48 return client.checkDNSNameAvailabilityHandleResponse(resp) 49} 50 51// checkDNSNameAvailabilityCreateRequest creates the CheckDNSNameAvailability request. 52func (client *NetworkManagementClient) checkDNSNameAvailabilityCreateRequest(ctx context.Context, location string, domainNameLabel string, options *NetworkManagementClientCheckDNSNameAvailabilityOptions) (*azcore.Request, error) { 53 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/CheckDnsNameAvailability" 54 if location == "" { 55 return nil, errors.New("parameter location cannot be empty") 56 } 57 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 58 if client.subscriptionID == "" { 59 return nil, errors.New("parameter client.subscriptionID cannot be empty") 60 } 61 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 62 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 63 if err != nil { 64 return nil, err 65 } 66 req.Telemetry(telemetryInfo) 67 reqQP := req.URL.Query() 68 reqQP.Set("domainNameLabel", domainNameLabel) 69 reqQP.Set("api-version", "2021-02-01") 70 req.URL.RawQuery = reqQP.Encode() 71 req.Header.Set("Accept", "application/json") 72 return req, nil 73} 74 75// checkDNSNameAvailabilityHandleResponse handles the CheckDNSNameAvailability response. 76func (client *NetworkManagementClient) checkDNSNameAvailabilityHandleResponse(resp *azcore.Response) (DNSNameAvailabilityResultResponse, error) { 77 var val *DNSNameAvailabilityResult 78 if err := resp.UnmarshalAsJSON(&val); err != nil { 79 return DNSNameAvailabilityResultResponse{}, err 80 } 81 return DNSNameAvailabilityResultResponse{RawResponse: resp.Response, DNSNameAvailabilityResult: val}, nil 82} 83 84// checkDNSNameAvailabilityHandleError handles the CheckDNSNameAvailability error response. 85func (client *NetworkManagementClient) checkDNSNameAvailabilityHandleError(resp *azcore.Response) error { 86 body, err := resp.Payload() 87 if err != nil { 88 return azcore.NewResponseError(err, resp.Response) 89 } 90 errType := CloudError{raw: string(body)} 91 if err := resp.UnmarshalAsJSON(&errType); err != nil { 92 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 93 } 94 return azcore.NewResponseError(&errType, resp.Response) 95} 96 97// BeginDeleteBastionShareableLink - Deletes the Bastion Shareable Links for all the VMs specified in the request. 98// If the operation fails it returns the *CloudError error type. 99func (client *NetworkManagementClient) BeginDeleteBastionShareableLink(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientBeginDeleteBastionShareableLinkOptions) (HTTPPollerResponse, error) { 100 resp, err := client.deleteBastionShareableLink(ctx, resourceGroupName, bastionHostName, bslRequest, options) 101 if err != nil { 102 return HTTPPollerResponse{}, err 103 } 104 result := HTTPPollerResponse{ 105 RawResponse: resp.Response, 106 } 107 pt, err := armcore.NewLROPoller("NetworkManagementClient.DeleteBastionShareableLink", "location", resp, client.con.Pipeline(), client.deleteBastionShareableLinkHandleError) 108 if err != nil { 109 return HTTPPollerResponse{}, err 110 } 111 poller := &httpPoller{ 112 pt: pt, 113 } 114 result.Poller = poller 115 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 116 return poller.pollUntilDone(ctx, frequency) 117 } 118 return result, nil 119} 120 121// ResumeDeleteBastionShareableLink creates a new HTTPPoller from the specified resume token. 122// token - The value must come from a previous call to HTTPPoller.ResumeToken(). 123func (client *NetworkManagementClient) ResumeDeleteBastionShareableLink(ctx context.Context, token string) (HTTPPollerResponse, error) { 124 pt, err := armcore.NewLROPollerFromResumeToken("NetworkManagementClient.DeleteBastionShareableLink", token, client.con.Pipeline(), client.deleteBastionShareableLinkHandleError) 125 if err != nil { 126 return HTTPPollerResponse{}, err 127 } 128 poller := &httpPoller{ 129 pt: pt, 130 } 131 resp, err := poller.Poll(ctx) 132 if err != nil { 133 return HTTPPollerResponse{}, err 134 } 135 result := HTTPPollerResponse{ 136 RawResponse: resp, 137 } 138 result.Poller = poller 139 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 140 return poller.pollUntilDone(ctx, frequency) 141 } 142 return result, nil 143} 144 145// DeleteBastionShareableLink - Deletes the Bastion Shareable Links for all the VMs specified in the request. 146// If the operation fails it returns the *CloudError error type. 147func (client *NetworkManagementClient) deleteBastionShareableLink(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientBeginDeleteBastionShareableLinkOptions) (*azcore.Response, error) { 148 req, err := client.deleteBastionShareableLinkCreateRequest(ctx, resourceGroupName, bastionHostName, bslRequest, options) 149 if err != nil { 150 return nil, err 151 } 152 resp, err := client.con.Pipeline().Do(req) 153 if err != nil { 154 return nil, err 155 } 156 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 157 return nil, client.deleteBastionShareableLinkHandleError(resp) 158 } 159 return resp, nil 160} 161 162// deleteBastionShareableLinkCreateRequest creates the DeleteBastionShareableLink request. 163func (client *NetworkManagementClient) deleteBastionShareableLinkCreateRequest(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientBeginDeleteBastionShareableLinkOptions) (*azcore.Request, error) { 164 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}/deleteShareableLinks" 165 if resourceGroupName == "" { 166 return nil, errors.New("parameter resourceGroupName cannot be empty") 167 } 168 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 169 if bastionHostName == "" { 170 return nil, errors.New("parameter bastionHostName cannot be empty") 171 } 172 urlPath = strings.ReplaceAll(urlPath, "{bastionHostName}", url.PathEscape(bastionHostName)) 173 if client.subscriptionID == "" { 174 return nil, errors.New("parameter client.subscriptionID cannot be empty") 175 } 176 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 177 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 178 if err != nil { 179 return nil, err 180 } 181 req.Telemetry(telemetryInfo) 182 reqQP := req.URL.Query() 183 reqQP.Set("api-version", "2021-02-01") 184 req.URL.RawQuery = reqQP.Encode() 185 req.Header.Set("Accept", "application/json") 186 return req, req.MarshalAsJSON(bslRequest) 187} 188 189// deleteBastionShareableLinkHandleError handles the DeleteBastionShareableLink error response. 190func (client *NetworkManagementClient) deleteBastionShareableLinkHandleError(resp *azcore.Response) error { 191 body, err := resp.Payload() 192 if err != nil { 193 return azcore.NewResponseError(err, resp.Response) 194 } 195 errType := CloudError{raw: string(body)} 196 if err := resp.UnmarshalAsJSON(&errType); err != nil { 197 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 198 } 199 return azcore.NewResponseError(&errType, resp.Response) 200} 201 202// DisconnectActiveSessions - Returns the list of currently active sessions on the Bastion. 203// If the operation fails it returns the *CloudError error type. 204func (client *NetworkManagementClient) DisconnectActiveSessions(resourceGroupName string, bastionHostName string, sessionIDs SessionIDs, options *NetworkManagementClientDisconnectActiveSessionsOptions) BastionSessionDeleteResultPager { 205 return &bastionSessionDeleteResultPager{ 206 pipeline: client.con.Pipeline(), 207 requester: func(ctx context.Context) (*azcore.Request, error) { 208 return client.disconnectActiveSessionsCreateRequest(ctx, resourceGroupName, bastionHostName, sessionIDs, options) 209 }, 210 responder: client.disconnectActiveSessionsHandleResponse, 211 errorer: client.disconnectActiveSessionsHandleError, 212 advancer: func(ctx context.Context, resp BastionSessionDeleteResultResponse) (*azcore.Request, error) { 213 return azcore.NewRequest(ctx, http.MethodGet, *resp.BastionSessionDeleteResult.NextLink) 214 }, 215 statusCodes: []int{http.StatusOK}, 216 } 217} 218 219// disconnectActiveSessionsCreateRequest creates the DisconnectActiveSessions request. 220func (client *NetworkManagementClient) disconnectActiveSessionsCreateRequest(ctx context.Context, resourceGroupName string, bastionHostName string, sessionIDs SessionIDs, options *NetworkManagementClientDisconnectActiveSessionsOptions) (*azcore.Request, error) { 221 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}/disconnectActiveSessions" 222 if resourceGroupName == "" { 223 return nil, errors.New("parameter resourceGroupName cannot be empty") 224 } 225 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 226 if bastionHostName == "" { 227 return nil, errors.New("parameter bastionHostName cannot be empty") 228 } 229 urlPath = strings.ReplaceAll(urlPath, "{bastionHostName}", url.PathEscape(bastionHostName)) 230 if client.subscriptionID == "" { 231 return nil, errors.New("parameter client.subscriptionID cannot be empty") 232 } 233 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 234 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 235 if err != nil { 236 return nil, err 237 } 238 req.Telemetry(telemetryInfo) 239 reqQP := req.URL.Query() 240 reqQP.Set("api-version", "2021-02-01") 241 req.URL.RawQuery = reqQP.Encode() 242 req.Header.Set("Accept", "application/json") 243 return req, req.MarshalAsJSON(sessionIDs) 244} 245 246// disconnectActiveSessionsHandleResponse handles the DisconnectActiveSessions response. 247func (client *NetworkManagementClient) disconnectActiveSessionsHandleResponse(resp *azcore.Response) (BastionSessionDeleteResultResponse, error) { 248 var val *BastionSessionDeleteResult 249 if err := resp.UnmarshalAsJSON(&val); err != nil { 250 return BastionSessionDeleteResultResponse{}, err 251 } 252 return BastionSessionDeleteResultResponse{RawResponse: resp.Response, BastionSessionDeleteResult: val}, nil 253} 254 255// disconnectActiveSessionsHandleError handles the DisconnectActiveSessions error response. 256func (client *NetworkManagementClient) disconnectActiveSessionsHandleError(resp *azcore.Response) error { 257 body, err := resp.Payload() 258 if err != nil { 259 return azcore.NewResponseError(err, resp.Response) 260 } 261 errType := CloudError{raw: string(body)} 262 if err := resp.UnmarshalAsJSON(&errType); err != nil { 263 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 264 } 265 return azcore.NewResponseError(&errType, resp.Response) 266} 267 268// BeginGeneratevirtualwanvpnserverconfigurationvpnprofile - Generates a unique VPN profile for P2S clients for VirtualWan and associated VpnServerConfiguration 269// combination in the specified resource group. 270// If the operation fails it returns the *CloudError error type. 271func (client *NetworkManagementClient) BeginGeneratevirtualwanvpnserverconfigurationvpnprofile(ctx context.Context, resourceGroupName string, virtualWANName string, vpnClientParams VirtualWanVPNProfileParameters, options *NetworkManagementClientBeginGeneratevirtualwanvpnserverconfigurationvpnprofileOptions) (VPNProfileResponsePollerResponse, error) { 272 resp, err := client.generatevirtualwanvpnserverconfigurationvpnprofile(ctx, resourceGroupName, virtualWANName, vpnClientParams, options) 273 if err != nil { 274 return VPNProfileResponsePollerResponse{}, err 275 } 276 result := VPNProfileResponsePollerResponse{ 277 RawResponse: resp.Response, 278 } 279 pt, err := armcore.NewLROPoller("NetworkManagementClient.Generatevirtualwanvpnserverconfigurationvpnprofile", "location", resp, client.con.Pipeline(), client.generatevirtualwanvpnserverconfigurationvpnprofileHandleError) 280 if err != nil { 281 return VPNProfileResponsePollerResponse{}, err 282 } 283 poller := &vpnProfileResponsePoller{ 284 pt: pt, 285 } 286 result.Poller = poller 287 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (VPNProfileResponseResponse, error) { 288 return poller.pollUntilDone(ctx, frequency) 289 } 290 return result, nil 291} 292 293// ResumeGeneratevirtualwanvpnserverconfigurationvpnprofile creates a new VPNProfileResponsePoller from the specified resume token. 294// token - The value must come from a previous call to VPNProfileResponsePoller.ResumeToken(). 295func (client *NetworkManagementClient) ResumeGeneratevirtualwanvpnserverconfigurationvpnprofile(ctx context.Context, token string) (VPNProfileResponsePollerResponse, error) { 296 pt, err := armcore.NewLROPollerFromResumeToken("NetworkManagementClient.Generatevirtualwanvpnserverconfigurationvpnprofile", token, client.con.Pipeline(), client.generatevirtualwanvpnserverconfigurationvpnprofileHandleError) 297 if err != nil { 298 return VPNProfileResponsePollerResponse{}, err 299 } 300 poller := &vpnProfileResponsePoller{ 301 pt: pt, 302 } 303 resp, err := poller.Poll(ctx) 304 if err != nil { 305 return VPNProfileResponsePollerResponse{}, err 306 } 307 result := VPNProfileResponsePollerResponse{ 308 RawResponse: resp, 309 } 310 result.Poller = poller 311 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (VPNProfileResponseResponse, error) { 312 return poller.pollUntilDone(ctx, frequency) 313 } 314 return result, nil 315} 316 317// Generatevirtualwanvpnserverconfigurationvpnprofile - Generates a unique VPN profile for P2S clients for VirtualWan and associated VpnServerConfiguration 318// combination in the specified resource group. 319// If the operation fails it returns the *CloudError error type. 320func (client *NetworkManagementClient) generatevirtualwanvpnserverconfigurationvpnprofile(ctx context.Context, resourceGroupName string, virtualWANName string, vpnClientParams VirtualWanVPNProfileParameters, options *NetworkManagementClientBeginGeneratevirtualwanvpnserverconfigurationvpnprofileOptions) (*azcore.Response, error) { 321 req, err := client.generatevirtualwanvpnserverconfigurationvpnprofileCreateRequest(ctx, resourceGroupName, virtualWANName, vpnClientParams, options) 322 if err != nil { 323 return nil, err 324 } 325 resp, err := client.con.Pipeline().Do(req) 326 if err != nil { 327 return nil, err 328 } 329 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 330 return nil, client.generatevirtualwanvpnserverconfigurationvpnprofileHandleError(resp) 331 } 332 return resp, nil 333} 334 335// generatevirtualwanvpnserverconfigurationvpnprofileCreateRequest creates the Generatevirtualwanvpnserverconfigurationvpnprofile request. 336func (client *NetworkManagementClient) generatevirtualwanvpnserverconfigurationvpnprofileCreateRequest(ctx context.Context, resourceGroupName string, virtualWANName string, vpnClientParams VirtualWanVPNProfileParameters, options *NetworkManagementClientBeginGeneratevirtualwanvpnserverconfigurationvpnprofileOptions) (*azcore.Request, error) { 337 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualWans/{virtualWANName}/GenerateVpnProfile" 338 if client.subscriptionID == "" { 339 return nil, errors.New("parameter client.subscriptionID cannot be empty") 340 } 341 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 342 if resourceGroupName == "" { 343 return nil, errors.New("parameter resourceGroupName cannot be empty") 344 } 345 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 346 if virtualWANName == "" { 347 return nil, errors.New("parameter virtualWANName cannot be empty") 348 } 349 urlPath = strings.ReplaceAll(urlPath, "{virtualWANName}", url.PathEscape(virtualWANName)) 350 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 351 if err != nil { 352 return nil, err 353 } 354 req.Telemetry(telemetryInfo) 355 reqQP := req.URL.Query() 356 reqQP.Set("api-version", "2021-02-01") 357 req.URL.RawQuery = reqQP.Encode() 358 req.Header.Set("Accept", "application/json") 359 return req, req.MarshalAsJSON(vpnClientParams) 360} 361 362// generatevirtualwanvpnserverconfigurationvpnprofileHandleError handles the Generatevirtualwanvpnserverconfigurationvpnprofile error response. 363func (client *NetworkManagementClient) generatevirtualwanvpnserverconfigurationvpnprofileHandleError(resp *azcore.Response) error { 364 body, err := resp.Payload() 365 if err != nil { 366 return azcore.NewResponseError(err, resp.Response) 367 } 368 errType := CloudError{raw: string(body)} 369 if err := resp.UnmarshalAsJSON(&errType); err != nil { 370 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 371 } 372 return azcore.NewResponseError(&errType, resp.Response) 373} 374 375// BeginGetActiveSessions - Returns the list of currently active sessions on the Bastion. 376// If the operation fails it returns the *CloudError error type. 377func (client *NetworkManagementClient) BeginGetActiveSessions(ctx context.Context, resourceGroupName string, bastionHostName string, options *NetworkManagementClientBeginGetActiveSessionsOptions) (BastionActiveSessionListResultPagerPollerResponse, error) { 378 resp, err := client.getActiveSessions(ctx, resourceGroupName, bastionHostName, options) 379 if err != nil { 380 return BastionActiveSessionListResultPagerPollerResponse{}, err 381 } 382 result := BastionActiveSessionListResultPagerPollerResponse{ 383 RawResponse: resp.Response, 384 } 385 pt, err := armcore.NewLROPoller("NetworkManagementClient.GetActiveSessions", "location", resp, client.con.Pipeline(), client.getActiveSessionsHandleError) 386 if err != nil { 387 return BastionActiveSessionListResultPagerPollerResponse{}, err 388 } 389 poller := &bastionActiveSessionListResultPagerPoller{ 390 pt: pt, 391 errHandler: func(resp *azcore.Response) error { 392 if resp.HasStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 393 return nil 394 } 395 return client.getActiveSessionsHandleError(resp) 396 }, 397 respHandler: func(resp *azcore.Response) (BastionActiveSessionListResultResponse, error) { 398 var val *BastionActiveSessionListResult 399 if err := resp.UnmarshalAsJSON(&val); err != nil { 400 return BastionActiveSessionListResultResponse{}, err 401 } 402 return BastionActiveSessionListResultResponse{RawResponse: resp.Response, BastionActiveSessionListResult: val}, nil 403 }, 404 statusCodes: []int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, 405 } 406 result.Poller = poller 407 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (BastionActiveSessionListResultPager, error) { 408 return poller.pollUntilDone(ctx, frequency) 409 } 410 return result, nil 411} 412 413// ResumeGetActiveSessions creates a new BastionActiveSessionListResultPagerPoller from the specified resume token. 414// token - The value must come from a previous call to BastionActiveSessionListResultPagerPoller.ResumeToken(). 415func (client *NetworkManagementClient) ResumeGetActiveSessions(ctx context.Context, token string) (BastionActiveSessionListResultPagerPollerResponse, error) { 416 pt, err := armcore.NewLROPollerFromResumeToken("NetworkManagementClient.GetActiveSessions", token, client.con.Pipeline(), client.getActiveSessionsHandleError) 417 if err != nil { 418 return BastionActiveSessionListResultPagerPollerResponse{}, err 419 } 420 poller := &bastionActiveSessionListResultPagerPoller{ 421 pt: pt, 422 errHandler: func(resp *azcore.Response) error { 423 if resp.HasStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 424 return nil 425 } 426 return client.getActiveSessionsHandleError(resp) 427 }, 428 respHandler: func(resp *azcore.Response) (BastionActiveSessionListResultResponse, error) { 429 var val *BastionActiveSessionListResult 430 if err := resp.UnmarshalAsJSON(&val); err != nil { 431 return BastionActiveSessionListResultResponse{}, err 432 } 433 return BastionActiveSessionListResultResponse{RawResponse: resp.Response, BastionActiveSessionListResult: val}, nil 434 }, 435 statusCodes: []int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, 436 } 437 resp, err := poller.Poll(ctx) 438 if err != nil { 439 return BastionActiveSessionListResultPagerPollerResponse{}, err 440 } 441 result := BastionActiveSessionListResultPagerPollerResponse{ 442 RawResponse: resp, 443 } 444 result.Poller = poller 445 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (BastionActiveSessionListResultPager, error) { 446 return poller.pollUntilDone(ctx, frequency) 447 } 448 return result, nil 449} 450 451// GetActiveSessions - Returns the list of currently active sessions on the Bastion. 452// If the operation fails it returns the *CloudError error type. 453func (client *NetworkManagementClient) getActiveSessions(ctx context.Context, resourceGroupName string, bastionHostName string, options *NetworkManagementClientBeginGetActiveSessionsOptions) (*azcore.Response, error) { 454 req, err := client.getActiveSessionsCreateRequest(ctx, resourceGroupName, bastionHostName, options) 455 if err != nil { 456 return nil, err 457 } 458 resp, err := client.con.Pipeline().Do(req) 459 if err != nil { 460 return nil, err 461 } 462 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 463 return nil, client.getActiveSessionsHandleError(resp) 464 } 465 return resp, nil 466} 467 468// getActiveSessionsCreateRequest creates the GetActiveSessions request. 469func (client *NetworkManagementClient) getActiveSessionsCreateRequest(ctx context.Context, resourceGroupName string, bastionHostName string, options *NetworkManagementClientBeginGetActiveSessionsOptions) (*azcore.Request, error) { 470 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}/getActiveSessions" 471 if resourceGroupName == "" { 472 return nil, errors.New("parameter resourceGroupName cannot be empty") 473 } 474 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 475 if bastionHostName == "" { 476 return nil, errors.New("parameter bastionHostName cannot be empty") 477 } 478 urlPath = strings.ReplaceAll(urlPath, "{bastionHostName}", url.PathEscape(bastionHostName)) 479 if client.subscriptionID == "" { 480 return nil, errors.New("parameter client.subscriptionID cannot be empty") 481 } 482 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 483 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 484 if err != nil { 485 return nil, err 486 } 487 req.Telemetry(telemetryInfo) 488 reqQP := req.URL.Query() 489 reqQP.Set("api-version", "2021-02-01") 490 req.URL.RawQuery = reqQP.Encode() 491 req.Header.Set("Accept", "application/json") 492 return req, nil 493} 494 495// getActiveSessionsHandleError handles the GetActiveSessions error response. 496func (client *NetworkManagementClient) getActiveSessionsHandleError(resp *azcore.Response) error { 497 body, err := resp.Payload() 498 if err != nil { 499 return azcore.NewResponseError(err, resp.Response) 500 } 501 errType := CloudError{raw: string(body)} 502 if err := resp.UnmarshalAsJSON(&errType); err != nil { 503 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 504 } 505 return azcore.NewResponseError(&errType, resp.Response) 506} 507 508// GetBastionShareableLink - Return the Bastion Shareable Links for all the VMs specified in the request. 509// If the operation fails it returns the *CloudError error type. 510func (client *NetworkManagementClient) GetBastionShareableLink(resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientGetBastionShareableLinkOptions) BastionShareableLinkListResultPager { 511 return &bastionShareableLinkListResultPager{ 512 pipeline: client.con.Pipeline(), 513 requester: func(ctx context.Context) (*azcore.Request, error) { 514 return client.getBastionShareableLinkCreateRequest(ctx, resourceGroupName, bastionHostName, bslRequest, options) 515 }, 516 responder: client.getBastionShareableLinkHandleResponse, 517 errorer: client.getBastionShareableLinkHandleError, 518 advancer: func(ctx context.Context, resp BastionShareableLinkListResultResponse) (*azcore.Request, error) { 519 return azcore.NewRequest(ctx, http.MethodGet, *resp.BastionShareableLinkListResult.NextLink) 520 }, 521 statusCodes: []int{http.StatusOK}, 522 } 523} 524 525// getBastionShareableLinkCreateRequest creates the GetBastionShareableLink request. 526func (client *NetworkManagementClient) getBastionShareableLinkCreateRequest(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientGetBastionShareableLinkOptions) (*azcore.Request, error) { 527 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}/getShareableLinks" 528 if resourceGroupName == "" { 529 return nil, errors.New("parameter resourceGroupName cannot be empty") 530 } 531 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 532 if bastionHostName == "" { 533 return nil, errors.New("parameter bastionHostName cannot be empty") 534 } 535 urlPath = strings.ReplaceAll(urlPath, "{bastionHostName}", url.PathEscape(bastionHostName)) 536 if client.subscriptionID == "" { 537 return nil, errors.New("parameter client.subscriptionID cannot be empty") 538 } 539 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 540 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 541 if err != nil { 542 return nil, err 543 } 544 req.Telemetry(telemetryInfo) 545 reqQP := req.URL.Query() 546 reqQP.Set("api-version", "2021-02-01") 547 req.URL.RawQuery = reqQP.Encode() 548 req.Header.Set("Accept", "application/json") 549 return req, req.MarshalAsJSON(bslRequest) 550} 551 552// getBastionShareableLinkHandleResponse handles the GetBastionShareableLink response. 553func (client *NetworkManagementClient) getBastionShareableLinkHandleResponse(resp *azcore.Response) (BastionShareableLinkListResultResponse, error) { 554 var val *BastionShareableLinkListResult 555 if err := resp.UnmarshalAsJSON(&val); err != nil { 556 return BastionShareableLinkListResultResponse{}, err 557 } 558 return BastionShareableLinkListResultResponse{RawResponse: resp.Response, BastionShareableLinkListResult: val}, nil 559} 560 561// getBastionShareableLinkHandleError handles the GetBastionShareableLink error response. 562func (client *NetworkManagementClient) getBastionShareableLinkHandleError(resp *azcore.Response) error { 563 body, err := resp.Payload() 564 if err != nil { 565 return azcore.NewResponseError(err, resp.Response) 566 } 567 errType := CloudError{raw: string(body)} 568 if err := resp.UnmarshalAsJSON(&errType); err != nil { 569 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 570 } 571 return azcore.NewResponseError(&errType, resp.Response) 572} 573 574// BeginPutBastionShareableLink - Creates a Bastion Shareable Links for all the VMs specified in the request. 575// If the operation fails it returns the *CloudError error type. 576func (client *NetworkManagementClient) BeginPutBastionShareableLink(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientBeginPutBastionShareableLinkOptions) (BastionShareableLinkListResultPagerPollerResponse, error) { 577 resp, err := client.putBastionShareableLink(ctx, resourceGroupName, bastionHostName, bslRequest, options) 578 if err != nil { 579 return BastionShareableLinkListResultPagerPollerResponse{}, err 580 } 581 result := BastionShareableLinkListResultPagerPollerResponse{ 582 RawResponse: resp.Response, 583 } 584 pt, err := armcore.NewLROPoller("NetworkManagementClient.PutBastionShareableLink", "location", resp, client.con.Pipeline(), client.putBastionShareableLinkHandleError) 585 if err != nil { 586 return BastionShareableLinkListResultPagerPollerResponse{}, err 587 } 588 poller := &bastionShareableLinkListResultPagerPoller{ 589 pt: pt, 590 errHandler: func(resp *azcore.Response) error { 591 if resp.HasStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 592 return nil 593 } 594 return client.putBastionShareableLinkHandleError(resp) 595 }, 596 respHandler: func(resp *azcore.Response) (BastionShareableLinkListResultResponse, error) { 597 var val *BastionShareableLinkListResult 598 if err := resp.UnmarshalAsJSON(&val); err != nil { 599 return BastionShareableLinkListResultResponse{}, err 600 } 601 return BastionShareableLinkListResultResponse{RawResponse: resp.Response, BastionShareableLinkListResult: val}, nil 602 }, 603 statusCodes: []int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, 604 } 605 result.Poller = poller 606 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (BastionShareableLinkListResultPager, error) { 607 return poller.pollUntilDone(ctx, frequency) 608 } 609 return result, nil 610} 611 612// ResumePutBastionShareableLink creates a new BastionShareableLinkListResultPagerPoller from the specified resume token. 613// token - The value must come from a previous call to BastionShareableLinkListResultPagerPoller.ResumeToken(). 614func (client *NetworkManagementClient) ResumePutBastionShareableLink(ctx context.Context, token string) (BastionShareableLinkListResultPagerPollerResponse, error) { 615 pt, err := armcore.NewLROPollerFromResumeToken("NetworkManagementClient.PutBastionShareableLink", token, client.con.Pipeline(), client.putBastionShareableLinkHandleError) 616 if err != nil { 617 return BastionShareableLinkListResultPagerPollerResponse{}, err 618 } 619 poller := &bastionShareableLinkListResultPagerPoller{ 620 pt: pt, 621 errHandler: func(resp *azcore.Response) error { 622 if resp.HasStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 623 return nil 624 } 625 return client.putBastionShareableLinkHandleError(resp) 626 }, 627 respHandler: func(resp *azcore.Response) (BastionShareableLinkListResultResponse, error) { 628 var val *BastionShareableLinkListResult 629 if err := resp.UnmarshalAsJSON(&val); err != nil { 630 return BastionShareableLinkListResultResponse{}, err 631 } 632 return BastionShareableLinkListResultResponse{RawResponse: resp.Response, BastionShareableLinkListResult: val}, nil 633 }, 634 statusCodes: []int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, 635 } 636 resp, err := poller.Poll(ctx) 637 if err != nil { 638 return BastionShareableLinkListResultPagerPollerResponse{}, err 639 } 640 result := BastionShareableLinkListResultPagerPollerResponse{ 641 RawResponse: resp, 642 } 643 result.Poller = poller 644 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (BastionShareableLinkListResultPager, error) { 645 return poller.pollUntilDone(ctx, frequency) 646 } 647 return result, nil 648} 649 650// PutBastionShareableLink - Creates a Bastion Shareable Links for all the VMs specified in the request. 651// If the operation fails it returns the *CloudError error type. 652func (client *NetworkManagementClient) putBastionShareableLink(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientBeginPutBastionShareableLinkOptions) (*azcore.Response, error) { 653 req, err := client.putBastionShareableLinkCreateRequest(ctx, resourceGroupName, bastionHostName, bslRequest, options) 654 if err != nil { 655 return nil, err 656 } 657 resp, err := client.con.Pipeline().Do(req) 658 if err != nil { 659 return nil, err 660 } 661 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 662 return nil, client.putBastionShareableLinkHandleError(resp) 663 } 664 return resp, nil 665} 666 667// putBastionShareableLinkCreateRequest creates the PutBastionShareableLink request. 668func (client *NetworkManagementClient) putBastionShareableLinkCreateRequest(ctx context.Context, resourceGroupName string, bastionHostName string, bslRequest BastionShareableLinkListRequest, options *NetworkManagementClientBeginPutBastionShareableLinkOptions) (*azcore.Request, error) { 669 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}/createShareableLinks" 670 if resourceGroupName == "" { 671 return nil, errors.New("parameter resourceGroupName cannot be empty") 672 } 673 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 674 if bastionHostName == "" { 675 return nil, errors.New("parameter bastionHostName cannot be empty") 676 } 677 urlPath = strings.ReplaceAll(urlPath, "{bastionHostName}", url.PathEscape(bastionHostName)) 678 if client.subscriptionID == "" { 679 return nil, errors.New("parameter client.subscriptionID cannot be empty") 680 } 681 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 682 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 683 if err != nil { 684 return nil, err 685 } 686 req.Telemetry(telemetryInfo) 687 reqQP := req.URL.Query() 688 reqQP.Set("api-version", "2021-02-01") 689 req.URL.RawQuery = reqQP.Encode() 690 req.Header.Set("Accept", "application/json") 691 return req, req.MarshalAsJSON(bslRequest) 692} 693 694// putBastionShareableLinkHandleError handles the PutBastionShareableLink error response. 695func (client *NetworkManagementClient) putBastionShareableLinkHandleError(resp *azcore.Response) error { 696 body, err := resp.Payload() 697 if err != nil { 698 return azcore.NewResponseError(err, resp.Response) 699 } 700 errType := CloudError{raw: string(body)} 701 if err := resp.UnmarshalAsJSON(&errType); err != nil { 702 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 703 } 704 return azcore.NewResponseError(&errType, resp.Response) 705} 706 707// SupportedSecurityProviders - Gives the supported security providers for the virtual wan. 708// If the operation fails it returns the *CloudError error type. 709func (client *NetworkManagementClient) SupportedSecurityProviders(ctx context.Context, resourceGroupName string, virtualWANName string, options *NetworkManagementClientSupportedSecurityProvidersOptions) (VirtualWanSecurityProvidersResponse, error) { 710 req, err := client.supportedSecurityProvidersCreateRequest(ctx, resourceGroupName, virtualWANName, options) 711 if err != nil { 712 return VirtualWanSecurityProvidersResponse{}, err 713 } 714 resp, err := client.con.Pipeline().Do(req) 715 if err != nil { 716 return VirtualWanSecurityProvidersResponse{}, err 717 } 718 if !resp.HasStatusCode(http.StatusOK) { 719 return VirtualWanSecurityProvidersResponse{}, client.supportedSecurityProvidersHandleError(resp) 720 } 721 return client.supportedSecurityProvidersHandleResponse(resp) 722} 723 724// supportedSecurityProvidersCreateRequest creates the SupportedSecurityProviders request. 725func (client *NetworkManagementClient) supportedSecurityProvidersCreateRequest(ctx context.Context, resourceGroupName string, virtualWANName string, options *NetworkManagementClientSupportedSecurityProvidersOptions) (*azcore.Request, error) { 726 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualWans/{virtualWANName}/supportedSecurityProviders" 727 if client.subscriptionID == "" { 728 return nil, errors.New("parameter client.subscriptionID cannot be empty") 729 } 730 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 731 if resourceGroupName == "" { 732 return nil, errors.New("parameter resourceGroupName cannot be empty") 733 } 734 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 735 if virtualWANName == "" { 736 return nil, errors.New("parameter virtualWANName cannot be empty") 737 } 738 urlPath = strings.ReplaceAll(urlPath, "{virtualWANName}", url.PathEscape(virtualWANName)) 739 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 740 if err != nil { 741 return nil, err 742 } 743 req.Telemetry(telemetryInfo) 744 reqQP := req.URL.Query() 745 reqQP.Set("api-version", "2021-02-01") 746 req.URL.RawQuery = reqQP.Encode() 747 req.Header.Set("Accept", "application/json") 748 return req, nil 749} 750 751// supportedSecurityProvidersHandleResponse handles the SupportedSecurityProviders response. 752func (client *NetworkManagementClient) supportedSecurityProvidersHandleResponse(resp *azcore.Response) (VirtualWanSecurityProvidersResponse, error) { 753 var val *VirtualWanSecurityProviders 754 if err := resp.UnmarshalAsJSON(&val); err != nil { 755 return VirtualWanSecurityProvidersResponse{}, err 756 } 757 return VirtualWanSecurityProvidersResponse{RawResponse: resp.Response, VirtualWanSecurityProviders: val}, nil 758} 759 760// supportedSecurityProvidersHandleError handles the SupportedSecurityProviders error response. 761func (client *NetworkManagementClient) supportedSecurityProvidersHandleError(resp *azcore.Response) error { 762 body, err := resp.Payload() 763 if err != nil { 764 return azcore.NewResponseError(err, resp.Response) 765 } 766 errType := CloudError{raw: string(body)} 767 if err := resp.UnmarshalAsJSON(&errType); err != nil { 768 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 769 } 770 return azcore.NewResponseError(&errType, resp.Response) 771} 772