1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iot
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/iot/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13	"time"
14)
15
16// Lists the findings (results) of a Device Defender audit or of the audits
17// performed during a specified time period. (Findings are retained for 90 days.)
18func (c *Client) ListAuditFindings(ctx context.Context, params *ListAuditFindingsInput, optFns ...func(*Options)) (*ListAuditFindingsOutput, error) {
19	if params == nil {
20		params = &ListAuditFindingsInput{}
21	}
22
23	result, metadata, err := c.invokeOperation(ctx, "ListAuditFindings", params, optFns, addOperationListAuditFindingsMiddlewares)
24	if err != nil {
25		return nil, err
26	}
27
28	out := result.(*ListAuditFindingsOutput)
29	out.ResultMetadata = metadata
30	return out, nil
31}
32
33type ListAuditFindingsInput struct {
34
35	// A filter to limit results to the findings for the specified audit check.
36	CheckName *string
37
38	// A filter to limit results to those found before the specified time. You must
39	// specify either the startTime and endTime or the taskId, but not both.
40	EndTime *time.Time
41
42	// Boolean flag indicating whether only the suppressed findings or the unsuppressed
43	// findings should be listed. If this parameter isn't provided, the response will
44	// list both suppressed and unsuppressed findings.
45	ListSuppressedFindings bool
46
47	// The maximum number of results to return at one time. The default is 25.
48	MaxResults *int32
49
50	// The token for the next set of results.
51	NextToken *string
52
53	// Information identifying the noncompliant resource.
54	ResourceIdentifier *types.ResourceIdentifier
55
56	// A filter to limit results to those found after the specified time. You must
57	// specify either the startTime and endTime or the taskId, but not both.
58	StartTime *time.Time
59
60	// A filter to limit results to the audit with the specified ID. You must specify
61	// either the taskId or the startTime and endTime, but not both.
62	TaskId *string
63}
64
65type ListAuditFindingsOutput struct {
66
67	// The findings (results) of the audit.
68	Findings []types.AuditFinding
69
70	// A token that can be used to retrieve the next set of results, or null if there
71	// are no additional results.
72	NextToken *string
73
74	// Metadata pertaining to the operation's result.
75	ResultMetadata middleware.Metadata
76}
77
78func addOperationListAuditFindingsMiddlewares(stack *middleware.Stack, options Options) (err error) {
79	err = stack.Serialize.Add(&awsRestjson1_serializeOpListAuditFindings{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListAuditFindings{}, middleware.After)
84	if err != nil {
85		return err
86	}
87	if err = addSetLoggerMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
91		return err
92	}
93	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
94		return err
95	}
96	if err = addResolveEndpointMiddleware(stack, options); err != nil {
97		return err
98	}
99	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
100		return err
101	}
102	if err = addRetryMiddlewares(stack, options); err != nil {
103		return err
104	}
105	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
112		return err
113	}
114	if err = addClientUserAgent(stack); err != nil {
115		return err
116	}
117	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAuditFindings(options.Region), middleware.Before); err != nil {
124		return err
125	}
126	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
127		return err
128	}
129	if err = addResponseErrorMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addRequestResponseLogging(stack, options); err != nil {
133		return err
134	}
135	return nil
136}
137
138// ListAuditFindingsAPIClient is a client that implements the ListAuditFindings
139// operation.
140type ListAuditFindingsAPIClient interface {
141	ListAuditFindings(context.Context, *ListAuditFindingsInput, ...func(*Options)) (*ListAuditFindingsOutput, error)
142}
143
144var _ ListAuditFindingsAPIClient = (*Client)(nil)
145
146// ListAuditFindingsPaginatorOptions is the paginator options for ListAuditFindings
147type ListAuditFindingsPaginatorOptions struct {
148	// The maximum number of results to return at one time. The default is 25.
149	Limit int32
150
151	// Set to true if pagination should stop if the service returns a pagination token
152	// that matches the most recent token provided to the service.
153	StopOnDuplicateToken bool
154}
155
156// ListAuditFindingsPaginator is a paginator for ListAuditFindings
157type ListAuditFindingsPaginator struct {
158	options   ListAuditFindingsPaginatorOptions
159	client    ListAuditFindingsAPIClient
160	params    *ListAuditFindingsInput
161	nextToken *string
162	firstPage bool
163}
164
165// NewListAuditFindingsPaginator returns a new ListAuditFindingsPaginator
166func NewListAuditFindingsPaginator(client ListAuditFindingsAPIClient, params *ListAuditFindingsInput, optFns ...func(*ListAuditFindingsPaginatorOptions)) *ListAuditFindingsPaginator {
167	if params == nil {
168		params = &ListAuditFindingsInput{}
169	}
170
171	options := ListAuditFindingsPaginatorOptions{}
172	if params.MaxResults != nil {
173		options.Limit = *params.MaxResults
174	}
175
176	for _, fn := range optFns {
177		fn(&options)
178	}
179
180	return &ListAuditFindingsPaginator{
181		options:   options,
182		client:    client,
183		params:    params,
184		firstPage: true,
185	}
186}
187
188// HasMorePages returns a boolean indicating whether more pages are available
189func (p *ListAuditFindingsPaginator) HasMorePages() bool {
190	return p.firstPage || p.nextToken != nil
191}
192
193// NextPage retrieves the next ListAuditFindings page.
194func (p *ListAuditFindingsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAuditFindingsOutput, error) {
195	if !p.HasMorePages() {
196		return nil, fmt.Errorf("no more pages available")
197	}
198
199	params := *p.params
200	params.NextToken = p.nextToken
201
202	var limit *int32
203	if p.options.Limit > 0 {
204		limit = &p.options.Limit
205	}
206	params.MaxResults = limit
207
208	result, err := p.client.ListAuditFindings(ctx, &params, optFns...)
209	if err != nil {
210		return nil, err
211	}
212	p.firstPage = false
213
214	prevToken := p.nextToken
215	p.nextToken = result.NextToken
216
217	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
218		p.nextToken = nil
219	}
220
221	return result, nil
222}
223
224func newServiceMetadataMiddleware_opListAuditFindings(region string) *awsmiddleware.RegisterServiceMetadata {
225	return &awsmiddleware.RegisterServiceMetadata{
226		Region:        region,
227		ServiceID:     ServiceID,
228		SigningName:   "execute-api",
229		OperationName: "ListAuditFindings",
230	}
231}
232