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// ClusterPrincipalAssignmentsClient is the the Azure Kusto management API provides a RESTful set of web services that 30// interact with Azure Kusto services to manage your clusters and databases. The API enables you to create, update, and 31// delete clusters and databases. 32type ClusterPrincipalAssignmentsClient struct { 33 BaseClient 34} 35 36// NewClusterPrincipalAssignmentsClient creates an instance of the ClusterPrincipalAssignmentsClient client. 37func NewClusterPrincipalAssignmentsClient(subscriptionID string) ClusterPrincipalAssignmentsClient { 38 return NewClusterPrincipalAssignmentsClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewClusterPrincipalAssignmentsClientWithBaseURI creates an instance of the ClusterPrincipalAssignmentsClient client 42// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 43// clouds, Azure stack). 44func NewClusterPrincipalAssignmentsClientWithBaseURI(baseURI string, subscriptionID string) ClusterPrincipalAssignmentsClient { 45 return ClusterPrincipalAssignmentsClient{NewWithBaseURI(baseURI, subscriptionID)} 46} 47 48// CheckNameAvailability checks that the principal assignment name is valid and is not already in use. 49// Parameters: 50// resourceGroupName - the name of the resource group containing the Kusto cluster. 51// clusterName - the name of the Kusto cluster. 52// principalAssignmentName - the name of the principal assignment. 53func (client ClusterPrincipalAssignmentsClient) CheckNameAvailability(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName ClusterPrincipalAssignmentCheckNameRequest) (result CheckNameResult, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/ClusterPrincipalAssignmentsClient.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: principalAssignmentName, 66 Constraints: []validation.Constraint{{Target: "principalAssignmentName.Name", Name: validation.Null, Rule: true, Chain: nil}, 67 {Target: "principalAssignmentName.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 68 return result, validation.NewError("kusto.ClusterPrincipalAssignmentsClient", "CheckNameAvailability", err.Error()) 69 } 70 71 req, err := client.CheckNameAvailabilityPreparer(ctx, resourceGroupName, clusterName, principalAssignmentName) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "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.ClusterPrincipalAssignmentsClient", "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.ClusterPrincipalAssignmentsClient", "CheckNameAvailability", resp, "Failure responding to request") 87 return 88 } 89 90 return 91} 92 93// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request. 94func (client ClusterPrincipalAssignmentsClient) CheckNameAvailabilityPreparer(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName ClusterPrincipalAssignmentCheckNameRequest) (*http.Request, error) { 95 pathParameters := map[string]interface{}{ 96 "clusterName": autorest.Encode("path", clusterName), 97 "resourceGroupName": autorest.Encode("path", resourceGroupName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 } 100 101 const APIVersion = "2020-09-18" 102 queryParameters := map[string]interface{}{ 103 "api-version": APIVersion, 104 } 105 106 preparer := autorest.CreatePreparer( 107 autorest.AsContentType("application/json; charset=utf-8"), 108 autorest.AsPost(), 109 autorest.WithBaseURL(client.BaseURI), 110 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/checkPrincipalAssignmentNameAvailability", pathParameters), 111 autorest.WithJSON(principalAssignmentName), 112 autorest.WithQueryParameters(queryParameters)) 113 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 114} 115 116// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the 117// http.Response Body if it receives an error. 118func (client ClusterPrincipalAssignmentsClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) { 119 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 120} 121 122// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always 123// closes the http.Response Body. 124func (client ClusterPrincipalAssignmentsClient) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameResult, err error) { 125 err = autorest.Respond( 126 resp, 127 azure.WithErrorUnlessStatusCode(http.StatusOK), 128 autorest.ByUnmarshallingJSON(&result), 129 autorest.ByClosing()) 130 result.Response = autorest.Response{Response: resp} 131 return 132} 133 134// CreateOrUpdate create a Kusto cluster principalAssignment. 135// Parameters: 136// resourceGroupName - the name of the resource group containing the Kusto cluster. 137// clusterName - the name of the Kusto cluster. 138// principalAssignmentName - the name of the Kusto principalAssignment. 139// parameters - the Kusto cluster principalAssignment's parameters supplied for the operation. 140func (client ClusterPrincipalAssignmentsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName string, parameters ClusterPrincipalAssignment) (result ClusterPrincipalAssignmentsCreateOrUpdateFuture, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/ClusterPrincipalAssignmentsClient.CreateOrUpdate") 143 defer func() { 144 sc := -1 145 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 146 sc = result.FutureAPI.Response().StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 if err := validation.Validate([]validation.Validation{ 152 {TargetValue: parameters, 153 Constraints: []validation.Constraint{{Target: "parameters.ClusterPrincipalProperties", Name: validation.Null, Rule: false, 154 Chain: []validation.Constraint{{Target: "parameters.ClusterPrincipalProperties.PrincipalID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 155 return result, validation.NewError("kusto.ClusterPrincipalAssignmentsClient", "CreateOrUpdate", err.Error()) 156 } 157 158 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, clusterName, principalAssignmentName, parameters) 159 if err != nil { 160 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "CreateOrUpdate", nil, "Failure preparing request") 161 return 162 } 163 164 result, err = client.CreateOrUpdateSender(req) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "CreateOrUpdate", nil, "Failure sending request") 167 return 168 } 169 170 return 171} 172 173// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 174func (client ClusterPrincipalAssignmentsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName string, parameters ClusterPrincipalAssignment) (*http.Request, error) { 175 pathParameters := map[string]interface{}{ 176 "clusterName": autorest.Encode("path", clusterName), 177 "principalAssignmentName": autorest.Encode("path", principalAssignmentName), 178 "resourceGroupName": autorest.Encode("path", resourceGroupName), 179 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 180 } 181 182 const APIVersion = "2020-09-18" 183 queryParameters := map[string]interface{}{ 184 "api-version": APIVersion, 185 } 186 187 preparer := autorest.CreatePreparer( 188 autorest.AsContentType("application/json; charset=utf-8"), 189 autorest.AsPut(), 190 autorest.WithBaseURL(client.BaseURI), 191 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/principalAssignments/{principalAssignmentName}", pathParameters), 192 autorest.WithJSON(parameters), 193 autorest.WithQueryParameters(queryParameters)) 194 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 195} 196 197// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 198// http.Response Body if it receives an error. 199func (client ClusterPrincipalAssignmentsClient) CreateOrUpdateSender(req *http.Request) (future ClusterPrincipalAssignmentsCreateOrUpdateFuture, err error) { 200 var resp *http.Response 201 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 202 if err != nil { 203 return 204 } 205 var azf azure.Future 206 azf, err = azure.NewFutureFromResponse(resp) 207 future.FutureAPI = &azf 208 future.Result = func(client ClusterPrincipalAssignmentsClient) (cpa ClusterPrincipalAssignment, err error) { 209 var done bool 210 done, err = future.DoneWithContext(context.Background(), client) 211 if err != nil { 212 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 213 return 214 } 215 if !done { 216 err = azure.NewAsyncOpIncompleteError("kusto.ClusterPrincipalAssignmentsCreateOrUpdateFuture") 217 return 218 } 219 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 220 cpa.Response.Response, err = future.GetResult(sender) 221 if cpa.Response.Response == nil && err == nil { 222 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsCreateOrUpdateFuture", "Result", nil, "received nil response and error") 223 } 224 if err == nil && cpa.Response.Response.StatusCode != http.StatusNoContent { 225 cpa, err = client.CreateOrUpdateResponder(cpa.Response.Response) 226 if err != nil { 227 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsCreateOrUpdateFuture", "Result", cpa.Response.Response, "Failure responding to request") 228 } 229 } 230 return 231 } 232 return 233} 234 235// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 236// closes the http.Response Body. 237func (client ClusterPrincipalAssignmentsClient) CreateOrUpdateResponder(resp *http.Response) (result ClusterPrincipalAssignment, err error) { 238 err = autorest.Respond( 239 resp, 240 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 241 autorest.ByUnmarshallingJSON(&result), 242 autorest.ByClosing()) 243 result.Response = autorest.Response{Response: resp} 244 return 245} 246 247// Delete deletes a Kusto cluster principalAssignment. 248// Parameters: 249// resourceGroupName - the name of the resource group containing the Kusto cluster. 250// clusterName - the name of the Kusto cluster. 251// principalAssignmentName - the name of the Kusto principalAssignment. 252func (client ClusterPrincipalAssignmentsClient) Delete(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName string) (result ClusterPrincipalAssignmentsDeleteFuture, err error) { 253 if tracing.IsEnabled() { 254 ctx = tracing.StartSpan(ctx, fqdn+"/ClusterPrincipalAssignmentsClient.Delete") 255 defer func() { 256 sc := -1 257 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 258 sc = result.FutureAPI.Response().StatusCode 259 } 260 tracing.EndSpan(ctx, sc, err) 261 }() 262 } 263 req, err := client.DeletePreparer(ctx, resourceGroupName, clusterName, principalAssignmentName) 264 if err != nil { 265 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "Delete", nil, "Failure preparing request") 266 return 267 } 268 269 result, err = client.DeleteSender(req) 270 if err != nil { 271 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "Delete", nil, "Failure sending request") 272 return 273 } 274 275 return 276} 277 278// DeletePreparer prepares the Delete request. 279func (client ClusterPrincipalAssignmentsClient) DeletePreparer(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName string) (*http.Request, error) { 280 pathParameters := map[string]interface{}{ 281 "clusterName": autorest.Encode("path", clusterName), 282 "principalAssignmentName": autorest.Encode("path", principalAssignmentName), 283 "resourceGroupName": autorest.Encode("path", resourceGroupName), 284 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 285 } 286 287 const APIVersion = "2020-09-18" 288 queryParameters := map[string]interface{}{ 289 "api-version": APIVersion, 290 } 291 292 preparer := autorest.CreatePreparer( 293 autorest.AsDelete(), 294 autorest.WithBaseURL(client.BaseURI), 295 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/principalAssignments/{principalAssignmentName}", pathParameters), 296 autorest.WithQueryParameters(queryParameters)) 297 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 298} 299 300// DeleteSender sends the Delete request. The method will close the 301// http.Response Body if it receives an error. 302func (client ClusterPrincipalAssignmentsClient) DeleteSender(req *http.Request) (future ClusterPrincipalAssignmentsDeleteFuture, err error) { 303 var resp *http.Response 304 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 305 if err != nil { 306 return 307 } 308 var azf azure.Future 309 azf, err = azure.NewFutureFromResponse(resp) 310 future.FutureAPI = &azf 311 future.Result = func(client ClusterPrincipalAssignmentsClient) (ar autorest.Response, err error) { 312 var done bool 313 done, err = future.DoneWithContext(context.Background(), client) 314 if err != nil { 315 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsDeleteFuture", "Result", future.Response(), "Polling failure") 316 return 317 } 318 if !done { 319 err = azure.NewAsyncOpIncompleteError("kusto.ClusterPrincipalAssignmentsDeleteFuture") 320 return 321 } 322 ar.Response = future.Response() 323 return 324 } 325 return 326} 327 328// DeleteResponder handles the response to the Delete request. The method always 329// closes the http.Response Body. 330func (client ClusterPrincipalAssignmentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 331 err = autorest.Respond( 332 resp, 333 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 334 autorest.ByClosing()) 335 result.Response = resp 336 return 337} 338 339// Get gets a Kusto cluster principalAssignment. 340// Parameters: 341// resourceGroupName - the name of the resource group containing the Kusto cluster. 342// clusterName - the name of the Kusto cluster. 343// principalAssignmentName - the name of the Kusto principalAssignment. 344func (client ClusterPrincipalAssignmentsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName string) (result ClusterPrincipalAssignment, err error) { 345 if tracing.IsEnabled() { 346 ctx = tracing.StartSpan(ctx, fqdn+"/ClusterPrincipalAssignmentsClient.Get") 347 defer func() { 348 sc := -1 349 if result.Response.Response != nil { 350 sc = result.Response.Response.StatusCode 351 } 352 tracing.EndSpan(ctx, sc, err) 353 }() 354 } 355 req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, principalAssignmentName) 356 if err != nil { 357 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "Get", nil, "Failure preparing request") 358 return 359 } 360 361 resp, err := client.GetSender(req) 362 if err != nil { 363 result.Response = autorest.Response{Response: resp} 364 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "Get", resp, "Failure sending request") 365 return 366 } 367 368 result, err = client.GetResponder(resp) 369 if err != nil { 370 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "Get", resp, "Failure responding to request") 371 return 372 } 373 374 return 375} 376 377// GetPreparer prepares the Get request. 378func (client ClusterPrincipalAssignmentsClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, principalAssignmentName string) (*http.Request, error) { 379 pathParameters := map[string]interface{}{ 380 "clusterName": autorest.Encode("path", clusterName), 381 "principalAssignmentName": autorest.Encode("path", principalAssignmentName), 382 "resourceGroupName": autorest.Encode("path", resourceGroupName), 383 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 384 } 385 386 const APIVersion = "2020-09-18" 387 queryParameters := map[string]interface{}{ 388 "api-version": APIVersion, 389 } 390 391 preparer := autorest.CreatePreparer( 392 autorest.AsGet(), 393 autorest.WithBaseURL(client.BaseURI), 394 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/principalAssignments/{principalAssignmentName}", pathParameters), 395 autorest.WithQueryParameters(queryParameters)) 396 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 397} 398 399// GetSender sends the Get request. The method will close the 400// http.Response Body if it receives an error. 401func (client ClusterPrincipalAssignmentsClient) GetSender(req *http.Request) (*http.Response, error) { 402 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 403} 404 405// GetResponder handles the response to the Get request. The method always 406// closes the http.Response Body. 407func (client ClusterPrincipalAssignmentsClient) GetResponder(resp *http.Response) (result ClusterPrincipalAssignment, err error) { 408 err = autorest.Respond( 409 resp, 410 azure.WithErrorUnlessStatusCode(http.StatusOK), 411 autorest.ByUnmarshallingJSON(&result), 412 autorest.ByClosing()) 413 result.Response = autorest.Response{Response: resp} 414 return 415} 416 417// List lists all Kusto cluster principalAssignments. 418// Parameters: 419// resourceGroupName - the name of the resource group containing the Kusto cluster. 420// clusterName - the name of the Kusto cluster. 421func (client ClusterPrincipalAssignmentsClient) List(ctx context.Context, resourceGroupName string, clusterName string) (result ClusterPrincipalAssignmentListResult, err error) { 422 if tracing.IsEnabled() { 423 ctx = tracing.StartSpan(ctx, fqdn+"/ClusterPrincipalAssignmentsClient.List") 424 defer func() { 425 sc := -1 426 if result.Response.Response != nil { 427 sc = result.Response.Response.StatusCode 428 } 429 tracing.EndSpan(ctx, sc, err) 430 }() 431 } 432 req, err := client.ListPreparer(ctx, resourceGroupName, clusterName) 433 if err != nil { 434 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "List", nil, "Failure preparing request") 435 return 436 } 437 438 resp, err := client.ListSender(req) 439 if err != nil { 440 result.Response = autorest.Response{Response: resp} 441 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "List", resp, "Failure sending request") 442 return 443 } 444 445 result, err = client.ListResponder(resp) 446 if err != nil { 447 err = autorest.NewErrorWithError(err, "kusto.ClusterPrincipalAssignmentsClient", "List", resp, "Failure responding to request") 448 return 449 } 450 451 return 452} 453 454// ListPreparer prepares the List request. 455func (client ClusterPrincipalAssignmentsClient) ListPreparer(ctx context.Context, resourceGroupName string, clusterName string) (*http.Request, error) { 456 pathParameters := map[string]interface{}{ 457 "clusterName": autorest.Encode("path", clusterName), 458 "resourceGroupName": autorest.Encode("path", resourceGroupName), 459 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 460 } 461 462 const APIVersion = "2020-09-18" 463 queryParameters := map[string]interface{}{ 464 "api-version": APIVersion, 465 } 466 467 preparer := autorest.CreatePreparer( 468 autorest.AsGet(), 469 autorest.WithBaseURL(client.BaseURI), 470 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/principalAssignments", pathParameters), 471 autorest.WithQueryParameters(queryParameters)) 472 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 473} 474 475// ListSender sends the List request. The method will close the 476// http.Response Body if it receives an error. 477func (client ClusterPrincipalAssignmentsClient) ListSender(req *http.Request) (*http.Response, error) { 478 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 479} 480 481// ListResponder handles the response to the List request. The method always 482// closes the http.Response Body. 483func (client ClusterPrincipalAssignmentsClient) ListResponder(resp *http.Response) (result ClusterPrincipalAssignmentListResult, err error) { 484 err = autorest.Respond( 485 resp, 486 azure.WithErrorUnlessStatusCode(http.StatusOK), 487 autorest.ByUnmarshallingJSON(&result), 488 autorest.ByClosing()) 489 result.Response = autorest.Response{Response: resp} 490 return 491} 492