This is an automated email from the ASF dual-hosted git repository.

amoghj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 19637903e9 AWS: Update S3 signer spec to allow an optional string body 
in S3SignRequest. (#8361)
19637903e9 is described below

commit 19637903e9b417ff724821adabb1252757741380
Author: Amogh Jahagirdar <[email protected]>
AuthorDate: Mon Aug 21 15:14:58 2023 -0700

    AWS: Update S3 signer spec to allow an optional string body in 
S3SignRequest. (#8361)
    
    Update S3 signer parser implementation to enable
    serialization/deserialization of the body.
    
    Note: This will only be populated for requests which do not transmit
    relevant data to sign as part of the URI itself (e.g.
    DeleteObjectsRequest)
---
 .../iceberg/aws/s3/signer/S3SignRequest.java       |  7 ++++
 .../iceberg/aws/s3/signer/S3SignRequestParser.java |  9 +++++
 aws/src/main/resources/s3-signer-open-api.yaml     |  4 +++
 .../aws/s3/signer/TestS3SignRequestParser.java     | 42 ++++++++++++++++++++++
 4 files changed, 62 insertions(+)

diff --git 
a/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequest.java 
b/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequest.java
index d8323fd868..879ce85993 100644
--- a/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequest.java
+++ b/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequest.java
@@ -21,6 +21,7 @@ package org.apache.iceberg.aws.s3.signer;
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
+import javax.annotation.Nullable;
 import org.apache.iceberg.rest.RESTRequest;
 import org.immutables.value.Value;
 
@@ -36,6 +37,12 @@ public interface S3SignRequest extends RESTRequest {
 
   Map<String, String> properties();
 
+  @Value.Default
+  @Nullable
+  default String body() {
+    return null;
+  }
+
   @Override
   default void validate() {}
 }
diff --git 
a/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequestParser.java 
b/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequestParser.java
index f5d6f711a0..efb11b3cdf 100644
--- 
a/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequestParser.java
+++ 
b/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3SignRequestParser.java
@@ -36,6 +36,7 @@ public class S3SignRequestParser {
   private static final String URI = "uri";
   private static final String HEADERS = "headers";
   private static final String PROPERTIES = "properties";
+  private static final String BODY = "body";
 
   private S3SignRequestParser() {}
 
@@ -61,6 +62,10 @@ public class S3SignRequestParser {
       JsonUtil.writeStringMap(PROPERTIES, request.properties(), gen);
     }
 
+    if (request.body() != null && !request.body().isEmpty()) {
+      gen.writeStringField(BODY, request.body());
+    }
+
     gen.writeEndObject();
   }
 
@@ -85,6 +90,10 @@ public class S3SignRequestParser {
       builder.properties(JsonUtil.getStringMap(PROPERTIES, json));
     }
 
+    if (json.has(BODY)) {
+      builder.body(JsonUtil.getString(BODY, json));
+    }
+
     return builder.build();
   }
 
diff --git a/aws/src/main/resources/s3-signer-open-api.yaml 
b/aws/src/main/resources/s3-signer-open-api.yaml
index be9775b82c..1e4dafa6c1 100644
--- a/aws/src/main/resources/s3-signer-open-api.yaml
+++ b/aws/src/main/resources/s3-signer-open-api.yaml
@@ -121,6 +121,10 @@ components:
           type: object
           additionalProperties:
             type: string
+        body:
+          type: string
+          description: Optional body of the S3 request to send to the signing 
API. This should only be populated
+            for S3 requests which do not have the relevant data in the URI 
itself (e.g. DeleteObjects requests)
 
 
   #############################
diff --git 
a/aws/src/test/java/org/apache/iceberg/aws/s3/signer/TestS3SignRequestParser.java
 
b/aws/src/test/java/org/apache/iceberg/aws/s3/signer/TestS3SignRequestParser.java
index 753d2078c4..a6928183f7 100644
--- 
a/aws/src/test/java/org/apache/iceberg/aws/s3/signer/TestS3SignRequestParser.java
+++ 
b/aws/src/test/java/org/apache/iceberg/aws/s3/signer/TestS3SignRequestParser.java
@@ -185,4 +185,46 @@ public class TestS3SignRequestParser {
                 + "  }\n"
                 + "}");
   }
+
+  @Test
+  public void roundTripWithBody() {
+    ImmutableS3SignRequest s3SignRequest =
+        ImmutableS3SignRequest.builder()
+            .uri(URI.create("http://localhost:49208/iceberg-signer-test";))
+            .method("PUT")
+            .region("us-west-2")
+            .headers(
+                ImmutableMap.of(
+                    "amz-sdk-request",
+                    Arrays.asList("attempt=1", "max=4"),
+                    "Content-Length",
+                    Arrays.asList("191"),
+                    "Content-Type",
+                    Arrays.asList("application/json"),
+                    "User-Agent",
+                    Arrays.asList("aws-sdk-java/2.20.18", "Linux/5.4.0-126")))
+            .properties(ImmutableMap.of("k1", "v1"))
+            .body("some-body")
+            .build();
+
+    String json = S3SignRequestParser.toJson(s3SignRequest, true);
+    
Assertions.assertThat(S3SignRequestParser.fromJson(json)).isEqualTo(s3SignRequest);
+    Assertions.assertThat(json)
+        .isEqualTo(
+            "{\n"
+                + "  \"region\" : \"us-west-2\",\n"
+                + "  \"method\" : \"PUT\",\n"
+                + "  \"uri\" : 
\"http://localhost:49208/iceberg-signer-test\",\n";
+                + "  \"headers\" : {\n"
+                + "    \"amz-sdk-request\" : [ \"attempt=1\", \"max=4\" ],\n"
+                + "    \"Content-Length\" : [ \"191\" ],\n"
+                + "    \"Content-Type\" : [ \"application/json\" ],\n"
+                + "    \"User-Agent\" : [ \"aws-sdk-java/2.20.18\", 
\"Linux/5.4.0-126\" ]\n"
+                + "  },\n"
+                + "  \"properties\" : {\n"
+                + "    \"k1\" : \"v1\"\n"
+                + "  },\n"
+                + "  \"body\" : \"some-body\"\n"
+                + "}");
+  }
 }

Reply via email to