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