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// * AWS Secrets Manager -
21// specify the Amazon Resource Name (ARN) of the secret and the cluster identifier
22// that matches the cluster in the secret.
23//
24// * Temporary credentials - specify the
25// cluster identifier, the database name, and the database user name. Permission to
26// call the redshift:GetClusterCredentials operation is required to use this
27// 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, 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 AWS 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 AWS 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
99type ListTablesOutput struct {
100
101	// A value that indicates the starting point for the next set of response records
102	// in a subsequent request. If a value is returned in a response, you can retrieve
103	// the next set of records by providing this returned NextToken value in the next
104	// NextToken parameter and retrying the command. If the NextToken field is empty,
105	// all response records have been retrieved for the request.
106	NextToken *string
107
108	// The tables that match the request pattern.
109	Tables []types.TableMember
110
111	// Metadata pertaining to the operation's result.
112	ResultMetadata middleware.Metadata
113}
114
115func addOperationListTablesMiddlewares(stack *middleware.Stack, options Options) (err error) {
116	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTables{}, middleware.After)
117	if err != nil {
118		return err
119	}
120	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTables{}, middleware.After)
121	if err != nil {
122		return err
123	}
124	if err = addSetLoggerMiddleware(stack, options); err != nil {
125		return err
126	}
127	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
128		return err
129	}
130	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addResolveEndpointMiddleware(stack, options); err != nil {
134		return err
135	}
136	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
137		return err
138	}
139	if err = addRetryMiddlewares(stack, options); err != nil {
140		return err
141	}
142	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
143		return err
144	}
145	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
146		return err
147	}
148	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
149		return err
150	}
151	if err = addClientUserAgent(stack); err != nil {
152		return err
153	}
154	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
155		return err
156	}
157	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
158		return err
159	}
160	if err = addOpListTablesValidationMiddleware(stack); err != nil {
161		return err
162	}
163	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTables(options.Region), middleware.Before); err != nil {
164		return err
165	}
166	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
167		return err
168	}
169	if err = addResponseErrorMiddleware(stack); err != nil {
170		return err
171	}
172	if err = addRequestResponseLogging(stack, options); err != nil {
173		return err
174	}
175	return nil
176}
177
178// ListTablesAPIClient is a client that implements the ListTables operation.
179type ListTablesAPIClient interface {
180	ListTables(context.Context, *ListTablesInput, ...func(*Options)) (*ListTablesOutput, error)
181}
182
183var _ ListTablesAPIClient = (*Client)(nil)
184
185// ListTablesPaginatorOptions is the paginator options for ListTables
186type ListTablesPaginatorOptions struct {
187	// The maximum number of tables to return in the response. If more tables exist
188	// than fit in one response, then NextToken is returned to page through the
189	// results.
190	Limit int32
191
192	// Set to true if pagination should stop if the service returns a pagination token
193	// that matches the most recent token provided to the service.
194	StopOnDuplicateToken bool
195}
196
197// ListTablesPaginator is a paginator for ListTables
198type ListTablesPaginator struct {
199	options   ListTablesPaginatorOptions
200	client    ListTablesAPIClient
201	params    *ListTablesInput
202	nextToken *string
203	firstPage bool
204}
205
206// NewListTablesPaginator returns a new ListTablesPaginator
207func NewListTablesPaginator(client ListTablesAPIClient, params *ListTablesInput, optFns ...func(*ListTablesPaginatorOptions)) *ListTablesPaginator {
208	if params == nil {
209		params = &ListTablesInput{}
210	}
211
212	options := ListTablesPaginatorOptions{}
213	if params.MaxResults != 0 {
214		options.Limit = params.MaxResults
215	}
216
217	for _, fn := range optFns {
218		fn(&options)
219	}
220
221	return &ListTablesPaginator{
222		options:   options,
223		client:    client,
224		params:    params,
225		firstPage: true,
226	}
227}
228
229// HasMorePages returns a boolean indicating whether more pages are available
230func (p *ListTablesPaginator) HasMorePages() bool {
231	return p.firstPage || p.nextToken != nil
232}
233
234// NextPage retrieves the next ListTables page.
235func (p *ListTablesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTablesOutput, error) {
236	if !p.HasMorePages() {
237		return nil, fmt.Errorf("no more pages available")
238	}
239
240	params := *p.params
241	params.NextToken = p.nextToken
242
243	params.MaxResults = p.options.Limit
244
245	result, err := p.client.ListTables(ctx, &params, optFns...)
246	if err != nil {
247		return nil, err
248	}
249	p.firstPage = false
250
251	prevToken := p.nextToken
252	p.nextToken = result.NextToken
253
254	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
255		p.nextToken = nil
256	}
257
258	return result, nil
259}
260
261func newServiceMetadataMiddleware_opListTables(region string) *awsmiddleware.RegisterServiceMetadata {
262	return &awsmiddleware.RegisterServiceMetadata{
263		Region:        region,
264		ServiceID:     ServiceID,
265		SigningName:   "redshift-data",
266		OperationName: "ListTables",
267	}
268}
269