1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package cloudformation
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/cloudformation/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns summary information about stack sets that are associated with the
16// user.
17//
18// * [Self-managed permissions] If you set the CallAs parameter to SELF
19// while signed in to your AWS account, ListStackSets returns all self-managed
20// stack sets in your AWS account.
21//
22// * [Service-managed permissions] If you set the
23// CallAs parameter to SELF while signed in to the organization's management
24// account, ListStackSets returns all stack sets in the management account.
25//
26// *
27// [Service-managed permissions] If you set the CallAs parameter to DELEGATED_ADMIN
28// while signed in to your member account, ListStackSets returns all stack sets
29// with service-managed permissions in the management account.
30func (c *Client) ListStackSets(ctx context.Context, params *ListStackSetsInput, optFns ...func(*Options)) (*ListStackSetsOutput, error) {
31	if params == nil {
32		params = &ListStackSetsInput{}
33	}
34
35	result, metadata, err := c.invokeOperation(ctx, "ListStackSets", params, optFns, addOperationListStackSetsMiddlewares)
36	if err != nil {
37		return nil, err
38	}
39
40	out := result.(*ListStackSetsOutput)
41	out.ResultMetadata = metadata
42	return out, nil
43}
44
45type ListStackSetsInput struct {
46
47	// [Service-managed permissions] Specifies whether you are acting as an account
48	// administrator in the management account or as a delegated administrator in a
49	// member account. By default, SELF is specified. Use SELF for stack sets with
50	// self-managed permissions.
51	//
52	// * If you are signed in to the management account,
53	// specify SELF.
54	//
55	// * If you are signed in to a delegated administrator account,
56	// specify DELEGATED_ADMIN. Your AWS account must be registered as a delegated
57	// administrator in the management account. For more information, see Register a
58	// delegated administrator
59	// (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-delegated-admin.html)
60	// in the AWS CloudFormation User Guide.
61	CallAs types.CallAs
62
63	// The maximum number of results to be returned with a single call. If the number
64	// of available results exceeds this maximum, the response includes a NextToken
65	// value that you can assign to the NextToken request parameter to get the next set
66	// of results.
67	MaxResults *int32
68
69	// If the previous paginated request didn't return all of the remaining results,
70	// the response object's NextToken parameter value is set to a token. To retrieve
71	// the next set of results, call ListStackSets again and assign that token to the
72	// request object's NextToken parameter. If there are no remaining results, the
73	// previous response object's NextToken parameter is set to null.
74	NextToken *string
75
76	// The status of the stack sets that you want to get summary information about.
77	Status types.StackSetStatus
78}
79
80type ListStackSetsOutput struct {
81
82	// If the request doesn't return all of the remaining results, NextToken is set to
83	// a token. To retrieve the next set of results, call ListStackInstances again and
84	// assign that token to the request object's NextToken parameter. If the request
85	// returns all results, NextToken is set to null.
86	NextToken *string
87
88	// A list of StackSetSummary structures that contain information about the user's
89	// stack sets.
90	Summaries []types.StackSetSummary
91
92	// Metadata pertaining to the operation's result.
93	ResultMetadata middleware.Metadata
94}
95
96func addOperationListStackSetsMiddlewares(stack *middleware.Stack, options Options) (err error) {
97	err = stack.Serialize.Add(&awsAwsquery_serializeOpListStackSets{}, middleware.After)
98	if err != nil {
99		return err
100	}
101	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpListStackSets{}, middleware.After)
102	if err != nil {
103		return err
104	}
105	if err = addSetLoggerMiddleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
112		return err
113	}
114	if err = addResolveEndpointMiddleware(stack, options); err != nil {
115		return err
116	}
117	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
118		return err
119	}
120	if err = addRetryMiddlewares(stack, options); err != nil {
121		return err
122	}
123	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
124		return err
125	}
126	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
127		return err
128	}
129	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
130		return err
131	}
132	if err = addClientUserAgent(stack); err != nil {
133		return err
134	}
135	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
136		return err
137	}
138	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
139		return err
140	}
141	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListStackSets(options.Region), middleware.Before); err != nil {
142		return err
143	}
144	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
145		return err
146	}
147	if err = addResponseErrorMiddleware(stack); err != nil {
148		return err
149	}
150	if err = addRequestResponseLogging(stack, options); err != nil {
151		return err
152	}
153	return nil
154}
155
156// ListStackSetsAPIClient is a client that implements the ListStackSets operation.
157type ListStackSetsAPIClient interface {
158	ListStackSets(context.Context, *ListStackSetsInput, ...func(*Options)) (*ListStackSetsOutput, error)
159}
160
161var _ ListStackSetsAPIClient = (*Client)(nil)
162
163// ListStackSetsPaginatorOptions is the paginator options for ListStackSets
164type ListStackSetsPaginatorOptions struct {
165	// The maximum number of results to be returned with a single call. If the number
166	// of available results exceeds this maximum, the response includes a NextToken
167	// value that you can assign to the NextToken request parameter to get the next set
168	// of results.
169	Limit int32
170
171	// Set to true if pagination should stop if the service returns a pagination token
172	// that matches the most recent token provided to the service.
173	StopOnDuplicateToken bool
174}
175
176// ListStackSetsPaginator is a paginator for ListStackSets
177type ListStackSetsPaginator struct {
178	options   ListStackSetsPaginatorOptions
179	client    ListStackSetsAPIClient
180	params    *ListStackSetsInput
181	nextToken *string
182	firstPage bool
183}
184
185// NewListStackSetsPaginator returns a new ListStackSetsPaginator
186func NewListStackSetsPaginator(client ListStackSetsAPIClient, params *ListStackSetsInput, optFns ...func(*ListStackSetsPaginatorOptions)) *ListStackSetsPaginator {
187	if params == nil {
188		params = &ListStackSetsInput{}
189	}
190
191	options := ListStackSetsPaginatorOptions{}
192	if params.MaxResults != nil {
193		options.Limit = *params.MaxResults
194	}
195
196	for _, fn := range optFns {
197		fn(&options)
198	}
199
200	return &ListStackSetsPaginator{
201		options:   options,
202		client:    client,
203		params:    params,
204		firstPage: true,
205	}
206}
207
208// HasMorePages returns a boolean indicating whether more pages are available
209func (p *ListStackSetsPaginator) HasMorePages() bool {
210	return p.firstPage || p.nextToken != nil
211}
212
213// NextPage retrieves the next ListStackSets page.
214func (p *ListStackSetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListStackSetsOutput, error) {
215	if !p.HasMorePages() {
216		return nil, fmt.Errorf("no more pages available")
217	}
218
219	params := *p.params
220	params.NextToken = p.nextToken
221
222	var limit *int32
223	if p.options.Limit > 0 {
224		limit = &p.options.Limit
225	}
226	params.MaxResults = limit
227
228	result, err := p.client.ListStackSets(ctx, &params, optFns...)
229	if err != nil {
230		return nil, err
231	}
232	p.firstPage = false
233
234	prevToken := p.nextToken
235	p.nextToken = result.NextToken
236
237	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
238		p.nextToken = nil
239	}
240
241	return result, nil
242}
243
244func newServiceMetadataMiddleware_opListStackSets(region string) *awsmiddleware.RegisterServiceMetadata {
245	return &awsmiddleware.RegisterServiceMetadata{
246		Region:        region,
247		ServiceID:     ServiceID,
248		SigningName:   "cloudformation",
249		OperationName: "ListStackSets",
250	}
251}
252