1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package secretsmanager
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/secretsmanager/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists all of the versions attached to the specified secret. The output does not
16// include the SecretString or SecretBinary fields. By default, the list includes
17// only versions that have at least one staging label in VersionStage attached.
18// Always check the NextToken response parameter when calling any of the List*
19// operations. These operations can occasionally return an empty or shorter than
20// expected list of results even when there more results become available. When
21// this happens, the NextToken response parameter contains a value to pass to the
22// next call to the same API to request the next part of the list. Minimum
23// permissions To run this command, you must have the following permissions:
24//
25// *
26// secretsmanager:ListSecretVersionIds
27//
28// Related operations
29//
30// * To list the secrets
31// in an account, use ListSecrets.
32func (c *Client) ListSecretVersionIds(ctx context.Context, params *ListSecretVersionIdsInput, optFns ...func(*Options)) (*ListSecretVersionIdsOutput, error) {
33	if params == nil {
34		params = &ListSecretVersionIdsInput{}
35	}
36
37	result, metadata, err := c.invokeOperation(ctx, "ListSecretVersionIds", params, optFns, addOperationListSecretVersionIdsMiddlewares)
38	if err != nil {
39		return nil, err
40	}
41
42	out := result.(*ListSecretVersionIdsOutput)
43	out.ResultMetadata = metadata
44	return out, nil
45}
46
47type ListSecretVersionIdsInput struct {
48
49	// The identifier for the secret containing the versions you want to list. You can
50	// specify either the Amazon Resource Name (ARN) or the friendly name of the
51	// secret. If you specify an ARN, we generally recommend that you specify a
52	// complete ARN. You can specify a partial ARN too—for example, if you don’t
53	// include the final hyphen and six random characters that Secrets Manager adds at
54	// the end of the ARN when you created the secret. A partial ARN match can work as
55	// long as it uniquely matches only one secret. However, if your secret has a name
56	// that ends in a hyphen followed by six characters (before Secrets Manager adds
57	// the hyphen and six characters to the ARN) and you try to use that as a partial
58	// ARN, then those characters cause Secrets Manager to assume that you’re
59	// specifying a complete ARN. This confusion can cause unexpected results. To avoid
60	// this situation, we recommend that you don’t create secret names ending with a
61	// hyphen followed by six characters. If you specify an incomplete ARN without the
62	// random suffix, and instead provide the 'friendly name', you must not include the
63	// random suffix. If you do include the random suffix added by Secrets Manager, you
64	// receive either a ResourceNotFoundException or an AccessDeniedException error,
65	// depending on your permissions.
66	//
67	// This member is required.
68	SecretId *string
69
70	// (Optional) Specifies that you want the results to include versions that do not
71	// have any staging labels attached to them. Such versions are considered
72	// deprecated and are subject to deletion by Secrets Manager as needed.
73	IncludeDeprecated bool
74
75	// (Optional) Limits the number of results you want to include in the response. If
76	// you don't include this parameter, it defaults to a value that's specific to the
77	// operation. If additional items exist beyond the maximum you specify, the
78	// NextToken response element is present and has a value (isn't null). Include that
79	// value as the NextToken request parameter in the next call to the operation to
80	// get the next part of the results. Note that Secrets Manager might return fewer
81	// results than the maximum even when there are more results available. You should
82	// check NextToken after every operation to ensure that you receive all of the
83	// results.
84	MaxResults int32
85
86	// (Optional) Use this parameter in a request if you receive a NextToken response
87	// in a previous request indicating there's more output available. In a subsequent
88	// call, set it to the value of the previous call NextToken response to indicate
89	// where the output should continue from.
90	NextToken *string
91}
92
93type ListSecretVersionIdsOutput struct {
94
95	// The Amazon Resource Name (ARN) for the secret. Secrets Manager automatically
96	// adds several random characters to the name at the end of the ARN when you
97	// initially create a secret. This affects only the ARN and not the actual friendly
98	// name. This ensures that if you create a new secret with the same name as an old
99	// secret that you previously deleted, then users with access to the old secret
100	// don't automatically get access to the new secret because the ARNs are different.
101	ARN *string
102
103	// The friendly name of the secret.
104	Name *string
105
106	// If present in the response, this value indicates that there's more output
107	// available than included in the current response. This can occur even when the
108	// response includes no values at all, such as when you ask for a filtered view of
109	// a very long list. Use this value in the NextToken request parameter in a
110	// subsequent call to the operation to continue processing and get the next part of
111	// the output. You should repeat this until the NextToken response element comes
112	// back empty (as null).
113	NextToken *string
114
115	// The list of the currently available versions of the specified secret.
116	Versions []types.SecretVersionsListEntry
117
118	// Metadata pertaining to the operation's result.
119	ResultMetadata middleware.Metadata
120}
121
122func addOperationListSecretVersionIdsMiddlewares(stack *middleware.Stack, options Options) (err error) {
123	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListSecretVersionIds{}, middleware.After)
124	if err != nil {
125		return err
126	}
127	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListSecretVersionIds{}, middleware.After)
128	if err != nil {
129		return err
130	}
131	if err = addSetLoggerMiddleware(stack, options); err != nil {
132		return err
133	}
134	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
135		return err
136	}
137	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
138		return err
139	}
140	if err = addResolveEndpointMiddleware(stack, options); err != nil {
141		return err
142	}
143	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
144		return err
145	}
146	if err = addRetryMiddlewares(stack, options); err != nil {
147		return err
148	}
149	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
150		return err
151	}
152	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
153		return err
154	}
155	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
156		return err
157	}
158	if err = addClientUserAgent(stack); err != nil {
159		return err
160	}
161	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
162		return err
163	}
164	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
165		return err
166	}
167	if err = addOpListSecretVersionIdsValidationMiddleware(stack); err != nil {
168		return err
169	}
170	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListSecretVersionIds(options.Region), middleware.Before); err != nil {
171		return err
172	}
173	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
174		return err
175	}
176	if err = addResponseErrorMiddleware(stack); err != nil {
177		return err
178	}
179	if err = addRequestResponseLogging(stack, options); err != nil {
180		return err
181	}
182	return nil
183}
184
185// ListSecretVersionIdsAPIClient is a client that implements the
186// ListSecretVersionIds operation.
187type ListSecretVersionIdsAPIClient interface {
188	ListSecretVersionIds(context.Context, *ListSecretVersionIdsInput, ...func(*Options)) (*ListSecretVersionIdsOutput, error)
189}
190
191var _ ListSecretVersionIdsAPIClient = (*Client)(nil)
192
193// ListSecretVersionIdsPaginatorOptions is the paginator options for
194// ListSecretVersionIds
195type ListSecretVersionIdsPaginatorOptions struct {
196	// (Optional) Limits the number of results you want to include in the response. If
197	// you don't include this parameter, it defaults to a value that's specific to the
198	// operation. If additional items exist beyond the maximum you specify, the
199	// NextToken response element is present and has a value (isn't null). Include that
200	// value as the NextToken request parameter in the next call to the operation to
201	// get the next part of the results. Note that Secrets Manager might return fewer
202	// results than the maximum even when there are more results available. You should
203	// check NextToken after every operation to ensure that you receive all of the
204	// results.
205	Limit int32
206
207	// Set to true if pagination should stop if the service returns a pagination token
208	// that matches the most recent token provided to the service.
209	StopOnDuplicateToken bool
210}
211
212// ListSecretVersionIdsPaginator is a paginator for ListSecretVersionIds
213type ListSecretVersionIdsPaginator struct {
214	options   ListSecretVersionIdsPaginatorOptions
215	client    ListSecretVersionIdsAPIClient
216	params    *ListSecretVersionIdsInput
217	nextToken *string
218	firstPage bool
219}
220
221// NewListSecretVersionIdsPaginator returns a new ListSecretVersionIdsPaginator
222func NewListSecretVersionIdsPaginator(client ListSecretVersionIdsAPIClient, params *ListSecretVersionIdsInput, optFns ...func(*ListSecretVersionIdsPaginatorOptions)) *ListSecretVersionIdsPaginator {
223	options := ListSecretVersionIdsPaginatorOptions{}
224	if params.MaxResults != 0 {
225		options.Limit = params.MaxResults
226	}
227
228	for _, fn := range optFns {
229		fn(&options)
230	}
231
232	if params == nil {
233		params = &ListSecretVersionIdsInput{}
234	}
235
236	return &ListSecretVersionIdsPaginator{
237		options:   options,
238		client:    client,
239		params:    params,
240		firstPage: true,
241	}
242}
243
244// HasMorePages returns a boolean indicating whether more pages are available
245func (p *ListSecretVersionIdsPaginator) HasMorePages() bool {
246	return p.firstPage || p.nextToken != nil
247}
248
249// NextPage retrieves the next ListSecretVersionIds page.
250func (p *ListSecretVersionIdsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListSecretVersionIdsOutput, error) {
251	if !p.HasMorePages() {
252		return nil, fmt.Errorf("no more pages available")
253	}
254
255	params := *p.params
256	params.NextToken = p.nextToken
257
258	params.MaxResults = p.options.Limit
259
260	result, err := p.client.ListSecretVersionIds(ctx, &params, optFns...)
261	if err != nil {
262		return nil, err
263	}
264	p.firstPage = false
265
266	prevToken := p.nextToken
267	p.nextToken = result.NextToken
268
269	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
270		p.nextToken = nil
271	}
272
273	return result, nil
274}
275
276func newServiceMetadataMiddleware_opListSecretVersionIds(region string) *awsmiddleware.RegisterServiceMetadata {
277	return &awsmiddleware.RegisterServiceMetadata{
278		Region:        region,
279		ServiceID:     ServiceID,
280		SigningName:   "secretsmanager",
281		OperationName: "ListSecretVersionIds",
282	}
283}
284