1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ram
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/ram/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the principals that you have shared resources with or that have shared
16// resources with you.
17func (c *Client) ListPrincipals(ctx context.Context, params *ListPrincipalsInput, optFns ...func(*Options)) (*ListPrincipalsOutput, error) {
18	if params == nil {
19		params = &ListPrincipalsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListPrincipals", params, optFns, c.addOperationListPrincipalsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListPrincipalsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListPrincipalsInput struct {
33
34	// The type of owner.
35	//
36	// This member is required.
37	ResourceOwner types.ResourceOwner
38
39	// The maximum number of results to return with a single call. To retrieve the
40	// remaining results, make another call with the returned nextToken value.
41	MaxResults *int32
42
43	// The token for the next page of results.
44	NextToken *string
45
46	// The principals.
47	Principals []string
48
49	// The Amazon Resource Name (ARN) of the resource.
50	ResourceArn *string
51
52	// The Amazon Resource Names (ARN) of the resource shares.
53	ResourceShareArns []string
54
55	// The resource type. Valid values: acm-pca:CertificateAuthority | appmesh:Mesh |
56	// codebuild:Project | codebuild:ReportGroup | ec2:CapacityReservation |
57	// ec2:DedicatedHost | ec2:LocalGatewayRouteTable | ec2:PrefixList | ec2:Subnet |
58	// ec2:TrafficMirrorTarget | ec2:TransitGateway | imagebuilder:Component |
59	// imagebuilder:Image | imagebuilder:ImageRecipe | imagebuilder:ContainerRecipe |
60	// glue:Catalog | glue:Database | glue:Table | license-manager:LicenseConfiguration
61	// I network-firewall:FirewallPolicy | network-firewall:StatefulRuleGroup |
62	// network-firewall:StatelessRuleGroup | outposts:Outpost | resource-groups:Group |
63	// rds:Cluster | route53resolver:FirewallRuleGroup
64	// |route53resolver:ResolverQueryLogConfig | route53resolver:ResolverRule |
65	// s3-outposts:Outpost | ssm-contacts:Contact | ssm-incidents:ResponsePlan
66	ResourceType *string
67
68	noSmithyDocumentSerde
69}
70
71type ListPrincipalsOutput struct {
72
73	// The token to use to retrieve the next page of results. This value is null when
74	// there are no more results to return.
75	NextToken *string
76
77	// The principals.
78	Principals []types.Principal
79
80	// Metadata pertaining to the operation's result.
81	ResultMetadata middleware.Metadata
82
83	noSmithyDocumentSerde
84}
85
86func (c *Client) addOperationListPrincipalsMiddlewares(stack *middleware.Stack, options Options) (err error) {
87	err = stack.Serialize.Add(&awsRestjson1_serializeOpListPrincipals{}, middleware.After)
88	if err != nil {
89		return err
90	}
91	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListPrincipals{}, middleware.After)
92	if err != nil {
93		return err
94	}
95	if err = addSetLoggerMiddleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
102		return err
103	}
104	if err = addResolveEndpointMiddleware(stack, options); err != nil {
105		return err
106	}
107	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
108		return err
109	}
110	if err = addRetryMiddlewares(stack, options); err != nil {
111		return err
112	}
113	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
114		return err
115	}
116	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
117		return err
118	}
119	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
120		return err
121	}
122	if err = addClientUserAgent(stack); err != nil {
123		return err
124	}
125	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
126		return err
127	}
128	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addOpListPrincipalsValidationMiddleware(stack); err != nil {
132		return err
133	}
134	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPrincipals(options.Region), middleware.Before); err != nil {
135		return err
136	}
137	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
138		return err
139	}
140	if err = addResponseErrorMiddleware(stack); err != nil {
141		return err
142	}
143	if err = addRequestResponseLogging(stack, options); err != nil {
144		return err
145	}
146	return nil
147}
148
149// ListPrincipalsAPIClient is a client that implements the ListPrincipals
150// operation.
151type ListPrincipalsAPIClient interface {
152	ListPrincipals(context.Context, *ListPrincipalsInput, ...func(*Options)) (*ListPrincipalsOutput, error)
153}
154
155var _ ListPrincipalsAPIClient = (*Client)(nil)
156
157// ListPrincipalsPaginatorOptions is the paginator options for ListPrincipals
158type ListPrincipalsPaginatorOptions struct {
159	// The maximum number of results to return with a single call. To retrieve the
160	// remaining results, make another call with the returned nextToken value.
161	Limit int32
162
163	// Set to true if pagination should stop if the service returns a pagination token
164	// that matches the most recent token provided to the service.
165	StopOnDuplicateToken bool
166}
167
168// ListPrincipalsPaginator is a paginator for ListPrincipals
169type ListPrincipalsPaginator struct {
170	options   ListPrincipalsPaginatorOptions
171	client    ListPrincipalsAPIClient
172	params    *ListPrincipalsInput
173	nextToken *string
174	firstPage bool
175}
176
177// NewListPrincipalsPaginator returns a new ListPrincipalsPaginator
178func NewListPrincipalsPaginator(client ListPrincipalsAPIClient, params *ListPrincipalsInput, optFns ...func(*ListPrincipalsPaginatorOptions)) *ListPrincipalsPaginator {
179	if params == nil {
180		params = &ListPrincipalsInput{}
181	}
182
183	options := ListPrincipalsPaginatorOptions{}
184	if params.MaxResults != nil {
185		options.Limit = *params.MaxResults
186	}
187
188	for _, fn := range optFns {
189		fn(&options)
190	}
191
192	return &ListPrincipalsPaginator{
193		options:   options,
194		client:    client,
195		params:    params,
196		firstPage: true,
197	}
198}
199
200// HasMorePages returns a boolean indicating whether more pages are available
201func (p *ListPrincipalsPaginator) HasMorePages() bool {
202	return p.firstPage || p.nextToken != nil
203}
204
205// NextPage retrieves the next ListPrincipals page.
206func (p *ListPrincipalsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPrincipalsOutput, error) {
207	if !p.HasMorePages() {
208		return nil, fmt.Errorf("no more pages available")
209	}
210
211	params := *p.params
212	params.NextToken = p.nextToken
213
214	var limit *int32
215	if p.options.Limit > 0 {
216		limit = &p.options.Limit
217	}
218	params.MaxResults = limit
219
220	result, err := p.client.ListPrincipals(ctx, &params, optFns...)
221	if err != nil {
222		return nil, err
223	}
224	p.firstPage = false
225
226	prevToken := p.nextToken
227	p.nextToken = result.NextToken
228
229	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
230		p.nextToken = nil
231	}
232
233	return result, nil
234}
235
236func newServiceMetadataMiddleware_opListPrincipals(region string) *awsmiddleware.RegisterServiceMetadata {
237	return &awsmiddleware.RegisterServiceMetadata{
238		Region:        region,
239		ServiceID:     ServiceID,
240		SigningName:   "ram",
241		OperationName: "ListPrincipals",
242	}
243}
244