1package network
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// VpnLinkConnectionsClient is the network Client
29type VpnLinkConnectionsClient struct {
30	BaseClient
31}
32
33// NewVpnLinkConnectionsClient creates an instance of the VpnLinkConnectionsClient client.
34func NewVpnLinkConnectionsClient(subscriptionID string) VpnLinkConnectionsClient {
35	return NewVpnLinkConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewVpnLinkConnectionsClientWithBaseURI creates an instance of the VpnLinkConnectionsClient client using a custom
39// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
40// stack).
41func NewVpnLinkConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VpnLinkConnectionsClient {
42	return VpnLinkConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// ListByVpnConnection retrieves all vpn site link connections for a particular virtual wan vpn gateway vpn connection.
46// Parameters:
47// resourceGroupName - the resource group name of the VpnGateway.
48// gatewayName - the name of the gateway.
49// connectionName - the name of the vpn connection.
50func (client VpnLinkConnectionsClient) ListByVpnConnection(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result ListVpnSiteLinkConnectionsResultPage, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/VpnLinkConnectionsClient.ListByVpnConnection")
53		defer func() {
54			sc := -1
55			if result.lvslcr.Response.Response != nil {
56				sc = result.lvslcr.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	result.fn = client.listByVpnConnectionNextResults
62	req, err := client.ListByVpnConnectionPreparer(ctx, resourceGroupName, gatewayName, connectionName)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "ListByVpnConnection", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.ListByVpnConnectionSender(req)
69	if err != nil {
70		result.lvslcr.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "ListByVpnConnection", resp, "Failure sending request")
72		return
73	}
74
75	result.lvslcr, err = client.ListByVpnConnectionResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "ListByVpnConnection", resp, "Failure responding to request")
78	}
79
80	return
81}
82
83// ListByVpnConnectionPreparer prepares the ListByVpnConnection request.
84func (client VpnLinkConnectionsClient) ListByVpnConnectionPreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"connectionName":    autorest.Encode("path", connectionName),
87		"gatewayName":       autorest.Encode("path", gatewayName),
88		"resourceGroupName": autorest.Encode("path", resourceGroupName),
89		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2019-11-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsGet(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections", pathParameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// ListByVpnConnectionSender sends the ListByVpnConnection request. The method will close the
106// http.Response Body if it receives an error.
107func (client VpnLinkConnectionsClient) ListByVpnConnectionSender(req *http.Request) (*http.Response, error) {
108	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109}
110
111// ListByVpnConnectionResponder handles the response to the ListByVpnConnection request. The method always
112// closes the http.Response Body.
113func (client VpnLinkConnectionsClient) ListByVpnConnectionResponder(resp *http.Response) (result ListVpnSiteLinkConnectionsResult, err error) {
114	err = autorest.Respond(
115		resp,
116		client.ByInspecting(),
117		azure.WithErrorUnlessStatusCode(http.StatusOK),
118		autorest.ByUnmarshallingJSON(&result),
119		autorest.ByClosing())
120	result.Response = autorest.Response{Response: resp}
121	return
122}
123
124// listByVpnConnectionNextResults retrieves the next set of results, if any.
125func (client VpnLinkConnectionsClient) listByVpnConnectionNextResults(ctx context.Context, lastResults ListVpnSiteLinkConnectionsResult) (result ListVpnSiteLinkConnectionsResult, err error) {
126	req, err := lastResults.listVpnSiteLinkConnectionsResultPreparer(ctx)
127	if err != nil {
128		return result, autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "listByVpnConnectionNextResults", nil, "Failure preparing next results request")
129	}
130	if req == nil {
131		return
132	}
133	resp, err := client.ListByVpnConnectionSender(req)
134	if err != nil {
135		result.Response = autorest.Response{Response: resp}
136		return result, autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "listByVpnConnectionNextResults", resp, "Failure sending next results request")
137	}
138	result, err = client.ListByVpnConnectionResponder(resp)
139	if err != nil {
140		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "listByVpnConnectionNextResults", resp, "Failure responding to next results request")
141	}
142	return
143}
144
145// ListByVpnConnectionComplete enumerates all values, automatically crossing page boundaries as required.
146func (client VpnLinkConnectionsClient) ListByVpnConnectionComplete(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result ListVpnSiteLinkConnectionsResultIterator, err error) {
147	if tracing.IsEnabled() {
148		ctx = tracing.StartSpan(ctx, fqdn+"/VpnLinkConnectionsClient.ListByVpnConnection")
149		defer func() {
150			sc := -1
151			if result.Response().Response.Response != nil {
152				sc = result.page.Response().Response.Response.StatusCode
153			}
154			tracing.EndSpan(ctx, sc, err)
155		}()
156	}
157	result.page, err = client.ListByVpnConnection(ctx, resourceGroupName, gatewayName, connectionName)
158	return
159}
160