1package kusto 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// AttachedDatabaseConfigurationsClient is the the Azure Kusto management API provides a RESTful set of web services 19// that interact with Azure Kusto services to manage your clusters and databases. The API enables you to create, 20// update, and delete clusters and databases. 21type AttachedDatabaseConfigurationsClient struct { 22 BaseClient 23} 24 25// NewAttachedDatabaseConfigurationsClient creates an instance of the AttachedDatabaseConfigurationsClient client. 26func NewAttachedDatabaseConfigurationsClient(subscriptionID string) AttachedDatabaseConfigurationsClient { 27 return NewAttachedDatabaseConfigurationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewAttachedDatabaseConfigurationsClientWithBaseURI creates an instance of the AttachedDatabaseConfigurationsClient 31// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 32// (sovereign clouds, Azure stack). 33func NewAttachedDatabaseConfigurationsClientWithBaseURI(baseURI string, subscriptionID string) AttachedDatabaseConfigurationsClient { 34 return AttachedDatabaseConfigurationsClient{NewWithBaseURI(baseURI, subscriptionID)} 35} 36 37// CreateOrUpdate creates or updates an attached database configuration. 38// Parameters: 39// resourceGroupName - the name of the resource group containing the Kusto cluster. 40// clusterName - the name of the Kusto cluster. 41// attachedDatabaseConfigurationName - the name of the attached database configuration. 42// parameters - the database parameters supplied to the CreateOrUpdate operation. 43func (client AttachedDatabaseConfigurationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, attachedDatabaseConfigurationName string, parameters AttachedDatabaseConfiguration) (result AttachedDatabaseConfigurationsCreateOrUpdateFuture, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/AttachedDatabaseConfigurationsClient.CreateOrUpdate") 46 defer func() { 47 sc := -1 48 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 49 sc = result.FutureAPI.Response().StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 if err := validation.Validate([]validation.Validation{ 55 {TargetValue: parameters, 56 Constraints: []validation.Constraint{{Target: "parameters.AttachedDatabaseConfigurationProperties", Name: validation.Null, Rule: false, 57 Chain: []validation.Constraint{{Target: "parameters.AttachedDatabaseConfigurationProperties.DatabaseName", Name: validation.Null, Rule: true, Chain: nil}, 58 {Target: "parameters.AttachedDatabaseConfigurationProperties.ClusterResourceID", Name: validation.Null, Rule: true, Chain: nil}, 59 }}}}}); err != nil { 60 return result, validation.NewError("kusto.AttachedDatabaseConfigurationsClient", "CreateOrUpdate", err.Error()) 61 } 62 63 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, clusterName, attachedDatabaseConfigurationName, parameters) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "CreateOrUpdate", nil, "Failure preparing request") 66 return 67 } 68 69 result, err = client.CreateOrUpdateSender(req) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "CreateOrUpdate", nil, "Failure sending request") 72 return 73 } 74 75 return 76} 77 78// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 79func (client AttachedDatabaseConfigurationsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, clusterName string, attachedDatabaseConfigurationName string, parameters AttachedDatabaseConfiguration) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "attachedDatabaseConfigurationName": autorest.Encode("path", attachedDatabaseConfigurationName), 82 "clusterName": autorest.Encode("path", clusterName), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2019-09-07" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 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.Kusto/clusters/{clusterName}/attachedDatabaseConfigurations/{attachedDatabaseConfigurationName}", 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 AttachedDatabaseConfigurationsClient) CreateOrUpdateSender(req *http.Request) (future AttachedDatabaseConfigurationsCreateOrUpdateFuture, 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 AttachedDatabaseConfigurationsClient) CreateOrUpdateResponder(resp *http.Response) (result AttachedDatabaseConfiguration, err error) { 120 err = autorest.Respond( 121 resp, 122 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 123 autorest.ByUnmarshallingJSON(&result), 124 autorest.ByClosing()) 125 result.Response = autorest.Response{Response: resp} 126 return 127} 128 129// Delete deletes the attached database configuration with the given name. 130// Parameters: 131// resourceGroupName - the name of the resource group containing the Kusto cluster. 132// clusterName - the name of the Kusto cluster. 133// attachedDatabaseConfigurationName - the name of the attached database configuration. 134func (client AttachedDatabaseConfigurationsClient) Delete(ctx context.Context, resourceGroupName string, clusterName string, attachedDatabaseConfigurationName string) (result AttachedDatabaseConfigurationsDeleteFuture, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/AttachedDatabaseConfigurationsClient.Delete") 137 defer func() { 138 sc := -1 139 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 140 sc = result.FutureAPI.Response().StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 req, err := client.DeletePreparer(ctx, resourceGroupName, clusterName, attachedDatabaseConfigurationName) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "Delete", nil, "Failure preparing request") 148 return 149 } 150 151 result, err = client.DeleteSender(req) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "Delete", nil, "Failure sending request") 154 return 155 } 156 157 return 158} 159 160// DeletePreparer prepares the Delete request. 161func (client AttachedDatabaseConfigurationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, clusterName string, attachedDatabaseConfigurationName string) (*http.Request, error) { 162 pathParameters := map[string]interface{}{ 163 "attachedDatabaseConfigurationName": autorest.Encode("path", attachedDatabaseConfigurationName), 164 "clusterName": autorest.Encode("path", clusterName), 165 "resourceGroupName": autorest.Encode("path", resourceGroupName), 166 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 167 } 168 169 const APIVersion = "2019-09-07" 170 queryParameters := map[string]interface{}{ 171 "api-version": APIVersion, 172 } 173 174 preparer := autorest.CreatePreparer( 175 autorest.AsDelete(), 176 autorest.WithBaseURL(client.BaseURI), 177 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/attachedDatabaseConfigurations/{attachedDatabaseConfigurationName}", pathParameters), 178 autorest.WithQueryParameters(queryParameters)) 179 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 180} 181 182// DeleteSender sends the Delete request. The method will close the 183// http.Response Body if it receives an error. 184func (client AttachedDatabaseConfigurationsClient) DeleteSender(req *http.Request) (future AttachedDatabaseConfigurationsDeleteFuture, err error) { 185 var resp *http.Response 186 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 187 if err != nil { 188 return 189 } 190 var azf azure.Future 191 azf, err = azure.NewFutureFromResponse(resp) 192 future.FutureAPI = &azf 193 future.Result = future.result 194 return 195} 196 197// DeleteResponder handles the response to the Delete request. The method always 198// closes the http.Response Body. 199func (client AttachedDatabaseConfigurationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 200 err = autorest.Respond( 201 resp, 202 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 203 autorest.ByClosing()) 204 result.Response = resp 205 return 206} 207 208// Get returns an attached database configuration. 209// Parameters: 210// resourceGroupName - the name of the resource group containing the Kusto cluster. 211// clusterName - the name of the Kusto cluster. 212// attachedDatabaseConfigurationName - the name of the attached database configuration. 213func (client AttachedDatabaseConfigurationsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, attachedDatabaseConfigurationName string) (result AttachedDatabaseConfiguration, err error) { 214 if tracing.IsEnabled() { 215 ctx = tracing.StartSpan(ctx, fqdn+"/AttachedDatabaseConfigurationsClient.Get") 216 defer func() { 217 sc := -1 218 if result.Response.Response != nil { 219 sc = result.Response.Response.StatusCode 220 } 221 tracing.EndSpan(ctx, sc, err) 222 }() 223 } 224 req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, attachedDatabaseConfigurationName) 225 if err != nil { 226 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "Get", nil, "Failure preparing request") 227 return 228 } 229 230 resp, err := client.GetSender(req) 231 if err != nil { 232 result.Response = autorest.Response{Response: resp} 233 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "Get", resp, "Failure sending request") 234 return 235 } 236 237 result, err = client.GetResponder(resp) 238 if err != nil { 239 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "Get", resp, "Failure responding to request") 240 return 241 } 242 243 return 244} 245 246// GetPreparer prepares the Get request. 247func (client AttachedDatabaseConfigurationsClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, attachedDatabaseConfigurationName string) (*http.Request, error) { 248 pathParameters := map[string]interface{}{ 249 "attachedDatabaseConfigurationName": autorest.Encode("path", attachedDatabaseConfigurationName), 250 "clusterName": autorest.Encode("path", clusterName), 251 "resourceGroupName": autorest.Encode("path", resourceGroupName), 252 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 253 } 254 255 const APIVersion = "2019-09-07" 256 queryParameters := map[string]interface{}{ 257 "api-version": APIVersion, 258 } 259 260 preparer := autorest.CreatePreparer( 261 autorest.AsGet(), 262 autorest.WithBaseURL(client.BaseURI), 263 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/attachedDatabaseConfigurations/{attachedDatabaseConfigurationName}", pathParameters), 264 autorest.WithQueryParameters(queryParameters)) 265 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 266} 267 268// GetSender sends the Get request. The method will close the 269// http.Response Body if it receives an error. 270func (client AttachedDatabaseConfigurationsClient) GetSender(req *http.Request) (*http.Response, error) { 271 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 272} 273 274// GetResponder handles the response to the Get request. The method always 275// closes the http.Response Body. 276func (client AttachedDatabaseConfigurationsClient) GetResponder(resp *http.Response) (result AttachedDatabaseConfiguration, err error) { 277 err = autorest.Respond( 278 resp, 279 azure.WithErrorUnlessStatusCode(http.StatusOK), 280 autorest.ByUnmarshallingJSON(&result), 281 autorest.ByClosing()) 282 result.Response = autorest.Response{Response: resp} 283 return 284} 285 286// ListByCluster returns the list of attached database configurations of the given Kusto cluster. 287// Parameters: 288// resourceGroupName - the name of the resource group containing the Kusto cluster. 289// clusterName - the name of the Kusto cluster. 290func (client AttachedDatabaseConfigurationsClient) ListByCluster(ctx context.Context, resourceGroupName string, clusterName string) (result AttachedDatabaseConfigurationListResult, err error) { 291 if tracing.IsEnabled() { 292 ctx = tracing.StartSpan(ctx, fqdn+"/AttachedDatabaseConfigurationsClient.ListByCluster") 293 defer func() { 294 sc := -1 295 if result.Response.Response != nil { 296 sc = result.Response.Response.StatusCode 297 } 298 tracing.EndSpan(ctx, sc, err) 299 }() 300 } 301 req, err := client.ListByClusterPreparer(ctx, resourceGroupName, clusterName) 302 if err != nil { 303 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "ListByCluster", nil, "Failure preparing request") 304 return 305 } 306 307 resp, err := client.ListByClusterSender(req) 308 if err != nil { 309 result.Response = autorest.Response{Response: resp} 310 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "ListByCluster", resp, "Failure sending request") 311 return 312 } 313 314 result, err = client.ListByClusterResponder(resp) 315 if err != nil { 316 err = autorest.NewErrorWithError(err, "kusto.AttachedDatabaseConfigurationsClient", "ListByCluster", resp, "Failure responding to request") 317 return 318 } 319 320 return 321} 322 323// ListByClusterPreparer prepares the ListByCluster request. 324func (client AttachedDatabaseConfigurationsClient) ListByClusterPreparer(ctx context.Context, resourceGroupName string, clusterName string) (*http.Request, error) { 325 pathParameters := map[string]interface{}{ 326 "clusterName": autorest.Encode("path", clusterName), 327 "resourceGroupName": autorest.Encode("path", resourceGroupName), 328 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 329 } 330 331 const APIVersion = "2019-09-07" 332 queryParameters := map[string]interface{}{ 333 "api-version": APIVersion, 334 } 335 336 preparer := autorest.CreatePreparer( 337 autorest.AsGet(), 338 autorest.WithBaseURL(client.BaseURI), 339 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/attachedDatabaseConfigurations", pathParameters), 340 autorest.WithQueryParameters(queryParameters)) 341 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 342} 343 344// ListByClusterSender sends the ListByCluster request. The method will close the 345// http.Response Body if it receives an error. 346func (client AttachedDatabaseConfigurationsClient) ListByClusterSender(req *http.Request) (*http.Response, error) { 347 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 348} 349 350// ListByClusterResponder handles the response to the ListByCluster request. The method always 351// closes the http.Response Body. 352func (client AttachedDatabaseConfigurationsClient) ListByClusterResponder(resp *http.Response) (result AttachedDatabaseConfigurationListResult, err error) { 353 err = autorest.Respond( 354 resp, 355 azure.WithErrorUnlessStatusCode(http.StatusOK), 356 autorest.ByUnmarshallingJSON(&result), 357 autorest.ByClosing()) 358 result.Response = autorest.Response{Response: resp} 359 return 360} 361