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// Returns a summary of each of the portfolio shares that were created for the
16// specified portfolio. You can use this API to determine which accounts or
17// organizational nodes this portfolio have been shared, whether the recipient
18// entity has imported the share, and whether TagOptions are included with the
19// share. The PortfolioId and Type parameters are both required.
20func (c *Client) DescribePortfolioShares(ctx context.Context, params *DescribePortfolioSharesInput, optFns ...func(*Options)) (*DescribePortfolioSharesOutput, error) {
21	if params == nil {
22		params = &DescribePortfolioSharesInput{}
23	}
24
25	result, metadata, err := c.invokeOperation(ctx, "DescribePortfolioShares", params, optFns, c.addOperationDescribePortfolioSharesMiddlewares)
26	if err != nil {
27		return nil, err
28	}
29
30	out := result.(*DescribePortfolioSharesOutput)
31	out.ResultMetadata = metadata
32	return out, nil
33}
34
35type DescribePortfolioSharesInput struct {
36
37	// The unique identifier of the portfolio for which shares will be retrieved.
38	//
39	// This member is required.
40	PortfolioId *string
41
42	// The type of portfolio share to summarize. This field acts as a filter on the
43	// type of portfolio share, which can be one of the following: 1. ACCOUNT -
44	// Represents an external account to account share. 2. ORGANIZATION - Represents a
45	// share to an organization. This share is available to every account in the
46	// organization. 3. ORGANIZATIONAL_UNIT - Represents a share to an organizational
47	// unit. 4. ORGANIZATION_MEMBER_ACCOUNT - Represents a share to an account in the
48	// organization.
49	//
50	// This member is required.
51	Type types.DescribePortfolioShareType
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	noSmithyDocumentSerde
61}
62
63type DescribePortfolioSharesOutput struct {
64
65	// The page token to use to retrieve the next set of results. If there are no
66	// additional results, this value is null.
67	NextPageToken *string
68
69	// Summaries about each of the portfolio shares.
70	PortfolioShareDetails []types.PortfolioShareDetail
71
72	// Metadata pertaining to the operation's result.
73	ResultMetadata middleware.Metadata
74
75	noSmithyDocumentSerde
76}
77
78func (c *Client) addOperationDescribePortfolioSharesMiddlewares(stack *middleware.Stack, options Options) (err error) {
79	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribePortfolioShares{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribePortfolioShares{}, middleware.After)
84	if err != nil {
85		return err
86	}
87	if err = addSetLoggerMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
91		return err
92	}
93	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
94		return err
95	}
96	if err = addResolveEndpointMiddleware(stack, options); err != nil {
97		return err
98	}
99	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
100		return err
101	}
102	if err = addRetryMiddlewares(stack, options); err != nil {
103		return err
104	}
105	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
112		return err
113	}
114	if err = addClientUserAgent(stack); err != nil {
115		return err
116	}
117	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addOpDescribePortfolioSharesValidationMiddleware(stack); err != nil {
124		return err
125	}
126	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribePortfolioShares(options.Region), middleware.Before); err != nil {
127		return err
128	}
129	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addResponseErrorMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addRequestResponseLogging(stack, options); err != nil {
136		return err
137	}
138	return nil
139}
140
141// DescribePortfolioSharesAPIClient is a client that implements the
142// DescribePortfolioShares operation.
143type DescribePortfolioSharesAPIClient interface {
144	DescribePortfolioShares(context.Context, *DescribePortfolioSharesInput, ...func(*Options)) (*DescribePortfolioSharesOutput, error)
145}
146
147var _ DescribePortfolioSharesAPIClient = (*Client)(nil)
148
149// DescribePortfolioSharesPaginatorOptions is the paginator options for
150// DescribePortfolioShares
151type DescribePortfolioSharesPaginatorOptions struct {
152	// The maximum number of items to return with this call.
153	Limit int32
154
155	// Set to true if pagination should stop if the service returns a pagination token
156	// that matches the most recent token provided to the service.
157	StopOnDuplicateToken bool
158}
159
160// DescribePortfolioSharesPaginator is a paginator for DescribePortfolioShares
161type DescribePortfolioSharesPaginator struct {
162	options   DescribePortfolioSharesPaginatorOptions
163	client    DescribePortfolioSharesAPIClient
164	params    *DescribePortfolioSharesInput
165	nextToken *string
166	firstPage bool
167}
168
169// NewDescribePortfolioSharesPaginator returns a new
170// DescribePortfolioSharesPaginator
171func NewDescribePortfolioSharesPaginator(client DescribePortfolioSharesAPIClient, params *DescribePortfolioSharesInput, optFns ...func(*DescribePortfolioSharesPaginatorOptions)) *DescribePortfolioSharesPaginator {
172	if params == nil {
173		params = &DescribePortfolioSharesInput{}
174	}
175
176	options := DescribePortfolioSharesPaginatorOptions{}
177	if params.PageSize != 0 {
178		options.Limit = params.PageSize
179	}
180
181	for _, fn := range optFns {
182		fn(&options)
183	}
184
185	return &DescribePortfolioSharesPaginator{
186		options:   options,
187		client:    client,
188		params:    params,
189		firstPage: true,
190	}
191}
192
193// HasMorePages returns a boolean indicating whether more pages are available
194func (p *DescribePortfolioSharesPaginator) HasMorePages() bool {
195	return p.firstPage || p.nextToken != nil
196}
197
198// NextPage retrieves the next DescribePortfolioShares page.
199func (p *DescribePortfolioSharesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribePortfolioSharesOutput, error) {
200	if !p.HasMorePages() {
201		return nil, fmt.Errorf("no more pages available")
202	}
203
204	params := *p.params
205	params.PageToken = p.nextToken
206
207	params.PageSize = p.options.Limit
208
209	result, err := p.client.DescribePortfolioShares(ctx, &params, optFns...)
210	if err != nil {
211		return nil, err
212	}
213	p.firstPage = false
214
215	prevToken := p.nextToken
216	p.nextToken = result.NextPageToken
217
218	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
219		p.nextToken = nil
220	}
221
222	return result, nil
223}
224
225func newServiceMetadataMiddleware_opDescribePortfolioShares(region string) *awsmiddleware.RegisterServiceMetadata {
226	return &awsmiddleware.RegisterServiceMetadata{
227		Region:        region,
228		ServiceID:     ServiceID,
229		SigningName:   "servicecatalog",
230		OperationName: "DescribePortfolioShares",
231	}
232}
233