-
Notifications
You must be signed in to change notification settings - Fork 40
/
method_indicatorslist_autorest.go
235 lines (200 loc) · 7.47 KB
/
method_indicatorslist_autorest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package threatintelligence
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
)
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.
type IndicatorsListOperationResponse struct {
HttpResponse *http.Response
Model *[]ThreatIntelligenceInformation
nextLink *string
nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error)
}
type IndicatorsListCompleteResult struct {
Items []ThreatIntelligenceInformation
}
func (r IndicatorsListOperationResponse) HasMore() bool {
return r.nextLink != nil
}
func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) {
if !r.HasMore() {
err = fmt.Errorf("no more pages returned")
return
}
return r.nextPageFunc(ctx, *r.nextLink)
}
type IndicatorsListOperationOptions struct {
Filter *string
Orderby *string
Top *int64
}
func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions {
return IndicatorsListOperationOptions{}
}
func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} {
out := make(map[string]interface{})
return out
}
func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} {
out := make(map[string]interface{})
if o.Filter != nil {
out["$filter"] = *o.Filter
}
if o.Orderby != nil {
out["$orderby"] = *o.Orderby
}
if o.Top != nil {
out["$top"] = *o.Top
}
return out
}
// IndicatorsList ...
func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) {
req, err := c.preparerForIndicatorsList(ctx, id, options)
if err != nil {
err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request")
return
}
resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client))
if err != nil {
err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request")
return
}
resp, err = c.responderForIndicatorsList(resp.HttpResponse)
if err != nil {
err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request")
return
}
return
}
// preparerForIndicatorsList prepares the IndicatorsList request.
func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) {
queryParameters := map[string]interface{}{
"api-version": defaultApiVersion,
}
for k, v := range options.toQueryString() {
queryParameters[k] = autorest.Encode("query", v)
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/json; charset=utf-8"),
autorest.AsGet(),
autorest.WithBaseURL(c.baseUri),
autorest.WithHeaders(options.toHeaders()),
autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token.
func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) {
uri, err := url.Parse(nextLink)
if err != nil {
return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err)
}
queryParameters := map[string]interface{}{}
for k, v := range uri.Query() {
if len(v) == 0 {
continue
}
val := v[0]
val = autorest.Encode("query", val)
queryParameters[k] = val
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/json; charset=utf-8"),
autorest.AsGet(),
autorest.WithBaseURL(c.baseUri),
autorest.WithPath(uri.Path),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// responderForIndicatorsList handles the response to the IndicatorsList request. The method always
// closes the http.Response Body.
func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) {
type page struct {
Values []json.RawMessage `json:"value"`
NextLink *string `json:"nextLink"`
}
var respObj page
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&respObj),
autorest.ByClosing())
result.HttpResponse = resp
temp := make([]ThreatIntelligenceInformation, 0)
for i, v := range respObj.Values {
val, err := unmarshalThreatIntelligenceInformationImplementation(v)
if err != nil {
err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err)
return result, err
}
temp = append(temp, val)
}
result.Model = &temp
result.nextLink = respObj.NextLink
if respObj.NextLink != nil {
result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) {
req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink)
if err != nil {
err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request")
return
}
result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client))
if err != nil {
err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request")
return
}
result, err = c.responderForIndicatorsList(result.HttpResponse)
if err != nil {
err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request")
return
}
return
}
}
return
}
// IndicatorsListComplete retrieves all of the results into a single object
func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) {
return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{})
}
// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate
func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) {
items := make([]ThreatIntelligenceInformation, 0)
page, err := c.IndicatorsList(ctx, id, options)
if err != nil {
err = fmt.Errorf("loading the initial page: %+v", err)
return
}
if page.Model != nil {
for _, v := range *page.Model {
if predicate.Matches(v) {
items = append(items, v)
}
}
}
for page.HasMore() {
page, err = page.LoadMore(ctx)
if err != nil {
err = fmt.Errorf("loading the next page: %+v", err)
return
}
if page.Model != nil {
for _, v := range *page.Model {
if predicate.Matches(v) {
items = append(items, v)
}
}
}
}
out := IndicatorsListCompleteResult{
Items: items,
}
return out, nil
}