1 package network
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/tracing"
14 "net/http"
15 )
16
17
18 type VpnConnectionsClient struct {
19 BaseClient
20 }
21
22
23 func NewVpnConnectionsClient(subscriptionID string) VpnConnectionsClient {
24 return NewVpnConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewVpnConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VpnConnectionsClient {
30 return VpnConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38
39
40 func (client VpnConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VpnConnection) (result VpnConnectionsCreateOrUpdateFuture, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
46 sc = result.FutureAPI.Response().StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, gatewayName, connectionName, vpnConnectionParameters)
52 if err != nil {
53 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
54 return
55 }
56
57 result, err = client.CreateOrUpdateSender(req)
58 if err != nil {
59 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
60 return
61 }
62
63 return
64 }
65
66
67 func (client VpnConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VpnConnection) (*http.Request, error) {
68 pathParameters := map[string]interface{}{
69 "connectionName": autorest.Encode("path", connectionName),
70 "gatewayName": autorest.Encode("path", gatewayName),
71 "resourceGroupName": autorest.Encode("path", resourceGroupName),
72 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
73 }
74
75 const APIVersion = "2018-08-01"
76 queryParameters := map[string]interface{}{
77 "api-version": APIVersion,
78 }
79
80 vpnConnectionParameters.Etag = nil
81 preparer := autorest.CreatePreparer(
82 autorest.AsContentType("application/json; charset=utf-8"),
83 autorest.AsPut(),
84 autorest.WithBaseURL(client.BaseURI),
85 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters),
86 autorest.WithJSON(vpnConnectionParameters),
87 autorest.WithQueryParameters(queryParameters))
88 return preparer.Prepare((&http.Request{}).WithContext(ctx))
89 }
90
91
92
93 func (client VpnConnectionsClient) CreateOrUpdateSender(req *http.Request) (future VpnConnectionsCreateOrUpdateFuture, err error) {
94 var resp *http.Response
95 future.FutureAPI = &azure.Future{}
96 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
97 if err != nil {
98 return
99 }
100 var azf azure.Future
101 azf, err = azure.NewFutureFromResponse(resp)
102 future.FutureAPI = &azf
103 future.Result = future.result
104 return
105 }
106
107
108
109 func (client VpnConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result VpnConnection, err error) {
110 err = autorest.Respond(
111 resp,
112 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
113 autorest.ByUnmarshallingJSON(&result),
114 autorest.ByClosing())
115 result.Response = autorest.Response{Response: resp}
116 return
117 }
118
119
120
121
122
123
124 func (client VpnConnectionsClient) Delete(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result VpnConnectionsDeleteFuture, err error) {
125 if tracing.IsEnabled() {
126 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.Delete")
127 defer func() {
128 sc := -1
129 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
130 sc = result.FutureAPI.Response().StatusCode
131 }
132 tracing.EndSpan(ctx, sc, err)
133 }()
134 }
135 req, err := client.DeletePreparer(ctx, resourceGroupName, gatewayName, connectionName)
136 if err != nil {
137 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Delete", nil, "Failure preparing request")
138 return
139 }
140
141 result, err = client.DeleteSender(req)
142 if err != nil {
143 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Delete", result.Response(), "Failure sending request")
144 return
145 }
146
147 return
148 }
149
150
151 func (client VpnConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) {
152 pathParameters := map[string]interface{}{
153 "connectionName": autorest.Encode("path", connectionName),
154 "gatewayName": autorest.Encode("path", gatewayName),
155 "resourceGroupName": autorest.Encode("path", resourceGroupName),
156 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
157 }
158
159 const APIVersion = "2018-08-01"
160 queryParameters := map[string]interface{}{
161 "api-version": APIVersion,
162 }
163
164 preparer := autorest.CreatePreparer(
165 autorest.AsDelete(),
166 autorest.WithBaseURL(client.BaseURI),
167 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters),
168 autorest.WithQueryParameters(queryParameters))
169 return preparer.Prepare((&http.Request{}).WithContext(ctx))
170 }
171
172
173
174 func (client VpnConnectionsClient) DeleteSender(req *http.Request) (future VpnConnectionsDeleteFuture, err error) {
175 var resp *http.Response
176 future.FutureAPI = &azure.Future{}
177 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
178 if err != nil {
179 return
180 }
181 var azf azure.Future
182 azf, err = azure.NewFutureFromResponse(resp)
183 future.FutureAPI = &azf
184 future.Result = future.result
185 return
186 }
187
188
189
190 func (client VpnConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
191 err = autorest.Respond(
192 resp,
193 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
194 autorest.ByClosing())
195 result.Response = resp
196 return
197 }
198
199
200
201
202
203
204 func (client VpnConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result VpnConnection, err error) {
205 if tracing.IsEnabled() {
206 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.Get")
207 defer func() {
208 sc := -1
209 if result.Response.Response != nil {
210 sc = result.Response.Response.StatusCode
211 }
212 tracing.EndSpan(ctx, sc, err)
213 }()
214 }
215 req, err := client.GetPreparer(ctx, resourceGroupName, gatewayName, connectionName)
216 if err != nil {
217 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Get", nil, "Failure preparing request")
218 return
219 }
220
221 resp, err := client.GetSender(req)
222 if err != nil {
223 result.Response = autorest.Response{Response: resp}
224 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Get", resp, "Failure sending request")
225 return
226 }
227
228 result, err = client.GetResponder(resp)
229 if err != nil {
230 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "Get", resp, "Failure responding to request")
231 return
232 }
233
234 return
235 }
236
237
238 func (client VpnConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) {
239 pathParameters := map[string]interface{}{
240 "connectionName": autorest.Encode("path", connectionName),
241 "gatewayName": autorest.Encode("path", gatewayName),
242 "resourceGroupName": autorest.Encode("path", resourceGroupName),
243 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
244 }
245
246 const APIVersion = "2018-08-01"
247 queryParameters := map[string]interface{}{
248 "api-version": APIVersion,
249 }
250
251 preparer := autorest.CreatePreparer(
252 autorest.AsGet(),
253 autorest.WithBaseURL(client.BaseURI),
254 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters),
255 autorest.WithQueryParameters(queryParameters))
256 return preparer.Prepare((&http.Request{}).WithContext(ctx))
257 }
258
259
260
261 func (client VpnConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
262 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
263 }
264
265
266
267 func (client VpnConnectionsClient) GetResponder(resp *http.Response) (result VpnConnection, err error) {
268 err = autorest.Respond(
269 resp,
270 azure.WithErrorUnlessStatusCode(http.StatusOK),
271 autorest.ByUnmarshallingJSON(&result),
272 autorest.ByClosing())
273 result.Response = autorest.Response{Response: resp}
274 return
275 }
276
277
278
279
280
281 func (client VpnConnectionsClient) ListByVpnGateway(ctx context.Context, resourceGroupName string, gatewayName string) (result ListVpnConnectionsResultPage, err error) {
282 if tracing.IsEnabled() {
283 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.ListByVpnGateway")
284 defer func() {
285 sc := -1
286 if result.lvcr.Response.Response != nil {
287 sc = result.lvcr.Response.Response.StatusCode
288 }
289 tracing.EndSpan(ctx, sc, err)
290 }()
291 }
292 result.fn = client.listByVpnGatewayNextResults
293 req, err := client.ListByVpnGatewayPreparer(ctx, resourceGroupName, gatewayName)
294 if err != nil {
295 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", nil, "Failure preparing request")
296 return
297 }
298
299 resp, err := client.ListByVpnGatewaySender(req)
300 if err != nil {
301 result.lvcr.Response = autorest.Response{Response: resp}
302 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", resp, "Failure sending request")
303 return
304 }
305
306 result.lvcr, err = client.ListByVpnGatewayResponder(resp)
307 if err != nil {
308 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", resp, "Failure responding to request")
309 return
310 }
311 if result.lvcr.hasNextLink() && result.lvcr.IsEmpty() {
312 err = result.NextWithContext(ctx)
313 return
314 }
315
316 return
317 }
318
319
320 func (client VpnConnectionsClient) ListByVpnGatewayPreparer(ctx context.Context, resourceGroupName string, gatewayName string) (*http.Request, error) {
321 pathParameters := map[string]interface{}{
322 "gatewayName": autorest.Encode("path", gatewayName),
323 "resourceGroupName": autorest.Encode("path", resourceGroupName),
324 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
325 }
326
327 const APIVersion = "2018-08-01"
328 queryParameters := map[string]interface{}{
329 "api-version": APIVersion,
330 }
331
332 preparer := autorest.CreatePreparer(
333 autorest.AsGet(),
334 autorest.WithBaseURL(client.BaseURI),
335 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections", pathParameters),
336 autorest.WithQueryParameters(queryParameters))
337 return preparer.Prepare((&http.Request{}).WithContext(ctx))
338 }
339
340
341
342 func (client VpnConnectionsClient) ListByVpnGatewaySender(req *http.Request) (*http.Response, error) {
343 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
344 }
345
346
347
348 func (client VpnConnectionsClient) ListByVpnGatewayResponder(resp *http.Response) (result ListVpnConnectionsResult, err error) {
349 err = autorest.Respond(
350 resp,
351 azure.WithErrorUnlessStatusCode(http.StatusOK),
352 autorest.ByUnmarshallingJSON(&result),
353 autorest.ByClosing())
354 result.Response = autorest.Response{Response: resp}
355 return
356 }
357
358
359 func (client VpnConnectionsClient) listByVpnGatewayNextResults(ctx context.Context, lastResults ListVpnConnectionsResult) (result ListVpnConnectionsResult, err error) {
360 req, err := lastResults.listVpnConnectionsResultPreparer(ctx)
361 if err != nil {
362 return result, autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", nil, "Failure preparing next results request")
363 }
364 if req == nil {
365 return
366 }
367 resp, err := client.ListByVpnGatewaySender(req)
368 if err != nil {
369 result.Response = autorest.Response{Response: resp}
370 return result, autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", resp, "Failure sending next results request")
371 }
372 result, err = client.ListByVpnGatewayResponder(resp)
373 if err != nil {
374 err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", resp, "Failure responding to next results request")
375 }
376 return
377 }
378
379
380 func (client VpnConnectionsClient) ListByVpnGatewayComplete(ctx context.Context, resourceGroupName string, gatewayName string) (result ListVpnConnectionsResultIterator, err error) {
381 if tracing.IsEnabled() {
382 ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.ListByVpnGateway")
383 defer func() {
384 sc := -1
385 if result.Response().Response.Response != nil {
386 sc = result.page.Response().Response.Response.StatusCode
387 }
388 tracing.EndSpan(ctx, sc, err)
389 }()
390 }
391 result.page, err = client.ListByVpnGateway(ctx, resourceGroupName, gatewayName)
392 return
393 }
394
View as plain text