1package network
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
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// ExpressRouteCircuitAuthorizationsClient is the network Client
18type ExpressRouteCircuitAuthorizationsClient struct {
19	BaseClient
20}
21
22// NewExpressRouteCircuitAuthorizationsClient creates an instance of the ExpressRouteCircuitAuthorizationsClient
23// client.
24func NewExpressRouteCircuitAuthorizationsClient(subscriptionID string) ExpressRouteCircuitAuthorizationsClient {
25	return NewExpressRouteCircuitAuthorizationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewExpressRouteCircuitAuthorizationsClientWithBaseURI creates an instance of the
29// ExpressRouteCircuitAuthorizationsClient client using a custom endpoint.  Use this when interacting with an Azure
30// cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
31func NewExpressRouteCircuitAuthorizationsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitAuthorizationsClient {
32	return ExpressRouteCircuitAuthorizationsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate creates or updates an authorization in the specified express route circuit.
36// Parameters:
37// resourceGroupName - the name of the resource group.
38// circuitName - the name of the express route circuit.
39// authorizationName - the name of the authorization.
40// authorizationParameters - parameters supplied to the create or update express route circuit authorization
41// operation.
42func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, authorizationParameters ExpressRouteCircuitAuthorization) (result ExpressRouteCircuitAuthorizationsCreateOrUpdateFuture, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.CreateOrUpdate")
45		defer func() {
46			sc := -1
47			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
48				sc = result.FutureAPI.Response().StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, circuitName, authorizationName, authorizationParameters)
54	if err != nil {
55		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "CreateOrUpdate", nil, "Failure preparing request")
56		return
57	}
58
59	result, err = client.CreateOrUpdateSender(req)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "CreateOrUpdate", nil, "Failure sending request")
62		return
63	}
64
65	return
66}
67
68// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
69func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string, authorizationParameters ExpressRouteCircuitAuthorization) (*http.Request, error) {
70	pathParameters := map[string]interface{}{
71		"authorizationName": autorest.Encode("path", authorizationName),
72		"circuitName":       autorest.Encode("path", circuitName),
73		"resourceGroupName": autorest.Encode("path", resourceGroupName),
74		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
75	}
76
77	const APIVersion = "2017-09-01"
78	queryParameters := map[string]interface{}{
79		"api-version": APIVersion,
80	}
81
82	authorizationParameters.Etag = nil
83	preparer := autorest.CreatePreparer(
84		autorest.AsContentType("application/json; charset=utf-8"),
85		autorest.AsPut(),
86		autorest.WithBaseURL(client.BaseURI),
87		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/authorizations/{authorizationName}", pathParameters),
88		autorest.WithJSON(authorizationParameters),
89		autorest.WithQueryParameters(queryParameters))
90	return preparer.Prepare((&http.Request{}).WithContext(ctx))
91}
92
93// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
94// http.Response Body if it receives an error.
95func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitAuthorizationsCreateOrUpdateFuture, err error) {
96	var resp *http.Response
97	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
98	if err != nil {
99		return
100	}
101	var azf azure.Future
102	azf, err = azure.NewFutureFromResponse(resp)
103	future.FutureAPI = &azf
104	future.Result = future.result
105	return
106}
107
108// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
109// closes the http.Response Body.
110func (client ExpressRouteCircuitAuthorizationsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitAuthorization, err error) {
111	err = autorest.Respond(
112		resp,
113		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// Delete deletes the specified authorization from the specified express route circuit.
121// Parameters:
122// resourceGroupName - the name of the resource group.
123// circuitName - the name of the express route circuit.
124// authorizationName - the name of the authorization.
125func (client ExpressRouteCircuitAuthorizationsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (result ExpressRouteCircuitAuthorizationsDeleteFuture, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.Delete")
128		defer func() {
129			sc := -1
130			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
131				sc = result.FutureAPI.Response().StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, authorizationName)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Delete", nil, "Failure preparing request")
139		return
140	}
141
142	result, err = client.DeleteSender(req)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "Delete", nil, "Failure sending request")
145		return
146	}
147
148	return
149}
150
151// DeletePreparer prepares the Delete request.
152func (client ExpressRouteCircuitAuthorizationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (*http.Request, error) {
153	pathParameters := map[string]interface{}{
154		"authorizationName": autorest.Encode("path", authorizationName),
155		"circuitName":       autorest.Encode("path", circuitName),
156		"resourceGroupName": autorest.Encode("path", resourceGroupName),
157		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
158	}
159
160	const APIVersion = "2017-09-01"
161	queryParameters := map[string]interface{}{
162		"api-version": APIVersion,
163	}
164
165	preparer := autorest.CreatePreparer(
166		autorest.AsDelete(),
167		autorest.WithBaseURL(client.BaseURI),
168		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/authorizations/{authorizationName}", pathParameters),
169		autorest.WithQueryParameters(queryParameters))
170	return preparer.Prepare((&http.Request{}).WithContext(ctx))
171}
172
173// DeleteSender sends the Delete request. The method will close the
174// http.Response Body if it receives an error.
175func (client ExpressRouteCircuitAuthorizationsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitAuthorizationsDeleteFuture, err error) {
176	var resp *http.Response
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// DeleteResponder handles the response to the Delete request. The method always
189// closes the http.Response Body.
190func (client ExpressRouteCircuitAuthorizationsClient) 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// Get gets the specified authorization from the specified express route circuit.
200// Parameters:
201// resourceGroupName - the name of the resource group.
202// circuitName - the name of the express route circuit.
203// authorizationName - the name of the authorization.
204func (client ExpressRouteCircuitAuthorizationsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (result ExpressRouteCircuitAuthorization, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.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, circuitName, authorizationName)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "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.ExpressRouteCircuitAuthorizationsClient", "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.ExpressRouteCircuitAuthorizationsClient", "Get", resp, "Failure responding to request")
231		return
232	}
233
234	return
235}
236
237// GetPreparer prepares the Get request.
238func (client ExpressRouteCircuitAuthorizationsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, authorizationName string) (*http.Request, error) {
239	pathParameters := map[string]interface{}{
240		"authorizationName": autorest.Encode("path", authorizationName),
241		"circuitName":       autorest.Encode("path", circuitName),
242		"resourceGroupName": autorest.Encode("path", resourceGroupName),
243		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
244	}
245
246	const APIVersion = "2017-09-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/expressRouteCircuits/{circuitName}/authorizations/{authorizationName}", pathParameters),
255		autorest.WithQueryParameters(queryParameters))
256	return preparer.Prepare((&http.Request{}).WithContext(ctx))
257}
258
259// GetSender sends the Get request. The method will close the
260// http.Response Body if it receives an error.
261func (client ExpressRouteCircuitAuthorizationsClient) GetSender(req *http.Request) (*http.Response, error) {
262	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
263}
264
265// GetResponder handles the response to the Get request. The method always
266// closes the http.Response Body.
267func (client ExpressRouteCircuitAuthorizationsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitAuthorization, 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// List gets all authorizations in an express route circuit.
278// Parameters:
279// resourceGroupName - the name of the resource group.
280// circuitName - the name of the circuit.
281func (client ExpressRouteCircuitAuthorizationsClient) List(ctx context.Context, resourceGroupName string, circuitName string) (result AuthorizationListResultPage, err error) {
282	if tracing.IsEnabled() {
283		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.List")
284		defer func() {
285			sc := -1
286			if result.alr.Response.Response != nil {
287				sc = result.alr.Response.Response.StatusCode
288			}
289			tracing.EndSpan(ctx, sc, err)
290		}()
291	}
292	result.fn = client.listNextResults
293	req, err := client.ListPreparer(ctx, resourceGroupName, circuitName)
294	if err != nil {
295		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", nil, "Failure preparing request")
296		return
297	}
298
299	resp, err := client.ListSender(req)
300	if err != nil {
301		result.alr.Response = autorest.Response{Response: resp}
302		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure sending request")
303		return
304	}
305
306	result.alr, err = client.ListResponder(resp)
307	if err != nil {
308		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "List", resp, "Failure responding to request")
309		return
310	}
311	if result.alr.hasNextLink() && result.alr.IsEmpty() {
312		err = result.NextWithContext(ctx)
313		return
314	}
315
316	return
317}
318
319// ListPreparer prepares the List request.
320func (client ExpressRouteCircuitAuthorizationsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string) (*http.Request, error) {
321	pathParameters := map[string]interface{}{
322		"circuitName":       autorest.Encode("path", circuitName),
323		"resourceGroupName": autorest.Encode("path", resourceGroupName),
324		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
325	}
326
327	const APIVersion = "2017-09-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/expressRouteCircuits/{circuitName}/authorizations", pathParameters),
336		autorest.WithQueryParameters(queryParameters))
337	return preparer.Prepare((&http.Request{}).WithContext(ctx))
338}
339
340// ListSender sends the List request. The method will close the
341// http.Response Body if it receives an error.
342func (client ExpressRouteCircuitAuthorizationsClient) ListSender(req *http.Request) (*http.Response, error) {
343	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
344}
345
346// ListResponder handles the response to the List request. The method always
347// closes the http.Response Body.
348func (client ExpressRouteCircuitAuthorizationsClient) ListResponder(resp *http.Response) (result AuthorizationListResult, 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// listNextResults retrieves the next set of results, if any.
359func (client ExpressRouteCircuitAuthorizationsClient) listNextResults(ctx context.Context, lastResults AuthorizationListResult) (result AuthorizationListResult, err error) {
360	req, err := lastResults.authorizationListResultPreparer(ctx)
361	if err != nil {
362		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "listNextResults", nil, "Failure preparing next results request")
363	}
364	if req == nil {
365		return
366	}
367	resp, err := client.ListSender(req)
368	if err != nil {
369		result.Response = autorest.Response{Response: resp}
370		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "listNextResults", resp, "Failure sending next results request")
371	}
372	result, err = client.ListResponder(resp)
373	if err != nil {
374		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitAuthorizationsClient", "listNextResults", resp, "Failure responding to next results request")
375	}
376	return
377}
378
379// ListComplete enumerates all values, automatically crossing page boundaries as required.
380func (client ExpressRouteCircuitAuthorizationsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string) (result AuthorizationListResultIterator, err error) {
381	if tracing.IsEnabled() {
382		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitAuthorizationsClient.List")
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.List(ctx, resourceGroupName, circuitName)
392	return
393}
394