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// ExpressRouteConnectionsClient is the network Client
30type ExpressRouteConnectionsClient struct {
31	BaseClient
32}
33
34// NewExpressRouteConnectionsClient creates an instance of the ExpressRouteConnectionsClient client.
35func NewExpressRouteConnectionsClient(subscriptionID string) ExpressRouteConnectionsClient {
36	return NewExpressRouteConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewExpressRouteConnectionsClientWithBaseURI creates an instance of the ExpressRouteConnectionsClient 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 NewExpressRouteConnectionsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteConnectionsClient {
43	return ExpressRouteConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates a connection between an ExpressRoute gateway and an ExpressRoute circuit.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// expressRouteGatewayName - the name of the ExpressRoute gateway.
50// connectionName - the name of the connection subresource.
51// putExpressRouteConnectionParameters - parameters required in an ExpressRouteConnection PUT operation.
52func (client ExpressRouteConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection) (result ExpressRouteConnectionsCreateOrUpdateFuture, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.CreateOrUpdate")
55		defer func() {
56			sc := -1
57			if result.Response() != nil {
58				sc = result.Response().StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: putExpressRouteConnectionParameters,
65			Constraints: []validation.Constraint{{Target: "putExpressRouteConnectionParameters.ExpressRouteConnectionProperties", Name: validation.Null, Rule: false,
66				Chain: []validation.Constraint{{Target: "putExpressRouteConnectionParameters.ExpressRouteConnectionProperties.ExpressRouteCircuitPeering", Name: validation.Null, Rule: true, Chain: nil}}},
67				{Target: "putExpressRouteConnectionParameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
68		return result, validation.NewError("network.ExpressRouteConnectionsClient", "CreateOrUpdate", err.Error())
69	}
70
71	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, expressRouteGatewayName, connectionName, putExpressRouteConnectionParameters)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
74		return
75	}
76
77	result, err = client.CreateOrUpdateSender(req)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
80		return
81	}
82
83	return
84}
85
86// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
87func (client ExpressRouteConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection) (*http.Request, error) {
88	pathParameters := map[string]interface{}{
89		"connectionName":          autorest.Encode("path", connectionName),
90		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
91		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
92		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
93	}
94
95	const APIVersion = "2020-05-01"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsContentType("application/json; charset=utf-8"),
102		autorest.AsPut(),
103		autorest.WithBaseURL(client.BaseURI),
104		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}", pathParameters),
105		autorest.WithJSON(putExpressRouteConnectionParameters),
106		autorest.WithQueryParameters(queryParameters))
107	return preparer.Prepare((&http.Request{}).WithContext(ctx))
108}
109
110// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
111// http.Response Body if it receives an error.
112func (client ExpressRouteConnectionsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteConnectionsCreateOrUpdateFuture, err error) {
113	var resp *http.Response
114	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
115	if err != nil {
116		return
117	}
118	future.Future, err = azure.NewFutureFromResponse(resp)
119	return
120}
121
122// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
123// closes the http.Response Body.
124func (client ExpressRouteConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteConnection, err error) {
125	err = autorest.Respond(
126		resp,
127		client.ByInspecting(),
128		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
129		autorest.ByUnmarshallingJSON(&result),
130		autorest.ByClosing())
131	result.Response = autorest.Response{Response: resp}
132	return
133}
134
135// Delete deletes a connection to a ExpressRoute circuit.
136// Parameters:
137// resourceGroupName - the name of the resource group.
138// expressRouteGatewayName - the name of the ExpressRoute gateway.
139// connectionName - the name of the connection subresource.
140func (client ExpressRouteConnectionsClient) Delete(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (result ExpressRouteConnectionsDeleteFuture, err error) {
141	if tracing.IsEnabled() {
142		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.Delete")
143		defer func() {
144			sc := -1
145			if result.Response() != nil {
146				sc = result.Response().StatusCode
147			}
148			tracing.EndSpan(ctx, sc, err)
149		}()
150	}
151	req, err := client.DeletePreparer(ctx, resourceGroupName, expressRouteGatewayName, connectionName)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Delete", nil, "Failure preparing request")
154		return
155	}
156
157	result, err = client.DeleteSender(req)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Delete", result.Response(), "Failure sending request")
160		return
161	}
162
163	return
164}
165
166// DeletePreparer prepares the Delete request.
167func (client ExpressRouteConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (*http.Request, error) {
168	pathParameters := map[string]interface{}{
169		"connectionName":          autorest.Encode("path", connectionName),
170		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
171		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
172		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
173	}
174
175	const APIVersion = "2020-05-01"
176	queryParameters := map[string]interface{}{
177		"api-version": APIVersion,
178	}
179
180	preparer := autorest.CreatePreparer(
181		autorest.AsDelete(),
182		autorest.WithBaseURL(client.BaseURI),
183		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}", pathParameters),
184		autorest.WithQueryParameters(queryParameters))
185	return preparer.Prepare((&http.Request{}).WithContext(ctx))
186}
187
188// DeleteSender sends the Delete request. The method will close the
189// http.Response Body if it receives an error.
190func (client ExpressRouteConnectionsClient) DeleteSender(req *http.Request) (future ExpressRouteConnectionsDeleteFuture, err error) {
191	var resp *http.Response
192	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
193	if err != nil {
194		return
195	}
196	future.Future, err = azure.NewFutureFromResponse(resp)
197	return
198}
199
200// DeleteResponder handles the response to the Delete request. The method always
201// closes the http.Response Body.
202func (client ExpressRouteConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
203	err = autorest.Respond(
204		resp,
205		client.ByInspecting(),
206		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
207		autorest.ByClosing())
208	result.Response = resp
209	return
210}
211
212// Get gets the specified ExpressRouteConnection.
213// Parameters:
214// resourceGroupName - the name of the resource group.
215// expressRouteGatewayName - the name of the ExpressRoute gateway.
216// connectionName - the name of the ExpressRoute connection.
217func (client ExpressRouteConnectionsClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (result ExpressRouteConnection, err error) {
218	if tracing.IsEnabled() {
219		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.Get")
220		defer func() {
221			sc := -1
222			if result.Response.Response != nil {
223				sc = result.Response.Response.StatusCode
224			}
225			tracing.EndSpan(ctx, sc, err)
226		}()
227	}
228	req, err := client.GetPreparer(ctx, resourceGroupName, expressRouteGatewayName, connectionName)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Get", nil, "Failure preparing request")
231		return
232	}
233
234	resp, err := client.GetSender(req)
235	if err != nil {
236		result.Response = autorest.Response{Response: resp}
237		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Get", resp, "Failure sending request")
238		return
239	}
240
241	result, err = client.GetResponder(resp)
242	if err != nil {
243		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "Get", resp, "Failure responding to request")
244	}
245
246	return
247}
248
249// GetPreparer prepares the Get request.
250func (client ExpressRouteConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string) (*http.Request, error) {
251	pathParameters := map[string]interface{}{
252		"connectionName":          autorest.Encode("path", connectionName),
253		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
254		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
255		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
256	}
257
258	const APIVersion = "2020-05-01"
259	queryParameters := map[string]interface{}{
260		"api-version": APIVersion,
261	}
262
263	preparer := autorest.CreatePreparer(
264		autorest.AsGet(),
265		autorest.WithBaseURL(client.BaseURI),
266		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}", pathParameters),
267		autorest.WithQueryParameters(queryParameters))
268	return preparer.Prepare((&http.Request{}).WithContext(ctx))
269}
270
271// GetSender sends the Get request. The method will close the
272// http.Response Body if it receives an error.
273func (client ExpressRouteConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
274	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
275}
276
277// GetResponder handles the response to the Get request. The method always
278// closes the http.Response Body.
279func (client ExpressRouteConnectionsClient) GetResponder(resp *http.Response) (result ExpressRouteConnection, err error) {
280	err = autorest.Respond(
281		resp,
282		client.ByInspecting(),
283		azure.WithErrorUnlessStatusCode(http.StatusOK),
284		autorest.ByUnmarshallingJSON(&result),
285		autorest.ByClosing())
286	result.Response = autorest.Response{Response: resp}
287	return
288}
289
290// List lists ExpressRouteConnections.
291// Parameters:
292// resourceGroupName - the name of the resource group.
293// expressRouteGatewayName - the name of the ExpressRoute gateway.
294func (client ExpressRouteConnectionsClient) List(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (result ExpressRouteConnectionList, err error) {
295	if tracing.IsEnabled() {
296		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteConnectionsClient.List")
297		defer func() {
298			sc := -1
299			if result.Response.Response != nil {
300				sc = result.Response.Response.StatusCode
301			}
302			tracing.EndSpan(ctx, sc, err)
303		}()
304	}
305	req, err := client.ListPreparer(ctx, resourceGroupName, expressRouteGatewayName)
306	if err != nil {
307		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "List", nil, "Failure preparing request")
308		return
309	}
310
311	resp, err := client.ListSender(req)
312	if err != nil {
313		result.Response = autorest.Response{Response: resp}
314		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "List", resp, "Failure sending request")
315		return
316	}
317
318	result, err = client.ListResponder(resp)
319	if err != nil {
320		err = autorest.NewErrorWithError(err, "network.ExpressRouteConnectionsClient", "List", resp, "Failure responding to request")
321	}
322
323	return
324}
325
326// ListPreparer prepares the List request.
327func (client ExpressRouteConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, expressRouteGatewayName string) (*http.Request, error) {
328	pathParameters := map[string]interface{}{
329		"expressRouteGatewayName": autorest.Encode("path", expressRouteGatewayName),
330		"resourceGroupName":       autorest.Encode("path", resourceGroupName),
331		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
332	}
333
334	const APIVersion = "2020-05-01"
335	queryParameters := map[string]interface{}{
336		"api-version": APIVersion,
337	}
338
339	preparer := autorest.CreatePreparer(
340		autorest.AsGet(),
341		autorest.WithBaseURL(client.BaseURI),
342		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections", pathParameters),
343		autorest.WithQueryParameters(queryParameters))
344	return preparer.Prepare((&http.Request{}).WithContext(ctx))
345}
346
347// ListSender sends the List request. The method will close the
348// http.Response Body if it receives an error.
349func (client ExpressRouteConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
350	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
351}
352
353// ListResponder handles the response to the List request. The method always
354// closes the http.Response Body.
355func (client ExpressRouteConnectionsClient) ListResponder(resp *http.Response) (result ExpressRouteConnectionList, err error) {
356	err = autorest.Respond(
357		resp,
358		client.ByInspecting(),
359		azure.WithErrorUnlessStatusCode(http.StatusOK),
360		autorest.ByUnmarshallingJSON(&result),
361		autorest.ByClosing())
362	result.Response = autorest.Response{Response: resp}
363	return
364}
365