-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service/s3: Add documentation for using unseekable body PutObject and…
… UploadPart (#1176) Adds additional documentation to the PutObject and UploadPart operations on how to to use unseekable values to be uploaded to S3. Updates the v4 package with a new helper to swap out the compute payload hash middleware for the unsigned payload middleware. This allows API operations to be updated to not compute the payload hash, and use UNSIGNED-PAYLOAD instead.
- Loading branch information
Showing
8 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ID": "sdk-feature-1615946574682127000", | ||
"SchemaVersion": 1, | ||
"Module": "/", | ||
"Type": "feature", | ||
"Description": "Add helper to V4 signer package to swap compute payload hash middleware with unsigned payload middleware", | ||
"MinVersion": "", | ||
"AffectedModules": null | ||
} |
9 changes: 9 additions & 0 deletions
9
.changes/next-release/service.s3-bugfix-1615945295096775000.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ID": "service.s3-bugfix-1615945295096775000", | ||
"SchemaVersion": 1, | ||
"Module": "service/s3", | ||
"Type": "bugfix", | ||
"Description": "Adds documentation to the PutObject and UploadPart operations Body member how to upload unseekable objects to an Amazon S3 Bucket.", | ||
"MinVersion": "", | ||
"AffectedModules": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
.../software/amazon/smithy/aws/go/codegen/customization/S3AddPutObjectUnseekableBodyDoc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package software.amazon.smithy.aws.go.codegen.customization; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
import software.amazon.smithy.codegen.core.CodegenException; | ||
import software.amazon.smithy.go.codegen.GoSettings; | ||
import software.amazon.smithy.go.codegen.integration.GoIntegration; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.MemberShape; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
import software.amazon.smithy.model.shapes.StructureShape; | ||
import software.amazon.smithy.model.traits.DocumentationTrait; | ||
import software.amazon.smithy.utils.MapUtils; | ||
import software.amazon.smithy.utils.Pair; | ||
import software.amazon.smithy.utils.SetUtils; | ||
|
||
public class S3AddPutObjectUnseekableBodyDoc implements GoIntegration { | ||
private static final Logger LOGGER = Logger.getLogger(S3AddPutObjectUnseekableBodyDoc.class.getName()); | ||
|
||
private static final Map<ShapeId, Set<Pair<ShapeId, String>>> SERVICE_TO_SHAPE_MAP = MapUtils.of( | ||
ShapeId.from("com.amazonaws.s3#AmazonS3"), SetUtils.of( | ||
new Pair(ShapeId.from("com.amazonaws.s3#PutObjectRequest"), "Body"), | ||
new Pair(ShapeId.from("com.amazonaws.s3#UploadPartRequest"), "Body") | ||
) | ||
); | ||
|
||
@Override | ||
public byte getOrder() { | ||
// This integration should happen before other integrations that rely on the presence of this trait | ||
return -60; | ||
} | ||
|
||
@Override | ||
public Model preprocessModel( | ||
Model model, GoSettings settings | ||
) { | ||
ShapeId serviceId = settings.getService(); | ||
if (!SERVICE_TO_SHAPE_MAP.containsKey(serviceId)) { | ||
return model; | ||
} | ||
|
||
Set<Pair<ShapeId, String>> shapeIds = SERVICE_TO_SHAPE_MAP.get(serviceId); | ||
|
||
Model.Builder builder = model.toBuilder(); | ||
for (Pair<ShapeId, String> pair : shapeIds) { | ||
ShapeId shapeId = pair.getLeft(); | ||
String memberName = pair.getRight(); | ||
StructureShape parent = model.expectShape(shapeId, StructureShape.class); | ||
|
||
Optional<MemberShape> memberOpt = parent.getMember(memberName); | ||
if (!memberOpt.isPresent()) { | ||
// Throw in case member is not present, bad things must of happened. | ||
throw new CodegenException("expect to find " + memberName + " member in shape " + parent.getId()); | ||
} | ||
|
||
MemberShape member = memberOpt.get(); | ||
Shape target = model.expectShape(member.getTarget()); | ||
|
||
Optional<DocumentationTrait> docTrait = member.getTrait(DocumentationTrait.class); | ||
String currentDocs = ""; | ||
if (docTrait.isPresent()) { | ||
currentDocs = docTrait.get().getValue(); | ||
} | ||
if (currentDocs.length() != 0) { | ||
currentDocs += "<br/><br/>"; | ||
} | ||
|
||
final String finalCurrentDocs = currentDocs; | ||
StructureShape.Builder parentBuilder = parent.toBuilder(); | ||
parentBuilder.removeMember(memberName); | ||
parentBuilder.addMember(memberName, target.getId(), (memberBuilder) -> { | ||
memberBuilder | ||
.addTraits(member.getAllTraits().values()) | ||
.addTrait(new DocumentationTrait(finalCurrentDocs + | ||
"For using values that are not seekable (io.Seeker) see, " + | ||
"https://aws.github.io/aws-sdk-go-v2/docs/sdk-utilisties/s3/#unseekable-streaming-input")); | ||
}); | ||
|
||
|
||
builder.addShape(parentBuilder.build()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.