1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package cloudhsmv2
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/cloudhsmv2/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Gets a list of tags for the specified AWS CloudHSM cluster. This is a paginated
16// operation, which means that each response might contain only a subset of all the
17// tags. When the response contains only a subset of tags, it includes a NextToken
18// value. Use this value in a subsequent ListTags request to get more tags. When
19// you receive a response with no NextToken (or an empty or null value), that means
20// there are no more tags to get.
21func (c *Client) ListTags(ctx context.Context, params *ListTagsInput, optFns ...func(*Options)) (*ListTagsOutput, error) {
22	if params == nil {
23		params = &ListTagsInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "ListTags", params, optFns, addOperationListTagsMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*ListTagsOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36type ListTagsInput struct {
37
38	// The cluster identifier (ID) for the cluster whose tags you are getting. To find
39	// the cluster ID, use DescribeClusters.
40	//
41	// This member is required.
42	ResourceId *string
43
44	// The maximum number of tags to return in the response. When there are more tags
45	// than the number you specify, the response contains a NextToken value.
46	MaxResults *int32
47
48	// The NextToken value that you received in the previous response. Use this value
49	// to get more tags.
50	NextToken *string
51}
52
53type ListTagsOutput struct {
54
55	// A list of tags.
56	//
57	// This member is required.
58	TagList []types.Tag
59
60	// An opaque string that indicates that the response contains only a subset of
61	// tags. Use this value in a subsequent ListTags request to get more tags.
62	NextToken *string
63
64	// Metadata pertaining to the operation's result.
65	ResultMetadata middleware.Metadata
66}
67
68func addOperationListTagsMiddlewares(stack *middleware.Stack, options Options) (err error) {
69	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTags{}, middleware.After)
70	if err != nil {
71		return err
72	}
73	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTags{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	if err = addSetLoggerMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
81		return err
82	}
83	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
84		return err
85	}
86	if err = addResolveEndpointMiddleware(stack, options); err != nil {
87		return err
88	}
89	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
90		return err
91	}
92	if err = addRetryMiddlewares(stack, options); err != nil {
93		return err
94	}
95	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
102		return err
103	}
104	if err = addClientUserAgent(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addOpListTagsValidationMiddleware(stack); err != nil {
114		return err
115	}
116	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTags(options.Region), middleware.Before); err != nil {
117		return err
118	}
119	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addResponseErrorMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addRequestResponseLogging(stack, options); err != nil {
126		return err
127	}
128	return nil
129}
130
131// ListTagsAPIClient is a client that implements the ListTags operation.
132type ListTagsAPIClient interface {
133	ListTags(context.Context, *ListTagsInput, ...func(*Options)) (*ListTagsOutput, error)
134}
135
136var _ ListTagsAPIClient = (*Client)(nil)
137
138// ListTagsPaginatorOptions is the paginator options for ListTags
139type ListTagsPaginatorOptions struct {
140	// The maximum number of tags to return in the response. When there are more tags
141	// than the number you specify, the response contains a NextToken value.
142	Limit int32
143
144	// Set to true if pagination should stop if the service returns a pagination token
145	// that matches the most recent token provided to the service.
146	StopOnDuplicateToken bool
147}
148
149// ListTagsPaginator is a paginator for ListTags
150type ListTagsPaginator struct {
151	options   ListTagsPaginatorOptions
152	client    ListTagsAPIClient
153	params    *ListTagsInput
154	nextToken *string
155	firstPage bool
156}
157
158// NewListTagsPaginator returns a new ListTagsPaginator
159func NewListTagsPaginator(client ListTagsAPIClient, params *ListTagsInput, optFns ...func(*ListTagsPaginatorOptions)) *ListTagsPaginator {
160	if params == nil {
161		params = &ListTagsInput{}
162	}
163
164	options := ListTagsPaginatorOptions{}
165	if params.MaxResults != nil {
166		options.Limit = *params.MaxResults
167	}
168
169	for _, fn := range optFns {
170		fn(&options)
171	}
172
173	return &ListTagsPaginator{
174		options:   options,
175		client:    client,
176		params:    params,
177		firstPage: true,
178	}
179}
180
181// HasMorePages returns a boolean indicating whether more pages are available
182func (p *ListTagsPaginator) HasMorePages() bool {
183	return p.firstPage || p.nextToken != nil
184}
185
186// NextPage retrieves the next ListTags page.
187func (p *ListTagsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTagsOutput, error) {
188	if !p.HasMorePages() {
189		return nil, fmt.Errorf("no more pages available")
190	}
191
192	params := *p.params
193	params.NextToken = p.nextToken
194
195	var limit *int32
196	if p.options.Limit > 0 {
197		limit = &p.options.Limit
198	}
199	params.MaxResults = limit
200
201	result, err := p.client.ListTags(ctx, &params, optFns...)
202	if err != nil {
203		return nil, err
204	}
205	p.firstPage = false
206
207	prevToken := p.nextToken
208	p.nextToken = result.NextToken
209
210	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
211		p.nextToken = nil
212	}
213
214	return result, nil
215}
216
217func newServiceMetadataMiddleware_opListTags(region string) *awsmiddleware.RegisterServiceMetadata {
218	return &awsmiddleware.RegisterServiceMetadata{
219		Region:        region,
220		ServiceID:     ServiceID,
221		SigningName:   "cloudhsm",
222		OperationName: "ListTags",
223	}
224}
225