1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package elasticbeanstalk
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/elasticbeanstalk/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the platform versions available for your account in an AWS Region.
16// Provides summary information about each platform version. Compare to
17// DescribePlatformVersion, which provides full details about a single platform
18// version. For definitions of platform version and other platform-related terms,
19// see AWS Elastic Beanstalk Platforms Glossary
20// (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-glossary.html).
21func (c *Client) ListPlatformVersions(ctx context.Context, params *ListPlatformVersionsInput, optFns ...func(*Options)) (*ListPlatformVersionsOutput, error) {
22	if params == nil {
23		params = &ListPlatformVersionsInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "ListPlatformVersions", params, optFns, addOperationListPlatformVersionsMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*ListPlatformVersionsOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36type ListPlatformVersionsInput struct {
37
38	// Criteria for restricting the resulting list of platform versions. The filter is
39	// interpreted as a logical conjunction (AND) of the separate PlatformFilter terms.
40	Filters []types.PlatformFilter
41
42	// The maximum number of platform version values returned in one call.
43	MaxRecords *int32
44
45	// For a paginated request. Specify a token from a previous response page to
46	// retrieve the next response page. All other parameter values must be identical to
47	// the ones specified in the initial request. If no NextToken is specified, the
48	// first page is retrieved.
49	NextToken *string
50}
51
52type ListPlatformVersionsOutput struct {
53
54	// In a paginated request, if this value isn't null, it's the token that you can
55	// pass in a subsequent request to get the next response page.
56	NextToken *string
57
58	// Summary information about the platform versions.
59	PlatformSummaryList []types.PlatformSummary
60
61	// Metadata pertaining to the operation's result.
62	ResultMetadata middleware.Metadata
63}
64
65func addOperationListPlatformVersionsMiddlewares(stack *middleware.Stack, options Options) (err error) {
66	err = stack.Serialize.Add(&awsAwsquery_serializeOpListPlatformVersions{}, middleware.After)
67	if err != nil {
68		return err
69	}
70	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpListPlatformVersions{}, middleware.After)
71	if err != nil {
72		return err
73	}
74	if err = addSetLoggerMiddleware(stack, options); err != nil {
75		return err
76	}
77	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
78		return err
79	}
80	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
81		return err
82	}
83	if err = addResolveEndpointMiddleware(stack, options); err != nil {
84		return err
85	}
86	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
87		return err
88	}
89	if err = addRetryMiddlewares(stack, options); err != nil {
90		return err
91	}
92	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
93		return err
94	}
95	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
99		return err
100	}
101	if err = addClientUserAgent(stack); err != nil {
102		return err
103	}
104	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
108		return err
109	}
110	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPlatformVersions(options.Region), middleware.Before); err != nil {
111		return err
112	}
113	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addResponseErrorMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addRequestResponseLogging(stack, options); err != nil {
120		return err
121	}
122	return nil
123}
124
125// ListPlatformVersionsAPIClient is a client that implements the
126// ListPlatformVersions operation.
127type ListPlatformVersionsAPIClient interface {
128	ListPlatformVersions(context.Context, *ListPlatformVersionsInput, ...func(*Options)) (*ListPlatformVersionsOutput, error)
129}
130
131var _ ListPlatformVersionsAPIClient = (*Client)(nil)
132
133// ListPlatformVersionsPaginatorOptions is the paginator options for
134// ListPlatformVersions
135type ListPlatformVersionsPaginatorOptions struct {
136	// The maximum number of platform version values returned in one call.
137	Limit int32
138
139	// Set to true if pagination should stop if the service returns a pagination token
140	// that matches the most recent token provided to the service.
141	StopOnDuplicateToken bool
142}
143
144// ListPlatformVersionsPaginator is a paginator for ListPlatformVersions
145type ListPlatformVersionsPaginator struct {
146	options   ListPlatformVersionsPaginatorOptions
147	client    ListPlatformVersionsAPIClient
148	params    *ListPlatformVersionsInput
149	nextToken *string
150	firstPage bool
151}
152
153// NewListPlatformVersionsPaginator returns a new ListPlatformVersionsPaginator
154func NewListPlatformVersionsPaginator(client ListPlatformVersionsAPIClient, params *ListPlatformVersionsInput, optFns ...func(*ListPlatformVersionsPaginatorOptions)) *ListPlatformVersionsPaginator {
155	if params == nil {
156		params = &ListPlatformVersionsInput{}
157	}
158
159	options := ListPlatformVersionsPaginatorOptions{}
160	if params.MaxRecords != nil {
161		options.Limit = *params.MaxRecords
162	}
163
164	for _, fn := range optFns {
165		fn(&options)
166	}
167
168	return &ListPlatformVersionsPaginator{
169		options:   options,
170		client:    client,
171		params:    params,
172		firstPage: true,
173	}
174}
175
176// HasMorePages returns a boolean indicating whether more pages are available
177func (p *ListPlatformVersionsPaginator) HasMorePages() bool {
178	return p.firstPage || p.nextToken != nil
179}
180
181// NextPage retrieves the next ListPlatformVersions page.
182func (p *ListPlatformVersionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPlatformVersionsOutput, error) {
183	if !p.HasMorePages() {
184		return nil, fmt.Errorf("no more pages available")
185	}
186
187	params := *p.params
188	params.NextToken = p.nextToken
189
190	var limit *int32
191	if p.options.Limit > 0 {
192		limit = &p.options.Limit
193	}
194	params.MaxRecords = limit
195
196	result, err := p.client.ListPlatformVersions(ctx, &params, optFns...)
197	if err != nil {
198		return nil, err
199	}
200	p.firstPage = false
201
202	prevToken := p.nextToken
203	p.nextToken = result.NextToken
204
205	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
206		p.nextToken = nil
207	}
208
209	return result, nil
210}
211
212func newServiceMetadataMiddleware_opListPlatformVersions(region string) *awsmiddleware.RegisterServiceMetadata {
213	return &awsmiddleware.RegisterServiceMetadata{
214		Region:        region,
215		ServiceID:     ServiceID,
216		SigningName:   "elasticbeanstalk",
217		OperationName: "ListPlatformVersions",
218	}
219}
220