1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ssoadmin
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 PermissionSets in an SSO instance.
15func (c *Client) ListPermissionSets(ctx context.Context, params *ListPermissionSetsInput, optFns ...func(*Options)) (*ListPermissionSetsOutput, error) {
16	if params == nil {
17		params = &ListPermissionSetsInput{}
18	}
19
20	result, metadata, err := c.invokeOperation(ctx, "ListPermissionSets", params, optFns, addOperationListPermissionSetsMiddlewares)
21	if err != nil {
22		return nil, err
23	}
24
25	out := result.(*ListPermissionSetsOutput)
26	out.ResultMetadata = metadata
27	return out, nil
28}
29
30type ListPermissionSetsInput struct {
31
32	// The ARN of the SSO instance under which the operation will be executed. For more
33	// information about ARNs, see Amazon Resource Names (ARNs) and AWS Service
34	// Namespaces in the AWS General Reference.
35	//
36	// This member is required.
37	InstanceArn *string
38
39	// The maximum number of results to display for the assignment.
40	MaxResults *int32
41
42	// The pagination token for the list API. Initially the value is null. Use the
43	// output of previous API calls to make subsequent calls.
44	NextToken *string
45}
46
47type ListPermissionSetsOutput struct {
48
49	// The pagination token for the list API. Initially the value is null. Use the
50	// output of previous API calls to make subsequent calls.
51	NextToken *string
52
53	// Defines the level of access on an AWS account.
54	PermissionSets []string
55
56	// Metadata pertaining to the operation's result.
57	ResultMetadata middleware.Metadata
58}
59
60func addOperationListPermissionSetsMiddlewares(stack *middleware.Stack, options Options) (err error) {
61	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListPermissionSets{}, middleware.After)
62	if err != nil {
63		return err
64	}
65	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListPermissionSets{}, middleware.After)
66	if err != nil {
67		return err
68	}
69	if err = addSetLoggerMiddleware(stack, options); err != nil {
70		return err
71	}
72	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
73		return err
74	}
75	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
76		return err
77	}
78	if err = addResolveEndpointMiddleware(stack, options); err != nil {
79		return err
80	}
81	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
82		return err
83	}
84	if err = addRetryMiddlewares(stack, options); err != nil {
85		return err
86	}
87	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
94		return err
95	}
96	if err = addClientUserAgent(stack); err != nil {
97		return err
98	}
99	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
100		return err
101	}
102	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
103		return err
104	}
105	if err = addOpListPermissionSetsValidationMiddleware(stack); err != nil {
106		return err
107	}
108	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPermissionSets(options.Region), middleware.Before); err != nil {
109		return err
110	}
111	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
112		return err
113	}
114	if err = addResponseErrorMiddleware(stack); err != nil {
115		return err
116	}
117	if err = addRequestResponseLogging(stack, options); err != nil {
118		return err
119	}
120	return nil
121}
122
123// ListPermissionSetsAPIClient is a client that implements the ListPermissionSets
124// operation.
125type ListPermissionSetsAPIClient interface {
126	ListPermissionSets(context.Context, *ListPermissionSetsInput, ...func(*Options)) (*ListPermissionSetsOutput, error)
127}
128
129var _ ListPermissionSetsAPIClient = (*Client)(nil)
130
131// ListPermissionSetsPaginatorOptions is the paginator options for
132// ListPermissionSets
133type ListPermissionSetsPaginatorOptions struct {
134	// The maximum number of results to display for the assignment.
135	Limit int32
136
137	// Set to true if pagination should stop if the service returns a pagination token
138	// that matches the most recent token provided to the service.
139	StopOnDuplicateToken bool
140}
141
142// ListPermissionSetsPaginator is a paginator for ListPermissionSets
143type ListPermissionSetsPaginator struct {
144	options   ListPermissionSetsPaginatorOptions
145	client    ListPermissionSetsAPIClient
146	params    *ListPermissionSetsInput
147	nextToken *string
148	firstPage bool
149}
150
151// NewListPermissionSetsPaginator returns a new ListPermissionSetsPaginator
152func NewListPermissionSetsPaginator(client ListPermissionSetsAPIClient, params *ListPermissionSetsInput, optFns ...func(*ListPermissionSetsPaginatorOptions)) *ListPermissionSetsPaginator {
153	options := ListPermissionSetsPaginatorOptions{}
154	if params.MaxResults != nil {
155		options.Limit = *params.MaxResults
156	}
157
158	for _, fn := range optFns {
159		fn(&options)
160	}
161
162	if params == nil {
163		params = &ListPermissionSetsInput{}
164	}
165
166	return &ListPermissionSetsPaginator{
167		options:   options,
168		client:    client,
169		params:    params,
170		firstPage: true,
171	}
172}
173
174// HasMorePages returns a boolean indicating whether more pages are available
175func (p *ListPermissionSetsPaginator) HasMorePages() bool {
176	return p.firstPage || p.nextToken != nil
177}
178
179// NextPage retrieves the next ListPermissionSets page.
180func (p *ListPermissionSetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPermissionSetsOutput, error) {
181	if !p.HasMorePages() {
182		return nil, fmt.Errorf("no more pages available")
183	}
184
185	params := *p.params
186	params.NextToken = p.nextToken
187
188	var limit *int32
189	if p.options.Limit > 0 {
190		limit = &p.options.Limit
191	}
192	params.MaxResults = limit
193
194	result, err := p.client.ListPermissionSets(ctx, &params, optFns...)
195	if err != nil {
196		return nil, err
197	}
198	p.firstPage = false
199
200	prevToken := p.nextToken
201	p.nextToken = result.NextToken
202
203	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
204		p.nextToken = nil
205	}
206
207	return result, nil
208}
209
210func newServiceMetadataMiddleware_opListPermissionSets(region string) *awsmiddleware.RegisterServiceMetadata {
211	return &awsmiddleware.RegisterServiceMetadata{
212		Region:        region,
213		ServiceID:     ServiceID,
214		SigningName:   "sso",
215		OperationName: "ListPermissionSets",
216	}
217}
218