1package search
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	"github.com/gofrs/uuid"
15	"net/http"
16)
17
18// SharedPrivateLinkResourcesClient is the client that can be used to manage Azure Cognitive Search services and API
19// keys.
20type SharedPrivateLinkResourcesClient struct {
21	BaseClient
22}
23
24// NewSharedPrivateLinkResourcesClient creates an instance of the SharedPrivateLinkResourcesClient client.
25func NewSharedPrivateLinkResourcesClient(subscriptionID string) SharedPrivateLinkResourcesClient {
26	return NewSharedPrivateLinkResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewSharedPrivateLinkResourcesClientWithBaseURI creates an instance of the SharedPrivateLinkResourcesClient client
30// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
31// clouds, Azure stack).
32func NewSharedPrivateLinkResourcesClientWithBaseURI(baseURI string, subscriptionID string) SharedPrivateLinkResourcesClient {
33	return SharedPrivateLinkResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate initiates the creation or update of a shared private link resource managed by the search service in
37// the given resource group.
38// Parameters:
39// resourceGroupName - the name of the resource group within the current subscription. You can obtain this
40// value from the Azure Resource Manager API or the portal.
41// searchServiceName - the name of the Azure Cognitive Search service associated with the specified resource
42// group.
43// sharedPrivateLinkResourceName - the name of the shared private link resource managed by the Azure Cognitive
44// Search service within the specified resource group.
45// sharedPrivateLinkResource - the definition of the shared private link resource to create or update.
46// clientRequestID - a client-generated GUID value that identifies this request. If specified, this will be
47// included in response information as a way to track the request.
48func (client SharedPrivateLinkResourcesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, searchServiceName string, sharedPrivateLinkResourceName string, sharedPrivateLinkResource SharedPrivateLinkResource, clientRequestID *uuid.UUID) (result SharedPrivateLinkResourcesCreateOrUpdateFuture, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.CreateOrUpdate")
51		defer func() {
52			sc := -1
53			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
54				sc = result.FutureAPI.Response().StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, searchServiceName, sharedPrivateLinkResourceName, sharedPrivateLinkResource, clientRequestID)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "CreateOrUpdate", nil, "Failure preparing request")
62		return
63	}
64
65	result, err = client.CreateOrUpdateSender(req)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "CreateOrUpdate", nil, "Failure sending request")
68		return
69	}
70
71	return
72}
73
74// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
75func (client SharedPrivateLinkResourcesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, searchServiceName string, sharedPrivateLinkResourceName string, sharedPrivateLinkResource SharedPrivateLinkResource, clientRequestID *uuid.UUID) (*http.Request, error) {
76	pathParameters := map[string]interface{}{
77		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
78		"searchServiceName":             autorest.Encode("path", searchServiceName),
79		"sharedPrivateLinkResourceName": autorest.Encode("path", sharedPrivateLinkResourceName),
80		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
81	}
82
83	const APIVersion = "2020-08-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsContentType("application/json; charset=utf-8"),
90		autorest.AsPut(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/sharedPrivateLinkResources/{sharedPrivateLinkResourceName}", pathParameters),
93		autorest.WithJSON(sharedPrivateLinkResource),
94		autorest.WithQueryParameters(queryParameters))
95	if clientRequestID != nil {
96		preparer = autorest.DecoratePreparer(preparer,
97			autorest.WithHeader("x-ms-client-request-id", autorest.String(clientRequestID)))
98	}
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.StatusAccepted),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// Delete initiates the deletion of the shared private link resource from the search service.
130// Parameters:
131// resourceGroupName - the name of the resource group within the current subscription. You can obtain this
132// value from the Azure Resource Manager API or the portal.
133// searchServiceName - the name of the Azure Cognitive Search service associated with the specified resource
134// group.
135// sharedPrivateLinkResourceName - the name of the shared private link resource managed by the Azure Cognitive
136// Search service within the specified resource group.
137// clientRequestID - a client-generated GUID value that identifies this request. If specified, this will be
138// included in response information as a way to track the request.
139func (client SharedPrivateLinkResourcesClient) Delete(ctx context.Context, resourceGroupName string, searchServiceName string, sharedPrivateLinkResourceName string, clientRequestID *uuid.UUID) (result SharedPrivateLinkResourcesDeleteFuture, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.Delete")
142		defer func() {
143			sc := -1
144			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
145				sc = result.FutureAPI.Response().StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	req, err := client.DeletePreparer(ctx, resourceGroupName, searchServiceName, sharedPrivateLinkResourceName, clientRequestID)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "Delete", nil, "Failure preparing request")
153		return
154	}
155
156	result, err = client.DeleteSender(req)
157	if err != nil {
158		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "Delete", nil, "Failure sending request")
159		return
160	}
161
162	return
163}
164
165// DeletePreparer prepares the Delete request.
166func (client SharedPrivateLinkResourcesClient) DeletePreparer(ctx context.Context, resourceGroupName string, searchServiceName string, sharedPrivateLinkResourceName string, clientRequestID *uuid.UUID) (*http.Request, error) {
167	pathParameters := map[string]interface{}{
168		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
169		"searchServiceName":             autorest.Encode("path", searchServiceName),
170		"sharedPrivateLinkResourceName": autorest.Encode("path", sharedPrivateLinkResourceName),
171		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
172	}
173
174	const APIVersion = "2020-08-01"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsDelete(),
181		autorest.WithBaseURL(client.BaseURI),
182		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/sharedPrivateLinkResources/{sharedPrivateLinkResourceName}", pathParameters),
183		autorest.WithQueryParameters(queryParameters))
184	if clientRequestID != nil {
185		preparer = autorest.DecoratePreparer(preparer,
186			autorest.WithHeader("x-ms-client-request-id", autorest.String(clientRequestID)))
187	}
188	return preparer.Prepare((&http.Request{}).WithContext(ctx))
189}
190
191// DeleteSender sends the Delete request. The method will close the
192// http.Response Body if it receives an error.
193func (client SharedPrivateLinkResourcesClient) DeleteSender(req *http.Request) (future SharedPrivateLinkResourcesDeleteFuture, err error) {
194	var resp *http.Response
195	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
196	if err != nil {
197		return
198	}
199	var azf azure.Future
200	azf, err = azure.NewFutureFromResponse(resp)
201	future.FutureAPI = &azf
202	future.Result = future.result
203	return
204}
205
206// DeleteResponder handles the response to the Delete request. The method always
207// closes the http.Response Body.
208func (client SharedPrivateLinkResourcesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
209	err = autorest.Respond(
210		resp,
211		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent, http.StatusNotFound),
212		autorest.ByClosing())
213	result.Response = resp
214	return
215}
216
217// Get gets the details of the shared private link resource managed by the search service in the given resource group.
218// Parameters:
219// resourceGroupName - the name of the resource group within the current subscription. You can obtain this
220// value from the Azure Resource Manager API or the portal.
221// searchServiceName - the name of the Azure Cognitive Search service associated with the specified resource
222// group.
223// sharedPrivateLinkResourceName - the name of the shared private link resource managed by the Azure Cognitive
224// Search service within the specified resource group.
225// clientRequestID - a client-generated GUID value that identifies this request. If specified, this will be
226// included in response information as a way to track the request.
227func (client SharedPrivateLinkResourcesClient) Get(ctx context.Context, resourceGroupName string, searchServiceName string, sharedPrivateLinkResourceName string, clientRequestID *uuid.UUID) (result SharedPrivateLinkResource, err error) {
228	if tracing.IsEnabled() {
229		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.Get")
230		defer func() {
231			sc := -1
232			if result.Response.Response != nil {
233				sc = result.Response.Response.StatusCode
234			}
235			tracing.EndSpan(ctx, sc, err)
236		}()
237	}
238	req, err := client.GetPreparer(ctx, resourceGroupName, searchServiceName, sharedPrivateLinkResourceName, clientRequestID)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "Get", nil, "Failure preparing request")
241		return
242	}
243
244	resp, err := client.GetSender(req)
245	if err != nil {
246		result.Response = autorest.Response{Response: resp}
247		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "Get", resp, "Failure sending request")
248		return
249	}
250
251	result, err = client.GetResponder(resp)
252	if err != nil {
253		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "Get", resp, "Failure responding to request")
254		return
255	}
256
257	return
258}
259
260// GetPreparer prepares the Get request.
261func (client SharedPrivateLinkResourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, searchServiceName string, sharedPrivateLinkResourceName string, clientRequestID *uuid.UUID) (*http.Request, error) {
262	pathParameters := map[string]interface{}{
263		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
264		"searchServiceName":             autorest.Encode("path", searchServiceName),
265		"sharedPrivateLinkResourceName": autorest.Encode("path", sharedPrivateLinkResourceName),
266		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
267	}
268
269	const APIVersion = "2020-08-01"
270	queryParameters := map[string]interface{}{
271		"api-version": APIVersion,
272	}
273
274	preparer := autorest.CreatePreparer(
275		autorest.AsGet(),
276		autorest.WithBaseURL(client.BaseURI),
277		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/sharedPrivateLinkResources/{sharedPrivateLinkResourceName}", pathParameters),
278		autorest.WithQueryParameters(queryParameters))
279	if clientRequestID != nil {
280		preparer = autorest.DecoratePreparer(preparer,
281			autorest.WithHeader("x-ms-client-request-id", autorest.String(clientRequestID)))
282	}
283	return preparer.Prepare((&http.Request{}).WithContext(ctx))
284}
285
286// GetSender sends the Get request. The method will close the
287// http.Response Body if it receives an error.
288func (client SharedPrivateLinkResourcesClient) GetSender(req *http.Request) (*http.Response, error) {
289	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
290}
291
292// GetResponder handles the response to the Get request. The method always
293// closes the http.Response Body.
294func (client SharedPrivateLinkResourcesClient) GetResponder(resp *http.Response) (result SharedPrivateLinkResource, err error) {
295	err = autorest.Respond(
296		resp,
297		azure.WithErrorUnlessStatusCode(http.StatusOK),
298		autorest.ByUnmarshallingJSON(&result),
299		autorest.ByClosing())
300	result.Response = autorest.Response{Response: resp}
301	return
302}
303
304// ListByService gets a list of all shared private link resources managed by the given service.
305// Parameters:
306// resourceGroupName - the name of the resource group within the current subscription. You can obtain this
307// value from the Azure Resource Manager API or the portal.
308// searchServiceName - the name of the Azure Cognitive Search service associated with the specified resource
309// group.
310// clientRequestID - a client-generated GUID value that identifies this request. If specified, this will be
311// included in response information as a way to track the request.
312func (client SharedPrivateLinkResourcesClient) ListByService(ctx context.Context, resourceGroupName string, searchServiceName string, clientRequestID *uuid.UUID) (result SharedPrivateLinkResourceListResultPage, err error) {
313	if tracing.IsEnabled() {
314		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.ListByService")
315		defer func() {
316			sc := -1
317			if result.splrlr.Response.Response != nil {
318				sc = result.splrlr.Response.Response.StatusCode
319			}
320			tracing.EndSpan(ctx, sc, err)
321		}()
322	}
323	result.fn = client.listByServiceNextResults
324	req, err := client.ListByServicePreparer(ctx, resourceGroupName, searchServiceName, clientRequestID)
325	if err != nil {
326		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "ListByService", nil, "Failure preparing request")
327		return
328	}
329
330	resp, err := client.ListByServiceSender(req)
331	if err != nil {
332		result.splrlr.Response = autorest.Response{Response: resp}
333		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "ListByService", resp, "Failure sending request")
334		return
335	}
336
337	result.splrlr, err = client.ListByServiceResponder(resp)
338	if err != nil {
339		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "ListByService", resp, "Failure responding to request")
340		return
341	}
342	if result.splrlr.hasNextLink() && result.splrlr.IsEmpty() {
343		err = result.NextWithContext(ctx)
344		return
345	}
346
347	return
348}
349
350// ListByServicePreparer prepares the ListByService request.
351func (client SharedPrivateLinkResourcesClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, searchServiceName string, clientRequestID *uuid.UUID) (*http.Request, error) {
352	pathParameters := map[string]interface{}{
353		"resourceGroupName": autorest.Encode("path", resourceGroupName),
354		"searchServiceName": autorest.Encode("path", searchServiceName),
355		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
356	}
357
358	const APIVersion = "2020-08-01"
359	queryParameters := map[string]interface{}{
360		"api-version": APIVersion,
361	}
362
363	preparer := autorest.CreatePreparer(
364		autorest.AsGet(),
365		autorest.WithBaseURL(client.BaseURI),
366		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/sharedPrivateLinkResources", pathParameters),
367		autorest.WithQueryParameters(queryParameters))
368	if clientRequestID != nil {
369		preparer = autorest.DecoratePreparer(preparer,
370			autorest.WithHeader("x-ms-client-request-id", autorest.String(clientRequestID)))
371	}
372	return preparer.Prepare((&http.Request{}).WithContext(ctx))
373}
374
375// ListByServiceSender sends the ListByService request. The method will close the
376// http.Response Body if it receives an error.
377func (client SharedPrivateLinkResourcesClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
378	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
379}
380
381// ListByServiceResponder handles the response to the ListByService request. The method always
382// closes the http.Response Body.
383func (client SharedPrivateLinkResourcesClient) ListByServiceResponder(resp *http.Response) (result SharedPrivateLinkResourceListResult, err error) {
384	err = autorest.Respond(
385		resp,
386		azure.WithErrorUnlessStatusCode(http.StatusOK),
387		autorest.ByUnmarshallingJSON(&result),
388		autorest.ByClosing())
389	result.Response = autorest.Response{Response: resp}
390	return
391}
392
393// listByServiceNextResults retrieves the next set of results, if any.
394func (client SharedPrivateLinkResourcesClient) listByServiceNextResults(ctx context.Context, lastResults SharedPrivateLinkResourceListResult) (result SharedPrivateLinkResourceListResult, err error) {
395	req, err := lastResults.sharedPrivateLinkResourceListResultPreparer(ctx)
396	if err != nil {
397		return result, autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "listByServiceNextResults", nil, "Failure preparing next results request")
398	}
399	if req == nil {
400		return
401	}
402	resp, err := client.ListByServiceSender(req)
403	if err != nil {
404		result.Response = autorest.Response{Response: resp}
405		return result, autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "listByServiceNextResults", resp, "Failure sending next results request")
406	}
407	result, err = client.ListByServiceResponder(resp)
408	if err != nil {
409		err = autorest.NewErrorWithError(err, "search.SharedPrivateLinkResourcesClient", "listByServiceNextResults", resp, "Failure responding to next results request")
410	}
411	return
412}
413
414// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
415func (client SharedPrivateLinkResourcesClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, searchServiceName string, clientRequestID *uuid.UUID) (result SharedPrivateLinkResourceListResultIterator, err error) {
416	if tracing.IsEnabled() {
417		ctx = tracing.StartSpan(ctx, fqdn+"/SharedPrivateLinkResourcesClient.ListByService")
418		defer func() {
419			sc := -1
420			if result.Response().Response.Response != nil {
421				sc = result.page.Response().Response.Response.StatusCode
422			}
423			tracing.EndSpan(ctx, sc, err)
424		}()
425	}
426	result.page, err = client.ListByService(ctx, resourceGroupName, searchServiceName, clientRequestID)
427	return
428}
429