1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package redshiftdata
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/redshiftdata/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// List the tables in a database. If neither SchemaPattern nor TablePattern are
16// specified, then all tables in the database are returned. A token is returned to
17// page through the table list. Depending on the authorization method, use one of
18// the following combinations of request parameters:
19//
20// * Secrets Manager - specify
21// the Amazon Resource Name (ARN) of the secret, the database name, and the cluster
22// identifier that matches the cluster in the secret.
23//
24// * Temporary credentials -
25// specify the cluster identifier, the database name, and the database user name.
26// Permission to call the redshift:GetClusterCredentials operation is required to
27// use this method.
28func (c *Client) ListTables(ctx context.Context, params *ListTablesInput, optFns ...func(*Options)) (*ListTablesOutput, error) {
29	if params == nil {
30		params = &ListTablesInput{}
31	}
32
33	result, metadata, err := c.invokeOperation(ctx, "ListTables", params, optFns, c.addOperationListTablesMiddlewares)
34	if err != nil {
35		return nil, err
36	}
37
38	out := result.(*ListTablesOutput)
39	out.ResultMetadata = metadata
40	return out, nil
41}
42
43type ListTablesInput struct {
44
45	// The cluster identifier. This parameter is required when authenticating using
46	// either Secrets Manager or temporary credentials.
47	//
48	// This member is required.
49	ClusterIdentifier *string
50
51	// The name of the database that contains the tables to list. If ConnectedDatabase
52	// is not specified, this is also the database to connect to with your
53	// authentication credentials.
54	//
55	// This member is required.
56	Database *string
57
58	// A database name. The connected database is specified when you connect with your
59	// authentication credentials.
60	ConnectedDatabase *string
61
62	// The database user name. This parameter is required when authenticating using
63	// temporary credentials.
64	DbUser *string
65
66	// The maximum number of tables to return in the response. If more tables exist
67	// than fit in one response, then NextToken is returned to page through the
68	// results.
69	MaxResults int32
70
71	// A value that indicates the starting point for the next set of response records
72	// in a subsequent request. If a value is returned in a response, you can retrieve
73	// the next set of records by providing this returned NextToken value in the next
74	// NextToken parameter and retrying the command. If the NextToken field is empty,
75	// all response records have been retrieved for the request.
76	NextToken *string
77
78	// A pattern to filter results by schema name. Within a schema pattern, "%" means
79	// match any substring of 0 or more characters and "_" means match any one
80	// character. Only schema name entries matching the search pattern are returned. If
81	// SchemaPattern is not specified, then all tables that match TablePattern are
82	// returned. If neither SchemaPattern or TablePattern are specified, then all
83	// tables are returned.
84	SchemaPattern *string
85
86	// The name or ARN of the secret that enables access to the database. This
87	// parameter is required when authenticating using Secrets Manager.
88	SecretArn *string
89
90	// A pattern to filter results by table name. Within a table pattern, "%" means
91	// match any substring of 0 or more characters and "_" means match any one
92	// character. Only table name entries matching the search pattern are returned. If
93	// TablePattern is not specified, then all tables that match SchemaPatternare
94	// returned. If neither SchemaPattern or TablePattern are specified, then all
95	// tables are returned.
96	TablePattern *string
97
98	noSmithyDocumentSerde
99}
100
101type ListTablesOutput struct {
102
103	// A value that indicates the starting point for the next set of response records
104	// in a subsequent request. If a value is returned in a response, you can retrieve
105	// the next set of records by providing this returned NextToken value in the next
106	// NextToken parameter and retrying the command. If the NextToken field is empty,
107	// all response records have been retrieved for the request.
108	NextToken *string
109
110	// The tables that match the request pattern.
111	Tables []types.TableMember
112
113	// Metadata pertaining to the operation's result.
114	ResultMetadata middleware.Metadata
115
116	noSmithyDocumentSerde
117}
118
119func (c *Client) addOperationListTablesMiddlewares(stack *middleware.Stack, options Options) (err error) {
120	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTables{}, middleware.After)
121	if err != nil {
122		return err
123	}
124	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTables{}, middleware.After)
125	if err != nil {
126		return err
127	}
128	if err = addSetLoggerMiddleware(stack, options); err != nil {
129		return err
130	}
131	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
132		return err
133	}
134	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
135		return err
136	}
137	if err = addResolveEndpointMiddleware(stack, options); err != nil {
138		return err
139	}
140	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
141		return err
142	}
143	if err = addRetryMiddlewares(stack, options); err != nil {
144		return err
145	}
146	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
147		return err
148	}
149	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
150		return err
151	}
152	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
153		return err
154	}
155	if err = addClientUserAgent(stack); err != nil {
156		return err
157	}
158	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
159		return err
160	}
161	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
162		return err
163	}
164	if err = addOpListTablesValidationMiddleware(stack); err != nil {
165		return err
166	}
167	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTables(options.Region), middleware.Before); err != nil {
168		return err
169	}
170	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
171		return err
172	}
173	if err = addResponseErrorMiddleware(stack); err != nil {
174		return err
175	}
176	if err = addRequestResponseLogging(stack, options); err != nil {
177		return err
178	}
179	return nil
180}
181
182// ListTablesAPIClient is a client that implements the ListTables operation.
183type ListTablesAPIClient interface {
184	ListTables(context.Context, *ListTablesInput, ...func(*Options)) (*ListTablesOutput, error)
185}
186
187var _ ListTablesAPIClient = (*Client)(nil)
188
189// ListTablesPaginatorOptions is the paginator options for ListTables
190type ListTablesPaginatorOptions struct {
191	// The maximum number of tables to return in the response. If more tables exist
192	// than fit in one response, then NextToken is returned to page through the
193	// results.
194	Limit int32
195
196	// Set to true if pagination should stop if the service returns a pagination token
197	// that matches the most recent token provided to the service.
198	StopOnDuplicateToken bool
199}
200
201// ListTablesPaginator is a paginator for ListTables
202type ListTablesPaginator struct {
203	options   ListTablesPaginatorOptions
204	client    ListTablesAPIClient
205	params    *ListTablesInput
206	nextToken *string
207	firstPage bool
208}
209
210// NewListTablesPaginator returns a new ListTablesPaginator
211func NewListTablesPaginator(client ListTablesAPIClient, params *ListTablesInput, optFns ...func(*ListTablesPaginatorOptions)) *ListTablesPaginator {
212	if params == nil {
213		params = &ListTablesInput{}
214	}
215
216	options := ListTablesPaginatorOptions{}
217	if params.MaxResults != 0 {
218		options.Limit = params.MaxResults
219	}
220
221	for _, fn := range optFns {
222		fn(&options)
223	}
224
225	return &ListTablesPaginator{
226		options:   options,
227		client:    client,
228		params:    params,
229		firstPage: true,
230	}
231}
232
233// HasMorePages returns a boolean indicating whether more pages are available
234func (p *ListTablesPaginator) HasMorePages() bool {
235	return p.firstPage || p.nextToken != nil
236}
237
238// NextPage retrieves the next ListTables page.
239func (p *ListTablesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTablesOutput, error) {
240	if !p.HasMorePages() {
241		return nil, fmt.Errorf("no more pages available")
242	}
243
244	params := *p.params
245	params.NextToken = p.nextToken
246
247	params.MaxResults = p.options.Limit
248
249	result, err := p.client.ListTables(ctx, &params, optFns...)
250	if err != nil {
251		return nil, err
252	}
253	p.firstPage = false
254
255	prevToken := p.nextToken
256	p.nextToken = result.NextToken
257
258	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
259		p.nextToken = nil
260	}
261
262	return result, nil
263}
264
265func newServiceMetadataMiddleware_opListTables(region string) *awsmiddleware.RegisterServiceMetadata {
266	return &awsmiddleware.RegisterServiceMetadata{
267		Region:        region,
268		ServiceID:     ServiceID,
269		SigningName:   "redshift-data",
270		OperationName: "ListTables",
271	}
272}
273