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