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 templates that correspond to the assessment targets that
16// are specified by the ARNs of the assessment targets.
17func (c *Client) ListAssessmentTemplates(ctx context.Context, params *ListAssessmentTemplatesInput, optFns ...func(*Options)) (*ListAssessmentTemplatesOutput, error) {
18	if params == nil {
19		params = &ListAssessmentTemplatesInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListAssessmentTemplates", params, optFns, c.addOperationListAssessmentTemplatesMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListAssessmentTemplatesOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListAssessmentTemplatesInput struct {
33
34	// A list of ARNs that specifies the assessment targets whose assessment templates
35	// you want to list.
36	AssessmentTargetArns []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.AssessmentTemplateFilter
43
44	// You can use this parameter to indicate the maximum number of items you want in
45	// 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 ListAssessmentTemplates 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	noSmithyDocumentSerde
55}
56
57type ListAssessmentTemplatesOutput struct {
58
59	// A list of ARNs that specifies the assessment templates returned by the action.
60	//
61	// This member is required.
62	AssessmentTemplateArns []string
63
64	// When a response is generated, if there is more data to be listed, this parameter
65	// is present in the response and contains the value to use for the nextToken
66	// parameter in a subsequent pagination request. If there is no more data to be
67	// listed, this parameter is set to null.
68	NextToken *string
69
70	// Metadata pertaining to the operation's result.
71	ResultMetadata middleware.Metadata
72
73	noSmithyDocumentSerde
74}
75
76func (c *Client) addOperationListAssessmentTemplatesMiddlewares(stack *middleware.Stack, options Options) (err error) {
77	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListAssessmentTemplates{}, middleware.After)
78	if err != nil {
79		return err
80	}
81	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListAssessmentTemplates{}, middleware.After)
82	if err != nil {
83		return err
84	}
85	if err = addSetLoggerMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
89		return err
90	}
91	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
92		return err
93	}
94	if err = addResolveEndpointMiddleware(stack, options); err != nil {
95		return err
96	}
97	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
98		return err
99	}
100	if err = addRetryMiddlewares(stack, options); err != nil {
101		return err
102	}
103	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
107		return err
108	}
109	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
110		return err
111	}
112	if err = addClientUserAgent(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
119		return err
120	}
121	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAssessmentTemplates(options.Region), middleware.Before); err != nil {
122		return err
123	}
124	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addResponseErrorMiddleware(stack); err != nil {
128		return err
129	}
130	if err = addRequestResponseLogging(stack, options); err != nil {
131		return err
132	}
133	return nil
134}
135
136// ListAssessmentTemplatesAPIClient is a client that implements the
137// ListAssessmentTemplates operation.
138type ListAssessmentTemplatesAPIClient interface {
139	ListAssessmentTemplates(context.Context, *ListAssessmentTemplatesInput, ...func(*Options)) (*ListAssessmentTemplatesOutput, error)
140}
141
142var _ ListAssessmentTemplatesAPIClient = (*Client)(nil)
143
144// ListAssessmentTemplatesPaginatorOptions is the paginator options for
145// ListAssessmentTemplates
146type ListAssessmentTemplatesPaginatorOptions struct {
147	// You can use this parameter to indicate the maximum number of items you want in
148	// the response. The default value is 10. The maximum value is 500.
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// ListAssessmentTemplatesPaginator is a paginator for ListAssessmentTemplates
157type ListAssessmentTemplatesPaginator struct {
158	options   ListAssessmentTemplatesPaginatorOptions
159	client    ListAssessmentTemplatesAPIClient
160	params    *ListAssessmentTemplatesInput
161	nextToken *string
162	firstPage bool
163}
164
165// NewListAssessmentTemplatesPaginator returns a new
166// ListAssessmentTemplatesPaginator
167func NewListAssessmentTemplatesPaginator(client ListAssessmentTemplatesAPIClient, params *ListAssessmentTemplatesInput, optFns ...func(*ListAssessmentTemplatesPaginatorOptions)) *ListAssessmentTemplatesPaginator {
168	if params == nil {
169		params = &ListAssessmentTemplatesInput{}
170	}
171
172	options := ListAssessmentTemplatesPaginatorOptions{}
173	if params.MaxResults != nil {
174		options.Limit = *params.MaxResults
175	}
176
177	for _, fn := range optFns {
178		fn(&options)
179	}
180
181	return &ListAssessmentTemplatesPaginator{
182		options:   options,
183		client:    client,
184		params:    params,
185		firstPage: true,
186	}
187}
188
189// HasMorePages returns a boolean indicating whether more pages are available
190func (p *ListAssessmentTemplatesPaginator) HasMorePages() bool {
191	return p.firstPage || p.nextToken != nil
192}
193
194// NextPage retrieves the next ListAssessmentTemplates page.
195func (p *ListAssessmentTemplatesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAssessmentTemplatesOutput, error) {
196	if !p.HasMorePages() {
197		return nil, fmt.Errorf("no more pages available")
198	}
199
200	params := *p.params
201	params.NextToken = p.nextToken
202
203	var limit *int32
204	if p.options.Limit > 0 {
205		limit = &p.options.Limit
206	}
207	params.MaxResults = limit
208
209	result, err := p.client.ListAssessmentTemplates(ctx, &params, optFns...)
210	if err != nil {
211		return nil, err
212	}
213	p.firstPage = false
214
215	prevToken := p.nextToken
216	p.nextToken = result.NextToken
217
218	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
219		p.nextToken = nil
220	}
221
222	return result, nil
223}
224
225func newServiceMetadataMiddleware_opListAssessmentTemplates(region string) *awsmiddleware.RegisterServiceMetadata {
226	return &awsmiddleware.RegisterServiceMetadata{
227		Region:        region,
228		ServiceID:     ServiceID,
229		SigningName:   "inspector",
230		OperationName: "ListAssessmentTemplates",
231	}
232}
233