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 using a
40// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
41// Azure stack).
42func NewVpnSitesConfigurationClientWithBaseURI(baseURI string, subscriptionID string) VpnSitesConfigurationClient {
43	return VpnSitesConfigurationClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// Download gives the sas-url to download the configurations for vpn-sites in a resource group.
47// Parameters:
48// resourceGroupName - the resource group name.
49// virtualWANName - the name of the VirtualWAN for which configuration of all vpn-sites is needed.
50// request - parameters supplied to download vpn-sites configuration.
51func (client VpnSitesConfigurationClient) Download(ctx context.Context, resourceGroupName string, virtualWANName string, request GetVpnSitesConfigurationRequest) (result VpnSitesConfigurationDownloadFuture, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/VpnSitesConfigurationClient.Download")
54		defer func() {
55			sc := -1
56			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
57				sc = result.FutureAPI.Response().StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: request,
64			Constraints: []validation.Constraint{{Target: "request.OutputBlobSasURL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
65		return result, validation.NewError("network.VpnSitesConfigurationClient", "Download", err.Error())
66	}
67
68	req, err := client.DownloadPreparer(ctx, resourceGroupName, virtualWANName, request)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "network.VpnSitesConfigurationClient", "Download", nil, "Failure preparing request")
71		return
72	}
73
74	result, err = client.DownloadSender(req)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "network.VpnSitesConfigurationClient", "Download", nil, "Failure sending request")
77		return
78	}
79
80	return
81}
82
83// DownloadPreparer prepares the Download request.
84func (client VpnSitesConfigurationClient) DownloadPreparer(ctx context.Context, resourceGroupName string, virtualWANName string, request GetVpnSitesConfigurationRequest) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"resourceGroupName": autorest.Encode("path", resourceGroupName),
87		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
88		"virtualWANName":    autorest.Encode("path", virtualWANName),
89	}
90
91	const APIVersion = "2019-06-01"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsContentType("application/json; charset=utf-8"),
98		autorest.AsPost(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualWans/{virtualWANName}/vpnConfiguration", pathParameters),
101		autorest.WithJSON(request),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// DownloadSender sends the Download request. The method will close the
107// http.Response Body if it receives an error.
108func (client VpnSitesConfigurationClient) DownloadSender(req *http.Request) (future VpnSitesConfigurationDownloadFuture, err error) {
109	var resp *http.Response
110	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
111	if err != nil {
112		return
113	}
114	var azf azure.Future
115	azf, err = azure.NewFutureFromResponse(resp)
116	future.FutureAPI = &azf
117	future.Result = func(client VpnSitesConfigurationClient) (ar autorest.Response, err error) {
118		var done bool
119		done, err = future.DoneWithContext(context.Background(), client)
120		if err != nil {
121			err = autorest.NewErrorWithError(err, "network.VpnSitesConfigurationDownloadFuture", "Result", future.Response(), "Polling failure")
122			return
123		}
124		if !done {
125			err = azure.NewAsyncOpIncompleteError("network.VpnSitesConfigurationDownloadFuture")
126			return
127		}
128		ar.Response = future.Response()
129		return
130	}
131	return
132}
133
134// DownloadResponder handles the response to the Download request. The method always
135// closes the http.Response Body.
136func (client VpnSitesConfigurationClient) DownloadResponder(resp *http.Response) (result autorest.Response, err error) {
137	err = autorest.Respond(
138		resp,
139		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
140		autorest.ByClosing())
141	result.Response = resp
142	return
143}
144