Skip to content

Commit f41d1fe

Browse files
committed
fix: Mark CalculateContentMD5Header as deprecated
1 parent c7f3eb1 commit f41d1fe

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

modules/AWSPowerShell/Cmdlets/S3/Advanced/Write-S3Object-Cmdlet.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ public class WriteS3ObjectCmdlet : AmazonS3ClientCmdlet, IExecutor
405405
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ParamSet_FromContent)]
406406
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ParamSet_FromStream)]
407407
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ParamSet_FromLocalFileChecksum, Mandatory = true)]
408-
[Amazon.PowerShell.Common.AWSRequiredParameter(ParameterSets = new[] { ParamSet_FromLocalFileChecksum })]
408+
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ParamSet_FromLocalFolder)]
409+
[AWSRequiredParameter(ParameterSets = new[] { ParamSet_FromLocalFileChecksum })]
409410
[AWSConstantClassSource("Amazon.S3.ChecksumAlgorithm")]
410411
public ChecksumAlgorithm ChecksumAlgorithm { get; set; }
411412
#endregion
@@ -415,7 +416,7 @@ public class WriteS3ObjectCmdlet : AmazonS3ClientCmdlet, IExecutor
415416
/// The checksum of the object base64 encoded with the alorithm specified in the <code>ChecksumAlgorithm</code> parameter. This checksum is only present if the checksum was uploaded
416417
/// with the object. When you use an API operation on an object that was uploaded using multipart uploads, this value may not be a direct checksum value of the full object.
417418
/// Instead, it's a calculation based on the checksum values of each individual part. For more information about how checksums are calculated
418-
/// with multipart uploads, see <a href=\"https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums\">
419+
/// with multipart uploads, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums">
419420
/// Checking object integrity</a> in the <i>Amazon S3 User Guide</i>."
420421
/// </summary>
421422
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ParamSet_FromLocalFileChecksum)]
@@ -467,6 +468,7 @@ public class WriteS3ObjectCmdlet : AmazonS3ClientCmdlet, IExecutor
467468
/// This property determines whether the Content-MD5 header should be calculated for upload.
468469
/// </summary>
469470
[Parameter(ValueFromPipelineByPropertyName = true)]
471+
[Obsolete("This parameter is redundant in the latest version of the S3 module, which automatically calculates a checksum to verify data integrity")]
470472
public bool CalculateContentMD5Header { get; set; }
471473
#endregion
472474

@@ -598,8 +600,11 @@ protected override void ProcessRecord()
598600
context.Metadata = this.Metadata;
599601
context.Headers = this.HeaderCollection;
600602
context.TagSet = this.TagSet;
603+
604+
#pragma warning disable CS0618 // A class member was marked with the Obsolete attribute
601605
context.CalculateContentMD5Header = this.CalculateContentMD5Header;
602-
606+
#pragma warning restore CS0618 // A class member was marked with the Obsolete attribute
607+
603608
if (this.ChecksumAlgorithm != null)
604609
{
605610
context.ChecksumAlgorithm = this.ChecksumAlgorithm;
@@ -695,7 +700,9 @@ CmdletOutput UploadTextToS3(ExecutorContext context)
695700
if (!string.IsNullOrEmpty(cmdletContext.IfNoneMatch))
696701
request.IfNoneMatch = cmdletContext.IfNoneMatch;
697702

703+
#pragma warning disable CS0618 // A class member was marked with the Obsolete attribute
698704
request.CalculateContentMD5Header = cmdletContext.CalculateContentMD5Header;
705+
#pragma warning restore CS0618 // A class member was marked with the Obsolete attribute
699706

700707
if (cmdletContext.RequestPayer != null)
701708
{
@@ -795,7 +802,9 @@ private CmdletOutput UploadFileToS3(ExecutorContext context)
795802
if (!string.IsNullOrEmpty(cmdletContext.IfNoneMatch))
796803
request.IfNoneMatch = cmdletContext.IfNoneMatch;
797804

805+
#pragma warning disable CS0618 // A class member was marked with the Obsolete attribute
798806
request.CalculateContentMD5Header = cmdletContext.CalculateContentMD5Header;
807+
#pragma warning restore CS0618 // A class member was marked with the Obsolete attribute
799808

800809
if (cmdletContext.PartSize != null)
801810
request.PartSize = cmdletContext.PartSize.Value;
@@ -864,7 +873,14 @@ private CmdletOutput UploadFolderToS3(ExecutorContext context)
864873
if (cmdletContext.TagSet != null)
865874
request.TagSet = new List<Tag>(cmdletContext.TagSet);
866875

876+
#pragma warning disable CS0618 // A class member was marked with the Obsolete attribute
867877
request.CalculateContentMD5Header = cmdletContext.CalculateContentMD5Header;
878+
#pragma warning restore CS0618 // A class member was marked with the Obsolete attribute
879+
880+
if (cmdletContext.ChecksumAlgorithm != null)
881+
{
882+
request.ChecksumAlgorithm = cmdletContext.ChecksumAlgorithm;
883+
}
868884

869885
if (cmdletContext.RequestPayer != null)
870886
{

tests/S3/S3.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,14 @@ Describe -Tag "Smoke" "S3" {
236236
$checksumValue = 'abc123'
237237
{Write-S3Object -BucketName $script:bucketName -Key foo.txt -File $testFilePath -ChecksumAlgorithm CRC32C -ChecksumValue $checksumValue} | Should -Throw '* is invalid.'
238238
}
239+
240+
It "Can upload a folder using a checksum different than the default" {
241+
$void = New-Item -Path "temp\checksums-upload" -Type directory -Force
242+
"sample text" | Out-File -FilePath ".\temp\checksums-upload\test.txt" -Force
243+
"more sample text" | Out-File -FilePath ".\temp\checksums-upload\test2.txt" -Force
244+
245+
Write-S3Object -BucketName $script:bucketName -KeyPrefix checksums\ -Folder ".\temp\checksums-upload" -Recurse -ChecksumAlgorithm CRC32C
246+
Read-S3Object -BucketName $script:bucketName -KeyPrefix checksums -Folder ".\temp\checksums-download"
247+
}
239248
}
240249
}

0 commit comments

Comments
 (0)