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// List the databases in a cluster. A token is returned to page through the 15// database 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) ListDatabases(ctx context.Context, params *ListDatabasesInput, optFns ...func(*Options)) (*ListDatabasesOutput, error) { 26 if params == nil { 27 params = &ListDatabasesInput{} 28 } 29 30 result, metadata, err := c.invokeOperation(ctx, "ListDatabases", params, optFns, addOperationListDatabasesMiddlewares) 31 if err != nil { 32 return nil, err 33 } 34 35 out := result.(*ListDatabasesOutput) 36 out.ResultMetadata = metadata 37 return out, nil 38} 39 40type ListDatabasesInput 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. This parameter is required when authenticating using 49 // temporary credentials. 50 Database *string 51 52 // The database user name. This parameter is required when authenticating using 53 // temporary credentials. 54 DbUser *string 55 56 // The maximum number of databases to return in the response. If more databases 57 // exist than fit in one response, then NextToken is returned to page through the 58 // results. 59 MaxResults int32 60 61 // A value that indicates the starting point for the next set of response records 62 // in a subsequent request. If a value is returned in a response, you can retrieve 63 // the next set of records by providing this returned NextToken value in the next 64 // NextToken parameter and retrying the command. If the NextToken field is empty, 65 // all response records have been retrieved for the request. 66 NextToken *string 67 68 // The name or ARN of the secret that enables access to the database. This 69 // parameter is required when authenticating using AWS Secrets Manager. 70 SecretArn *string 71} 72 73type ListDatabasesOutput struct { 74 75 // The names of databases. 76 Databases []string 77 78 // A value that indicates the starting point for the next set of response records 79 // in a subsequent request. If a value is returned in a response, you can retrieve 80 // the next set of records by providing this returned NextToken value in the next 81 // NextToken parameter and retrying the command. If the NextToken field is empty, 82 // all response records have been retrieved for the request. 83 NextToken *string 84 85 // Metadata pertaining to the operation's result. 86 ResultMetadata middleware.Metadata 87} 88 89func addOperationListDatabasesMiddlewares(stack *middleware.Stack, options Options) (err error) { 90 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListDatabases{}, middleware.After) 91 if err != nil { 92 return err 93 } 94 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListDatabases{}, middleware.After) 95 if err != nil { 96 return err 97 } 98 if err = addSetLoggerMiddleware(stack, options); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 102 return err 103 } 104 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 105 return err 106 } 107 if err = addResolveEndpointMiddleware(stack, options); err != nil { 108 return err 109 } 110 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 111 return err 112 } 113 if err = addRetryMiddlewares(stack, options); err != nil { 114 return err 115 } 116 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 117 return err 118 } 119 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 120 return err 121 } 122 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 123 return err 124 } 125 if err = addClientUserAgent(stack); err != nil { 126 return err 127 } 128 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 129 return err 130 } 131 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 132 return err 133 } 134 if err = addOpListDatabasesValidationMiddleware(stack); err != nil { 135 return err 136 } 137 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDatabases(options.Region), middleware.Before); err != nil { 138 return err 139 } 140 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 141 return err 142 } 143 if err = addResponseErrorMiddleware(stack); err != nil { 144 return err 145 } 146 if err = addRequestResponseLogging(stack, options); err != nil { 147 return err 148 } 149 return nil 150} 151 152// ListDatabasesAPIClient is a client that implements the ListDatabases operation. 153type ListDatabasesAPIClient interface { 154 ListDatabases(context.Context, *ListDatabasesInput, ...func(*Options)) (*ListDatabasesOutput, error) 155} 156 157var _ ListDatabasesAPIClient = (*Client)(nil) 158 159// ListDatabasesPaginatorOptions is the paginator options for ListDatabases 160type ListDatabasesPaginatorOptions struct { 161 // The maximum number of databases to return in the response. If more databases 162 // exist than fit in one response, then NextToken is returned to page through the 163 // results. 164 Limit int32 165 166 // Set to true if pagination should stop if the service returns a pagination token 167 // that matches the most recent token provided to the service. 168 StopOnDuplicateToken bool 169} 170 171// ListDatabasesPaginator is a paginator for ListDatabases 172type ListDatabasesPaginator struct { 173 options ListDatabasesPaginatorOptions 174 client ListDatabasesAPIClient 175 params *ListDatabasesInput 176 nextToken *string 177 firstPage bool 178} 179 180// NewListDatabasesPaginator returns a new ListDatabasesPaginator 181func NewListDatabasesPaginator(client ListDatabasesAPIClient, params *ListDatabasesInput, optFns ...func(*ListDatabasesPaginatorOptions)) *ListDatabasesPaginator { 182 if params == nil { 183 params = &ListDatabasesInput{} 184 } 185 186 options := ListDatabasesPaginatorOptions{} 187 if params.MaxResults != 0 { 188 options.Limit = params.MaxResults 189 } 190 191 for _, fn := range optFns { 192 fn(&options) 193 } 194 195 return &ListDatabasesPaginator{ 196 options: options, 197 client: client, 198 params: params, 199 firstPage: true, 200 } 201} 202 203// HasMorePages returns a boolean indicating whether more pages are available 204func (p *ListDatabasesPaginator) HasMorePages() bool { 205 return p.firstPage || p.nextToken != nil 206} 207 208// NextPage retrieves the next ListDatabases page. 209func (p *ListDatabasesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDatabasesOutput, error) { 210 if !p.HasMorePages() { 211 return nil, fmt.Errorf("no more pages available") 212 } 213 214 params := *p.params 215 params.NextToken = p.nextToken 216 217 params.MaxResults = p.options.Limit 218 219 result, err := p.client.ListDatabases(ctx, ¶ms, optFns...) 220 if err != nil { 221 return nil, err 222 } 223 p.firstPage = false 224 225 prevToken := p.nextToken 226 p.nextToken = result.NextToken 227 228 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 229 p.nextToken = nil 230 } 231 232 return result, nil 233} 234 235func newServiceMetadataMiddleware_opListDatabases(region string) *awsmiddleware.RegisterServiceMetadata { 236 return &awsmiddleware.RegisterServiceMetadata{ 237 Region: region, 238 ServiceID: ServiceID, 239 SigningName: "redshift-data", 240 OperationName: "ListDatabases", 241 } 242} 243