1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package servicecatalog
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/servicecatalog/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists all principal ARNs associated with the specified portfolio.
16func (c *Client) ListPrincipalsForPortfolio(ctx context.Context, params *ListPrincipalsForPortfolioInput, optFns ...func(*Options)) (*ListPrincipalsForPortfolioOutput, error) {
17	if params == nil {
18		params = &ListPrincipalsForPortfolioInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListPrincipalsForPortfolio", params, optFns, addOperationListPrincipalsForPortfolioMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListPrincipalsForPortfolioOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListPrincipalsForPortfolioInput struct {
32
33	// The portfolio identifier.
34	//
35	// This member is required.
36	PortfolioId *string
37
38	// The language code.
39	//
40	// * en - English (default)
41	//
42	// * jp - Japanese
43	//
44	// * zh - Chinese
45	AcceptLanguage *string
46
47	// The maximum number of items to return with this call.
48	PageSize int32
49
50	// The page token for the next set of results. To retrieve the first set of
51	// results, use null.
52	PageToken *string
53}
54
55type ListPrincipalsForPortfolioOutput struct {
56
57	// The page token to use to retrieve the next set of results. If there are no
58	// additional results, this value is null.
59	NextPageToken *string
60
61	// The IAM principals (users or roles) associated with the portfolio.
62	Principals []types.Principal
63
64	// Metadata pertaining to the operation's result.
65	ResultMetadata middleware.Metadata
66}
67
68func addOperationListPrincipalsForPortfolioMiddlewares(stack *middleware.Stack, options Options) (err error) {
69	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListPrincipalsForPortfolio{}, middleware.After)
70	if err != nil {
71		return err
72	}
73	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListPrincipalsForPortfolio{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	if err = addSetLoggerMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
81		return err
82	}
83	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
84		return err
85	}
86	if err = addResolveEndpointMiddleware(stack, options); err != nil {
87		return err
88	}
89	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
90		return err
91	}
92	if err = addRetryMiddlewares(stack, options); err != nil {
93		return err
94	}
95	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
102		return err
103	}
104	if err = addClientUserAgent(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addOpListPrincipalsForPortfolioValidationMiddleware(stack); err != nil {
114		return err
115	}
116	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPrincipalsForPortfolio(options.Region), middleware.Before); err != nil {
117		return err
118	}
119	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addResponseErrorMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addRequestResponseLogging(stack, options); err != nil {
126		return err
127	}
128	return nil
129}
130
131// ListPrincipalsForPortfolioAPIClient is a client that implements the
132// ListPrincipalsForPortfolio operation.
133type ListPrincipalsForPortfolioAPIClient interface {
134	ListPrincipalsForPortfolio(context.Context, *ListPrincipalsForPortfolioInput, ...func(*Options)) (*ListPrincipalsForPortfolioOutput, error)
135}
136
137var _ ListPrincipalsForPortfolioAPIClient = (*Client)(nil)
138
139// ListPrincipalsForPortfolioPaginatorOptions is the paginator options for
140// ListPrincipalsForPortfolio
141type ListPrincipalsForPortfolioPaginatorOptions struct {
142	// The maximum number of items to return with this call.
143	Limit int32
144
145	// Set to true if pagination should stop if the service returns a pagination token
146	// that matches the most recent token provided to the service.
147	StopOnDuplicateToken bool
148}
149
150// ListPrincipalsForPortfolioPaginator is a paginator for
151// ListPrincipalsForPortfolio
152type ListPrincipalsForPortfolioPaginator struct {
153	options   ListPrincipalsForPortfolioPaginatorOptions
154	client    ListPrincipalsForPortfolioAPIClient
155	params    *ListPrincipalsForPortfolioInput
156	nextToken *string
157	firstPage bool
158}
159
160// NewListPrincipalsForPortfolioPaginator returns a new
161// ListPrincipalsForPortfolioPaginator
162func NewListPrincipalsForPortfolioPaginator(client ListPrincipalsForPortfolioAPIClient, params *ListPrincipalsForPortfolioInput, optFns ...func(*ListPrincipalsForPortfolioPaginatorOptions)) *ListPrincipalsForPortfolioPaginator {
163	options := ListPrincipalsForPortfolioPaginatorOptions{}
164	if params.PageSize != 0 {
165		options.Limit = params.PageSize
166	}
167
168	for _, fn := range optFns {
169		fn(&options)
170	}
171
172	if params == nil {
173		params = &ListPrincipalsForPortfolioInput{}
174	}
175
176	return &ListPrincipalsForPortfolioPaginator{
177		options:   options,
178		client:    client,
179		params:    params,
180		firstPage: true,
181	}
182}
183
184// HasMorePages returns a boolean indicating whether more pages are available
185func (p *ListPrincipalsForPortfolioPaginator) HasMorePages() bool {
186	return p.firstPage || p.nextToken != nil
187}
188
189// NextPage retrieves the next ListPrincipalsForPortfolio page.
190func (p *ListPrincipalsForPortfolioPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPrincipalsForPortfolioOutput, error) {
191	if !p.HasMorePages() {
192		return nil, fmt.Errorf("no more pages available")
193	}
194
195	params := *p.params
196	params.PageToken = p.nextToken
197
198	params.PageSize = p.options.Limit
199
200	result, err := p.client.ListPrincipalsForPortfolio(ctx, &params, optFns...)
201	if err != nil {
202		return nil, err
203	}
204	p.firstPage = false
205
206	prevToken := p.nextToken
207	p.nextToken = result.NextPageToken
208
209	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
210		p.nextToken = nil
211	}
212
213	return result, nil
214}
215
216func newServiceMetadataMiddleware_opListPrincipalsForPortfolio(region string) *awsmiddleware.RegisterServiceMetadata {
217	return &awsmiddleware.RegisterServiceMetadata{
218		Region:        region,
219		ServiceID:     ServiceID,
220		SigningName:   "servicecatalog",
221		OperationName: "ListPrincipalsForPortfolio",
222	}
223}
224