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