1package kusto
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// DataConnectionsClient is the the Azure Kusto management API provides a RESTful set of web services that interact
30// with Azure Kusto services to manage your clusters and databases. The API enables you to create, update, and delete
31// clusters and databases.
32type DataConnectionsClient struct {
33	BaseClient
34}
35
36// NewDataConnectionsClient creates an instance of the DataConnectionsClient client.
37func NewDataConnectionsClient(subscriptionID string) DataConnectionsClient {
38	return NewDataConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
39}
40
41// NewDataConnectionsClientWithBaseURI creates an instance of the DataConnectionsClient client using a custom endpoint.
42// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
43func NewDataConnectionsClientWithBaseURI(baseURI string, subscriptionID string) DataConnectionsClient {
44	return DataConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
45}
46
47// CheckNameAvailability checks that the data connection name is valid and is not already in use.
48// Parameters:
49// resourceGroupName - the name of the resource group containing the Kusto cluster.
50// clusterName - the name of the Kusto cluster.
51// databaseName - the name of the database in the Kusto cluster.
52// dataConnectionName - the name of the data connection.
53func (client DataConnectionsClient) CheckNameAvailability(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName DataConnectionCheckNameRequest) (result CheckNameResult, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.CheckNameAvailability")
56		defer func() {
57			sc := -1
58			if result.Response.Response != nil {
59				sc = result.Response.Response.StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	if err := validation.Validate([]validation.Validation{
65		{TargetValue: dataConnectionName,
66			Constraints: []validation.Constraint{{Target: "dataConnectionName.Name", Name: validation.Null, Rule: true, Chain: nil},
67				{Target: "dataConnectionName.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
68		return result, validation.NewError("kusto.DataConnectionsClient", "CheckNameAvailability", err.Error())
69	}
70
71	req, err := client.CheckNameAvailabilityPreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "CheckNameAvailability", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.CheckNameAvailabilitySender(req)
78	if err != nil {
79		result.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "CheckNameAvailability", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.CheckNameAvailabilityResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "CheckNameAvailability", resp, "Failure responding to request")
87		return
88	}
89
90	return
91}
92
93// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
94func (client DataConnectionsClient) CheckNameAvailabilityPreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName DataConnectionCheckNameRequest) (*http.Request, error) {
95	pathParameters := map[string]interface{}{
96		"clusterName":       autorest.Encode("path", clusterName),
97		"databaseName":      autorest.Encode("path", databaseName),
98		"resourceGroupName": autorest.Encode("path", resourceGroupName),
99		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
100	}
101
102	const APIVersion = "2019-11-09"
103	queryParameters := map[string]interface{}{
104		"api-version": APIVersion,
105	}
106
107	preparer := autorest.CreatePreparer(
108		autorest.AsContentType("application/json; charset=utf-8"),
109		autorest.AsPost(),
110		autorest.WithBaseURL(client.BaseURI),
111		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/checkNameAvailability", pathParameters),
112		autorest.WithJSON(dataConnectionName),
113		autorest.WithQueryParameters(queryParameters))
114	return preparer.Prepare((&http.Request{}).WithContext(ctx))
115}
116
117// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
118// http.Response Body if it receives an error.
119func (client DataConnectionsClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
120	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
121}
122
123// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
124// closes the http.Response Body.
125func (client DataConnectionsClient) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameResult, err error) {
126	err = autorest.Respond(
127		resp,
128		azure.WithErrorUnlessStatusCode(http.StatusOK),
129		autorest.ByUnmarshallingJSON(&result),
130		autorest.ByClosing())
131	result.Response = autorest.Response{Response: resp}
132	return
133}
134
135// CreateOrUpdate creates or updates a data connection.
136// Parameters:
137// resourceGroupName - the name of the resource group containing the Kusto cluster.
138// clusterName - the name of the Kusto cluster.
139// databaseName - the name of the database in the Kusto cluster.
140// dataConnectionName - the name of the data connection.
141// parameters - the data connection parameters supplied to the CreateOrUpdate operation.
142func (client DataConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string, parameters BasicDataConnection) (result DataConnectionsCreateOrUpdateFuture, err error) {
143	if tracing.IsEnabled() {
144		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.CreateOrUpdate")
145		defer func() {
146			sc := -1
147			if result.Response() != nil {
148				sc = result.Response().StatusCode
149			}
150			tracing.EndSpan(ctx, sc, err)
151		}()
152	}
153	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName, parameters)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
156		return
157	}
158
159	result, err = client.CreateOrUpdateSender(req)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "CreateOrUpdate", nil, "Failure sending request")
162		return
163	}
164
165	return
166}
167
168// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
169func (client DataConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string, parameters BasicDataConnection) (*http.Request, error) {
170	pathParameters := map[string]interface{}{
171		"clusterName":        autorest.Encode("path", clusterName),
172		"databaseName":       autorest.Encode("path", databaseName),
173		"dataConnectionName": autorest.Encode("path", dataConnectionName),
174		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
175		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
176	}
177
178	const APIVersion = "2019-11-09"
179	queryParameters := map[string]interface{}{
180		"api-version": APIVersion,
181	}
182
183	preparer := autorest.CreatePreparer(
184		autorest.AsContentType("application/json; charset=utf-8"),
185		autorest.AsPut(),
186		autorest.WithBaseURL(client.BaseURI),
187		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
188		autorest.WithJSON(parameters),
189		autorest.WithQueryParameters(queryParameters))
190	return preparer.Prepare((&http.Request{}).WithContext(ctx))
191}
192
193// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
194// http.Response Body if it receives an error.
195func (client DataConnectionsClient) CreateOrUpdateSender(req *http.Request) (future DataConnectionsCreateOrUpdateFuture, err error) {
196	var resp *http.Response
197	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
198	if err != nil {
199		return
200	}
201	var azf azure.Future
202	azf, err = azure.NewFutureFromResponse(resp)
203	future.FutureAPI = &azf
204	future.Result = func(client DataConnectionsClient) (dcm DataConnectionModel, err error) {
205		var done bool
206		done, err = future.DoneWithContext(context.Background(), client)
207		if err != nil {
208			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
209			return
210		}
211		if !done {
212			err = azure.NewAsyncOpIncompleteError("kusto.DataConnectionsCreateOrUpdateFuture")
213			return
214		}
215		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
216		if dcm.Response.Response, err = future.GetResult(sender); err == nil && dcm.Response.Response.StatusCode != http.StatusNoContent {
217			dcm, err = client.CreateOrUpdateResponder(dcm.Response.Response)
218			if err != nil {
219				err = autorest.NewErrorWithError(err, "kusto.DataConnectionsCreateOrUpdateFuture", "Result", dcm.Response.Response, "Failure responding to request")
220			}
221		}
222		return
223	}
224	return
225}
226
227// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
228// closes the http.Response Body.
229func (client DataConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result DataConnectionModel, err error) {
230	err = autorest.Respond(
231		resp,
232		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
233		autorest.ByUnmarshallingJSON(&result),
234		autorest.ByClosing())
235	result.Response = autorest.Response{Response: resp}
236	return
237}
238
239// DataConnectionValidationMethod checks that the data connection parameters are valid.
240// Parameters:
241// resourceGroupName - the name of the resource group containing the Kusto cluster.
242// clusterName - the name of the Kusto cluster.
243// databaseName - the name of the database in the Kusto cluster.
244// parameters - the data connection parameters supplied to the CreateOrUpdate operation.
245func (client DataConnectionsClient) DataConnectionValidationMethod(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters DataConnectionValidation) (result DataConnectionValidationListResult, err error) {
246	if tracing.IsEnabled() {
247		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.DataConnectionValidationMethod")
248		defer func() {
249			sc := -1
250			if result.Response.Response != nil {
251				sc = result.Response.Response.StatusCode
252			}
253			tracing.EndSpan(ctx, sc, err)
254		}()
255	}
256	req, err := client.DataConnectionValidationMethodPreparer(ctx, resourceGroupName, clusterName, databaseName, parameters)
257	if err != nil {
258		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "DataConnectionValidationMethod", nil, "Failure preparing request")
259		return
260	}
261
262	resp, err := client.DataConnectionValidationMethodSender(req)
263	if err != nil {
264		result.Response = autorest.Response{Response: resp}
265		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "DataConnectionValidationMethod", resp, "Failure sending request")
266		return
267	}
268
269	result, err = client.DataConnectionValidationMethodResponder(resp)
270	if err != nil {
271		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "DataConnectionValidationMethod", resp, "Failure responding to request")
272		return
273	}
274
275	return
276}
277
278// DataConnectionValidationMethodPreparer prepares the DataConnectionValidationMethod request.
279func (client DataConnectionsClient) DataConnectionValidationMethodPreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters DataConnectionValidation) (*http.Request, error) {
280	pathParameters := map[string]interface{}{
281		"clusterName":       autorest.Encode("path", clusterName),
282		"databaseName":      autorest.Encode("path", databaseName),
283		"resourceGroupName": autorest.Encode("path", resourceGroupName),
284		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
285	}
286
287	const APIVersion = "2019-11-09"
288	queryParameters := map[string]interface{}{
289		"api-version": APIVersion,
290	}
291
292	preparer := autorest.CreatePreparer(
293		autorest.AsContentType("application/json; charset=utf-8"),
294		autorest.AsPost(),
295		autorest.WithBaseURL(client.BaseURI),
296		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnectionValidation", pathParameters),
297		autorest.WithJSON(parameters),
298		autorest.WithQueryParameters(queryParameters))
299	return preparer.Prepare((&http.Request{}).WithContext(ctx))
300}
301
302// DataConnectionValidationMethodSender sends the DataConnectionValidationMethod request. The method will close the
303// http.Response Body if it receives an error.
304func (client DataConnectionsClient) DataConnectionValidationMethodSender(req *http.Request) (*http.Response, error) {
305	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
306}
307
308// DataConnectionValidationMethodResponder handles the response to the DataConnectionValidationMethod request. The method always
309// closes the http.Response Body.
310func (client DataConnectionsClient) DataConnectionValidationMethodResponder(resp *http.Response) (result DataConnectionValidationListResult, err error) {
311	err = autorest.Respond(
312		resp,
313		azure.WithErrorUnlessStatusCode(http.StatusOK),
314		autorest.ByUnmarshallingJSON(&result),
315		autorest.ByClosing())
316	result.Response = autorest.Response{Response: resp}
317	return
318}
319
320// Delete deletes the data connection with the given name.
321// Parameters:
322// resourceGroupName - the name of the resource group containing the Kusto cluster.
323// clusterName - the name of the Kusto cluster.
324// databaseName - the name of the database in the Kusto cluster.
325// dataConnectionName - the name of the data connection.
326func (client DataConnectionsClient) Delete(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (result DataConnectionsDeleteFuture, err error) {
327	if tracing.IsEnabled() {
328		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.Delete")
329		defer func() {
330			sc := -1
331			if result.Response() != nil {
332				sc = result.Response().StatusCode
333			}
334			tracing.EndSpan(ctx, sc, err)
335		}()
336	}
337	req, err := client.DeletePreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName)
338	if err != nil {
339		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Delete", nil, "Failure preparing request")
340		return
341	}
342
343	result, err = client.DeleteSender(req)
344	if err != nil {
345		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Delete", nil, "Failure sending request")
346		return
347	}
348
349	return
350}
351
352// DeletePreparer prepares the Delete request.
353func (client DataConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (*http.Request, error) {
354	pathParameters := map[string]interface{}{
355		"clusterName":        autorest.Encode("path", clusterName),
356		"databaseName":       autorest.Encode("path", databaseName),
357		"dataConnectionName": autorest.Encode("path", dataConnectionName),
358		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
359		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
360	}
361
362	const APIVersion = "2019-11-09"
363	queryParameters := map[string]interface{}{
364		"api-version": APIVersion,
365	}
366
367	preparer := autorest.CreatePreparer(
368		autorest.AsDelete(),
369		autorest.WithBaseURL(client.BaseURI),
370		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
371		autorest.WithQueryParameters(queryParameters))
372	return preparer.Prepare((&http.Request{}).WithContext(ctx))
373}
374
375// DeleteSender sends the Delete request. The method will close the
376// http.Response Body if it receives an error.
377func (client DataConnectionsClient) DeleteSender(req *http.Request) (future DataConnectionsDeleteFuture, err error) {
378	var resp *http.Response
379	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
380	if err != nil {
381		return
382	}
383	var azf azure.Future
384	azf, err = azure.NewFutureFromResponse(resp)
385	future.FutureAPI = &azf
386	future.Result = func(client DataConnectionsClient) (ar autorest.Response, err error) {
387		var done bool
388		done, err = future.DoneWithContext(context.Background(), client)
389		if err != nil {
390			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsDeleteFuture", "Result", future.Response(), "Polling failure")
391			return
392		}
393		if !done {
394			err = azure.NewAsyncOpIncompleteError("kusto.DataConnectionsDeleteFuture")
395			return
396		}
397		ar.Response = future.Response()
398		return
399	}
400	return
401}
402
403// DeleteResponder handles the response to the Delete request. The method always
404// closes the http.Response Body.
405func (client DataConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
406	err = autorest.Respond(
407		resp,
408		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
409		autorest.ByClosing())
410	result.Response = resp
411	return
412}
413
414// Get returns a data connection.
415// Parameters:
416// resourceGroupName - the name of the resource group containing the Kusto cluster.
417// clusterName - the name of the Kusto cluster.
418// databaseName - the name of the database in the Kusto cluster.
419// dataConnectionName - the name of the data connection.
420func (client DataConnectionsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (result DataConnectionModel, err error) {
421	if tracing.IsEnabled() {
422		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.Get")
423		defer func() {
424			sc := -1
425			if result.Response.Response != nil {
426				sc = result.Response.Response.StatusCode
427			}
428			tracing.EndSpan(ctx, sc, err)
429		}()
430	}
431	req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName)
432	if err != nil {
433		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Get", nil, "Failure preparing request")
434		return
435	}
436
437	resp, err := client.GetSender(req)
438	if err != nil {
439		result.Response = autorest.Response{Response: resp}
440		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Get", resp, "Failure sending request")
441		return
442	}
443
444	result, err = client.GetResponder(resp)
445	if err != nil {
446		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Get", resp, "Failure responding to request")
447		return
448	}
449
450	return
451}
452
453// GetPreparer prepares the Get request.
454func (client DataConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (*http.Request, error) {
455	pathParameters := map[string]interface{}{
456		"clusterName":        autorest.Encode("path", clusterName),
457		"databaseName":       autorest.Encode("path", databaseName),
458		"dataConnectionName": autorest.Encode("path", dataConnectionName),
459		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
460		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
461	}
462
463	const APIVersion = "2019-11-09"
464	queryParameters := map[string]interface{}{
465		"api-version": APIVersion,
466	}
467
468	preparer := autorest.CreatePreparer(
469		autorest.AsGet(),
470		autorest.WithBaseURL(client.BaseURI),
471		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
472		autorest.WithQueryParameters(queryParameters))
473	return preparer.Prepare((&http.Request{}).WithContext(ctx))
474}
475
476// GetSender sends the Get request. The method will close the
477// http.Response Body if it receives an error.
478func (client DataConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
479	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
480}
481
482// GetResponder handles the response to the Get request. The method always
483// closes the http.Response Body.
484func (client DataConnectionsClient) GetResponder(resp *http.Response) (result DataConnectionModel, err error) {
485	err = autorest.Respond(
486		resp,
487		azure.WithErrorUnlessStatusCode(http.StatusOK),
488		autorest.ByUnmarshallingJSON(&result),
489		autorest.ByClosing())
490	result.Response = autorest.Response{Response: resp}
491	return
492}
493
494// ListByDatabase returns the list of data connections of the given Kusto database.
495// Parameters:
496// resourceGroupName - the name of the resource group containing the Kusto cluster.
497// clusterName - the name of the Kusto cluster.
498// databaseName - the name of the database in the Kusto cluster.
499func (client DataConnectionsClient) ListByDatabase(ctx context.Context, resourceGroupName string, clusterName string, databaseName string) (result DataConnectionListResult, err error) {
500	if tracing.IsEnabled() {
501		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.ListByDatabase")
502		defer func() {
503			sc := -1
504			if result.Response.Response != nil {
505				sc = result.Response.Response.StatusCode
506			}
507			tracing.EndSpan(ctx, sc, err)
508		}()
509	}
510	req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, clusterName, databaseName)
511	if err != nil {
512		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "ListByDatabase", nil, "Failure preparing request")
513		return
514	}
515
516	resp, err := client.ListByDatabaseSender(req)
517	if err != nil {
518		result.Response = autorest.Response{Response: resp}
519		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "ListByDatabase", resp, "Failure sending request")
520		return
521	}
522
523	result, err = client.ListByDatabaseResponder(resp)
524	if err != nil {
525		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "ListByDatabase", resp, "Failure responding to request")
526		return
527	}
528
529	return
530}
531
532// ListByDatabasePreparer prepares the ListByDatabase request.
533func (client DataConnectionsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string) (*http.Request, error) {
534	pathParameters := map[string]interface{}{
535		"clusterName":       autorest.Encode("path", clusterName),
536		"databaseName":      autorest.Encode("path", databaseName),
537		"resourceGroupName": autorest.Encode("path", resourceGroupName),
538		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
539	}
540
541	const APIVersion = "2019-11-09"
542	queryParameters := map[string]interface{}{
543		"api-version": APIVersion,
544	}
545
546	preparer := autorest.CreatePreparer(
547		autorest.AsGet(),
548		autorest.WithBaseURL(client.BaseURI),
549		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections", pathParameters),
550		autorest.WithQueryParameters(queryParameters))
551	return preparer.Prepare((&http.Request{}).WithContext(ctx))
552}
553
554// ListByDatabaseSender sends the ListByDatabase request. The method will close the
555// http.Response Body if it receives an error.
556func (client DataConnectionsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) {
557	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
558}
559
560// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always
561// closes the http.Response Body.
562func (client DataConnectionsClient) ListByDatabaseResponder(resp *http.Response) (result DataConnectionListResult, err error) {
563	err = autorest.Respond(
564		resp,
565		azure.WithErrorUnlessStatusCode(http.StatusOK),
566		autorest.ByUnmarshallingJSON(&result),
567		autorest.ByClosing())
568	result.Response = autorest.Response{Response: resp}
569	return
570}
571
572// Update updates a data connection.
573// Parameters:
574// resourceGroupName - the name of the resource group containing the Kusto cluster.
575// clusterName - the name of the Kusto cluster.
576// databaseName - the name of the database in the Kusto cluster.
577// dataConnectionName - the name of the data connection.
578// parameters - the data connection parameters supplied to the Update operation.
579func (client DataConnectionsClient) Update(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string, parameters BasicDataConnection) (result DataConnectionsUpdateFuture, err error) {
580	if tracing.IsEnabled() {
581		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.Update")
582		defer func() {
583			sc := -1
584			if result.Response() != nil {
585				sc = result.Response().StatusCode
586			}
587			tracing.EndSpan(ctx, sc, err)
588		}()
589	}
590	req, err := client.UpdatePreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName, parameters)
591	if err != nil {
592		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Update", nil, "Failure preparing request")
593		return
594	}
595
596	result, err = client.UpdateSender(req)
597	if err != nil {
598		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Update", nil, "Failure sending request")
599		return
600	}
601
602	return
603}
604
605// UpdatePreparer prepares the Update request.
606func (client DataConnectionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string, parameters BasicDataConnection) (*http.Request, error) {
607	pathParameters := map[string]interface{}{
608		"clusterName":        autorest.Encode("path", clusterName),
609		"databaseName":       autorest.Encode("path", databaseName),
610		"dataConnectionName": autorest.Encode("path", dataConnectionName),
611		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
612		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
613	}
614
615	const APIVersion = "2019-11-09"
616	queryParameters := map[string]interface{}{
617		"api-version": APIVersion,
618	}
619
620	preparer := autorest.CreatePreparer(
621		autorest.AsContentType("application/json; charset=utf-8"),
622		autorest.AsPatch(),
623		autorest.WithBaseURL(client.BaseURI),
624		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
625		autorest.WithJSON(parameters),
626		autorest.WithQueryParameters(queryParameters))
627	return preparer.Prepare((&http.Request{}).WithContext(ctx))
628}
629
630// UpdateSender sends the Update request. The method will close the
631// http.Response Body if it receives an error.
632func (client DataConnectionsClient) UpdateSender(req *http.Request) (future DataConnectionsUpdateFuture, err error) {
633	var resp *http.Response
634	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
635	if err != nil {
636		return
637	}
638	var azf azure.Future
639	azf, err = azure.NewFutureFromResponse(resp)
640	future.FutureAPI = &azf
641	future.Result = func(client DataConnectionsClient) (dcm DataConnectionModel, err error) {
642		var done bool
643		done, err = future.DoneWithContext(context.Background(), client)
644		if err != nil {
645			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsUpdateFuture", "Result", future.Response(), "Polling failure")
646			return
647		}
648		if !done {
649			err = azure.NewAsyncOpIncompleteError("kusto.DataConnectionsUpdateFuture")
650			return
651		}
652		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
653		if dcm.Response.Response, err = future.GetResult(sender); err == nil && dcm.Response.Response.StatusCode != http.StatusNoContent {
654			dcm, err = client.UpdateResponder(dcm.Response.Response)
655			if err != nil {
656				err = autorest.NewErrorWithError(err, "kusto.DataConnectionsUpdateFuture", "Result", dcm.Response.Response, "Failure responding to request")
657			}
658		}
659		return
660	}
661	return
662}
663
664// UpdateResponder handles the response to the Update request. The method always
665// closes the http.Response Body.
666func (client DataConnectionsClient) UpdateResponder(resp *http.Response) (result DataConnectionModel, err error) {
667	err = autorest.Respond(
668		resp,
669		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
670		autorest.ByUnmarshallingJSON(&result),
671		autorest.ByClosing())
672	result.Response = autorest.Response{Response: resp}
673	return
674}
675