github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/routemaps_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 // RouteMapsClient contains the methods for the RouteMaps group. 24 // Don't use this type directly, use NewRouteMapsClient() instead. 25 type RouteMapsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewRouteMapsClient creates a new instance of RouteMapsClient 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 NewRouteMapsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*RouteMapsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &RouteMapsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates a RouteMap if it doesn't exist else updates the existing one. 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 RouteMap's resource group. 52 // - virtualHubName - The name of the VirtualHub containing the RouteMap. 53 // - routeMapName - The name of the RouteMap. 54 // - routeMapParameters - Parameters supplied to create or update a RouteMap. 55 // - options - RouteMapsClientBeginCreateOrUpdateOptions contains the optional parameters for the RouteMapsClient.BeginCreateOrUpdate 56 // method. 57 func (client *RouteMapsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, routeMapParameters RouteMap, options *RouteMapsClientBeginCreateOrUpdateOptions) (*runtime.Poller[RouteMapsClientCreateOrUpdateResponse], error) { 58 if options == nil || options.ResumeToken == "" { 59 resp, err := client.createOrUpdate(ctx, resourceGroupName, virtualHubName, routeMapName, routeMapParameters, options) 60 if err != nil { 61 return nil, err 62 } 63 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteMapsClientCreateOrUpdateResponse]{ 64 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 65 Tracer: client.internal.Tracer(), 66 }) 67 return poller, err 68 } else { 69 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[RouteMapsClientCreateOrUpdateResponse]{ 70 Tracer: client.internal.Tracer(), 71 }) 72 } 73 } 74 75 // CreateOrUpdate - Creates a RouteMap if it doesn't exist else updates the existing one. 76 // If the operation fails it returns an *azcore.ResponseError type. 77 // 78 // Generated from API version 2024-05-01 79 func (client *RouteMapsClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, routeMapParameters RouteMap, options *RouteMapsClientBeginCreateOrUpdateOptions) (*http.Response, error) { 80 var err error 81 const operationName = "RouteMapsClient.BeginCreateOrUpdate" 82 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 83 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 84 defer func() { endSpan(err) }() 85 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, virtualHubName, routeMapName, routeMapParameters, options) 86 if err != nil { 87 return nil, err 88 } 89 httpResp, err := client.internal.Pipeline().Do(req) 90 if err != nil { 91 return nil, err 92 } 93 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 94 err = runtime.NewResponseError(httpResp) 95 return nil, err 96 } 97 return httpResp, nil 98 } 99 100 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 101 func (client *RouteMapsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, routeMapParameters RouteMap, options *RouteMapsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 102 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/routeMaps/{routeMapName}" 103 if client.subscriptionID == "" { 104 return nil, errors.New("parameter client.subscriptionID cannot be empty") 105 } 106 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 107 if resourceGroupName == "" { 108 return nil, errors.New("parameter resourceGroupName cannot be empty") 109 } 110 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 111 if virtualHubName == "" { 112 return nil, errors.New("parameter virtualHubName cannot be empty") 113 } 114 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 115 if routeMapName == "" { 116 return nil, errors.New("parameter routeMapName cannot be empty") 117 } 118 urlPath = strings.ReplaceAll(urlPath, "{routeMapName}", url.PathEscape(routeMapName)) 119 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 120 if err != nil { 121 return nil, err 122 } 123 reqQP := req.Raw().URL.Query() 124 reqQP.Set("api-version", "2024-05-01") 125 req.Raw().URL.RawQuery = reqQP.Encode() 126 req.Raw().Header["Accept"] = []string{"application/json"} 127 if err := runtime.MarshalAsJSON(req, routeMapParameters); err != nil { 128 return nil, err 129 } 130 return req, nil 131 } 132 133 // BeginDelete - Deletes a RouteMap. 134 // If the operation fails it returns an *azcore.ResponseError type. 135 // 136 // Generated from API version 2024-05-01 137 // - resourceGroupName - The resource group name of the RouteMap's resource group. 138 // - virtualHubName - The name of the VirtualHub containing the RouteMap. 139 // - routeMapName - The name of the RouteMap. 140 // - options - RouteMapsClientBeginDeleteOptions contains the optional parameters for the RouteMapsClient.BeginDelete method. 141 func (client *RouteMapsClient) BeginDelete(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientBeginDeleteOptions) (*runtime.Poller[RouteMapsClientDeleteResponse], error) { 142 if options == nil || options.ResumeToken == "" { 143 resp, err := client.deleteOperation(ctx, resourceGroupName, virtualHubName, routeMapName, options) 144 if err != nil { 145 return nil, err 146 } 147 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RouteMapsClientDeleteResponse]{ 148 FinalStateVia: runtime.FinalStateViaLocation, 149 Tracer: client.internal.Tracer(), 150 }) 151 return poller, err 152 } else { 153 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[RouteMapsClientDeleteResponse]{ 154 Tracer: client.internal.Tracer(), 155 }) 156 } 157 } 158 159 // Delete - Deletes a RouteMap. 160 // If the operation fails it returns an *azcore.ResponseError type. 161 // 162 // Generated from API version 2024-05-01 163 func (client *RouteMapsClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientBeginDeleteOptions) (*http.Response, error) { 164 var err error 165 const operationName = "RouteMapsClient.BeginDelete" 166 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 167 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 168 defer func() { endSpan(err) }() 169 req, err := client.deleteCreateRequest(ctx, resourceGroupName, virtualHubName, routeMapName, options) 170 if err != nil { 171 return nil, err 172 } 173 httpResp, err := client.internal.Pipeline().Do(req) 174 if err != nil { 175 return nil, err 176 } 177 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 178 err = runtime.NewResponseError(httpResp) 179 return nil, err 180 } 181 return httpResp, nil 182 } 183 184 // deleteCreateRequest creates the Delete request. 185 func (client *RouteMapsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientBeginDeleteOptions) (*policy.Request, error) { 186 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/routeMaps/{routeMapName}" 187 if client.subscriptionID == "" { 188 return nil, errors.New("parameter client.subscriptionID cannot be empty") 189 } 190 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 191 if resourceGroupName == "" { 192 return nil, errors.New("parameter resourceGroupName cannot be empty") 193 } 194 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 195 if virtualHubName == "" { 196 return nil, errors.New("parameter virtualHubName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 199 if routeMapName == "" { 200 return nil, errors.New("parameter routeMapName cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{routeMapName}", url.PathEscape(routeMapName)) 203 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 204 if err != nil { 205 return nil, err 206 } 207 reqQP := req.Raw().URL.Query() 208 reqQP.Set("api-version", "2024-05-01") 209 req.Raw().URL.RawQuery = reqQP.Encode() 210 req.Raw().Header["Accept"] = []string{"application/json"} 211 return req, nil 212 } 213 214 // Get - Retrieves the details of a RouteMap. 215 // If the operation fails it returns an *azcore.ResponseError type. 216 // 217 // Generated from API version 2024-05-01 218 // - resourceGroupName - The resource group name of the RouteMap's resource group. 219 // - virtualHubName - The name of the VirtualHub containing the RouteMap. 220 // - routeMapName - The name of the RouteMap. 221 // - options - RouteMapsClientGetOptions contains the optional parameters for the RouteMapsClient.Get method. 222 func (client *RouteMapsClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientGetOptions) (RouteMapsClientGetResponse, error) { 223 var err error 224 const operationName = "RouteMapsClient.Get" 225 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 226 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 227 defer func() { endSpan(err) }() 228 req, err := client.getCreateRequest(ctx, resourceGroupName, virtualHubName, routeMapName, options) 229 if err != nil { 230 return RouteMapsClientGetResponse{}, err 231 } 232 httpResp, err := client.internal.Pipeline().Do(req) 233 if err != nil { 234 return RouteMapsClientGetResponse{}, err 235 } 236 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 237 err = runtime.NewResponseError(httpResp) 238 return RouteMapsClientGetResponse{}, err 239 } 240 resp, err := client.getHandleResponse(httpResp) 241 return resp, err 242 } 243 244 // getCreateRequest creates the Get request. 245 func (client *RouteMapsClient) getCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, routeMapName string, options *RouteMapsClientGetOptions) (*policy.Request, error) { 246 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/routeMaps/{routeMapName}" 247 if client.subscriptionID == "" { 248 return nil, errors.New("parameter client.subscriptionID cannot be empty") 249 } 250 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 251 if resourceGroupName == "" { 252 return nil, errors.New("parameter resourceGroupName cannot be empty") 253 } 254 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 255 if virtualHubName == "" { 256 return nil, errors.New("parameter virtualHubName cannot be empty") 257 } 258 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 259 if routeMapName == "" { 260 return nil, errors.New("parameter routeMapName cannot be empty") 261 } 262 urlPath = strings.ReplaceAll(urlPath, "{routeMapName}", url.PathEscape(routeMapName)) 263 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 264 if err != nil { 265 return nil, err 266 } 267 reqQP := req.Raw().URL.Query() 268 reqQP.Set("api-version", "2024-05-01") 269 req.Raw().URL.RawQuery = reqQP.Encode() 270 req.Raw().Header["Accept"] = []string{"application/json"} 271 return req, nil 272 } 273 274 // getHandleResponse handles the Get response. 275 func (client *RouteMapsClient) getHandleResponse(resp *http.Response) (RouteMapsClientGetResponse, error) { 276 result := RouteMapsClientGetResponse{} 277 if err := runtime.UnmarshalAsJSON(resp, &result.RouteMap); err != nil { 278 return RouteMapsClientGetResponse{}, err 279 } 280 return result, nil 281 } 282 283 // NewListPager - Retrieves the details of all RouteMaps. 284 // 285 // Generated from API version 2024-05-01 286 // - resourceGroupName - The resource group name of the RouteMap's resource group'. 287 // - virtualHubName - The name of the VirtualHub containing the RouteMap. 288 // - options - RouteMapsClientListOptions contains the optional parameters for the RouteMapsClient.NewListPager method. 289 func (client *RouteMapsClient) NewListPager(resourceGroupName string, virtualHubName string, options *RouteMapsClientListOptions) *runtime.Pager[RouteMapsClientListResponse] { 290 return runtime.NewPager(runtime.PagingHandler[RouteMapsClientListResponse]{ 291 More: func(page RouteMapsClientListResponse) bool { 292 return page.NextLink != nil && len(*page.NextLink) > 0 293 }, 294 Fetcher: func(ctx context.Context, page *RouteMapsClientListResponse) (RouteMapsClientListResponse, error) { 295 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RouteMapsClient.NewListPager") 296 nextLink := "" 297 if page != nil { 298 nextLink = *page.NextLink 299 } 300 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 301 return client.listCreateRequest(ctx, resourceGroupName, virtualHubName, options) 302 }, nil) 303 if err != nil { 304 return RouteMapsClientListResponse{}, err 305 } 306 return client.listHandleResponse(resp) 307 }, 308 Tracer: client.internal.Tracer(), 309 }) 310 } 311 312 // listCreateRequest creates the List request. 313 func (client *RouteMapsClient) listCreateRequest(ctx context.Context, resourceGroupName string, virtualHubName string, options *RouteMapsClientListOptions) (*policy.Request, error) { 314 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/routeMaps" 315 if client.subscriptionID == "" { 316 return nil, errors.New("parameter client.subscriptionID cannot be empty") 317 } 318 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 319 if resourceGroupName == "" { 320 return nil, errors.New("parameter resourceGroupName cannot be empty") 321 } 322 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 323 if virtualHubName == "" { 324 return nil, errors.New("parameter virtualHubName cannot be empty") 325 } 326 urlPath = strings.ReplaceAll(urlPath, "{virtualHubName}", url.PathEscape(virtualHubName)) 327 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 328 if err != nil { 329 return nil, err 330 } 331 reqQP := req.Raw().URL.Query() 332 reqQP.Set("api-version", "2024-05-01") 333 req.Raw().URL.RawQuery = reqQP.Encode() 334 req.Raw().Header["Accept"] = []string{"application/json"} 335 return req, nil 336 } 337 338 // listHandleResponse handles the List response. 339 func (client *RouteMapsClient) listHandleResponse(resp *http.Response) (RouteMapsClientListResponse, error) { 340 result := RouteMapsClientListResponse{} 341 if err := runtime.UnmarshalAsJSON(resp, &result.ListRouteMapsResult); err != nil { 342 return RouteMapsClientListResponse{}, err 343 } 344 return result, nil 345 }