fix: fix s3 createbucket response format for rust sdk compatibility (#11)

This commit is contained in:
Hector Ventura committed 2026-03-23 11:58:08 -05:00
1 parent e4446c0377
commit 0e29c65266
7 files changed
+57 -27

No files matched your search

@@ -136,7 +136,7 @@ public class CloudFormationResourceProvisioner {
if (bucketName == null || bucketName.isBlank()) {
bucketName = "cfn-" + UUID.randomUUID().toString().substring(0, 12).toLowerCase();
}
s3Service.createBucket(bucketName);
s3Service.createBucket(bucketName, region);
r.setPhysicalId(bucketName);
r.getAttributes().put("Arn", "arn:aws:s3:::" + bucketName);
r.getAttributes().put("DomainName", bucketName + ".s3.amazonaws.com");
@@ -139,7 +139,13 @@ public class S3Controller {
return Response.ok().build();
}
s3Service.createBucket(bucket);
String locationConstraint = null;
if (body != null && body.length > 0) {
locationConstraint = XmlParser.extractFirst(new String(body, StandardCharsets.UTF_8),
"LocationConstraint", null);
}
String region = locationConstraint != null ? locationConstraint : regionResolver.getDefaultRegion();
s3Service.createBucket(bucket, region);
String lockEnabled = httpHeaders.getHeaderString("x-amz-bucket-object-lock-enabled");
if ("true".equalsIgnoreCase(lockEnabled)) {
s3Service.putBucketVersioning(bucket, "Enabled");
@@ -721,8 +727,10 @@ public class S3Controller {
// --- Bucket Location ---
private Response handleGetBucketLocation(String bucket) {
s3Service.headBucket(bucket);
String region = regionResolver.getDefaultRegion();
String region = s3Service.getBucketRegion(bucket);
if (region == null) {
region = regionResolver.getDefaultRegion();
}
String xml = new XmlBuilder()
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.start("LocationConstraint", AwsNamespaces.S3)
@@ -90,7 +90,7 @@ public class S3Service {
}
}
public Bucket createBucket(String bucketName) {
public Bucket createBucket(String bucketName, String region) {
var existing = bucketStore.get(bucketName);
if (existing.isPresent()) {
throw new AwsException("BucketAlreadyOwnedByYou",
@@ -98,8 +98,9 @@ public class S3Service {
}
Bucket bucket = new Bucket(bucketName);
bucket.setRegion(region);
bucketStore.put(bucketName, bucket);
LOG.infov("Created bucket: {0}", bucketName);
LOG.infov("Created bucket: {0} in region: {1}", bucketName, region);
return bucket;
}
@@ -436,6 +437,11 @@ public class S3Service {
ensureBucketExists(bucketName);
}
public String getBucketRegion(String bucketName) {
ensureBucketExists(bucketName);
return bucketStore.get(bucketName).map(Bucket::getRegion).orElse(null);
}
// --- Batch Delete ---
public record DeleteResult(String key, String versionId, boolean deleteMarker, String deleteMarkerVersionId) {
@@ -23,6 +23,7 @@ public class Bucket {
private String lifecycleConfiguration;
private String acl; // XML representation or JSON stub
private String encryptionConfiguration; // XML string
private String region;
public Bucket() {
this.tags = new HashMap<>();
@@ -74,4 +75,7 @@ public class Bucket {
public String getEncryptionConfiguration() { return encryptionConfiguration; }
public void setEncryptionConfiguration(String encryptionConfiguration) { this.encryptionConfiguration = encryptionConfiguration; }
public String getRegion() { return region; }
public void setRegion(String region) { this.region = region; }
}