Skip to content

Commit 20f97ce

Browse files
committed
refactor: Remove obsolete code in ChecksumUtils and update S3 marshallers
1 parent e43298a commit 20f97ce

File tree

5 files changed

+18
-115
lines changed

5 files changed

+18
-115
lines changed

sdk/src/Core/Amazon.Runtime/Internal/Util/ChecksumUtils.cs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,6 @@ internal static string GetChecksumHeaderKey(CoreChecksumAlgorithm checksumAlgori
6363
return $"{_checksumHeaderPrefix}{checksumAlgorithm.ToString().ToLower()}";
6464
}
6565

66-
/// <remarks>
67-
/// Note, this was called directly from service packages prior to compression support
68-
/// being added shortly after 3.7.200. It's important to preserve the signature and functionality
69-
/// until the next minor version for those older 3.7.* service packages.
70-
/// </remarks>
71-
/// <summary>
72-
/// Attempts to select and then calculate the checksum for a request
73-
/// </summary>
74-
/// <param name="request">Request to calculate the checksum for</param>
75-
/// <param name="checksumAlgorithm">Checksum algorithm to use, specified on the request using a service-specific enum</param>
76-
/// <param name="fallbackToMD5">If checksumAlgorithm is <see cref="CoreChecksumAlgorithm.NONE"/>, this flag controls whether or not to fallback to using a MD5 to generate a checksum</param>
77-
[Obsolete("This method is deprecated in favor of SetRequestChecksumV2")]
78-
public static void SetRequestChecksum(IRequest request, string checksumAlgorithm, bool fallbackToMD5 = true)
79-
{
80-
// TODO: As mentioned in the remarks section, this method used to be called from the marshallers in older service packages.
81-
// It's not used anymore from Core (which uses "SetRequestChecksumV2" instead), and should be removed in V4.
82-
if (request.ChecksumData == null)
83-
{
84-
SetChecksumData(request, checksumAlgorithm, fallbackToMD5);
85-
return;
86-
}
87-
88-
SetRequestChecksumV2(request, clientConfig: null);
89-
}
90-
9166
/// <summary>
9267
/// Attempts to select and then calculate the checksum for a request.
9368
/// </summary>
@@ -314,40 +289,6 @@ private static CoreChecksumAlgorithm ConvertToCoreChecksumAlgorithm(string selec
314289
return selectedCoreChecksumAlgorithm;
315290
}
316291

317-
/// <summary>
318-
/// Set checksum data in marshaller after compressing request payload.
319-
/// </summary>
320-
/// <param name="request">Request to calculate the checksum for</param>
321-
/// <param name="checksumAlgorithm">Checksum algorithm to use, specified on the request using a service-specific enum</param>
322-
/// <param name="fallbackToMD5">This flag controls whether or not to fallback to using a MD5 to generate a checksum</param>
323-
[Obsolete("This overload is deprecated in favor of the options that accept whether the checksum is required for the given request")]
324-
public static void SetChecksumData(IRequest request, string checksumAlgorithm, bool fallbackToMD5 = true)
325-
{
326-
// This overload will only be invoked from older service packages (i.e. not updated for the latest flexible checksums specification).
327-
// We need to maintain the previous behavior (of only setting a checksum if provided) to account for edge cases in multipart uploads (S3 was
328-
// the only service using the checksum trait in the initial revision of the specification).
329-
330-
// The specific scenario we're concerned about is:
331-
// - Customer is using multiple SDK packages
332-
// - Customer updates one of their dependencies (let's say SQS), which brings the latest version of Core as well
333-
// - Previous version of S3 will still compile successfully since it specifies "AWSSDK.Core(>= 3.7.x && < 4.0.0)" as a dependency
334-
// - Large object is uploaded using the TransferUtility, and setting the checksum automatically for the individual parts will
335-
// cause the CompleteMPU call to fail (as our SDK will add the part checksums via CompleteMultipartUploadRequest.AddPartETags - which
336-
// S3 does not support).
337-
338-
// TODO: Similar to "SetRequestChecksum", this method should be removed in V4.
339-
if (!string.IsNullOrEmpty(checksumAlgorithm))
340-
{
341-
SetChecksumData(request, checksumAlgorithm, fallbackToMD5, isRequestChecksumRequired: true);
342-
}
343-
else
344-
{
345-
// Important: We can't set ChecksumData to null as previous versions of the S3 package assume it'll be present.
346-
// The SkipChecksum flag is then used in the pipeline handler to determine whether the calculation should be performed.
347-
request.ChecksumData = new ChecksumData { SkipChecksum = true };
348-
}
349-
}
350-
351292
/// <summary>
352293
/// Set checksum data in marshaller after compressing request payload.
353294
/// </summary>
@@ -414,14 +355,6 @@ public class ChecksumData
414355
/// </summary>
415356
public string HeaderName { get; set; }
416357

