1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package acmpca
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/acmpca/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the tags, if any, that are associated with your private CA or one that has
16// been shared with you. Tags are labels that you can use to identify and organize
17// your CAs. Each tag consists of a key and an optional value. Call the
18// TagCertificateAuthority
19// (https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_TagCertificateAuthority.html)
20// action to add one or more tags to your CA. Call the UntagCertificateAuthority
21// (https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_UntagCertificateAuthority.html)
22// action to remove tags.
23func (c *Client) ListTags(ctx context.Context, params *ListTagsInput, optFns ...func(*Options)) (*ListTagsOutput, error) {
24	if params == nil {
25		params = &ListTagsInput{}
26	}
27
28	result, metadata, err := c.invokeOperation(ctx, "ListTags", params, optFns, addOperationListTagsMiddlewares)
29	if err != nil {
30		return nil, err
31	}
32
33	out := result.(*ListTagsOutput)
34	out.ResultMetadata = metadata
35	return out, nil
36}
37
38type ListTagsInput struct {
39
40	// The Amazon Resource Name (ARN) that was returned when you called the
41	// CreateCertificateAuthority
42	// (https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_CreateCertificateAuthority.html)
43	// action. This must be of the form:
44	// arn:aws:acm-pca:region:account:certificate-authority/12345678-1234-1234-1234-123456789012
45	//
46	// This member is required.
47	CertificateAuthorityArn *string
48
49	// Use this parameter when paginating results to specify the maximum number of
50	// items to return in the response. If additional items exist beyond the number you
51	// specify, the NextToken element is sent in the response. Use this NextToken value
52	// in a subsequent request to retrieve additional items.
53	MaxResults *int32
54
55	// Use this parameter when paginating results in a subsequent request after you
56	// receive a response with truncated results. Set it to the value of NextToken from
57	// the response you just received.
58	NextToken *string
59}
60
61type ListTagsOutput struct {
62
63	// When the list is truncated, this value is present and should be used for the
64	// NextToken parameter in a subsequent pagination request.
65	NextToken *string
66
67	// The tags associated with your private CA.
68	Tags []types.Tag
69
70	// Metadata pertaining to the operation's result.
71	ResultMetadata middleware.Metadata
72}
73
74func addOperationListTagsMiddlewares(stack *middleware.Stack, options Options) (err error) {
75	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTags{}, middleware.After)
76	if err != nil {
77		return err
78	}
79	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTags{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	if err = addSetLoggerMiddleware(stack, options); err != nil {
84		return err
85	}
86	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
87		return err
88	}
89	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
90		return err
91	}
92	if err = addResolveEndpointMiddleware(stack, options); err != nil {
93		return err
94	}
95	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
96		return err
97	}
98	if err = addRetryMiddlewares(stack, options); err != nil {
99		return err
100	}
101	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
105		return err
106	}
107	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
108		return err
109	}
110	if err = addClientUserAgent(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addOpListTagsValidationMiddleware(stack); err != nil {
120		return err
121	}
122	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTags(options.Region), middleware.Before); err != nil {
123		return err
124	}
125	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
126		return err
127	}
128	if err = addResponseErrorMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addRequestResponseLogging(stack, options); err != nil {
132		return err
133	}
134	return nil
135}
136
137// ListTagsAPIClient is a client that implements the ListTags operation.
138type ListTagsAPIClient interface {
139	ListTags(context.Context, *ListTagsInput, ...func(*Options)) (*ListTagsOutput, error)
140}
141
142var _ ListTagsAPIClient = (*Client)(nil)
143
144// ListTagsPaginatorOptions is the paginator options for ListTags
145type ListTagsPaginatorOptions struct {
146	// Use this parameter when paginating results to specify the maximum number of
147	// items to return in the response. If additional items exist beyond the number you
148	// specify, the NextToken element is sent in the response. Use this NextToken value
149	// in a subsequent request to retrieve additional items.
150	Limit int32
151
152	// Set to true if pagination should stop if the service returns a pagination token
153	// that matches the most recent token provided to the service.
154	StopOnDuplicateToken bool
155}
156
157// ListTagsPaginator is a paginator for ListTags
158type ListTagsPaginator struct {
159	options   ListTagsPaginatorOptions
160	client    ListTagsAPIClient
161	params    *ListTagsInput
162	nextToken *string
163	firstPage bool
164}
165
166// NewListTagsPaginator returns a new ListTagsPaginator
167func NewListTagsPaginator(client ListTagsAPIClient, params *ListTagsInput, optFns ...func(*ListTagsPaginatorOptions)) *ListTagsPaginator {
168	if params == nil {
169		params = &ListTagsInput{}
170	}
171
172	options := ListTagsPaginatorOptions{}
173	if params.MaxResults != nil {
174		options.Limit = *params.MaxResults
175	}
176
177	for _, fn := range optFns {
178		fn(&options)
179	}
180
181	return &ListTagsPaginator{
182		options:   options,
183		client:    client,
184		params:    params,
185		firstPage: true,
186	}
187}
188
189// HasMorePages returns a boolean indicating whether more pages are available
190func (p *ListTagsPaginator) HasMorePages() bool {
191	return p.firstPage || p.nextToken != nil
192}
193
194// NextPage retrieves the next ListTags page.
195func (p *ListTagsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTagsOutput, error) {
196	if !p.HasMorePages() {
197		return nil, fmt.Errorf("no more pages available")
198	}
199
200	params := *p.params
201	params.NextToken = p.nextToken
202
203	var limit *int32
204	if p.options.Limit > 0 {
205		limit = &p.options.Limit
206	}
207	params.MaxResults = limit
208
209	result, err := p.client.ListTags(ctx, &params, optFns...)
210	if err != nil {
211		return nil, err
212	}
213	p.firstPage = false
214
215	prevToken := p.nextToken
216	p.nextToken = result.NextToken
217
218	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
219		p.nextToken = nil
220	}
221
222	return result, nil
223}
224
225func newServiceMetadataMiddleware_opListTags(region string) *awsmiddleware.RegisterServiceMetadata {
226	return &awsmiddleware.RegisterServiceMetadata{
227		Region:        region,
228		ServiceID:     ServiceID,
229		SigningName:   "acm-pca",
230		OperationName: "ListTags",
231	}
232}
233