1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package redshift
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/redshift/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns information about Amazon Redshift security groups. If the name of a
16// security group is specified, the response will contain only information about
17// only that security group. For information about managing security groups, go to
18// Amazon Redshift Cluster Security Groups
19// (https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-security-groups.html)
20// in the Amazon Redshift Cluster Management Guide. If you specify both tag keys
21// and tag values in the same request, Amazon Redshift returns all security groups
22// that match any combination of the specified keys and values. For example, if you
23// have owner and environment for tag keys, and admin and test for tag values, all
24// security groups that have any combination of those values are returned. If both
25// tag keys and values are omitted from the request, security groups are returned
26// regardless of whether they have tag keys or values associated with them.
27func (c *Client) DescribeClusterSecurityGroups(ctx context.Context, params *DescribeClusterSecurityGroupsInput, optFns ...func(*Options)) (*DescribeClusterSecurityGroupsOutput, error) {
28	if params == nil {
29		params = &DescribeClusterSecurityGroupsInput{}
30	}
31
32	result, metadata, err := c.invokeOperation(ctx, "DescribeClusterSecurityGroups", params, optFns, addOperationDescribeClusterSecurityGroupsMiddlewares)
33	if err != nil {
34		return nil, err
35	}
36
37	out := result.(*DescribeClusterSecurityGroupsOutput)
38	out.ResultMetadata = metadata
39	return out, nil
40}
41
42//
43type DescribeClusterSecurityGroupsInput struct {
44
45	// The name of a cluster security group for which you are requesting details. You
46	// can specify either the Marker parameter or a ClusterSecurityGroupName parameter,
47	// but not both. Example: securitygroup1
48	ClusterSecurityGroupName *string
49
50	// An optional parameter that specifies the starting point to return a set of
51	// response records. When the results of a DescribeClusterSecurityGroups request
52	// exceed the value specified in MaxRecords, AWS returns a value in the Marker
53	// field of the response. You can retrieve the next set of response records by
54	// providing the returned marker value in the Marker parameter and retrying the
55	// request. Constraints: You can specify either the ClusterSecurityGroupName
56	// parameter or the Marker parameter, but not both.
57	Marker *string
58
59	// The maximum number of response records to return in each call. If the number of
60	// remaining response records exceeds the specified MaxRecords value, a value is
61	// returned in a marker field of the response. You can retrieve the next set of
62	// records by retrying the command with the returned marker value. Default: 100
63	// Constraints: minimum 20, maximum 100.
64	MaxRecords *int32
65
66	// A tag key or keys for which you want to return all matching cluster security
67	// groups that are associated with the specified key or keys. For example, suppose
68	// that you have security groups that are tagged with keys called owner and
69	// environment. If you specify both of these tag keys in the request, Amazon
70	// Redshift returns a response with the security groups that have either or both of
71	// these tag keys associated with them.
72	TagKeys []string
73
74	// A tag value or values for which you want to return all matching cluster security
75	// groups that are associated with the specified tag value or values. For example,
76	// suppose that you have security groups that are tagged with values called admin
77	// and test. If you specify both of these tag values in the request, Amazon
78	// Redshift returns a response with the security groups that have either or both of
79	// these tag values associated with them.
80	TagValues []string
81}
82
83//
84type DescribeClusterSecurityGroupsOutput struct {
85
86	// A list of ClusterSecurityGroup instances.
87	ClusterSecurityGroups []types.ClusterSecurityGroup
88
89	// A value that indicates the starting point for the next set of response records
90	// in a subsequent request. If a value is returned in a response, you can retrieve
91	// the next set of records by providing this returned marker value in the Marker
92	// parameter and retrying the command. If the Marker field is empty, all response
93	// records have been retrieved for the request.
94	Marker *string
95
96	// Metadata pertaining to the operation's result.
97	ResultMetadata middleware.Metadata
98}
99
100func addOperationDescribeClusterSecurityGroupsMiddlewares(stack *middleware.Stack, options Options) (err error) {
101	err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeClusterSecurityGroups{}, middleware.After)
102	if err != nil {
103		return err
104	}
105	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeClusterSecurityGroups{}, middleware.After)
106	if err != nil {
107		return err
108	}
109	if err = addSetLoggerMiddleware(stack, options); err != nil {
110		return err
111	}
112	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
116		return err
117	}
118	if err = addResolveEndpointMiddleware(stack, options); err != nil {
119		return err
120	}
121	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
122		return err
123	}
124	if err = addRetryMiddlewares(stack, options); err != nil {
125		return err
126	}
127	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
128		return err
129	}
130	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
131		return err
132	}
133	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
134		return err
135	}
136	if err = addClientUserAgent(stack); err != nil {
137		return err
138	}
139	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
140		return err
141	}
142	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
143		return err
144	}
145	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeClusterSecurityGroups(options.Region), middleware.Before); err != nil {
146		return err
147	}
148	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addResponseErrorMiddleware(stack); err != nil {
152		return err
153	}
154	if err = addRequestResponseLogging(stack, options); err != nil {
155		return err
156	}
157	return nil
158}
159
160// DescribeClusterSecurityGroupsAPIClient is a client that implements the
161// DescribeClusterSecurityGroups operation.
162type DescribeClusterSecurityGroupsAPIClient interface {
163	DescribeClusterSecurityGroups(context.Context, *DescribeClusterSecurityGroupsInput, ...func(*Options)) (*DescribeClusterSecurityGroupsOutput, error)
164}
165
166var _ DescribeClusterSecurityGroupsAPIClient = (*Client)(nil)
167
168// DescribeClusterSecurityGroupsPaginatorOptions is the paginator options for
169// DescribeClusterSecurityGroups
170type DescribeClusterSecurityGroupsPaginatorOptions struct {
171	// The maximum number of response records to return in each call. If the number of
172	// remaining response records exceeds the specified MaxRecords value, a value is
173	// returned in a marker field of the response. You can retrieve the next set of
174	// records by retrying the command with the returned marker value. Default: 100
175	// Constraints: minimum 20, maximum 100.
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// DescribeClusterSecurityGroupsPaginator is a paginator for
184// DescribeClusterSecurityGroups
185type DescribeClusterSecurityGroupsPaginator struct {
186	options   DescribeClusterSecurityGroupsPaginatorOptions
187	client    DescribeClusterSecurityGroupsAPIClient
188	params    *DescribeClusterSecurityGroupsInput
189	nextToken *string
190	firstPage bool
191}
192
193// NewDescribeClusterSecurityGroupsPaginator returns a new
194// DescribeClusterSecurityGroupsPaginator
195func NewDescribeClusterSecurityGroupsPaginator(client DescribeClusterSecurityGroupsAPIClient, params *DescribeClusterSecurityGroupsInput, optFns ...func(*DescribeClusterSecurityGroupsPaginatorOptions)) *DescribeClusterSecurityGroupsPaginator {
196	if params == nil {
197		params = &DescribeClusterSecurityGroupsInput{}
198	}
199
200	options := DescribeClusterSecurityGroupsPaginatorOptions{}
201	if params.MaxRecords != nil {
202		options.Limit = *params.MaxRecords
203	}
204
205	for _, fn := range optFns {
206		fn(&options)
207	}
208
209	return &DescribeClusterSecurityGroupsPaginator{
210		options:   options,
211		client:    client,
212		params:    params,
213		firstPage: true,
214	}
215}
216
217// HasMorePages returns a boolean indicating whether more pages are available
218func (p *DescribeClusterSecurityGroupsPaginator) HasMorePages() bool {
219	return p.firstPage || p.nextToken != nil
220}
221
222// NextPage retrieves the next DescribeClusterSecurityGroups page.
223func (p *DescribeClusterSecurityGroupsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeClusterSecurityGroupsOutput, error) {
224	if !p.HasMorePages() {
225		return nil, fmt.Errorf("no more pages available")
226	}
227
228	params := *p.params
229	params.Marker = p.nextToken
230
231	var limit *int32
232	if p.options.Limit > 0 {
233		limit = &p.options.Limit
234	}
235	params.MaxRecords = limit
236
237	result, err := p.client.DescribeClusterSecurityGroups(ctx, &params, optFns...)
238	if err != nil {
239		return nil, err
240	}
241	p.firstPage = false
242
243	prevToken := p.nextToken
244	p.nextToken = result.Marker
245
246	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
247		p.nextToken = nil
248	}
249
250	return result, nil
251}
252
253func newServiceMetadataMiddleware_opDescribeClusterSecurityGroups(region string) *awsmiddleware.RegisterServiceMetadata {
254	return &awsmiddleware.RegisterServiceMetadata{
255		Region:        region,
256		ServiceID:     ServiceID,
257		SigningName:   "redshift",
258		OperationName: "DescribeClusterSecurityGroups",
259	}
260}
261