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// ApplicationGatewaysClient contains the methods for the ApplicationGateways group. 23// Don't use this type directly, use NewApplicationGatewaysClient() instead. 24type ApplicationGatewaysClient struct { 25 con *armcore.Connection 26 subscriptionID string 27} 28 29// NewApplicationGatewaysClient creates a new instance of ApplicationGatewaysClient with the specified values. 30func NewApplicationGatewaysClient(con *armcore.Connection, subscriptionID string) *ApplicationGatewaysClient { 31 return &ApplicationGatewaysClient{con: con, subscriptionID: subscriptionID} 32} 33 34// BeginBackendHealth - Gets the backend health of the specified application gateway in a resource group. 35// If the operation fails it returns the *CloudError error type. 36func (client *ApplicationGatewaysClient) BeginBackendHealth(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginBackendHealthOptions) (ApplicationGatewayBackendHealthPollerResponse, error) { 37 resp, err := client.backendHealth(ctx, resourceGroupName, applicationGatewayName, options) 38 if err != nil { 39 return ApplicationGatewayBackendHealthPollerResponse{}, err 40 } 41 result := ApplicationGatewayBackendHealthPollerResponse{ 42 RawResponse: resp.Response, 43 } 44 pt, err := armcore.NewLROPoller("ApplicationGatewaysClient.BackendHealth", "location", resp, client.con.Pipeline(), client.backendHealthHandleError) 45 if err != nil { 46 return ApplicationGatewayBackendHealthPollerResponse{}, err 47 } 48 poller := &applicationGatewayBackendHealthPoller{ 49 pt: pt, 50 } 51 result.Poller = poller 52 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ApplicationGatewayBackendHealthResponse, error) { 53 return poller.pollUntilDone(ctx, frequency) 54 } 55 return result, nil 56} 57 58// ResumeBackendHealth creates a new ApplicationGatewayBackendHealthPoller from the specified resume token. 59// token - The value must come from a previous call to ApplicationGatewayBackendHealthPoller.ResumeToken(). 60func (client *ApplicationGatewaysClient) ResumeBackendHealth(ctx context.Context, token string) (ApplicationGatewayBackendHealthPollerResponse, error) { 61 pt, err := armcore.NewLROPollerFromResumeToken("ApplicationGatewaysClient.BackendHealth", token, client.con.Pipeline(), client.backendHealthHandleError) 62 if err != nil { 63 return ApplicationGatewayBackendHealthPollerResponse{}, err 64 } 65 poller := &applicationGatewayBackendHealthPoller{ 66 pt: pt, 67 } 68 resp, err := poller.Poll(ctx) 69 if err != nil { 70 return ApplicationGatewayBackendHealthPollerResponse{}, err 71 } 72 result := ApplicationGatewayBackendHealthPollerResponse{ 73 RawResponse: resp, 74 } 75 result.Poller = poller 76 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ApplicationGatewayBackendHealthResponse, error) { 77 return poller.pollUntilDone(ctx, frequency) 78 } 79 return result, nil 80} 81 82// BackendHealth - Gets the backend health of the specified application gateway in a resource group. 83// If the operation fails it returns the *CloudError error type. 84func (client *ApplicationGatewaysClient) backendHealth(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginBackendHealthOptions) (*azcore.Response, error) { 85 req, err := client.backendHealthCreateRequest(ctx, resourceGroupName, applicationGatewayName, options) 86 if err != nil { 87 return nil, err 88 } 89 resp, err := client.con.Pipeline().Do(req) 90 if err != nil { 91 return nil, err 92 } 93 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 94 return nil, client.backendHealthHandleError(resp) 95 } 96 return resp, nil 97} 98 99// backendHealthCreateRequest creates the BackendHealth request. 100func (client *ApplicationGatewaysClient) backendHealthCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginBackendHealthOptions) (*azcore.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/backendhealth" 102 if resourceGroupName == "" { 103 return nil, errors.New("parameter resourceGroupName cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 106 if applicationGatewayName == "" { 107 return nil, errors.New("parameter applicationGatewayName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 110 if client.subscriptionID == "" { 111 return nil, errors.New("parameter client.subscriptionID cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 114 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 115 if err != nil { 116 return nil, err 117 } 118 req.Telemetry(telemetryInfo) 119 reqQP := req.URL.Query() 120 reqQP.Set("api-version", "2021-02-01") 121 if options != nil && options.Expand != nil { 122 reqQP.Set("$expand", *options.Expand) 123 } 124 req.URL.RawQuery = reqQP.Encode() 125 req.Header.Set("Accept", "application/json") 126 return req, nil 127} 128 129// backendHealthHandleError handles the BackendHealth error response. 130func (client *ApplicationGatewaysClient) backendHealthHandleError(resp *azcore.Response) error { 131 body, err := resp.Payload() 132 if err != nil { 133 return azcore.NewResponseError(err, resp.Response) 134 } 135 errType := CloudError{raw: string(body)} 136 if err := resp.UnmarshalAsJSON(&errType); err != nil { 137 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 138 } 139 return azcore.NewResponseError(&errType, resp.Response) 140} 141 142// BeginBackendHealthOnDemand - Gets the backend health for given combination of backend pool and http setting of the specified application gateway in a 143// resource group. 144// If the operation fails it returns the *CloudError error type. 145func (client *ApplicationGatewaysClient) BeginBackendHealthOnDemand(ctx context.Context, resourceGroupName string, applicationGatewayName string, probeRequest ApplicationGatewayOnDemandProbe, options *ApplicationGatewaysBeginBackendHealthOnDemandOptions) (ApplicationGatewayBackendHealthOnDemandPollerResponse, error) { 146 resp, err := client.backendHealthOnDemand(ctx, resourceGroupName, applicationGatewayName, probeRequest, options) 147 if err != nil { 148 return ApplicationGatewayBackendHealthOnDemandPollerResponse{}, err 149 } 150 result := ApplicationGatewayBackendHealthOnDemandPollerResponse{ 151 RawResponse: resp.Response, 152 } 153 pt, err := armcore.NewLROPoller("ApplicationGatewaysClient.BackendHealthOnDemand", "location", resp, client.con.Pipeline(), client.backendHealthOnDemandHandleError) 154 if err != nil { 155 return ApplicationGatewayBackendHealthOnDemandPollerResponse{}, err 156 } 157 poller := &applicationGatewayBackendHealthOnDemandPoller{ 158 pt: pt, 159 } 160 result.Poller = poller 161 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ApplicationGatewayBackendHealthOnDemandResponse, error) { 162 return poller.pollUntilDone(ctx, frequency) 163 } 164 return result, nil 165} 166 167// ResumeBackendHealthOnDemand creates a new ApplicationGatewayBackendHealthOnDemandPoller from the specified resume token. 168// token - The value must come from a previous call to ApplicationGatewayBackendHealthOnDemandPoller.ResumeToken(). 169func (client *ApplicationGatewaysClient) ResumeBackendHealthOnDemand(ctx context.Context, token string) (ApplicationGatewayBackendHealthOnDemandPollerResponse, error) { 170 pt, err := armcore.NewLROPollerFromResumeToken("ApplicationGatewaysClient.BackendHealthOnDemand", token, client.con.Pipeline(), client.backendHealthOnDemandHandleError) 171 if err != nil { 172 return ApplicationGatewayBackendHealthOnDemandPollerResponse{}, err 173 } 174 poller := &applicationGatewayBackendHealthOnDemandPoller{ 175 pt: pt, 176 } 177 resp, err := poller.Poll(ctx) 178 if err != nil { 179 return ApplicationGatewayBackendHealthOnDemandPollerResponse{}, err 180 } 181 result := ApplicationGatewayBackendHealthOnDemandPollerResponse{ 182 RawResponse: resp, 183 } 184 result.Poller = poller 185 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ApplicationGatewayBackendHealthOnDemandResponse, error) { 186 return poller.pollUntilDone(ctx, frequency) 187 } 188 return result, nil 189} 190 191// BackendHealthOnDemand - Gets the backend health for given combination of backend pool and http setting of the specified application gateway in a resource 192// group. 193// If the operation fails it returns the *CloudError error type. 194func (client *ApplicationGatewaysClient) backendHealthOnDemand(ctx context.Context, resourceGroupName string, applicationGatewayName string, probeRequest ApplicationGatewayOnDemandProbe, options *ApplicationGatewaysBeginBackendHealthOnDemandOptions) (*azcore.Response, error) { 195 req, err := client.backendHealthOnDemandCreateRequest(ctx, resourceGroupName, applicationGatewayName, probeRequest, options) 196 if err != nil { 197 return nil, err 198 } 199 resp, err := client.con.Pipeline().Do(req) 200 if err != nil { 201 return nil, err 202 } 203 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 204 return nil, client.backendHealthOnDemandHandleError(resp) 205 } 206 return resp, nil 207} 208 209// backendHealthOnDemandCreateRequest creates the BackendHealthOnDemand request. 210func (client *ApplicationGatewaysClient) backendHealthOnDemandCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, probeRequest ApplicationGatewayOnDemandProbe, options *ApplicationGatewaysBeginBackendHealthOnDemandOptions) (*azcore.Request, error) { 211 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/getBackendHealthOnDemand" 212 if resourceGroupName == "" { 213 return nil, errors.New("parameter resourceGroupName cannot be empty") 214 } 215 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 216 if applicationGatewayName == "" { 217 return nil, errors.New("parameter applicationGatewayName cannot be empty") 218 } 219 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 220 if client.subscriptionID == "" { 221 return nil, errors.New("parameter client.subscriptionID cannot be empty") 222 } 223 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 224 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 225 if err != nil { 226 return nil, err 227 } 228 req.Telemetry(telemetryInfo) 229 reqQP := req.URL.Query() 230 reqQP.Set("api-version", "2021-02-01") 231 if options != nil && options.Expand != nil { 232 reqQP.Set("$expand", *options.Expand) 233 } 234 req.URL.RawQuery = reqQP.Encode() 235 req.Header.Set("Accept", "application/json") 236 return req, req.MarshalAsJSON(probeRequest) 237} 238 239// backendHealthOnDemandHandleError handles the BackendHealthOnDemand error response. 240func (client *ApplicationGatewaysClient) backendHealthOnDemandHandleError(resp *azcore.Response) error { 241 body, err := resp.Payload() 242 if err != nil { 243 return azcore.NewResponseError(err, resp.Response) 244 } 245 errType := CloudError{raw: string(body)} 246 if err := resp.UnmarshalAsJSON(&errType); err != nil { 247 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 248 } 249 return azcore.NewResponseError(&errType, resp.Response) 250} 251 252// BeginCreateOrUpdate - Creates or updates the specified application gateway. 253// If the operation fails it returns the *CloudError error type. 254func (client *ApplicationGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters ApplicationGateway, options *ApplicationGatewaysBeginCreateOrUpdateOptions) (ApplicationGatewayPollerResponse, error) { 255 resp, err := client.createOrUpdate(ctx, resourceGroupName, applicationGatewayName, parameters, options) 256 if err != nil { 257 return ApplicationGatewayPollerResponse{}, err 258 } 259 result := ApplicationGatewayPollerResponse{ 260 RawResponse: resp.Response, 261 } 262 pt, err := armcore.NewLROPoller("ApplicationGatewaysClient.CreateOrUpdate", "azure-async-operation", resp, client.con.Pipeline(), client.createOrUpdateHandleError) 263 if err != nil { 264 return ApplicationGatewayPollerResponse{}, err 265 } 266 poller := &applicationGatewayPoller{ 267 pt: pt, 268 } 269 result.Poller = poller 270 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ApplicationGatewayResponse, error) { 271 return poller.pollUntilDone(ctx, frequency) 272 } 273 return result, nil 274} 275 276// ResumeCreateOrUpdate creates a new ApplicationGatewayPoller from the specified resume token. 277// token - The value must come from a previous call to ApplicationGatewayPoller.ResumeToken(). 278func (client *ApplicationGatewaysClient) ResumeCreateOrUpdate(ctx context.Context, token string) (ApplicationGatewayPollerResponse, error) { 279 pt, err := armcore.NewLROPollerFromResumeToken("ApplicationGatewaysClient.CreateOrUpdate", token, client.con.Pipeline(), client.createOrUpdateHandleError) 280 if err != nil { 281 return ApplicationGatewayPollerResponse{}, err 282 } 283 poller := &applicationGatewayPoller{ 284 pt: pt, 285 } 286 resp, err := poller.Poll(ctx) 287 if err != nil { 288 return ApplicationGatewayPollerResponse{}, err 289 } 290 result := ApplicationGatewayPollerResponse{ 291 RawResponse: resp, 292 } 293 result.Poller = poller 294 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ApplicationGatewayResponse, error) { 295 return poller.pollUntilDone(ctx, frequency) 296 } 297 return result, nil 298} 299 300// CreateOrUpdate - Creates or updates the specified application gateway. 301// If the operation fails it returns the *CloudError error type. 302func (client *ApplicationGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters ApplicationGateway, options *ApplicationGatewaysBeginCreateOrUpdateOptions) (*azcore.Response, error) { 303 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, applicationGatewayName, parameters, options) 304 if err != nil { 305 return nil, err 306 } 307 resp, err := client.con.Pipeline().Do(req) 308 if err != nil { 309 return nil, err 310 } 311 if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) { 312 return nil, client.createOrUpdateHandleError(resp) 313 } 314 return resp, nil 315} 316 317// createOrUpdateCreateRequest creates the CreateOrUpdate request. 318func (client *ApplicationGatewaysClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters ApplicationGateway, options *ApplicationGatewaysBeginCreateOrUpdateOptions) (*azcore.Request, error) { 319 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}" 320 if resourceGroupName == "" { 321 return nil, errors.New("parameter resourceGroupName cannot be empty") 322 } 323 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 324 if applicationGatewayName == "" { 325 return nil, errors.New("parameter applicationGatewayName cannot be empty") 326 } 327 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 328 if client.subscriptionID == "" { 329 return nil, errors.New("parameter client.subscriptionID cannot be empty") 330 } 331 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 332 req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 333 if err != nil { 334 return nil, err 335 } 336 req.Telemetry(telemetryInfo) 337 reqQP := req.URL.Query() 338 reqQP.Set("api-version", "2021-02-01") 339 req.URL.RawQuery = reqQP.Encode() 340 req.Header.Set("Accept", "application/json") 341 return req, req.MarshalAsJSON(parameters) 342} 343 344// createOrUpdateHandleError handles the CreateOrUpdate error response. 345func (client *ApplicationGatewaysClient) createOrUpdateHandleError(resp *azcore.Response) error { 346 body, err := resp.Payload() 347 if err != nil { 348 return azcore.NewResponseError(err, resp.Response) 349 } 350 errType := CloudError{raw: string(body)} 351 if err := resp.UnmarshalAsJSON(&errType); err != nil { 352 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 353 } 354 return azcore.NewResponseError(&errType, resp.Response) 355} 356 357// BeginDelete - Deletes the specified application gateway. 358// If the operation fails it returns the *CloudError error type. 359func (client *ApplicationGatewaysClient) BeginDelete(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginDeleteOptions) (HTTPPollerResponse, error) { 360 resp, err := client.deleteOperation(ctx, resourceGroupName, applicationGatewayName, options) 361 if err != nil { 362 return HTTPPollerResponse{}, err 363 } 364 result := HTTPPollerResponse{ 365 RawResponse: resp.Response, 366 } 367 pt, err := armcore.NewLROPoller("ApplicationGatewaysClient.Delete", "location", resp, client.con.Pipeline(), client.deleteHandleError) 368 if err != nil { 369 return HTTPPollerResponse{}, err 370 } 371 poller := &httpPoller{ 372 pt: pt, 373 } 374 result.Poller = poller 375 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 376 return poller.pollUntilDone(ctx, frequency) 377 } 378 return result, nil 379} 380 381// ResumeDelete creates a new HTTPPoller from the specified resume token. 382// token - The value must come from a previous call to HTTPPoller.ResumeToken(). 383func (client *ApplicationGatewaysClient) ResumeDelete(ctx context.Context, token string) (HTTPPollerResponse, error) { 384 pt, err := armcore.NewLROPollerFromResumeToken("ApplicationGatewaysClient.Delete", token, client.con.Pipeline(), client.deleteHandleError) 385 if err != nil { 386 return HTTPPollerResponse{}, err 387 } 388 poller := &httpPoller{ 389 pt: pt, 390 } 391 resp, err := poller.Poll(ctx) 392 if err != nil { 393 return HTTPPollerResponse{}, err 394 } 395 result := HTTPPollerResponse{ 396 RawResponse: resp, 397 } 398 result.Poller = poller 399 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 400 return poller.pollUntilDone(ctx, frequency) 401 } 402 return result, nil 403} 404 405// Delete - Deletes the specified application gateway. 406// If the operation fails it returns the *CloudError error type. 407func (client *ApplicationGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginDeleteOptions) (*azcore.Response, error) { 408 req, err := client.deleteCreateRequest(ctx, resourceGroupName, applicationGatewayName, options) 409 if err != nil { 410 return nil, err 411 } 412 resp, err := client.con.Pipeline().Do(req) 413 if err != nil { 414 return nil, err 415 } 416 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 417 return nil, client.deleteHandleError(resp) 418 } 419 return resp, nil 420} 421 422// deleteCreateRequest creates the Delete request. 423func (client *ApplicationGatewaysClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginDeleteOptions) (*azcore.Request, error) { 424 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}" 425 if resourceGroupName == "" { 426 return nil, errors.New("parameter resourceGroupName cannot be empty") 427 } 428 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 429 if applicationGatewayName == "" { 430 return nil, errors.New("parameter applicationGatewayName cannot be empty") 431 } 432 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 433 if client.subscriptionID == "" { 434 return nil, errors.New("parameter client.subscriptionID cannot be empty") 435 } 436 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 437 req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 438 if err != nil { 439 return nil, err 440 } 441 req.Telemetry(telemetryInfo) 442 reqQP := req.URL.Query() 443 reqQP.Set("api-version", "2021-02-01") 444 req.URL.RawQuery = reqQP.Encode() 445 req.Header.Set("Accept", "application/json") 446 return req, nil 447} 448 449// deleteHandleError handles the Delete error response. 450func (client *ApplicationGatewaysClient) deleteHandleError(resp *azcore.Response) error { 451 body, err := resp.Payload() 452 if err != nil { 453 return azcore.NewResponseError(err, resp.Response) 454 } 455 errType := CloudError{raw: string(body)} 456 if err := resp.UnmarshalAsJSON(&errType); err != nil { 457 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 458 } 459 return azcore.NewResponseError(&errType, resp.Response) 460} 461 462// Get - Gets the specified application gateway. 463// If the operation fails it returns the *CloudError error type. 464func (client *ApplicationGatewaysClient) Get(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysGetOptions) (ApplicationGatewayResponse, error) { 465 req, err := client.getCreateRequest(ctx, resourceGroupName, applicationGatewayName, options) 466 if err != nil { 467 return ApplicationGatewayResponse{}, err 468 } 469 resp, err := client.con.Pipeline().Do(req) 470 if err != nil { 471 return ApplicationGatewayResponse{}, err 472 } 473 if !resp.HasStatusCode(http.StatusOK) { 474 return ApplicationGatewayResponse{}, client.getHandleError(resp) 475 } 476 return client.getHandleResponse(resp) 477} 478 479// getCreateRequest creates the Get request. 480func (client *ApplicationGatewaysClient) getCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysGetOptions) (*azcore.Request, error) { 481 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}" 482 if resourceGroupName == "" { 483 return nil, errors.New("parameter resourceGroupName cannot be empty") 484 } 485 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 486 if applicationGatewayName == "" { 487 return nil, errors.New("parameter applicationGatewayName cannot be empty") 488 } 489 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 490 if client.subscriptionID == "" { 491 return nil, errors.New("parameter client.subscriptionID cannot be empty") 492 } 493 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 494 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 495 if err != nil { 496 return nil, err 497 } 498 req.Telemetry(telemetryInfo) 499 reqQP := req.URL.Query() 500 reqQP.Set("api-version", "2021-02-01") 501 req.URL.RawQuery = reqQP.Encode() 502 req.Header.Set("Accept", "application/json") 503 return req, nil 504} 505 506// getHandleResponse handles the Get response. 507func (client *ApplicationGatewaysClient) getHandleResponse(resp *azcore.Response) (ApplicationGatewayResponse, error) { 508 var val *ApplicationGateway 509 if err := resp.UnmarshalAsJSON(&val); err != nil { 510 return ApplicationGatewayResponse{}, err 511 } 512 return ApplicationGatewayResponse{RawResponse: resp.Response, ApplicationGateway: val}, nil 513} 514 515// getHandleError handles the Get error response. 516func (client *ApplicationGatewaysClient) getHandleError(resp *azcore.Response) error { 517 body, err := resp.Payload() 518 if err != nil { 519 return azcore.NewResponseError(err, resp.Response) 520 } 521 errType := CloudError{raw: string(body)} 522 if err := resp.UnmarshalAsJSON(&errType); err != nil { 523 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 524 } 525 return azcore.NewResponseError(&errType, resp.Response) 526} 527 528// GetSSLPredefinedPolicy - Gets Ssl predefined policy with the specified policy name. 529// If the operation fails it returns the *CloudError error type. 530func (client *ApplicationGatewaysClient) GetSSLPredefinedPolicy(ctx context.Context, predefinedPolicyName string, options *ApplicationGatewaysGetSSLPredefinedPolicyOptions) (ApplicationGatewaySSLPredefinedPolicyResponse, error) { 531 req, err := client.getSSLPredefinedPolicyCreateRequest(ctx, predefinedPolicyName, options) 532 if err != nil { 533 return ApplicationGatewaySSLPredefinedPolicyResponse{}, err 534 } 535 resp, err := client.con.Pipeline().Do(req) 536 if err != nil { 537 return ApplicationGatewaySSLPredefinedPolicyResponse{}, err 538 } 539 if !resp.HasStatusCode(http.StatusOK) { 540 return ApplicationGatewaySSLPredefinedPolicyResponse{}, client.getSSLPredefinedPolicyHandleError(resp) 541 } 542 return client.getSSLPredefinedPolicyHandleResponse(resp) 543} 544 545// getSSLPredefinedPolicyCreateRequest creates the GetSSLPredefinedPolicy request. 546func (client *ApplicationGatewaysClient) getSSLPredefinedPolicyCreateRequest(ctx context.Context, predefinedPolicyName string, options *ApplicationGatewaysGetSSLPredefinedPolicyOptions) (*azcore.Request, error) { 547 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default/predefinedPolicies/{predefinedPolicyName}" 548 if client.subscriptionID == "" { 549 return nil, errors.New("parameter client.subscriptionID cannot be empty") 550 } 551 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 552 if predefinedPolicyName == "" { 553 return nil, errors.New("parameter predefinedPolicyName cannot be empty") 554 } 555 urlPath = strings.ReplaceAll(urlPath, "{predefinedPolicyName}", url.PathEscape(predefinedPolicyName)) 556 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 557 if err != nil { 558 return nil, err 559 } 560 req.Telemetry(telemetryInfo) 561 reqQP := req.URL.Query() 562 reqQP.Set("api-version", "2021-02-01") 563 req.URL.RawQuery = reqQP.Encode() 564 req.Header.Set("Accept", "application/json") 565 return req, nil 566} 567 568// getSSLPredefinedPolicyHandleResponse handles the GetSSLPredefinedPolicy response. 569func (client *ApplicationGatewaysClient) getSSLPredefinedPolicyHandleResponse(resp *azcore.Response) (ApplicationGatewaySSLPredefinedPolicyResponse, error) { 570 var val *ApplicationGatewaySSLPredefinedPolicy 571 if err := resp.UnmarshalAsJSON(&val); err != nil { 572 return ApplicationGatewaySSLPredefinedPolicyResponse{}, err 573 } 574 return ApplicationGatewaySSLPredefinedPolicyResponse{RawResponse: resp.Response, ApplicationGatewaySSLPredefinedPolicy: val}, nil 575} 576 577// getSSLPredefinedPolicyHandleError handles the GetSSLPredefinedPolicy error response. 578func (client *ApplicationGatewaysClient) getSSLPredefinedPolicyHandleError(resp *azcore.Response) error { 579 body, err := resp.Payload() 580 if err != nil { 581 return azcore.NewResponseError(err, resp.Response) 582 } 583 errType := CloudError{raw: string(body)} 584 if err := resp.UnmarshalAsJSON(&errType); err != nil { 585 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 586 } 587 return azcore.NewResponseError(&errType, resp.Response) 588} 589 590// List - Lists all application gateways in a resource group. 591// If the operation fails it returns the *CloudError error type. 592func (client *ApplicationGatewaysClient) List(resourceGroupName string, options *ApplicationGatewaysListOptions) ApplicationGatewayListResultPager { 593 return &applicationGatewayListResultPager{ 594 pipeline: client.con.Pipeline(), 595 requester: func(ctx context.Context) (*azcore.Request, error) { 596 return client.listCreateRequest(ctx, resourceGroupName, options) 597 }, 598 responder: client.listHandleResponse, 599 errorer: client.listHandleError, 600 advancer: func(ctx context.Context, resp ApplicationGatewayListResultResponse) (*azcore.Request, error) { 601 return azcore.NewRequest(ctx, http.MethodGet, *resp.ApplicationGatewayListResult.NextLink) 602 }, 603 statusCodes: []int{http.StatusOK}, 604 } 605} 606 607// listCreateRequest creates the List request. 608func (client *ApplicationGatewaysClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *ApplicationGatewaysListOptions) (*azcore.Request, error) { 609 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways" 610 if resourceGroupName == "" { 611 return nil, errors.New("parameter resourceGroupName cannot be empty") 612 } 613 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 614 if client.subscriptionID == "" { 615 return nil, errors.New("parameter client.subscriptionID cannot be empty") 616 } 617 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 618 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 619 if err != nil { 620 return nil, err 621 } 622 req.Telemetry(telemetryInfo) 623 reqQP := req.URL.Query() 624 reqQP.Set("api-version", "2021-02-01") 625 req.URL.RawQuery = reqQP.Encode() 626 req.Header.Set("Accept", "application/json") 627 return req, nil 628} 629 630// listHandleResponse handles the List response. 631func (client *ApplicationGatewaysClient) listHandleResponse(resp *azcore.Response) (ApplicationGatewayListResultResponse, error) { 632 var val *ApplicationGatewayListResult 633 if err := resp.UnmarshalAsJSON(&val); err != nil { 634 return ApplicationGatewayListResultResponse{}, err 635 } 636 return ApplicationGatewayListResultResponse{RawResponse: resp.Response, ApplicationGatewayListResult: val}, nil 637} 638 639// listHandleError handles the List error response. 640func (client *ApplicationGatewaysClient) listHandleError(resp *azcore.Response) error { 641 body, err := resp.Payload() 642 if err != nil { 643 return azcore.NewResponseError(err, resp.Response) 644 } 645 errType := CloudError{raw: string(body)} 646 if err := resp.UnmarshalAsJSON(&errType); err != nil { 647 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 648 } 649 return azcore.NewResponseError(&errType, resp.Response) 650} 651 652// ListAll - Gets all the application gateways in a subscription. 653// If the operation fails it returns the *CloudError error type. 654func (client *ApplicationGatewaysClient) ListAll(options *ApplicationGatewaysListAllOptions) ApplicationGatewayListResultPager { 655 return &applicationGatewayListResultPager{ 656 pipeline: client.con.Pipeline(), 657 requester: func(ctx context.Context) (*azcore.Request, error) { 658 return client.listAllCreateRequest(ctx, options) 659 }, 660 responder: client.listAllHandleResponse, 661 errorer: client.listAllHandleError, 662 advancer: func(ctx context.Context, resp ApplicationGatewayListResultResponse) (*azcore.Request, error) { 663 return azcore.NewRequest(ctx, http.MethodGet, *resp.ApplicationGatewayListResult.NextLink) 664 }, 665 statusCodes: []int{http.StatusOK}, 666 } 667} 668 669// listAllCreateRequest creates the ListAll request. 670func (client *ApplicationGatewaysClient) listAllCreateRequest(ctx context.Context, options *ApplicationGatewaysListAllOptions) (*azcore.Request, error) { 671 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGateways" 672 if client.subscriptionID == "" { 673 return nil, errors.New("parameter client.subscriptionID cannot be empty") 674 } 675 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 676 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 677 if err != nil { 678 return nil, err 679 } 680 req.Telemetry(telemetryInfo) 681 reqQP := req.URL.Query() 682 reqQP.Set("api-version", "2021-02-01") 683 req.URL.RawQuery = reqQP.Encode() 684 req.Header.Set("Accept", "application/json") 685 return req, nil 686} 687 688// listAllHandleResponse handles the ListAll response. 689func (client *ApplicationGatewaysClient) listAllHandleResponse(resp *azcore.Response) (ApplicationGatewayListResultResponse, error) { 690 var val *ApplicationGatewayListResult 691 if err := resp.UnmarshalAsJSON(&val); err != nil { 692 return ApplicationGatewayListResultResponse{}, err 693 } 694 return ApplicationGatewayListResultResponse{RawResponse: resp.Response, ApplicationGatewayListResult: val}, nil 695} 696 697// listAllHandleError handles the ListAll error response. 698func (client *ApplicationGatewaysClient) listAllHandleError(resp *azcore.Response) error { 699 body, err := resp.Payload() 700 if err != nil { 701 return azcore.NewResponseError(err, resp.Response) 702 } 703 errType := CloudError{raw: string(body)} 704 if err := resp.UnmarshalAsJSON(&errType); err != nil { 705 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 706 } 707 return azcore.NewResponseError(&errType, resp.Response) 708} 709 710// ListAvailableRequestHeaders - Lists all available request headers. 711// If the operation fails it returns the *Error error type. 712func (client *ApplicationGatewaysClient) ListAvailableRequestHeaders(ctx context.Context, options *ApplicationGatewaysListAvailableRequestHeadersOptions) (StringArrayResponse, error) { 713 req, err := client.listAvailableRequestHeadersCreateRequest(ctx, options) 714 if err != nil { 715 return StringArrayResponse{}, err 716 } 717 resp, err := client.con.Pipeline().Do(req) 718 if err != nil { 719 return StringArrayResponse{}, err 720 } 721 if !resp.HasStatusCode(http.StatusOK) { 722 return StringArrayResponse{}, client.listAvailableRequestHeadersHandleError(resp) 723 } 724 return client.listAvailableRequestHeadersHandleResponse(resp) 725} 726 727// listAvailableRequestHeadersCreateRequest creates the ListAvailableRequestHeaders request. 728func (client *ApplicationGatewaysClient) listAvailableRequestHeadersCreateRequest(ctx context.Context, options *ApplicationGatewaysListAvailableRequestHeadersOptions) (*azcore.Request, error) { 729 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableRequestHeaders" 730 if client.subscriptionID == "" { 731 return nil, errors.New("parameter client.subscriptionID cannot be empty") 732 } 733 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 734 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 735 if err != nil { 736 return nil, err 737 } 738 req.Telemetry(telemetryInfo) 739 reqQP := req.URL.Query() 740 reqQP.Set("api-version", "2021-02-01") 741 req.URL.RawQuery = reqQP.Encode() 742 req.Header.Set("Accept", "application/json") 743 return req, nil 744} 745 746// listAvailableRequestHeadersHandleResponse handles the ListAvailableRequestHeaders response. 747func (client *ApplicationGatewaysClient) listAvailableRequestHeadersHandleResponse(resp *azcore.Response) (StringArrayResponse, error) { 748 var val []*string 749 if err := resp.UnmarshalAsJSON(&val); err != nil { 750 return StringArrayResponse{}, err 751 } 752 return StringArrayResponse{RawResponse: resp.Response, StringArray: val}, nil 753} 754 755// listAvailableRequestHeadersHandleError handles the ListAvailableRequestHeaders error response. 756func (client *ApplicationGatewaysClient) listAvailableRequestHeadersHandleError(resp *azcore.Response) error { 757 body, err := resp.Payload() 758 if err != nil { 759 return azcore.NewResponseError(err, resp.Response) 760 } 761 errType := Error{raw: string(body)} 762 if err := resp.UnmarshalAsJSON(&errType); err != nil { 763 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 764 } 765 return azcore.NewResponseError(&errType, resp.Response) 766} 767 768// ListAvailableResponseHeaders - Lists all available response headers. 769// If the operation fails it returns the *Error error type. 770func (client *ApplicationGatewaysClient) ListAvailableResponseHeaders(ctx context.Context, options *ApplicationGatewaysListAvailableResponseHeadersOptions) (StringArrayResponse, error) { 771 req, err := client.listAvailableResponseHeadersCreateRequest(ctx, options) 772 if err != nil { 773 return StringArrayResponse{}, err 774 } 775 resp, err := client.con.Pipeline().Do(req) 776 if err != nil { 777 return StringArrayResponse{}, err 778 } 779 if !resp.HasStatusCode(http.StatusOK) { 780 return StringArrayResponse{}, client.listAvailableResponseHeadersHandleError(resp) 781 } 782 return client.listAvailableResponseHeadersHandleResponse(resp) 783} 784 785// listAvailableResponseHeadersCreateRequest creates the ListAvailableResponseHeaders request. 786func (client *ApplicationGatewaysClient) listAvailableResponseHeadersCreateRequest(ctx context.Context, options *ApplicationGatewaysListAvailableResponseHeadersOptions) (*azcore.Request, error) { 787 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableResponseHeaders" 788 if client.subscriptionID == "" { 789 return nil, errors.New("parameter client.subscriptionID cannot be empty") 790 } 791 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 792 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 793 if err != nil { 794 return nil, err 795 } 796 req.Telemetry(telemetryInfo) 797 reqQP := req.URL.Query() 798 reqQP.Set("api-version", "2021-02-01") 799 req.URL.RawQuery = reqQP.Encode() 800 req.Header.Set("Accept", "application/json") 801 return req, nil 802} 803 804// listAvailableResponseHeadersHandleResponse handles the ListAvailableResponseHeaders response. 805func (client *ApplicationGatewaysClient) listAvailableResponseHeadersHandleResponse(resp *azcore.Response) (StringArrayResponse, error) { 806 var val []*string 807 if err := resp.UnmarshalAsJSON(&val); err != nil { 808 return StringArrayResponse{}, err 809 } 810 return StringArrayResponse{RawResponse: resp.Response, StringArray: val}, nil 811} 812 813// listAvailableResponseHeadersHandleError handles the ListAvailableResponseHeaders error response. 814func (client *ApplicationGatewaysClient) listAvailableResponseHeadersHandleError(resp *azcore.Response) error { 815 body, err := resp.Payload() 816 if err != nil { 817 return azcore.NewResponseError(err, resp.Response) 818 } 819 errType := Error{raw: string(body)} 820 if err := resp.UnmarshalAsJSON(&errType); err != nil { 821 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 822 } 823 return azcore.NewResponseError(&errType, resp.Response) 824} 825 826// ListAvailableSSLOptions - Lists available Ssl options for configuring Ssl policy. 827// If the operation fails it returns the *CloudError error type. 828func (client *ApplicationGatewaysClient) ListAvailableSSLOptions(ctx context.Context, options *ApplicationGatewaysListAvailableSSLOptionsOptions) (ApplicationGatewayAvailableSSLOptionsResponse, error) { 829 req, err := client.listAvailableSSLOptionsCreateRequest(ctx, options) 830 if err != nil { 831 return ApplicationGatewayAvailableSSLOptionsResponse{}, err 832 } 833 resp, err := client.con.Pipeline().Do(req) 834 if err != nil { 835 return ApplicationGatewayAvailableSSLOptionsResponse{}, err 836 } 837 if !resp.HasStatusCode(http.StatusOK) { 838 return ApplicationGatewayAvailableSSLOptionsResponse{}, client.listAvailableSSLOptionsHandleError(resp) 839 } 840 return client.listAvailableSSLOptionsHandleResponse(resp) 841} 842 843// listAvailableSSLOptionsCreateRequest creates the ListAvailableSSLOptions request. 844func (client *ApplicationGatewaysClient) listAvailableSSLOptionsCreateRequest(ctx context.Context, options *ApplicationGatewaysListAvailableSSLOptionsOptions) (*azcore.Request, error) { 845 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default" 846 if client.subscriptionID == "" { 847 return nil, errors.New("parameter client.subscriptionID cannot be empty") 848 } 849 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 850 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 851 if err != nil { 852 return nil, err 853 } 854 req.Telemetry(telemetryInfo) 855 reqQP := req.URL.Query() 856 reqQP.Set("api-version", "2021-02-01") 857 req.URL.RawQuery = reqQP.Encode() 858 req.Header.Set("Accept", "application/json") 859 return req, nil 860} 861 862// listAvailableSSLOptionsHandleResponse handles the ListAvailableSSLOptions response. 863func (client *ApplicationGatewaysClient) listAvailableSSLOptionsHandleResponse(resp *azcore.Response) (ApplicationGatewayAvailableSSLOptionsResponse, error) { 864 var val *ApplicationGatewayAvailableSSLOptions 865 if err := resp.UnmarshalAsJSON(&val); err != nil { 866 return ApplicationGatewayAvailableSSLOptionsResponse{}, err 867 } 868 return ApplicationGatewayAvailableSSLOptionsResponse{RawResponse: resp.Response, ApplicationGatewayAvailableSSLOptions: val}, nil 869} 870 871// listAvailableSSLOptionsHandleError handles the ListAvailableSSLOptions error response. 872func (client *ApplicationGatewaysClient) listAvailableSSLOptionsHandleError(resp *azcore.Response) error { 873 body, err := resp.Payload() 874 if err != nil { 875 return azcore.NewResponseError(err, resp.Response) 876 } 877 errType := CloudError{raw: string(body)} 878 if err := resp.UnmarshalAsJSON(&errType); err != nil { 879 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 880 } 881 return azcore.NewResponseError(&errType, resp.Response) 882} 883 884// ListAvailableSSLPredefinedPolicies - Lists all SSL predefined policies for configuring Ssl policy. 885// If the operation fails it returns the *CloudError error type. 886func (client *ApplicationGatewaysClient) ListAvailableSSLPredefinedPolicies(options *ApplicationGatewaysListAvailableSSLPredefinedPoliciesOptions) ApplicationGatewayAvailableSSLPredefinedPoliciesPager { 887 return &applicationGatewayAvailableSSLPredefinedPoliciesPager{ 888 pipeline: client.con.Pipeline(), 889 requester: func(ctx context.Context) (*azcore.Request, error) { 890 return client.listAvailableSSLPredefinedPoliciesCreateRequest(ctx, options) 891 }, 892 responder: client.listAvailableSSLPredefinedPoliciesHandleResponse, 893 errorer: client.listAvailableSSLPredefinedPoliciesHandleError, 894 advancer: func(ctx context.Context, resp ApplicationGatewayAvailableSSLPredefinedPoliciesResponse) (*azcore.Request, error) { 895 return azcore.NewRequest(ctx, http.MethodGet, *resp.ApplicationGatewayAvailableSSLPredefinedPolicies.NextLink) 896 }, 897 statusCodes: []int{http.StatusOK}, 898 } 899} 900 901// listAvailableSSLPredefinedPoliciesCreateRequest creates the ListAvailableSSLPredefinedPolicies request. 902func (client *ApplicationGatewaysClient) listAvailableSSLPredefinedPoliciesCreateRequest(ctx context.Context, options *ApplicationGatewaysListAvailableSSLPredefinedPoliciesOptions) (*azcore.Request, error) { 903 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default/predefinedPolicies" 904 if client.subscriptionID == "" { 905 return nil, errors.New("parameter client.subscriptionID cannot be empty") 906 } 907 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 908 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 909 if err != nil { 910 return nil, err 911 } 912 req.Telemetry(telemetryInfo) 913 reqQP := req.URL.Query() 914 reqQP.Set("api-version", "2021-02-01") 915 req.URL.RawQuery = reqQP.Encode() 916 req.Header.Set("Accept", "application/json") 917 return req, nil 918} 919 920// listAvailableSSLPredefinedPoliciesHandleResponse handles the ListAvailableSSLPredefinedPolicies response. 921func (client *ApplicationGatewaysClient) listAvailableSSLPredefinedPoliciesHandleResponse(resp *azcore.Response) (ApplicationGatewayAvailableSSLPredefinedPoliciesResponse, error) { 922 var val *ApplicationGatewayAvailableSSLPredefinedPolicies 923 if err := resp.UnmarshalAsJSON(&val); err != nil { 924 return ApplicationGatewayAvailableSSLPredefinedPoliciesResponse{}, err 925 } 926 return ApplicationGatewayAvailableSSLPredefinedPoliciesResponse{RawResponse: resp.Response, ApplicationGatewayAvailableSSLPredefinedPolicies: val}, nil 927} 928 929// listAvailableSSLPredefinedPoliciesHandleError handles the ListAvailableSSLPredefinedPolicies error response. 930func (client *ApplicationGatewaysClient) listAvailableSSLPredefinedPoliciesHandleError(resp *azcore.Response) error { 931 body, err := resp.Payload() 932 if err != nil { 933 return azcore.NewResponseError(err, resp.Response) 934 } 935 errType := CloudError{raw: string(body)} 936 if err := resp.UnmarshalAsJSON(&errType); err != nil { 937 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 938 } 939 return azcore.NewResponseError(&errType, resp.Response) 940} 941 942// ListAvailableServerVariables - Lists all available server variables. 943// If the operation fails it returns the *Error error type. 944func (client *ApplicationGatewaysClient) ListAvailableServerVariables(ctx context.Context, options *ApplicationGatewaysListAvailableServerVariablesOptions) (StringArrayResponse, error) { 945 req, err := client.listAvailableServerVariablesCreateRequest(ctx, options) 946 if err != nil { 947 return StringArrayResponse{}, err 948 } 949 resp, err := client.con.Pipeline().Do(req) 950 if err != nil { 951 return StringArrayResponse{}, err 952 } 953 if !resp.HasStatusCode(http.StatusOK) { 954 return StringArrayResponse{}, client.listAvailableServerVariablesHandleError(resp) 955 } 956 return client.listAvailableServerVariablesHandleResponse(resp) 957} 958 959// listAvailableServerVariablesCreateRequest creates the ListAvailableServerVariables request. 960func (client *ApplicationGatewaysClient) listAvailableServerVariablesCreateRequest(ctx context.Context, options *ApplicationGatewaysListAvailableServerVariablesOptions) (*azcore.Request, error) { 961 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableServerVariables" 962 if client.subscriptionID == "" { 963 return nil, errors.New("parameter client.subscriptionID cannot be empty") 964 } 965 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 966 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 967 if err != nil { 968 return nil, err 969 } 970 req.Telemetry(telemetryInfo) 971 reqQP := req.URL.Query() 972 reqQP.Set("api-version", "2021-02-01") 973 req.URL.RawQuery = reqQP.Encode() 974 req.Header.Set("Accept", "application/json") 975 return req, nil 976} 977 978// listAvailableServerVariablesHandleResponse handles the ListAvailableServerVariables response. 979func (client *ApplicationGatewaysClient) listAvailableServerVariablesHandleResponse(resp *azcore.Response) (StringArrayResponse, error) { 980 var val []*string 981 if err := resp.UnmarshalAsJSON(&val); err != nil { 982 return StringArrayResponse{}, err 983 } 984 return StringArrayResponse{RawResponse: resp.Response, StringArray: val}, nil 985} 986 987// listAvailableServerVariablesHandleError handles the ListAvailableServerVariables error response. 988func (client *ApplicationGatewaysClient) listAvailableServerVariablesHandleError(resp *azcore.Response) error { 989 body, err := resp.Payload() 990 if err != nil { 991 return azcore.NewResponseError(err, resp.Response) 992 } 993 errType := Error{raw: string(body)} 994 if err := resp.UnmarshalAsJSON(&errType); err != nil { 995 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 996 } 997 return azcore.NewResponseError(&errType, resp.Response) 998} 999 1000// ListAvailableWafRuleSets - Lists all available web application firewall rule sets. 1001// If the operation fails it returns the *CloudError error type. 1002func (client *ApplicationGatewaysClient) ListAvailableWafRuleSets(ctx context.Context, options *ApplicationGatewaysListAvailableWafRuleSetsOptions) (ApplicationGatewayAvailableWafRuleSetsResultResponse, error) { 1003 req, err := client.listAvailableWafRuleSetsCreateRequest(ctx, options) 1004 if err != nil { 1005 return ApplicationGatewayAvailableWafRuleSetsResultResponse{}, err 1006 } 1007 resp, err := client.con.Pipeline().Do(req) 1008 if err != nil { 1009 return ApplicationGatewayAvailableWafRuleSetsResultResponse{}, err 1010 } 1011 if !resp.HasStatusCode(http.StatusOK) { 1012 return ApplicationGatewayAvailableWafRuleSetsResultResponse{}, client.listAvailableWafRuleSetsHandleError(resp) 1013 } 1014 return client.listAvailableWafRuleSetsHandleResponse(resp) 1015} 1016 1017// listAvailableWafRuleSetsCreateRequest creates the ListAvailableWafRuleSets request. 1018func (client *ApplicationGatewaysClient) listAvailableWafRuleSetsCreateRequest(ctx context.Context, options *ApplicationGatewaysListAvailableWafRuleSetsOptions) (*azcore.Request, error) { 1019 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/applicationGatewayAvailableWafRuleSets" 1020 if client.subscriptionID == "" { 1021 return nil, errors.New("parameter client.subscriptionID cannot be empty") 1022 } 1023 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 1024 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 1025 if err != nil { 1026 return nil, err 1027 } 1028 req.Telemetry(telemetryInfo) 1029 reqQP := req.URL.Query() 1030 reqQP.Set("api-version", "2021-02-01") 1031 req.URL.RawQuery = reqQP.Encode() 1032 req.Header.Set("Accept", "application/json") 1033 return req, nil 1034} 1035 1036// listAvailableWafRuleSetsHandleResponse handles the ListAvailableWafRuleSets response. 1037func (client *ApplicationGatewaysClient) listAvailableWafRuleSetsHandleResponse(resp *azcore.Response) (ApplicationGatewayAvailableWafRuleSetsResultResponse, error) { 1038 var val *ApplicationGatewayAvailableWafRuleSetsResult 1039 if err := resp.UnmarshalAsJSON(&val); err != nil { 1040 return ApplicationGatewayAvailableWafRuleSetsResultResponse{}, err 1041 } 1042 return ApplicationGatewayAvailableWafRuleSetsResultResponse{RawResponse: resp.Response, ApplicationGatewayAvailableWafRuleSetsResult: val}, nil 1043} 1044 1045// listAvailableWafRuleSetsHandleError handles the ListAvailableWafRuleSets error response. 1046func (client *ApplicationGatewaysClient) listAvailableWafRuleSetsHandleError(resp *azcore.Response) error { 1047 body, err := resp.Payload() 1048 if err != nil { 1049 return azcore.NewResponseError(err, resp.Response) 1050 } 1051 errType := CloudError{raw: string(body)} 1052 if err := resp.UnmarshalAsJSON(&errType); err != nil { 1053 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 1054 } 1055 return azcore.NewResponseError(&errType, resp.Response) 1056} 1057 1058// BeginStart - Starts the specified application gateway. 1059// If the operation fails it returns the *CloudError error type. 1060func (client *ApplicationGatewaysClient) BeginStart(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginStartOptions) (HTTPPollerResponse, error) { 1061 resp, err := client.start(ctx, resourceGroupName, applicationGatewayName, options) 1062 if err != nil { 1063 return HTTPPollerResponse{}, err 1064 } 1065 result := HTTPPollerResponse{ 1066 RawResponse: resp.Response, 1067 } 1068 pt, err := armcore.NewLROPoller("ApplicationGatewaysClient.Start", "location", resp, client.con.Pipeline(), client.startHandleError) 1069 if err != nil { 1070 return HTTPPollerResponse{}, err 1071 } 1072 poller := &httpPoller{ 1073 pt: pt, 1074 } 1075 result.Poller = poller 1076 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 1077 return poller.pollUntilDone(ctx, frequency) 1078 } 1079 return result, nil 1080} 1081 1082// ResumeStart creates a new HTTPPoller from the specified resume token. 1083// token - The value must come from a previous call to HTTPPoller.ResumeToken(). 1084func (client *ApplicationGatewaysClient) ResumeStart(ctx context.Context, token string) (HTTPPollerResponse, error) { 1085 pt, err := armcore.NewLROPollerFromResumeToken("ApplicationGatewaysClient.Start", token, client.con.Pipeline(), client.startHandleError) 1086 if err != nil { 1087 return HTTPPollerResponse{}, err 1088 } 1089 poller := &httpPoller{ 1090 pt: pt, 1091 } 1092 resp, err := poller.Poll(ctx) 1093 if err != nil { 1094 return HTTPPollerResponse{}, err 1095 } 1096 result := HTTPPollerResponse{ 1097 RawResponse: resp, 1098 } 1099 result.Poller = poller 1100 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 1101 return poller.pollUntilDone(ctx, frequency) 1102 } 1103 return result, nil 1104} 1105 1106// Start - Starts the specified application gateway. 1107// If the operation fails it returns the *CloudError error type. 1108func (client *ApplicationGatewaysClient) start(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginStartOptions) (*azcore.Response, error) { 1109 req, err := client.startCreateRequest(ctx, resourceGroupName, applicationGatewayName, options) 1110 if err != nil { 1111 return nil, err 1112 } 1113 resp, err := client.con.Pipeline().Do(req) 1114 if err != nil { 1115 return nil, err 1116 } 1117 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 1118 return nil, client.startHandleError(resp) 1119 } 1120 return resp, nil 1121} 1122 1123// startCreateRequest creates the Start request. 1124func (client *ApplicationGatewaysClient) startCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginStartOptions) (*azcore.Request, error) { 1125 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/start" 1126 if resourceGroupName == "" { 1127 return nil, errors.New("parameter resourceGroupName cannot be empty") 1128 } 1129 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 1130 if applicationGatewayName == "" { 1131 return nil, errors.New("parameter applicationGatewayName cannot be empty") 1132 } 1133 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 1134 if client.subscriptionID == "" { 1135 return nil, errors.New("parameter client.subscriptionID cannot be empty") 1136 } 1137 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 1138 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 1139 if err != nil { 1140 return nil, err 1141 } 1142 req.Telemetry(telemetryInfo) 1143 reqQP := req.URL.Query() 1144 reqQP.Set("api-version", "2021-02-01") 1145 req.URL.RawQuery = reqQP.Encode() 1146 req.Header.Set("Accept", "application/json") 1147 return req, nil 1148} 1149 1150// startHandleError handles the Start error response. 1151func (client *ApplicationGatewaysClient) startHandleError(resp *azcore.Response) error { 1152 body, err := resp.Payload() 1153 if err != nil { 1154 return azcore.NewResponseError(err, resp.Response) 1155 } 1156 errType := CloudError{raw: string(body)} 1157 if err := resp.UnmarshalAsJSON(&errType); err != nil { 1158 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 1159 } 1160 return azcore.NewResponseError(&errType, resp.Response) 1161} 1162 1163// BeginStop - Stops the specified application gateway in a resource group. 1164// If the operation fails it returns the *CloudError error type. 1165func (client *ApplicationGatewaysClient) BeginStop(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginStopOptions) (HTTPPollerResponse, error) { 1166 resp, err := client.stop(ctx, resourceGroupName, applicationGatewayName, options) 1167 if err != nil { 1168 return HTTPPollerResponse{}, err 1169 } 1170 result := HTTPPollerResponse{ 1171 RawResponse: resp.Response, 1172 } 1173 pt, err := armcore.NewLROPoller("ApplicationGatewaysClient.Stop", "location", resp, client.con.Pipeline(), client.stopHandleError) 1174 if err != nil { 1175 return HTTPPollerResponse{}, err 1176 } 1177 poller := &httpPoller{ 1178 pt: pt, 1179 } 1180 result.Poller = poller 1181 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 1182 return poller.pollUntilDone(ctx, frequency) 1183 } 1184 return result, nil 1185} 1186 1187// ResumeStop creates a new HTTPPoller from the specified resume token. 1188// token - The value must come from a previous call to HTTPPoller.ResumeToken(). 1189func (client *ApplicationGatewaysClient) ResumeStop(ctx context.Context, token string) (HTTPPollerResponse, error) { 1190 pt, err := armcore.NewLROPollerFromResumeToken("ApplicationGatewaysClient.Stop", token, client.con.Pipeline(), client.stopHandleError) 1191 if err != nil { 1192 return HTTPPollerResponse{}, err 1193 } 1194 poller := &httpPoller{ 1195 pt: pt, 1196 } 1197 resp, err := poller.Poll(ctx) 1198 if err != nil { 1199 return HTTPPollerResponse{}, err 1200 } 1201 result := HTTPPollerResponse{ 1202 RawResponse: resp, 1203 } 1204 result.Poller = poller 1205 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 1206 return poller.pollUntilDone(ctx, frequency) 1207 } 1208 return result, nil 1209} 1210 1211// Stop - Stops the specified application gateway in a resource group. 1212// If the operation fails it returns the *CloudError error type. 1213func (client *ApplicationGatewaysClient) stop(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginStopOptions) (*azcore.Response, error) { 1214 req, err := client.stopCreateRequest(ctx, resourceGroupName, applicationGatewayName, options) 1215 if err != nil { 1216 return nil, err 1217 } 1218 resp, err := client.con.Pipeline().Do(req) 1219 if err != nil { 1220 return nil, err 1221 } 1222 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 1223 return nil, client.stopHandleError(resp) 1224 } 1225 return resp, nil 1226} 1227 1228// stopCreateRequest creates the Stop request. 1229func (client *ApplicationGatewaysClient) stopCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewaysBeginStopOptions) (*azcore.Request, error) { 1230 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/stop" 1231 if resourceGroupName == "" { 1232 return nil, errors.New("parameter resourceGroupName cannot be empty") 1233 } 1234 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 1235 if applicationGatewayName == "" { 1236 return nil, errors.New("parameter applicationGatewayName cannot be empty") 1237 } 1238 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 1239 if client.subscriptionID == "" { 1240 return nil, errors.New("parameter client.subscriptionID cannot be empty") 1241 } 1242 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 1243 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 1244 if err != nil { 1245 return nil, err 1246 } 1247 req.Telemetry(telemetryInfo) 1248 reqQP := req.URL.Query() 1249 reqQP.Set("api-version", "2021-02-01") 1250 req.URL.RawQuery = reqQP.Encode() 1251 req.Header.Set("Accept", "application/json") 1252 return req, nil 1253} 1254 1255// stopHandleError handles the Stop error response. 1256func (client *ApplicationGatewaysClient) stopHandleError(resp *azcore.Response) error { 1257 body, err := resp.Payload() 1258 if err != nil { 1259 return azcore.NewResponseError(err, resp.Response) 1260 } 1261 errType := CloudError{raw: string(body)} 1262 if err := resp.UnmarshalAsJSON(&errType); err != nil { 1263 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 1264 } 1265 return azcore.NewResponseError(&errType, resp.Response) 1266} 1267 1268// UpdateTags - Updates the specified application gateway tags. 1269// If the operation fails it returns the *CloudError error type. 1270func (client *ApplicationGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters TagsObject, options *ApplicationGatewaysUpdateTagsOptions) (ApplicationGatewayResponse, error) { 1271 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, applicationGatewayName, parameters, options) 1272 if err != nil { 1273 return ApplicationGatewayResponse{}, err 1274 } 1275 resp, err := client.con.Pipeline().Do(req) 1276 if err != nil { 1277 return ApplicationGatewayResponse{}, err 1278 } 1279 if !resp.HasStatusCode(http.StatusOK) { 1280 return ApplicationGatewayResponse{}, client.updateTagsHandleError(resp) 1281 } 1282 return client.updateTagsHandleResponse(resp) 1283} 1284 1285// updateTagsCreateRequest creates the UpdateTags request. 1286func (client *ApplicationGatewaysClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, parameters TagsObject, options *ApplicationGatewaysUpdateTagsOptions) (*azcore.Request, error) { 1287 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}" 1288 if resourceGroupName == "" { 1289 return nil, errors.New("parameter resourceGroupName cannot be empty") 1290 } 1291 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 1292 if applicationGatewayName == "" { 1293 return nil, errors.New("parameter applicationGatewayName cannot be empty") 1294 } 1295 urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName)) 1296 if client.subscriptionID == "" { 1297 return nil, errors.New("parameter client.subscriptionID cannot be empty") 1298 } 1299 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 1300 req, err := azcore.NewRequest(ctx, http.MethodPatch, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 1301 if err != nil { 1302 return nil, err 1303 } 1304 req.Telemetry(telemetryInfo) 1305 reqQP := req.URL.Query() 1306 reqQP.Set("api-version", "2021-02-01") 1307 req.URL.RawQuery = reqQP.Encode() 1308 req.Header.Set("Accept", "application/json") 1309 return req, req.MarshalAsJSON(parameters) 1310} 1311 1312// updateTagsHandleResponse handles the UpdateTags response. 1313func (client *ApplicationGatewaysClient) updateTagsHandleResponse(resp *azcore.Response) (ApplicationGatewayResponse, error) { 1314 var val *ApplicationGateway 1315 if err := resp.UnmarshalAsJSON(&val); err != nil { 1316 return ApplicationGatewayResponse{}, err 1317 } 1318 return ApplicationGatewayResponse{RawResponse: resp.Response, ApplicationGateway: val}, nil 1319} 1320 1321// updateTagsHandleError handles the UpdateTags error response. 1322func (client *ApplicationGatewaysClient) updateTagsHandleError(resp *azcore.Response) error { 1323 body, err := resp.Payload() 1324 if err != nil { 1325 return azcore.NewResponseError(err, resp.Response) 1326 } 1327 errType := CloudError{raw: string(body)} 1328 if err := resp.UnmarshalAsJSON(&errType); err != nil { 1329 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 1330 } 1331 return azcore.NewResponseError(&errType, resp.Response) 1332} 1333