github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/virtualhubs_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // VirtualHubsClient contains the methods for the VirtualHubs group. 24 // Don't use this type directly, use NewVirtualHubsClient() instead. 25 type VirtualHubsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewVirtualHubsClient creates a new instance of VirtualHubsClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewVirtualHubsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VirtualHubsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &VirtualHubsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates a VirtualHub resource if it doesn't exist else updates the existing VirtualHub. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The resource group name of the VirtualHub. 52 // - virtualHubName - The name of the VirtualHub. 53 // - virtualHubParameters - Parameters supplied to create or update VirtualHub. 54 // - options - VirtualHubsClientBeginCreateOrUpdateOptions contains the optional parameters for the VirtualHubsClient.BeginCreateOrUpdate 55 // method. 56 func (client *VirtualHubsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters VirtualHub, options *VirtualHubsClientBeginCreateOrUpdateOptions) (*runtime.Poller[VirtualHubsClientCreateOrUpdateResponse], error) { 57 if options == nil || options.ResumeToken == "" { 58 resp, err := client.createOrUpdate(ctx, resourceGroupName, virtualHubName, virtualHubParameters, options) 59 if err != nil { 60 return nil, err 61 } 62 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientCreateOrUpdateResponse]{ 63 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 64 Tracer: client.internal.Tracer(), 65 }) 66 return poller, err 67 } else { 68 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualHubsClientCreateOrUpdateResponse]{ 69 Tracer: client.internal.Tracer(), 70 }) 71 } 72 } 73 74 // CreateOrUpdate - Creates a VirtualHub resource if it doesn't exist else updates the existing VirtualHub. 75 // If the operation fails it returns an *azcore.ResponseError type. 76 // 77 // Generated from API version 2024-05-01 78 func (client *VirtualHubsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters VirtualHub, options *VirtualHubsClientBeginCreateOrUpdateOptions) (*http.Response, error) { 79 var err error 80 const operationName = "VirtualHubsClient.BeginCreateOrUpdate" 81 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 82 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 83 defer func() { endSpan(err) }() 84 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, virtualHubName, virtualHubParameters, options) 85 if err != nil { 86 return nil, err 87 } 88 httpResp, err := client.internal.Pipeline().Do(req) 89 if err != nil { 90 return nil, err 91 } 92 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 93 err = runtime.NewResponseError(httpResp) 94 return nil, err 95 } 96 return httpResp, nil 97 } 98 99 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 100 func (client *VirtualHubsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters VirtualHub, options *VirtualHubsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}" 102 if client.subscriptionID == "" { 103 return nil, errors.New("parameter client.subscriptionID cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 106 if resourceGroupName == "" { 107 return nil, errors.New("parameter resourceGroupName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 110 if virtualHubName == "" { 111 return nil, errors.New("parameter virtualHubName cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 114 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 115 if err != nil { 116 return nil, err 117 } 118 reqQP := req.Raw().URL.Query() 119 reqQP.Set("api-version", "2024-05-01") 120 req.Raw().URL.RawQuery = reqQP.Encode() 121 req.Raw().Header["Accept"] = []string{"application/json"} 122 if err := runtime.MarshalAsJSON(req, virtualHubParameters); err != nil { 123 return nil, err 124 } 125 return req, nil 126 } 127 128 // BeginDelete - Deletes a VirtualHub. 129 // If the operation fails it returns an *azcore.ResponseError type. 130 // 131 // Generated from API version 2024-05-01 132 // - resourceGroupName - The resource group name of the VirtualHub. 133 // - virtualHubName - The name of the VirtualHub. 134 // - options - VirtualHubsClientBeginDeleteOptions contains the optional parameters for the VirtualHubsClient.BeginDelete method. 135 func (client *VirtualHubsClient) BeginDelete(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginDeleteOptions) (*runtime.Poller[VirtualHubsClientDeleteResponse], error) { 136 if options == nil || options.ResumeToken == "" { 137 resp, err := client.deleteOperation(ctx, resourceGroupName, virtualHubName, options) 138 if err != nil { 139 return nil, err 140 } 141 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientDeleteResponse]{ 142 FinalStateVia: runtime.FinalStateViaLocation, 143 Tracer: client.internal.Tracer(), 144 }) 145 return poller, err 146 } else { 147 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualHubsClientDeleteResponse]{ 148 Tracer: client.internal.Tracer(), 149 }) 150 } 151 } 152 153 // Delete - Deletes a VirtualHub. 154 // If the operation fails it returns an *azcore.ResponseError type. 155 // 156 // Generated from API version 2024-05-01 157 func (client *VirtualHubsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginDeleteOptions) (*http.Response, error) { 158 var err error 159 const operationName = "VirtualHubsClient.BeginDelete" 160 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 161 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 162 defer func() { endSpan(err) }() 163 req, err := client.deleteCreateRequest(ctx, resourceGroupName, virtualHubName, options) 164 if err != nil { 165 return nil, err 166 } 167 httpResp, err := client.internal.Pipeline().Do(req) 168 if err != nil { 169 return nil, err 170 } 171 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 172 err = runtime.NewResponseError(httpResp) 173 return nil, err 174 } 175 return httpResp, nil 176 } 177 178 // deleteCreateRequest creates the Delete request. 179 func (client *VirtualHubsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginDeleteOptions) (*policy.Request, error) { 180 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}" 181 if client.subscriptionID == "" { 182 return nil, errors.New("parameter client.subscriptionID cannot be empty") 183 } 184 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 185 if resourceGroupName == "" { 186 return nil, errors.New("parameter resourceGroupName cannot be empty") 187 } 188 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 189 if virtualHubName == "" { 190 return nil, errors.New("parameter virtualHubName cannot be empty") 191 } 192 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 193 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 194 if err != nil { 195 return nil, err 196 } 197 reqQP := req.Raw().URL.Query() 198 reqQP.Set("api-version", "2024-05-01") 199 req.Raw().URL.RawQuery = reqQP.Encode() 200 req.Raw().Header["Accept"] = []string{"application/json"} 201 return req, nil 202 } 203 204 // Get - Retrieves the details of a VirtualHub. 205 // If the operation fails it returns an *azcore.ResponseError type. 206 // 207 // Generated from API version 2024-05-01 208 // - resourceGroupName - The resource group name of the VirtualHub. 209 // - virtualHubName - The name of the VirtualHub. 210 // - options - VirtualHubsClientGetOptions contains the optional parameters for the VirtualHubsClient.Get method. 211 func (client *VirtualHubsClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientGetOptions) (VirtualHubsClientGetResponse, error) { 212 var err error 213 const operationName = "VirtualHubsClient.Get" 214 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 215 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 216 defer func() { endSpan(err) }() 217 req, err := client.getCreateRequest(ctx, resourceGroupName, virtualHubName, options) 218 if err != nil { 219 return VirtualHubsClientGetResponse{}, err 220 } 221 httpResp, err := client.internal.Pipeline().Do(req) 222 if err != nil { 223 return VirtualHubsClientGetResponse{}, err 224 } 225 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 226 err = runtime.NewResponseError(httpResp) 227 return VirtualHubsClientGetResponse{}, err 228 } 229 resp, err := client.getHandleResponse(httpResp) 230 return resp, err 231 } 232 233 // getCreateRequest creates the Get request. 234 func (client *VirtualHubsClient) getCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientGetOptions) (*policy.Request, error) { 235 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}" 236 if client.subscriptionID == "" { 237 return nil, errors.New("parameter client.subscriptionID cannot be empty") 238 } 239 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 240 if resourceGroupName == "" { 241 return nil, errors.New("parameter resourceGroupName cannot be empty") 242 } 243 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 244 if virtualHubName == "" { 245 return nil, errors.New("parameter virtualHubName cannot be empty") 246 } 247 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 248 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 249 if err != nil { 250 return nil, err 251 } 252 reqQP := req.Raw().URL.Query() 253 reqQP.Set("api-version", "2024-05-01") 254 req.Raw().URL.RawQuery = reqQP.Encode() 255 req.Raw().Header["Accept"] = []string{"application/json"} 256 return req, nil 257 } 258 259 // getHandleResponse handles the Get response. 260 func (client *VirtualHubsClient) getHandleResponse(resp *http.Response) (VirtualHubsClientGetResponse, error) { 261 result := VirtualHubsClientGetResponse{} 262 if err := runtime.UnmarshalAsJSON(resp, &result.VirtualHub); err != nil { 263 return VirtualHubsClientGetResponse{}, err 264 } 265 return result, nil 266 } 267 268 // BeginGetEffectiveVirtualHubRoutes - Gets the effective routes configured for the Virtual Hub resource or the specified 269 // resource . 270 // If the operation fails it returns an *azcore.ResponseError type. 271 // 272 // Generated from API version 2024-05-01 273 // - resourceGroupName - The resource group name of the VirtualHub. 274 // - virtualHubName - The name of the VirtualHub. 275 // - options - VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions contains the optional parameters for the VirtualHubsClient.BeginGetEffectiveVirtualHubRoutes 276 // method. 277 func (client *VirtualHubsClient) BeginGetEffectiveVirtualHubRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions) (*runtime.Poller[VirtualHubsClientGetEffectiveVirtualHubRoutesResponse], error) { 278 if options == nil || options.ResumeToken == "" { 279 resp, err := client.getEffectiveVirtualHubRoutes(ctx, resourceGroupName, virtualHubName, options) 280 if err != nil { 281 return nil, err 282 } 283 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetEffectiveVirtualHubRoutesResponse]{ 284 FinalStateVia: runtime.FinalStateViaLocation, 285 Tracer: client.internal.Tracer(), 286 }) 287 return poller, err 288 } else { 289 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualHubsClientGetEffectiveVirtualHubRoutesResponse]{ 290 Tracer: client.internal.Tracer(), 291 }) 292 } 293 } 294 295 // GetEffectiveVirtualHubRoutes - Gets the effective routes configured for the Virtual Hub resource or the specified resource 296 // . 297 // If the operation fails it returns an *azcore.ResponseError type. 298 // 299 // Generated from API version 2024-05-01 300 func (client *VirtualHubsClient) getEffectiveVirtualHubRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions) (*http.Response, error) { 301 var err error 302 const operationName = "VirtualHubsClient.BeginGetEffectiveVirtualHubRoutes" 303 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 304 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 305 defer func() { endSpan(err) }() 306 req, err := client.getEffectiveVirtualHubRoutesCreateRequest(ctx, resourceGroupName, virtualHubName, options) 307 if err != nil { 308 return nil, err 309 } 310 httpResp, err := client.internal.Pipeline().Do(req) 311 if err != nil { 312 return nil, err 313 } 314 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 315 err = runtime.NewResponseError(httpResp) 316 return nil, err 317 } 318 return httpResp, nil 319 } 320 321 // getEffectiveVirtualHubRoutesCreateRequest creates the GetEffectiveVirtualHubRoutes request. 322 func (client *VirtualHubsClient) getEffectiveVirtualHubRoutesCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, options *VirtualHubsClientBeginGetEffectiveVirtualHubRoutesOptions) (*policy.Request, error) { 323 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/effectiveRoutes" 324 if client.subscriptionID == "" { 325 return nil, errors.New("parameter client.subscriptionID cannot be empty") 326 } 327 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 328 if resourceGroupName == "" { 329 return nil, errors.New("parameter resourceGroupName cannot be empty") 330 } 331 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 332 if virtualHubName == "" { 333 return nil, errors.New("parameter virtualHubName cannot be empty") 334 } 335 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 336 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 337 if err != nil { 338 return nil, err 339 } 340 reqQP := req.Raw().URL.Query() 341 reqQP.Set("api-version", "2024-05-01") 342 req.Raw().URL.RawQuery = reqQP.Encode() 343 req.Raw().Header["Accept"] = []string{"application/json"} 344 if options != nil && options.EffectiveRoutesParameters != nil { 345 if err := runtime.MarshalAsJSON(req, *options.EffectiveRoutesParameters); err != nil { 346 return nil, err 347 } 348 return req, nil 349 } 350 return req, nil 351 } 352 353 // BeginGetInboundRoutes - Gets the inbound routes configured for the Virtual Hub on a particular connection. 354 // If the operation fails it returns an *azcore.ResponseError type. 355 // 356 // Generated from API version 2024-05-01 357 // - resourceGroupName - The resource group name of the VirtualHub. 358 // - virtualHubName - The name of the VirtualHub. 359 // - getInboundRoutesParameters - Parameters supplied to get the inbound routes for a connection resource. 360 // - options - VirtualHubsClientBeginGetInboundRoutesOptions contains the optional parameters for the VirtualHubsClient.BeginGetInboundRoutes 361 // method. 362 func (client *VirtualHubsClient) BeginGetInboundRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, getInboundRoutesParameters GetInboundRoutesParameters, options *VirtualHubsClientBeginGetInboundRoutesOptions) (*runtime.Poller[VirtualHubsClientGetInboundRoutesResponse], error) { 363 if options == nil || options.ResumeToken == "" { 364 resp, err := client.getInboundRoutes(ctx, resourceGroupName, virtualHubName, getInboundRoutesParameters, options) 365 if err != nil { 366 return nil, err 367 } 368 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetInboundRoutesResponse]{ 369 FinalStateVia: runtime.FinalStateViaLocation, 370 Tracer: client.internal.Tracer(), 371 }) 372 return poller, err 373 } else { 374 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualHubsClientGetInboundRoutesResponse]{ 375 Tracer: client.internal.Tracer(), 376 }) 377 } 378 } 379 380 // GetInboundRoutes - Gets the inbound routes configured for the Virtual Hub on a particular connection. 381 // If the operation fails it returns an *azcore.ResponseError type. 382 // 383 // Generated from API version 2024-05-01 384 func (client *VirtualHubsClient) getInboundRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, getInboundRoutesParameters GetInboundRoutesParameters, options *VirtualHubsClientBeginGetInboundRoutesOptions) (*http.Response, error) { 385 var err error 386 const operationName = "VirtualHubsClient.BeginGetInboundRoutes" 387 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 388 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 389 defer func() { endSpan(err) }() 390 req, err := client.getInboundRoutesCreateRequest(ctx, resourceGroupName, virtualHubName, getInboundRoutesParameters, options) 391 if err != nil { 392 return nil, err 393 } 394 httpResp, err := client.internal.Pipeline().Do(req) 395 if err != nil { 396 return nil, err 397 } 398 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 399 err = runtime.NewResponseError(httpResp) 400 return nil, err 401 } 402 return httpResp, nil 403 } 404 405 // getInboundRoutesCreateRequest creates the GetInboundRoutes request. 406 func (client *VirtualHubsClient) getInboundRoutesCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, getInboundRoutesParameters GetInboundRoutesParameters, options *VirtualHubsClientBeginGetInboundRoutesOptions) (*policy.Request, error) { 407 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/inboundRoutes" 408 if client.subscriptionID == "" { 409 return nil, errors.New("parameter client.subscriptionID cannot be empty") 410 } 411 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 412 if resourceGroupName == "" { 413 return nil, errors.New("parameter resourceGroupName cannot be empty") 414 } 415 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 416 if virtualHubName == "" { 417 return nil, errors.New("parameter virtualHubName cannot be empty") 418 } 419 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 420 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 421 if err != nil { 422 return nil, err 423 } 424 reqQP := req.Raw().URL.Query() 425 reqQP.Set("api-version", "2024-05-01") 426 req.Raw().URL.RawQuery = reqQP.Encode() 427 req.Raw().Header["Accept"] = []string{"application/json"} 428 if err := runtime.MarshalAsJSON(req, getInboundRoutesParameters); err != nil { 429 return nil, err 430 } 431 return req, nil 432 } 433 434 // BeginGetOutboundRoutes - Gets the outbound routes configured for the Virtual Hub on a particular connection. 435 // If the operation fails it returns an *azcore.ResponseError type. 436 // 437 // Generated from API version 2024-05-01 438 // - resourceGroupName - The resource group name of the VirtualHub. 439 // - virtualHubName - The name of the VirtualHub. 440 // - getOutboundRoutesParameters - Parameters supplied to get the outbound routes for a connection resource. 441 // - options - VirtualHubsClientBeginGetOutboundRoutesOptions contains the optional parameters for the VirtualHubsClient.BeginGetOutboundRoutes 442 // method. 443 func (client *VirtualHubsClient) BeginGetOutboundRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, getOutboundRoutesParameters GetOutboundRoutesParameters, options *VirtualHubsClientBeginGetOutboundRoutesOptions) (*runtime.Poller[VirtualHubsClientGetOutboundRoutesResponse], error) { 444 if options == nil || options.ResumeToken == "" { 445 resp, err := client.getOutboundRoutes(ctx, resourceGroupName, virtualHubName, getOutboundRoutesParameters, options) 446 if err != nil { 447 return nil, err 448 } 449 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualHubsClientGetOutboundRoutesResponse]{ 450 FinalStateVia: runtime.FinalStateViaLocation, 451 Tracer: client.internal.Tracer(), 452 }) 453 return poller, err 454 } else { 455 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualHubsClientGetOutboundRoutesResponse]{ 456 Tracer: client.internal.Tracer(), 457 }) 458 } 459 } 460 461 // GetOutboundRoutes - Gets the outbound routes configured for the Virtual Hub on a particular connection. 462 // If the operation fails it returns an *azcore.ResponseError type. 463 // 464 // Generated from API version 2024-05-01 465 func (client *VirtualHubsClient) getOutboundRoutes(ctx context.Context, resourceGroupName string, virtualHubName string, getOutboundRoutesParameters GetOutboundRoutesParameters, options *VirtualHubsClientBeginGetOutboundRoutesOptions) (*http.Response, error) { 466 var err error 467 const operationName = "VirtualHubsClient.BeginGetOutboundRoutes" 468 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 469 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 470 defer func() { endSpan(err) }() 471 req, err := client.getOutboundRoutesCreateRequest(ctx, resourceGroupName, virtualHubName, getOutboundRoutesParameters, options) 472 if err != nil { 473 return nil, err 474 } 475 httpResp, err := client.internal.Pipeline().Do(req) 476 if err != nil { 477 return nil, err 478 } 479 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 480 err = runtime.NewResponseError(httpResp) 481 return nil, err 482 } 483 return httpResp, nil 484 } 485 486 // getOutboundRoutesCreateRequest creates the GetOutboundRoutes request. 487 func (client *VirtualHubsClient) getOutboundRoutesCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, getOutboundRoutesParameters GetOutboundRoutesParameters, options *VirtualHubsClientBeginGetOutboundRoutesOptions) (*policy.Request, error) { 488 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/outboundRoutes" 489 if client.subscriptionID == "" { 490 return nil, errors.New("parameter client.subscriptionID cannot be empty") 491 } 492 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 493 if resourceGroupName == "" { 494 return nil, errors.New("parameter resourceGroupName cannot be empty") 495 } 496 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 497 if virtualHubName == "" { 498 return nil, errors.New("parameter virtualHubName cannot be empty") 499 } 500 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 501 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 502 if err != nil { 503 return nil, err 504 } 505 reqQP := req.Raw().URL.Query() 506 reqQP.Set("api-version", "2024-05-01") 507 req.Raw().URL.RawQuery = reqQP.Encode() 508 req.Raw().Header["Accept"] = []string{"application/json"} 509 if err := runtime.MarshalAsJSON(req, getOutboundRoutesParameters); err != nil { 510 return nil, err 511 } 512 return req, nil 513 } 514 515 // NewListPager - Lists all the VirtualHubs in a subscription. 516 // 517 // Generated from API version 2024-05-01 518 // - options - VirtualHubsClientListOptions contains the optional parameters for the VirtualHubsClient.NewListPager method. 519 func (client *VirtualHubsClient) NewListPager(options *VirtualHubsClientListOptions) *runtime.Pager[VirtualHubsClientListResponse] { 520 return runtime.NewPager(runtime.PagingHandler[VirtualHubsClientListResponse]{ 521 More: func(page VirtualHubsClientListResponse) bool { 522 return page.NextLink != nil && len(*page.NextLink) > 0 523 }, 524 Fetcher: func(ctx context.Context, page *VirtualHubsClientListResponse) (VirtualHubsClientListResponse, error) { 525 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubsClient.NewListPager") 526 nextLink := "" 527 if page != nil { 528 nextLink = *page.NextLink 529 } 530 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 531 return client.listCreateRequest(ctx, options) 532 }, nil) 533 if err != nil { 534 return VirtualHubsClientListResponse{}, err 535 } 536 return client.listHandleResponse(resp) 537 }, 538 Tracer: client.internal.Tracer(), 539 }) 540 } 541 542 // listCreateRequest creates the List request. 543 func (client *VirtualHubsClient) listCreateRequest(ctx context.Context, options *VirtualHubsClientListOptions) (*policy.Request, error) { 544 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/virtualHubs" 545 if client.subscriptionID == "" { 546 return nil, errors.New("parameter client.subscriptionID cannot be empty") 547 } 548 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 549 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 550 if err != nil { 551 return nil, err 552 } 553 reqQP := req.Raw().URL.Query() 554 reqQP.Set("api-version", "2024-05-01") 555 req.Raw().URL.RawQuery = reqQP.Encode() 556 req.Raw().Header["Accept"] = []string{"application/json"} 557 return req, nil 558 } 559 560 // listHandleResponse handles the List response. 561 func (client *VirtualHubsClient) listHandleResponse(resp *http.Response) (VirtualHubsClientListResponse, error) { 562 result := VirtualHubsClientListResponse{} 563 if err := runtime.UnmarshalAsJSON(resp, &result.ListVirtualHubsResult); err != nil { 564 return VirtualHubsClientListResponse{}, err 565 } 566 return result, nil 567 } 568 569 // NewListByResourceGroupPager - Lists all the VirtualHubs in a resource group. 570 // 571 // Generated from API version 2024-05-01 572 // - resourceGroupName - The resource group name of the VirtualHub. 573 // - options - VirtualHubsClientListByResourceGroupOptions contains the optional parameters for the VirtualHubsClient.NewListByResourceGroupPager 574 // method. 575 func (client *VirtualHubsClient) NewListByResourceGroupPager(resourceGroupName string, options *VirtualHubsClientListByResourceGroupOptions) *runtime.Pager[VirtualHubsClientListByResourceGroupResponse] { 576 return runtime.NewPager(runtime.PagingHandler[VirtualHubsClientListByResourceGroupResponse]{ 577 More: func(page VirtualHubsClientListByResourceGroupResponse) bool { 578 return page.NextLink != nil && len(*page.NextLink) > 0 579 }, 580 Fetcher: func(ctx context.Context, page *VirtualHubsClientListByResourceGroupResponse) (VirtualHubsClientListByResourceGroupResponse, error) { 581 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualHubsClient.NewListByResourceGroupPager") 582 nextLink := "" 583 if page != nil { 584 nextLink = *page.NextLink 585 } 586 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 587 return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) 588 }, nil) 589 if err != nil { 590 return VirtualHubsClientListByResourceGroupResponse{}, err 591 } 592 return client.listByResourceGroupHandleResponse(resp) 593 }, 594 Tracer: client.internal.Tracer(), 595 }) 596 } 597 598 // listByResourceGroupCreateRequest creates the ListByResourceGroup request. 599 func (client *VirtualHubsClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *VirtualHubsClientListByResourceGroupOptions) (*policy.Request, error) { 600 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs" 601 if client.subscriptionID == "" { 602 return nil, errors.New("parameter client.subscriptionID cannot be empty") 603 } 604 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 605 if resourceGroupName == "" { 606 return nil, errors.New("parameter resourceGroupName cannot be empty") 607 } 608 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 609 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 610 if err != nil { 611 return nil, err 612 } 613 reqQP := req.Raw().URL.Query() 614 reqQP.Set("api-version", "2024-05-01") 615 req.Raw().URL.RawQuery = reqQP.Encode() 616 req.Raw().Header["Accept"] = []string{"application/json"} 617 return req, nil 618 } 619 620 // listByResourceGroupHandleResponse handles the ListByResourceGroup response. 621 func (client *VirtualHubsClient) listByResourceGroupHandleResponse(resp *http.Response) (VirtualHubsClientListByResourceGroupResponse, error) { 622 result := VirtualHubsClientListByResourceGroupResponse{} 623 if err := runtime.UnmarshalAsJSON(resp, &result.ListVirtualHubsResult); err != nil { 624 return VirtualHubsClientListByResourceGroupResponse{}, err 625 } 626 return result, nil 627 } 628 629 // UpdateTags - Updates VirtualHub tags. 630 // If the operation fails it returns an *azcore.ResponseError type. 631 // 632 // Generated from API version 2024-05-01 633 // - resourceGroupName - The resource group name of the VirtualHub. 634 // - virtualHubName - The name of the VirtualHub. 635 // - virtualHubParameters - Parameters supplied to update VirtualHub tags. 636 // - options - VirtualHubsClientUpdateTagsOptions contains the optional parameters for the VirtualHubsClient.UpdateTags method. 637 func (client *VirtualHubsClient) UpdateTags(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters TagsObject, options *VirtualHubsClientUpdateTagsOptions) (VirtualHubsClientUpdateTagsResponse, error) { 638 var err error 639 const operationName = "VirtualHubsClient.UpdateTags" 640 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 641 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 642 defer func() { endSpan(err) }() 643 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualHubName, virtualHubParameters, options) 644 if err != nil { 645 return VirtualHubsClientUpdateTagsResponse{}, err 646 } 647 httpResp, err := client.internal.Pipeline().Do(req) 648 if err != nil { 649 return VirtualHubsClientUpdateTagsResponse{}, err 650 } 651 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 652 err = runtime.NewResponseError(httpResp) 653 return VirtualHubsClientUpdateTagsResponse{}, err 654 } 655 resp, err := client.updateTagsHandleResponse(httpResp) 656 return resp, err 657 } 658 659 // updateTagsCreateRequest creates the UpdateTags request. 660 func (client *VirtualHubsClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, virtualHubParameters TagsObject, options *VirtualHubsClientUpdateTagsOptions) (*policy.Request, error) { 661 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}" 662 if client.subscriptionID == "" { 663 return nil, errors.New("parameter client.subscriptionID cannot be empty") 664 } 665 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 666 if resourceGroupName == "" { 667 return nil, errors.New("parameter resourceGroupName cannot be empty") 668 } 669 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 670 if virtualHubName == "" { 671 return nil, errors.New("parameter virtualHubName cannot be empty") 672 } 673 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 674 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 675 if err != nil { 676 return nil, err 677 } 678 reqQP := req.Raw().URL.Query() 679 reqQP.Set("api-version", "2024-05-01") 680 req.Raw().URL.RawQuery = reqQP.Encode() 681 req.Raw().Header["Accept"] = []string{"application/json"} 682 if err := runtime.MarshalAsJSON(req, virtualHubParameters); err != nil { 683 return nil, err 684 } 685 return req, nil 686 } 687 688 // updateTagsHandleResponse handles the UpdateTags response. 689 func (client *VirtualHubsClient) updateTagsHandleResponse(resp *http.Response) (VirtualHubsClientUpdateTagsResponse, error) { 690 result := VirtualHubsClientUpdateTagsResponse{} 691 if err := runtime.UnmarshalAsJSON(resp, &result.VirtualHub); err != nil { 692 return VirtualHubsClientUpdateTagsResponse{}, err 693 } 694 return result, nil 695 }