1// +build go1.13
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package armnetwork
9
10import (
11	"context"
12	"github.com/Azure/azure-sdk-for-go/sdk/armcore"
13	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
14	"net/http"
15	"net/url"
16	"strings"
17)
18
19// VpnLinkConnectionsClient contains the methods for the VpnLinkConnections group.
20// Don't use this type directly, use NewVpnLinkConnectionsClient() instead.
21type VpnLinkConnectionsClient struct {
22	con            *armcore.Connection
23	subscriptionID string
24}
25
26// NewVpnLinkConnectionsClient creates a new instance of VpnLinkConnectionsClient with the specified values.
27func NewVpnLinkConnectionsClient(con *armcore.Connection, subscriptionID string) *VpnLinkConnectionsClient {
28	return &VpnLinkConnectionsClient{con: con, subscriptionID: subscriptionID}
29}
30
31// ListByVpnConnection - Retrieves all vpn site link connections for a particular virtual wan vpn gateway vpn connection.
32func (client *VpnLinkConnectionsClient) ListByVpnConnection(resourceGroupName string, gatewayName string, connectionName string, options *VpnLinkConnectionsListByVpnConnectionOptions) ListVpnSiteLinkConnectionsResultPager {
33	return &listVpnSiteLinkConnectionsResultPager{
34		pipeline: client.con.Pipeline(),
35		requester: func(ctx context.Context) (*azcore.Request, error) {
36			return client.listByVpnConnectionCreateRequest(ctx, resourceGroupName, gatewayName, connectionName, options)
37		},
38		responder: client.listByVpnConnectionHandleResponse,
39		errorer:   client.listByVpnConnectionHandleError,
40		advancer: func(ctx context.Context, resp ListVpnSiteLinkConnectionsResultResponse) (*azcore.Request, error) {
41			return azcore.NewRequest(ctx, http.MethodGet, *resp.ListVpnSiteLinkConnectionsResult.NextLink)
42		},
43		statusCodes: []int{http.StatusOK},
44	}
45}
46
47// listByVpnConnectionCreateRequest creates the ListByVpnConnection request.
48func (client *VpnLinkConnectionsClient) listByVpnConnectionCreateRequest(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, options *VpnLinkConnectionsListByVpnConnectionOptions) (*azcore.Request, error) {
49	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections"
50	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
51	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
52	urlPath = strings.ReplaceAll(urlPath, "{gatewayName}", url.PathEscape(gatewayName))
53	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
54	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
55	if err != nil {
56		return nil, err
57	}
58	req.Telemetry(telemetryInfo)
59	query := req.URL.Query()
60	query.Set("api-version", "2020-07-01")
61	req.URL.RawQuery = query.Encode()
62	req.Header.Set("Accept", "application/json")
63	return req, nil
64}
65
66// listByVpnConnectionHandleResponse handles the ListByVpnConnection response.
67func (client *VpnLinkConnectionsClient) listByVpnConnectionHandleResponse(resp *azcore.Response) (ListVpnSiteLinkConnectionsResultResponse, error) {
68	var val *ListVpnSiteLinkConnectionsResult
69	if err := resp.UnmarshalAsJSON(&val); err != nil {
70		return ListVpnSiteLinkConnectionsResultResponse{}, err
71	}
72	return ListVpnSiteLinkConnectionsResultResponse{RawResponse: resp.Response, ListVpnSiteLinkConnectionsResult: val}, nil
73}
74
75// listByVpnConnectionHandleError handles the ListByVpnConnection error response.
76func (client *VpnLinkConnectionsClient) listByVpnConnectionHandleError(resp *azcore.Response) error {
77	var err CloudError
78	if err := resp.UnmarshalAsJSON(&err); err != nil {
79		return err
80	}
81	return azcore.NewResponseError(&err, resp.Response)
82}
83