Skip to content

Generate PutBucketEncryption, GetBucketEncryption, GetBucketAccelerate #3876

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

Merged
merged 4 commits into from
Jun 18, 2025

Conversation

peterrsongg
Copy link
Contributor

@peterrsongg peterrsongg commented Jun 12, 2025

Description

In this PR I generate PutBucketEncryption, GetBucketEncryption, and GetBucketAccelerate. As discussed, phase 1 will include updates to our rest-xml tt files too since they aren't used for many services and will now be used for the most used service. As such, I have refactored where I thought necessary to reduce code duplication by moving things into functions that can be reusable. I've added comments in the PR as to why I did so.

Motivation and Context

Testing

Output from AssemblyComparer ( All are internal and the ones that aren't I checked and there were no backwards incompatibilities)

C:\Dev\Repos\AwsSdkDotNetBuildUtilities\AssemblyComparer\AssemblyComparer\bin\Debug\net8.0 [mainline ≡]> ./AssemblyComparer.exe assembly-comparer --old-assembly "C:\AssemblyComparisons\AWSSDK.S3.Old.dll" --new-assembly "C:\AssemblyComparisons\AWSSDK.S3.New.dll"
AssemblyComparer AWSSDK.S3.New.dll: Error Amazon.S3.Model.Internal.MarshallTransformations.PutBucketEncryptionRequestMarshaller/ParameterNameChanged: Parameter name changed for method Amazon.Runtime.Internal.IRequest Marshall(Amazon.S3.Model.PutBucketEncryptionRequest) in Amazon.S3.Model.Internal.MarshallTransformations.PutBucketEncryptionRequestMarshaller from putBucketEncryptionRequest to publicRequest
AssemblyComparer AWSSDK.S3.New.dll: Error Amazon.S3.AmazonS3Client/MethodReturnTypeChanged: Return type changed for method System.Threading.Tasks.Task<Amazon.S3.Model.PutBucketEncryptionResponse> PutBucketEncryptionAsync(Amazon.S3.Model.PutBucketEncryptionRequest, System.Threading.CancellationToken) in Amazon.S3.AmazonS3Client from System.Threading.Tasks.Task [System.Runtime 8.0.0.0]<Amazon.S3.PutBucketEncryptionResponse> to System.Threading.Tasks.Task [System.Runtime 8.0.0.0]<Amazon.S3.Model.PutBucketEncryptionResponse>
AssemblyComparer AWSSDK.S3.New.dll: Error Amazon.S3.PutBucketEncryptionResponse/TypeRemoved: Missing type Amazon.S3.PutBucketEncryptionResponse
AssemblyComparer AWSSDK.S3.New.dll: Message Amazon.S3.Model.Internal.MarshallTransformations.PutBucketEncryptionResponseUnmarshaller/MethodAdded: New method Amazon.Runtime.AmazonServiceException UnmarshallException(Amazon.Runtime.Internal.Transform.XmlUnmarshallerContext, System.Exception, System.Net.HttpStatusCode) in Amazon.S3.Model.Internal.MarshallTransformations.PutBucketEncryptionResponseUnmarshaller
AssemblyComparer AWSSDK.S3.New.dll: Error Amazon.S3.Model.Internal.MarshallTransformations.GetBucketEncryptionRequestMarshaller/ParameterNameChanged: Parameter name changed for method Amazon.Runtime.Internal.IRequest Marshall(Amazon.S3.Model.GetBucketEncryptionRequest) in Amazon.S3.Model.Internal.MarshallTransformations.GetBucketEncryptionRequestMarshaller from getEncryptionRequest to publicRequest
AssemblyComparer AWSSDK.S3.New.dll: Error Amazon.S3.IAmazonS3/MethodReturnTypeChanged: Return type changed for method System.Threading.Tasks.Task<Amazon.S3.Model.PutBucketEncryptionResponse> PutBucketEncryptionAsync(Amazon.S3.Model.PutBucketEncryptionRequest, System.Threading.CancellationToken) in Amazon.S3.IAmazonS3 from System.Threading.Tasks.Task [System.Runtime 8.0.0.0]<Amazon.S3.PutBucketEncryptionResponse> to System.Threading.Tasks.Task [System.Runtime 8.0.0.0]<Amazon.S3.Model.PutBucketEncryptionResponse>
AssemblyComparer AWSSDK.S3.New.dll: Message Amazon.S3.Model.Internal.MarshallTransformations.GetBucketEncryptionResponseUnmarshaller/MethodAdded: New method Amazon.Runtime.AmazonServiceException UnmarshallException(Amazon.Runtime.Internal.Transform.XmlUnmarshallerContext, System.Exception, System.Net.HttpStatusCode) in Amazon.S3.Model.Internal.MarshallTransformations.GetBucketEncryptionResponseUnmarshaller
AssemblyComparer AWSSDK.S3.New.dll: Error Amazon.S3.Model.Internal.MarshallTransformations.GetBucketAccelerateConfigurationRequestMarshaller/ParameterNameChanged: Parameter name changed for method Amazon.Runtime.Internal.IRequest Marshall(Amazon.S3.Model.GetBucketAccelerateConfigurationRequest) in Amazon.S3.Model.Internal.MarshallTransformations.GetBucketAccelerateConfigurationRequestMarshaller from getBucketAccelerateRequest to publicRequest
AssemblyComparer AWSSDK.S3.New.dll: Message Amazon.S3.Model.PutBucketEncryptionResponse/TypeAdded: New type Amazon.S3.Model.PutBucketEncryptionResponse
AssemblyComparer AWSSDK.S3.New.dll: Message Amazon.S3.Model.Internal.MarshallTransformations.GetBucketAccelerateConfigurationResponseUnmarshaller/MethodAdded: New method Amazon.Runtime.AmazonServiceException UnmarshallException(Amazon.Runtime.Internal.Transform.XmlUnmarshallerContext, System.Exception, System.Net.HttpStatusCode) in Amazon.S3.Model.Internal.MarshallTransformations.GetBucketAccelerateConfigurationResponseUnmarshaller
AssemblyComparer AWSSDK.S3.New.dll: Message Amazon.S3.Model.Internal.MarshallTransformations.ServerSideEncryptionConfigurationUnmarshaller/TypeAdded: New type Amazon.S3.Model.Internal.MarshallTransformations.ServerSideEncryptionConfigurationUnmarshaller

Build id: 9efcf94b-4022-4e5f-a497-e8861471e561 SUCCEEDED
For PutBucketEncryption

    var request = new PutBucketEncryptionRequest
    {
        BucketName = "petesong-east-1-bucket",
        ServerSideEncryptionConfiguration = new ServerSideEncryptionConfiguration
        {
            ServerSideEncryptionRules = new List<ServerSideEncryptionRule> 
            {
                new ServerSideEncryptionRule
                {
                    ServerSideEncryptionByDefault = new ServerSideEncryptionByDefault
                    {
                        SSEAlgorithm = ServerSideEncryptionMethod.AWSKMS, // or AES256
                        KMSMasterKeyID = "e90ac20e-d5dc-47c3-aa0d-bebd6805521f"
                    },
                    BucketKeyEnabled = true // Enables bucket key for cost optimization (only for KMS)
                }
            }
        },
        ExpectedBucketOwner = "404186920727", // Optional: the expected AWS account ID of the bucket owner
        ChecksumAlgorithm = ChecksumAlgorithm.SHA256 // Optional: supported values are SHA256, SHA1, CRC32, CRC32C
    };

    try
    {
        var response = await s3Client.PutBucketEncryptionAsync(request);
        Console.WriteLine($"Encryption configuration set for bucket: petesong-east-1-bucket");
    }
    catch (AmazonS3Exception ex)
    {
        Console.WriteLine($"Error setting encryption: {ex.Message}");
    }

validated that the request is sent correctly
What we are sending:

<ServerSideEncryptionConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Rule>
        <BucketKeyEnabled>true</BucketKeyEnabled>
        <ApplyServerSideEncryptionByDefault>
            <KMSMasterKeyID>******</KMSMasterKeyID>
            <SSEAlgorithm>aws:kms</SSEAlgorithm>
        </ApplyServerSideEncryptionByDefault>
    </Rule>
</ServerSideEncryptionConfiguration>

From the docs

<ServerSideEncryptionConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
   <Rule>
      <ApplyServerSideEncryptionByDefault>
         <KMSMasterKeyID>string</KMSMasterKeyID>
         <SSEAlgorithm>string</SSEAlgorithm>
      </ApplyServerSideEncryptionByDefault>
      <BucketKeyEnabled>boolean</BucketKeyEnabled>
   </Rule>
   ...
</ServerSideEncryptionConfiguration>

For GetBucketEncryptionRequest

    var getBucketEncryptionRequest = new GetBucketEncryptionRequest
    {
        BucketName = "<by_bucket>",
        ExpectedBucketOwner = <my_account>
    };
        var getBucketEncryptionResponse = await s3Client.GetBucketEncryptionAsync(getBucketEncryptionRequest).ConfigureAwait(false);
        var sseConfiguration = getBucketEncryptionResponse.ServerSideEncryptionConfiguration;
        foreach (var rule in sseConfiguration.ServerSideEncryptionRules)
        {
            Console.WriteLine(rule.BucketKeyEnabled);
            Console.WriteLine(rule.ServerSideEncryptionByDefault.KMSMasterKeyID);
            Console.WriteLine(rule.ServerSideEncryptionByDefault.SSEAlgorithm);
        }

correctly printed out the results.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@peterrsongg peterrsongg marked this pull request as draft June 12, 2025 07:33
@peterrsongg peterrsongg force-pushed the petesong/generate-s3-phase-1-part4 branch from d0b0c91 to 46481b0 Compare June 13, 2025 21:52
@peterrsongg peterrsongg force-pushed the petesong/generate-s3-phase-1-part4 branch from 46481b0 to 0239a8a Compare June 16, 2025 16:10
@peterrsongg peterrsongg marked this pull request as ready for review June 16, 2025 23:44
@normj normj self-requested a review June 17, 2025 20:28
Copy link
Member

@normj normj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a minor nit

}

// some structure members do not have a locationName.
// so if we get to this point, it is gauranteed that the marshall name we are determining is for a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo gauranteed -> guaranteed

@peterrsongg peterrsongg merged commit 57d031b into development Jun 18, 2025
3 checks passed
@peterrsongg peterrsongg deleted the petesong/generate-s3-phase-1-part4 branch June 18, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants