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