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 a list of the source AWS Regions where the current AWS Region can create
16// a read replica, copy a DB snapshot from, or replicate automated backups from.
17// This API action supports pagination.
18func (c *Client) DescribeSourceRegions(ctx context.Context, params *DescribeSourceRegionsInput, optFns ...func(*Options)) (*DescribeSourceRegionsOutput, error) {
19	if params == nil {
20		params = &DescribeSourceRegionsInput{}
21	}
22
23	result, metadata, err := c.invokeOperation(ctx, "DescribeSourceRegions", params, optFns, addOperationDescribeSourceRegionsMiddlewares)
24	if err != nil {
25		return nil, err
26	}
27
28	out := result.(*DescribeSourceRegionsOutput)
29	out.ResultMetadata = metadata
30	return out, nil
31}
32
33//
34type DescribeSourceRegionsInput struct {
35
36	// This parameter isn't currently supported.
37	Filters []types.Filter
38
39	// An optional pagination token provided by a previous DescribeSourceRegions
40	// request. If this parameter is specified, the response includes only records
41	// beyond the marker, up to the value specified by MaxRecords.
42	Marker *string
43
44	// The maximum number of records to include in the response. If more records exist
45	// than the specified MaxRecords value, a pagination token called a marker is
46	// included in the response so you can retrieve the remaining results. Default: 100
47	// Constraints: Minimum 20, maximum 100.
48	MaxRecords *int32
49
50	// The source AWS Region name. For example, us-east-1. Constraints:
51	//
52	// * Must specify
53	// a valid AWS Region name.
54	RegionName *string
55}
56
57// Contains the result of a successful invocation of the DescribeSourceRegions
58// action.
59type DescribeSourceRegionsOutput struct {
60
61	// An optional pagination token provided by a previous request. If this parameter
62	// is specified, the response includes only records beyond the marker, up to the
63	// value specified by MaxRecords.
64	Marker *string
65
66	// A list of SourceRegion instances that contains each source AWS Region that the
67	// current AWS Region can get a read replica or a DB snapshot from.
68	SourceRegions []types.SourceRegion
69
70	// Metadata pertaining to the operation's result.
71	ResultMetadata middleware.Metadata
72}
73
74func addOperationDescribeSourceRegionsMiddlewares(stack *middleware.Stack, options Options) (err error) {
75	err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeSourceRegions{}, middleware.After)
76	if err != nil {
77		return err
78	}
79	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeSourceRegions{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	if err = addSetLoggerMiddleware(stack, options); err != nil {
84		return err
85	}
86	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
87		return err
88	}
89	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
90		return err
91	}
92	if err = addResolveEndpointMiddleware(stack, options); err != nil {
93		return err
94	}
95	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
96		return err
97	}
98	if err = addRetryMiddlewares(stack, options); err != nil {
99		return err
100	}
101	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
105		return err
106	}
107	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
108		return err
109	}
110	if err = addClientUserAgent(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addOpDescribeSourceRegionsValidationMiddleware(stack); err != nil {
120		return err
121	}
122	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeSourceRegions(options.Region), middleware.Before); err != nil {
123		return err
124	}
125	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
126		return err
127	}
128	if err = addResponseErrorMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addRequestResponseLogging(stack, options); err != nil {
132		return err
133	}
134	return nil
135}
136
137// DescribeSourceRegionsAPIClient is a client that implements the
138// DescribeSourceRegions operation.
139type DescribeSourceRegionsAPIClient interface {
140	DescribeSourceRegions(context.Context, *DescribeSourceRegionsInput, ...func(*Options)) (*DescribeSourceRegionsOutput, error)
141}
142
143var _ DescribeSourceRegionsAPIClient = (*Client)(nil)
144
145// DescribeSourceRegionsPaginatorOptions is the paginator options for
146// DescribeSourceRegions
147type DescribeSourceRegionsPaginatorOptions struct {
148	// The maximum number of records to include in the response. If more records exist
149	// than the specified MaxRecords value, a pagination token called a marker is
150	// included in the response so you can retrieve the remaining results. Default: 100
151	// Constraints: Minimum 20, maximum 100.
152	Limit int32
153
154	// Set to true if pagination should stop if the service returns a pagination token
155	// that matches the most recent token provided to the service.
156	StopOnDuplicateToken bool
157}
158
159// DescribeSourceRegionsPaginator is a paginator for DescribeSourceRegions
160type DescribeSourceRegionsPaginator struct {
161	options   DescribeSourceRegionsPaginatorOptions
162	client    DescribeSourceRegionsAPIClient
163	params    *DescribeSourceRegionsInput
164	nextToken *string
165	firstPage bool
166}
167
168// NewDescribeSourceRegionsPaginator returns a new DescribeSourceRegionsPaginator
169func NewDescribeSourceRegionsPaginator(client DescribeSourceRegionsAPIClient, params *DescribeSourceRegionsInput, optFns ...func(*DescribeSourceRegionsPaginatorOptions)) *DescribeSourceRegionsPaginator {
170	if params == nil {
171		params = &DescribeSourceRegionsInput{}
172	}
173
174	options := DescribeSourceRegionsPaginatorOptions{}
175	if params.MaxRecords != nil {
176		options.Limit = *params.MaxRecords
177	}
178
179	for _, fn := range optFns {
180		fn(&options)
181	}
182
183	return &DescribeSourceRegionsPaginator{
184		options:   options,
185		client:    client,
186		params:    params,
187		firstPage: true,
188	}
189}
190
191// HasMorePages returns a boolean indicating whether more pages are available
192func (p *DescribeSourceRegionsPaginator) HasMorePages() bool {
193	return p.firstPage || p.nextToken != nil
194}
195
196// NextPage retrieves the next DescribeSourceRegions page.
197func (p *DescribeSourceRegionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeSourceRegionsOutput, error) {
198	if !p.HasMorePages() {
199		return nil, fmt.Errorf("no more pages available")
200	}
201
202	params := *p.params
203	params.Marker = p.nextToken
204
205	var limit *int32
206	if p.options.Limit > 0 {
207		limit = &p.options.Limit
208	}
209	params.MaxRecords = limit
210
211	result, err := p.client.DescribeSourceRegions(ctx, &params, optFns...)
212	if err != nil {
213		return nil, err
214	}
215	p.firstPage = false
216
217	prevToken := p.nextToken
218	p.nextToken = result.Marker
219
220	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
221		p.nextToken = nil
222	}
223
224	return result, nil
225}
226
227func newServiceMetadataMiddleware_opDescribeSourceRegions(region string) *awsmiddleware.RegisterServiceMetadata {
228	return &awsmiddleware.RegisterServiceMetadata{
229		Region:        region,
230		ServiceID:     ServiceID,
231		SigningName:   "rds",
232		OperationName: "DescribeSourceRegions",
233	}
234}
235