Skip to content

Commit 9b3066d

Browse files
committed
create tuabortmultipartuploadrequest (#4093)
1 parent e6f904f commit 9b3066d

File tree

7 files changed

+324
-19
lines changed

7 files changed

+324
-19
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"Create AbortMultipartUploads api that takes in TransferUtilityAbortMultipartUploadRequest."
8+
]
9+
}
10+
]
11+
}

sdk/src/Services/S3/Custom/Transfer/Internal/AbortMultipartUploadsCommand.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,30 @@ namespace Amazon.S3.Transfer.Internal
3131
internal partial class AbortMultipartUploadsCommand : BaseCommand
3232
{
3333
IAmazonS3 _s3Client;
34-
string _bucketName;
35-
DateTime _initiatedDate;
34+
TransferUtilityAbortMultipartUploadRequest _request;
35+
TransferUtilityConfig _config;
3636

37-
internal AbortMultipartUploadsCommand(IAmazonS3 s3Client, string bucketName, DateTime initiateDate)
37+
internal AbortMultipartUploadsCommand(IAmazonS3 s3Client, TransferUtilityAbortMultipartUploadRequest request, TransferUtilityConfig config)
3838
{
3939
this._s3Client = s3Client;
40-
this._bucketName = bucketName;
41-
this._initiatedDate = initiateDate;
40+
this._request = request;
41+
this._config = config;
4242
}
4343

4444
internal ListMultipartUploadsRequest ConstructListMultipartUploadsRequest(ListMultipartUploadsResponse listResponse)
4545
{
4646
ListMultipartUploadsRequest listRequest = new ListMultipartUploadsRequest()
4747
{
48-
BucketName = this._bucketName,
48+
BucketName = this._request.BucketName,
4949
KeyMarker = listResponse.KeyMarker,
5050
UploadIdMarker = listResponse.NextUploadIdMarker,
51+
ExpectedBucketOwner = this._request.ExpectedBucketOwner,
52+
RequestPayer = this._request.RequestPayer
5153
};
54+
55+
56+
57+
5258
((Amazon.Runtime.Internal.IAmazonWebServiceRequest)listRequest).AddBeforeRequestHandler(this.RequestEventHandler);
5359
return listRequest;
5460
}
@@ -57,10 +63,13 @@ internal AbortMultipartUploadRequest ConstructAbortMultipartUploadRequest(Multip
5763
{
5864
var abortRequest = new AbortMultipartUploadRequest()
5965
{
60-
BucketName = this._bucketName,
66+
BucketName = this._request.BucketName,
6167
Key = upload.Key,
6268
UploadId = upload.UploadId,
69+
ExpectedBucketOwner = this._request.ExpectedBucketOwner,
70+
RequestPayer = this._request.RequestPayer
6371
};
72+
6473
((Amazon.Runtime.Internal.IAmazonWebServiceRequest)abortRequest).AddBeforeRequestHandler(this.RequestEventHandler);
6574
return abortRequest;
6675
}

sdk/src/Services/S3/Custom/Transfer/Internal/_async/AbortMultipartUploadsCommand.async.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,19 @@ namespace Amazon.S3.Transfer.Internal
2626
{
2727
internal partial class AbortMultipartUploadsCommand : BaseCommand
2828
{
29-
TransferUtilityConfig _config;
30-
31-
internal AbortMultipartUploadsCommand(IAmazonS3 s3Client, string bucketName, DateTime initiateDate, TransferUtilityConfig config)
32-
{
33-
this._s3Client = s3Client;
34-
this._bucketName = bucketName;
35-
this._initiatedDate = initiateDate;
36-
this._config = config;
37-
}
3829

3930
public override async Task ExecuteAsync(CancellationToken cancellationToken)
4031
{
41-
if (string.IsNullOrEmpty(this._bucketName))
32+
if (string.IsNullOrEmpty(this._request.BucketName))
4233
{
4334
throw new InvalidOperationException("The bucketName specified is null or empty!");
4435
}
4536

37+
if (!this._request.IsSetInitiatedDate())
38+
{
39+
throw new InvalidOperationException("InitiatedDate must be specified!");
40+
}
41+
4642
SemaphoreSlim asyncThrottler = null;
4743
CancellationTokenSource internalCts = null;
4844
try
@@ -72,7 +68,7 @@ public override async Task ExecuteAsync(CancellationToken cancellationToken)
7268
// responses and throw the original exception.
7369
break;
7470
}
75-
if (upload.Initiated < this._initiatedDate)
71+
if (upload.Initiated < this._request.InitiatedDate.Value)
7672
{
7773
await asyncThrottler.WaitAsync(cancellationToken)
7874
.ConfigureAwait(continueOnCapturedContext: false);
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*******************************************************************************
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
4+
* this file except in compliance with the License. A copy of the License is located at
5+
*
6+
* http://aws.amazon.com/apache2.0
7+
*
8+
* or in the "license" file accompanying this file.
9+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
* *****************************************************************************
13+
* __ _ _ ___
14+
* ( )( \/\/ )/ __)
15+
* /__\ \ / \__ \
16+
* (_)(_) \/\/ (___/
17+
*
18+
* AWS SDK for .NET
19+
* API Version: 2006-03-01
20+
*
21+
*/
22+
using System;
23+
using Amazon.S3.Model;
24+
25+
namespace Amazon.S3.Transfer
26+
{
27+
/// <summary>
28+
/// Contains all the parameters that can be set when making a request to abort multipart uploads
29+
/// with the <c>TransferUtility</c> method.
30+
/// </summary>
31+
public class TransferUtilityAbortMultipartUploadRequest
32+
{
33+
private string _bucketName;
34+
private DateTime? _initiatedDate;
35+
private string _expectedBucketOwner;
36+
private RequestPayer _requestPayer;
37+
38+
/// <summary>
39+
/// Gets or sets the name of the bucket containing multipart uploads.
40+
/// </summary>
41+
/// <value>
42+
/// The name of the bucket containing multipart uploads.
43+
/// </value>
44+
public string BucketName
45+
{
46+
get { return this._bucketName; }
47+
set { this._bucketName = value; }
48+
}
49+
50+
/// <summary>
51+
/// Checks if BucketName property is set.
52+
/// </summary>
53+
/// <returns>true if BucketName property is set.</returns>
54+
internal bool IsSetBucketName()
55+
{
56+
return !string.IsNullOrEmpty(this._bucketName);
57+
}
58+
59+
/// <summary>
60+
/// Gets or sets the date before which the multipart uploads were initiated.
61+
/// </summary>
62+
/// <value>
63+
/// The date before which the multipart uploads were initiated.
64+
/// </value>
65+
public DateTime? InitiatedDate
66+
{
67+
get { return this._initiatedDate; }
68+
set { this._initiatedDate = value; }
69+
}
70+
71+
/// <summary>
72+
/// Checks if InitiatedDate property is set.
73+
/// </summary>
74+
/// <returns>true if InitiatedDate property is set.</returns>
75+
internal bool IsSetInitiatedDate()
76+
{
77+
return this._initiatedDate.HasValue;
78+
}
79+
80+
/// <summary>
81+
/// Gets or sets the account ID of the expected bucket owner.
82+
/// If the account ID that you provide does not match the actual owner of the bucket,
83+
/// the request fails with the HTTP status code 403 Forbidden (access denied).
84+
/// </summary>
85+
/// <value>
86+
/// The account ID of the expected bucket owner.
87+
/// </value>
88+
public string ExpectedBucketOwner
89+
{
90+
get { return this._expectedBucketOwner; }
91+
set { this._expectedBucketOwner = value; }
92+
}
93+
94+
/// <summary>
95+
/// Checks if ExpectedBucketOwner property is set.
96+
/// </summary>
97+
/// <returns>true if ExpectedBucketOwner property is set.</returns>
98+
internal bool IsSetExpectedBucketOwner()
99+
{
100+
return !string.IsNullOrEmpty(this._expectedBucketOwner);
101+
}
102+
103+
/// <summary>
104+
/// Gets or sets the request payer setting for the abort multipart upload operations.
105+
/// Confirms that the requester knows that they will be charged for the request.
106+
/// Bucket owners need not specify this parameter in their requests.
107+
/// </summary>
108+
/// <value>
109+
/// The request payer setting for the abort multipart upload operations.
110+
/// </value>
111+
public RequestPayer RequestPayer
112+
{
113+
get { return this._requestPayer; }
114+
set { this._requestPayer = value; }
115+
}
116+
117+
/// <summary>
118+
/// Checks if RequestPayer property is set.
119+
/// </summary>
120+
/// <returns>true if RequestPayer property is set.</returns>
121+
internal bool IsSetRequestPayer()
122+
{
123+
return this._requestPayer != null;
124+
}
125+
}
126+
}

sdk/src/Services/S3/Custom/Transfer/_async/TransferUtility.async.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,32 @@ public partial class TransferUtility : ITransferUtility
238238
using(CreateSpan(nameof(AbortMultipartUploadsAsync), null, Amazon.Runtime.Telemetry.Tracing.SpanKind.CLIENT))
239239
{
240240
CheckForBlockedArn(bucketName, "AbortMultipartUploads");
241-
var command = new AbortMultipartUploadsCommand(this._s3Client, bucketName, initiatedDate, this._config);
241+
var request = new TransferUtilityAbortMultipartUploadRequest
242+
{
243+
BucketName = bucketName,
244+
InitiatedDate = initiatedDate
245+
};
246+
var command = new AbortMultipartUploadsCommand(this._s3Client, request, this._config);
247+
await command.ExecuteAsync(cancellationToken).ConfigureAwait(false);
248+
}
249+
}
250+
251+
/// <summary>
252+
/// Aborts the multipart uploads based on the specified request parameters.
253+
/// </summary>
254+
/// <param name="request">
255+
/// Contains all the parameters required to abort multipart uploads.
256+
/// </param>
257+
/// <param name="cancellationToken">
258+
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
259+
/// </param>
260+
/// <returns>The task object representing the asynchronous operation.</returns>
261+
public async Task AbortMultipartUploadsAsync(TransferUtilityAbortMultipartUploadRequest request, CancellationToken cancellationToken = default(CancellationToken))
262+
{
263+
using(CreateSpan(nameof(AbortMultipartUploadsAsync), null, Amazon.Runtime.Telemetry.Tracing.SpanKind.CLIENT))
264+
{
265+
CheckForBlockedArn(request.BucketName, "AbortMultipartUploads");
266+
var command = new AbortMultipartUploadsCommand(this._s3Client, request, this._config);
242267
await command.ExecuteAsync(cancellationToken).ConfigureAwait(false);
243268
}
244269
}

sdk/src/Services/S3/Custom/Transfer/_bcl+netstandard/TransferUtility.sync.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,24 @@ public void AbortMultipartUploads(string bucketName, DateTime initiatedDate)
459459
}
460460
}
461461

462+
/// <summary>
463+
/// Aborts the multipart uploads based on the specified request parameters.
464+
/// </summary>
465+
/// <param name="request">
466+
/// Contains all the parameters required to abort multipart uploads.
467+
/// </param>
468+
public void AbortMultipartUploads(TransferUtilityAbortMultipartUploadRequest request)
469+
{
470+
try
471+
{
472+
AbortMultipartUploadsAsync(request).Wait();
473+
}
474+
catch (AggregateException e)
475+
{
476+
ExceptionDispatchInfo.Capture(e.InnerException).Throw();
477+
}
478+
}
479+
462480
#endregion
463481
}
464482
}

0 commit comments

Comments
 (0)