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/tracing"
25	"net/http"
26)
27
28// ExpressRouteCircuitAuthorizationsClient is the network Client
29type ExpressRouteCircuitAuthorizationsClient struct {
30	BaseClient
31}
32
33// NewExpressRouteCircuitAuthorizationsClient creates an instance of the ExpressRouteCircuitAuthorizationsClient
34// client.
35func NewExpressRouteCircuitAuthorizationsClient(subscriptionID string) ExpressRouteCircuitAuthorizationsClient {
36	return NewExpressRouteCircuitAuthorizationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewExpressRouteCircuitAuthorizationsClientWithBaseURI creates an instance of the
40// ExpressRouteCircuitAuthorizationsClient client.
41func NewExpressRouteCircuitAuthorizationsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitAuthorizationsClient {
42	return ExpressRouteCircuitAuthorizationsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate creates or updates an authorization in the specified express route circuit.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// circuitName - the name of the express route circuit.
49// authorizationName - the name of the authorization.
50// authorizationParameters - parameters supplied to the create or update express route circuit authorization
51// operation.
52func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, authorizationParameters ExpressRouteCircuitAuthorization) (result ExpressRouteCircuitAuthorizationsCreateOrUpdateFuture, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.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	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, circuitName, authorizationName, authorizationParameters)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "CreateOrUpdate", nil, "Failure preparing request")
66		return
67	}
68
69	result, err = client.CreateOrUpdateSender(req)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
72		return
73	}
74
75	return
76}
77
78// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
79func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, authorizationParameters ExpressRouteCircuitAuthorization) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"authorizationName": autorest.Encode("path", authorizationName),
82		"circuitName":       autorest.Encode("path", circuitName),
83		"resourceGroupName": autorest.Encode("path", resourceGroupName),
84		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
85	}
86
87	const APIVersion = "2018-10-01"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	preparer := autorest.CreatePreparer(
93		autorest.AsContentType("application/json; charset=utf-8"),
94		autorest.AsPut(),
95		autorest.WithBaseURL(client.BaseURI),
96		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/authorizations/{authorizationName}", pathParameters),
97		autorest.WithJSON(authorizationParameters),
98		autorest.WithQueryParameters(queryParameters))
99	return preparer.Prepare((&http.Request{}).WithContext(ctx))
100}
101
102// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
103// http.Response Body if it receives an error.
104func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitAuthorizationsCreateOrUpdateFuture, err error) {
105	var resp *http.Response
106	resp, err = autorest.SendWithSender(client, req,
107		azure.DoRetryWithRegistration(client.Client))
108	if err != nil {
109		return
110	}
111	future.Future, err = azure.NewFutureFromResponse(resp)
112	return
113}
114
115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
116// closes the http.Response Body.
117func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitAuthorization, err error) {
118	err = autorest.Respond(
119		resp,
120		client.ByInspecting(),
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Delete deletes the specified authorization from the specified express route circuit.
129// Parameters:
130// resourceGroupName - the name of the resource group.
131// circuitName - the name of the express route circuit.
132// authorizationName - the name of the authorization.
133func (client ExpressRouteCircuitAuthorizationsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (result ExpressRouteCircuitAuthorizationsDeleteFuture, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.Delete")
136		defer func() {
137			sc := -1
138			if result.Response() != nil {
139				sc = result.Response().StatusCode
140			}
141			tracing.EndSpan(ctx, sc, err)
142		}()
143	}
144	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, authorizationName)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Delete", nil, "Failure preparing request")
147		return
148	}
149
150	result, err = client.DeleteSender(req)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Delete", result.Response(), "Failure sending request")
153		return
154	}
155
156	return
157}
158
159// DeletePreparer prepares the Delete request.
160func (client ExpressRouteCircuitAuthorizationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (*http.Request, error) {
161	pathParameters := map[string]interface{}{
162		"authorizationName": autorest.Encode("path", authorizationName),
163		"circuitName":       autorest.Encode("path", circuitName),
164		"resourceGroupName": autorest.Encode("path", resourceGroupName),
165		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
166	}
167
168	const APIVersion = "2018-10-01"
169	queryParameters := map[string]interface{}{
170		"api-version": APIVersion,
171	}
172
173	preparer := autorest.CreatePreparer(
174		autorest.AsDelete(),
175		autorest.WithBaseURL(client.BaseURI),
176		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/authorizations/{authorizationName}", pathParameters),
177		autorest.WithQueryParameters(queryParameters))
178	return preparer.Prepare((&http.Request{}).WithContext(ctx))
179}
180
181// DeleteSender sends the Delete request. The method will close the
182// http.Response Body if it receives an error.
183func (client ExpressRouteCircuitAuthorizationsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitAuthorizationsDeleteFuture, err error) {
184	var resp *http.Response
185	resp, err = autorest.SendWithSender(client, req,
186		azure.DoRetryWithRegistration(client.Client))
187	if err != nil {
188		return
189	}
190	future.Future, err = azure.NewFutureFromResponse(resp)
191	return
192}
193
194// DeleteResponder handles the response to the Delete request. The method always
195// closes the http.Response Body.
196func (client ExpressRouteCircuitAuthorizationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
197	err = autorest.Respond(
198		resp,
199		client.ByInspecting(),
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
201		autorest.ByClosing())
202	result.Response = resp
203	return
204}
205
206// Get gets the specified authorization from the specified express route circuit.
207// Parameters:
208// resourceGroupName - the name of the resource group.
209// circuitName - the name of the express route circuit.
210// authorizationName - the name of the authorization.
211func (client ExpressRouteCircuitAuthorizationsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (result ExpressRouteCircuitAuthorization, err error) {
212	if tracing.IsEnabled() {
213		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.Get")
214		defer func() {
215			sc := -1
216			if result.Response.Response != nil {
217				sc = result.Response.Response.StatusCode
218			}
219			tracing.EndSpan(ctx, sc, err)
220		}()
221	}
222	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, authorizationName)
223	if err != nil {
224		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Get", nil, "Failure preparing request")
225		return
226	}
227
228	resp, err := client.GetSender(req)
229	if err != nil {
230		result.Response = autorest.Response{Response: resp}
231		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Get", resp, "Failure sending request")
232		return
233	}
234
235	result, err = client.GetResponder(resp)
236	if err != nil {
237		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Get", resp, "Failure responding to request")
238	}
239
240	return
241}
242
243// GetPreparer prepares the Get request.
244func (client ExpressRouteCircuitAuthorizationsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (*http.Request, error) {
245	pathParameters := map[string]interface{}{
246		"authorizationName": autorest.Encode("path", authorizationName),
247		"circuitName":       autorest.Encode("path", circuitName),
248		"resourceGroupName": autorest.Encode("path", resourceGroupName),
249		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
250	}
251
252	const APIVersion = "2018-10-01"
253	queryParameters := map[string]interface{}{
254		"api-version": APIVersion,
255	}
256
257	preparer := autorest.CreatePreparer(
258		autorest.AsGet(),
259		autorest.WithBaseURL(client.BaseURI),
260		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/authorizations/{authorizationName}", pathParameters),
261		autorest.WithQueryParameters(queryParameters))
262	return preparer.Prepare((&http.Request{}).WithContext(ctx))
263}
264
265// GetSender sends the Get request. The method will close the
266// http.Response Body if it receives an error.
267func (client ExpressRouteCircuitAuthorizationsClient) GetSender(req *http.Request) (*http.Response, error) {
268	return autorest.SendWithSender(client, req,
269		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 ExpressRouteCircuitAuthorizationsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitAuthorization, 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// List gets all authorizations in an express route circuit.
286// Parameters:
287// resourceGroupName - the name of the resource group.
288// circuitName - the name of the circuit.
289func (client ExpressRouteCircuitAuthorizationsClient) List(ctx context.Context, resourceGroupName string, circuitName string) (result AuthorizationListResultPage, err error) {
290	if tracing.IsEnabled() {
291		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.List")
292		defer func() {
293			sc := -1
294			if result.alr.Response.Response != nil {
295				sc = result.alr.Response.Response.StatusCode
296			}
297			tracing.EndSpan(ctx, sc, err)
298		}()
299	}
300	result.fn = client.listNextResults
301	req, err := client.ListPreparer(ctx, resourceGroupName, circuitName)
302	if err != nil {
303		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", nil, "Failure preparing request")
304		return
305	}
306
307	resp, err := client.ListSender(req)
308	if err != nil {
309		result.alr.Response = autorest.Response{Response: resp}
310		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure sending request")
311		return
312	}
313
314	result.alr, err = client.ListResponder(resp)
315	if err != nil {
316		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure responding to request")
317	}
318
319	return
320}
321
322// ListPreparer prepares the List request.
323func (client ExpressRouteCircuitAuthorizationsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string) (*http.Request, error) {
324	pathParameters := map[string]interface{}{
325		"circuitName":       autorest.Encode("path", circuitName),
326		"resourceGroupName": autorest.Encode("path", resourceGroupName),
327		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
328	}
329
330	const APIVersion = "2018-10-01"
331	queryParameters := map[string]interface{}{
332		"api-version": APIVersion,
333	}
334
335	preparer := autorest.CreatePreparer(
336		autorest.AsGet(),
337		autorest.WithBaseURL(client.BaseURI),
338		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/authorizations", pathParameters),
339		autorest.WithQueryParameters(queryParameters))
340	return preparer.Prepare((&http.Request{}).WithContext(ctx))
341}
342
343// ListSender sends the List request. The method will close the
344// http.Response Body if it receives an error.
345func (client ExpressRouteCircuitAuthorizationsClient) ListSender(req *http.Request) (*http.Response, error) {
346	return autorest.SendWithSender(client, req,
347		azure.DoRetryWithRegistration(client.Client))
348}
349
350// ListResponder handles the response to the List request. The method always
351// closes the http.Response Body.
352func (client ExpressRouteCircuitAuthorizationsClient) ListResponder(resp *http.Response) (result AuthorizationListResult, err error) {
353	err = autorest.Respond(
354		resp,
355		client.ByInspecting(),
356		azure.WithErrorUnlessStatusCode(http.StatusOK),
357		autorest.ByUnmarshallingJSON(&result),
358		autorest.ByClosing())
359	result.Response = autorest.Response{Response: resp}
360	return
361}
362
363// listNextResults retrieves the next set of results, if any.
364func (client ExpressRouteCircuitAuthorizationsClient) listNextResults(ctx context.Context, lastResults AuthorizationListResult) (result AuthorizationListResult, err error) {
365	req, err := lastResults.authorizationListResultPreparer(ctx)
366	if err != nil {
367		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "listNextResults", nil, "Failure preparing next results request")
368	}
369	if req == nil {
370		return
371	}
372	resp, err := client.ListSender(req)
373	if err != nil {
374		result.Response = autorest.Response{Response: resp}
375		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "listNextResults", resp, "Failure sending next results request")
376	}
377	result, err = client.ListResponder(resp)
378	if err != nil {
379		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "listNextResults", resp, "Failure responding to next results request")
380	}
381	return
382}
383
384// ListComplete enumerates all values, automatically crossing page boundaries as required.
385func (client ExpressRouteCircuitAuthorizationsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string) (result AuthorizationListResultIterator, err error) {
386	if tracing.IsEnabled() {
387		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.List")
388		defer func() {
389			sc := -1
390			if result.Response().Response.Response != nil {
391				sc = result.page.Response().Response.Response.StatusCode
392			}
393			tracing.EndSpan(ctx, sc, err)
394		}()
395	}
396	result.page, err = client.List(ctx, resourceGroupName, circuitName)
397	return
398}
399