1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package guardduty
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/guardduty/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists Amazon GuardDuty findings for the specified detector ID.
16func (c *Client) ListFindings(ctx context.Context, params *ListFindingsInput, optFns ...func(*Options)) (*ListFindingsOutput, error) {
17	if params == nil {
18		params = &ListFindingsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListFindings", params, optFns, addOperationListFindingsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListFindingsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListFindingsInput struct {
32
33	// The ID of the detector that specifies the GuardDuty service whose findings you
34	// want to list.
35	//
36	// This member is required.
37	DetectorId *string
38
39	// Represents the criteria used for querying findings. Valid values include:
40	//
41	// *
42	// JSON field name
43	//
44	// * accountId
45	//
46	// * region
47	//
48	// * confidence
49	//
50	// * id
51	//
52	// *
53	// resource.accessKeyDetails.accessKeyId
54	//
55	// *
56	// resource.accessKeyDetails.principalId
57	//
58	// * resource.accessKeyDetails.userName
59	//
60	// *
61	// resource.accessKeyDetails.userType
62	//
63	// *
64	// resource.instanceDetails.iamInstanceProfile.id
65	//
66	// *
67	// resource.instanceDetails.imageId
68	//
69	// * resource.instanceDetails.instanceId
70	//
71	// *
72	// resource.instanceDetails.networkInterfaces.ipv6Addresses
73	//
74	// *
75	// resource.instanceDetails.networkInterfaces.privateIpAddresses.privateIpAddress
76	//
77	// *
78	// resource.instanceDetails.networkInterfaces.publicDnsName
79	//
80	// *
81	// resource.instanceDetails.networkInterfaces.publicIp
82	//
83	// *
84	// resource.instanceDetails.networkInterfaces.securityGroups.groupId
85	//
86	// *
87	// resource.instanceDetails.networkInterfaces.securityGroups.groupName
88	//
89	// *
90	// resource.instanceDetails.networkInterfaces.subnetId
91	//
92	// *
93	// resource.instanceDetails.networkInterfaces.vpcId
94	//
95	// *
96	// resource.instanceDetails.tags.key
97	//
98	// * resource.instanceDetails.tags.value
99	//
100	// *
101	// resource.resourceType
102	//
103	// * service.action.actionType
104	//
105	// *
106	// service.action.awsApiCallAction.api
107	//
108	// *
109	// service.action.awsApiCallAction.callerType
110	//
111	// *
112	// service.action.awsApiCallAction.remoteIpDetails.city.cityName
113	//
114	// *
115	// service.action.awsApiCallAction.remoteIpDetails.country.countryName
116	//
117	// *
118	// service.action.awsApiCallAction.remoteIpDetails.ipAddressV4
119	//
120	// *
121	// service.action.awsApiCallAction.remoteIpDetails.organization.asn
122	//
123	// *
124	// service.action.awsApiCallAction.remoteIpDetails.organization.asnOrg
125	//
126	// *
127	// service.action.awsApiCallAction.serviceName
128	//
129	// *
130	// service.action.dnsRequestAction.domain
131	//
132	// *
133	// service.action.networkConnectionAction.blocked
134	//
135	// *
136	// service.action.networkConnectionAction.connectionDirection
137	//
138	// *
139	// service.action.networkConnectionAction.localPortDetails.port
140	//
141	// *
142	// service.action.networkConnectionAction.protocol
143	//
144	// *
145	// service.action.networkConnectionAction.remoteIpDetails.city.cityName
146	//
147	// *
148	// service.action.networkConnectionAction.remoteIpDetails.country.countryName
149	//
150	// *
151	// service.action.networkConnectionAction.remoteIpDetails.ipAddressV4
152	//
153	// *
154	// service.action.networkConnectionAction.remoteIpDetails.organization.asn
155	//
156	// *
157	// service.action.networkConnectionAction.remoteIpDetails.organization.asnOrg
158	//
159	// *
160	// service.action.networkConnectionAction.remotePortDetails.port
161	//
162	// *
163	// service.additionalInfo.threatListName
164	//
165	// * service.archived When this attribute is
166	// set to 'true', only archived findings are listed. When it's set to 'false', only
167	// unarchived findings are listed. When this attribute is not set, all existing
168	// findings are listed.
169	//
170	// * service.resourceRole
171	//
172	// * severity
173	//
174	// * type
175	//
176	// * updatedAt
177	// Type: Timestamp in Unix Epoch millisecond format: 1486685375000
178	FindingCriteria *types.FindingCriteria
179
180	// You can use this parameter to indicate the maximum number of items you want in
181	// the response. The default value is 50. The maximum value is 50.
182	MaxResults int32
183
184	// You can use this parameter when paginating results. Set the value of this
185	// parameter to null on your first call to the list action. For subsequent calls to
186	// the action, fill nextToken in the request with the value of NextToken from the
187	// previous response to continue listing data.
188	NextToken *string
189
190	// Represents the criteria used for sorting findings.
191	SortCriteria *types.SortCriteria
192}
193
194type ListFindingsOutput struct {
195
196	// The IDs of the findings that you're listing.
197	//
198	// This member is required.
199	FindingIds []string
200
201	// The pagination parameter to be used on the next list operation to retrieve more
202	// items.
203	NextToken *string
204
205	// Metadata pertaining to the operation's result.
206	ResultMetadata middleware.Metadata
207}
208
209func addOperationListFindingsMiddlewares(stack *middleware.Stack, options Options) (err error) {
210	err = stack.Serialize.Add(&awsRestjson1_serializeOpListFindings{}, middleware.After)
211	if err != nil {
212		return err
213	}
214	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListFindings{}, middleware.After)
215	if err != nil {
216		return err
217	}
218	if err = addSetLoggerMiddleware(stack, options); err != nil {
219		return err
220	}
221	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
222		return err
223	}
224	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
225		return err
226	}
227	if err = addResolveEndpointMiddleware(stack, options); err != nil {
228		return err
229	}
230	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
231		return err
232	}
233	if err = addRetryMiddlewares(stack, options); err != nil {
234		return err
235	}
236	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
237		return err
238	}
239	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
240		return err
241	}
242	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
243		return err
244	}
245	if err = addClientUserAgent(stack); err != nil {
246		return err
247	}
248	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
249		return err
250	}
251	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
252		return err
253	}
254	if err = addOpListFindingsValidationMiddleware(stack); err != nil {
255		return err
256	}
257	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListFindings(options.Region), middleware.Before); err != nil {
258		return err
259	}
260	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
261		return err
262	}
263	if err = addResponseErrorMiddleware(stack); err != nil {
264		return err
265	}
266	if err = addRequestResponseLogging(stack, options); err != nil {
267		return err
268	}
269	return nil
270}
271
272// ListFindingsAPIClient is a client that implements the ListFindings operation.
273type ListFindingsAPIClient interface {
274	ListFindings(context.Context, *ListFindingsInput, ...func(*Options)) (*ListFindingsOutput, error)
275}
276
277var _ ListFindingsAPIClient = (*Client)(nil)
278
279// ListFindingsPaginatorOptions is the paginator options for ListFindings
280type ListFindingsPaginatorOptions struct {
281	// You can use this parameter to indicate the maximum number of items you want in
282	// the response. The default value is 50. The maximum value is 50.
283	Limit int32
284
285	// Set to true if pagination should stop if the service returns a pagination token
286	// that matches the most recent token provided to the service.
287	StopOnDuplicateToken bool
288}
289
290// ListFindingsPaginator is a paginator for ListFindings
291type ListFindingsPaginator struct {
292	options   ListFindingsPaginatorOptions
293	client    ListFindingsAPIClient
294	params    *ListFindingsInput
295	nextToken *string
296	firstPage bool
297}
298
299// NewListFindingsPaginator returns a new ListFindingsPaginator
300func NewListFindingsPaginator(client ListFindingsAPIClient, params *ListFindingsInput, optFns ...func(*ListFindingsPaginatorOptions)) *ListFindingsPaginator {
301	if params == nil {
302		params = &ListFindingsInput{}
303	}
304
305	options := ListFindingsPaginatorOptions{}
306	if params.MaxResults != 0 {
307		options.Limit = params.MaxResults
308	}
309
310	for _, fn := range optFns {
311		fn(&options)
312	}
313
314	return &ListFindingsPaginator{
315		options:   options,
316		client:    client,
317		params:    params,
318		firstPage: true,
319	}
320}
321
322// HasMorePages returns a boolean indicating whether more pages are available
323func (p *ListFindingsPaginator) HasMorePages() bool {
324	return p.firstPage || p.nextToken != nil
325}
326
327// NextPage retrieves the next ListFindings page.
328func (p *ListFindingsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListFindingsOutput, error) {
329	if !p.HasMorePages() {
330		return nil, fmt.Errorf("no more pages available")
331	}
332
333	params := *p.params
334	params.NextToken = p.nextToken
335
336	params.MaxResults = p.options.Limit
337
338	result, err := p.client.ListFindings(ctx, &params, optFns...)
339	if err != nil {
340		return nil, err
341	}
342	p.firstPage = false
343
344	prevToken := p.nextToken
345	p.nextToken = result.NextToken
346
347	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
348		p.nextToken = nil
349	}
350
351	return result, nil
352}
353
354func newServiceMetadataMiddleware_opListFindings(region string) *awsmiddleware.RegisterServiceMetadata {
355	return &awsmiddleware.RegisterServiceMetadata{
356		Region:        region,
357		ServiceID:     ServiceID,
358		SigningName:   "guardduty",
359		OperationName: "ListFindings",
360	}
361}
362