1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package redshift
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/redshift/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns descriptions of the available Amazon Redshift cluster versions. You can
16// call this operation even before creating any clusters to learn more about the
17// Amazon Redshift versions. For more information about managing clusters, go to
18// Amazon Redshift Clusters
19// (https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html) in
20// the Amazon Redshift Cluster Management Guide.
21func (c *Client) DescribeClusterVersions(ctx context.Context, params *DescribeClusterVersionsInput, optFns ...func(*Options)) (*DescribeClusterVersionsOutput, error) {
22	if params == nil {
23		params = &DescribeClusterVersionsInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "DescribeClusterVersions", params, optFns, addOperationDescribeClusterVersionsMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*DescribeClusterVersionsOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36//
37type DescribeClusterVersionsInput struct {
38
39	// The name of a specific cluster parameter group family to return details for.
40	// Constraints:
41	//
42	// * Must be 1 to 255 alphanumeric characters
43	//
44	// * First character must
45	// be a letter
46	//
47	// * Cannot end with a hyphen or contain two consecutive hyphens
48	ClusterParameterGroupFamily *string
49
50	// The specific cluster version to return. Example: 1.0
51	ClusterVersion *string
52
53	// An optional parameter that specifies the starting point to return a set of
54	// response records. When the results of a DescribeClusterVersions request exceed
55	// the value specified in MaxRecords, AWS returns a value in the Marker field of
56	// the response. You can retrieve the next set of response records by providing the
57	// returned marker value in the Marker parameter and retrying the request.
58	Marker *string
59
60	// The maximum number of response records to return in each call. If the number of
61	// remaining response records exceeds the specified MaxRecords value, a value is
62	// returned in a marker field of the response. You can retrieve the next set of
63	// records by retrying the command with the returned marker value. Default: 100
64	// Constraints: minimum 20, maximum 100.
65	MaxRecords *int32
66}
67
68// Contains the output from the DescribeClusterVersions action.
69type DescribeClusterVersionsOutput struct {
70
71	// A list of Version elements.
72	ClusterVersions []types.ClusterVersion
73
74	// A value that indicates the starting point for the next set of response records
75	// in a subsequent request. If a value is returned in a response, you can retrieve
76	// the next set of records by providing this returned marker value in the Marker
77	// parameter and retrying the command. If the Marker field is empty, all response
78	// records have been retrieved for the request.
79	Marker *string
80
81	// Metadata pertaining to the operation's result.
82	ResultMetadata middleware.Metadata
83}
84
85func addOperationDescribeClusterVersionsMiddlewares(stack *middleware.Stack, options Options) (err error) {
86	err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeClusterVersions{}, middleware.After)
87	if err != nil {
88		return err
89	}
90	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeClusterVersions{}, middleware.After)
91	if err != nil {
92		return err
93	}
94	if err = addSetLoggerMiddleware(stack, options); err != nil {
95		return err
96	}
97	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
98		return err
99	}
100	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
101		return err
102	}
103	if err = addResolveEndpointMiddleware(stack, options); err != nil {
104		return err
105	}
106	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
107		return err
108	}
109	if err = addRetryMiddlewares(stack, options); err != nil {
110		return err
111	}
112	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
113		return err
114	}
115	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
119		return err
120	}
121	if err = addClientUserAgent(stack); err != nil {
122		return err
123	}
124	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
125		return err
126	}
127	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
128		return err
129	}
130	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeClusterVersions(options.Region), middleware.Before); err != nil {
131		return err
132	}
133	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
134		return err
135	}
136	if err = addResponseErrorMiddleware(stack); err != nil {
137		return err
138	}
139	if err = addRequestResponseLogging(stack, options); err != nil {
140		return err
141	}
142	return nil
143}
144
145// DescribeClusterVersionsAPIClient is a client that implements the
146// DescribeClusterVersions operation.
147type DescribeClusterVersionsAPIClient interface {
148	DescribeClusterVersions(context.Context, *DescribeClusterVersionsInput, ...func(*Options)) (*DescribeClusterVersionsOutput, error)
149}
150
151var _ DescribeClusterVersionsAPIClient = (*Client)(nil)
152
153// DescribeClusterVersionsPaginatorOptions is the paginator options for
154// DescribeClusterVersions
155type DescribeClusterVersionsPaginatorOptions struct {
156	// The maximum number of response records to return in each call. If the number of
157	// remaining response records exceeds the specified MaxRecords value, a value is
158	// returned in a marker field of the response. You can retrieve the next set of
159	// records by retrying the command with the returned marker value. Default: 100
160	// Constraints: minimum 20, maximum 100.
161	Limit int32
162
163	// Set to true if pagination should stop if the service returns a pagination token
164	// that matches the most recent token provided to the service.
165	StopOnDuplicateToken bool
166}
167
168// DescribeClusterVersionsPaginator is a paginator for DescribeClusterVersions
169type DescribeClusterVersionsPaginator struct {
170	options   DescribeClusterVersionsPaginatorOptions
171	client    DescribeClusterVersionsAPIClient
172	params    *DescribeClusterVersionsInput
173	nextToken *string
174	firstPage bool
175}
176
177// NewDescribeClusterVersionsPaginator returns a new
178// DescribeClusterVersionsPaginator
179func NewDescribeClusterVersionsPaginator(client DescribeClusterVersionsAPIClient, params *DescribeClusterVersionsInput, optFns ...func(*DescribeClusterVersionsPaginatorOptions)) *DescribeClusterVersionsPaginator {
180	if params == nil {
181		params = &DescribeClusterVersionsInput{}
182	}
183
184	options := DescribeClusterVersionsPaginatorOptions{}
185	if params.MaxRecords != nil {
186		options.Limit = *params.MaxRecords
187	}
188
189	for _, fn := range optFns {
190		fn(&options)
191	}
192
193	return &DescribeClusterVersionsPaginator{
194		options:   options,
195		client:    client,
196		params:    params,
197		firstPage: true,
198	}
199}
200
201// HasMorePages returns a boolean indicating whether more pages are available
202func (p *DescribeClusterVersionsPaginator) HasMorePages() bool {
203	return p.firstPage || p.nextToken != nil
204}
205
206// NextPage retrieves the next DescribeClusterVersions page.
207func (p *DescribeClusterVersionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeClusterVersionsOutput, error) {
208	if !p.HasMorePages() {
209		return nil, fmt.Errorf("no more pages available")
210	}
211
212	params := *p.params
213	params.Marker = p.nextToken
214
215	var limit *int32
216	if p.options.Limit > 0 {
217		limit = &p.options.Limit
218	}
219	params.MaxRecords = limit
220
221	result, err := p.client.DescribeClusterVersions(ctx, &params, optFns...)
222	if err != nil {
223		return nil, err
224	}
225	p.firstPage = false
226
227	prevToken := p.nextToken
228	p.nextToken = result.Marker
229
230	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
231		p.nextToken = nil
232	}
233
234	return result, nil
235}
236
237func newServiceMetadataMiddleware_opDescribeClusterVersions(region string) *awsmiddleware.RegisterServiceMetadata {
238	return &awsmiddleware.RegisterServiceMetadata{
239		Region:        region,
240		ServiceID:     ServiceID,
241		SigningName:   "redshift",
242		OperationName: "DescribeClusterVersions",
243	}
244}
245