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// VpnSiteLinkConnectionsClient is the network Client
29type VpnSiteLinkConnectionsClient struct {
30	BaseClient
31}
32
33// NewVpnSiteLinkConnectionsClient creates an instance of the VpnSiteLinkConnectionsClient client.
34func NewVpnSiteLinkConnectionsClient(subscriptionID string) VpnSiteLinkConnectionsClient {
35	return NewVpnSiteLinkConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewVpnSiteLinkConnectionsClientWithBaseURI creates an instance of the VpnSiteLinkConnectionsClient client using a
39// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
40// Azure stack).
41func NewVpnSiteLinkConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VpnSiteLinkConnectionsClient {
42	return VpnSiteLinkConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get retrieves the details of a vpn site link 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.
50// linkConnectionName - the name of the vpn connection.
51func (client VpnSiteLinkConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string) (result VpnSiteLinkConnection, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinkConnectionsClient.Get")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	req, err := client.GetPreparer(ctx, resourceGroupName, gatewayName, connectionName, linkConnectionName)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "network.VpnSiteLinkConnectionsClient", "Get", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.GetSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "network.VpnSiteLinkConnectionsClient", "Get", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.GetResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "network.VpnSiteLinkConnectionsClient", "Get", resp, "Failure responding to request")
78	}
79
80	return
81}
82
83// GetPreparer prepares the Get request.
84func (client VpnSiteLinkConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, linkConnectionName string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"connectionName":     autorest.Encode("path", connectionName),
87		"gatewayName":        autorest.Encode("path", gatewayName),
88		"linkConnectionName": autorest.Encode("path", linkConnectionName),
89		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
90		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
91	}
92
93	const APIVersion = "2020-04-01"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsGet(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}", pathParameters),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// GetSender sends the Get request. The method will close the
107// http.Response Body if it receives an error.
108func (client VpnSiteLinkConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
109	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
110}
111
112// GetResponder handles the response to the Get request. The method always
113// closes the http.Response Body.
114func (client VpnSiteLinkConnectionsClient) GetResponder(resp *http.Response) (result VpnSiteLinkConnection, err error) {
115	err = autorest.Respond(
116		resp,
117		client.ByInspecting(),
118		azure.WithErrorUnlessStatusCode(http.StatusOK),
119		autorest.ByUnmarshallingJSON(&result),
120		autorest.ByClosing())
121	result.Response = autorest.Response{Response: resp}
122	return
123}
124