1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package efs
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/efs/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists all tags for a top-level EFS resource. You must provide the ID of the
16// resource that you want to retrieve the tags for. This operation requires
17// permissions for the elasticfilesystem:DescribeAccessPoints action.
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, c.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	// Specifies the EFS resource you want to retrieve tags for. You can retrieve tags
36	// for EFS file systems and access points using this API endpoint.
37	//
38	// This member is required.
39	ResourceId *string
40
41	// (Optional) Specifies the maximum number of tag objects to return in the
42	// response. The default value is 100.
43	MaxResults *int32
44
45	// (Optional) You can use NextToken in a subsequent request to fetch the next page
46	// of access point descriptions if the response payload was paginated.
47	NextToken *string
48
49	noSmithyDocumentSerde
50}
51
52type ListTagsForResourceOutput struct {
53
54	// NextToken is present if the response payload is paginated. You can use NextToken
55	// in a subsequent request to fetch the next page of access point descriptions.
56	NextToken *string
57
58	// An array of the tags for the specified EFS resource.
59	Tags []types.Tag
60
61	// Metadata pertaining to the operation's result.
62	ResultMetadata middleware.Metadata
63
64	noSmithyDocumentSerde
65}
66
67func (c *Client) addOperationListTagsForResourceMiddlewares(stack *middleware.Stack, options Options) (err error) {
68	err = stack.Serialize.Add(&awsRestjson1_serializeOpListTagsForResource{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListTagsForResource{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	if err = addSetLoggerMiddleware(stack, options); err != nil {
77		return err
78	}
79	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
80		return err
81	}
82	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
83		return err
84	}
85	if err = addResolveEndpointMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
89		return err
90	}
91	if err = addRetryMiddlewares(stack, options); err != nil {
92		return err
93	}
94	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
95		return err
96	}
97	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
101		return err
102	}
103	if err = addClientUserAgent(stack); err != nil {
104		return err
105	}
106	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
107		return err
108	}
109	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
110		return err
111	}
112	if err = addOpListTagsForResourceValidationMiddleware(stack); err != nil {
113		return err
114	}
115	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTagsForResource(options.Region), middleware.Before); err != nil {
116		return err
117	}
118	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addResponseErrorMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addRequestResponseLogging(stack, options); err != nil {
125		return err
126	}
127	return nil
128}
129
130// ListTagsForResourceAPIClient is a client that implements the ListTagsForResource
131// operation.
132type ListTagsForResourceAPIClient interface {
133	ListTagsForResource(context.Context, *ListTagsForResourceInput, ...func(*Options)) (*ListTagsForResourceOutput, error)
134}
135
136var _ ListTagsForResourceAPIClient = (*Client)(nil)
137
138// ListTagsForResourcePaginatorOptions is the paginator options for
139// ListTagsForResource
140type ListTagsForResourcePaginatorOptions struct {
141	// (Optional) Specifies the maximum number of tag objects to return in the
142	// response. The default value is 100.
143	Limit int32
144
145	// Set to true if pagination should stop if the service returns a pagination token
146	// that matches the most recent token provided to the service.
147	StopOnDuplicateToken bool
148}
149
150// ListTagsForResourcePaginator is a paginator for ListTagsForResource
151type ListTagsForResourcePaginator struct {
152	options   ListTagsForResourcePaginatorOptions
153	client    ListTagsForResourceAPIClient
154	params    *ListTagsForResourceInput
155	nextToken *string
156	firstPage bool
157}
158
159// NewListTagsForResourcePaginator returns a new ListTagsForResourcePaginator
160func NewListTagsForResourcePaginator(client ListTagsForResourceAPIClient, params *ListTagsForResourceInput, optFns ...func(*ListTagsForResourcePaginatorOptions)) *ListTagsForResourcePaginator {
161	if params == nil {
162		params = &ListTagsForResourceInput{}
163	}
164
165	options := ListTagsForResourcePaginatorOptions{}
166	if params.MaxResults != nil {
167		options.Limit = *params.MaxResults
168	}
169
170	for _, fn := range optFns {
171		fn(&options)
172	}
173
174	return &ListTagsForResourcePaginator{
175		options:   options,
176		client:    client,
177		params:    params,
178		firstPage: true,
179	}
180}
181
182// HasMorePages returns a boolean indicating whether more pages are available
183func (p *ListTagsForResourcePaginator) HasMorePages() bool {
184	return p.firstPage || p.nextToken != nil
185}
186
187// NextPage retrieves the next ListTagsForResource page.
188func (p *ListTagsForResourcePaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTagsForResourceOutput, error) {
189	if !p.HasMorePages() {
190		return nil, fmt.Errorf("no more pages available")
191	}
192
193	params := *p.params
194	params.NextToken = p.nextToken
195
196	var limit *int32
197	if p.options.Limit > 0 {
198		limit = &p.options.Limit
199	}
200	params.MaxResults = limit
201
202	result, err := p.client.ListTagsForResource(ctx, &params, optFns...)
203	if err != nil {
204		return nil, err
205	}
206	p.firstPage = false
207
208	prevToken := p.nextToken
209	p.nextToken = result.NextToken
210
211	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
212		p.nextToken = nil
213	}
214
215	return result, nil
216}
217
218func newServiceMetadataMiddleware_opListTagsForResource(region string) *awsmiddleware.RegisterServiceMetadata {
219	return &awsmiddleware.RegisterServiceMetadata{
220		Region:        region,
221		ServiceID:     ServiceID,
222		SigningName:   "elasticfilesystem",
223		OperationName: "ListTagsForResource",
224	}
225}
226