Skip to content

S3 Gen Phase 2: Generate PutBucket #3909

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 5 commits into from
Jul 21, 2025

Conversation

peterrsongg
Copy link
Contributor

@peterrsongg peterrsongg commented Jul 10, 2025

Description

This generates PutBucket. The major changes are

  1. Added InheritAlternateBaseClass customization for PutBucketRequest to inherit from PutWithAclRequest as defined in custom
  2. I moved PostMarshallCustomization to before the try catch block where we set the content because we could be altering the content in that method
  3. There is some custom logic that exists for PutBucketRequestMarshaller where the user could set BucketRegion or BucketRegionName and not have to create a PutBucketConfiguration object and we would create the appropriate xml for the user. I moved that logic to the setters of both BucketRegion and BucketRegionName
  4. I excluded some un-used members since PutBucketRequest has logic with setting ACLs

Motivation and Context

S3 Generation Phase 2.

Testing

I did some manual checks to make sure that a user could still only specify the bucket region and name and create a bucket without having to create the PutBucketConfiguration object themselves.

Assembly comparer output (empty)

C:\Scripts> .\assembly-comparison.ps1
Already on 'petesong/generate-s3-phase-2-pr1'
  AWSSDK.Core.NetStandard net8.0 succeeded (39.0s) → C:\Dev\Repos\aws-sdk-net-staging\sdk\src\Core\bin\Debug\net8.0\AWSSDK.Core.dll
  AWSSDK.S3.NetStandard net8.0 succeeded (8.8s) → bin\Debug\net8.0\AWSSDK.S3.dll

Build succeeded in 53.0s

Workload updates are available. Run `dotnet workload list` for more information.
Switched to branch 'development'
Your branch is up to date with 'public/development'.
  AWSSDK.Core.NetStandard net8.0 succeeded (5.3s) → C:\Dev\Repos\aws-sdk-net-staging\sdk\src\Core\bin\Debug\net8.0\AWSSDK.Core.dll
  AWSSDK.S3.NetStandard net8.0 succeeded (4.5s) → bin\Debug\net8.0\AWSSDK.S3.dll

Build succeeded in 10.3s

Dry_Run passes caeb33aa-9f50-4418-af23-d054dcd47197

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

@@ -181,17 +187,41 @@ WriteXmlAttributeString(level, member, variableName, isPayload: false);
#>
if (<#=variableName + ".IsSet" + operation.RequestPayloadMember.PropertyName#>())
{
<#+
// S3 doesn't follow the rule where if the request payload member's location name is the same as the payload member name, we marshall with the payload member's shape's marshall name instead
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without this, we would incorrectly write PutBucketConfiguration as the xml element name when it should be CreateBucketConfiguration. S3 doesn't follow this rule.

@normj normj self-requested a review July 10, 2025 06:56
@@ -97,7 +97,7 @@ public IRequest Marshall(PutObjectRetentionRequest publicRequest)
{
if (publicRequest.IsSetRetention())
{
xmlWriter.WriteStartElement("ObjectLockRetention", "http://s3.amazonaws.com/doc/2006-03-01/");
xmlWriter.WriteStartElement("Retention", "http://s3.amazonaws.com/doc/2006-03-01/");
Copy link
Member

Choose a reason for hiding this comment

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

I assume this was a benign bug that we were using the wrong root element name. I see in the docs Retention is the correct value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, i also tested the operation when i did a sweep of all released operations

@GarrettBeatty GarrettBeatty requested a review from Copilot July 16, 2025 01:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds the S3 PutBucket operation support by:

  • Customizing the base class of PutBucketRequest to inherit from PutWithACLRequest
  • Moving PostMarshallCustomization calls into the generated marshaller template for more precise timing
  • Implementing logic in the BucketRegion and BucketRegionName setters to auto-create a PutBucketConfiguration and removing unused members

Reviewed Changes

Copilot reviewed 9 out of 38 changed files in this pull request and generated 4 comments.

File Description
sdk/src/Services/S3/Custom/Model/PutBucketRequest.cs Updated inheritance, moved ACL logic to base class, added region-based configuration in property setters, removed unused properties
sdk/src/Services/S3/Custom/Model/PutBucketConfiguration.cs Deleted manual copy of PutBucketConfiguration (now generated)
sdk/src/Services/S3/Custom/Model/Internal/MarshallTransformations/PutBucketRequestMarshaller.cs Converted to partial class, preserved ACL header logic in PostMarshallCustomization
generator/ServiceClientGeneratorLib/* Added support for inheritAlternateBaseClass in generator and patched the T4 marshaller template to invoke PostMarshallCustomization

Comment on lines +72 to +73
_putBucketConfiguration.LocationConstraint = bucketRegion.Value;
}
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

The BucketRegion setter only initializes the configuration once, so updating the region a second time won’t update LocationConstraint. Consider always assigning or updating _putBucketConfiguration.LocationConstraint to reflect the latest BucketRegion.

Suggested change
_putBucketConfiguration.LocationConstraint = bucketRegion.Value;
}
}
_putBucketConfiguration.LocationConstraint = bucketRegion.Value;

Copilot uses AI. Check for mistakes.

set
{
this.bucketRegionName = value;
if (bucketRegionName != "us-east-1")
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

When BucketRegionName is reset to "us-east-1", the existing _putBucketConfiguration isn’t cleared, potentially leaving a stale LocationConstraint. Consider clearing or resetting the configuration when returning to the default region.

Copilot uses AI. Check for mistakes.

{
_putBucketConfiguration = new PutBucketConfiguration();
if (bucketRegionName == "eu-west-1")
_putBucketConfiguration.LocationConstraint = "EU";
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Hard-coded region strings (e.g., "eu-west-1", "EU") can lead to typos or drift. Prefer using defined constants or the S3Region enum to ensure consistency.

Suggested change
_putBucketConfiguration.LocationConstraint = "EU";
_putBucketConfiguration.LocationConstraint = S3Region.EU.Value;

Copilot uses AI. Check for mistakes.

// the NoAcl logic exists because it was originally a part of the IsSetCannedACL()
// method https://github.com/aws/aws-sdk-net/blob/623dc261499331cb38bfec47789ddc4ef456222c/sdk/src/Services/S3/Custom/Model/PutBucketRequest.cs#L195-L198
if (publicRequest.IsSetCannedACL() && publicRequest.CannedACL == S3CannedACL.NoACL)
defaultRequest.Headers.Remove("x-amz-acl");
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use the HeaderKeys.XAmzAclHeader constant instead of a literal string to remove the ACL header, improving consistency and reducing the risk of typos.

Suggested change
defaultRequest.Headers.Remove("x-amz-acl");
defaultRequest.Headers.Remove(HeaderKeys.XAmzAclHeader);

Copilot uses AI. Check for mistakes.

@peterrsongg peterrsongg merged commit 6501007 into development Jul 21, 2025
6 checks passed
@peterrsongg peterrsongg deleted the petesong/generate-s3-phase-2-pr1 branch July 21, 2025 15:21
peterrsongg added a commit that referenced this pull request Jul 21, 2025
peterrsongg added a commit that referenced this pull request Jul 21, 2025
@peterrsongg peterrsongg restored the petesong/generate-s3-phase-2-pr1 branch July 21, 2025 19:56
@peterrsongg peterrsongg mentioned this pull request Jul 22, 2025
10 tasks
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