1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package frauddetector
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/frauddetector/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists all tags associated with the resource. This is a paginated API. To get the
16// next page results, provide the pagination token from the response as part of
17// your request. A null pagination token fetches the records from the beginning.
18func (c *Client) ListTagsForResource(ctx context.Context, params *ListTagsForResourceInput, optFns ...func(*Options)) (*ListTagsForResourceOutput, error) {
19	if params == nil {
20		params = &ListTagsForResourceInput{}
21	}
22
23	result, metadata, err := c.invokeOperation(ctx, "ListTagsForResource", params, optFns, addOperationListTagsForResourceMiddlewares)
24	if err != nil {
25		return nil, err
26	}
27
28	out := result.(*ListTagsForResourceOutput)
29	out.ResultMetadata = metadata
30	return out, nil
31}
32
33type ListTagsForResourceInput struct {
34
35	// The ARN that specifies the resource whose tags you want to list.
36	//
37	// This member is required.
38	ResourceARN *string
39
40	// The maximum number of objects to return for the request.
41	MaxResults *int32
42
43	// The next token from the previous results.
44	NextToken *string
45}
46
47type ListTagsForResourceOutput struct {
48
49	// The next token for subsequent requests.
50	NextToken *string
51
52	// A collection of key and value pairs.
53	Tags []types.Tag
54
55	// Metadata pertaining to the operation's result.
56	ResultMetadata middleware.Metadata
57}
58
59func addOperationListTagsForResourceMiddlewares(stack *middleware.Stack, options Options) (err error) {
60	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTagsForResource{}, middleware.After)
61	if err != nil {
62		return err
63	}
64	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTagsForResource{}, 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 = addOpListTagsForResourceValidationMiddleware(stack); err != nil {
105		return err
106	}
107	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTagsForResource(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// ListTagsForResourceAPIClient is a client that implements the ListTagsForResource
123// operation.
124type ListTagsForResourceAPIClient interface {
125	ListTagsForResource(context.Context, *ListTagsForResourceInput, ...func(*Options)) (*ListTagsForResourceOutput, error)
126}
127
128var _ ListTagsForResourceAPIClient = (*Client)(nil)
129
130// ListTagsForResourcePaginatorOptions is the paginator options for
131// ListTagsForResource
132type ListTagsForResourcePaginatorOptions struct {
133	// The maximum number of objects to return for the request.
134	Limit int32
135
136	// Set to true if pagination should stop if the service returns a pagination token
137	// that matches the most recent token provided to the service.
138	StopOnDuplicateToken bool
139}
140
141// ListTagsForResourcePaginator is a paginator for ListTagsForResource
142type ListTagsForResourcePaginator struct {
143	options   ListTagsForResourcePaginatorOptions
144	client    ListTagsForResourceAPIClient
145	params    *ListTagsForResourceInput
146	nextToken *string
147	firstPage bool
148}
149
150// NewListTagsForResourcePaginator returns a new ListTagsForResourcePaginator
151func NewListTagsForResourcePaginator(client ListTagsForResourceAPIClient, params *ListTagsForResourceInput, optFns ...func(*ListTagsForResourcePaginatorOptions)) *ListTagsForResourcePaginator {
152	options := ListTagsForResourcePaginatorOptions{}
153	if params.MaxResults != nil {
154		options.Limit = *params.MaxResults
155	}
156
157	for _, fn := range optFns {
158		fn(&options)
159	}
160
161	if params == nil {
162		params = &ListTagsForResourceInput{}
163	}
164
165	return &ListTagsForResourcePaginator{
166		options:   options,
167		client:    client,
168		params:    params,
169		firstPage: true,
170	}
171}
172
173// HasMorePages returns a boolean indicating whether more pages are available
174func (p *ListTagsForResourcePaginator) HasMorePages() bool {
175	return p.firstPage || p.nextToken != nil
176}
177
178// NextPage retrieves the next ListTagsForResource page.
179func (p *ListTagsForResourcePaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTagsForResourceOutput, error) {
180	if !p.HasMorePages() {
181		return nil, fmt.Errorf("no more pages available")
182	}
183
184	params := *p.params
185	params.NextToken = p.nextToken
186
187	var limit *int32
188	if p.options.Limit > 0 {
189		limit = &p.options.Limit
190	}
191	params.MaxResults = limit
192
193	result, err := p.client.ListTagsForResource(ctx, &params, optFns...)
194	if err != nil {
195		return nil, err
196	}
197	p.firstPage = false
198
199	prevToken := p.nextToken
200	p.nextToken = result.NextToken
201
202	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
203		p.nextToken = nil
204	}
205
206	return result, nil
207}
208
209func newServiceMetadataMiddleware_opListTagsForResource(region string) *awsmiddleware.RegisterServiceMetadata {
210	return &awsmiddleware.RegisterServiceMetadata{
211		Region:        region,
212		ServiceID:     ServiceID,
213		SigningName:   "frauddetector",
214		OperationName: "ListTagsForResource",
215	}
216}
217