1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package rds
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/rds/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns information about reserved DB instances for this account, or about a
16// specified reserved DB instance.
17func (c *Client) DescribeReservedDBInstances(ctx context.Context, params *DescribeReservedDBInstancesInput, optFns ...func(*Options)) (*DescribeReservedDBInstancesOutput, error) {
18	if params == nil {
19		params = &DescribeReservedDBInstancesInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "DescribeReservedDBInstances", params, optFns, addOperationDescribeReservedDBInstancesMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*DescribeReservedDBInstancesOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32//
33type DescribeReservedDBInstancesInput struct {
34
35	// The DB instance class filter value. Specify this parameter to show only those
36	// reservations matching the specified DB instances class.
37	DBInstanceClass *string
38
39	// The duration filter value, specified in years or seconds. Specify this parameter
40	// to show only reservations for this duration. Valid Values: 1 | 3 | 31536000 |
41	// 94608000
42	Duration *string
43
44	// This parameter isn't currently supported.
45	Filters []types.Filter
46
47	// The lease identifier filter value. Specify this parameter to show only the
48	// reservation that matches the specified lease ID. AWS Support might request the
49	// lease ID for an issue related to a reserved DB instance.
50	LeaseId *string
51
52	// An optional pagination token provided by a previous request. If this parameter
53	// is specified, the response includes only records beyond the marker, up to the
54	// value specified by MaxRecords.
55	Marker *string
56
57	// The maximum number of records to include in the response. If more than the
58	// MaxRecords value is available, a pagination token called a marker is included in
59	// the response so you can retrieve the remaining results. Default: 100
60	// Constraints: Minimum 20, maximum 100.
61	MaxRecords *int32
62
63	// A value that indicates whether to show only those reservations that support
64	// Multi-AZ.
65	MultiAZ *bool
66
67	// The offering type filter value. Specify this parameter to show only the
68	// available offerings matching the specified offering type. Valid Values: "Partial
69	// Upfront" | "All Upfront" | "No Upfront"
70	OfferingType *string
71
72	// The product description filter value. Specify this parameter to show only those
73	// reservations matching the specified product description.
74	ProductDescription *string
75
76	// The reserved DB instance identifier filter value. Specify this parameter to show
77	// only the reservation that matches the specified reservation ID.
78	ReservedDBInstanceId *string
79
80	// The offering identifier filter value. Specify this parameter to show only
81	// purchased reservations matching the specified offering identifier.
82	ReservedDBInstancesOfferingId *string
83}
84
85// Contains the result of a successful invocation of the
86// DescribeReservedDBInstances action.
87type DescribeReservedDBInstancesOutput struct {
88
89	// An optional pagination token provided by a previous request. If this parameter
90	// is specified, the response includes only records beyond the marker, up to the
91	// value specified by MaxRecords.
92	Marker *string
93
94	// A list of reserved DB instances.
95	ReservedDBInstances []types.ReservedDBInstance
96
97	// Metadata pertaining to the operation's result.
98	ResultMetadata middleware.Metadata
99}
100
101func addOperationDescribeReservedDBInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) {
102	err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeReservedDBInstances{}, middleware.After)
103	if err != nil {
104		return err
105	}
106	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeReservedDBInstances{}, middleware.After)
107	if err != nil {
108		return err
109	}
110	if err = addSetLoggerMiddleware(stack, options); err != nil {
111		return err
112	}
113	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addResolveEndpointMiddleware(stack, options); err != nil {
120		return err
121	}
122	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
123		return err
124	}
125	if err = addRetryMiddlewares(stack, options); err != nil {
126		return err
127	}
128	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
129		return err
130	}
131	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
132		return err
133	}
134	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
135		return err
136	}
137	if err = addClientUserAgent(stack); err != nil {
138		return err
139	}
140	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
141		return err
142	}
143	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
144		return err
145	}
146	if err = addOpDescribeReservedDBInstancesValidationMiddleware(stack); err != nil {
147		return err
148	}
149	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeReservedDBInstances(options.Region), middleware.Before); err != nil {
150		return err
151	}
152	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
153		return err
154	}
155	if err = addResponseErrorMiddleware(stack); err != nil {
156		return err
157	}
158	if err = addRequestResponseLogging(stack, options); err != nil {
159		return err
160	}
161	return nil
162}
163
164// DescribeReservedDBInstancesAPIClient is a client that implements the
165// DescribeReservedDBInstances operation.
166type DescribeReservedDBInstancesAPIClient interface {
167	DescribeReservedDBInstances(context.Context, *DescribeReservedDBInstancesInput, ...func(*Options)) (*DescribeReservedDBInstancesOutput, error)
168}
169
170var _ DescribeReservedDBInstancesAPIClient = (*Client)(nil)
171
172// DescribeReservedDBInstancesPaginatorOptions is the paginator options for
173// DescribeReservedDBInstances
174type DescribeReservedDBInstancesPaginatorOptions struct {
175	// The maximum number of records to include in the response. If more than the
176	// MaxRecords value is available, a pagination token called a marker is included in
177	// the response so you can retrieve the remaining results. Default: 100
178	// Constraints: Minimum 20, maximum 100.
179	Limit int32
180
181	// Set to true if pagination should stop if the service returns a pagination token
182	// that matches the most recent token provided to the service.
183	StopOnDuplicateToken bool
184}
185
186// DescribeReservedDBInstancesPaginator is a paginator for
187// DescribeReservedDBInstances
188type DescribeReservedDBInstancesPaginator struct {
189	options   DescribeReservedDBInstancesPaginatorOptions
190	client    DescribeReservedDBInstancesAPIClient
191	params    *DescribeReservedDBInstancesInput
192	nextToken *string
193	firstPage bool
194}
195
196// NewDescribeReservedDBInstancesPaginator returns a new
197// DescribeReservedDBInstancesPaginator
198func NewDescribeReservedDBInstancesPaginator(client DescribeReservedDBInstancesAPIClient, params *DescribeReservedDBInstancesInput, optFns ...func(*DescribeReservedDBInstancesPaginatorOptions)) *DescribeReservedDBInstancesPaginator {
199	if params == nil {
200		params = &DescribeReservedDBInstancesInput{}
201	}
202
203	options := DescribeReservedDBInstancesPaginatorOptions{}
204	if params.MaxRecords != nil {
205		options.Limit = *params.MaxRecords
206	}
207
208	for _, fn := range optFns {
209		fn(&options)
210	}
211
212	return &DescribeReservedDBInstancesPaginator{
213		options:   options,
214		client:    client,
215		params:    params,
216		firstPage: true,
217	}
218}
219
220// HasMorePages returns a boolean indicating whether more pages are available
221func (p *DescribeReservedDBInstancesPaginator) HasMorePages() bool {
222	return p.firstPage || p.nextToken != nil
223}
224
225// NextPage retrieves the next DescribeReservedDBInstances page.
226func (p *DescribeReservedDBInstancesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeReservedDBInstancesOutput, error) {
227	if !p.HasMorePages() {
228		return nil, fmt.Errorf("no more pages available")
229	}
230
231	params := *p.params
232	params.Marker = p.nextToken
233
234	var limit *int32
235	if p.options.Limit > 0 {
236		limit = &p.options.Limit
237	}
238	params.MaxRecords = limit
239
240	result, err := p.client.DescribeReservedDBInstances(ctx, &params, optFns...)
241	if err != nil {
242		return nil, err
243	}
244	p.firstPage = false
245
246	prevToken := p.nextToken
247	p.nextToken = result.Marker
248
249	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
250		p.nextToken = nil
251	}
252
253	return result, nil
254}
255
256func newServiceMetadataMiddleware_opDescribeReservedDBInstances(region string) *awsmiddleware.RegisterServiceMetadata {
257	return &awsmiddleware.RegisterServiceMetadata{
258		Region:        region,
259		ServiceID:     ServiceID,
260		SigningName:   "rds",
261		OperationName: "DescribeReservedDBInstances",
262	}
263}
264