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

Draft
wants to merge 5 commits into
base: development
Choose a base branch
from

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.

Relevant CommitId: d0b0c91

Motivation and Context

Testing

DRY_RUN-286a5bea-fbd6-4a41-b36b-2d2da858173b 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
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.

1 participant