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