github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/routetables_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 // RouteTablesClient contains the methods for the RouteTables group. 24 // Don't use this type directly, use NewRouteTablesClient() instead. 25 type RouteTablesClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewRouteTablesClient creates a new instance of RouteTablesClient 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 NewRouteTablesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*RouteTablesClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &RouteTablesClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Create or updates a route table in a specified resource group. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - routeTableName - The name of the route table. 53 // - parameters - Parameters supplied to the create or update route table operation. 54 // - options - RouteTablesClientBeginCreateOrUpdateOptions contains the optional parameters for the RouteTablesClient.BeginCreateOrUpdate 55 // method. 56 func (client *RouteTablesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters RouteTable, options *RouteTablesClientBeginCreateOrUpdateOptions) (*runtime.Poller[RouteTablesClientCreateOrUpdateResponse], error) { 57 if options == nil || options.ResumeToken == "" { 58 resp, err := client.createOrUpdate(ctx, resourceGroupName, routeTableName, parameters, options) 59 if err != nil { 60 return nil, err 61 } 62 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteTablesClientCreateOrUpdateResponse]{ 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[RouteTablesClientCreateOrUpdateResponse]{ 69 Tracer: client.internal.Tracer(), 70 }) 71 } 72 } 73 74 // CreateOrUpdate - Create or updates a route table in a specified resource group. 75 // If the operation fails it returns an *azcore.ResponseError type. 76 // 77 // Generated from API version 2024-05-01 78 func (client *RouteTablesClient) createOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters RouteTable, options *RouteTablesClientBeginCreateOrUpdateOptions) (*http.Response, error) { 79 var err error 80 const operationName = "RouteTablesClient.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, routeTableName, parameters, 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 *RouteTablesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, parameters RouteTable, options *RouteTablesClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}" 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 routeTableName == "" { 107 return nil, errors.New("parameter routeTableName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 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 := 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, parameters); err != nil { 123 return nil, err 124 } 125 return req, nil 126 } 127 128 // BeginDelete - Deletes the specified route table. 129 // If the operation fails it returns an *azcore.ResponseError type. 130 // 131 // Generated from API version 2024-05-01 132 // - resourceGroupName - The name of the resource group. 133 // - routeTableName - The name of the route table. 134 // - options - RouteTablesClientBeginDeleteOptions contains the optional parameters for the RouteTablesClient.BeginDelete method. 135 func (client *RouteTablesClient) BeginDelete(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientBeginDeleteOptions) (*runtime.Poller[RouteTablesClientDeleteResponse], error) { 136 if options == nil || options.ResumeToken == "" { 137 resp, err := client.deleteOperation(ctx, resourceGroupName, routeTableName, options) 138 if err != nil { 139 return nil, err 140 } 141 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteTablesClientDeleteResponse]{ 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[RouteTablesClientDeleteResponse]{ 148 Tracer: client.internal.Tracer(), 149 }) 150 } 151 } 152 153 // Delete - Deletes the specified route table. 154 // If the operation fails it returns an *azcore.ResponseError type. 155 // 156 // Generated from API version 2024-05-01 157 func (client *RouteTablesClient) deleteOperation(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientBeginDeleteOptions) (*http.Response, error) { 158 var err error 159 const operationName = "RouteTablesClient.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, routeTableName, 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 *RouteTablesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientBeginDeleteOptions) (*policy.Request, error) { 180 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}" 181 if resourceGroupName == "" { 182 return nil, errors.New("parameter resourceGroupName cannot be empty") 183 } 184 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 185 if routeTableName == "" { 186 return nil, errors.New("parameter routeTableName cannot be empty") 187 } 188 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 189 if client.subscriptionID == "" { 190 return nil, errors.New("parameter client.subscriptionID cannot be empty") 191 } 192 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 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 - Gets the specified route table. 205 // If the operation fails it returns an *azcore.ResponseError type. 206 // 207 // Generated from API version 2024-05-01 208 // - resourceGroupName - The name of the resource group. 209 // - routeTableName - The name of the route table. 210 // - options - RouteTablesClientGetOptions contains the optional parameters for the RouteTablesClient.Get method. 211 func (client *RouteTablesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientGetOptions) (RouteTablesClientGetResponse, error) { 212 var err error 213 const operationName = "RouteTablesClient.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, routeTableName, options) 218 if err != nil { 219 return RouteTablesClientGetResponse{}, err 220 } 221 httpResp, err := client.internal.Pipeline().Do(req) 222 if err != nil { 223 return RouteTablesClientGetResponse{}, err 224 } 225 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 226 err = runtime.NewResponseError(httpResp) 227 return RouteTablesClientGetResponse{}, err 228 } 229 resp, err := client.getHandleResponse(httpResp) 230 return resp, err 231 } 232 233 // getCreateRequest creates the Get request. 234 func (client *RouteTablesClient) getCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, options *RouteTablesClientGetOptions) (*policy.Request, error) { 235 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}" 236 if resourceGroupName == "" { 237 return nil, errors.New("parameter resourceGroupName cannot be empty") 238 } 239 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 240 if routeTableName == "" { 241 return nil, errors.New("parameter routeTableName cannot be empty") 242 } 243 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 244 if client.subscriptionID == "" { 245 return nil, errors.New("parameter client.subscriptionID cannot be empty") 246 } 247 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 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 if options != nil && options.Expand != nil { 254 reqQP.Set("$expand", *options.Expand) 255 } 256 reqQP.Set("api-version", "2024-05-01") 257 req.Raw().URL.RawQuery = reqQP.Encode() 258 req.Raw().Header["Accept"] = []string{"application/json"} 259 return req, nil 260 } 261 262 // getHandleResponse handles the Get response. 263 func (client *RouteTablesClient) getHandleResponse(resp *http.Response) (RouteTablesClientGetResponse, error) { 264 result := RouteTablesClientGetResponse{} 265 if err := runtime.UnmarshalAsJSON(resp, &result.RouteTable); err != nil { 266 return RouteTablesClientGetResponse{}, err 267 } 268 return result, nil 269 } 270 271 // NewListPager - Gets all route tables in a resource group. 272 // 273 // Generated from API version 2024-05-01 274 // - resourceGroupName - The name of the resource group. 275 // - options - RouteTablesClientListOptions contains the optional parameters for the RouteTablesClient.NewListPager method. 276 func (client *RouteTablesClient) NewListPager(resourceGroupName string, options *RouteTablesClientListOptions) *runtime.Pager[RouteTablesClientListResponse] { 277 return runtime.NewPager(runtime.PagingHandler[RouteTablesClientListResponse]{ 278 More: func(page RouteTablesClientListResponse) bool { 279 return page.NextLink != nil && len(*page.NextLink) > 0 280 }, 281 Fetcher: func(ctx context.Context, page *RouteTablesClientListResponse) (RouteTablesClientListResponse, error) { 282 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteTablesClient.NewListPager") 283 nextLink := "" 284 if page != nil { 285 nextLink = *page.NextLink 286 } 287 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 288 return client.listCreateRequest(ctx, resourceGroupName, options) 289 }, nil) 290 if err != nil { 291 return RouteTablesClientListResponse{}, err 292 } 293 return client.listHandleResponse(resp) 294 }, 295 Tracer: client.internal.Tracer(), 296 }) 297 } 298 299 // listCreateRequest creates the List request. 300 func (client *RouteTablesClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *RouteTablesClientListOptions) (*policy.Request, error) { 301 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables" 302 if resourceGroupName == "" { 303 return nil, errors.New("parameter resourceGroupName cannot be empty") 304 } 305 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 306 if client.subscriptionID == "" { 307 return nil, errors.New("parameter client.subscriptionID cannot be empty") 308 } 309 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 310 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 311 if err != nil { 312 return nil, err 313 } 314 reqQP := req.Raw().URL.Query() 315 reqQP.Set("api-version", "2024-05-01") 316 req.Raw().URL.RawQuery = reqQP.Encode() 317 req.Raw().Header["Accept"] = []string{"application/json"} 318 return req, nil 319 } 320 321 // listHandleResponse handles the List response. 322 func (client *RouteTablesClient) listHandleResponse(resp *http.Response) (RouteTablesClientListResponse, error) { 323 result := RouteTablesClientListResponse{} 324 if err := runtime.UnmarshalAsJSON(resp, &result.RouteTableListResult); err != nil { 325 return RouteTablesClientListResponse{}, err 326 } 327 return result, nil 328 } 329 330 // NewListAllPager - Gets all route tables in a subscription. 331 // 332 // Generated from API version 2024-05-01 333 // - options - RouteTablesClientListAllOptions contains the optional parameters for the RouteTablesClient.NewListAllPager method. 334 func (client *RouteTablesClient) NewListAllPager(options *RouteTablesClientListAllOptions) *runtime.Pager[RouteTablesClientListAllResponse] { 335 return runtime.NewPager(runtime.PagingHandler[RouteTablesClientListAllResponse]{ 336 More: func(page RouteTablesClientListAllResponse) bool { 337 return page.NextLink != nil && len(*page.NextLink) > 0 338 }, 339 Fetcher: func(ctx context.Context, page *RouteTablesClientListAllResponse) (RouteTablesClientListAllResponse, error) { 340 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteTablesClient.NewListAllPager") 341 nextLink := "" 342 if page != nil { 343 nextLink = *page.NextLink 344 } 345 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 346 return client.listAllCreateRequest(ctx, options) 347 }, nil) 348 if err != nil { 349 return RouteTablesClientListAllResponse{}, err 350 } 351 return client.listAllHandleResponse(resp) 352 }, 353 Tracer: client.internal.Tracer(), 354 }) 355 } 356 357 // listAllCreateRequest creates the ListAll request. 358 func (client *RouteTablesClient) listAllCreateRequest(ctx context.Context, options *RouteTablesClientListAllOptions) (*policy.Request, error) { 359 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/routeTables" 360 if client.subscriptionID == "" { 361 return nil, errors.New("parameter client.subscriptionID cannot be empty") 362 } 363 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 364 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 365 if err != nil { 366 return nil, err 367 } 368 reqQP := req.Raw().URL.Query() 369 reqQP.Set("api-version", "2024-05-01") 370 req.Raw().URL.RawQuery = reqQP.Encode() 371 req.Raw().Header["Accept"] = []string{"application/json"} 372 return req, nil 373 } 374 375 // listAllHandleResponse handles the ListAll response. 376 func (client *RouteTablesClient) listAllHandleResponse(resp *http.Response) (RouteTablesClientListAllResponse, error) { 377 result := RouteTablesClientListAllResponse{} 378 if err := runtime.UnmarshalAsJSON(resp, &result.RouteTableListResult); err != nil { 379 return RouteTablesClientListAllResponse{}, err 380 } 381 return result, nil 382 } 383 384 // UpdateTags - Updates a route table tags. 385 // If the operation fails it returns an *azcore.ResponseError type. 386 // 387 // Generated from API version 2024-05-01 388 // - resourceGroupName - The name of the resource group. 389 // - routeTableName - The name of the route table. 390 // - parameters - Parameters supplied to update route table tags. 391 // - options - RouteTablesClientUpdateTagsOptions contains the optional parameters for the RouteTablesClient.UpdateTags method. 392 func (client *RouteTablesClient) UpdateTags(ctx context.Context, resourceGroupName string, routeTableName string, parameters TagsObject, options *RouteTablesClientUpdateTagsOptions) (RouteTablesClientUpdateTagsResponse, error) { 393 var err error 394 const operationName = "RouteTablesClient.UpdateTags" 395 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 396 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 397 defer func() { endSpan(err) }() 398 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, routeTableName, parameters, options) 399 if err != nil { 400 return RouteTablesClientUpdateTagsResponse{}, err 401 } 402 httpResp, err := client.internal.Pipeline().Do(req) 403 if err != nil { 404 return RouteTablesClientUpdateTagsResponse{}, err 405 } 406 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 407 err = runtime.NewResponseError(httpResp) 408 return RouteTablesClientUpdateTagsResponse{}, err 409 } 410 resp, err := client.updateTagsHandleResponse(httpResp) 411 return resp, err 412 } 413 414 // updateTagsCreateRequest creates the UpdateTags request. 415 func (client *RouteTablesClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, parameters TagsObject, options *RouteTablesClientUpdateTagsOptions) (*policy.Request, error) { 416 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}" 417 if resourceGroupName == "" { 418 return nil, errors.New("parameter resourceGroupName cannot be empty") 419 } 420 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 421 if routeTableName == "" { 422 return nil, errors.New("parameter routeTableName cannot be empty") 423 } 424 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 425 if client.subscriptionID == "" { 426 return nil, errors.New("parameter client.subscriptionID cannot be empty") 427 } 428 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 429 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 430 if err != nil { 431 return nil, err 432 } 433 reqQP := req.Raw().URL.Query() 434 reqQP.Set("api-version", "2024-05-01") 435 req.Raw().URL.RawQuery = reqQP.Encode() 436 req.Raw().Header["Accept"] = []string{"application/json"} 437 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 438 return nil, err 439 } 440 return req, nil 441 } 442 443 // updateTagsHandleResponse handles the UpdateTags response. 444 func (client *RouteTablesClient) updateTagsHandleResponse(resp *http.Response) (RouteTablesClientUpdateTagsResponse, error) { 445 result := RouteTablesClientUpdateTagsResponse{} 446 if err := runtime.UnmarshalAsJSON(resp, &result.RouteTable); err != nil { 447 return RouteTablesClientUpdateTagsResponse{}, err 448 } 449 return result, nil 450 }