417-
/// <summary>
418-
/// TODO: This property is only used to handle the mismatch of older service packages and newer Core.
419-
/// It should also be removed in V4 (same comment applies to the internal parameterless constructor) .
420-
/// </summary>
421-
internal bool SkipChecksum { get; set; }
422-
423-
internal ChecksumData() { }
424-
425358
public ChecksumData(string selectedChecksum, bool MD5Checksum, bool? fallbackToMD5, bool isRequestChecksumRequired, string headerName)
426359
{
427360
this.SelectedChecksum = selectedChecksum;

sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/ChecksumHandler.cs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,46 +73,13 @@ protected virtual void PreInvoke(IExecutionContext executionContext)
7373
return;
7474
}
7575

76-
if (ShouldSkipChecksum(request, clientConfig))
77-
{
78-
return;
79-
}
80-
81-
ChecksumUtils.SetRequestChecksumV2(request, clientConfig);
82-
}
83-
84-
private bool ShouldSkipChecksum(IRequest request, IClientConfig clientConfig)
85-
{
86-
if (request.ChecksumData.SkipChecksum)
87-
{
88-
return true;
89-
}
90-
9176
// Do not attempt to set checksum when using SigV2 (only applicable to S3).
9277
if (clientConfig.SignatureVersion == "2")
9378
{
94-
return true;
95-
}
96-
97-
// This is a workaround for mismatches between older S3 packages and newer Core (and more specifically for S3 Express and multi-part
98-
// uploads). The service package would attempt to override the checksum for directory buckets, but the approach used would cause Core (which
99-
// is following the flexible checksum specification) to calculate a checksum for the InitiateMPU / CreateMPU operations.
100-
// TODO: This should be removed in V4 (the only component of this method that should remain is the signature version check)
101-
if (clientConfig.ServiceId.Equals("S3", StringComparison.OrdinalIgnoreCase))
102-
{
103-
var isMPURequest =
104-
request.RequestName.Equals("InitiateMultipartUploadRequest", StringComparison.OrdinalIgnoreCase) ||
105-
request.RequestName.Equals("CompleteMultipartUploadRequest", StringComparison.OrdinalIgnoreCase);
106-
var isS3ExpressRequest =
107-
request.EndpointAttributes["backend"] != null && (string)request.EndpointAttributes["backend"] == "S3Express";
108-
109-
if (isMPURequest && isS3ExpressRequest)
110-
{
111-
return true;
112-
}
79+
return;
11380
}
11481

115-
return false;
82+
ChecksumUtils.SetRequestChecksumV2(request, clientConfig);
11683
}
11784
}
11885
}

sdk/src/Services/S3/Custom/Model/GetObjectMetadataResponse.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ public class GetObjectMetadataResponse : AmazonWebServiceResponse
6060
private string _checksumSHA256;
6161
private ChecksumType _checksumType;
6262

63-
/// <summary>
64-
/// Flag which returns true if the Expires property has been unmarshalled
65-
/// from the raw value or set by user code.
66-
/// </summary>
67-
private bool isExpiresUnmarshalled;
68-
6963
/// <summary>
7064
/// The date and time at which the object is no longer cacheable.
7165
/// </summary>

sdk/src/Services/S3/Custom/Model/Internal/MarshallTransformations/PutBucketACLRequestMarshaller.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,14 @@ public IRequest Marshall(PutBucketAclRequest publicRequest)
169169
string content = stringWriter.ToString();
170170
request.Content = Encoding.UTF8.GetBytes(content);
171171
request.Headers[HeaderKeys.ContentTypeHeader] = "application/xml";
172-
if (publicRequest.IsSetContentMD5())
173-
request.Headers[Amazon.Util.HeaderKeys.ContentMD5Header] = publicRequest.ContentMD5;
174-
ChecksumUtils.SetChecksumData(request, publicRequest.ChecksumAlgorithm);
172+
173+
ChecksumUtils.SetChecksumData(
174+
request,
175+
publicRequest.ChecksumAlgorithm,
176+
fallbackToMD5: false,
177+
isRequestChecksumRequired: true,
178+
headerName: S3Constants.AmzHeaderSdkChecksumAlgorithm
179+
);
175180
}
176181
catch (EncoderFallbackException e)
177182
{

sdk/src/Services/S3/Custom/Model/Internal/MarshallTransformations/PutObjectACLRequestMarshaller.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ public IRequest Marshall(PutObjectAclRequest publicRequest)
177177
string content = stringWriter.ToString();
178178
request.Content = System.Text.Encoding.UTF8.GetBytes(content);
179179
request.Headers["Content-Type"] = "application/xml";
180-
if (publicRequest.IsSetContentMD5())
181-
request.Headers[Amazon.Util.HeaderKeys.ContentMD5Header] = publicRequest.ContentMD5;
182-
ChecksumUtils.SetChecksumData(request, publicRequest.ChecksumAlgorithm, fallbackToMD5: true);
183-
request.Headers[Amazon.Util.HeaderKeys.XAmzApiVersion] = "2006-03-01";
180+
181+
ChecksumUtils.SetChecksumData(
182+
request,
183+
publicRequest.ChecksumAlgorithm,
184+
fallbackToMD5: false,
185+
isRequestChecksumRequired: true,
186+
headerName: S3Constants.AmzHeaderSdkChecksumAlgorithm
187+
);
184188
}
185189
catch (EncoderFallbackException e)
186190
{

0 commit comments

Comments
 (0)