1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package macie2 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/macie2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Retrieves a subset of information about one or more findings. 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 criteria to use to filter the results. 34 FindingCriteria *types.FindingCriteria 35 36 // The maximum number of items to include in each page of the response. 37 MaxResults int32 38 39 // The nextToken string that specifies which page of results to return in a 40 // paginated response. 41 NextToken *string 42 43 // The criteria to use to sort the results. 44 SortCriteria *types.SortCriteria 45} 46 47type ListFindingsOutput struct { 48 49 // An array of strings, where each string is the unique identifier for a finding 50 // that meets the filter criteria specified in the request. 51 FindingIds []string 52 53 // The string to use in a subsequent request to get the next page of results in a 54 // paginated response. This value is null if there are no additional pages. 55 NextToken *string 56 57 // Metadata pertaining to the operation's result. 58 ResultMetadata middleware.Metadata 59} 60 61func addOperationListFindingsMiddlewares(stack *middleware.Stack, options Options) (err error) { 62 err = stack.Serialize.Add(&awsRestjson1_serializeOpListFindings{}, middleware.After) 63 if err != nil { 64 return err 65 } 66 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListFindings{}, middleware.After) 67 if err != nil { 68 return err 69 } 70 if err = addSetLoggerMiddleware(stack, options); err != nil { 71 return err 72 } 73 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 74 return err 75 } 76 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 77 return err 78 } 79 if err = addResolveEndpointMiddleware(stack, options); err != nil { 80 return err 81 } 82 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 83 return err 84 } 85 if err = addRetryMiddlewares(stack, options); err != nil { 86 return err 87 } 88 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 89 return err 90 } 91 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 92 return err 93 } 94 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 95 return err 96 } 97 if err = addClientUserAgent(stack); err != nil { 98 return err 99 } 100 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 101 return err 102 } 103 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 104 return err 105 } 106 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListFindings(options.Region), middleware.Before); err != nil { 107 return err 108 } 109 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 110 return err 111 } 112 if err = addResponseErrorMiddleware(stack); err != nil { 113 return err 114 } 115 if err = addRequestResponseLogging(stack, options); err != nil { 116 return err 117 } 118 return nil 119} 120 121// ListFindingsAPIClient is a client that implements the ListFindings operation. 122type ListFindingsAPIClient interface { 123 ListFindings(context.Context, *ListFindingsInput, ...func(*Options)) (*ListFindingsOutput, error) 124} 125 126var _ ListFindingsAPIClient = (*Client)(nil) 127 128// ListFindingsPaginatorOptions is the paginator options for ListFindings 129type ListFindingsPaginatorOptions struct { 130 // The maximum number of items to include in each page of the response. 131 Limit int32 132 133 // Set to true if pagination should stop if the service returns a pagination token 134 // that matches the most recent token provided to the service. 135 StopOnDuplicateToken bool 136} 137 138// ListFindingsPaginator is a paginator for ListFindings 139type ListFindingsPaginator struct { 140 options ListFindingsPaginatorOptions 141 client ListFindingsAPIClient 142 params *ListFindingsInput 143 nextToken *string 144 firstPage bool 145} 146 147// NewListFindingsPaginator returns a new ListFindingsPaginator 148func NewListFindingsPaginator(client ListFindingsAPIClient, params *ListFindingsInput, optFns ...func(*ListFindingsPaginatorOptions)) *ListFindingsPaginator { 149 options := ListFindingsPaginatorOptions{} 150 if params.MaxResults != 0 { 151 options.Limit = params.MaxResults 152 } 153 154 for _, fn := range optFns { 155 fn(&options) 156 } 157 158 if params == nil { 159 params = &ListFindingsInput{} 160 } 161 162 return &ListFindingsPaginator{ 163 options: options, 164 client: client, 165 params: params, 166 firstPage: true, 167 } 168} 169 170// HasMorePages returns a boolean indicating whether more pages are available 171func (p *ListFindingsPaginator) HasMorePages() bool { 172 return p.firstPage || p.nextToken != nil 173} 174 175// NextPage retrieves the next ListFindings page. 176func (p *ListFindingsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListFindingsOutput, error) { 177 if !p.HasMorePages() { 178 return nil, fmt.Errorf("no more pages available") 179 } 180 181 params := *p.params 182 params.NextToken = p.nextToken 183 184 params.MaxResults = p.options.Limit 185 186 result, err := p.client.ListFindings(ctx, ¶ms, optFns...) 187 if err != nil { 188 return nil, err 189 } 190 p.firstPage = false 191 192 prevToken := p.nextToken 193 p.nextToken = result.NextToken 194 195 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 196 p.nextToken = nil 197 } 198 199 return result, nil 200} 201 202func newServiceMetadataMiddleware_opListFindings(region string) *awsmiddleware.RegisterServiceMetadata { 203 return &awsmiddleware.RegisterServiceMetadata{ 204 Region: region, 205 ServiceID: ServiceID, 206 SigningName: "macie2", 207 OperationName: "ListFindings", 208 } 209} 210