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// EntitiesClient is the API spec for Microsoft.SecurityInsights (Azure Security Insights) resource provider 30type EntitiesClient struct { 31 BaseClient 32} 33 34// NewEntitiesClient creates an instance of the EntitiesClient client. 35func NewEntitiesClient(subscriptionID string) EntitiesClient { 36 return NewEntitiesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewEntitiesClientWithBaseURI creates an instance of the EntitiesClient client. 40func NewEntitiesClientWithBaseURI(baseURI string, subscriptionID string) EntitiesClient { 41 return EntitiesClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// Expand expands an entity. 45// Parameters: 46// resourceGroupName - the name of the resource group within the user's subscription. The name is case 47// insensitive. 48// operationalInsightsResourceProvider - the namespace of workspaces resource provider- 49// Microsoft.OperationalInsights. 50// workspaceName - the name of the workspace. 51// entityID - entity ID 52// parameters - the parameters required to execute an expand operation on the given entity. 53func (client EntitiesClient) Expand(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, entityID string, parameters EntityExpandParameters) (result EntityExpandResponse, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.Expand") 56 defer func() { 57 sc := -1 58 if result.Response.Response != nil { 59 sc = result.Response.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 if err := validation.Validate([]validation.Validation{ 65 {TargetValue: client.SubscriptionID, 66 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}}}, 67 {TargetValue: resourceGroupName, 68 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 69 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 70 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 71 {TargetValue: workspaceName, 72 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 73 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 74 return result, validation.NewError("securityinsight.EntitiesClient", "Expand", err.Error()) 75 } 76 77 req, err := client.ExpandPreparer(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName, entityID, parameters) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "Expand", nil, "Failure preparing request") 80 return 81 } 82 83 resp, err := client.ExpandSender(req) 84 if err != nil { 85 result.Response = autorest.Response{Response: resp} 86 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "Expand", resp, "Failure sending request") 87 return 88 } 89 90 result, err = client.ExpandResponder(resp) 91 if err != nil { 92 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "Expand", resp, "Failure responding to request") 93 } 94 95 return 96} 97 98// ExpandPreparer prepares the Expand request. 99func (client EntitiesClient) ExpandPreparer(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, entityID string, parameters EntityExpandParameters) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "entityId": autorest.Encode("path", entityID), 102 "operationalInsightsResourceProvider": autorest.Encode("path", operationalInsightsResourceProvider), 103 "resourceGroupName": autorest.Encode("path", resourceGroupName), 104 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 105 "workspaceName": autorest.Encode("path", workspaceName), 106 } 107 108 const APIVersion = "2019-01-01-preview" 109 queryParameters := map[string]interface{}{ 110 "api-version": APIVersion, 111 } 112 113 preparer := autorest.CreatePreparer( 114 autorest.AsContentType("application/json; charset=utf-8"), 115 autorest.AsPost(), 116 autorest.WithBaseURL(client.BaseURI), 117 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/entities/{entityId}/expand", pathParameters), 118 autorest.WithJSON(parameters), 119 autorest.WithQueryParameters(queryParameters)) 120 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 121} 122 123// ExpandSender sends the Expand request. The method will close the 124// http.Response Body if it receives an error. 125func (client EntitiesClient) ExpandSender(req *http.Request) (*http.Response, error) { 126 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 127 return autorest.SendWithSender(client, req, sd...) 128} 129 130// ExpandResponder handles the response to the Expand request. The method always 131// closes the http.Response Body. 132func (client EntitiesClient) ExpandResponder(resp *http.Response) (result EntityExpandResponse, err error) { 133 err = autorest.Respond( 134 resp, 135 client.ByInspecting(), 136 azure.WithErrorUnlessStatusCode(http.StatusOK), 137 autorest.ByUnmarshallingJSON(&result), 138 autorest.ByClosing()) 139 result.Response = autorest.Response{Response: resp} 140 return 141} 142 143// Get gets an entity. 144// Parameters: 145// resourceGroupName - the name of the resource group within the user's subscription. The name is case 146// insensitive. 147// operationalInsightsResourceProvider - the namespace of workspaces resource provider- 148// Microsoft.OperationalInsights. 149// workspaceName - the name of the workspace. 150// entityID - entity ID 151func (client EntitiesClient) Get(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, entityID string) (result EntityModel, err error) { 152 if tracing.IsEnabled() { 153 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.Get") 154 defer func() { 155 sc := -1 156 if result.Response.Response != nil { 157 sc = result.Response.Response.StatusCode 158 } 159 tracing.EndSpan(ctx, sc, err) 160 }() 161 } 162 if err := validation.Validate([]validation.Validation{ 163 {TargetValue: client.SubscriptionID, 164 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}}}, 165 {TargetValue: resourceGroupName, 166 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 167 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 168 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 169 {TargetValue: workspaceName, 170 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 171 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 172 return result, validation.NewError("securityinsight.EntitiesClient", "Get", err.Error()) 173 } 174 175 req, err := client.GetPreparer(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName, entityID) 176 if err != nil { 177 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "Get", nil, "Failure preparing request") 178 return 179 } 180 181 resp, err := client.GetSender(req) 182 if err != nil { 183 result.Response = autorest.Response{Response: resp} 184 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "Get", resp, "Failure sending request") 185 return 186 } 187 188 result, err = client.GetResponder(resp) 189 if err != nil { 190 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "Get", resp, "Failure responding to request") 191 } 192 193 return 194} 195 196// GetPreparer prepares the Get request. 197func (client EntitiesClient) GetPreparer(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, entityID string) (*http.Request, error) { 198 pathParameters := map[string]interface{}{ 199 "entityId": autorest.Encode("path", entityID), 200 "operationalInsightsResourceProvider": autorest.Encode("path", operationalInsightsResourceProvider), 201 "resourceGroupName": autorest.Encode("path", resourceGroupName), 202 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 203 "workspaceName": autorest.Encode("path", workspaceName), 204 } 205 206 const APIVersion = "2019-01-01-preview" 207 queryParameters := map[string]interface{}{ 208 "api-version": APIVersion, 209 } 210 211 preparer := autorest.CreatePreparer( 212 autorest.AsGet(), 213 autorest.WithBaseURL(client.BaseURI), 214 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/entities/{entityId}", pathParameters), 215 autorest.WithQueryParameters(queryParameters)) 216 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 217} 218 219// GetSender sends the Get request. The method will close the 220// http.Response Body if it receives an error. 221func (client EntitiesClient) GetSender(req *http.Request) (*http.Response, error) { 222 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 223 return autorest.SendWithSender(client, req, sd...) 224} 225 226// GetResponder handles the response to the Get request. The method always 227// closes the http.Response Body. 228func (client EntitiesClient) GetResponder(resp *http.Response) (result EntityModel, err error) { 229 err = autorest.Respond( 230 resp, 231 client.ByInspecting(), 232 azure.WithErrorUnlessStatusCode(http.StatusOK), 233 autorest.ByUnmarshallingJSON(&result), 234 autorest.ByClosing()) 235 result.Response = autorest.Response{Response: resp} 236 return 237} 238 239// List gets all entities. 240// Parameters: 241// resourceGroupName - the name of the resource group within the user's subscription. The name is case 242// insensitive. 243// operationalInsightsResourceProvider - the namespace of workspaces resource provider- 244// Microsoft.OperationalInsights. 245// workspaceName - the name of the workspace. 246func (client EntitiesClient) List(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string) (result EntityListPage, err error) { 247 if tracing.IsEnabled() { 248 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List") 249 defer func() { 250 sc := -1 251 if result.el.Response.Response != nil { 252 sc = result.el.Response.Response.StatusCode 253 } 254 tracing.EndSpan(ctx, sc, err) 255 }() 256 } 257 if err := validation.Validate([]validation.Validation{ 258 {TargetValue: client.SubscriptionID, 259 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}}}, 260 {TargetValue: resourceGroupName, 261 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 262 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 263 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 264 {TargetValue: workspaceName, 265 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 266 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 267 return result, validation.NewError("securityinsight.EntitiesClient", "List", err.Error()) 268 } 269 270 result.fn = client.listNextResults 271 req, err := client.ListPreparer(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName) 272 if err != nil { 273 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "List", nil, "Failure preparing request") 274 return 275 } 276 277 resp, err := client.ListSender(req) 278 if err != nil { 279 result.el.Response = autorest.Response{Response: resp} 280 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "List", resp, "Failure sending request") 281 return 282 } 283 284 result.el, err = client.ListResponder(resp) 285 if err != nil { 286 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "List", resp, "Failure responding to request") 287 } 288 289 return 290} 291 292// ListPreparer prepares the List request. 293func (client EntitiesClient) ListPreparer(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string) (*http.Request, error) { 294 pathParameters := map[string]interface{}{ 295 "operationalInsightsResourceProvider": autorest.Encode("path", operationalInsightsResourceProvider), 296 "resourceGroupName": autorest.Encode("path", resourceGroupName), 297 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 298 "workspaceName": autorest.Encode("path", workspaceName), 299 } 300 301 const APIVersion = "2019-01-01-preview" 302 queryParameters := map[string]interface{}{ 303 "api-version": APIVersion, 304 } 305 306 preparer := autorest.CreatePreparer( 307 autorest.AsGet(), 308 autorest.WithBaseURL(client.BaseURI), 309 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/entities", pathParameters), 310 autorest.WithQueryParameters(queryParameters)) 311 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 312} 313 314// ListSender sends the List request. The method will close the 315// http.Response Body if it receives an error. 316func (client EntitiesClient) ListSender(req *http.Request) (*http.Response, error) { 317 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 318 return autorest.SendWithSender(client, req, sd...) 319} 320 321// ListResponder handles the response to the List request. The method always 322// closes the http.Response Body. 323func (client EntitiesClient) ListResponder(resp *http.Response) (result EntityList, err error) { 324 err = autorest.Respond( 325 resp, 326 client.ByInspecting(), 327 azure.WithErrorUnlessStatusCode(http.StatusOK), 328 autorest.ByUnmarshallingJSON(&result), 329 autorest.ByClosing()) 330 result.Response = autorest.Response{Response: resp} 331 return 332} 333 334// listNextResults retrieves the next set of results, if any. 335func (client EntitiesClient) listNextResults(ctx context.Context, lastResults EntityList) (result EntityList, err error) { 336 req, err := lastResults.entityListPreparer(ctx) 337 if err != nil { 338 return result, autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "listNextResults", nil, "Failure preparing next results request") 339 } 340 if req == nil { 341 return 342 } 343 resp, err := client.ListSender(req) 344 if err != nil { 345 result.Response = autorest.Response{Response: resp} 346 return result, autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "listNextResults", resp, "Failure sending next results request") 347 } 348 result, err = client.ListResponder(resp) 349 if err != nil { 350 err = autorest.NewErrorWithError(err, "securityinsight.EntitiesClient", "listNextResults", resp, "Failure responding to next results request") 351 } 352 return 353} 354 355// ListComplete enumerates all values, automatically crossing page boundaries as required. 356func (client EntitiesClient) ListComplete(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string) (result EntityListIterator, err error) { 357 if tracing.IsEnabled() { 358 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List") 359 defer func() { 360 sc := -1 361 if result.Response().Response.Response != nil { 362 sc = result.page.Response().Response.Response.StatusCode 363 } 364 tracing.EndSpan(ctx, sc, err) 365 }() 366 } 367 result.page, err = client.List(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName) 368 return 369} 370