1package webpubsub
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/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// SharedPrivateLinkResourcesClient is the REST API for Azure WebPubSub Service
19type SharedPrivateLinkResourcesClient struct {
20	BaseClient
21}
22
23// NewSharedPrivateLinkResourcesClient creates an instance of the SharedPrivateLinkResourcesClient client.
24func NewSharedPrivateLinkResourcesClient(subscriptionID string) SharedPrivateLinkResourcesClient {
25	return NewSharedPrivateLinkResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewSharedPrivateLinkResourcesClientWithBaseURI creates an instance of the SharedPrivateLinkResourcesClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewSharedPrivateLinkResourcesClientWithBaseURI(baseURI string, subscriptionID string) SharedPrivateLinkResourcesClient {
32	return SharedPrivateLinkResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate create or update a shared private link resource
36// Parameters:
37// sharedPrivateLinkResourceName - the name of the shared private link resource
38// parameters - the shared private link resource
39// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
40// from the Azure Resource Manager API or the portal.
41// resourceName - the name of the resource.
42func (client SharedPrivateLinkResourcesClient) CreateOrUpdate(ctx context.Context, sharedPrivateLinkResourceName string, parameters SharedPrivateLinkResource, resourceGroupName string, resourceName string) (result SharedPrivateLinkResourcesCreateOrUpdateFuture, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.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	if err := validation.Validate([]validation.Validation{
54		{TargetValue: parameters,
55			Constraints: []validation.Constraint{{Target: "parameters.SharedPrivateLinkResourceProperties", Name: validation.Null, Rule: false,
56				Chain: []validation.Constraint{{Target: "parameters.SharedPrivateLinkResourceProperties.GroupID", Name: validation.Null, Rule: true, Chain: nil},
57					{Target: "parameters.SharedPrivateLinkResourceProperties.PrivateLinkResourceID", Name: validation.Null, Rule: true, Chain: nil},
58				}}}}}); err != nil {
59		return result, validation.NewError("webpubsub.SharedPrivateLinkResourcesClient", "CreateOrUpdate", err.Error())
60	}
61
62	req, err := client.CreateOrUpdatePreparer(ctx, sharedPrivateLinkResourceName, parameters, resourceGroupName, resourceName)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "CreateOrUpdate", nil, "Failure preparing request")
65		return
66	}
67
68	result, err = client.CreateOrUpdateSender(req)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "CreateOrUpdate", nil, "Failure sending request")
71		return
72	}
73
74	return
75}
76
77// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
78func (client SharedPrivateLinkResourcesClient) CreateOrUpdatePreparer(ctx context.Context, sharedPrivateLinkResourceName string, parameters SharedPrivateLinkResource, resourceGroupName string, resourceName string) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
81		"resourceName":                  autorest.Encode("path", resourceName),
82		"sharedPrivateLinkResourceName": autorest.Encode("path", sharedPrivateLinkResourceName),
83		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
84	}
85
86	const APIVersion = "2021-04-01-preview"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	parameters.SystemData = nil
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.SignalRService/webPubSub/{resourceName}/sharedPrivateLinkResources/{sharedPrivateLinkResourceName}", pathParameters),
97		autorest.WithJSON(parameters),
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 SharedPrivateLinkResourcesClient) CreateOrUpdateSender(req *http.Request) (future SharedPrivateLinkResourcesCreateOrUpdateFuture, err error) {
105	var resp *http.Response
106	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
107	if err != nil {
108		return
109	}
110	var azf azure.Future
111	azf, err = azure.NewFutureFromResponse(resp)
112	future.FutureAPI = &azf
113	future.Result = future.result
114	return
115}
116
117// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
118// closes the http.Response Body.
119func (client SharedPrivateLinkResourcesClient) CreateOrUpdateResponder(resp *http.Response) (result SharedPrivateLinkResource, err error) {
120	err = autorest.Respond(
121		resp,
122		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// Delete delete the specified shared private link resource
130// Parameters:
131// sharedPrivateLinkResourceName - the name of the shared private link resource
132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
133// from the Azure Resource Manager API or the portal.
134// resourceName - the name of the resource.
135func (client SharedPrivateLinkResourcesClient) Delete(ctx context.Context, sharedPrivateLinkResourceName string, resourceGroupName string, resourceName string) (result SharedPrivateLinkResourcesDeleteFuture, err error) {
136	if tracing.IsEnabled() {
137		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.Delete")
138		defer func() {
139			sc := -1
140			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
141				sc = result.FutureAPI.Response().StatusCode
142			}
143			tracing.EndSpan(ctx, sc, err)
144		}()
145	}
146	req, err := client.DeletePreparer(ctx, sharedPrivateLinkResourceName, resourceGroupName, resourceName)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "Delete", nil, "Failure preparing request")
149		return
150	}
151
152	result, err = client.DeleteSender(req)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "Delete", nil, "Failure sending request")
155		return
156	}
157
158	return
159}
160
161// DeletePreparer prepares the Delete request.
162func (client SharedPrivateLinkResourcesClient) DeletePreparer(ctx context.Context, sharedPrivateLinkResourceName string, resourceGroupName string, resourceName string) (*http.Request, error) {
163	pathParameters := map[string]interface{}{
164		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
165		"resourceName":                  autorest.Encode("path", resourceName),
166		"sharedPrivateLinkResourceName": autorest.Encode("path", sharedPrivateLinkResourceName),
167		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
168	}
169
170	const APIVersion = "2021-04-01-preview"
171	queryParameters := map[string]interface{}{
172		"api-version": APIVersion,
173	}
174
175	preparer := autorest.CreatePreparer(
176		autorest.AsDelete(),
177		autorest.WithBaseURL(client.BaseURI),
178		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/webPubSub/{resourceName}/sharedPrivateLinkResources/{sharedPrivateLinkResourceName}", pathParameters),
179		autorest.WithQueryParameters(queryParameters))
180	return preparer.Prepare((&http.Request{}).WithContext(ctx))
181}
182
183// DeleteSender sends the Delete request. The method will close the
184// http.Response Body if it receives an error.
185func (client SharedPrivateLinkResourcesClient) DeleteSender(req *http.Request) (future SharedPrivateLinkResourcesDeleteFuture, err error) {
186	var resp *http.Response
187	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
188	if err != nil {
189		return
190	}
191	var azf azure.Future
192	azf, err = azure.NewFutureFromResponse(resp)
193	future.FutureAPI = &azf
194	future.Result = future.result
195	return
196}
197
198// DeleteResponder handles the response to the Delete request. The method always
199// closes the http.Response Body.
200func (client SharedPrivateLinkResourcesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
201	err = autorest.Respond(
202		resp,
203		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
204		autorest.ByClosing())
205	result.Response = resp
206	return
207}
208
209// Get get the specified shared private link resource
210// Parameters:
211// sharedPrivateLinkResourceName - the name of the shared private link resource
212// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
213// from the Azure Resource Manager API or the portal.
214// resourceName - the name of the resource.
215func (client SharedPrivateLinkResourcesClient) Get(ctx context.Context, sharedPrivateLinkResourceName string, resourceGroupName string, resourceName string) (result SharedPrivateLinkResource, err error) {
216	if tracing.IsEnabled() {
217		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.Get")
218		defer func() {
219			sc := -1
220			if result.Response.Response != nil {
221				sc = result.Response.Response.StatusCode
222			}
223			tracing.EndSpan(ctx, sc, err)
224		}()
225	}
226	req, err := client.GetPreparer(ctx, sharedPrivateLinkResourceName, resourceGroupName, resourceName)
227	if err != nil {
228		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "Get", nil, "Failure preparing request")
229		return
230	}
231
232	resp, err := client.GetSender(req)
233	if err != nil {
234		result.Response = autorest.Response{Response: resp}
235		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "Get", resp, "Failure sending request")
236		return
237	}
238
239	result, err = client.GetResponder(resp)
240	if err != nil {
241		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "Get", resp, "Failure responding to request")
242		return
243	}
244
245	return
246}
247
248// GetPreparer prepares the Get request.
249func (client SharedPrivateLinkResourcesClient) GetPreparer(ctx context.Context, sharedPrivateLinkResourceName string, resourceGroupName string, resourceName string) (*http.Request, error) {
250	pathParameters := map[string]interface{}{
251		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
252		"resourceName":                  autorest.Encode("path", resourceName),
253		"sharedPrivateLinkResourceName": autorest.Encode("path", sharedPrivateLinkResourceName),
254		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
255	}
256
257	const APIVersion = "2021-04-01-preview"
258	queryParameters := map[string]interface{}{
259		"api-version": APIVersion,
260	}
261
262	preparer := autorest.CreatePreparer(
263		autorest.AsGet(),
264		autorest.WithBaseURL(client.BaseURI),
265		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/webPubSub/{resourceName}/sharedPrivateLinkResources/{sharedPrivateLinkResourceName}", pathParameters),
266		autorest.WithQueryParameters(queryParameters))
267	return preparer.Prepare((&http.Request{}).WithContext(ctx))
268}
269
270// GetSender sends the Get request. The method will close the
271// http.Response Body if it receives an error.
272func (client SharedPrivateLinkResourcesClient) GetSender(req *http.Request) (*http.Response, error) {
273	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
274}
275
276// GetResponder handles the response to the Get request. The method always
277// closes the http.Response Body.
278func (client SharedPrivateLinkResourcesClient) GetResponder(resp *http.Response) (result SharedPrivateLinkResource, err error) {
279	err = autorest.Respond(
280		resp,
281		azure.WithErrorUnlessStatusCode(http.StatusOK),
282		autorest.ByUnmarshallingJSON(&result),
283		autorest.ByClosing())
284	result.Response = autorest.Response{Response: resp}
285	return
286}
287
288// List list shared private link resources
289// Parameters:
290// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
291// from the Azure Resource Manager API or the portal.
292// resourceName - the name of the resource.
293func (client SharedPrivateLinkResourcesClient) List(ctx context.Context, resourceGroupName string, resourceName string) (result SharedPrivateLinkResourceListPage, err error) {
294	if tracing.IsEnabled() {
295		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.List")
296		defer func() {
297			sc := -1
298			if result.splrl.Response.Response != nil {
299				sc = result.splrl.Response.Response.StatusCode
300			}
301			tracing.EndSpan(ctx, sc, err)
302		}()
303	}
304	result.fn = client.listNextResults
305	req, err := client.ListPreparer(ctx, resourceGroupName, resourceName)
306	if err != nil {
307		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "List", nil, "Failure preparing request")
308		return
309	}
310
311	resp, err := client.ListSender(req)
312	if err != nil {
313		result.splrl.Response = autorest.Response{Response: resp}
314		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "List", resp, "Failure sending request")
315		return
316	}
317
318	result.splrl, err = client.ListResponder(resp)
319	if err != nil {
320		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "List", resp, "Failure responding to request")
321		return
322	}
323	if result.splrl.hasNextLink() && result.splrl.IsEmpty() {
324		err = result.NextWithContext(ctx)
325		return
326	}
327
328	return
329}
330
331// ListPreparer prepares the List request.
332func (client SharedPrivateLinkResourcesClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
333	pathParameters := map[string]interface{}{
334		"resourceGroupName": autorest.Encode("path", resourceGroupName),
335		"resourceName":      autorest.Encode("path", resourceName),
336		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
337	}
338
339	const APIVersion = "2021-04-01-preview"
340	queryParameters := map[string]interface{}{
341		"api-version": APIVersion,
342	}
343
344	preparer := autorest.CreatePreparer(
345		autorest.AsGet(),
346		autorest.WithBaseURL(client.BaseURI),
347		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/webPubSub/{resourceName}/sharedPrivateLinkResources", pathParameters),
348		autorest.WithQueryParameters(queryParameters))
349	return preparer.Prepare((&http.Request{}).WithContext(ctx))
350}
351
352// ListSender sends the List request. The method will close the
353// http.Response Body if it receives an error.
354func (client SharedPrivateLinkResourcesClient) ListSender(req *http.Request) (*http.Response, error) {
355	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
356}
357
358// ListResponder handles the response to the List request. The method always
359// closes the http.Response Body.
360func (client SharedPrivateLinkResourcesClient) ListResponder(resp *http.Response) (result SharedPrivateLinkResourceList, err error) {
361	err = autorest.Respond(
362		resp,
363		azure.WithErrorUnlessStatusCode(http.StatusOK),
364		autorest.ByUnmarshallingJSON(&result),
365		autorest.ByClosing())
366	result.Response = autorest.Response{Response: resp}
367	return
368}
369
370// listNextResults retrieves the next set of results, if any.
371func (client SharedPrivateLinkResourcesClient) listNextResults(ctx context.Context, lastResults SharedPrivateLinkResourceList) (result SharedPrivateLinkResourceList, err error) {
372	req, err := lastResults.sharedPrivateLinkResourceListPreparer(ctx)
373	if err != nil {
374		return result, autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "listNextResults", nil, "Failure preparing next results request")
375	}
376	if req == nil {
377		return
378	}
379	resp, err := client.ListSender(req)
380	if err != nil {
381		result.Response = autorest.Response{Response: resp}
382		return result, autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "listNextResults", resp, "Failure sending next results request")
383	}
384	result, err = client.ListResponder(resp)
385	if err != nil {
386		err = autorest.NewErrorWithError(err, "webpubsub.SharedPrivateLinkResourcesClient", "listNextResults", resp, "Failure responding to next results request")
387	}
388	return
389}
390
391// ListComplete enumerates all values, automatically crossing page boundaries as required.
392func (client SharedPrivateLinkResourcesClient) ListComplete(ctx context.Context, resourceGroupName string, resourceName string) (result SharedPrivateLinkResourceListIterator, err error) {
393	if tracing.IsEnabled() {
394		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.List")
395		defer func() {
396			sc := -1
397			if result.Response().Response.Response != nil {
398				sc = result.page.Response().Response.Response.StatusCode
399			}
400			tracing.EndSpan(ctx, sc, err)
401		}()
402	}
403	result.page, err = client.List(ctx, resourceGroupName, resourceName)
404	return
405}
406