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