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// BastionHostsClient is the network Client
18type BastionHostsClient struct {
19	BaseClient
20}
21
22// NewBastionHostsClient creates an instance of the BastionHostsClient client.
23func NewBastionHostsClient(subscriptionID string) BastionHostsClient {
24	return NewBastionHostsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewBastionHostsClientWithBaseURI creates an instance of the BastionHostsClient client using a custom endpoint.  Use
28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewBastionHostsClientWithBaseURI(baseURI string, subscriptionID string) BastionHostsClient {
30	return BastionHostsClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// CreateOrUpdate creates or updates the specified Bastion Host.
34// Parameters:
35// resourceGroupName - the name of the resource group.
36// bastionHostName - the name of the Bastion Host.
37// parameters - parameters supplied to the create or update Bastion Host operation.
38func (client BastionHostsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, bastionHostName string, parameters BastionHost) (result BastionHostsCreateOrUpdateFuture, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.CreateOrUpdate")
41		defer func() {
42			sc := -1
43			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
44				sc = result.FutureAPI.Response().StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, bastionHostName, parameters)
50	if err != nil {
51		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "CreateOrUpdate", nil, "Failure preparing request")
52		return
53	}
54
55	result, err = client.CreateOrUpdateSender(req)
56	if err != nil {
57		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "CreateOrUpdate", nil, "Failure sending request")
58		return
59	}
60
61	return
62}
63
64// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
65func (client BastionHostsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, bastionHostName string, parameters BastionHost) (*http.Request, error) {
66	pathParameters := map[string]interface{}{
67		"bastionHostName":   autorest.Encode("path", bastionHostName),
68		"resourceGroupName": autorest.Encode("path", resourceGroupName),
69		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
70	}
71
72	const APIVersion = "2020-05-01"
73	queryParameters := map[string]interface{}{
74		"api-version": APIVersion,
75	}
76
77	parameters.Etag = nil
78	preparer := autorest.CreatePreparer(
79		autorest.AsContentType("application/json; charset=utf-8"),
80		autorest.AsPut(),
81		autorest.WithBaseURL(client.BaseURI),
82		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}", pathParameters),
83		autorest.WithJSON(parameters),
84		autorest.WithQueryParameters(queryParameters))
85	return preparer.Prepare((&http.Request{}).WithContext(ctx))
86}
87
88// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
89// http.Response Body if it receives an error.
90func (client BastionHostsClient) CreateOrUpdateSender(req *http.Request) (future BastionHostsCreateOrUpdateFuture, err error) {
91	var resp *http.Response
92	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
93	if err != nil {
94		return
95	}
96	var azf azure.Future
97	azf, err = azure.NewFutureFromResponse(resp)
98	future.FutureAPI = &azf
99	future.Result = future.result
100	return
101}
102
103// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
104// closes the http.Response Body.
105func (client BastionHostsClient) CreateOrUpdateResponder(resp *http.Response) (result BastionHost, err error) {
106	err = autorest.Respond(
107		resp,
108		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
109		autorest.ByUnmarshallingJSON(&result),
110		autorest.ByClosing())
111	result.Response = autorest.Response{Response: resp}
112	return
113}
114
115// Delete deletes the specified Bastion Host.
116// Parameters:
117// resourceGroupName - the name of the resource group.
118// bastionHostName - the name of the Bastion Host.
119func (client BastionHostsClient) Delete(ctx context.Context, resourceGroupName string, bastionHostName string) (result BastionHostsDeleteFuture, err error) {
120	if tracing.IsEnabled() {
121		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.Delete")
122		defer func() {
123			sc := -1
124			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
125				sc = result.FutureAPI.Response().StatusCode
126			}
127			tracing.EndSpan(ctx, sc, err)
128		}()
129	}
130	req, err := client.DeletePreparer(ctx, resourceGroupName, bastionHostName)
131	if err != nil {
132		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "Delete", nil, "Failure preparing request")
133		return
134	}
135
136	result, err = client.DeleteSender(req)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "Delete", nil, "Failure sending request")
139		return
140	}
141
142	return
143}
144
145// DeletePreparer prepares the Delete request.
146func (client BastionHostsClient) DeletePreparer(ctx context.Context, resourceGroupName string, bastionHostName string) (*http.Request, error) {
147	pathParameters := map[string]interface{}{
148		"bastionHostName":   autorest.Encode("path", bastionHostName),
149		"resourceGroupName": autorest.Encode("path", resourceGroupName),
150		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
151	}
152
153	const APIVersion = "2020-05-01"
154	queryParameters := map[string]interface{}{
155		"api-version": APIVersion,
156	}
157
158	preparer := autorest.CreatePreparer(
159		autorest.AsDelete(),
160		autorest.WithBaseURL(client.BaseURI),
161		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}", pathParameters),
162		autorest.WithQueryParameters(queryParameters))
163	return preparer.Prepare((&http.Request{}).WithContext(ctx))
164}
165
166// DeleteSender sends the Delete request. The method will close the
167// http.Response Body if it receives an error.
168func (client BastionHostsClient) DeleteSender(req *http.Request) (future BastionHostsDeleteFuture, err error) {
169	var resp *http.Response
170	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
171	if err != nil {
172		return
173	}
174	var azf azure.Future
175	azf, err = azure.NewFutureFromResponse(resp)
176	future.FutureAPI = &azf
177	future.Result = future.result
178	return
179}
180
181// DeleteResponder handles the response to the Delete request. The method always
182// closes the http.Response Body.
183func (client BastionHostsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
184	err = autorest.Respond(
185		resp,
186		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
187		autorest.ByClosing())
188	result.Response = resp
189	return
190}
191
192// Get gets the specified Bastion Host.
193// Parameters:
194// resourceGroupName - the name of the resource group.
195// bastionHostName - the name of the Bastion Host.
196func (client BastionHostsClient) Get(ctx context.Context, resourceGroupName string, bastionHostName string) (result BastionHost, err error) {
197	if tracing.IsEnabled() {
198		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.Get")
199		defer func() {
200			sc := -1
201			if result.Response.Response != nil {
202				sc = result.Response.Response.StatusCode
203			}
204			tracing.EndSpan(ctx, sc, err)
205		}()
206	}
207	req, err := client.GetPreparer(ctx, resourceGroupName, bastionHostName)
208	if err != nil {
209		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "Get", nil, "Failure preparing request")
210		return
211	}
212
213	resp, err := client.GetSender(req)
214	if err != nil {
215		result.Response = autorest.Response{Response: resp}
216		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "Get", resp, "Failure sending request")
217		return
218	}
219
220	result, err = client.GetResponder(resp)
221	if err != nil {
222		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "Get", resp, "Failure responding to request")
223		return
224	}
225
226	return
227}
228
229// GetPreparer prepares the Get request.
230func (client BastionHostsClient) GetPreparer(ctx context.Context, resourceGroupName string, bastionHostName string) (*http.Request, error) {
231	pathParameters := map[string]interface{}{
232		"bastionHostName":   autorest.Encode("path", bastionHostName),
233		"resourceGroupName": autorest.Encode("path", resourceGroupName),
234		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
235	}
236
237	const APIVersion = "2020-05-01"
238	queryParameters := map[string]interface{}{
239		"api-version": APIVersion,
240	}
241
242	preparer := autorest.CreatePreparer(
243		autorest.AsGet(),
244		autorest.WithBaseURL(client.BaseURI),
245		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts/{bastionHostName}", pathParameters),
246		autorest.WithQueryParameters(queryParameters))
247	return preparer.Prepare((&http.Request{}).WithContext(ctx))
248}
249
250// GetSender sends the Get request. The method will close the
251// http.Response Body if it receives an error.
252func (client BastionHostsClient) GetSender(req *http.Request) (*http.Response, error) {
253	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
254}
255
256// GetResponder handles the response to the Get request. The method always
257// closes the http.Response Body.
258func (client BastionHostsClient) GetResponder(resp *http.Response) (result BastionHost, err error) {
259	err = autorest.Respond(
260		resp,
261		azure.WithErrorUnlessStatusCode(http.StatusOK),
262		autorest.ByUnmarshallingJSON(&result),
263		autorest.ByClosing())
264	result.Response = autorest.Response{Response: resp}
265	return
266}
267
268// List lists all Bastion Hosts in a subscription.
269func (client BastionHostsClient) List(ctx context.Context) (result BastionHostListResultPage, err error) {
270	if tracing.IsEnabled() {
271		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.List")
272		defer func() {
273			sc := -1
274			if result.bhlr.Response.Response != nil {
275				sc = result.bhlr.Response.Response.StatusCode
276			}
277			tracing.EndSpan(ctx, sc, err)
278		}()
279	}
280	result.fn = client.listNextResults
281	req, err := client.ListPreparer(ctx)
282	if err != nil {
283		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "List", nil, "Failure preparing request")
284		return
285	}
286
287	resp, err := client.ListSender(req)
288	if err != nil {
289		result.bhlr.Response = autorest.Response{Response: resp}
290		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "List", resp, "Failure sending request")
291		return
292	}
293
294	result.bhlr, err = client.ListResponder(resp)
295	if err != nil {
296		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "List", resp, "Failure responding to request")
297		return
298	}
299	if result.bhlr.hasNextLink() && result.bhlr.IsEmpty() {
300		err = result.NextWithContext(ctx)
301		return
302	}
303
304	return
305}
306
307// ListPreparer prepares the List request.
308func (client BastionHostsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
309	pathParameters := map[string]interface{}{
310		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
311	}
312
313	const APIVersion = "2020-05-01"
314	queryParameters := map[string]interface{}{
315		"api-version": APIVersion,
316	}
317
318	preparer := autorest.CreatePreparer(
319		autorest.AsGet(),
320		autorest.WithBaseURL(client.BaseURI),
321		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/bastionHosts", pathParameters),
322		autorest.WithQueryParameters(queryParameters))
323	return preparer.Prepare((&http.Request{}).WithContext(ctx))
324}
325
326// ListSender sends the List request. The method will close the
327// http.Response Body if it receives an error.
328func (client BastionHostsClient) ListSender(req *http.Request) (*http.Response, error) {
329	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
330}
331
332// ListResponder handles the response to the List request. The method always
333// closes the http.Response Body.
334func (client BastionHostsClient) ListResponder(resp *http.Response) (result BastionHostListResult, err error) {
335	err = autorest.Respond(
336		resp,
337		azure.WithErrorUnlessStatusCode(http.StatusOK),
338		autorest.ByUnmarshallingJSON(&result),
339		autorest.ByClosing())
340	result.Response = autorest.Response{Response: resp}
341	return
342}
343
344// listNextResults retrieves the next set of results, if any.
345func (client BastionHostsClient) listNextResults(ctx context.Context, lastResults BastionHostListResult) (result BastionHostListResult, err error) {
346	req, err := lastResults.bastionHostListResultPreparer(ctx)
347	if err != nil {
348		return result, autorest.NewErrorWithError(err, "network.BastionHostsClient", "listNextResults", nil, "Failure preparing next results request")
349	}
350	if req == nil {
351		return
352	}
353	resp, err := client.ListSender(req)
354	if err != nil {
355		result.Response = autorest.Response{Response: resp}
356		return result, autorest.NewErrorWithError(err, "network.BastionHostsClient", "listNextResults", resp, "Failure sending next results request")
357	}
358	result, err = client.ListResponder(resp)
359	if err != nil {
360		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "listNextResults", resp, "Failure responding to next results request")
361	}
362	return
363}
364
365// ListComplete enumerates all values, automatically crossing page boundaries as required.
366func (client BastionHostsClient) ListComplete(ctx context.Context) (result BastionHostListResultIterator, err error) {
367	if tracing.IsEnabled() {
368		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.List")
369		defer func() {
370			sc := -1
371			if result.Response().Response.Response != nil {
372				sc = result.page.Response().Response.Response.StatusCode
373			}
374			tracing.EndSpan(ctx, sc, err)
375		}()
376	}
377	result.page, err = client.List(ctx)
378	return
379}
380
381// ListByResourceGroup lists all Bastion Hosts in a resource group.
382// Parameters:
383// resourceGroupName - the name of the resource group.
384func (client BastionHostsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result BastionHostListResultPage, err error) {
385	if tracing.IsEnabled() {
386		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.ListByResourceGroup")
387		defer func() {
388			sc := -1
389			if result.bhlr.Response.Response != nil {
390				sc = result.bhlr.Response.Response.StatusCode
391			}
392			tracing.EndSpan(ctx, sc, err)
393		}()
394	}
395	result.fn = client.listByResourceGroupNextResults
396	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
397	if err != nil {
398		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "ListByResourceGroup", nil, "Failure preparing request")
399		return
400	}
401
402	resp, err := client.ListByResourceGroupSender(req)
403	if err != nil {
404		result.bhlr.Response = autorest.Response{Response: resp}
405		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "ListByResourceGroup", resp, "Failure sending request")
406		return
407	}
408
409	result.bhlr, err = client.ListByResourceGroupResponder(resp)
410	if err != nil {
411		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "ListByResourceGroup", resp, "Failure responding to request")
412		return
413	}
414	if result.bhlr.hasNextLink() && result.bhlr.IsEmpty() {
415		err = result.NextWithContext(ctx)
416		return
417	}
418
419	return
420}
421
422// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
423func (client BastionHostsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
424	pathParameters := map[string]interface{}{
425		"resourceGroupName": autorest.Encode("path", resourceGroupName),
426		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
427	}
428
429	const APIVersion = "2020-05-01"
430	queryParameters := map[string]interface{}{
431		"api-version": APIVersion,
432	}
433
434	preparer := autorest.CreatePreparer(
435		autorest.AsGet(),
436		autorest.WithBaseURL(client.BaseURI),
437		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/bastionHosts", pathParameters),
438		autorest.WithQueryParameters(queryParameters))
439	return preparer.Prepare((&http.Request{}).WithContext(ctx))
440}
441
442// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
443// http.Response Body if it receives an error.
444func (client BastionHostsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
445	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
446}
447
448// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
449// closes the http.Response Body.
450func (client BastionHostsClient) ListByResourceGroupResponder(resp *http.Response) (result BastionHostListResult, err error) {
451	err = autorest.Respond(
452		resp,
453		azure.WithErrorUnlessStatusCode(http.StatusOK),
454		autorest.ByUnmarshallingJSON(&result),
455		autorest.ByClosing())
456	result.Response = autorest.Response{Response: resp}
457	return
458}
459
460// listByResourceGroupNextResults retrieves the next set of results, if any.
461func (client BastionHostsClient) listByResourceGroupNextResults(ctx context.Context, lastResults BastionHostListResult) (result BastionHostListResult, err error) {
462	req, err := lastResults.bastionHostListResultPreparer(ctx)
463	if err != nil {
464		return result, autorest.NewErrorWithError(err, "network.BastionHostsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
465	}
466	if req == nil {
467		return
468	}
469	resp, err := client.ListByResourceGroupSender(req)
470	if err != nil {
471		result.Response = autorest.Response{Response: resp}
472		return result, autorest.NewErrorWithError(err, "network.BastionHostsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
473	}
474	result, err = client.ListByResourceGroupResponder(resp)
475	if err != nil {
476		err = autorest.NewErrorWithError(err, "network.BastionHostsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
477	}
478	return
479}
480
481// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
482func (client BastionHostsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result BastionHostListResultIterator, err error) {
483	if tracing.IsEnabled() {
484		ctx = tracing.StartSpan(ctx, fqdn+"/BastionHostsClient.ListByResourceGroup")
485		defer func() {
486			sc := -1
487			if result.Response().Response.Response != nil {
488				sc = result.page.Response().Response.Response.StatusCode
489			}
490			tracing.EndSpan(ctx, sc, err)
491		}()
492	}
493	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
494	return
495}
496