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// SoftwareInventoriesClient is the API spec for Microsoft.Security (Azure Security Center) resource provider 19type SoftwareInventoriesClient struct { 20 BaseClient 21} 22 23// NewSoftwareInventoriesClient creates an instance of the SoftwareInventoriesClient client. 24func NewSoftwareInventoriesClient(subscriptionID string, ascLocation string) SoftwareInventoriesClient { 25 return NewSoftwareInventoriesClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation) 26} 27 28// NewSoftwareInventoriesClientWithBaseURI creates an instance of the SoftwareInventoriesClient 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 NewSoftwareInventoriesClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) SoftwareInventoriesClient { 32 return SoftwareInventoriesClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)} 33} 34 35// Get gets a single software data of the virtual machine. 36// Parameters: 37// resourceGroupName - the name of the resource group within the user's subscription. The name is case 38// insensitive. 39// resourceNamespace - the namespace of the resource. 40// resourceType - the type of the resource. 41// resourceName - name of the resource. 42// softwareName - name of the installed software. 43func (client SoftwareInventoriesClient) Get(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, softwareName string) (result Software, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareInventoriesClient.Get") 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}}}}); err != nil { 61 return result, validation.NewError("security.SoftwareInventoriesClient", "Get", err.Error()) 62 } 63 64 req, err := client.GetPreparer(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName, softwareName) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "Get", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.GetSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "Get", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.GetResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "Get", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// GetPreparer prepares the Get request. 87func (client SoftwareInventoriesClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, softwareName string) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "resourceGroupName": autorest.Encode("path", resourceGroupName), 90 "resourceName": autorest.Encode("path", resourceName), 91 "resourceNamespace": autorest.Encode("path", resourceNamespace), 92 "resourceType": autorest.Encode("path", resourceType), 93 "softwareName": autorest.Encode("path", softwareName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 } 96 97 const APIVersion = "2021-05-01-preview" 98 queryParameters := map[string]interface{}{ 99 "api-version": APIVersion, 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsGet(), 104 autorest.WithBaseURL(client.BaseURI), 105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.Security/softwareInventories/{softwareName}", pathParameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// GetSender sends the Get request. The method will close the 111// http.Response Body if it receives an error. 112func (client SoftwareInventoriesClient) GetSender(req *http.Request) (*http.Response, error) { 113 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 114} 115 116// GetResponder handles the response to the Get request. The method always 117// closes the http.Response Body. 118func (client SoftwareInventoriesClient) GetResponder(resp *http.Response) (result Software, err error) { 119 err = autorest.Respond( 120 resp, 121 azure.WithErrorUnlessStatusCode(http.StatusOK), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127 128// ListByExtendedResource gets the software inventory of the virtual machine. 129// Parameters: 130// resourceGroupName - the name of the resource group within the user's subscription. The name is case 131// insensitive. 132// resourceNamespace - the namespace of the resource. 133// resourceType - the type of the resource. 134// resourceName - name of the resource. 135func (client SoftwareInventoriesClient) ListByExtendedResource(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string) (result SoftwaresListPage, err error) { 136 if tracing.IsEnabled() { 137 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareInventoriesClient.ListByExtendedResource") 138 defer func() { 139 sc := -1 140 if result.sl.Response.Response != nil { 141 sc = result.sl.Response.Response.StatusCode 142 } 143 tracing.EndSpan(ctx, sc, err) 144 }() 145 } 146 if err := validation.Validate([]validation.Validation{ 147 {TargetValue: client.SubscriptionID, 148 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}}}, 149 {TargetValue: resourceGroupName, 150 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 151 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 152 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 153 return result, validation.NewError("security.SoftwareInventoriesClient", "ListByExtendedResource", err.Error()) 154 } 155 156 result.fn = client.listByExtendedResourceNextResults 157 req, err := client.ListByExtendedResourcePreparer(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "ListByExtendedResource", nil, "Failure preparing request") 160 return 161 } 162 163 resp, err := client.ListByExtendedResourceSender(req) 164 if err != nil { 165 result.sl.Response = autorest.Response{Response: resp} 166 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "ListByExtendedResource", resp, "Failure sending request") 167 return 168 } 169 170 result.sl, err = client.ListByExtendedResourceResponder(resp) 171 if err != nil { 172 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "ListByExtendedResource", resp, "Failure responding to request") 173 return 174 } 175 if result.sl.hasNextLink() && result.sl.IsEmpty() { 176 err = result.NextWithContext(ctx) 177 return 178 } 179 180 return 181} 182 183// ListByExtendedResourcePreparer prepares the ListByExtendedResource request. 184func (client SoftwareInventoriesClient) ListByExtendedResourcePreparer(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string) (*http.Request, error) { 185 pathParameters := map[string]interface{}{ 186 "resourceGroupName": autorest.Encode("path", resourceGroupName), 187 "resourceName": autorest.Encode("path", resourceName), 188 "resourceNamespace": autorest.Encode("path", resourceNamespace), 189 "resourceType": autorest.Encode("path", resourceType), 190 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 191 } 192 193 const APIVersion = "2021-05-01-preview" 194 queryParameters := map[string]interface{}{ 195 "api-version": APIVersion, 196 } 197 198 preparer := autorest.CreatePreparer( 199 autorest.AsGet(), 200 autorest.WithBaseURL(client.BaseURI), 201 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.Security/softwareInventories", pathParameters), 202 autorest.WithQueryParameters(queryParameters)) 203 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 204} 205 206// ListByExtendedResourceSender sends the ListByExtendedResource request. The method will close the 207// http.Response Body if it receives an error. 208func (client SoftwareInventoriesClient) ListByExtendedResourceSender(req *http.Request) (*http.Response, error) { 209 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 210} 211 212// ListByExtendedResourceResponder handles the response to the ListByExtendedResource request. The method always 213// closes the http.Response Body. 214func (client SoftwareInventoriesClient) ListByExtendedResourceResponder(resp *http.Response) (result SoftwaresList, err error) { 215 err = autorest.Respond( 216 resp, 217 azure.WithErrorUnlessStatusCode(http.StatusOK), 218 autorest.ByUnmarshallingJSON(&result), 219 autorest.ByClosing()) 220 result.Response = autorest.Response{Response: resp} 221 return 222} 223 224// listByExtendedResourceNextResults retrieves the next set of results, if any. 225func (client SoftwareInventoriesClient) listByExtendedResourceNextResults(ctx context.Context, lastResults SoftwaresList) (result SoftwaresList, err error) { 226 req, err := lastResults.softwaresListPreparer(ctx) 227 if err != nil { 228 return result, autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "listByExtendedResourceNextResults", nil, "Failure preparing next results request") 229 } 230 if req == nil { 231 return 232 } 233 resp, err := client.ListByExtendedResourceSender(req) 234 if err != nil { 235 result.Response = autorest.Response{Response: resp} 236 return result, autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "listByExtendedResourceNextResults", resp, "Failure sending next results request") 237 } 238 result, err = client.ListByExtendedResourceResponder(resp) 239 if err != nil { 240 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "listByExtendedResourceNextResults", resp, "Failure responding to next results request") 241 } 242 return 243} 244 245// ListByExtendedResourceComplete enumerates all values, automatically crossing page boundaries as required. 246func (client SoftwareInventoriesClient) ListByExtendedResourceComplete(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string) (result SoftwaresListIterator, err error) { 247 if tracing.IsEnabled() { 248 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareInventoriesClient.ListByExtendedResource") 249 defer func() { 250 sc := -1 251 if result.Response().Response.Response != nil { 252 sc = result.page.Response().Response.Response.StatusCode 253 } 254 tracing.EndSpan(ctx, sc, err) 255 }() 256 } 257 result.page, err = client.ListByExtendedResource(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName) 258 return 259} 260 261// ListBySubscription gets the software inventory of all virtual machines in the subscriptions. 262func (client SoftwareInventoriesClient) ListBySubscription(ctx context.Context) (result SoftwaresListPage, err error) { 263 if tracing.IsEnabled() { 264 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareInventoriesClient.ListBySubscription") 265 defer func() { 266 sc := -1 267 if result.sl.Response.Response != nil { 268 sc = result.sl.Response.Response.StatusCode 269 } 270 tracing.EndSpan(ctx, sc, err) 271 }() 272 } 273 if err := validation.Validate([]validation.Validation{ 274 {TargetValue: client.SubscriptionID, 275 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 { 276 return result, validation.NewError("security.SoftwareInventoriesClient", "ListBySubscription", err.Error()) 277 } 278 279 result.fn = client.listBySubscriptionNextResults 280 req, err := client.ListBySubscriptionPreparer(ctx) 281 if err != nil { 282 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "ListBySubscription", nil, "Failure preparing request") 283 return 284 } 285 286 resp, err := client.ListBySubscriptionSender(req) 287 if err != nil { 288 result.sl.Response = autorest.Response{Response: resp} 289 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "ListBySubscription", resp, "Failure sending request") 290 return 291 } 292 293 result.sl, err = client.ListBySubscriptionResponder(resp) 294 if err != nil { 295 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "ListBySubscription", resp, "Failure responding to request") 296 return 297 } 298 if result.sl.hasNextLink() && result.sl.IsEmpty() { 299 err = result.NextWithContext(ctx) 300 return 301 } 302 303 return 304} 305 306// ListBySubscriptionPreparer prepares the ListBySubscription request. 307func (client SoftwareInventoriesClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { 308 pathParameters := map[string]interface{}{ 309 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 310 } 311 312 const APIVersion = "2021-05-01-preview" 313 queryParameters := map[string]interface{}{ 314 "api-version": APIVersion, 315 } 316 317 preparer := autorest.CreatePreparer( 318 autorest.AsGet(), 319 autorest.WithBaseURL(client.BaseURI), 320 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/softwareInventories", pathParameters), 321 autorest.WithQueryParameters(queryParameters)) 322 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 323} 324 325// ListBySubscriptionSender sends the ListBySubscription request. The method will close the 326// http.Response Body if it receives an error. 327func (client SoftwareInventoriesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { 328 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 329} 330 331// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always 332// closes the http.Response Body. 333func (client SoftwareInventoriesClient) ListBySubscriptionResponder(resp *http.Response) (result SoftwaresList, err error) { 334 err = autorest.Respond( 335 resp, 336 azure.WithErrorUnlessStatusCode(http.StatusOK), 337 autorest.ByUnmarshallingJSON(&result), 338 autorest.ByClosing()) 339 result.Response = autorest.Response{Response: resp} 340 return 341} 342 343// listBySubscriptionNextResults retrieves the next set of results, if any. 344func (client SoftwareInventoriesClient) listBySubscriptionNextResults(ctx context.Context, lastResults SoftwaresList) (result SoftwaresList, err error) { 345 req, err := lastResults.softwaresListPreparer(ctx) 346 if err != nil { 347 return result, autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request") 348 } 349 if req == nil { 350 return 351 } 352 resp, err := client.ListBySubscriptionSender(req) 353 if err != nil { 354 result.Response = autorest.Response{Response: resp} 355 return result, autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "listBySubscriptionNextResults", resp, "Failure sending next results request") 356 } 357 result, err = client.ListBySubscriptionResponder(resp) 358 if err != nil { 359 err = autorest.NewErrorWithError(err, "security.SoftwareInventoriesClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request") 360 } 361 return 362} 363 364// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required. 365func (client SoftwareInventoriesClient) ListBySubscriptionComplete(ctx context.Context) (result SoftwaresListIterator, err error) { 366 if tracing.IsEnabled() { 367 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareInventoriesClient.ListBySubscription") 368 defer func() { 369 sc := -1 370 if result.Response().Response.Response != nil { 371 sc = result.page.Response().Response.Response.StatusCode 372 } 373 tracing.EndSpan(ctx, sc, err) 374 }() 375 } 376 result.page, err = client.ListBySubscription(ctx) 377 return 378} 379