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 resources that you added to a resource shares or the resources that
16// are shared with you.
17func (c *Client) ListResources(ctx context.Context, params *ListResourcesInput, optFns ...func(*Options)) (*ListResourcesOutput, error) {
18	if params == nil {
19		params = &ListResourcesInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListResources", params, optFns, addOperationListResourcesMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListResourcesOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListResourcesInput 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 principal.
47	Principal *string
48
49	// The Amazon Resource Names (ARN) of the resources.
50	ResourceArns []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	ResourceType *string
66}
67
68type ListResourcesOutput struct {
69
70	// The token to use to retrieve the next page of results. This value is null when
71	// there are no more results to return.
72	NextToken *string
73
74	// Information about the resources.
75	Resources []types.Resource
76
77	// Metadata pertaining to the operation's result.
78	ResultMetadata middleware.Metadata
79}
80
81func addOperationListResourcesMiddlewares(stack *middleware.Stack, options Options) (err error) {
82	err = stack.Serialize.Add(&awsRestjson1_serializeOpListResources{}, middleware.After)
83	if err != nil {
84		return err
85	}
86	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListResources{}, middleware.After)
87	if err != nil {
88		return err
89	}
90	if err = addSetLoggerMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
97		return err
98	}
99	if err = addResolveEndpointMiddleware(stack, options); err != nil {
100		return err
101	}
102	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
103		return err
104	}
105	if err = addRetryMiddlewares(stack, options); err != nil {
106		return err
107	}
108	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
112		return err
113	}
114	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
115		return err
116	}
117	if err = addClientUserAgent(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addOpListResourcesValidationMiddleware(stack); err != nil {
127		return err
128	}
129	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListResources(options.Region), middleware.Before); err != nil {
130		return err
131	}
132	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addResponseErrorMiddleware(stack); err != nil {
136		return err
137	}
138	if err = addRequestResponseLogging(stack, options); err != nil {
139		return err
140	}
141	return nil
142}
143
144// ListResourcesAPIClient is a client that implements the ListResources operation.
145type ListResourcesAPIClient interface {
146	ListResources(context.Context, *ListResourcesInput, ...func(*Options)) (*ListResourcesOutput, error)
147}
148
149var _ ListResourcesAPIClient = (*Client)(nil)
150
151// ListResourcesPaginatorOptions is the paginator options for ListResources
152type ListResourcesPaginatorOptions struct {
153	// The maximum number of results to return with a single call. To retrieve the
154	// remaining results, make another call with the returned nextToken value.
155	Limit int32
156
157	// Set to true if pagination should stop if the service returns a pagination token
158	// that matches the most recent token provided to the service.
159	StopOnDuplicateToken bool
160}
161
162// ListResourcesPaginator is a paginator for ListResources
163type ListResourcesPaginator struct {
164	options   ListResourcesPaginatorOptions
165	client    ListResourcesAPIClient
166	params    *ListResourcesInput
167	nextToken *string
168	firstPage bool
169}
170
171// NewListResourcesPaginator returns a new ListResourcesPaginator
172func NewListResourcesPaginator(client ListResourcesAPIClient, params *ListResourcesInput, optFns ...func(*ListResourcesPaginatorOptions)) *ListResourcesPaginator {
173	if params == nil {
174		params = &ListResourcesInput{}
175	}
176
177	options := ListResourcesPaginatorOptions{}
178	if params.MaxResults != nil {
179		options.Limit = *params.MaxResults
180	}
181
182	for _, fn := range optFns {
183		fn(&options)
184	}
185
186	return &ListResourcesPaginator{
187		options:   options,
188		client:    client,
189		params:    params,
190		firstPage: true,
191	}
192}
193
194// HasMorePages returns a boolean indicating whether more pages are available
195func (p *ListResourcesPaginator) HasMorePages() bool {
196	return p.firstPage || p.nextToken != nil
197}
198
199// NextPage retrieves the next ListResources page.
200func (p *ListResourcesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListResourcesOutput, error) {
201	if !p.HasMorePages() {
202		return nil, fmt.Errorf("no more pages available")
203	}
204
205	params := *p.params
206	params.NextToken = p.nextToken
207
208	var limit *int32
209	if p.options.Limit > 0 {
210		limit = &p.options.Limit
211	}
212	params.MaxResults = limit
213
214	result, err := p.client.ListResources(ctx, &params, optFns...)
215	if err != nil {
216		return nil, err
217	}
218	p.firstPage = false
219
220	prevToken := p.nextToken
221	p.nextToken = result.NextToken
222
223	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
224		p.nextToken = nil
225	}
226
227	return result, nil
228}
229
230func newServiceMetadataMiddleware_opListResources(region string) *awsmiddleware.RegisterServiceMetadata {
231	return &awsmiddleware.RegisterServiceMetadata{
232		Region:        region,
233		ServiceID:     ServiceID,
234		SigningName:   "ram",
235		OperationName: "ListResources",
236	}
237}
238