github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/interfaceipconfigurations_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  // InterfaceIPConfigurationsClient contains the methods for the NetworkInterfaceIPConfigurations group.
    24  // Don't use this type directly, use NewInterfaceIPConfigurationsClient() instead.
    25  type InterfaceIPConfigurationsClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewInterfaceIPConfigurationsClient creates a new instance of InterfaceIPConfigurationsClient 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 NewInterfaceIPConfigurationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*InterfaceIPConfigurationsClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &InterfaceIPConfigurationsClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // Get - Gets the specified network interface ip configuration.
    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  //   - networkInterfaceName - The name of the network interface.
    53  //   - ipConfigurationName - The name of the ip configuration name.
    54  //   - options - InterfaceIPConfigurationsClientGetOptions contains the optional parameters for the InterfaceIPConfigurationsClient.Get
    55  //     method.
    56  func (client *InterfaceIPConfigurationsClient) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *InterfaceIPConfigurationsClientGetOptions) (InterfaceIPConfigurationsClientGetResponse, error) {
    57  	var err error
    58  	const operationName = "InterfaceIPConfigurationsClient.Get"
    59  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    60  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    61  	defer func() { endSpan(err) }()
    62  	req, err := client.getCreateRequest(ctx, resourceGroupName, networkInterfaceName, ipConfigurationName, options)
    63  	if err != nil {
    64  		return InterfaceIPConfigurationsClientGetResponse{}, err
    65  	}
    66  	httpResp, err := client.internal.Pipeline().Do(req)
    67  	if err != nil {
    68  		return InterfaceIPConfigurationsClientGetResponse{}, err
    69  	}
    70  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    71  		err = runtime.NewResponseError(httpResp)
    72  		return InterfaceIPConfigurationsClientGetResponse{}, err
    73  	}
    74  	resp, err := client.getHandleResponse(httpResp)
    75  	return resp, err
    76  }
    77  
    78  // getCreateRequest creates the Get request.
    79  func (client *InterfaceIPConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *InterfaceIPConfigurationsClientGetOptions) (*policy.Request, error) {
    80  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/ipConfigurations/{ipConfigurationName}"
    81  	if resourceGroupName == "" {
    82  		return nil, errors.New("parameter resourceGroupName cannot be empty")
    83  	}
    84  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
    85  	if networkInterfaceName == "" {
    86  		return nil, errors.New("parameter networkInterfaceName cannot be empty")
    87  	}
    88  	urlPath = strings.ReplaceAll(urlPath, "{networkInterfaceName}", url.PathEscape(networkInterfaceName))
    89  	if ipConfigurationName == "" {
    90  		return nil, errors.New("parameter ipConfigurationName cannot be empty")
    91  	}
    92  	urlPath = strings.ReplaceAll(urlPath, "{ipConfigurationName}", url.PathEscape(ipConfigurationName))
    93  	if client.subscriptionID == "" {
    94  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    95  	}
    96  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    97  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  	reqQP := req.Raw().URL.Query()
   102  	reqQP.Set("api-version", "2024-05-01")
   103  	req.Raw().URL.RawQuery = reqQP.Encode()
   104  	req.Raw().Header["Accept"] = []string{"application/json"}
   105  	return req, nil
   106  }
   107  
   108  // getHandleResponse handles the Get response.
   109  func (client *InterfaceIPConfigurationsClient) getHandleResponse(resp *http.Response) (InterfaceIPConfigurationsClientGetResponse, error) {
   110  	result := InterfaceIPConfigurationsClientGetResponse{}
   111  	if err := runtime.UnmarshalAsJSON(resp, &result.InterfaceIPConfiguration); err != nil {
   112  		return InterfaceIPConfigurationsClientGetResponse{}, err
   113  	}
   114  	return result, nil
   115  }
   116  
   117  // NewListPager - Get all ip configurations in a network interface.
   118  //
   119  // Generated from API version 2024-05-01
   120  //   - resourceGroupName - The name of the resource group.
   121  //   - networkInterfaceName - The name of the network interface.
   122  //   - options - InterfaceIPConfigurationsClientListOptions contains the optional parameters for the InterfaceIPConfigurationsClient.NewListPager
   123  //     method.
   124  func (client *InterfaceIPConfigurationsClient) NewListPager(resourceGroupName string, networkInterfaceName string, options *InterfaceIPConfigurationsClientListOptions) *runtime.Pager[InterfaceIPConfigurationsClientListResponse] {
   125  	return runtime.NewPager(runtime.PagingHandler[InterfaceIPConfigurationsClientListResponse]{
   126  		More: func(page InterfaceIPConfigurationsClientListResponse) bool {
   127  			return page.NextLink != nil && len(*page.NextLink) > 0
   128  		},
   129  		Fetcher: func(ctx context.Context, page *InterfaceIPConfigurationsClientListResponse) (InterfaceIPConfigurationsClientListResponse, error) {
   130  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfaceIPConfigurationsClient.NewListPager")
   131  			nextLink := ""
   132  			if page != nil {
   133  				nextLink = *page.NextLink
   134  			}
   135  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   136  				return client.listCreateRequest(ctx, resourceGroupName, networkInterfaceName, options)
   137  			}, nil)
   138  			if err != nil {
   139  				return InterfaceIPConfigurationsClientListResponse{}, err
   140  			}
   141  			return client.listHandleResponse(resp)
   142  		},
   143  		Tracer: client.internal.Tracer(),
   144  	})
   145  }
   146  
   147  // listCreateRequest creates the List request.
   148  func (client *InterfaceIPConfigurationsClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *InterfaceIPConfigurationsClientListOptions) (*policy.Request, error) {
   149  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/ipConfigurations"
   150  	if resourceGroupName == "" {
   151  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   152  	}
   153  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   154  	if networkInterfaceName == "" {
   155  		return nil, errors.New("parameter networkInterfaceName cannot be empty")
   156  	}
   157  	urlPath = strings.ReplaceAll(urlPath, "{networkInterfaceName}", url.PathEscape(networkInterfaceName))
   158  	if client.subscriptionID == "" {
   159  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   160  	}
   161  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   162  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   163  	if err != nil {
   164  		return nil, err
   165  	}
   166  	reqQP := req.Raw().URL.Query()
   167  	reqQP.Set("api-version", "2024-05-01")
   168  	req.Raw().URL.RawQuery = reqQP.Encode()
   169  	req.Raw().Header["Accept"] = []string{"application/json"}
   170  	return req, nil
   171  }
   172  
   173  // listHandleResponse handles the List response.
   174  func (client *InterfaceIPConfigurationsClient) listHandleResponse(resp *http.Response) (InterfaceIPConfigurationsClientListResponse, error) {
   175  	result := InterfaceIPConfigurationsClientListResponse{}
   176  	if err := runtime.UnmarshalAsJSON(resp, &result.InterfaceIPConfigurationListResult); err != nil {
   177  		return InterfaceIPConfigurationsClientListResponse{}, err
   178  	}
   179  	return result, nil
   180  }