1package security 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// WorkspaceSettingsClient is the API spec for Microsoft.Security (Azure Security Center) resource provider 19type WorkspaceSettingsClient struct { 20 BaseClient 21} 22 23// NewWorkspaceSettingsClient creates an instance of the WorkspaceSettingsClient client. 24func NewWorkspaceSettingsClient(subscriptionID string, ascLocation string) WorkspaceSettingsClient { 25 return NewWorkspaceSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation) 26} 27 28// NewWorkspaceSettingsClientWithBaseURI creates an instance of the WorkspaceSettingsClient client using a custom 29// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 30// stack). 31func NewWorkspaceSettingsClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) WorkspaceSettingsClient { 32 return WorkspaceSettingsClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)} 33} 34 35// Create creating settings about where we should store your security data and logs 36// Parameters: 37// workspaceSettingName - name of the security setting 38// workspaceSetting - security data setting object 39func (client WorkspaceSettingsClient) Create(ctx context.Context, workspaceSettingName string, workspaceSetting WorkspaceSetting) (result WorkspaceSetting, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceSettingsClient.Create") 42 defer func() { 43 sc := -1 44 if result.Response.Response != nil { 45 sc = result.Response.Response.StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: client.SubscriptionID, 52 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}, 53 {TargetValue: workspaceSetting, 54 Constraints: []validation.Constraint{{Target: "workspaceSetting.WorkspaceSettingProperties", Name: validation.Null, Rule: false, 55 Chain: []validation.Constraint{{Target: "workspaceSetting.WorkspaceSettingProperties.WorkspaceID", Name: validation.Null, Rule: true, Chain: nil}, 56 {Target: "workspaceSetting.WorkspaceSettingProperties.Scope", Name: validation.Null, Rule: true, Chain: nil}, 57 }}}}}); err != nil { 58 return result, validation.NewError("security.WorkspaceSettingsClient", "Create", err.Error()) 59 } 60 61 req, err := client.CreatePreparer(ctx, workspaceSettingName, workspaceSetting) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Create", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.CreateSender(req) 68 if err != nil { 69 result.Response = autorest.Response{Response: resp} 70 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Create", resp, "Failure sending request") 71 return 72 } 73 74 result, err = client.CreateResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Create", resp, "Failure responding to request") 77 return 78 } 79 80 return 81} 82 83// CreatePreparer prepares the Create request. 84func (client WorkspaceSettingsClient) CreatePreparer(ctx context.Context, workspaceSettingName string, workspaceSetting WorkspaceSetting) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 87 "workspaceSettingName": autorest.Encode("path", workspaceSettingName), 88 } 89 90 const APIVersion = "2017-08-01-preview" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsContentType("application/json; charset=utf-8"), 97 autorest.AsPut(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings/{workspaceSettingName}", pathParameters), 100 autorest.WithJSON(workspaceSetting), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CreateSender sends the Create request. The method will close the 106// http.Response Body if it receives an error. 107func (client WorkspaceSettingsClient) CreateSender(req *http.Request) (*http.Response, error) { 108 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 109} 110 111// CreateResponder handles the response to the Create request. The method always 112// closes the http.Response Body. 113func (client WorkspaceSettingsClient) CreateResponder(resp *http.Response) (result WorkspaceSetting, err error) { 114 err = autorest.Respond( 115 resp, 116 azure.WithErrorUnlessStatusCode(http.StatusOK), 117 autorest.ByUnmarshallingJSON(&result), 118 autorest.ByClosing()) 119 result.Response = autorest.Response{Response: resp} 120 return 121} 122 123// Delete deletes the custom workspace settings for this subscription. new VMs will report to the default workspace 124// Parameters: 125// workspaceSettingName - name of the security setting 126func (client WorkspaceSettingsClient) Delete(ctx context.Context, workspaceSettingName string) (result autorest.Response, err error) { 127 if tracing.IsEnabled() { 128 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceSettingsClient.Delete") 129 defer func() { 130 sc := -1 131 if result.Response != nil { 132 sc = result.Response.StatusCode 133 } 134 tracing.EndSpan(ctx, sc, err) 135 }() 136 } 137 if err := validation.Validate([]validation.Validation{ 138 {TargetValue: client.SubscriptionID, 139 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil { 140 return result, validation.NewError("security.WorkspaceSettingsClient", "Delete", err.Error()) 141 } 142 143 req, err := client.DeletePreparer(ctx, workspaceSettingName) 144 if err != nil { 145 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Delete", nil, "Failure preparing request") 146 return 147 } 148 149 resp, err := client.DeleteSender(req) 150 if err != nil { 151 result.Response = resp 152 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Delete", resp, "Failure sending request") 153 return 154 } 155 156 result, err = client.DeleteResponder(resp) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Delete", resp, "Failure responding to request") 159 return 160 } 161 162 return 163} 164 165// DeletePreparer prepares the Delete request. 166func (client WorkspaceSettingsClient) DeletePreparer(ctx context.Context, workspaceSettingName string) (*http.Request, error) { 167 pathParameters := map[string]interface{}{ 168 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 169 "workspaceSettingName": autorest.Encode("path", workspaceSettingName), 170 } 171 172 const APIVersion = "2017-08-01-preview" 173 queryParameters := map[string]interface{}{ 174 "api-version": APIVersion, 175 } 176 177 preparer := autorest.CreatePreparer( 178 autorest.AsDelete(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings/{workspaceSettingName}", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 183} 184 185// DeleteSender sends the Delete request. The method will close the 186// http.Response Body if it receives an error. 187func (client WorkspaceSettingsClient) DeleteSender(req *http.Request) (*http.Response, error) { 188 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 189} 190 191// DeleteResponder handles the response to the Delete request. The method always 192// closes the http.Response Body. 193func (client WorkspaceSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 194 err = autorest.Respond( 195 resp, 196 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 197 autorest.ByClosing()) 198 result.Response = resp 199 return 200} 201 202// Get settings about where we should store your security data and logs. If the result is empty, it means that no 203// custom-workspace configuration was set 204// Parameters: 205// workspaceSettingName - name of the security setting 206func (client WorkspaceSettingsClient) Get(ctx context.Context, workspaceSettingName string) (result WorkspaceSetting, err error) { 207 if tracing.IsEnabled() { 208 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceSettingsClient.Get") 209 defer func() { 210 sc := -1 211 if result.Response.Response != nil { 212 sc = result.Response.Response.StatusCode 213 } 214 tracing.EndSpan(ctx, sc, err) 215 }() 216 } 217 if err := validation.Validate([]validation.Validation{ 218 {TargetValue: client.SubscriptionID, 219 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil { 220 return result, validation.NewError("security.WorkspaceSettingsClient", "Get", err.Error()) 221 } 222 223 req, err := client.GetPreparer(ctx, workspaceSettingName) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Get", nil, "Failure preparing request") 226 return 227 } 228 229 resp, err := client.GetSender(req) 230 if err != nil { 231 result.Response = autorest.Response{Response: resp} 232 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Get", resp, "Failure sending request") 233 return 234 } 235 236 result, err = client.GetResponder(resp) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Get", resp, "Failure responding to request") 239 return 240 } 241 242 return 243} 244 245// GetPreparer prepares the Get request. 246func (client WorkspaceSettingsClient) GetPreparer(ctx context.Context, workspaceSettingName string) (*http.Request, error) { 247 pathParameters := map[string]interface{}{ 248 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 249 "workspaceSettingName": autorest.Encode("path", workspaceSettingName), 250 } 251 252 const APIVersion = "2017-08-01-preview" 253 queryParameters := map[string]interface{}{ 254 "api-version": APIVersion, 255 } 256 257 preparer := autorest.CreatePreparer( 258 autorest.AsGet(), 259 autorest.WithBaseURL(client.BaseURI), 260 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings/{workspaceSettingName}", pathParameters), 261 autorest.WithQueryParameters(queryParameters)) 262 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 263} 264 265// GetSender sends the Get request. The method will close the 266// http.Response Body if it receives an error. 267func (client WorkspaceSettingsClient) GetSender(req *http.Request) (*http.Response, error) { 268 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 269} 270 271// GetResponder handles the response to the Get request. The method always 272// closes the http.Response Body. 273func (client WorkspaceSettingsClient) GetResponder(resp *http.Response) (result WorkspaceSetting, err error) { 274 err = autorest.Respond( 275 resp, 276 azure.WithErrorUnlessStatusCode(http.StatusOK), 277 autorest.ByUnmarshallingJSON(&result), 278 autorest.ByClosing()) 279 result.Response = autorest.Response{Response: resp} 280 return 281} 282 283// List settings about where we should store your security data and logs. If the result is empty, it means that no 284// custom-workspace configuration was set 285func (client WorkspaceSettingsClient) List(ctx context.Context) (result WorkspaceSettingListPage, err error) { 286 if tracing.IsEnabled() { 287 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceSettingsClient.List") 288 defer func() { 289 sc := -1 290 if result.wsl.Response.Response != nil { 291 sc = result.wsl.Response.Response.StatusCode 292 } 293 tracing.EndSpan(ctx, sc, err) 294 }() 295 } 296 if err := validation.Validate([]validation.Validation{ 297 {TargetValue: client.SubscriptionID, 298 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil { 299 return result, validation.NewError("security.WorkspaceSettingsClient", "List", err.Error()) 300 } 301 302 result.fn = client.listNextResults 303 req, err := client.ListPreparer(ctx) 304 if err != nil { 305 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "List", nil, "Failure preparing request") 306 return 307 } 308 309 resp, err := client.ListSender(req) 310 if err != nil { 311 result.wsl.Response = autorest.Response{Response: resp} 312 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "List", resp, "Failure sending request") 313 return 314 } 315 316 result.wsl, err = client.ListResponder(resp) 317 if err != nil { 318 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "List", resp, "Failure responding to request") 319 return 320 } 321 if result.wsl.hasNextLink() && result.wsl.IsEmpty() { 322 err = result.NextWithContext(ctx) 323 return 324 } 325 326 return 327} 328 329// ListPreparer prepares the List request. 330func (client WorkspaceSettingsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 331 pathParameters := map[string]interface{}{ 332 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 333 } 334 335 const APIVersion = "2017-08-01-preview" 336 queryParameters := map[string]interface{}{ 337 "api-version": APIVersion, 338 } 339 340 preparer := autorest.CreatePreparer( 341 autorest.AsGet(), 342 autorest.WithBaseURL(client.BaseURI), 343 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings", pathParameters), 344 autorest.WithQueryParameters(queryParameters)) 345 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 346} 347 348// ListSender sends the List request. The method will close the 349// http.Response Body if it receives an error. 350func (client WorkspaceSettingsClient) ListSender(req *http.Request) (*http.Response, error) { 351 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 352} 353 354// ListResponder handles the response to the List request. The method always 355// closes the http.Response Body. 356func (client WorkspaceSettingsClient) ListResponder(resp *http.Response) (result WorkspaceSettingList, err error) { 357 err = autorest.Respond( 358 resp, 359 azure.WithErrorUnlessStatusCode(http.StatusOK), 360 autorest.ByUnmarshallingJSON(&result), 361 autorest.ByClosing()) 362 result.Response = autorest.Response{Response: resp} 363 return 364} 365 366// listNextResults retrieves the next set of results, if any. 367func (client WorkspaceSettingsClient) listNextResults(ctx context.Context, lastResults WorkspaceSettingList) (result WorkspaceSettingList, err error) { 368 req, err := lastResults.workspaceSettingListPreparer(ctx) 369 if err != nil { 370 return result, autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "listNextResults", nil, "Failure preparing next results request") 371 } 372 if req == nil { 373 return 374 } 375 resp, err := client.ListSender(req) 376 if err != nil { 377 result.Response = autorest.Response{Response: resp} 378 return result, autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "listNextResults", resp, "Failure sending next results request") 379 } 380 result, err = client.ListResponder(resp) 381 if err != nil { 382 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "listNextResults", resp, "Failure responding to next results request") 383 } 384 return 385} 386 387// ListComplete enumerates all values, automatically crossing page boundaries as required. 388func (client WorkspaceSettingsClient) ListComplete(ctx context.Context) (result WorkspaceSettingListIterator, err error) { 389 if tracing.IsEnabled() { 390 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceSettingsClient.List") 391 defer func() { 392 sc := -1 393 if result.Response().Response.Response != nil { 394 sc = result.page.Response().Response.Response.StatusCode 395 } 396 tracing.EndSpan(ctx, sc, err) 397 }() 398 } 399 result.page, err = client.List(ctx) 400 return 401} 402 403// Update settings about where we should store your security data and logs 404// Parameters: 405// workspaceSettingName - name of the security setting 406// workspaceSetting - security data setting object 407func (client WorkspaceSettingsClient) Update(ctx context.Context, workspaceSettingName string, workspaceSetting WorkspaceSetting) (result WorkspaceSetting, err error) { 408 if tracing.IsEnabled() { 409 ctx = tracing.StartSpan(ctx, fqdn+"/WorkspaceSettingsClient.Update") 410 defer func() { 411 sc := -1 412 if result.Response.Response != nil { 413 sc = result.Response.Response.StatusCode 414 } 415 tracing.EndSpan(ctx, sc, err) 416 }() 417 } 418 if err := validation.Validate([]validation.Validation{ 419 {TargetValue: client.SubscriptionID, 420 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil { 421 return result, validation.NewError("security.WorkspaceSettingsClient", "Update", err.Error()) 422 } 423 424 req, err := client.UpdatePreparer(ctx, workspaceSettingName, workspaceSetting) 425 if err != nil { 426 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Update", nil, "Failure preparing request") 427 return 428 } 429 430 resp, err := client.UpdateSender(req) 431 if err != nil { 432 result.Response = autorest.Response{Response: resp} 433 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Update", resp, "Failure sending request") 434 return 435 } 436 437 result, err = client.UpdateResponder(resp) 438 if err != nil { 439 err = autorest.NewErrorWithError(err, "security.WorkspaceSettingsClient", "Update", resp, "Failure responding to request") 440 return 441 } 442 443 return 444} 445 446// UpdatePreparer prepares the Update request. 447func (client WorkspaceSettingsClient) UpdatePreparer(ctx context.Context, workspaceSettingName string, workspaceSetting WorkspaceSetting) (*http.Request, error) { 448 pathParameters := map[string]interface{}{ 449 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 450 "workspaceSettingName": autorest.Encode("path", workspaceSettingName), 451 } 452 453 const APIVersion = "2017-08-01-preview" 454 queryParameters := map[string]interface{}{ 455 "api-version": APIVersion, 456 } 457 458 preparer := autorest.CreatePreparer( 459 autorest.AsContentType("application/json; charset=utf-8"), 460 autorest.AsPatch(), 461 autorest.WithBaseURL(client.BaseURI), 462 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings/{workspaceSettingName}", pathParameters), 463 autorest.WithJSON(workspaceSetting), 464 autorest.WithQueryParameters(queryParameters)) 465 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 466} 467 468// UpdateSender sends the Update request. The method will close the 469// http.Response Body if it receives an error. 470func (client WorkspaceSettingsClient) UpdateSender(req *http.Request) (*http.Response, error) { 471 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 472} 473 474// UpdateResponder handles the response to the Update request. The method always 475// closes the http.Response Body. 476func (client WorkspaceSettingsClient) UpdateResponder(resp *http.Response) (result WorkspaceSetting, err error) { 477 err = autorest.Respond( 478 resp, 479 azure.WithErrorUnlessStatusCode(http.StatusOK), 480 autorest.ByUnmarshallingJSON(&result), 481 autorest.ByClosing()) 482 result.Response = autorest.Response{Response: resp} 483 return 484} 485