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