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