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 using a custom
40// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
41// stack).
42func NewExpressRouteGatewaysClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteGatewaysClient {
43	return ExpressRouteGatewaysClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates or updates a ExpressRoute gateway in a specified resource group.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// expressRouteGatewayName - the name of the ExpressRoute gateway.
50// putExpressRouteGatewayParameters - parameters required in an ExpressRoute gateway PUT operation.
51func (client ExpressRouteGatewaysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway) (result ExpressRouteGatewaysCreateOrUpdateFuture, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.CreateOrUpdate")
54		defer func() {
55			sc := -1
56			if result.Response() != nil {
57				sc = result.Response().StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: putExpressRouteGatewayParameters,
64			Constraints: []validation.Constraint{{Target: "putExpressRouteGatewayParameters.ExpressRouteGatewayProperties", Name: validation.Null, Rule: false,
65				Chain: []validation.Constraint{{Target: "putExpressRouteGatewayParameters.ExpressRouteGatewayProperties.VirtualHub", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
66		return result, validation.NewError("network.ExpressRouteGatewaysClient", "CreateOrUpdate", err.Error())
67	}
68
69	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, expressRouteGatewayName, putExpressRouteGatewayParameters)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request")
72		return
73	}
74
75	result, err = client.CreateOrUpdateSender(req)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "CreateOrUpdate", result.Response(), "Failure sending request")
78		return
79	}
80
81	return
82}
83
84// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
85func (client ExpressRouteGatewaysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters ExpressRouteGateway) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
88		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
89		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2019-11-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	putExpressRouteGatewayParameters.Etag = nil
98	preparer := autorest.CreatePreparer(
99		autorest.AsContentType("application/json; charset=utf-8"),
100		autorest.AsPut(),
101		autorest.WithBaseURL(client.BaseURI),
102		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
103		autorest.WithJSON(putExpressRouteGatewayParameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
109// http.Response Body if it receives an error.
110func (client ExpressRouteGatewaysClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteGatewaysCreateOrUpdateFuture, err error) {
111	var resp *http.Response
112	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
113	if err != nil {
114		return
115	}
116	future.Future, err = azure.NewFutureFromResponse(resp)
117	return
118}
119
120// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
121// closes the http.Response Body.
122func (client ExpressRouteGatewaysClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteGateway, err error) {
123	err = autorest.Respond(
124		resp,
125		client.ByInspecting(),
126		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
127		autorest.ByUnmarshallingJSON(&result),
128		autorest.ByClosing())
129	result.Response = autorest.Response{Response: resp}
130	return
131}
132
133// Delete deletes the specified ExpressRoute gateway in a resource group. An ExpressRoute gateway resource can only be
134// deleted when there are no connection subresources.
135// Parameters:
136// resourceGroupName - the name of the resource group.
137// expressRouteGatewayName - the name of the ExpressRoute gateway.
138func (client ExpressRouteGatewaysClient) Delete(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteGatewaysDeleteFuture, err error) {
139	if tracing.IsEnabled() {
140		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.Delete")
141		defer func() {
142			sc := -1
143			if result.Response() != nil {
144				sc = result.Response().StatusCode
145			}
146			tracing.EndSpan(ctx, sc, err)
147		}()
148	}
149	req, err := client.DeletePreparer(ctx, resourceGroupName, expressRouteGatewayName)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Delete", nil, "Failure preparing request")
152		return
153	}
154
155	result, err = client.DeleteSender(req)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "Delete", result.Response(), "Failure sending request")
158		return
159	}
160
161	return
162}
163
164// DeletePreparer prepares the Delete request.
165func (client ExpressRouteGatewaysClient) DeletePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
166	pathParameters := map[string]interface{}{
167		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
168		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
169		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
170	}
171
172	const APIVersion = "2019-11-01"
173	queryParameters := map[string]interface{}{
174		"api-version": APIVersion,
175	}
176
177	preparer := autorest.CreatePreparer(
178		autorest.AsDelete(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}", pathParameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// DeleteSender sends the Delete request. The method will close the
186// http.Response Body if it receives an error.
187func (client ExpressRouteGatewaysClient) DeleteSender(req *http.Request) (future ExpressRouteGatewaysDeleteFuture, err error) {
188	var resp *http.Response
189	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
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-11-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	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
270}
271
272// GetResponder handles the response to the Get request. The method always
273// closes the http.Response Body.
274func (client ExpressRouteGatewaysClient) GetResponder(resp *http.Response) (result ExpressRouteGateway, err error) {
275	err = autorest.Respond(
276		resp,
277		client.ByInspecting(),
278		azure.WithErrorUnlessStatusCode(http.StatusOK),
279		autorest.ByUnmarshallingJSON(&result),
280		autorest.ByClosing())
281	result.Response = autorest.Response{Response: resp}
282	return
283}
284
285// ListByResourceGroup lists ExpressRoute gateways in a given resource group.
286// Parameters:
287// resourceGroupName - the name of the resource group.
288func (client ExpressRouteGatewaysClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ExpressRouteGatewayList, err error) {
289	if tracing.IsEnabled() {
290		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.ListByResourceGroup")
291		defer func() {
292			sc := -1
293			if result.Response.Response != nil {
294				sc = result.Response.Response.StatusCode
295			}
296			tracing.EndSpan(ctx, sc, err)
297		}()
298	}
299	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
300	if err != nil {
301		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", nil, "Failure preparing request")
302		return
303	}
304
305	resp, err := client.ListByResourceGroupSender(req)
306	if err != nil {
307		result.Response = autorest.Response{Response: resp}
308		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", resp, "Failure sending request")
309		return
310	}
311
312	result, err = client.ListByResourceGroupResponder(resp)
313	if err != nil {
314		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListByResourceGroup", resp, "Failure responding to request")
315	}
316
317	return
318}
319
320// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
321func (client ExpressRouteGatewaysClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
322	pathParameters := map[string]interface{}{
323		"resourceGroupName": autorest.Encode("path", resourceGroupName),
324		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
325	}
326
327	const APIVersion = "2019-11-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/expressRouteGateways", pathParameters),
336		autorest.WithQueryParameters(queryParameters))
337	return preparer.Prepare((&http.Request{}).WithContext(ctx))
338}
339
340// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
341// http.Response Body if it receives an error.
342func (client ExpressRouteGatewaysClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
343	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
344}
345
346// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
347// closes the http.Response Body.
348func (client ExpressRouteGatewaysClient) ListByResourceGroupResponder(resp *http.Response) (result ExpressRouteGatewayList, err error) {
349	err = autorest.Respond(
350		resp,
351		client.ByInspecting(),
352		azure.WithErrorUnlessStatusCode(http.StatusOK),
353		autorest.ByUnmarshallingJSON(&result),
354		autorest.ByClosing())
355	result.Response = autorest.Response{Response: resp}
356	return
357}
358
359// ListBySubscription lists ExpressRoute gateways under a given subscription.
360func (client ExpressRouteGatewaysClient) ListBySubscription(ctx context.Context) (result ExpressRouteGatewayList, err error) {
361	if tracing.IsEnabled() {
362		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteGatewaysClient.ListBySubscription")
363		defer func() {
364			sc := -1
365			if result.Response.Response != nil {
366				sc = result.Response.Response.StatusCode
367			}
368			tracing.EndSpan(ctx, sc, err)
369		}()
370	}
371	req, err := client.ListBySubscriptionPreparer(ctx)
372	if err != nil {
373		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", nil, "Failure preparing request")
374		return
375	}
376
377	resp, err := client.ListBySubscriptionSender(req)
378	if err != nil {
379		result.Response = autorest.Response{Response: resp}
380		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", resp, "Failure sending request")
381		return
382	}
383
384	result, err = client.ListBySubscriptionResponder(resp)
385	if err != nil {
386		err = autorest.NewErrorWithError(err, "network.ExpressRouteGatewaysClient", "ListBySubscription", resp, "Failure responding to request")
387	}
388
389	return
390}
391
392// ListBySubscriptionPreparer prepares the ListBySubscription request.
393func (client ExpressRouteGatewaysClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
394	pathParameters := map[string]interface{}{
395		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
396	}
397
398	const APIVersion = "2019-11-01"
399	queryParameters := map[string]interface{}{
400		"api-version": APIVersion,
401	}
402
403	preparer := autorest.CreatePreparer(
404		autorest.AsGet(),
405		autorest.WithBaseURL(client.BaseURI),
406		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteGateways", pathParameters),
407		autorest.WithQueryParameters(queryParameters))
408	return preparer.Prepare((&http.Request{}).WithContext(ctx))
409}
410
411// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
412// http.Response Body if it receives an error.
413func (client ExpressRouteGatewaysClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
414	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
415}
416
417// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
418// closes the http.Response Body.
419func (client ExpressRouteGatewaysClient) ListBySubscriptionResponder(resp *http.Response) (result ExpressRouteGatewayList, err error) {
420	err = autorest.Respond(
421		resp,
422		client.ByInspecting(),
423		azure.WithErrorUnlessStatusCode(http.StatusOK),
424		autorest.ByUnmarshallingJSON(&result),
425		autorest.ByClosing())
426	result.Response = autorest.Response{Response: resp}
427	return
428}
429