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// WorkspaceManagedSQLServerBlobAuditingPoliciesClient is the azure Synapse Analytics Management Client
19type WorkspaceManagedSQLServerBlobAuditingPoliciesClient struct {
20	BaseClient
21}
22
23// NewWorkspaceManagedSQLServerBlobAuditingPoliciesClient creates an instance of the
24// WorkspaceManagedSQLServerBlobAuditingPoliciesClient client.
25func NewWorkspaceManagedSQLServerBlobAuditingPoliciesClient(subscriptionID string) WorkspaceManagedSQLServerBlobAuditingPoliciesClient {
26	return NewWorkspaceManagedSQLServerBlobAuditingPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewWorkspaceManagedSQLServerBlobAuditingPoliciesClientWithBaseURI creates an instance of the
30// WorkspaceManagedSQLServerBlobAuditingPoliciesClient client using a custom endpoint.  Use this when interacting with
31// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewWorkspaceManagedSQLServerBlobAuditingPoliciesClientWithBaseURI(baseURI string, subscriptionID string) WorkspaceManagedSQLServerBlobAuditingPoliciesClient {
33	return WorkspaceManagedSQLServerBlobAuditingPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate create or Update a workspace managed sql server's blob auditing policy.
37// Parameters:
38// resourceGroupName - the name of the resource group. The name is case insensitive.
39// workspaceName - the name of the workspace
40// parameters - properties of extended blob auditing policy.
41func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, parameters ServerBlobAuditingPolicy) (result WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.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.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "CreateOrUpdate", err.Error())
60	}
61
62	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, parameters)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
65		return
66	}
67
68	result, err = client.CreateOrUpdateSender(req)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure sending request")
71		return
72	}
73
74	return
75}
76
77// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
78func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, parameters ServerBlobAuditingPolicy) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"blobAuditingPolicyName": autorest.Encode("path", "default"),
81		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
82		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
83		"workspaceName":          autorest.Encode("path", workspaceName),
84	}
85
86	const APIVersion = "2020-12-01"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsContentType("application/json; charset=utf-8"),
93		autorest.AsPut(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/auditingSettings/{blobAuditingPolicyName}", pathParameters),
96		autorest.WithJSON(parameters),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
102// http.Response Body if it receives an error.
103func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdateSender(req *http.Request) (future WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) {
104	var resp *http.Response
105	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
106	if err != nil {
107		return
108	}
109	var azf azure.Future
110	azf, err = azure.NewFutureFromResponse(resp)
111	future.FutureAPI = &azf
112	future.Result = future.result
113	return
114}
115
116// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
117// closes the http.Response Body.
118func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ServerBlobAuditingPolicy, err error) {
119	err = autorest.Respond(
120		resp,
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Get get a workspace managed sql server's blob auditing policy.
129// Parameters:
130// resourceGroupName - the name of the resource group. The name is case insensitive.
131// workspaceName - the name of the workspace
132func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) Get(ctx context.Context, resourceGroupName string, workspaceName string) (result ServerBlobAuditingPolicy, err error) {
133	if tracing.IsEnabled() {
134		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.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.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "Get", err.Error())
151	}
152
153	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "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.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "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.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "Get", resp, "Failure responding to request")
169		return
170	}
171
172	return
173}
174
175// GetPreparer prepares the Get request.
176func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"blobAuditingPolicyName": 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 = "2020-12-01"
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}/auditingSettings/{blobAuditingPolicyName}", 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 WorkspaceManagedSQLServerBlobAuditingPoliciesClient) 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 WorkspaceManagedSQLServerBlobAuditingPoliciesClient) GetResponder(resp *http.Response) (result ServerBlobAuditingPolicy, 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// ListByWorkspace list workspace managed sql server's blob auditing policies.
216// Parameters:
217// resourceGroupName - the name of the resource group. The name is case insensitive.
218// workspaceName - the name of the workspace
219func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspace(ctx context.Context, resourceGroupName string, workspaceName string) (result ServerBlobAuditingPolicyListResultPage, err error) {
220	if tracing.IsEnabled() {
221		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.ListByWorkspace")
222		defer func() {
223			sc := -1
224			if result.sbaplr.Response.Response != nil {
225				sc = result.sbaplr.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},
236				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
237		return result, validation.NewError("synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", err.Error())
238	}
239
240	result.fn = client.listByWorkspaceNextResults
241	req, err := client.ListByWorkspacePreparer(ctx, resourceGroupName, workspaceName)
242	if err != nil {
243		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", nil, "Failure preparing request")
244		return
245	}
246
247	resp, err := client.ListByWorkspaceSender(req)
248	if err != nil {
249		result.sbaplr.Response = autorest.Response{Response: resp}
250		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", resp, "Failure sending request")
251		return
252	}
253
254	result.sbaplr, err = client.ListByWorkspaceResponder(resp)
255	if err != nil {
256		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", resp, "Failure responding to request")
257		return
258	}
259	if result.sbaplr.hasNextLink() && result.sbaplr.IsEmpty() {
260		err = result.NextWithContext(ctx)
261		return
262	}
263
264	return
265}
266
267// ListByWorkspacePreparer prepares the ListByWorkspace request.
268func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspacePreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) {
269	pathParameters := map[string]interface{}{
270		"resourceGroupName": autorest.Encode("path", resourceGroupName),
271		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
272		"workspaceName":     autorest.Encode("path", workspaceName),
273	}
274
275	const APIVersion = "2020-12-01"
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}/auditingSettings", pathParameters),
284		autorest.WithQueryParameters(queryParameters))
285	return preparer.Prepare((&http.Request{}).WithContext(ctx))
286}
287
288// ListByWorkspaceSender sends the ListByWorkspace request. The method will close the
289// http.Response Body if it receives an error.
290func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspaceSender(req *http.Request) (*http.Response, error) {
291	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
292}
293
294// ListByWorkspaceResponder handles the response to the ListByWorkspace request. The method always
295// closes the http.Response Body.
296func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspaceResponder(resp *http.Response) (result ServerBlobAuditingPolicyListResult, 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// listByWorkspaceNextResults retrieves the next set of results, if any.
307func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) listByWorkspaceNextResults(ctx context.Context, lastResults ServerBlobAuditingPolicyListResult) (result ServerBlobAuditingPolicyListResult, err error) {
308	req, err := lastResults.serverBlobAuditingPolicyListResultPreparer(ctx)
309	if err != nil {
310		return result, autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "listByWorkspaceNextResults", nil, "Failure preparing next results request")
311	}
312	if req == nil {
313		return
314	}
315	resp, err := client.ListByWorkspaceSender(req)
316	if err != nil {
317		result.Response = autorest.Response{Response: resp}
318		return result, autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "listByWorkspaceNextResults", resp, "Failure sending next results request")
319	}
320	result, err = client.ListByWorkspaceResponder(resp)
321	if err != nil {
322		err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "listByWorkspaceNextResults", resp, "Failure responding to next results request")
323	}
324	return
325}
326
327// ListByWorkspaceComplete enumerates all values, automatically crossing page boundaries as required.
328func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspaceComplete(ctx context.Context, resourceGroupName string, workspaceName string) (result ServerBlobAuditingPolicyListResultIterator, err error) {
329	if tracing.IsEnabled() {
330		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.ListByWorkspace")
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.ListByWorkspace(ctx, resourceGroupName, workspaceName)
340	return
341}
342