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.
39func NewVpnLinkConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VpnLinkConnectionsClient {
40	return VpnLinkConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// ListByVpnConnection retrieves all vpn site link connections for a particular virtual wan vpn gateway vpn connection.
44// Parameters:
45// resourceGroupName - the resource group name of the VpnGateway.
46// gatewayName - the name of the gateway.
47// connectionName - the name of the vpn connection.
48func (client VpnLinkConnectionsClient) ListByVpnConnection(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result ListVpnSiteLinkConnectionsResultPage, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/VpnLinkConnectionsClient.ListByVpnConnection")
51		defer func() {
52			sc := -1
53			if result.lvslcr.Response.Response != nil {
54				sc = result.lvslcr.Response.Response.StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	result.fn = client.listByVpnConnectionNextResults
60	req, err := client.ListByVpnConnectionPreparer(ctx, resourceGroupName, gatewayName, connectionName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "ListByVpnConnection", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.ListByVpnConnectionSender(req)
67	if err != nil {
68		result.lvslcr.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "ListByVpnConnection", resp, "Failure sending request")
70		return
71	}
72
73	result.lvslcr, err = client.ListByVpnConnectionResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "ListByVpnConnection", resp, "Failure responding to request")
76	}
77
78	return
79}
80
81// ListByVpnConnectionPreparer prepares the ListByVpnConnection request.
82func (client VpnLinkConnectionsClient) ListByVpnConnectionPreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"connectionName":    autorest.Encode("path", connectionName),
85		"gatewayName":       autorest.Encode("path", gatewayName),
86		"resourceGroupName": autorest.Encode("path", resourceGroupName),
87		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
88	}
89
90	const APIVersion = "2019-09-01"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsGet(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections", pathParameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// ListByVpnConnectionSender sends the ListByVpnConnection request. The method will close the
104// http.Response Body if it receives an error.
105func (client VpnLinkConnectionsClient) ListByVpnConnectionSender(req *http.Request) (*http.Response, error) {
106	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
107	return autorest.SendWithSender(client, req, sd...)
108}
109
110// ListByVpnConnectionResponder handles the response to the ListByVpnConnection request. The method always
111// closes the http.Response Body.
112func (client VpnLinkConnectionsClient) ListByVpnConnectionResponder(resp *http.Response) (result ListVpnSiteLinkConnectionsResult, err error) {
113	err = autorest.Respond(
114		resp,
115		client.ByInspecting(),
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122
123// listByVpnConnectionNextResults retrieves the next set of results, if any.
124func (client VpnLinkConnectionsClient) listByVpnConnectionNextResults(ctx context.Context, lastResults ListVpnSiteLinkConnectionsResult) (result ListVpnSiteLinkConnectionsResult, err error) {
125	req, err := lastResults.listVpnSiteLinkConnectionsResultPreparer(ctx)
126	if err != nil {
127		return result, autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "listByVpnConnectionNextResults", nil, "Failure preparing next results request")
128	}
129	if req == nil {
130		return
131	}
132	resp, err := client.ListByVpnConnectionSender(req)
133	if err != nil {
134		result.Response = autorest.Response{Response: resp}
135		return result, autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "listByVpnConnectionNextResults", resp, "Failure sending next results request")
136	}
137	result, err = client.ListByVpnConnectionResponder(resp)
138	if err != nil {
139		err = autorest.NewErrorWithError(err, "network.VpnLinkConnectionsClient", "listByVpnConnectionNextResults", resp, "Failure responding to next results request")
140	}
141	return
142}
143
144// ListByVpnConnectionComplete enumerates all values, automatically crossing page boundaries as required.
145func (client VpnLinkConnectionsClient) ListByVpnConnectionComplete(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result ListVpnSiteLinkConnectionsResultIterator, err error) {
146	if tracing.IsEnabled() {
147		ctx = tracing.StartSpan(ctx, fqdn+"/VpnLinkConnectionsClient.ListByVpnConnection")
148		defer func() {
149			sc := -1
150			if result.Response().Response.Response != nil {
151				sc = result.page.Response().Response.Response.StatusCode
152			}
153			tracing.EndSpan(ctx, sc, err)
154		}()
155	}
156	result.page, err = client.ListByVpnConnection(ctx, resourceGroupName, gatewayName, connectionName)
157	return
158}
159