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.FutureAPI != nil && result.FutureAPI.Response() != nil {
148				sc = result.FutureAPI.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		dcm.Response.Response, err = future.GetResult(sender)
217		if dcm.Response.Response == nil && err == nil {
218			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsCreateOrUpdateFuture", "Result", nil, "received nil response and error")
219		}
220		if err == nil && dcm.Response.Response.StatusCode != http.StatusNoContent {
221			dcm, err = client.CreateOrUpdateResponder(dcm.Response.Response)
222			if err != nil {
223				err = autorest.NewErrorWithError(err, "kusto.DataConnectionsCreateOrUpdateFuture", "Result", dcm.Response.Response, "Failure responding to request")
224			}
225		}
226		return
227	}
228	return
229}
230
231// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
232// closes the http.Response Body.
233func (client DataConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result DataConnectionModel, err error) {
234	err = autorest.Respond(
235		resp,
236		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
237		autorest.ByUnmarshallingJSON(&result),
238		autorest.ByClosing())
239	result.Response = autorest.Response{Response: resp}
240	return
241}
242
243// DataConnectionValidationMethod checks that the data connection parameters are valid.
244// Parameters:
245// resourceGroupName - the name of the resource group containing the Kusto cluster.
246// clusterName - the name of the Kusto cluster.
247// databaseName - the name of the database in the Kusto cluster.
248// parameters - the data connection parameters supplied to the CreateOrUpdate operation.
249func (client DataConnectionsClient) DataConnectionValidationMethod(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters DataConnectionValidation) (result DataConnectionValidationListResult, err error) {
250	if tracing.IsEnabled() {
251		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.DataConnectionValidationMethod")
252		defer func() {
253			sc := -1
254			if result.Response.Response != nil {
255				sc = result.Response.Response.StatusCode
256			}
257			tracing.EndSpan(ctx, sc, err)
258		}()
259	}
260	req, err := client.DataConnectionValidationMethodPreparer(ctx, resourceGroupName, clusterName, databaseName, parameters)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "DataConnectionValidationMethod", nil, "Failure preparing request")
263		return
264	}
265
266	resp, err := client.DataConnectionValidationMethodSender(req)
267	if err != nil {
268		result.Response = autorest.Response{Response: resp}
269		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "DataConnectionValidationMethod", resp, "Failure sending request")
270		return
271	}
272
273	result, err = client.DataConnectionValidationMethodResponder(resp)
274	if err != nil {
275		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "DataConnectionValidationMethod", resp, "Failure responding to request")
276		return
277	}
278
279	return
280}
281
282// DataConnectionValidationMethodPreparer prepares the DataConnectionValidationMethod request.
283func (client DataConnectionsClient) DataConnectionValidationMethodPreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters DataConnectionValidation) (*http.Request, error) {
284	pathParameters := map[string]interface{}{
285		"clusterName":       autorest.Encode("path", clusterName),
286		"databaseName":      autorest.Encode("path", databaseName),
287		"resourceGroupName": autorest.Encode("path", resourceGroupName),
288		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
289	}
290
291	const APIVersion = "2019-11-09"
292	queryParameters := map[string]interface{}{
293		"api-version": APIVersion,
294	}
295
296	preparer := autorest.CreatePreparer(
297		autorest.AsContentType("application/json; charset=utf-8"),
298		autorest.AsPost(),
299		autorest.WithBaseURL(client.BaseURI),
300		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnectionValidation", pathParameters),
301		autorest.WithJSON(parameters),
302		autorest.WithQueryParameters(queryParameters))
303	return preparer.Prepare((&http.Request{}).WithContext(ctx))
304}
305
306// DataConnectionValidationMethodSender sends the DataConnectionValidationMethod request. The method will close the
307// http.Response Body if it receives an error.
308func (client DataConnectionsClient) DataConnectionValidationMethodSender(req *http.Request) (*http.Response, error) {
309	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
310}
311
312// DataConnectionValidationMethodResponder handles the response to the DataConnectionValidationMethod request. The method always
313// closes the http.Response Body.
314func (client DataConnectionsClient) DataConnectionValidationMethodResponder(resp *http.Response) (result DataConnectionValidationListResult, err error) {
315	err = autorest.Respond(
316		resp,
317		azure.WithErrorUnlessStatusCode(http.StatusOK),
318		autorest.ByUnmarshallingJSON(&result),
319		autorest.ByClosing())
320	result.Response = autorest.Response{Response: resp}
321	return
322}
323
324// Delete deletes the data connection with the given name.
325// Parameters:
326// resourceGroupName - the name of the resource group containing the Kusto cluster.
327// clusterName - the name of the Kusto cluster.
328// databaseName - the name of the database in the Kusto cluster.
329// dataConnectionName - the name of the data connection.
330func (client DataConnectionsClient) Delete(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (result DataConnectionsDeleteFuture, err error) {
331	if tracing.IsEnabled() {
332		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.Delete")
333		defer func() {
334			sc := -1
335			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
336				sc = result.FutureAPI.Response().StatusCode
337			}
338			tracing.EndSpan(ctx, sc, err)
339		}()
340	}
341	req, err := client.DeletePreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName)
342	if err != nil {
343		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Delete", nil, "Failure preparing request")
344		return
345	}
346
347	result, err = client.DeleteSender(req)
348	if err != nil {
349		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Delete", nil, "Failure sending request")
350		return
351	}
352
353	return
354}
355
356// DeletePreparer prepares the Delete request.
357func (client DataConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (*http.Request, error) {
358	pathParameters := map[string]interface{}{
359		"clusterName":        autorest.Encode("path", clusterName),
360		"databaseName":       autorest.Encode("path", databaseName),
361		"dataConnectionName": autorest.Encode("path", dataConnectionName),
362		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
363		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
364	}
365
366	const APIVersion = "2019-11-09"
367	queryParameters := map[string]interface{}{
368		"api-version": APIVersion,
369	}
370
371	preparer := autorest.CreatePreparer(
372		autorest.AsDelete(),
373		autorest.WithBaseURL(client.BaseURI),
374		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
375		autorest.WithQueryParameters(queryParameters))
376	return preparer.Prepare((&http.Request{}).WithContext(ctx))
377}
378
379// DeleteSender sends the Delete request. The method will close the
380// http.Response Body if it receives an error.
381func (client DataConnectionsClient) DeleteSender(req *http.Request) (future DataConnectionsDeleteFuture, err error) {
382	var resp *http.Response
383	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
384	if err != nil {
385		return
386	}
387	var azf azure.Future
388	azf, err = azure.NewFutureFromResponse(resp)
389	future.FutureAPI = &azf
390	future.Result = func(client DataConnectionsClient) (ar autorest.Response, err error) {
391		var done bool
392		done, err = future.DoneWithContext(context.Background(), client)
393		if err != nil {
394			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsDeleteFuture", "Result", future.Response(), "Polling failure")
395			return
396		}
397		if !done {
398			err = azure.NewAsyncOpIncompleteError("kusto.DataConnectionsDeleteFuture")
399			return
400		}
401		ar.Response = future.Response()
402		return
403	}
404	return
405}
406
407// DeleteResponder handles the response to the Delete request. The method always
408// closes the http.Response Body.
409func (client DataConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
410	err = autorest.Respond(
411		resp,
412		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
413		autorest.ByClosing())
414	result.Response = resp
415	return
416}
417
418// Get returns a data connection.
419// Parameters:
420// resourceGroupName - the name of the resource group containing the Kusto cluster.
421// clusterName - the name of the Kusto cluster.
422// databaseName - the name of the database in the Kusto cluster.
423// dataConnectionName - the name of the data connection.
424func (client DataConnectionsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (result DataConnectionModel, err error) {
425	if tracing.IsEnabled() {
426		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.Get")
427		defer func() {
428			sc := -1
429			if result.Response.Response != nil {
430				sc = result.Response.Response.StatusCode
431			}
432			tracing.EndSpan(ctx, sc, err)
433		}()
434	}
435	req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName)
436	if err != nil {
437		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Get", nil, "Failure preparing request")
438		return
439	}
440
441	resp, err := client.GetSender(req)
442	if err != nil {
443		result.Response = autorest.Response{Response: resp}
444		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Get", resp, "Failure sending request")
445		return
446	}
447
448	result, err = client.GetResponder(resp)
449	if err != nil {
450		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Get", resp, "Failure responding to request")
451		return
452	}
453
454	return
455}
456
457// GetPreparer prepares the Get request.
458func (client DataConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string) (*http.Request, error) {
459	pathParameters := map[string]interface{}{
460		"clusterName":        autorest.Encode("path", clusterName),
461		"databaseName":       autorest.Encode("path", databaseName),
462		"dataConnectionName": autorest.Encode("path", dataConnectionName),
463		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
464		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
465	}
466
467	const APIVersion = "2019-11-09"
468	queryParameters := map[string]interface{}{
469		"api-version": APIVersion,
470	}
471
472	preparer := autorest.CreatePreparer(
473		autorest.AsGet(),
474		autorest.WithBaseURL(client.BaseURI),
475		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
476		autorest.WithQueryParameters(queryParameters))
477	return preparer.Prepare((&http.Request{}).WithContext(ctx))
478}
479
480// GetSender sends the Get request. The method will close the
481// http.Response Body if it receives an error.
482func (client DataConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
483	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
484}
485
486// GetResponder handles the response to the Get request. The method always
487// closes the http.Response Body.
488func (client DataConnectionsClient) GetResponder(resp *http.Response) (result DataConnectionModel, err error) {
489	err = autorest.Respond(
490		resp,
491		azure.WithErrorUnlessStatusCode(http.StatusOK),
492		autorest.ByUnmarshallingJSON(&result),
493		autorest.ByClosing())
494	result.Response = autorest.Response{Response: resp}
495	return
496}
497
498// ListByDatabase returns the list of data connections of the given Kusto database.
499// Parameters:
500// resourceGroupName - the name of the resource group containing the Kusto cluster.
501// clusterName - the name of the Kusto cluster.
502// databaseName - the name of the database in the Kusto cluster.
503func (client DataConnectionsClient) ListByDatabase(ctx context.Context, resourceGroupName string, clusterName string, databaseName string) (result DataConnectionListResult, err error) {
504	if tracing.IsEnabled() {
505		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.ListByDatabase")
506		defer func() {
507			sc := -1
508			if result.Response.Response != nil {
509				sc = result.Response.Response.StatusCode
510			}
511			tracing.EndSpan(ctx, sc, err)
512		}()
513	}
514	req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, clusterName, databaseName)
515	if err != nil {
516		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "ListByDatabase", nil, "Failure preparing request")
517		return
518	}
519
520	resp, err := client.ListByDatabaseSender(req)
521	if err != nil {
522		result.Response = autorest.Response{Response: resp}
523		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "ListByDatabase", resp, "Failure sending request")
524		return
525	}
526
527	result, err = client.ListByDatabaseResponder(resp)
528	if err != nil {
529		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "ListByDatabase", resp, "Failure responding to request")
530		return
531	}
532
533	return
534}
535
536// ListByDatabasePreparer prepares the ListByDatabase request.
537func (client DataConnectionsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string) (*http.Request, error) {
538	pathParameters := map[string]interface{}{
539		"clusterName":       autorest.Encode("path", clusterName),
540		"databaseName":      autorest.Encode("path", databaseName),
541		"resourceGroupName": autorest.Encode("path", resourceGroupName),
542		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
543	}
544
545	const APIVersion = "2019-11-09"
546	queryParameters := map[string]interface{}{
547		"api-version": APIVersion,
548	}
549
550	preparer := autorest.CreatePreparer(
551		autorest.AsGet(),
552		autorest.WithBaseURL(client.BaseURI),
553		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections", pathParameters),
554		autorest.WithQueryParameters(queryParameters))
555	return preparer.Prepare((&http.Request{}).WithContext(ctx))
556}
557
558// ListByDatabaseSender sends the ListByDatabase request. The method will close the
559// http.Response Body if it receives an error.
560func (client DataConnectionsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) {
561	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
562}
563
564// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always
565// closes the http.Response Body.
566func (client DataConnectionsClient) ListByDatabaseResponder(resp *http.Response) (result DataConnectionListResult, err error) {
567	err = autorest.Respond(
568		resp,
569		azure.WithErrorUnlessStatusCode(http.StatusOK),
570		autorest.ByUnmarshallingJSON(&result),
571		autorest.ByClosing())
572	result.Response = autorest.Response{Response: resp}
573	return
574}
575
576// Update updates a data connection.
577// Parameters:
578// resourceGroupName - the name of the resource group containing the Kusto cluster.
579// clusterName - the name of the Kusto cluster.
580// databaseName - the name of the database in the Kusto cluster.
581// dataConnectionName - the name of the data connection.
582// parameters - the data connection parameters supplied to the Update operation.
583func (client DataConnectionsClient) Update(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string, parameters BasicDataConnection) (result DataConnectionsUpdateFuture, err error) {
584	if tracing.IsEnabled() {
585		ctx = tracing.StartSpan(ctx, fqdn+"/DataConnectionsClient.Update")
586		defer func() {
587			sc := -1
588			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
589				sc = result.FutureAPI.Response().StatusCode
590			}
591			tracing.EndSpan(ctx, sc, err)
592		}()
593	}
594	req, err := client.UpdatePreparer(ctx, resourceGroupName, clusterName, databaseName, dataConnectionName, parameters)
595	if err != nil {
596		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Update", nil, "Failure preparing request")
597		return
598	}
599
600	result, err = client.UpdateSender(req)
601	if err != nil {
602		err = autorest.NewErrorWithError(err, "kusto.DataConnectionsClient", "Update", nil, "Failure sending request")
603		return
604	}
605
606	return
607}
608
609// UpdatePreparer prepares the Update request.
610func (client DataConnectionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, dataConnectionName string, parameters BasicDataConnection) (*http.Request, error) {
611	pathParameters := map[string]interface{}{
612		"clusterName":        autorest.Encode("path", clusterName),
613		"databaseName":       autorest.Encode("path", databaseName),
614		"dataConnectionName": autorest.Encode("path", dataConnectionName),
615		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
616		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
617	}
618
619	const APIVersion = "2019-11-09"
620	queryParameters := map[string]interface{}{
621		"api-version": APIVersion,
622	}
623
624	preparer := autorest.CreatePreparer(
625		autorest.AsContentType("application/json; charset=utf-8"),
626		autorest.AsPatch(),
627		autorest.WithBaseURL(client.BaseURI),
628		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/dataConnections/{dataConnectionName}", pathParameters),
629		autorest.WithJSON(parameters),
630		autorest.WithQueryParameters(queryParameters))
631	return preparer.Prepare((&http.Request{}).WithContext(ctx))
632}
633
634// UpdateSender sends the Update request. The method will close the
635// http.Response Body if it receives an error.
636func (client DataConnectionsClient) UpdateSender(req *http.Request) (future DataConnectionsUpdateFuture, err error) {
637	var resp *http.Response
638	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
639	if err != nil {
640		return
641	}
642	var azf azure.Future
643	azf, err = azure.NewFutureFromResponse(resp)
644	future.FutureAPI = &azf
645	future.Result = func(client DataConnectionsClient) (dcm DataConnectionModel, err error) {
646		var done bool
647		done, err = future.DoneWithContext(context.Background(), client)
648		if err != nil {
649			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsUpdateFuture", "Result", future.Response(), "Polling failure")
650			return
651		}
652		if !done {
653			err = azure.NewAsyncOpIncompleteError("kusto.DataConnectionsUpdateFuture")
654			return
655		}
656		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
657		dcm.Response.Response, err = future.GetResult(sender)
658		if dcm.Response.Response == nil && err == nil {
659			err = autorest.NewErrorWithError(err, "kusto.DataConnectionsUpdateFuture", "Result", nil, "received nil response and error")
660		}
661		if err == nil && dcm.Response.Response.StatusCode != http.StatusNoContent {
662			dcm, err = client.UpdateResponder(dcm.Response.Response)
663			if err != nil {
664				err = autorest.NewErrorWithError(err, "kusto.DataConnectionsUpdateFuture", "Result", dcm.Response.Response, "Failure responding to request")
665			}
666		}
667		return
668	}
669	return
670}
671
672// UpdateResponder handles the response to the Update request. The method always
673// closes the http.Response Body.
674func (client DataConnectionsClient) UpdateResponder(resp *http.Response) (result DataConnectionModel, err error) {
675	err = autorest.Respond(
676		resp,
677		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
678		autorest.ByUnmarshallingJSON(&result),
679		autorest.ByClosing())
680	result.Response = autorest.Response{Response: resp}
681	return
682}
683