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// ThreatIntelligenceIndicatorsClient is the API spec for Microsoft.SecurityInsights (Azure Security Insights) resource 19// provider 20type ThreatIntelligenceIndicatorsClient struct { 21 BaseClient 22} 23 24// NewThreatIntelligenceIndicatorsClient creates an instance of the ThreatIntelligenceIndicatorsClient client. 25func NewThreatIntelligenceIndicatorsClient(subscriptionID string) ThreatIntelligenceIndicatorsClient { 26 return NewThreatIntelligenceIndicatorsClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewThreatIntelligenceIndicatorsClientWithBaseURI creates an instance of the ThreatIntelligenceIndicatorsClient 30// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 31// (sovereign clouds, Azure stack). 32func NewThreatIntelligenceIndicatorsClientWithBaseURI(baseURI string, subscriptionID string) ThreatIntelligenceIndicatorsClient { 33 return ThreatIntelligenceIndicatorsClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// List get all threat intelligence indicators. 37// Parameters: 38// resourceGroupName - the name of the resource group within the user's subscription. The name is case 39// insensitive. 40// operationalInsightsResourceProvider - the namespace of workspaces resource provider- 41// Microsoft.OperationalInsights. 42// workspaceName - the name of the workspace. 43// filter - filters the results, based on a Boolean condition. Optional. 44// top - returns only the first n results. Optional. 45// skipToken - skiptoken is only used if a previous operation returned a partial result. If a previous response 46// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that 47// specifies a starting point to use for subsequent calls. Optional. 48// orderby - sorts the results. Optional. 49func (client ThreatIntelligenceIndicatorsClient) List(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, filter string, top *int32, skipToken string, orderby string) (result ThreatIntelligenceInformationListPage, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/ThreatIntelligenceIndicatorsClient.List") 52 defer func() { 53 sc := -1 54 if result.tiil.Response.Response != nil { 55 sc = result.tiil.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 if err := validation.Validate([]validation.Validation{ 61 {TargetValue: client.SubscriptionID, 62 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}}}, 63 {TargetValue: resourceGroupName, 64 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 65 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 67 {TargetValue: workspaceName, 68 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 69 {Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 70 return result, validation.NewError("securityinsight.ThreatIntelligenceIndicatorsClient", "List", err.Error()) 71 } 72 73 result.fn = client.listNextResults 74 req, err := client.ListPreparer(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName, filter, top, skipToken, orderby) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "securityinsight.ThreatIntelligenceIndicatorsClient", "List", nil, "Failure preparing request") 77 return 78 } 79 80 resp, err := client.ListSender(req) 81 if err != nil { 82 result.tiil.Response = autorest.Response{Response: resp} 83 err = autorest.NewErrorWithError(err, "securityinsight.ThreatIntelligenceIndicatorsClient", "List", resp, "Failure sending request") 84 return 85 } 86 87 result.tiil, err = client.ListResponder(resp) 88 if err != nil { 89 err = autorest.NewErrorWithError(err, "securityinsight.ThreatIntelligenceIndicatorsClient", "List", resp, "Failure responding to request") 90 return 91 } 92 if result.tiil.hasNextLink() && result.tiil.IsEmpty() { 93 err = result.NextWithContext(ctx) 94 return 95 } 96 97 return 98} 99 100// ListPreparer prepares the List request. 101func (client ThreatIntelligenceIndicatorsClient) ListPreparer(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, filter string, top *int32, skipToken string, orderby string) (*http.Request, error) { 102 pathParameters := map[string]interface{}{ 103 "operationalInsightsResourceProvider": autorest.Encode("path", operationalInsightsResourceProvider), 104 "resourceGroupName": autorest.Encode("path", resourceGroupName), 105 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 106 "workspaceName": autorest.Encode("path", workspaceName), 107 } 108 109 const APIVersion = "2019-01-01-preview" 110 queryParameters := map[string]interface{}{ 111 "api-version": APIVersion, 112 } 113 if len(filter) > 0 { 114 queryParameters["$filter"] = autorest.Encode("query", filter) 115 } 116 if top != nil { 117 queryParameters["$top"] = autorest.Encode("query", *top) 118 } 119 if len(skipToken) > 0 { 120 queryParameters["$skipToken"] = autorest.Encode("query", skipToken) 121 } 122 if len(orderby) > 0 { 123 queryParameters["$orderby"] = autorest.Encode("query", orderby) 124 } 125 126 preparer := autorest.CreatePreparer( 127 autorest.AsGet(), 128 autorest.WithBaseURL(client.BaseURI), 129 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", pathParameters), 130 autorest.WithQueryParameters(queryParameters)) 131 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 132} 133 134// ListSender sends the List request. The method will close the 135// http.Response Body if it receives an error. 136func (client ThreatIntelligenceIndicatorsClient) ListSender(req *http.Request) (*http.Response, error) { 137 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 138} 139 140// ListResponder handles the response to the List request. The method always 141// closes the http.Response Body. 142func (client ThreatIntelligenceIndicatorsClient) ListResponder(resp *http.Response) (result ThreatIntelligenceInformationList, err error) { 143 err = autorest.Respond( 144 resp, 145 azure.WithErrorUnlessStatusCode(http.StatusOK), 146 autorest.ByUnmarshallingJSON(&result), 147 autorest.ByClosing()) 148 result.Response = autorest.Response{Response: resp} 149 return 150} 151 152// listNextResults retrieves the next set of results, if any. 153func (client ThreatIntelligenceIndicatorsClient) listNextResults(ctx context.Context, lastResults ThreatIntelligenceInformationList) (result ThreatIntelligenceInformationList, err error) { 154 req, err := lastResults.threatIntelligenceInformationListPreparer(ctx) 155 if err != nil { 156 return result, autorest.NewErrorWithError(err, "securityinsight.ThreatIntelligenceIndicatorsClient", "listNextResults", nil, "Failure preparing next results request") 157 } 158 if req == nil { 159 return 160 } 161 resp, err := client.ListSender(req) 162 if err != nil { 163 result.Response = autorest.Response{Response: resp} 164 return result, autorest.NewErrorWithError(err, "securityinsight.ThreatIntelligenceIndicatorsClient", "listNextResults", resp, "Failure sending next results request") 165 } 166 result, err = client.ListResponder(resp) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "securityinsight.ThreatIntelligenceIndicatorsClient", "listNextResults", resp, "Failure responding to next results request") 169 } 170 return 171} 172 173// ListComplete enumerates all values, automatically crossing page boundaries as required. 174func (client ThreatIntelligenceIndicatorsClient) ListComplete(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, filter string, top *int32, skipToken string, orderby string) (result ThreatIntelligenceInformationListIterator, err error) { 175 if tracing.IsEnabled() { 176 ctx = tracing.StartSpan(ctx, fqdn+"/ThreatIntelligenceIndicatorsClient.List") 177 defer func() { 178 sc := -1 179 if result.Response().Response.Response != nil { 180 sc = result.page.Response().Response.Response.StatusCode 181 } 182 tracing.EndSpan(ctx, sc, err) 183 }() 184 } 185 result.page, err = client.List(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName, filter, top, skipToken, orderby) 186 return 187} 188