Skip to content
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

Async S3 Client Presigned Url Download API #5587

Open
wants to merge 9 commits into
base: feature/master/presigned-url-download
Choose a base branch
from

Conversation

davidh44
Copy link
Contributor

Motivation and Context

Modifications

  • New handwritten request POJO PresignedDownloadRequest and corresponding marshaller
  • New SdkInternalExecutionAttribute : PRESIGNED_URL
  • Added CustomSdkOperations and CustomSdkOperationsProcessor to add custom PresignedDownload operation to S3 customization config
  • Updated codegen logic to handle custom operation with input having fqcn and marshallerFqcn
  • Updated protocol specs to use custom request type and marshaller, and add presigned url ExecutionAttribute
  • Skipping sync client for now, will revisit
  • Updated AuthSchemeInterceptorSpec to use NoAuthAuthScheme if presigned url operation
  • Updated RequestEndpointInterceptorSpec to skip setting endpoint if presigned url operation

Testing

  • Added customization to codegen test models and updated generated classes
  • Added S3 Integ tests
  • To add unit tests in follow up PRs

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

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

@davidh44 davidh44 requested a review from a team as a code owner September 11, 2024 16:48
Copy link

sonarcloud bot commented Sep 11, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
64.3% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

import java.util.Map;
import software.amazon.awssdk.codegen.model.service.Operation;

public class CustomSdkOperations {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please mention the Json in Java doc of how this class looks like

import software.amazon.awssdk.codegen.model.service.Operation;

public class CustomSdkOperations {
private Map<String, Operation> operations;
Copy link
Contributor

Choose a reason for hiding this comment

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

operations more sounds like List , can we rename it to something that conveys its a Map

@@ -97,6 +98,11 @@ public TypeSpec poetSpec() {
.addMethod(generateTrySelectAuthScheme())
.addMethod(generateGetIdentityMetric())
.addMethod(putSelectedAuthSchemeMethodSpec());

if (endpointRulesSpecUtils.isS3()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid Service specific info in the Core ? Can we get this from customization local to the specific service ?

"PresignedCustomOperation":{
"name":"PresignedCustomOperation",
"input":{
"fqcn": "software.amazon.awssdk.codegen.poet.model.PresignedCustomOperation",
Copy link
Contributor

@joviegas joviegas Sep 13, 2024

Choose a reason for hiding this comment

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

Instead of giving fqn can we generate the Requests from Json
The below is not accurate , but we can do something similar as below ?

{
   "PresignedDownloadRequest":{
      "type":"structure",
      "required":["PresignedUrl"],
      "members":{
         "PresignedUrl":{
            "shape":"URL",
            "documentation":"<p>The presigned URL to download the object.</p>",
            "locationName":"presignedUrl"
         },
         "StartByte":{
            "shape":"Long",
            "documentation":"<p>The byte at which to start downloading the object.</p>",
            "locationName":"start"
         },
         "EndByte":{
            "shape":"Long",
            "documentation":"<p>The byte at which to stop downloading the object.</p>",
            "locationName":"end"
         },
         "CustomHeaders":{
            "shape":"CustomHeadersMap",
            "documentation":"<p>Any custom headers to include in the request.</p>",
            "locationName":"x-amz-custom-headers"
         }
      }
   },
   "URL":{"type":"string"},
   "Long":{"type":"long"},
   "CustomHeadersMap":{
      "type":"map",
      "key":{"shape":"String"},
      "value":{"shape":"HeaderValues"}
   },
   "HeaderValues":{
      "type":"list",
      "member":{"shape":"String"}
   },
   "String":{"type":"string"}
}

@@ -93,6 +95,22 @@ public void setShapeName(String shapeName) {
this.shapeName = shapeName;
}

public String getFqcn() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I donot think we should directly gives Fqcn for operations , We already have

  "customSdkShapes": {
    "shapes":{
      "SdkPartType":{
        "type":"string",
        "enum":[
          "DEFAULT",
          "LAST"
        ]
      }
    }
  }

Can we use it and pass the input and outputs as modeled structures ?

@@ -71,6 +71,13 @@ private MethodSpec modifyHttpRequestMethod() {
.addStatement("return context.httpRequest()")
.endControlFlow().build();

if (endpointRulesSpecUtils.isS3()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this for this feature ?
Can we make a check to rely on customization specific to this feature and can we add to only to New Custom operation rather than all the APIs ?

return intermediateModel.getShapes().values().stream().filter(s -> s.getC2jName().equals(shapeC2jName)).collect(toList());
return intermediateModel.getShapes().values().stream()
.filter(s -> s.getC2jName() != null)
.filter(s -> s.getC2jName().equals(shapeC2jName)).collect(toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

we can do shapeC2jName.equals to avoid additional null check as below

intermediateModel.getShapes().values().stream()
    .filter(s -> shapeC2jName.equals(s.getC2jName()))
    .collect(toList());

@@ -303,6 +306,18 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
return builder.build();
}

private void addMarshaller(CodeBlock.Builder builder, OperationModel opModel, IntermediateModel intermediateModel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we model the request with Json as I mentioned in the customization.config we will not need this

@joviegas
Copy link
Contributor

joviegas commented Sep 13, 2024

Overall I was thinking we should try to be consistent with the model structure
We already have "shapeModifiers" we can have something "operationModifiers" and have a field "add" this adds custom operations to the existing operations.
Can you please give a try for this approach

{
  "operationModifiers": {
    "PresignedDownload": {
      "addNew": [
        {
          "name": "PresignedDownload",
          "http": {
            "method": "GET",
            "requestUri": "/"
          },
          "input": "PresignedDownloadInput"
          },
          "output": {
            "shape": "GetObjectOutput"
          },
          "errors": [
            {
              "shape": "InvalidObjectState"
            }
          ],
          "documentation": "Non-modeled operation for downloading S3 object with pre-signed URL"
        }
      ]
    }
  }
}

Define PresignedDownloadInput as mentioned in another comment

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.

2 participants