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