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/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// VpnSitesConfigurationClient is the network Client
30type VpnSitesConfigurationClient struct {
31	BaseClient
32}
33
34// NewVpnSitesConfigurationClient creates an instance of the VpnSitesConfigurationClient client.
35func NewVpnSitesConfigurationClient(subscriptionID string) VpnSitesConfigurationClient {
36	return NewVpnSitesConfigurationClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewVpnSitesConfigurationClientWithBaseURI creates an instance of the VpnSitesConfigurationClient client.
40func NewVpnSitesConfigurationClientWithBaseURI(baseURI string, subscriptionID string) VpnSitesConfigurationClient {
41	return VpnSitesConfigurationClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Download gives the sas-url to download the configurations for vpn-sites in a resource group.
45// Parameters:
46// resourceGroupName - the resource group name.
47// virtualWANName - the name of the VirtualWAN for which configuration of all vpn-sites is needed.
48// request - parameters supplied to download vpn-sites configuration.
49func (client VpnSitesConfigurationClient) Download(ctx context.Context, resourceGroupName string, virtualWANName string, request GetVpnSitesConfigurationRequest) (result VpnSitesConfigurationDownloadFuture, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/VpnSitesConfigurationClient.Download")
52		defer func() {
53			sc := -1
54			if result.Response() != nil {
55				sc = result.Response().StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: request,
62			Constraints: []validation.Constraint{{Target: "request.OutputBlobSasURL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
63		return result, validation.NewError("network.VpnSitesConfigurationClient", "Download", err.Error())
64	}
65
66	req, err := client.DownloadPreparer(ctx, resourceGroupName, virtualWANName, request)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "network.VpnSitesConfigurationClient", "Download", nil, "Failure preparing request")
69		return
70	}
71
72	result, err = client.DownloadSender(req)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "network.VpnSitesConfigurationClient", "Download", result.Response(), "Failure sending request")
75		return
76	}
77
78	return
79}
80
81// DownloadPreparer prepares the Download request.
82func (client VpnSitesConfigurationClient) DownloadPreparer(ctx context.Context, resourceGroupName string, virtualWANName string, request GetVpnSitesConfigurationRequest) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"resourceGroupName": autorest.Encode("path", resourceGroupName),
85		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
86		"virtualWANName":    autorest.Encode("path", virtualWANName),
87	}
88
89	const APIVersion = "2019-07-01"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	preparer := autorest.CreatePreparer(
95		autorest.AsContentType("application/json; charset=utf-8"),
96		autorest.AsPost(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualWans/{virtualWANName}/vpnConfiguration", pathParameters),
99		autorest.WithJSON(request),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// DownloadSender sends the Download request. The method will close the
105// http.Response Body if it receives an error.
106func (client VpnSitesConfigurationClient) DownloadSender(req *http.Request) (future VpnSitesConfigurationDownloadFuture, err error) {
107	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
108	var resp *http.Response
109	resp, err = autorest.SendWithSender(client, req, sd...)
110	if err != nil {
111		return
112	}
113	future.Future, err = azure.NewFutureFromResponse(resp)
114	return
115}
116
117// DownloadResponder handles the response to the Download request. The method always
118// closes the http.Response Body.
119func (client VpnSitesConfigurationClient) DownloadResponder(resp *http.Response) (result autorest.Response, err error) {
120	err = autorest.Respond(
121		resp,
122		client.ByInspecting(),
123		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
124		autorest.ByClosing())
125	result.Response = resp
126	return
127}
128