Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not trim leading slashes for copy object and copy part operations #3532

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions generator/.DevConfigs/2869e4ae-e992-4bb7-938e-fed27e1b1d47.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"services": [
{
"serviceName": "S3",
"type": "patch",
"changeLogMessages": [
"Remove the DisableTrimmingLeadingSlash flag for CopyObject and CopyPart operations. The SDK will no longer trim leading slashes."
]
}
]
}
11 changes: 0 additions & 11 deletions sdk/src/Services/S3/Custom/Model/CopyObjectRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public partial class CopyObjectRequest : PutWithACLRequest
private string copySourceServerSideEncryptionCustomerProvidedKeyMD5;
private TaggingDirective taggingDirective;

private bool disableTrimmingLeadingSlash = false;

/// <summary>
/// A canned access control list (CACL) to apply to the object.
Expand Down Expand Up @@ -1189,16 +1188,6 @@ internal bool IsSetChecksumAlgorithm()
return this._checksumAlgorithm != null;
}

/// <summary>
/// If this is set to true then the Amazon S3 client will not remove leading slashes from <see cref="SourceKey"/> and <see cref="DestinationKey"/>.
/// The default value is false.
/// </summary>
public bool DisableTrimmingLeadingSlash
{
get { return this.disableTrimmingLeadingSlash; }
set { this.disableTrimmingLeadingSlash = value; }
}

/// <summary>
/// Specifies whether the object tag-set is copied from the source object or replaced with the tag-set that's provided in the request.
/// <para>
Expand Down
10 changes: 0 additions & 10 deletions sdk/src/Services/S3/Custom/Model/CopyPartRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public partial class CopyPartRequest : AmazonWebServiceRequest
private string copySourceServerSideEncryptionCustomerProvidedKey;
private string copySourceServerSideEncryptionCustomerProvidedKeyMD5;

private bool disableTrimmingLeadingSlash = false;

/// <summary>
/// The name of the bucket containing the object to copy.
Expand Down Expand Up @@ -823,14 +822,5 @@ internal bool IsSetRequestPayer()
return requestPayer != null;
}

/// <summary>
/// If this is set to true then the Amazon S3 client will not remove leading slashes from <see cref="SourceKey"/> and <see cref="DestinationKey"/>.
/// The default value is false.
/// </summary>
public bool DisableTrimmingLeadingSlash
{
get { return this.disableTrimmingLeadingSlash; }
set { this.disableTrimmingLeadingSlash = value; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@ public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)

public IRequest Marshall(CopyObjectRequest copyObjectRequest)
{
var sourceKey =
copyObjectRequest.DisableTrimmingLeadingSlash || string.IsNullOrEmpty(copyObjectRequest.SourceKey) ?
copyObjectRequest.SourceKey :
AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.SourceKey);

var destinationKey =
copyObjectRequest.DisableTrimmingLeadingSlash || string.IsNullOrEmpty(copyObjectRequest.DestinationKey) ?
copyObjectRequest.DestinationKey:
AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.DestinationKey);
var sourceKey = copyObjectRequest.SourceKey;

var destinationKey = copyObjectRequest.DestinationKey;

IRequest request = new DefaultRequest(copyObjectRequest, "AmazonS3");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ public IRequest Marshall(CopyPartRequest copyPartRequest)
{
IRequest request = new DefaultRequest(copyPartRequest, "AmazonS3");

var sourceKey =
copyPartRequest.DisableTrimmingLeadingSlash ?
copyPartRequest.SourceKey :
AmazonS3Util.RemoveLeadingSlash(copyPartRequest.SourceKey);

var destinationKey =
copyPartRequest.DisableTrimmingLeadingSlash ?
copyPartRequest.DestinationKey :
AmazonS3Util.RemoveLeadingSlash(copyPartRequest.DestinationKey);
var sourceKey = copyPartRequest.SourceKey;

var destinationKey = copyPartRequest.DestinationKey;

request.HttpMethod = "PUT";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ protected override void Dispose(bool disposing)
}

[Theory]
[InlineData(false, testKey, "/destinationTestKey1.txt", "destinationTestKey1.txt")]
[InlineData(true, testKeyWithSlash, "/destinationTestKey2.txt", "/destinationTestKey2.txt")]
[InlineData(true, testKeyWithSlash, "/", "/")]
[InlineData(testKey, "/destinationTestKey1.txt", "/destinationTestKey1.txt")]
[InlineData(testKeyWithSlash, "/destinationTestKey2.txt", "/destinationTestKey2.txt")]
[InlineData(testKeyWithSlash, "/", "/")]
[Trait(CategoryAttribute, "S3")]
public async Task CopyObjectTestWithLeadingSlash(bool disableTrimmingLeadingSlash, string sourceKey, string destinationKey, string expectedKey)
public async Task CopyObjectTestWithLeadingSlash(string sourceKey, string destinationKey, string expectedKey)
{
var copyResponse = await Client.CopyObjectAsync(new CopyObjectRequest
{
Expand All @@ -55,8 +55,6 @@ public async Task CopyObjectTestWithLeadingSlash(bool disableTrimmingLeadingSlas

DestinationBucket = bucketName,
DestinationKey = destinationKey,

DisableTrimmingLeadingSlash = disableTrimmingLeadingSlash
});
Assert.Equal(HttpStatusCode.OK, copyResponse.HttpStatusCode);

Expand Down
9 changes: 4 additions & 5 deletions sdk/test/Services/S3/IntegrationTests/CopyObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ public void TestCopyObjectWithTagsReplace()
Assert.IsTrue(taggingMetadata.Tagging.Any(tag => tag.Key == "newtag1" && tag.Value == "1"));
}

[DataRow(false, testKey, "/destinationTestKey1.txt", "destinationTestKey1.txt")]
[DataRow(true, testKeyWithSlash, "/destinationTestKey2.txt", "/destinationTestKey2.txt")]
[DataRow(true, testKeyWithSlash, "/", "/")]
[DataRow(testKey, "destinationTestKey1.txt", "destinationTestKey1.txt")]
[DataRow(testKeyWithSlash, "/destinationTestKey2.txt", "/destinationTestKey2.txt")]
[DataRow(testKeyWithSlash, "/", "/")]
[DataTestMethod]
[TestCategory("S3")]
public void TestCopyObjectWithLeadingSlash(bool disableTrimmingLeadingSlash, string sourceKey, string destinationKey, string expectedKey)
public void TestCopyObjectWithLeadingSlash(string sourceKey, string destinationKey, string expectedKey)
{
var copyObjectResponse = usEastClient.CopyObject(new CopyObjectRequest
{
Expand All @@ -172,7 +172,6 @@ public void TestCopyObjectWithLeadingSlash(bool disableTrimmingLeadingSlash, str
DestinationBucket = westBucketName,
DestinationKey = destinationKey,

DisableTrimmingLeadingSlash = disableTrimmingLeadingSlash
});
Assert.AreEqual(HttpStatusCode.OK, copyObjectResponse.HttpStatusCode);

Expand Down
1 change: 0 additions & 1 deletion sdk/test/Services/S3/IntegrationTests/CopyPartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void TestCopyPartWithLeadingSlash()
UploadId = uploadId,
PartNumber = 1,

DisableTrimmingLeadingSlash = true
});
Assert.IsNotNull(copyPartResponse.ETag);
Assert.IsTrue(copyPartResponse.ETag != null && copyPartResponse.ETag.Length > 0);
Expand Down