1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package s3
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	s3cust "github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations"
11	"github.com/aws/aws-sdk-go-v2/service/s3/types"
12	"github.com/aws/smithy-go/middleware"
13	smithyhttp "github.com/aws/smithy-go/transport/http"
14	"time"
15)
16
17// Lists the parts that have been uploaded for a specific multipart upload. This
18// operation must include the upload ID, which you obtain by sending the initiate
19// multipart upload request (see CreateMultipartUpload
20// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html)).
21// This request returns a maximum of 1,000 uploaded parts. The default number of
22// parts returned is 1,000 parts. You can restrict the number of parts returned by
23// specifying the max-parts request parameter. If your multipart upload consists of
24// more than 1,000 parts, the response returns an IsTruncated field with the value
25// of true, and a NextPartNumberMarker element. In subsequent ListParts requests
26// you can include the part-number-marker query string parameter and set its value
27// to the NextPartNumberMarker field value from the previous response. For more
28// information on multipart uploads, see Uploading Objects Using Multipart Upload
29// (https://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html). For
30// information on permissions required to use the multipart upload API, see
31// Multipart Upload and Permissions
32// (https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuAndPermissions.html). The
33// following operations are related to ListParts:
34//
35// * CreateMultipartUpload
36// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html)
37//
38// *
39// UploadPart
40// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPart.html)
41//
42// *
43// CompleteMultipartUpload
44// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html)
45//
46// *
47// AbortMultipartUpload
48// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html)
49//
50// *
51// ListMultipartUploads
52// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html)
53func (c *Client) ListParts(ctx context.Context, params *ListPartsInput, optFns ...func(*Options)) (*ListPartsOutput, error) {
54	if params == nil {
55		params = &ListPartsInput{}
56	}
57
58	result, metadata, err := c.invokeOperation(ctx, "ListParts", params, optFns, addOperationListPartsMiddlewares)
59	if err != nil {
60		return nil, err
61	}
62
63	out := result.(*ListPartsOutput)
64	out.ResultMetadata = metadata
65	return out, nil
66}
67
68type ListPartsInput struct {
69
70	// The name of the bucket to which the parts are being uploaded. When using this
71	// action with an access point, you must direct requests to the access point
72	// hostname. The access point hostname takes the form
73	// AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this
74	// action with an access point through the AWS SDKs, you provide the access point
75	// ARN in place of the bucket name. For more information about access point ARNs,
76	// see Using Access Points
77	// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html)
78	// in the Amazon S3 User Guide. When using this action with Amazon S3 on Outposts,
79	// you must direct requests to the S3 on Outposts hostname. The S3 on Outposts
80	// hostname takes the form
81	// AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using
82	// this action using S3 on Outposts through the AWS SDKs, you provide the Outposts
83	// bucket ARN in place of the bucket name. For more information about S3 on
84	// Outposts ARNs, see Using S3 on Outposts
85	// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html) in the
86	// Amazon S3 User Guide.
87	//
88	// This member is required.
89	Bucket *string
90
91	// Object key for which the multipart upload was initiated.
92	//
93	// This member is required.
94	Key *string
95
96	// Upload ID identifying the multipart upload whose parts are being listed.
97	//
98	// This member is required.
99	UploadId *string
100
101	// The account ID of the expected bucket owner. If the bucket is owned by a
102	// different account, the request will fail with an HTTP 403 (Access Denied) error.
103	ExpectedBucketOwner *string
104
105	// Sets the maximum number of parts to return.
106	MaxParts int32
107
108	// Specifies the part after which listing should begin. Only parts with higher part
109	// numbers will be listed.
110	PartNumberMarker *string
111
112	// Confirms that the requester knows that they will be charged for the request.
113	// Bucket owners need not specify this parameter in their requests. For information
114	// about downloading objects from requester pays buckets, see Downloading Objects
115	// in Requestor Pays Buckets
116	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html)
117	// in the Amazon S3 Developer Guide.
118	RequestPayer types.RequestPayer
119}
120
121type ListPartsOutput struct {
122
123	// If the bucket has a lifecycle rule configured with an action to abort incomplete
124	// multipart uploads and the prefix in the lifecycle rule matches the object name
125	// in the request, then the response includes this header indicating when the
126	// initiated multipart upload will become eligible for abort operation. For more
127	// information, see Aborting Incomplete Multipart Uploads Using a Bucket Lifecycle
128	// Policy
129	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html#mpu-abort-incomplete-mpu-lifecycle-config).
130	// The response will also include the x-amz-abort-rule-id header that will provide
131	// the ID of the lifecycle configuration rule that defines this action.
132	AbortDate *time.Time
133
134	// This header is returned along with the x-amz-abort-date header. It identifies
135	// applicable lifecycle configuration rule that defines the action to abort
136	// incomplete multipart uploads.
137	AbortRuleId *string
138
139	// The name of the bucket to which the multipart upload was initiated.
140	Bucket *string
141
142	// Container element that identifies who initiated the multipart upload. If the
143	// initiator is an AWS account, this element provides the same information as the
144	// Owner element. If the initiator is an IAM User, this element provides the user
145	// ARN and display name.
146	Initiator *types.Initiator
147
148	// Indicates whether the returned list of parts is truncated. A true value
149	// indicates that the list was truncated. A list can be truncated if the number of
150	// parts exceeds the limit returned in the MaxParts element.
151	IsTruncated bool
152
153	// Object key for which the multipart upload was initiated.
154	Key *string
155
156	// Maximum number of parts that were allowed in the response.
157	MaxParts int32
158
159	// When a list is truncated, this element specifies the last part in the list, as
160	// well as the value to use for the part-number-marker request parameter in a
161	// subsequent request.
162	NextPartNumberMarker *string
163
164	// Container element that identifies the object owner, after the object is created.
165	// If multipart upload is initiated by an IAM user, this element provides the
166	// parent account ID and display name.
167	Owner *types.Owner
168
169	// When a list is truncated, this element specifies the last part in the list, as
170	// well as the value to use for the part-number-marker request parameter in a
171	// subsequent request.
172	PartNumberMarker *string
173
174	// Container for elements related to a particular part. A response can contain zero
175	// or more Part elements.
176	Parts []types.Part
177
178	// If present, indicates that the requester was successfully charged for the
179	// request.
180	RequestCharged types.RequestCharged
181
182	// Class of storage (STANDARD or REDUCED_REDUNDANCY) used to store the uploaded
183	// object.
184	StorageClass types.StorageClass
185
186	// Upload ID identifying the multipart upload whose parts are being listed.
187	UploadId *string
188
189	// Metadata pertaining to the operation's result.
190	ResultMetadata middleware.Metadata
191}
192
193func addOperationListPartsMiddlewares(stack *middleware.Stack, options Options) (err error) {
194	err = stack.Serialize.Add(&awsRestxml_serializeOpListParts{}, middleware.After)
195	if err != nil {
196		return err
197	}
198	err = stack.Deserialize.Add(&awsRestxml_deserializeOpListParts{}, middleware.After)
199	if err != nil {
200		return err
201	}
202	if err = addSetLoggerMiddleware(stack, options); err != nil {
203		return err
204	}
205	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
206		return err
207	}
208	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
209		return err
210	}
211	if err = addResolveEndpointMiddleware(stack, options); err != nil {
212		return err
213	}
214	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
215		return err
216	}
217	if err = addRetryMiddlewares(stack, options); err != nil {
218		return err
219	}
220	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
221		return err
222	}
223	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
224		return err
225	}
226	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
227		return err
228	}
229	if err = addClientUserAgent(stack); err != nil {
230		return err
231	}
232	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
233		return err
234	}
235	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
236		return err
237	}
238	if err = addOpListPartsValidationMiddleware(stack); err != nil {
239		return err
240	}
241	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListParts(options.Region), middleware.Before); err != nil {
242		return err
243	}
244	if err = addMetadataRetrieverMiddleware(stack); err != nil {
245		return err
246	}
247	if err = addListPartsUpdateEndpoint(stack, options); err != nil {
248		return err
249	}
250	if err = addResponseErrorMiddleware(stack); err != nil {
251		return err
252	}
253	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
254		return err
255	}
256	if err = disableAcceptEncodingGzip(stack); err != nil {
257		return err
258	}
259	if err = addRequestResponseLogging(stack, options); err != nil {
260		return err
261	}
262	return nil
263}
264
265// ListPartsAPIClient is a client that implements the ListParts operation.
266type ListPartsAPIClient interface {
267	ListParts(context.Context, *ListPartsInput, ...func(*Options)) (*ListPartsOutput, error)
268}
269
270var _ ListPartsAPIClient = (*Client)(nil)
271
272// ListPartsPaginatorOptions is the paginator options for ListParts
273type ListPartsPaginatorOptions struct {
274	// Sets the maximum number of parts to return.
275	Limit int32
276
277	// Set to true if pagination should stop if the service returns a pagination token
278	// that matches the most recent token provided to the service.
279	StopOnDuplicateToken bool
280}
281
282// ListPartsPaginator is a paginator for ListParts
283type ListPartsPaginator struct {
284	options   ListPartsPaginatorOptions
285	client    ListPartsAPIClient
286	params    *ListPartsInput
287	nextToken *string
288	firstPage bool
289}
290
291// NewListPartsPaginator returns a new ListPartsPaginator
292func NewListPartsPaginator(client ListPartsAPIClient, params *ListPartsInput, optFns ...func(*ListPartsPaginatorOptions)) *ListPartsPaginator {
293	if params == nil {
294		params = &ListPartsInput{}
295	}
296
297	options := ListPartsPaginatorOptions{}
298	if params.MaxParts != 0 {
299		options.Limit = params.MaxParts
300	}
301
302	for _, fn := range optFns {
303		fn(&options)
304	}
305
306	return &ListPartsPaginator{
307		options:   options,
308		client:    client,
309		params:    params,
310		firstPage: true,
311	}
312}
313
314// HasMorePages returns a boolean indicating whether more pages are available
315func (p *ListPartsPaginator) HasMorePages() bool {
316	return p.firstPage || p.nextToken != nil
317}
318
319// NextPage retrieves the next ListParts page.
320func (p *ListPartsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPartsOutput, error) {
321	if !p.HasMorePages() {
322		return nil, fmt.Errorf("no more pages available")
323	}
324
325	params := *p.params
326	params.PartNumberMarker = p.nextToken
327
328	params.MaxParts = p.options.Limit
329
330	result, err := p.client.ListParts(ctx, &params, optFns...)
331	if err != nil {
332		return nil, err
333	}
334	p.firstPage = false
335
336	prevToken := p.nextToken
337	p.nextToken = nil
338	if result.IsTruncated {
339		p.nextToken = result.NextPartNumberMarker
340	}
341
342	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
343		p.nextToken = nil
344	}
345
346	return result, nil
347}
348
349func newServiceMetadataMiddleware_opListParts(region string) *awsmiddleware.RegisterServiceMetadata {
350	return &awsmiddleware.RegisterServiceMetadata{
351		Region:        region,
352		ServiceID:     ServiceID,
353		SigningName:   "s3",
354		OperationName: "ListParts",
355	}
356}
357
358// getListPartsBucketMember returns a pointer to string denoting a provided bucket
359// member valueand a boolean indicating if the input has a modeled bucket name,
360func getListPartsBucketMember(input interface{}) (*string, bool) {
361	in := input.(*ListPartsInput)
362	if in.Bucket == nil {
363		return nil, false
364	}
365	return in.Bucket, true
366}
367func addListPartsUpdateEndpoint(stack *middleware.Stack, options Options) error {
368	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
369		Accessor: s3cust.UpdateEndpointParameterAccessor{
370			GetBucketFromInput: getListPartsBucketMember,
371		},
372		UsePathStyle:            options.UsePathStyle,
373		UseAccelerate:           options.UseAccelerate,
374		SupportsAccelerate:      true,
375		TargetS3ObjectLambda:    false,
376		EndpointResolver:        options.EndpointResolver,
377		EndpointResolverOptions: options.EndpointOptions,
378		UseDualstack:            options.UseDualstack,
379		UseARNRegion:            options.UseARNRegion,
380	})
381}
382