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// SQLPoolTransparentDataEncryptionsClient is the azure Synapse Analytics Management Client
19type SQLPoolTransparentDataEncryptionsClient struct {
20	BaseClient
21}
22
23// NewSQLPoolTransparentDataEncryptionsClient creates an instance of the SQLPoolTransparentDataEncryptionsClient
24// client.
25func NewSQLPoolTransparentDataEncryptionsClient(subscriptionID string) SQLPoolTransparentDataEncryptionsClient {
26	return NewSQLPoolTransparentDataEncryptionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewSQLPoolTransparentDataEncryptionsClientWithBaseURI creates an instance of the
30// SQLPoolTransparentDataEncryptionsClient client using a custom endpoint.  Use this when interacting with an Azure
31// cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewSQLPoolTransparentDataEncryptionsClientWithBaseURI(baseURI string, subscriptionID string) SQLPoolTransparentDataEncryptionsClient {
33	return SQLPoolTransparentDataEncryptionsClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate creates or updates a Sql pool's transparent data encryption configuration.
37// Parameters:
38// resourceGroupName - the name of the resource group. The name is case insensitive.
39// workspaceName - the name of the workspace
40// SQLPoolName - SQL pool name
41// parameters - the required parameters for creating or updating transparent data encryption.
42func (client SQLPoolTransparentDataEncryptionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, parameters TransparentDataEncryption) (result TransparentDataEncryption, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolTransparentDataEncryptionsClient.CreateOrUpdate")
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: client.SubscriptionID,
55			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
56		{TargetValue: resourceGroupName,
57			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
58				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
59				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
60		return result, validation.NewError("synapse.SQLPoolTransparentDataEncryptionsClient", "CreateOrUpdate", err.Error())
61	}
62
63	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, parameters)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "CreateOrUpdate", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.CreateOrUpdateSender(req)
70	if err != nil {
71		result.Response = autorest.Response{Response: resp}
72		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "CreateOrUpdate", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.CreateOrUpdateResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "CreateOrUpdate", resp, "Failure responding to request")
79		return
80	}
81
82	return
83}
84
85// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
86func (client SQLPoolTransparentDataEncryptionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, parameters TransparentDataEncryption) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
89		"sqlPoolName":                   autorest.Encode("path", SQLPoolName),
90		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
91		"transparentDataEncryptionName": autorest.Encode("path", "current"),
92		"workspaceName":                 autorest.Encode("path", workspaceName),
93	}
94
95	const APIVersion = "2020-12-01"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	parameters.Location = nil
101	preparer := autorest.CreatePreparer(
102		autorest.AsContentType("application/json; charset=utf-8"),
103		autorest.AsPut(),
104		autorest.WithBaseURL(client.BaseURI),
105		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/transparentDataEncryption/{transparentDataEncryptionName}", pathParameters),
106		autorest.WithJSON(parameters),
107		autorest.WithQueryParameters(queryParameters))
108	return preparer.Prepare((&http.Request{}).WithContext(ctx))
109}
110
111// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
112// http.Response Body if it receives an error.
113func (client SQLPoolTransparentDataEncryptionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
114	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
115}
116
117// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
118// closes the http.Response Body.
119func (client SQLPoolTransparentDataEncryptionsClient) CreateOrUpdateResponder(resp *http.Response) (result TransparentDataEncryption, err error) {
120	err = autorest.Respond(
121		resp,
122		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// Get get a SQL pool's transparent data encryption configuration.
130// Parameters:
131// resourceGroupName - the name of the resource group. The name is case insensitive.
132// workspaceName - the name of the workspace
133// SQLPoolName - SQL pool name
134func (client SQLPoolTransparentDataEncryptionsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result TransparentDataEncryption, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolTransparentDataEncryptionsClient.Get")
137		defer func() {
138			sc := -1
139			if result.Response.Response != nil {
140				sc = result.Response.Response.StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	if err := validation.Validate([]validation.Validation{
146		{TargetValue: client.SubscriptionID,
147			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
148		{TargetValue: resourceGroupName,
149			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
150				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
151				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
152		return result, validation.NewError("synapse.SQLPoolTransparentDataEncryptionsClient", "Get", err.Error())
153	}
154
155	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "Get", nil, "Failure preparing request")
158		return
159	}
160
161	resp, err := client.GetSender(req)
162	if err != nil {
163		result.Response = autorest.Response{Response: resp}
164		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "Get", resp, "Failure sending request")
165		return
166	}
167
168	result, err = client.GetResponder(resp)
169	if err != nil {
170		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "Get", resp, "Failure responding to request")
171		return
172	}
173
174	return
175}
176
177// GetPreparer prepares the Get request.
178func (client SQLPoolTransparentDataEncryptionsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (*http.Request, error) {
179	pathParameters := map[string]interface{}{
180		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
181		"sqlPoolName":                   autorest.Encode("path", SQLPoolName),
182		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
183		"transparentDataEncryptionName": autorest.Encode("path", "current"),
184		"workspaceName":                 autorest.Encode("path", workspaceName),
185	}
186
187	const APIVersion = "2020-12-01"
188	queryParameters := map[string]interface{}{
189		"api-version": APIVersion,
190	}
191
192	preparer := autorest.CreatePreparer(
193		autorest.AsGet(),
194		autorest.WithBaseURL(client.BaseURI),
195		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/transparentDataEncryption/{transparentDataEncryptionName}", pathParameters),
196		autorest.WithQueryParameters(queryParameters))
197	return preparer.Prepare((&http.Request{}).WithContext(ctx))
198}
199
200// GetSender sends the Get request. The method will close the
201// http.Response Body if it receives an error.
202func (client SQLPoolTransparentDataEncryptionsClient) GetSender(req *http.Request) (*http.Response, error) {
203	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
204}
205
206// GetResponder handles the response to the Get request. The method always
207// closes the http.Response Body.
208func (client SQLPoolTransparentDataEncryptionsClient) GetResponder(resp *http.Response) (result TransparentDataEncryption, err error) {
209	err = autorest.Respond(
210		resp,
211		azure.WithErrorUnlessStatusCode(http.StatusOK),
212		autorest.ByUnmarshallingJSON(&result),
213		autorest.ByClosing())
214	result.Response = autorest.Response{Response: resp}
215	return
216}
217
218// List get list of SQL pool's transparent data encryption configurations.
219// Parameters:
220// resourceGroupName - the name of the resource group. The name is case insensitive.
221// workspaceName - the name of the workspace
222// SQLPoolName - SQL pool name
223func (client SQLPoolTransparentDataEncryptionsClient) List(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result TransparentDataEncryptionListResultPage, err error) {
224	if tracing.IsEnabled() {
225		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolTransparentDataEncryptionsClient.List")
226		defer func() {
227			sc := -1
228			if result.tdelr.Response.Response != nil {
229				sc = result.tdelr.Response.Response.StatusCode
230			}
231			tracing.EndSpan(ctx, sc, err)
232		}()
233	}
234	if err := validation.Validate([]validation.Validation{
235		{TargetValue: client.SubscriptionID,
236			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
237		{TargetValue: resourceGroupName,
238			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
239				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
240				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
241		return result, validation.NewError("synapse.SQLPoolTransparentDataEncryptionsClient", "List", err.Error())
242	}
243
244	result.fn = client.listNextResults
245	req, err := client.ListPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName)
246	if err != nil {
247		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "List", nil, "Failure preparing request")
248		return
249	}
250
251	resp, err := client.ListSender(req)
252	if err != nil {
253		result.tdelr.Response = autorest.Response{Response: resp}
254		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "List", resp, "Failure sending request")
255		return
256	}
257
258	result.tdelr, err = client.ListResponder(resp)
259	if err != nil {
260		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "List", resp, "Failure responding to request")
261		return
262	}
263	if result.tdelr.hasNextLink() && result.tdelr.IsEmpty() {
264		err = result.NextWithContext(ctx)
265		return
266	}
267
268	return
269}
270
271// ListPreparer prepares the List request.
272func (client SQLPoolTransparentDataEncryptionsClient) ListPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (*http.Request, error) {
273	pathParameters := map[string]interface{}{
274		"resourceGroupName": autorest.Encode("path", resourceGroupName),
275		"sqlPoolName":       autorest.Encode("path", SQLPoolName),
276		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
277		"workspaceName":     autorest.Encode("path", workspaceName),
278	}
279
280	const APIVersion = "2020-12-01"
281	queryParameters := map[string]interface{}{
282		"api-version": APIVersion,
283	}
284
285	preparer := autorest.CreatePreparer(
286		autorest.AsGet(),
287		autorest.WithBaseURL(client.BaseURI),
288		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/transparentDataEncryption", pathParameters),
289		autorest.WithQueryParameters(queryParameters))
290	return preparer.Prepare((&http.Request{}).WithContext(ctx))
291}
292
293// ListSender sends the List request. The method will close the
294// http.Response Body if it receives an error.
295func (client SQLPoolTransparentDataEncryptionsClient) ListSender(req *http.Request) (*http.Response, error) {
296	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
297}
298
299// ListResponder handles the response to the List request. The method always
300// closes the http.Response Body.
301func (client SQLPoolTransparentDataEncryptionsClient) ListResponder(resp *http.Response) (result TransparentDataEncryptionListResult, err error) {
302	err = autorest.Respond(
303		resp,
304		azure.WithErrorUnlessStatusCode(http.StatusOK),
305		autorest.ByUnmarshallingJSON(&result),
306		autorest.ByClosing())
307	result.Response = autorest.Response{Response: resp}
308	return
309}
310
311// listNextResults retrieves the next set of results, if any.
312func (client SQLPoolTransparentDataEncryptionsClient) listNextResults(ctx context.Context, lastResults TransparentDataEncryptionListResult) (result TransparentDataEncryptionListResult, err error) {
313	req, err := lastResults.transparentDataEncryptionListResultPreparer(ctx)
314	if err != nil {
315		return result, autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "listNextResults", nil, "Failure preparing next results request")
316	}
317	if req == nil {
318		return
319	}
320	resp, err := client.ListSender(req)
321	if err != nil {
322		result.Response = autorest.Response{Response: resp}
323		return result, autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "listNextResults", resp, "Failure sending next results request")
324	}
325	result, err = client.ListResponder(resp)
326	if err != nil {
327		err = autorest.NewErrorWithError(err, "synapse.SQLPoolTransparentDataEncryptionsClient", "listNextResults", resp, "Failure responding to next results request")
328	}
329	return
330}
331
332// ListComplete enumerates all values, automatically crossing page boundaries as required.
333func (client SQLPoolTransparentDataEncryptionsClient) ListComplete(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result TransparentDataEncryptionListResultIterator, err error) {
334	if tracing.IsEnabled() {
335		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolTransparentDataEncryptionsClient.List")
336		defer func() {
337			sc := -1
338			if result.Response().Response.Response != nil {
339				sc = result.page.Response().Response.Response.StatusCode
340			}
341			tracing.EndSpan(ctx, sc, err)
342		}()
343	}
344	result.page, err = client.List(ctx, resourceGroupName, workspaceName, SQLPoolName)
345	return
346}
347