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// VpnSiteLinksClient is the network Client
29type VpnSiteLinksClient struct {
30	BaseClient
31}
32
33// NewVpnSiteLinksClient creates an instance of the VpnSiteLinksClient client.
34func NewVpnSiteLinksClient(subscriptionID string) VpnSiteLinksClient {
35	return NewVpnSiteLinksClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewVpnSiteLinksClientWithBaseURI creates an instance of the VpnSiteLinksClient client using a custom endpoint.  Use
39// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewVpnSiteLinksClientWithBaseURI(baseURI string, subscriptionID string) VpnSiteLinksClient {
41	return VpnSiteLinksClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Get retrieves the details of a VPN site link.
45// Parameters:
46// resourceGroupName - the resource group name of the VpnSite.
47// vpnSiteName - the name of the VpnSite.
48// vpnSiteLinkName - the name of the VpnSiteLink being retrieved.
49func (client VpnSiteLinksClient) Get(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteLinkName string) (result VpnSiteLink, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinksClient.Get")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	req, err := client.GetPreparer(ctx, resourceGroupName, vpnSiteName, vpnSiteLinkName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "Get", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.GetSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "Get", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.GetResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "Get", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// GetPreparer prepares the Get request.
83func (client VpnSiteLinksClient) GetPreparer(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteLinkName string) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"resourceGroupName": autorest.Encode("path", resourceGroupName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87		"vpnSiteLinkName":   autorest.Encode("path", vpnSiteLinkName),
88		"vpnSiteName":       autorest.Encode("path", vpnSiteName),
89	}
90
91	const APIVersion = "2019-07-01"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsGet(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnSites/{vpnSiteName}/vpnSiteLinks/{vpnSiteLinkName}", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// GetSender sends the Get request. The method will close the
105// http.Response Body if it receives an error.
106func (client VpnSiteLinksClient) GetSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// GetResponder handles the response to the Get request. The method always
111// closes the http.Response Body.
112func (client VpnSiteLinksClient) GetResponder(resp *http.Response) (result VpnSiteLink, err error) {
113	err = autorest.Respond(
114		resp,
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121
122// ListByVpnSite lists all the vpnSiteLinks in a resource group for a vpn site.
123// Parameters:
124// resourceGroupName - the resource group name of the VpnSite.
125// vpnSiteName - the name of the VpnSite.
126func (client VpnSiteLinksClient) ListByVpnSite(ctx context.Context, resourceGroupName string, vpnSiteName string) (result ListVpnSiteLinksResultPage, err error) {
127	if tracing.IsEnabled() {
128		ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinksClient.ListByVpnSite")
129		defer func() {
130			sc := -1
131			if result.lvslr.Response.Response != nil {
132				sc = result.lvslr.Response.Response.StatusCode
133			}
134			tracing.EndSpan(ctx, sc, err)
135		}()
136	}
137	result.fn = client.listByVpnSiteNextResults
138	req, err := client.ListByVpnSitePreparer(ctx, resourceGroupName, vpnSiteName)
139	if err != nil {
140		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "ListByVpnSite", nil, "Failure preparing request")
141		return
142	}
143
144	resp, err := client.ListByVpnSiteSender(req)
145	if err != nil {
146		result.lvslr.Response = autorest.Response{Response: resp}
147		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "ListByVpnSite", resp, "Failure sending request")
148		return
149	}
150
151	result.lvslr, err = client.ListByVpnSiteResponder(resp)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "ListByVpnSite", resp, "Failure responding to request")
154		return
155	}
156	if result.lvslr.hasNextLink() && result.lvslr.IsEmpty() {
157		err = result.NextWithContext(ctx)
158		return
159	}
160
161	return
162}
163
164// ListByVpnSitePreparer prepares the ListByVpnSite request.
165func (client VpnSiteLinksClient) ListByVpnSitePreparer(ctx context.Context, resourceGroupName string, vpnSiteName string) (*http.Request, error) {
166	pathParameters := map[string]interface{}{
167		"resourceGroupName": autorest.Encode("path", resourceGroupName),
168		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
169		"vpnSiteName":       autorest.Encode("path", vpnSiteName),
170	}
171
172	const APIVersion = "2019-07-01"
173	queryParameters := map[string]interface{}{
174		"api-version": APIVersion,
175	}
176
177	preparer := autorest.CreatePreparer(
178		autorest.AsGet(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnSites/{vpnSiteName}/vpnSiteLinks", pathParameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// ListByVpnSiteSender sends the ListByVpnSite request. The method will close the
186// http.Response Body if it receives an error.
187func (client VpnSiteLinksClient) ListByVpnSiteSender(req *http.Request) (*http.Response, error) {
188	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
189}
190
191// ListByVpnSiteResponder handles the response to the ListByVpnSite request. The method always
192// closes the http.Response Body.
193func (client VpnSiteLinksClient) ListByVpnSiteResponder(resp *http.Response) (result ListVpnSiteLinksResult, err error) {
194	err = autorest.Respond(
195		resp,
196		azure.WithErrorUnlessStatusCode(http.StatusOK),
197		autorest.ByUnmarshallingJSON(&result),
198		autorest.ByClosing())
199	result.Response = autorest.Response{Response: resp}
200	return
201}
202
203// listByVpnSiteNextResults retrieves the next set of results, if any.
204func (client VpnSiteLinksClient) listByVpnSiteNextResults(ctx context.Context, lastResults ListVpnSiteLinksResult) (result ListVpnSiteLinksResult, err error) {
205	req, err := lastResults.listVpnSiteLinksResultPreparer(ctx)
206	if err != nil {
207		return result, autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "listByVpnSiteNextResults", nil, "Failure preparing next results request")
208	}
209	if req == nil {
210		return
211	}
212	resp, err := client.ListByVpnSiteSender(req)
213	if err != nil {
214		result.Response = autorest.Response{Response: resp}
215		return result, autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "listByVpnSiteNextResults", resp, "Failure sending next results request")
216	}
217	result, err = client.ListByVpnSiteResponder(resp)
218	if err != nil {
219		err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "listByVpnSiteNextResults", resp, "Failure responding to next results request")
220	}
221	return
222}
223
224// ListByVpnSiteComplete enumerates all values, automatically crossing page boundaries as required.
225func (client VpnSiteLinksClient) ListByVpnSiteComplete(ctx context.Context, resourceGroupName string, vpnSiteName string) (result ListVpnSiteLinksResultIterator, err error) {
226	if tracing.IsEnabled() {
227		ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinksClient.ListByVpnSite")
228		defer func() {
229			sc := -1
230			if result.Response().Response.Response != nil {
231				sc = result.page.Response().Response.Response.StatusCode
232			}
233			tracing.EndSpan(ctx, sc, err)
234		}()
235	}
236	result.page, err = client.ListByVpnSite(ctx, resourceGroupName, vpnSiteName)
237	return
238}
239