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