1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package inspector
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/inspector/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the assessment runs that correspond to the assessment templates that are
16// specified by the ARNs of the assessment templates.
17func (c *Client) ListAssessmentRuns(ctx context.Context, params *ListAssessmentRunsInput, optFns ...func(*Options)) (*ListAssessmentRunsOutput, error) {
18	if params == nil {
19		params = &ListAssessmentRunsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListAssessmentRuns", params, optFns, addOperationListAssessmentRunsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListAssessmentRunsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListAssessmentRunsInput struct {
33
34	// The ARNs that specify the assessment templates whose assessment runs you want to
35	// list.
36	AssessmentTemplateArns []string
37
38	// You can use this parameter to specify a subset of data to be included in the
39	// action's response. For a record to match a filter, all specified filter
40	// attributes must match. When multiple values are specified for a filter
41	// attribute, any of the values can match.
42	Filter *types.AssessmentRunFilter
43
44	// You can use this parameter to indicate the maximum number of items that you want
45	// in the response. The default value is 10. The maximum value is 500.
46	MaxResults *int32
47
48	// You can use this parameter when paginating results. Set the value of this
49	// parameter to null on your first call to the ListAssessmentRuns action.
50	// Subsequent calls to the action fill nextToken in the request with the value of
51	// NextToken from the previous response to continue listing data.
52	NextToken *string
53}
54
55type ListAssessmentRunsOutput struct {
56
57	// A list of ARNs that specifies the assessment runs that are returned by the
58	// action.
59	//
60	// This member is required.
61	AssessmentRunArns []string
62
63	// When a response is generated, if there is more data to be listed, this parameter
64	// is present in the response and contains the value to use for the nextToken
65	// parameter in a subsequent pagination request. If there is no more data to be
66	// listed, this parameter is set to null.
67	NextToken *string
68
69	// Metadata pertaining to the operation's result.
70	ResultMetadata middleware.Metadata
71}
72
73func addOperationListAssessmentRunsMiddlewares(stack *middleware.Stack, options Options) (err error) {
74	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListAssessmentRuns{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListAssessmentRuns{}, middleware.After)
79	if err != nil {
80		return err
81	}
82	if err = addSetLoggerMiddleware(stack, options); err != nil {
83		return err
84	}
85	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
86		return err
87	}
88	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
89		return err
90	}
91	if err = addResolveEndpointMiddleware(stack, options); err != nil {
92		return err
93	}
94	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
95		return err
96	}
97	if err = addRetryMiddlewares(stack, options); err != nil {
98		return err
99	}
100	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
101		return err
102	}
103	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
107		return err
108	}
109	if err = addClientUserAgent(stack); err != nil {
110		return err
111	}
112	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAssessmentRuns(options.Region), middleware.Before); err != nil {
119		return err
120	}
121	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addResponseErrorMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addRequestResponseLogging(stack, options); err != nil {
128		return err
129	}
130	return nil
131}
132
133// ListAssessmentRunsAPIClient is a client that implements the ListAssessmentRuns
134// operation.
135type ListAssessmentRunsAPIClient interface {
136	ListAssessmentRuns(context.Context, *ListAssessmentRunsInput, ...func(*Options)) (*ListAssessmentRunsOutput, error)
137}
138
139var _ ListAssessmentRunsAPIClient = (*Client)(nil)
140
141// ListAssessmentRunsPaginatorOptions is the paginator options for
142// ListAssessmentRuns
143type ListAssessmentRunsPaginatorOptions struct {
144	// You can use this parameter to indicate the maximum number of items that you want
145	// in the response. The default value is 10. The maximum value is 500.
146	Limit int32
147
148	// Set to true if pagination should stop if the service returns a pagination token
149	// that matches the most recent token provided to the service.
150	StopOnDuplicateToken bool
151}
152
153// ListAssessmentRunsPaginator is a paginator for ListAssessmentRuns
154type ListAssessmentRunsPaginator struct {
155	options   ListAssessmentRunsPaginatorOptions
156	client    ListAssessmentRunsAPIClient
157	params    *ListAssessmentRunsInput
158	nextToken *string
159	firstPage bool
160}
161
162// NewListAssessmentRunsPaginator returns a new ListAssessmentRunsPaginator
163func NewListAssessmentRunsPaginator(client ListAssessmentRunsAPIClient, params *ListAssessmentRunsInput, optFns ...func(*ListAssessmentRunsPaginatorOptions)) *ListAssessmentRunsPaginator {
164	options := ListAssessmentRunsPaginatorOptions{}
165	if params.MaxResults != nil {
166		options.Limit = *params.MaxResults
167	}
168
169	for _, fn := range optFns {
170		fn(&options)
171	}
172
173	if params == nil {
174		params = &ListAssessmentRunsInput{}
175	}
176
177	return &ListAssessmentRunsPaginator{
178		options:   options,
179		client:    client,
180		params:    params,
181		firstPage: true,
182	}
183}
184
185// HasMorePages returns a boolean indicating whether more pages are available
186func (p *ListAssessmentRunsPaginator) HasMorePages() bool {
187	return p.firstPage || p.nextToken != nil
188}
189
190// NextPage retrieves the next ListAssessmentRuns page.
191func (p *ListAssessmentRunsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAssessmentRunsOutput, error) {
192	if !p.HasMorePages() {
193		return nil, fmt.Errorf("no more pages available")
194	}
195
196	params := *p.params
197	params.NextToken = p.nextToken
198
199	var limit *int32
200	if p.options.Limit > 0 {
201		limit = &p.options.Limit
202	}
203	params.MaxResults = limit
204
205	result, err := p.client.ListAssessmentRuns(ctx, &params, optFns...)
206	if err != nil {
207		return nil, err
208	}
209	p.firstPage = false
210
211	prevToken := p.nextToken
212	p.nextToken = result.NextToken
213
214	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
215		p.nextToken = nil
216	}
217
218	return result, nil
219}
220
221func newServiceMetadataMiddleware_opListAssessmentRuns(region string) *awsmiddleware.RegisterServiceMetadata {
222	return &awsmiddleware.RegisterServiceMetadata{
223		Region:        region,
224		ServiceID:     ServiceID,
225		SigningName:   "inspector",
226		OperationName: "ListAssessmentRuns",
227	}
228}
229