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// SQLPoolVulnerabilityAssessmentRuleBaselinesClient is the azure Synapse Analytics Management Client
19type SQLPoolVulnerabilityAssessmentRuleBaselinesClient struct {
20	BaseClient
21}
22
23// NewSQLPoolVulnerabilityAssessmentRuleBaselinesClient creates an instance of the
24// SQLPoolVulnerabilityAssessmentRuleBaselinesClient client.
25func NewSQLPoolVulnerabilityAssessmentRuleBaselinesClient(subscriptionID string) SQLPoolVulnerabilityAssessmentRuleBaselinesClient {
26	return NewSQLPoolVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewSQLPoolVulnerabilityAssessmentRuleBaselinesClientWithBaseURI creates an instance of the
30// SQLPoolVulnerabilityAssessmentRuleBaselinesClient client using a custom endpoint.  Use this when interacting with an
31// Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewSQLPoolVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(baseURI string, subscriptionID string) SQLPoolVulnerabilityAssessmentRuleBaselinesClient {
33	return SQLPoolVulnerabilityAssessmentRuleBaselinesClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate creates or updates a Sql pool's vulnerability assessment rule baseline.
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// ruleID - the vulnerability assessment rule ID.
42// baselineName - the name of the vulnerability assessment rule baseline (default implies a baseline on a Sql
43// pool level rule and master for workspace level rule).
44// parameters - the requested rule baseline resource.
45func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, ruleID string, baselineName VulnerabilityAssessmentPolicyBaselineName, parameters SQLPoolVulnerabilityAssessmentRuleBaseline) (result SQLPoolVulnerabilityAssessmentRuleBaseline, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolVulnerabilityAssessmentRuleBaselinesClient.CreateOrUpdate")
48		defer func() {
49			sc := -1
50			if result.Response.Response != nil {
51				sc = result.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	if err := validation.Validate([]validation.Validation{
57		{TargetValue: client.SubscriptionID,
58			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
59		{TargetValue: resourceGroupName,
60			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
61				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
62				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
63		{TargetValue: parameters,
64			Constraints: []validation.Constraint{{Target: "parameters.SQLPoolVulnerabilityAssessmentRuleBaselineProperties", Name: validation.Null, Rule: false,
65				Chain: []validation.Constraint{{Target: "parameters.SQLPoolVulnerabilityAssessmentRuleBaselineProperties.BaselineResults", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
66		return result, validation.NewError("synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "CreateOrUpdate", err.Error())
67	}
68
69	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, ruleID, baselineName, parameters)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "CreateOrUpdate", nil, "Failure preparing request")
72		return
73	}
74
75	resp, err := client.CreateOrUpdateSender(req)
76	if err != nil {
77		result.Response = autorest.Response{Response: resp}
78		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "CreateOrUpdate", resp, "Failure sending request")
79		return
80	}
81
82	result, err = client.CreateOrUpdateResponder(resp)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "CreateOrUpdate", resp, "Failure responding to request")
85		return
86	}
87
88	return
89}
90
91// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
92func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, ruleID string, baselineName VulnerabilityAssessmentPolicyBaselineName, parameters SQLPoolVulnerabilityAssessmentRuleBaseline) (*http.Request, error) {
93	pathParameters := map[string]interface{}{
94		"baselineName":                autorest.Encode("path", baselineName),
95		"resourceGroupName":           autorest.Encode("path", resourceGroupName),
96		"ruleId":                      autorest.Encode("path", ruleID),
97		"sqlPoolName":                 autorest.Encode("path", SQLPoolName),
98		"subscriptionId":              autorest.Encode("path", client.SubscriptionID),
99		"vulnerabilityAssessmentName": autorest.Encode("path", "default"),
100		"workspaceName":               autorest.Encode("path", workspaceName),
101	}
102
103	const APIVersion = "2020-12-01"
104	queryParameters := map[string]interface{}{
105		"api-version": APIVersion,
106	}
107
108	preparer := autorest.CreatePreparer(
109		autorest.AsContentType("application/json; charset=utf-8"),
110		autorest.AsPut(),
111		autorest.WithBaseURL(client.BaseURI),
112		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", pathParameters),
113		autorest.WithJSON(parameters),
114		autorest.WithQueryParameters(queryParameters))
115	return preparer.Prepare((&http.Request{}).WithContext(ctx))
116}
117
118// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
119// http.Response Body if it receives an error.
120func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
121	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
122}
123
124// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
125// closes the http.Response Body.
126func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdateResponder(resp *http.Response) (result SQLPoolVulnerabilityAssessmentRuleBaseline, err error) {
127	err = autorest.Respond(
128		resp,
129		azure.WithErrorUnlessStatusCode(http.StatusOK),
130		autorest.ByUnmarshallingJSON(&result),
131		autorest.ByClosing())
132	result.Response = autorest.Response{Response: resp}
133	return
134}
135
136// Delete removes the database's vulnerability assessment rule baseline.
137// Parameters:
138// resourceGroupName - the name of the resource group. The name is case insensitive.
139// workspaceName - the name of the workspace
140// SQLPoolName - SQL pool name
141// ruleID - the vulnerability assessment rule ID.
142// baselineName - the name of the vulnerability assessment rule baseline (default implies a baseline on a Sql
143// pool level rule and master for workspace level rule).
144func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, ruleID string, baselineName VulnerabilityAssessmentPolicyBaselineName) (result autorest.Response, err error) {
145	if tracing.IsEnabled() {
146		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolVulnerabilityAssessmentRuleBaselinesClient.Delete")
147		defer func() {
148			sc := -1
149			if result.Response != nil {
150				sc = result.Response.StatusCode
151			}
152			tracing.EndSpan(ctx, sc, err)
153		}()
154	}
155	if err := validation.Validate([]validation.Validation{
156		{TargetValue: client.SubscriptionID,
157			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
158		{TargetValue: resourceGroupName,
159			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
160				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
161				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
162		return result, validation.NewError("synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Delete", err.Error())
163	}
164
165	req, err := client.DeletePreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, ruleID, baselineName)
166	if err != nil {
167		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Delete", nil, "Failure preparing request")
168		return
169	}
170
171	resp, err := client.DeleteSender(req)
172	if err != nil {
173		result.Response = resp
174		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Delete", resp, "Failure sending request")
175		return
176	}
177
178	result, err = client.DeleteResponder(resp)
179	if err != nil {
180		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Delete", resp, "Failure responding to request")
181		return
182	}
183
184	return
185}
186
187// DeletePreparer prepares the Delete request.
188func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) DeletePreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, ruleID string, baselineName VulnerabilityAssessmentPolicyBaselineName) (*http.Request, error) {
189	pathParameters := map[string]interface{}{
190		"baselineName":                autorest.Encode("path", baselineName),
191		"resourceGroupName":           autorest.Encode("path", resourceGroupName),
192		"ruleId":                      autorest.Encode("path", ruleID),
193		"sqlPoolName":                 autorest.Encode("path", SQLPoolName),
194		"subscriptionId":              autorest.Encode("path", client.SubscriptionID),
195		"vulnerabilityAssessmentName": autorest.Encode("path", "default"),
196		"workspaceName":               autorest.Encode("path", workspaceName),
197	}
198
199	const APIVersion = "2020-12-01"
200	queryParameters := map[string]interface{}{
201		"api-version": APIVersion,
202	}
203
204	preparer := autorest.CreatePreparer(
205		autorest.AsDelete(),
206		autorest.WithBaseURL(client.BaseURI),
207		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", pathParameters),
208		autorest.WithQueryParameters(queryParameters))
209	return preparer.Prepare((&http.Request{}).WithContext(ctx))
210}
211
212// DeleteSender sends the Delete request. The method will close the
213// http.Response Body if it receives an error.
214func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) DeleteSender(req *http.Request) (*http.Response, error) {
215	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
216}
217
218// DeleteResponder handles the response to the Delete request. The method always
219// closes the http.Response Body.
220func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
221	err = autorest.Respond(
222		resp,
223		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
224		autorest.ByClosing())
225	result.Response = resp
226	return
227}
228
229// Get gets a SqlPool's vulnerability assessment rule baseline.
230// Parameters:
231// resourceGroupName - the name of the resource group. The name is case insensitive.
232// workspaceName - the name of the workspace
233// SQLPoolName - SQL pool name
234// ruleID - the vulnerability assessment rule ID.
235// baselineName - the name of the vulnerability assessment rule baseline (default implies a baseline on a Sql
236// pool level rule and master for server level rule).
237func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, ruleID string, baselineName VulnerabilityAssessmentPolicyBaselineName) (result SQLPoolVulnerabilityAssessmentRuleBaseline, err error) {
238	if tracing.IsEnabled() {
239		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolVulnerabilityAssessmentRuleBaselinesClient.Get")
240		defer func() {
241			sc := -1
242			if result.Response.Response != nil {
243				sc = result.Response.Response.StatusCode
244			}
245			tracing.EndSpan(ctx, sc, err)
246		}()
247	}
248	if err := validation.Validate([]validation.Validation{
249		{TargetValue: client.SubscriptionID,
250			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
251		{TargetValue: resourceGroupName,
252			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
253				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
254				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
255		return result, validation.NewError("synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Get", err.Error())
256	}
257
258	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, ruleID, baselineName)
259	if err != nil {
260		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Get", nil, "Failure preparing request")
261		return
262	}
263
264	resp, err := client.GetSender(req)
265	if err != nil {
266		result.Response = autorest.Response{Response: resp}
267		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Get", resp, "Failure sending request")
268		return
269	}
270
271	result, err = client.GetResponder(resp)
272	if err != nil {
273		err = autorest.NewErrorWithError(err, "synapse.SQLPoolVulnerabilityAssessmentRuleBaselinesClient", "Get", resp, "Failure responding to request")
274		return
275	}
276
277	return
278}
279
280// GetPreparer prepares the Get request.
281func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, ruleID string, baselineName VulnerabilityAssessmentPolicyBaselineName) (*http.Request, error) {
282	pathParameters := map[string]interface{}{
283		"baselineName":                autorest.Encode("path", baselineName),
284		"resourceGroupName":           autorest.Encode("path", resourceGroupName),
285		"ruleId":                      autorest.Encode("path", ruleID),
286		"sqlPoolName":                 autorest.Encode("path", SQLPoolName),
287		"subscriptionId":              autorest.Encode("path", client.SubscriptionID),
288		"vulnerabilityAssessmentName": autorest.Encode("path", "default"),
289		"workspaceName":               autorest.Encode("path", workspaceName),
290	}
291
292	const APIVersion = "2020-12-01"
293	queryParameters := map[string]interface{}{
294		"api-version": APIVersion,
295	}
296
297	preparer := autorest.CreatePreparer(
298		autorest.AsGet(),
299		autorest.WithBaseURL(client.BaseURI),
300		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", pathParameters),
301		autorest.WithQueryParameters(queryParameters))
302	return preparer.Prepare((&http.Request{}).WithContext(ctx))
303}
304
305// GetSender sends the Get request. The method will close the
306// http.Response Body if it receives an error.
307func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) GetSender(req *http.Request) (*http.Response, error) {
308	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
309}
310
311// GetResponder handles the response to the Get request. The method always
312// closes the http.Response Body.
313func (client SQLPoolVulnerabilityAssessmentRuleBaselinesClient) GetResponder(resp *http.Response) (result SQLPoolVulnerabilityAssessmentRuleBaseline, err error) {
314	err = autorest.Respond(
315		resp,
316		azure.WithErrorUnlessStatusCode(http.StatusOK),
317		autorest.ByUnmarshallingJSON(&result),
318		autorest.ByClosing())
319	result.Response = autorest.Response{Response: resp}
320	return
321}
322