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// ExpressRouteGatewaysClient is the network Client
30type ExpressRouteGatewaysClient struct {
31	BaseClient
32}
33
34// NewExpressRouteGatewaysClient creates an instance of the ExpressRouteGatewaysClient client.
35func NewExpressRouteGatewaysClient(subscriptionID string) ExpressRouteGatewaysClient {
36	return NewExpressRouteGatewaysClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewExpressRouteGatewaysClientWithBaseURI creates an instance of the ExpressRouteGatewaysClient client.
40func NewExpressRouteGatewaysClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteGatewaysClient {
41	return ExpressRouteGatewaysClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or updates a ExpressRoute gateway in a specified resource group.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// expressRouteGatewayName - the name of the ExpressRoute gateway.
48// putExpressRouteGatewayParameters - parameters required in an ExpressRoute gateway PUT operation.
49func (client ExpressRouteGatewaysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway) (result ExpressRouteGatewaysCreateOrUpdateFuture, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.CreateOrUpdate")
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: putExpressRouteGatewayParameters,
62			Constraints: []validation.Constraint{{Target: "putExpressRouteGatewayParameters.ExpressRouteGatewayProperties", Name: validation.Null, Rule: false,
63				Chain: []validation.Constraint{{Target: "putExpressRouteGatewayParameters.ExpressRouteGatewayProperties.VirtualHub", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
64		return result, validation.NewError("network.ExpressRouteGatewaysClient", "CreateOrUpdate", err.Error())
65	}
66
67	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, expressRouteGatewayName, putExpressRouteGatewayParameters)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request")
70		return
71	}
72
73	result, err = client.CreateOrUpdateSender(req)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "CreateOrUpdate", result.Response(), "Failure sending request")
76		return
77	}
78
79	return
80}
81
82// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
83func (client ExpressRouteGatewaysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
86		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
87		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
88	}
89
90	const APIVersion = "2019-07-01"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	putExpressRouteGatewayParameters.Etag = nil
96	preparer := autorest.CreatePreparer(
97		autorest.AsContentType("application/json; charset=utf-8"),
98		autorest.AsPut(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
101		autorest.WithJSON(putExpressRouteGatewayParameters),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
107// http.Response Body if it receives an error.
108func (client ExpressRouteGatewaysClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteGatewaysCreateOrUpdateFuture, err error) {
109	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
110	var resp *http.Response
111	resp, err = autorest.SendWithSender(client, req, sd...)
112	if err != nil {
113		return
114	}
115	future.Future, err = azure.NewFutureFromResponse(resp)
116	return
117}
118
119// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
120// closes the http.Response Body.
121func (client ExpressRouteGatewaysClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteGateway, err error) {
122	err = autorest.Respond(
123		resp,
124		client.ByInspecting(),
125		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
126		autorest.ByUnmarshallingJSON(&result),
127		autorest.ByClosing())
128	result.Response = autorest.Response{Response: resp}
129	return
130}
131
132// Delete deletes the specified ExpressRoute gateway in a resource group. An ExpressRoute gateway resource can only be
133// deleted when there are no connection subresources.
134// Parameters:
135// resourceGroupName - the name of the resource group.
136// expressRouteGatewayName - the name of the ExpressRoute gateway.
137func (client ExpressRouteGatewaysClient) Delete(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteGatewaysDeleteFuture, err error) {
138	if tracing.IsEnabled() {
139		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.Delete")
140		defer func() {
141			sc := -1
142			if result.Response() != nil {
143				sc = result.Response().StatusCode
144			}
145			tracing.EndSpan(ctx, sc, err)
146		}()
147	}
148	req, err := client.DeletePreparer(ctx, resourceGroupName, expressRouteGatewayName)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Delete", nil, "Failure preparing request")
151		return
152	}
153
154	result, err = client.DeleteSender(req)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Delete", result.Response(), "Failure sending request")
157		return
158	}
159
160	return
161}
162
163// DeletePreparer prepares the Delete request.
164func (client ExpressRouteGatewaysClient) DeletePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
167		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
168		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
169	}
170
171	const APIVersion = "2019-07-01"
172	queryParameters := map[string]interface{}{
173		"api-version": APIVersion,
174	}
175
176	preparer := autorest.CreatePreparer(
177		autorest.AsDelete(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
180		autorest.WithQueryParameters(queryParameters))
181	return preparer.Prepare((&http.Request{}).WithContext(ctx))
182}
183
184// DeleteSender sends the Delete request. The method will close the
185// http.Response Body if it receives an error.
186func (client ExpressRouteGatewaysClient) DeleteSender(req *http.Request) (future ExpressRouteGatewaysDeleteFuture, err error) {
187	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
188	var resp *http.Response
189	resp, err = autorest.SendWithSender(client, req, sd...)
190	if err != nil {
191		return
192	}
193	future.Future, err = azure.NewFutureFromResponse(resp)
194	return
195}
196
197// DeleteResponder handles the response to the Delete request. The method always
198// closes the http.Response Body.
199func (client ExpressRouteGatewaysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
200	err = autorest.Respond(
201		resp,
202		client.ByInspecting(),
203		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
204		autorest.ByClosing())
205	result.Response = resp
206	return
207}
208
209// Get fetches the details of a ExpressRoute gateway in a resource group.
210// Parameters:
211// resourceGroupName - the name of the resource group.
212// expressRouteGatewayName - the name of the ExpressRoute gateway.
213func (client ExpressRouteGatewaysClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteGateway, err error) {
214	if tracing.IsEnabled() {
215		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.Get")
216		defer func() {
217			sc := -1
218			if result.Response.Response != nil {
219				sc = result.Response.Response.StatusCode
220			}
221			tracing.EndSpan(ctx, sc, err)
222		}()
223	}
224	req, err := client.GetPreparer(ctx, resourceGroupName, expressRouteGatewayName)
225	if err != nil {
226		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Get", nil, "Failure preparing request")
227		return
228	}
229
230	resp, err := client.GetSender(req)
231	if err != nil {
232		result.Response = autorest.Response{Response: resp}
233		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Get", resp, "Failure sending request")
234		return
235	}
236
237	result, err = client.GetResponder(resp)
238	if err != nil {
239		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Get", resp, "Failure responding to request")
240	}
241
242	return
243}
244
245// GetPreparer prepares the Get request.
246func (client ExpressRouteGatewaysClient) GetPreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
247	pathParameters := map[string]interface{}{
248		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
249		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
250		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
251	}
252
253	const APIVersion = "2019-07-01"
254	queryParameters := map[string]interface{}{
255		"api-version": APIVersion,
256	}
257
258	preparer := autorest.CreatePreparer(
259		autorest.AsGet(),
260		autorest.WithBaseURL(client.BaseURI),
261		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
262		autorest.WithQueryParameters(queryParameters))
263	return preparer.Prepare((&http.Request{}).WithContext(ctx))
264}
265
266// GetSender sends the Get request. The method will close the
267// http.Response Body if it receives an error.
268func (client ExpressRouteGatewaysClient) GetSender(req *http.Request) (*http.Response, error) {
269	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
270	return autorest.SendWithSender(client, req, sd...)
271}
272
273// GetResponder handles the response to the Get request. The method always
274// closes the http.Response Body.
275func (client ExpressRouteGatewaysClient) GetResponder(resp *http.Response) (result ExpressRouteGateway, err error) {
276	err = autorest.Respond(
277		resp,
278		client.ByInspecting(),
279		azure.WithErrorUnlessStatusCode(http.StatusOK),
280		autorest.ByUnmarshallingJSON(&result),
281		autorest.ByClosing())
282	result.Response = autorest.Response{Response: resp}
283	return
284}
285
286// ListByResourceGroup lists ExpressRoute gateways in a given resource group.
287// Parameters:
288// resourceGroupName - the name of the resource group.
289func (client ExpressRouteGatewaysClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ExpressRouteGatewayList, err error) {
290	if tracing.IsEnabled() {
291		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.ListByResourceGroup")
292		defer func() {
293			sc := -1
294			if result.Response.Response != nil {
295				sc = result.Response.Response.StatusCode
296			}
297			tracing.EndSpan(ctx, sc, err)
298		}()
299	}
300	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
301	if err != nil {
302		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", nil, "Failure preparing request")
303		return
304	}
305
306	resp, err := client.ListByResourceGroupSender(req)
307	if err != nil {
308		result.Response = autorest.Response{Response: resp}
309		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", resp, "Failure sending request")
310		return
311	}
312
313	result, err = client.ListByResourceGroupResponder(resp)
314	if err != nil {
315		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", resp, "Failure responding to request")
316	}
317
318	return
319}
320
321// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
322func (client ExpressRouteGatewaysClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
323	pathParameters := map[string]interface{}{
324		"resourceGroupName": autorest.Encode("path", resourceGroupName),
325		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
326	}
327
328	const APIVersion = "2019-07-01"
329	queryParameters := map[string]interface{}{
330		"api-version": APIVersion,
331	}
332
333	preparer := autorest.CreatePreparer(
334		autorest.AsGet(),
335		autorest.WithBaseURL(client.BaseURI),
336		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways", pathParameters),
337		autorest.WithQueryParameters(queryParameters))
338	return preparer.Prepare((&http.Request{}).WithContext(ctx))
339}
340
341// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
342// http.Response Body if it receives an error.
343func (client ExpressRouteGatewaysClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
344	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
345	return autorest.SendWithSender(client, req, sd...)
346}
347
348// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
349// closes the http.Response Body.
350func (client ExpressRouteGatewaysClient) ListByResourceGroupResponder(resp *http.Response) (result ExpressRouteGatewayList, err error) {
351	err = autorest.Respond(
352		resp,
353		client.ByInspecting(),
354		azure.WithErrorUnlessStatusCode(http.StatusOK),
355		autorest.ByUnmarshallingJSON(&result),
356		autorest.ByClosing())
357	result.Response = autorest.Response{Response: resp}
358	return
359}
360
361// ListBySubscription lists ExpressRoute gateways under a given subscription.
362func (client ExpressRouteGatewaysClient) ListBySubscription(ctx context.Context) (result ExpressRouteGatewayList, err error) {
363	if tracing.IsEnabled() {
364		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.ListBySubscription")
365		defer func() {
366			sc := -1
367			if result.Response.Response != nil {
368				sc = result.Response.Response.StatusCode
369			}
370			tracing.EndSpan(ctx, sc, err)
371		}()
372	}
373	req, err := client.ListBySubscriptionPreparer(ctx)
374	if err != nil {
375		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", nil, "Failure preparing request")
376		return
377	}
378
379	resp, err := client.ListBySubscriptionSender(req)
380	if err != nil {
381		result.Response = autorest.Response{Response: resp}
382		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", resp, "Failure sending request")
383		return
384	}
385
386	result, err = client.ListBySubscriptionResponder(resp)
387	if err != nil {
388		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", resp, "Failure responding to request")
389	}
390
391	return
392}
393
394// ListBySubscriptionPreparer prepares the ListBySubscription request.
395func (client ExpressRouteGatewaysClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
396	pathParameters := map[string]interface{}{
397		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
398	}
399
400	const APIVersion = "2019-07-01"
401	queryParameters := map[string]interface{}{
402		"api-version": APIVersion,
403	}
404
405	preparer := autorest.CreatePreparer(
406		autorest.AsGet(),
407		autorest.WithBaseURL(client.BaseURI),
408		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteGateways", pathParameters),
409		autorest.WithQueryParameters(queryParameters))
410	return preparer.Prepare((&http.Request{}).WithContext(ctx))
411}
412
413// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
414// http.Response Body if it receives an error.
415func (client ExpressRouteGatewaysClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
416	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
417	return autorest.SendWithSender(client, req, sd...)
418}
419
420// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
421// closes the http.Response Body.
422func (client ExpressRouteGatewaysClient) ListBySubscriptionResponder(resp *http.Response) (result ExpressRouteGatewayList, err error) {
423	err = autorest.Respond(
424		resp,
425		client.ByInspecting(),
426		azure.WithErrorUnlessStatusCode(http.StatusOK),
427		autorest.ByUnmarshallingJSON(&result),
428		autorest.ByClosing())
429	result.Response = autorest.Response{Response: resp}
430	return
431}
432