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