1package securityinsight 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// ActionsClient is the API spec for Microsoft.SecurityInsights (Azure Security Insights) resource provider 30type ActionsClient struct { 31 BaseClient 32} 33 34// NewActionsClient creates an instance of the ActionsClient client. 35func NewActionsClient(subscriptionID string) ActionsClient { 36 return NewActionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewActionsClientWithBaseURI creates an instance of the ActionsClient client using a custom endpoint. Use this when 40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewActionsClientWithBaseURI(baseURI string, subscriptionID string) ActionsClient { 42 return ActionsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// ListByAlertRule gets all actions of alert rule. 46// Parameters: 47// resourceGroupName - the name of the resource group within the user's subscription. The name is case 48// insensitive. 49// workspaceName - the name of the workspace. 50// ruleID - alert rule ID 51func (client ActionsClient) ListByAlertRule(ctx context.Context, resourceGroupName string, workspaceName string, ruleID string) (result ActionsListPage, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/ActionsClient.ListByAlertRule") 54 defer func() { 55 sc := -1 56 if result.al.Response.Response != nil { 57 sc = result.al.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: client.SubscriptionID, 64 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}}}, 65 {TargetValue: resourceGroupName, 66 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 67 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 69 {TargetValue: workspaceName, 70 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 71 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 72 return result, validation.NewError("securityinsight.ActionsClient", "ListByAlertRule", err.Error()) 73 } 74 75 result.fn = client.listByAlertRuleNextResults 76 req, err := client.ListByAlertRulePreparer(ctx, resourceGroupName, workspaceName, ruleID) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "securityinsight.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") 79 return 80 } 81 82 resp, err := client.ListByAlertRuleSender(req) 83 if err != nil { 84 result.al.Response = autorest.Response{Response: resp} 85 err = autorest.NewErrorWithError(err, "securityinsight.ActionsClient", "ListByAlertRule", resp, "Failure sending request") 86 return 87 } 88 89 result.al, err = client.ListByAlertRuleResponder(resp) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "securityinsight.ActionsClient", "ListByAlertRule", resp, "Failure responding to request") 92 return 93 } 94 if result.al.hasNextLink() && result.al.IsEmpty() { 95 err = result.NextWithContext(ctx) 96 return 97 } 98 99 return 100} 101 102// ListByAlertRulePreparer prepares the ListByAlertRule request. 103func (client ActionsClient) ListByAlertRulePreparer(ctx context.Context, resourceGroupName string, workspaceName string, ruleID string) (*http.Request, error) { 104 pathParameters := map[string]interface{}{ 105 "resourceGroupName": autorest.Encode("path", resourceGroupName), 106 "ruleId": autorest.Encode("path", ruleID), 107 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 108 "workspaceName": autorest.Encode("path", workspaceName), 109 } 110 111 const APIVersion = "2020-01-01" 112 queryParameters := map[string]interface{}{ 113 "api-version": APIVersion, 114 } 115 116 preparer := autorest.CreatePreparer( 117 autorest.AsGet(), 118 autorest.WithBaseURL(client.BaseURI), 119 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/alertRules/{ruleId}/actions", pathParameters), 120 autorest.WithQueryParameters(queryParameters)) 121 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 122} 123 124// ListByAlertRuleSender sends the ListByAlertRule request. The method will close the 125// http.Response Body if it receives an error. 126func (client ActionsClient) ListByAlertRuleSender(req *http.Request) (*http.Response, error) { 127 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 128} 129 130// ListByAlertRuleResponder handles the response to the ListByAlertRule request. The method always 131// closes the http.Response Body. 132func (client ActionsClient) ListByAlertRuleResponder(resp *http.Response) (result ActionsList, err error) { 133 err = autorest.Respond( 134 resp, 135 azure.WithErrorUnlessStatusCode(http.StatusOK), 136 autorest.ByUnmarshallingJSON(&result), 137 autorest.ByClosing()) 138 result.Response = autorest.Response{Response: resp} 139 return 140} 141 142// listByAlertRuleNextResults retrieves the next set of results, if any. 143func (client ActionsClient) listByAlertRuleNextResults(ctx context.Context, lastResults ActionsList) (result ActionsList, err error) { 144 req, err := lastResults.actionsListPreparer(ctx) 145 if err != nil { 146 return result, autorest.NewErrorWithError(err, "securityinsight.ActionsClient", "listByAlertRuleNextResults", nil, "Failure preparing next results request") 147 } 148 if req == nil { 149 return 150 } 151 resp, err := client.ListByAlertRuleSender(req) 152 if err != nil { 153 result.Response = autorest.Response{Response: resp} 154 return result, autorest.NewErrorWithError(err, "securityinsight.ActionsClient", "listByAlertRuleNextResults", resp, "Failure sending next results request") 155 } 156 result, err = client.ListByAlertRuleResponder(resp) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "securityinsight.ActionsClient", "listByAlertRuleNextResults", resp, "Failure responding to next results request") 159 } 160 return 161} 162 163// ListByAlertRuleComplete enumerates all values, automatically crossing page boundaries as required. 164func (client ActionsClient) ListByAlertRuleComplete(ctx context.Context, resourceGroupName string, workspaceName string, ruleID string) (result ActionsListIterator, err error) { 165 if tracing.IsEnabled() { 166 ctx = tracing.StartSpan(ctx, fqdn+"/ActionsClient.ListByAlertRule") 167 defer func() { 168 sc := -1 169 if result.Response().Response.Response != nil { 170 sc = result.page.Response().Response.Response.StatusCode 171 } 172 tracing.EndSpan(ctx, sc, err) 173 }() 174 } 175 result.page, err = client.ListByAlertRule(ctx, resourceGroupName, workspaceName, ruleID) 176 return 177} 178