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