github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/vpnsitelinkconnections_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 // VPNSiteLinkConnectionsClient contains the methods for the VPNSiteLinkConnections group. 24 // Don't use this type directly, use NewVPNSiteLinkConnectionsClient() instead. 25 type VPNSiteLinkConnectionsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewVPNSiteLinkConnectionsClient creates a new instance of VPNSiteLinkConnectionsClient 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 NewVPNSiteLinkConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VPNSiteLinkConnectionsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &VPNSiteLinkConnectionsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // Get - Retrieves the details of a vpn site link connection. 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 VpnGateway. 52 // - gatewayName - The name of the gateway. 53 // - connectionName - The name of the vpn connection. 54 // - linkConnectionName - The name of the vpn connection. 55 // - options - VPNSiteLinkConnectionsClientGetOptions contains the optional parameters for the VPNSiteLinkConnectionsClient.Get 56 // method. 57 func (client *VPNSiteLinkConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *VPNSiteLinkConnectionsClientGetOptions) (VPNSiteLinkConnectionsClientGetResponse, error) { 58 var err error 59 const operationName = "VPNSiteLinkConnectionsClient.Get" 60 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 61 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 62 defer func() { endSpan(err) }() 63 req, err := client.getCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, linkConnectionName, options) 64 if err != nil { 65 return VPNSiteLinkConnectionsClientGetResponse{}, err 66 } 67 httpResp, err := client.internal.Pipeline().Do(req) 68 if err != nil { 69 return VPNSiteLinkConnectionsClientGetResponse{}, err 70 } 71 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 72 err = runtime.NewResponseError(httpResp) 73 return VPNSiteLinkConnectionsClientGetResponse{}, err 74 } 75 resp, err := client.getHandleResponse(httpResp) 76 return resp, err 77 } 78 79 // getCreateRequest creates the Get request. 80 func (client *VPNSiteLinkConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string, options *VPNSiteLinkConnectionsClientGetOptions) (*policy.Request, error) { 81 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}" 82 if client.subscriptionID == "" { 83 return nil, errors.New("parameter client.subscriptionID cannot be empty") 84 } 85 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 86 if resourceGroupName == "" { 87 return nil, errors.New("parameter resourceGroupName cannot be empty") 88 } 89 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 90 if gatewayName == "" { 91 return nil, errors.New("parameter gatewayName cannot be empty") 92 } 93 urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName)) 94 if connectionName == "" { 95 return nil, errors.New("parameter connectionName cannot be empty") 96 } 97 urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName)) 98 if linkConnectionName == "" { 99 return nil, errors.New("parameter linkConnectionName cannot be empty") 100 } 101 urlPath = strings.ReplaceAll(urlPath, "{linkConnectionName}", url.PathEscape(linkConnectionName)) 102 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 103 if err != nil { 104 return nil, err 105 } 106 reqQP := req.Raw().URL.Query() 107 reqQP.Set("api-version", "2024-05-01") 108 req.Raw().URL.RawQuery = reqQP.Encode() 109 req.Raw().Header["Accept"] = []string{"application/json"} 110 return req, nil 111 } 112 113 // getHandleResponse handles the Get response. 114 func (client *VPNSiteLinkConnectionsClient) getHandleResponse(resp *http.Response) (VPNSiteLinkConnectionsClientGetResponse, error) { 115 result := VPNSiteLinkConnectionsClientGetResponse{} 116 if err := runtime.UnmarshalAsJSON(resp, &result.VPNSiteLinkConnection); err != nil { 117 return VPNSiteLinkConnectionsClientGetResponse{}, err 118 } 119 return result, nil 120 }