1package synapse 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// WorkspaceManagedSQLServerBlobAuditingPoliciesClient is the azure Synapse Analytics Management Client 30type WorkspaceManagedSQLServerBlobAuditingPoliciesClient struct { 31 BaseClient 32} 33 34// NewWorkspaceManagedSQLServerBlobAuditingPoliciesClient creates an instance of the 35// WorkspaceManagedSQLServerBlobAuditingPoliciesClient client. 36func NewWorkspaceManagedSQLServerBlobAuditingPoliciesClient(subscriptionID string) WorkspaceManagedSQLServerBlobAuditingPoliciesClient { 37 return NewWorkspaceManagedSQLServerBlobAuditingPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewWorkspaceManagedSQLServerBlobAuditingPoliciesClientWithBaseURI creates an instance of the 41// WorkspaceManagedSQLServerBlobAuditingPoliciesClient client using a custom endpoint. Use this when interacting with 42// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 43func NewWorkspaceManagedSQLServerBlobAuditingPoliciesClientWithBaseURI(baseURI string, subscriptionID string) WorkspaceManagedSQLServerBlobAuditingPoliciesClient { 44 return WorkspaceManagedSQLServerBlobAuditingPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// CreateOrUpdate create or Update a workspace managed sql server's blob auditing policy. 48// Parameters: 49// resourceGroupName - the name of the resource group. The name is case insensitive. 50// workspaceName - the name of the workspace 51// parameters - properties of extended blob auditing policy. 52func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, parameters ServerBlobAuditingPolicy) (result WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.CreateOrUpdate") 55 defer func() { 56 sc := -1 57 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 58 sc = result.FutureAPI.Response().StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: client.SubscriptionID, 65 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 66 {TargetValue: resourceGroupName, 67 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 69 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 70 return result, validation.NewError("synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "CreateOrUpdate", err.Error()) 71 } 72 73 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, parameters) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 76 return 77 } 78 79 result, err = client.CreateOrUpdateSender(req) 80 if err != nil { 81 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure sending request") 82 return 83 } 84 85 return 86} 87 88// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 89func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, parameters ServerBlobAuditingPolicy) (*http.Request, error) { 90 pathParameters := map[string]interface{}{ 91 "blobAuditingPolicyName": autorest.Encode("path", "default"), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 "workspaceName": autorest.Encode("path", workspaceName), 95 } 96 97 const APIVersion = "2019-06-01-preview" 98 queryParameters := map[string]interface{}{ 99 "api-version": APIVersion, 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsContentType("application/json; charset=utf-8"), 104 autorest.AsPut(), 105 autorest.WithBaseURL(client.BaseURI), 106 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/auditingSettings/{blobAuditingPolicyName}", pathParameters), 107 autorest.WithJSON(parameters), 108 autorest.WithQueryParameters(queryParameters)) 109 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 110} 111 112// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 113// http.Response Body if it receives an error. 114func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdateSender(req *http.Request) (future WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) { 115 var resp *http.Response 116 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 117 if err != nil { 118 return 119 } 120 var azf azure.Future 121 azf, err = azure.NewFutureFromResponse(resp) 122 future.FutureAPI = &azf 123 future.Result = func(client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) (sbap ServerBlobAuditingPolicy, err error) { 124 var done bool 125 done, err = future.DoneWithContext(context.Background(), client) 126 if err != nil { 127 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 128 return 129 } 130 if !done { 131 err = azure.NewAsyncOpIncompleteError("synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture") 132 return 133 } 134 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 135 sbap.Response.Response, err = future.GetResult(sender) 136 if sbap.Response.Response == nil && err == nil { 137 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture", "Result", nil, "received nil response and error") 138 } 139 if err == nil && sbap.Response.Response.StatusCode != http.StatusNoContent { 140 sbap, err = client.CreateOrUpdateResponder(sbap.Response.Response) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesCreateOrUpdateFuture", "Result", sbap.Response.Response, "Failure responding to request") 143 } 144 } 145 return 146 } 147 return 148} 149 150// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 151// closes the http.Response Body. 152func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ServerBlobAuditingPolicy, err error) { 153 err = autorest.Respond( 154 resp, 155 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 156 autorest.ByUnmarshallingJSON(&result), 157 autorest.ByClosing()) 158 result.Response = autorest.Response{Response: resp} 159 return 160} 161 162// Get get a workspace managed sql server's blob auditing policy. 163// Parameters: 164// resourceGroupName - the name of the resource group. The name is case insensitive. 165// workspaceName - the name of the workspace 166func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) Get(ctx context.Context, resourceGroupName string, workspaceName string) (result ServerBlobAuditingPolicy, err error) { 167 if tracing.IsEnabled() { 168 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.Get") 169 defer func() { 170 sc := -1 171 if result.Response.Response != nil { 172 sc = result.Response.Response.StatusCode 173 } 174 tracing.EndSpan(ctx, sc, err) 175 }() 176 } 177 if err := validation.Validate([]validation.Validation{ 178 {TargetValue: client.SubscriptionID, 179 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 180 {TargetValue: resourceGroupName, 181 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 182 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 183 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 184 return result, validation.NewError("synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "Get", err.Error()) 185 } 186 187 req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName) 188 if err != nil { 189 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "Get", nil, "Failure preparing request") 190 return 191 } 192 193 resp, err := client.GetSender(req) 194 if err != nil { 195 result.Response = autorest.Response{Response: resp} 196 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "Get", resp, "Failure sending request") 197 return 198 } 199 200 result, err = client.GetResponder(resp) 201 if err != nil { 202 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "Get", resp, "Failure responding to request") 203 return 204 } 205 206 return 207} 208 209// GetPreparer prepares the Get request. 210func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) { 211 pathParameters := map[string]interface{}{ 212 "blobAuditingPolicyName": autorest.Encode("path", "default"), 213 "resourceGroupName": autorest.Encode("path", resourceGroupName), 214 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 215 "workspaceName": autorest.Encode("path", workspaceName), 216 } 217 218 const APIVersion = "2019-06-01-preview" 219 queryParameters := map[string]interface{}{ 220 "api-version": APIVersion, 221 } 222 223 preparer := autorest.CreatePreparer( 224 autorest.AsGet(), 225 autorest.WithBaseURL(client.BaseURI), 226 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/auditingSettings/{blobAuditingPolicyName}", pathParameters), 227 autorest.WithQueryParameters(queryParameters)) 228 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 229} 230 231// GetSender sends the Get request. The method will close the 232// http.Response Body if it receives an error. 233func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 234 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 235} 236 237// GetResponder handles the response to the Get request. The method always 238// closes the http.Response Body. 239func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) GetResponder(resp *http.Response) (result ServerBlobAuditingPolicy, err error) { 240 err = autorest.Respond( 241 resp, 242 azure.WithErrorUnlessStatusCode(http.StatusOK), 243 autorest.ByUnmarshallingJSON(&result), 244 autorest.ByClosing()) 245 result.Response = autorest.Response{Response: resp} 246 return 247} 248 249// ListByWorkspace list workspace managed sql server's blob auditing policies. 250// Parameters: 251// resourceGroupName - the name of the resource group. The name is case insensitive. 252// workspaceName - the name of the workspace 253func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspace(ctx context.Context, resourceGroupName string, workspaceName string) (result ServerBlobAuditingPolicyListResultPage, err error) { 254 if tracing.IsEnabled() { 255 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.ListByWorkspace") 256 defer func() { 257 sc := -1 258 if result.sbaplr.Response.Response != nil { 259 sc = result.sbaplr.Response.Response.StatusCode 260 } 261 tracing.EndSpan(ctx, sc, err) 262 }() 263 } 264 if err := validation.Validate([]validation.Validation{ 265 {TargetValue: client.SubscriptionID, 266 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 267 {TargetValue: resourceGroupName, 268 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 269 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 270 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 271 return result, validation.NewError("synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", err.Error()) 272 } 273 274 result.fn = client.listByWorkspaceNextResults 275 req, err := client.ListByWorkspacePreparer(ctx, resourceGroupName, workspaceName) 276 if err != nil { 277 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", nil, "Failure preparing request") 278 return 279 } 280 281 resp, err := client.ListByWorkspaceSender(req) 282 if err != nil { 283 result.sbaplr.Response = autorest.Response{Response: resp} 284 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", resp, "Failure sending request") 285 return 286 } 287 288 result.sbaplr, err = client.ListByWorkspaceResponder(resp) 289 if err != nil { 290 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "ListByWorkspace", resp, "Failure responding to request") 291 return 292 } 293 if result.sbaplr.hasNextLink() && result.sbaplr.IsEmpty() { 294 err = result.NextWithContext(ctx) 295 return 296 } 297 298 return 299} 300 301// ListByWorkspacePreparer prepares the ListByWorkspace request. 302func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspacePreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) { 303 pathParameters := map[string]interface{}{ 304 "resourceGroupName": autorest.Encode("path", resourceGroupName), 305 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 306 "workspaceName": autorest.Encode("path", workspaceName), 307 } 308 309 const APIVersion = "2019-06-01-preview" 310 queryParameters := map[string]interface{}{ 311 "api-version": APIVersion, 312 } 313 314 preparer := autorest.CreatePreparer( 315 autorest.AsGet(), 316 autorest.WithBaseURL(client.BaseURI), 317 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/auditingSettings", pathParameters), 318 autorest.WithQueryParameters(queryParameters)) 319 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 320} 321 322// ListByWorkspaceSender sends the ListByWorkspace request. The method will close the 323// http.Response Body if it receives an error. 324func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspaceSender(req *http.Request) (*http.Response, error) { 325 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 326} 327 328// ListByWorkspaceResponder handles the response to the ListByWorkspace request. The method always 329// closes the http.Response Body. 330func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspaceResponder(resp *http.Response) (result ServerBlobAuditingPolicyListResult, err error) { 331 err = autorest.Respond( 332 resp, 333 azure.WithErrorUnlessStatusCode(http.StatusOK), 334 autorest.ByUnmarshallingJSON(&result), 335 autorest.ByClosing()) 336 result.Response = autorest.Response{Response: resp} 337 return 338} 339 340// listByWorkspaceNextResults retrieves the next set of results, if any. 341func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) listByWorkspaceNextResults(ctx context.Context, lastResults ServerBlobAuditingPolicyListResult) (result ServerBlobAuditingPolicyListResult, err error) { 342 req, err := lastResults.serverBlobAuditingPolicyListResultPreparer(ctx) 343 if err != nil { 344 return result, autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "listByWorkspaceNextResults", nil, "Failure preparing next results request") 345 } 346 if req == nil { 347 return 348 } 349 resp, err := client.ListByWorkspaceSender(req) 350 if err != nil { 351 result.Response = autorest.Response{Response: resp} 352 return result, autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "listByWorkspaceNextResults", resp, "Failure sending next results request") 353 } 354 result, err = client.ListByWorkspaceResponder(resp) 355 if err != nil { 356 err = autorest.NewErrorWithError(err, "synapse.WorkspaceManagedSQLServerBlobAuditingPoliciesClient", "listByWorkspaceNextResults", resp, "Failure responding to next results request") 357 } 358 return 359} 360 361// ListByWorkspaceComplete enumerates all values, automatically crossing page boundaries as required. 362func (client WorkspaceManagedSQLServerBlobAuditingPoliciesClient) ListByWorkspaceComplete(ctx context.Context, resourceGroupName string, workspaceName string) (result ServerBlobAuditingPolicyListResultIterator, err error) { 363 if tracing.IsEnabled() { 364 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceManagedSQLServerBlobAuditingPoliciesClient.ListByWorkspace") 365 defer func() { 366 sc := -1 367 if result.Response().Response.Response != nil { 368 sc = result.page.Response().Response.Response.StatusCode 369 } 370 tracing.EndSpan(ctx, sc, err) 371 }() 372 } 373 result.page, err = client.ListByWorkspace(ctx, resourceGroupName, workspaceName) 374 return 375} 376