1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package quicksight
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/quicksight/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists data sources in current AWS Region that belong to this AWS account.
16func (c *Client) ListDataSources(ctx context.Context, params *ListDataSourcesInput, optFns ...func(*Options)) (*ListDataSourcesOutput, error) {
17	if params == nil {
18		params = &ListDataSourcesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListDataSources", params, optFns, addOperationListDataSourcesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListDataSourcesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListDataSourcesInput struct {
32
33	// The AWS account ID.
34	//
35	// This member is required.
36	AwsAccountId *string
37
38	// The maximum number of results to be returned per request.
39	MaxResults int32
40
41	// The token for the next set of results, or null if there are no more results.
42	NextToken *string
43}
44
45type ListDataSourcesOutput struct {
46
47	// A list of data sources.
48	DataSources []types.DataSource
49
50	// The token for the next set of results, or null if there are no more results.
51	NextToken *string
52
53	// The AWS request ID for this operation.
54	RequestId *string
55
56	// The HTTP status of the request.
57	Status int32
58
59	// Metadata pertaining to the operation's result.
60	ResultMetadata middleware.Metadata
61}
62
63func addOperationListDataSourcesMiddlewares(stack *middleware.Stack, options Options) (err error) {
64	err = stack.Serialize.Add(&awsRestjson1_serializeOpListDataSources{}, middleware.After)
65	if err != nil {
66		return err
67	}
68	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListDataSources{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	if err = addSetLoggerMiddleware(stack, options); err != nil {
73		return err
74	}
75	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
76		return err
77	}
78	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
79		return err
80	}
81	if err = addResolveEndpointMiddleware(stack, options); err != nil {
82		return err
83	}
84	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
85		return err
86	}
87	if err = addRetryMiddlewares(stack, options); err != nil {
88		return err
89	}
90	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
94		return err
95	}
96	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
97		return err
98	}
99	if err = addClientUserAgent(stack); err != nil {
100		return err
101	}
102	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
103		return err
104	}
105	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
106		return err
107	}
108	if err = addOpListDataSourcesValidationMiddleware(stack); err != nil {
109		return err
110	}
111	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDataSources(options.Region), middleware.Before); err != nil {
112		return err
113	}
114	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
115		return err
116	}
117	if err = addResponseErrorMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addRequestResponseLogging(stack, options); err != nil {
121		return err
122	}
123	return nil
124}
125
126// ListDataSourcesAPIClient is a client that implements the ListDataSources
127// operation.
128type ListDataSourcesAPIClient interface {
129	ListDataSources(context.Context, *ListDataSourcesInput, ...func(*Options)) (*ListDataSourcesOutput, error)
130}
131
132var _ ListDataSourcesAPIClient = (*Client)(nil)
133
134// ListDataSourcesPaginatorOptions is the paginator options for ListDataSources
135type ListDataSourcesPaginatorOptions struct {
136	// The maximum number of results to be returned per request.
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// ListDataSourcesPaginator is a paginator for ListDataSources
145type ListDataSourcesPaginator struct {
146	options   ListDataSourcesPaginatorOptions
147	client    ListDataSourcesAPIClient
148	params    *ListDataSourcesInput
149	nextToken *string
150	firstPage bool
151}
152
153// NewListDataSourcesPaginator returns a new ListDataSourcesPaginator
154func NewListDataSourcesPaginator(client ListDataSourcesAPIClient, params *ListDataSourcesInput, optFns ...func(*ListDataSourcesPaginatorOptions)) *ListDataSourcesPaginator {
155	options := ListDataSourcesPaginatorOptions{}
156	if params.MaxResults != 0 {
157		options.Limit = params.MaxResults
158	}
159
160	for _, fn := range optFns {
161		fn(&options)
162	}
163
164	if params == nil {
165		params = &ListDataSourcesInput{}
166	}
167
168	return &ListDataSourcesPaginator{
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 *ListDataSourcesPaginator) HasMorePages() bool {
178	return p.firstPage || p.nextToken != nil
179}
180
181// NextPage retrieves the next ListDataSources page.
182func (p *ListDataSourcesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDataSourcesOutput, 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	params.MaxResults = p.options.Limit
191
192	result, err := p.client.ListDataSources(ctx, &params, optFns...)
193	if err != nil {
194		return nil, err
195	}
196	p.firstPage = false
197
198	prevToken := p.nextToken
199	p.nextToken = result.NextToken
200
201	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
202		p.nextToken = nil
203	}
204
205	return result, nil
206}
207
208func newServiceMetadataMiddleware_opListDataSources(region string) *awsmiddleware.RegisterServiceMetadata {
209	return &awsmiddleware.RegisterServiceMetadata{
210		Region:        region,
211		ServiceID:     ServiceID,
212		SigningName:   "quicksight",
213		OperationName: "ListDataSources",
214	}
215}
216