github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/routingrulecollections_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 "strconv" 21 "strings" 22 ) 23 24 // RoutingRuleCollectionsClient contains the methods for the RoutingRuleCollections group. 25 // Don't use this type directly, use NewRoutingRuleCollectionsClient() instead. 26 type RoutingRuleCollectionsClient struct { 27 internal *arm.Client 28 subscriptionID string 29 } 30 31 // NewRoutingRuleCollectionsClient creates a new instance of RoutingRuleCollectionsClient with the specified values. 32 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 33 // ID forms part of the URI for every service call. 34 // - credential - used to authorize requests. Usually a credential from azidentity. 35 // - options - pass nil to accept the default values. 36 func NewRoutingRuleCollectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*RoutingRuleCollectionsClient, error) { 37 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 38 if err != nil { 39 return nil, err 40 } 41 client := &RoutingRuleCollectionsClient{ 42 subscriptionID: subscriptionID, 43 internal: cl, 44 } 45 return client, nil 46 } 47 48 // CreateOrUpdate - Creates or updates a routing rule collection. 49 // If the operation fails it returns an *azcore.ResponseError type. 50 // 51 // Generated from API version 2024-05-01 52 // - resourceGroupName - The name of the resource group. The name is case insensitive. 53 // - networkManagerName - The name of the network manager. 54 // - configurationName - The name of the network manager Routing Configuration. 55 // - ruleCollectionName - The name of the network manager routing Configuration rule collection. 56 // - ruleCollection - The Rule Collection to create or update 57 // - options - RoutingRuleCollectionsClientCreateOrUpdateOptions contains the optional parameters for the RoutingRuleCollectionsClient.CreateOrUpdate 58 // method. 59 func (client *RoutingRuleCollectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleCollection RoutingRuleCollection, options *RoutingRuleCollectionsClientCreateOrUpdateOptions) (RoutingRuleCollectionsClientCreateOrUpdateResponse, error) { 60 var err error 61 const operationName = "RoutingRuleCollectionsClient.CreateOrUpdate" 62 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 63 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 64 defer func() { endSpan(err) }() 65 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, ruleCollection, options) 66 if err != nil { 67 return RoutingRuleCollectionsClientCreateOrUpdateResponse{}, err 68 } 69 httpResp, err := client.internal.Pipeline().Do(req) 70 if err != nil { 71 return RoutingRuleCollectionsClientCreateOrUpdateResponse{}, err 72 } 73 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 74 err = runtime.NewResponseError(httpResp) 75 return RoutingRuleCollectionsClientCreateOrUpdateResponse{}, err 76 } 77 resp, err := client.createOrUpdateHandleResponse(httpResp) 78 return resp, err 79 } 80 81 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 82 func (client *RoutingRuleCollectionsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleCollection RoutingRuleCollection, options *RoutingRuleCollectionsClientCreateOrUpdateOptions) (*policy.Request, error) { 83 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/routingConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}" 84 if client.subscriptionID == "" { 85 return nil, errors.New("parameter client.subscriptionID cannot be empty") 86 } 87 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 88 if resourceGroupName == "" { 89 return nil, errors.New("parameter resourceGroupName cannot be empty") 90 } 91 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 92 if networkManagerName == "" { 93 return nil, errors.New("parameter networkManagerName cannot be empty") 94 } 95 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 96 if configurationName == "" { 97 return nil, errors.New("parameter configurationName cannot be empty") 98 } 99 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 100 if ruleCollectionName == "" { 101 return nil, errors.New("parameter ruleCollectionName cannot be empty") 102 } 103 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 104 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 105 if err != nil { 106 return nil, err 107 } 108 reqQP := req.Raw().URL.Query() 109 reqQP.Set("api-version", "2024-05-01") 110 req.Raw().URL.RawQuery = reqQP.Encode() 111 req.Raw().Header["Accept"] = []string{"application/json"} 112 if err := runtime.MarshalAsJSON(req, ruleCollection); err != nil { 113 return nil, err 114 } 115 return req, nil 116 } 117 118 // createOrUpdateHandleResponse handles the CreateOrUpdate response. 119 func (client *RoutingRuleCollectionsClient) createOrUpdateHandleResponse(resp *http.Response) (RoutingRuleCollectionsClientCreateOrUpdateResponse, error) { 120 result := RoutingRuleCollectionsClientCreateOrUpdateResponse{} 121 if err := runtime.UnmarshalAsJSON(resp, &result.RoutingRuleCollection); err != nil { 122 return RoutingRuleCollectionsClientCreateOrUpdateResponse{}, err 123 } 124 return result, nil 125 } 126 127 // BeginDelete - Deletes an routing rule collection. 128 // If the operation fails it returns an *azcore.ResponseError type. 129 // 130 // Generated from API version 2024-05-01 131 // - resourceGroupName - The name of the resource group. The name is case insensitive. 132 // - networkManagerName - The name of the network manager. 133 // - configurationName - The name of the network manager Routing Configuration. 134 // - ruleCollectionName - The name of the network manager routing Configuration rule collection. 135 // - options - RoutingRuleCollectionsClientBeginDeleteOptions contains the optional parameters for the RoutingRuleCollectionsClient.BeginDelete 136 // method. 137 func (client *RoutingRuleCollectionsClient) BeginDelete(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *RoutingRuleCollectionsClientBeginDeleteOptions) (*runtime.Poller[RoutingRuleCollectionsClientDeleteResponse], error) { 138 if options == nil || options.ResumeToken == "" { 139 resp, err := client.deleteOperation(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, options) 140 if err != nil { 141 return nil, err 142 } 143 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutingRuleCollectionsClientDeleteResponse]{ 144 FinalStateVia: runtime.FinalStateViaLocation, 145 Tracer: client.internal.Tracer(), 146 }) 147 return poller, err 148 } else { 149 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[RoutingRuleCollectionsClientDeleteResponse]{ 150 Tracer: client.internal.Tracer(), 151 }) 152 } 153 } 154 155 // Delete - Deletes an routing rule collection. 156 // If the operation fails it returns an *azcore.ResponseError type. 157 // 158 // Generated from API version 2024-05-01 159 func (client *RoutingRuleCollectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *RoutingRuleCollectionsClientBeginDeleteOptions) (*http.Response, error) { 160 var err error 161 const operationName = "RoutingRuleCollectionsClient.BeginDelete" 162 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 163 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 164 defer func() { endSpan(err) }() 165 req, err := client.deleteCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, options) 166 if err != nil { 167 return nil, err 168 } 169 httpResp, err := client.internal.Pipeline().Do(req) 170 if err != nil { 171 return nil, err 172 } 173 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 174 err = runtime.NewResponseError(httpResp) 175 return nil, err 176 } 177 return httpResp, nil 178 } 179 180 // deleteCreateRequest creates the Delete request. 181 func (client *RoutingRuleCollectionsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *RoutingRuleCollectionsClientBeginDeleteOptions) (*policy.Request, error) { 182 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/routingConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}" 183 if client.subscriptionID == "" { 184 return nil, errors.New("parameter client.subscriptionID cannot be empty") 185 } 186 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 187 if resourceGroupName == "" { 188 return nil, errors.New("parameter resourceGroupName cannot be empty") 189 } 190 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 191 if networkManagerName == "" { 192 return nil, errors.New("parameter networkManagerName cannot be empty") 193 } 194 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 195 if configurationName == "" { 196 return nil, errors.New("parameter configurationName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 199 if ruleCollectionName == "" { 200 return nil, errors.New("parameter ruleCollectionName cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 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 if options != nil && options.Force != nil { 210 reqQP.Set("force", strconv.FormatBool(*options.Force)) 211 } 212 req.Raw().URL.RawQuery = reqQP.Encode() 213 req.Raw().Header["Accept"] = []string{"application/json"} 214 return req, nil 215 } 216 217 // Get - Gets a network manager routing configuration rule collection. 218 // If the operation fails it returns an *azcore.ResponseError type. 219 // 220 // Generated from API version 2024-05-01 221 // - resourceGroupName - The name of the resource group. The name is case insensitive. 222 // - networkManagerName - The name of the network manager. 223 // - configurationName - The name of the network manager Routing Configuration. 224 // - ruleCollectionName - The name of the network manager routing Configuration rule collection. 225 // - options - RoutingRuleCollectionsClientGetOptions contains the optional parameters for the RoutingRuleCollectionsClient.Get 226 // method. 227 func (client *RoutingRuleCollectionsClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *RoutingRuleCollectionsClientGetOptions) (RoutingRuleCollectionsClientGetResponse, error) { 228 var err error 229 const operationName = "RoutingRuleCollectionsClient.Get" 230 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 231 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 232 defer func() { endSpan(err) }() 233 req, err := client.getCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, options) 234 if err != nil { 235 return RoutingRuleCollectionsClientGetResponse{}, err 236 } 237 httpResp, err := client.internal.Pipeline().Do(req) 238 if err != nil { 239 return RoutingRuleCollectionsClientGetResponse{}, err 240 } 241 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 242 err = runtime.NewResponseError(httpResp) 243 return RoutingRuleCollectionsClientGetResponse{}, err 244 } 245 resp, err := client.getHandleResponse(httpResp) 246 return resp, err 247 } 248 249 // getCreateRequest creates the Get request. 250 func (client *RoutingRuleCollectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *RoutingRuleCollectionsClientGetOptions) (*policy.Request, error) { 251 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/routingConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}" 252 if client.subscriptionID == "" { 253 return nil, errors.New("parameter client.subscriptionID cannot be empty") 254 } 255 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 256 if resourceGroupName == "" { 257 return nil, errors.New("parameter resourceGroupName cannot be empty") 258 } 259 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 260 if networkManagerName == "" { 261 return nil, errors.New("parameter networkManagerName cannot be empty") 262 } 263 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 264 if configurationName == "" { 265 return nil, errors.New("parameter configurationName cannot be empty") 266 } 267 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 268 if ruleCollectionName == "" { 269 return nil, errors.New("parameter ruleCollectionName cannot be empty") 270 } 271 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 272 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 273 if err != nil { 274 return nil, err 275 } 276 reqQP := req.Raw().URL.Query() 277 reqQP.Set("api-version", "2024-05-01") 278 req.Raw().URL.RawQuery = reqQP.Encode() 279 req.Raw().Header["Accept"] = []string{"application/json"} 280 return req, nil 281 } 282 283 // getHandleResponse handles the Get response. 284 func (client *RoutingRuleCollectionsClient) getHandleResponse(resp *http.Response) (RoutingRuleCollectionsClientGetResponse, error) { 285 result := RoutingRuleCollectionsClientGetResponse{} 286 if err := runtime.UnmarshalAsJSON(resp, &result.RoutingRuleCollection); err != nil { 287 return RoutingRuleCollectionsClientGetResponse{}, err 288 } 289 return result, nil 290 } 291 292 // NewListPager - Lists all the rule collections in a routing configuration, in a paginated format. 293 // 294 // Generated from API version 2024-05-01 295 // - resourceGroupName - The name of the resource group. The name is case insensitive. 296 // - networkManagerName - The name of the network manager. 297 // - configurationName - The name of the network manager Routing Configuration. 298 // - options - RoutingRuleCollectionsClientListOptions contains the optional parameters for the RoutingRuleCollectionsClient.NewListPager 299 // method. 300 func (client *RoutingRuleCollectionsClient) NewListPager(resourceGroupName string, networkManagerName string, configurationName string, options *RoutingRuleCollectionsClientListOptions) *runtime.Pager[RoutingRuleCollectionsClientListResponse] { 301 return runtime.NewPager(runtime.PagingHandler[RoutingRuleCollectionsClientListResponse]{ 302 More: func(page RoutingRuleCollectionsClientListResponse) bool { 303 return page.NextLink != nil && len(*page.NextLink) > 0 304 }, 305 Fetcher: func(ctx context.Context, page *RoutingRuleCollectionsClientListResponse) (RoutingRuleCollectionsClientListResponse, error) { 306 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoutingRuleCollectionsClient.NewListPager") 307 nextLink := "" 308 if page != nil { 309 nextLink = *page.NextLink 310 } 311 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 312 return client.listCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, options) 313 }, nil) 314 if err != nil { 315 return RoutingRuleCollectionsClientListResponse{}, err 316 } 317 return client.listHandleResponse(resp) 318 }, 319 Tracer: client.internal.Tracer(), 320 }) 321 } 322 323 // listCreateRequest creates the List request. 324 func (client *RoutingRuleCollectionsClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, options *RoutingRuleCollectionsClientListOptions) (*policy.Request, error) { 325 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/routingConfigurations/{configurationName}/ruleCollections" 326 if client.subscriptionID == "" { 327 return nil, errors.New("parameter client.subscriptionID cannot be empty") 328 } 329 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 330 if resourceGroupName == "" { 331 return nil, errors.New("parameter resourceGroupName cannot be empty") 332 } 333 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 334 if networkManagerName == "" { 335 return nil, errors.New("parameter networkManagerName cannot be empty") 336 } 337 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 338 if configurationName == "" { 339 return nil, errors.New("parameter configurationName cannot be empty") 340 } 341 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 342 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 343 if err != nil { 344 return nil, err 345 } 346 reqQP := req.Raw().URL.Query() 347 if options != nil && options.SkipToken != nil { 348 reqQP.Set("$skipToken", *options.SkipToken) 349 } 350 if options != nil && options.Top != nil { 351 reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) 352 } 353 reqQP.Set("api-version", "2024-05-01") 354 req.Raw().URL.RawQuery = reqQP.Encode() 355 req.Raw().Header["Accept"] = []string{"application/json"} 356 return req, nil 357 } 358 359 // listHandleResponse handles the List response. 360 func (client *RoutingRuleCollectionsClient) listHandleResponse(resp *http.Response) (RoutingRuleCollectionsClientListResponse, error) { 361 result := RoutingRuleCollectionsClientListResponse{} 362 if err := runtime.UnmarshalAsJSON(resp, &result.RoutingRuleCollectionListResult); err != nil { 363 return RoutingRuleCollectionsClientListResponse{}, err 364 } 365 return result, nil 366 }