1package synapse
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// AzureADOnlyAuthenticationsClient is the azure Synapse Analytics Management Client
19type AzureADOnlyAuthenticationsClient struct {
20	BaseClient
21}
22
23// NewAzureADOnlyAuthenticationsClient creates an instance of the AzureADOnlyAuthenticationsClient client.
24func NewAzureADOnlyAuthenticationsClient(subscriptionID string) AzureADOnlyAuthenticationsClient {
25	return NewAzureADOnlyAuthenticationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAzureADOnlyAuthenticationsClientWithBaseURI creates an instance of the AzureADOnlyAuthenticationsClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewAzureADOnlyAuthenticationsClientWithBaseURI(baseURI string, subscriptionID string) AzureADOnlyAuthenticationsClient {
32	return AzureADOnlyAuthenticationsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// Create create or Update a Azure Active Directory Only Authentication property for the workspace
36// Parameters:
37// resourceGroupName - the name of the resource group. The name is case insensitive.
38// workspaceName - the name of the workspace
39// azureADOnlyAuthenticationInfo - azure Active Directory Property
40func (client AzureADOnlyAuthenticationsClient) Create(ctx context.Context, resourceGroupName string, workspaceName string, azureADOnlyAuthenticationInfo AzureADOnlyAuthentication) (result AzureADOnlyAuthenticationsCreateFuture, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/AzureADOnlyAuthenticationsClient.Create")
43		defer func() {
44			sc := -1
45			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
46				sc = result.FutureAPI.Response().StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	if err := validation.Validate([]validation.Validation{
52		{TargetValue: client.SubscriptionID,
53			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
54		{TargetValue: resourceGroupName,
55			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
57		{TargetValue: azureADOnlyAuthenticationInfo,
58			Constraints: []validation.Constraint{{Target: "azureADOnlyAuthenticationInfo.AzureADOnlyAuthenticationProperties", Name: validation.Null, Rule: false,
59				Chain: []validation.Constraint{{Target: "azureADOnlyAuthenticationInfo.AzureADOnlyAuthenticationProperties.AzureADOnlyAuthentication", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
60		return result, validation.NewError("synapse.AzureADOnlyAuthenticationsClient", "Create", err.Error())
61	}
62
63	req, err := client.CreatePreparer(ctx, resourceGroupName, workspaceName, azureADOnlyAuthenticationInfo)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "Create", nil, "Failure preparing request")
66		return
67	}
68
69	result, err = client.CreateSender(req)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "Create", nil, "Failure sending request")
72		return
73	}
74
75	return
76}
77
78// CreatePreparer prepares the Create request.
79func (client AzureADOnlyAuthenticationsClient) CreatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, azureADOnlyAuthenticationInfo AzureADOnlyAuthentication) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"azureADOnlyAuthenticationName": autorest.Encode("path", "default"),
82		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
83		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
84		"workspaceName":                 autorest.Encode("path", workspaceName),
85	}
86
87	const APIVersion = "2021-06-01-preview"
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.Synapse/workspaces/{workspaceName}/azureADOnlyAuthentications/{azureADOnlyAuthenticationName}", pathParameters),
97		autorest.WithJSON(azureADOnlyAuthenticationInfo),
98		autorest.WithQueryParameters(queryParameters))
99	return preparer.Prepare((&http.Request{}).WithContext(ctx))
100}
101
102// CreateSender sends the Create request. The method will close the
103// http.Response Body if it receives an error.
104func (client AzureADOnlyAuthenticationsClient) CreateSender(req *http.Request) (future AzureADOnlyAuthenticationsCreateFuture, 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// CreateResponder handles the response to the Create request. The method always
118// closes the http.Response Body.
119func (client AzureADOnlyAuthenticationsClient) CreateResponder(resp *http.Response) (result AzureADOnlyAuthentication, 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// Get gets a Azure Active Directory Only Authentication property for the workspace
130// Parameters:
131// resourceGroupName - the name of the resource group. The name is case insensitive.
132// workspaceName - the name of the workspace
133func (client AzureADOnlyAuthenticationsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string) (result AzureADOnlyAuthentication, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/AzureADOnlyAuthenticationsClient.Get")
136		defer func() {
137			sc := -1
138			if result.Response.Response != nil {
139				sc = result.Response.Response.StatusCode
140			}
141			tracing.EndSpan(ctx, sc, err)
142		}()
143	}
144	if err := validation.Validate([]validation.Validation{
145		{TargetValue: client.SubscriptionID,
146			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
147		{TargetValue: resourceGroupName,
148			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
149				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
150		return result, validation.NewError("synapse.AzureADOnlyAuthenticationsClient", "Get", err.Error())
151	}
152
153	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "Get", nil, "Failure preparing request")
156		return
157	}
158
159	resp, err := client.GetSender(req)
160	if err != nil {
161		result.Response = autorest.Response{Response: resp}
162		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "Get", resp, "Failure sending request")
163		return
164	}
165
166	result, err = client.GetResponder(resp)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "Get", resp, "Failure responding to request")
169		return
170	}
171
172	return
173}
174
175// GetPreparer prepares the Get request.
176func (client AzureADOnlyAuthenticationsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"azureADOnlyAuthenticationName": autorest.Encode("path", "default"),
179		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
180		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
181		"workspaceName":                 autorest.Encode("path", workspaceName),
182	}
183
184	const APIVersion = "2021-06-01-preview"
185	queryParameters := map[string]interface{}{
186		"api-version": APIVersion,
187	}
188
189	preparer := autorest.CreatePreparer(
190		autorest.AsGet(),
191		autorest.WithBaseURL(client.BaseURI),
192		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/azureADOnlyAuthentications/{azureADOnlyAuthenticationName}", pathParameters),
193		autorest.WithQueryParameters(queryParameters))
194	return preparer.Prepare((&http.Request{}).WithContext(ctx))
195}
196
197// GetSender sends the Get request. The method will close the
198// http.Response Body if it receives an error.
199func (client AzureADOnlyAuthenticationsClient) GetSender(req *http.Request) (*http.Response, error) {
200	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
201}
202
203// GetResponder handles the response to the Get request. The method always
204// closes the http.Response Body.
205func (client AzureADOnlyAuthenticationsClient) GetResponder(resp *http.Response) (result AzureADOnlyAuthentication, err error) {
206	err = autorest.Respond(
207		resp,
208		azure.WithErrorUnlessStatusCode(http.StatusOK),
209		autorest.ByUnmarshallingJSON(&result),
210		autorest.ByClosing())
211	result.Response = autorest.Response{Response: resp}
212	return
213}
214
215// List gets a list of Azure Active Directory Only Authentication properties for a workspace
216// Parameters:
217// resourceGroupName - the name of the resource group. The name is case insensitive.
218// workspaceName - the name of the workspace
219func (client AzureADOnlyAuthenticationsClient) List(ctx context.Context, resourceGroupName string, workspaceName string) (result AzureADOnlyAuthenticationListResultPage, err error) {
220	if tracing.IsEnabled() {
221		ctx = tracing.StartSpan(ctx, fqdn+"/AzureADOnlyAuthenticationsClient.List")
222		defer func() {
223			sc := -1
224			if result.aaoalr.Response.Response != nil {
225				sc = result.aaoalr.Response.Response.StatusCode
226			}
227			tracing.EndSpan(ctx, sc, err)
228		}()
229	}
230	if err := validation.Validate([]validation.Validation{
231		{TargetValue: client.SubscriptionID,
232			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
233		{TargetValue: resourceGroupName,
234			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
235				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
236		return result, validation.NewError("synapse.AzureADOnlyAuthenticationsClient", "List", err.Error())
237	}
238
239	result.fn = client.listNextResults
240	req, err := client.ListPreparer(ctx, resourceGroupName, workspaceName)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "List", nil, "Failure preparing request")
243		return
244	}
245
246	resp, err := client.ListSender(req)
247	if err != nil {
248		result.aaoalr.Response = autorest.Response{Response: resp}
249		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "List", resp, "Failure sending request")
250		return
251	}
252
253	result.aaoalr, err = client.ListResponder(resp)
254	if err != nil {
255		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "List", resp, "Failure responding to request")
256		return
257	}
258	if result.aaoalr.hasNextLink() && result.aaoalr.IsEmpty() {
259		err = result.NextWithContext(ctx)
260		return
261	}
262
263	return
264}
265
266// ListPreparer prepares the List request.
267func (client AzureADOnlyAuthenticationsClient) ListPreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) {
268	pathParameters := map[string]interface{}{
269		"resourceGroupName": autorest.Encode("path", resourceGroupName),
270		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
271		"workspaceName":     autorest.Encode("path", workspaceName),
272	}
273
274	const APIVersion = "2021-06-01-preview"
275	queryParameters := map[string]interface{}{
276		"api-version": APIVersion,
277	}
278
279	preparer := autorest.CreatePreparer(
280		autorest.AsGet(),
281		autorest.WithBaseURL(client.BaseURI),
282		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/azureADOnlyAuthentications", pathParameters),
283		autorest.WithQueryParameters(queryParameters))
284	return preparer.Prepare((&http.Request{}).WithContext(ctx))
285}
286
287// ListSender sends the List request. The method will close the
288// http.Response Body if it receives an error.
289func (client AzureADOnlyAuthenticationsClient) ListSender(req *http.Request) (*http.Response, error) {
290	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
291}
292
293// ListResponder handles the response to the List request. The method always
294// closes the http.Response Body.
295func (client AzureADOnlyAuthenticationsClient) ListResponder(resp *http.Response) (result AzureADOnlyAuthenticationListResult, err error) {
296	err = autorest.Respond(
297		resp,
298		azure.WithErrorUnlessStatusCode(http.StatusOK),
299		autorest.ByUnmarshallingJSON(&result),
300		autorest.ByClosing())
301	result.Response = autorest.Response{Response: resp}
302	return
303}
304
305// listNextResults retrieves the next set of results, if any.
306func (client AzureADOnlyAuthenticationsClient) listNextResults(ctx context.Context, lastResults AzureADOnlyAuthenticationListResult) (result AzureADOnlyAuthenticationListResult, err error) {
307	req, err := lastResults.azureADOnlyAuthenticationListResultPreparer(ctx)
308	if err != nil {
309		return result, autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "listNextResults", nil, "Failure preparing next results request")
310	}
311	if req == nil {
312		return
313	}
314	resp, err := client.ListSender(req)
315	if err != nil {
316		result.Response = autorest.Response{Response: resp}
317		return result, autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "listNextResults", resp, "Failure sending next results request")
318	}
319	result, err = client.ListResponder(resp)
320	if err != nil {
321		err = autorest.NewErrorWithError(err, "synapse.AzureADOnlyAuthenticationsClient", "listNextResults", resp, "Failure responding to next results request")
322	}
323	return
324}
325
326// ListComplete enumerates all values, automatically crossing page boundaries as required.
327func (client AzureADOnlyAuthenticationsClient) ListComplete(ctx context.Context, resourceGroupName string, workspaceName string) (result AzureADOnlyAuthenticationListResultIterator, err error) {
328	if tracing.IsEnabled() {
329		ctx = tracing.StartSpan(ctx, fqdn+"/AzureADOnlyAuthenticationsClient.List")
330		defer func() {
331			sc := -1
332			if result.Response().Response.Response != nil {
333				sc = result.page.Response().Response.Response.StatusCode
334			}
335			tracing.EndSpan(ctx, sc, err)
336		}()
337	}
338	result.page, err = client.List(ctx, resourceGroupName, workspaceName)
339	return
340}
341