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// IncidentCommentsClient is the API spec for Microsoft.SecurityInsights (Azure Security Insights) resource provider 19type IncidentCommentsClient struct { 20 BaseClient 21} 22 23// NewIncidentCommentsClient creates an instance of the IncidentCommentsClient client. 24func NewIncidentCommentsClient(subscriptionID string) IncidentCommentsClient { 25 return NewIncidentCommentsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewIncidentCommentsClientWithBaseURI creates an instance of the IncidentCommentsClient 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 NewIncidentCommentsClientWithBaseURI(baseURI string, subscriptionID string) IncidentCommentsClient { 32 return IncidentCommentsClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateComment creates the incident comment. 36// Parameters: 37// resourceGroupName - the name of the resource group within the user's subscription. The name is case 38// insensitive. 39// workspaceName - the name of the workspace. 40// incidentID - incident ID 41// incidentCommentID - incident comment ID 42// incidentComment - the incident comment 43func (client IncidentCommentsClient) CreateComment(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, incidentCommentID string, incidentComment IncidentComment) (result IncidentComment, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/IncidentCommentsClient.CreateComment") 46 defer func() { 47 sc := -1 48 if result.Response.Response != nil { 49 sc = result.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 if err := validation.Validate([]validation.Validation{ 55 {TargetValue: client.SubscriptionID, 56 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}}}, 57 {TargetValue: resourceGroupName, 58 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 59 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 60 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 61 {TargetValue: workspaceName, 62 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 63 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 64 {TargetValue: incidentComment, 65 Constraints: []validation.Constraint{{Target: "incidentComment.IncidentCommentProperties", Name: validation.Null, Rule: false, 66 Chain: []validation.Constraint{{Target: "incidentComment.IncidentCommentProperties.Message", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 67 return result, validation.NewError("securityinsight.IncidentCommentsClient", "CreateComment", err.Error()) 68 } 69 70 req, err := client.CreateCommentPreparer(ctx, resourceGroupName, workspaceName, incidentID, incidentCommentID, incidentComment) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "CreateComment", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.CreateCommentSender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "CreateComment", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.CreateCommentResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "CreateComment", resp, "Failure responding to request") 86 return 87 } 88 89 return 90} 91 92// CreateCommentPreparer prepares the CreateComment request. 93func (client IncidentCommentsClient) CreateCommentPreparer(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, incidentCommentID string, incidentComment IncidentComment) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "incidentCommentId": autorest.Encode("path", incidentCommentID), 96 "incidentId": autorest.Encode("path", incidentID), 97 "resourceGroupName": autorest.Encode("path", resourceGroupName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 "workspaceName": autorest.Encode("path", workspaceName), 100 } 101 102 const APIVersion = "2020-01-01" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 107 preparer := autorest.CreatePreparer( 108 autorest.AsContentType("application/json; charset=utf-8"), 109 autorest.AsPut(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments/{incidentCommentId}", pathParameters), 112 autorest.WithJSON(incidentComment), 113 autorest.WithQueryParameters(queryParameters)) 114 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 115} 116 117// CreateCommentSender sends the CreateComment request. The method will close the 118// http.Response Body if it receives an error. 119func (client IncidentCommentsClient) CreateCommentSender(req *http.Request) (*http.Response, error) { 120 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 121} 122 123// CreateCommentResponder handles the response to the CreateComment request. The method always 124// closes the http.Response Body. 125func (client IncidentCommentsClient) CreateCommentResponder(resp *http.Response) (result IncidentComment, err error) { 126 err = autorest.Respond( 127 resp, 128 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// Get gets an incident comment. 136// Parameters: 137// resourceGroupName - the name of the resource group within the user's subscription. The name is case 138// insensitive. 139// workspaceName - the name of the workspace. 140// incidentID - incident ID 141// incidentCommentID - incident comment ID 142func (client IncidentCommentsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, incidentCommentID string) (result IncidentComment, err error) { 143 if tracing.IsEnabled() { 144 ctx = tracing.StartSpan(ctx, fqdn+"/IncidentCommentsClient.Get") 145 defer func() { 146 sc := -1 147 if result.Response.Response != nil { 148 sc = result.Response.Response.StatusCode 149 } 150 tracing.EndSpan(ctx, sc, err) 151 }() 152 } 153 if err := validation.Validate([]validation.Validation{ 154 {TargetValue: client.SubscriptionID, 155 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}}}, 156 {TargetValue: resourceGroupName, 157 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 158 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 159 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 160 {TargetValue: workspaceName, 161 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 162 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 163 return result, validation.NewError("securityinsight.IncidentCommentsClient", "Get", err.Error()) 164 } 165 166 req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, incidentID, incidentCommentID) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "Get", nil, "Failure preparing request") 169 return 170 } 171 172 resp, err := client.GetSender(req) 173 if err != nil { 174 result.Response = autorest.Response{Response: resp} 175 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "Get", resp, "Failure sending request") 176 return 177 } 178 179 result, err = client.GetResponder(resp) 180 if err != nil { 181 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "Get", resp, "Failure responding to request") 182 return 183 } 184 185 return 186} 187 188// GetPreparer prepares the Get request. 189func (client IncidentCommentsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, incidentCommentID string) (*http.Request, error) { 190 pathParameters := map[string]interface{}{ 191 "incidentCommentId": autorest.Encode("path", incidentCommentID), 192 "incidentId": autorest.Encode("path", incidentID), 193 "resourceGroupName": autorest.Encode("path", resourceGroupName), 194 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 195 "workspaceName": autorest.Encode("path", workspaceName), 196 } 197 198 const APIVersion = "2020-01-01" 199 queryParameters := map[string]interface{}{ 200 "api-version": APIVersion, 201 } 202 203 preparer := autorest.CreatePreparer( 204 autorest.AsGet(), 205 autorest.WithBaseURL(client.BaseURI), 206 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments/{incidentCommentId}", pathParameters), 207 autorest.WithQueryParameters(queryParameters)) 208 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 209} 210 211// GetSender sends the Get request. The method will close the 212// http.Response Body if it receives an error. 213func (client IncidentCommentsClient) GetSender(req *http.Request) (*http.Response, error) { 214 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 215} 216 217// GetResponder handles the response to the Get request. The method always 218// closes the http.Response Body. 219func (client IncidentCommentsClient) GetResponder(resp *http.Response) (result IncidentComment, err error) { 220 err = autorest.Respond( 221 resp, 222 azure.WithErrorUnlessStatusCode(http.StatusOK), 223 autorest.ByUnmarshallingJSON(&result), 224 autorest.ByClosing()) 225 result.Response = autorest.Response{Response: resp} 226 return 227} 228 229// ListByIncident gets all incident comments. 230// Parameters: 231// resourceGroupName - the name of the resource group within the user's subscription. The name is case 232// insensitive. 233// workspaceName - the name of the workspace. 234// incidentID - incident ID 235// filter - filters the results, based on a Boolean condition. Optional. 236// orderby - sorts the results. Optional. 237// top - returns only the first n results. Optional. 238// skipToken - skiptoken is only used if a previous operation returned a partial result. If a previous response 239// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that 240// specifies a starting point to use for subsequent calls. Optional. 241func (client IncidentCommentsClient) ListByIncident(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, filter string, orderby string, top *int32, skipToken string) (result IncidentCommentListPage, err error) { 242 if tracing.IsEnabled() { 243 ctx = tracing.StartSpan(ctx, fqdn+"/IncidentCommentsClient.ListByIncident") 244 defer func() { 245 sc := -1 246 if result.icl.Response.Response != nil { 247 sc = result.icl.Response.Response.StatusCode 248 } 249 tracing.EndSpan(ctx, sc, err) 250 }() 251 } 252 if err := validation.Validate([]validation.Validation{ 253 {TargetValue: client.SubscriptionID, 254 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}}}, 255 {TargetValue: resourceGroupName, 256 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 257 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 258 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 259 {TargetValue: workspaceName, 260 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 261 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 262 return result, validation.NewError("securityinsight.IncidentCommentsClient", "ListByIncident", err.Error()) 263 } 264 265 result.fn = client.listByIncidentNextResults 266 req, err := client.ListByIncidentPreparer(ctx, resourceGroupName, workspaceName, incidentID, filter, orderby, top, skipToken) 267 if err != nil { 268 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "ListByIncident", nil, "Failure preparing request") 269 return 270 } 271 272 resp, err := client.ListByIncidentSender(req) 273 if err != nil { 274 result.icl.Response = autorest.Response{Response: resp} 275 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "ListByIncident", resp, "Failure sending request") 276 return 277 } 278 279 result.icl, err = client.ListByIncidentResponder(resp) 280 if err != nil { 281 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "ListByIncident", resp, "Failure responding to request") 282 return 283 } 284 if result.icl.hasNextLink() && result.icl.IsEmpty() { 285 err = result.NextWithContext(ctx) 286 return 287 } 288 289 return 290} 291 292// ListByIncidentPreparer prepares the ListByIncident request. 293func (client IncidentCommentsClient) ListByIncidentPreparer(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, filter string, orderby string, top *int32, skipToken string) (*http.Request, error) { 294 pathParameters := map[string]interface{}{ 295 "incidentId": autorest.Encode("path", incidentID), 296 "resourceGroupName": autorest.Encode("path", resourceGroupName), 297 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 298 "workspaceName": autorest.Encode("path", workspaceName), 299 } 300 301 const APIVersion = "2020-01-01" 302 queryParameters := map[string]interface{}{ 303 "api-version": APIVersion, 304 } 305 if len(filter) > 0 { 306 queryParameters["$filter"] = autorest.Encode("query", filter) 307 } 308 if len(orderby) > 0 { 309 queryParameters["$orderby"] = autorest.Encode("query", orderby) 310 } 311 if top != nil { 312 queryParameters["$top"] = autorest.Encode("query", *top) 313 } 314 if len(skipToken) > 0 { 315 queryParameters["$skipToken"] = autorest.Encode("query", skipToken) 316 } 317 318 preparer := autorest.CreatePreparer( 319 autorest.AsGet(), 320 autorest.WithBaseURL(client.BaseURI), 321 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments", pathParameters), 322 autorest.WithQueryParameters(queryParameters)) 323 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 324} 325 326// ListByIncidentSender sends the ListByIncident request. The method will close the 327// http.Response Body if it receives an error. 328func (client IncidentCommentsClient) ListByIncidentSender(req *http.Request) (*http.Response, error) { 329 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 330} 331 332// ListByIncidentResponder handles the response to the ListByIncident request. The method always 333// closes the http.Response Body. 334func (client IncidentCommentsClient) ListByIncidentResponder(resp *http.Response) (result IncidentCommentList, err error) { 335 err = autorest.Respond( 336 resp, 337 azure.WithErrorUnlessStatusCode(http.StatusOK), 338 autorest.ByUnmarshallingJSON(&result), 339 autorest.ByClosing()) 340 result.Response = autorest.Response{Response: resp} 341 return 342} 343 344// listByIncidentNextResults retrieves the next set of results, if any. 345func (client IncidentCommentsClient) listByIncidentNextResults(ctx context.Context, lastResults IncidentCommentList) (result IncidentCommentList, err error) { 346 req, err := lastResults.incidentCommentListPreparer(ctx) 347 if err != nil { 348 return result, autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "listByIncidentNextResults", nil, "Failure preparing next results request") 349 } 350 if req == nil { 351 return 352 } 353 resp, err := client.ListByIncidentSender(req) 354 if err != nil { 355 result.Response = autorest.Response{Response: resp} 356 return result, autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "listByIncidentNextResults", resp, "Failure sending next results request") 357 } 358 result, err = client.ListByIncidentResponder(resp) 359 if err != nil { 360 err = autorest.NewErrorWithError(err, "securityinsight.IncidentCommentsClient", "listByIncidentNextResults", resp, "Failure responding to next results request") 361 } 362 return 363} 364 365// ListByIncidentComplete enumerates all values, automatically crossing page boundaries as required. 366func (client IncidentCommentsClient) ListByIncidentComplete(ctx context.Context, resourceGroupName string, workspaceName string, incidentID string, filter string, orderby string, top *int32, skipToken string) (result IncidentCommentListIterator, err error) { 367 if tracing.IsEnabled() { 368 ctx = tracing.StartSpan(ctx, fqdn+"/IncidentCommentsClient.ListByIncident") 369 defer func() { 370 sc := -1 371 if result.Response().Response.Response != nil { 372 sc = result.page.Response().Response.Response.StatusCode 373 } 374 tracing.EndSpan(ctx, sc, err) 375 }() 376 } 377 result.page, err = client.ListByIncident(ctx, resourceGroupName, workspaceName, incidentID, filter, orderby, top, skipToken) 378 return 379} 380