Skip to content

Commit 883d5ad

Browse files
author
Chase Coalwell
authored
Feat: update and apply S3 middleware (#478)
* feat: migrate s3 middleware * feat: apply validate-bucket-name plugin
1 parent 2fa77b5 commit 883d5ad

File tree

12 files changed

+77
-275
lines changed

12 files changed

+77
-275
lines changed

codegen/config/checkstyle/suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
2020
<suppressions>
2121
<suppress checks="TypeName"
22-
files="/Aws.*\d_\d.java$"/>
22+
files="AwsRestJson1_1.java|AwsRestJson1_0.java"/>
2323
</suppressions>

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ public List<RuntimeClientPlugin> getClientPlugins() {
5656
RuntimeClientPlugin.builder()
5757
.withConventions("@aws-sdk/middleware-sdk-api-gateway", "^0.1.0-preview.5",
5858
"AcceptsHeader", HAS_MIDDLEWARE)
59-
.servicePredicate((m, s) -> s.getId().getName().equals("BackplaneControlService"))
59+
.servicePredicate((m,s) -> s.getId().getName().equals("BackplaneControlService"))
60+
.build(),
61+
RuntimeClientPlugin.builder()
62+
.withConventions("@aws-sdk/middleware-sdk-s3", "^0.1.0-preview.2",
63+
"validateBucketNameMiddleware", HAS_MIDDLEWARE)
64+
.servicePredicate((m,s) -> s.getId().getName().equals("AmazonS3"))
6065
.build()
6166
);
6267
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddProtocols.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class AddProtocols implements TypeScriptIntegration {
2727

2828
@Override
2929
public List<ProtocolGenerator> getProtocolGenerators() {
30-
return ListUtils.of(new AwsRestJson1_0(), new AwsRestJson1_1(),
31-
new AwsJsonRpc1_0(), new AwsJsonRpc1_1());
30+
return ListUtils.of(new AwsRestJson1_0(), new AwsRestJson1_1());
3231
}
3332
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsJsonRpc1_0.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsJsonRpc1_1.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestJson1_0.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
public final class AwsRestJson1_0 extends RestJsonProtocolGenerator {
2626

2727
@Override
28-
protected String getDocumentContentType() {
29-
return "application/x-amz-json-1.0";
28+
public String getName() {
29+
return "aws.rest-json-1.0";
3030
}
3131

3232
@Override
33-
public String getName() {
34-
return "aws.rest-json-1.0";
33+
protected String getDocumentContentType() {
34+
return "application/x-amz-json-1.0";
3535
}
3636
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestJson1_1.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
public final class AwsRestJson1_1 extends RestJsonProtocolGenerator {
2626

2727
@Override
28-
protected String getDocumentContentType() {
29-
return "application/x-amz-json-1.1";
28+
public String getName() {
29+
return "aws.rest-json-1.1";
3030
}
3131

3232
@Override
33-
public String getName() {
34-
return "aws.rest-json-1.1";
33+
protected String getDocumentContentType() {
34+
return "application/x-amz-json-1.1";
3535
}
3636
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonProtocolUtils.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java

Lines changed: 0 additions & 118 deletions
This file was deleted.

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* @see JsonShapeSerVisitor
4545
* @see JsonShapeDeserVisitor
4646
* @see JsonMemberSerVisitor
47-
* @see JsonMemberDeserVisitor
47+
* @see DocumentMemberDeserVisitor
4848
* @see <a href="https://awslabs.github.io/smithy/spec/http.html">Smithy HTTP protocol bindings.</a>
4949
*/
5050
abstract class RestJsonProtocolGenerator extends HttpBindingProtocolGenerator {
@@ -75,7 +75,21 @@ private void generateDocumentShapeSerde(GenerationContext context, Set<Shape> sh
7575
@Override
7676
public void generateSharedComponents(GenerationContext context) {
7777
super.generateSharedComponents(context);
78-
JsonProtocolUtils.generateParseBody(context);
78+
TypeScriptWriter writer = context.getWriter();
79+
80+
// Include a JSON body parser used to deserialize documents from HTTP responses.
81+
writer.addImport("SerdeContext", "SerdeContext", "@aws-sdk/types");
82+
writer.openBlock("const parseBody = (streamBody: any, context: SerdeContext): any => {", "};", () -> {
83+
writer.openBlock("return context.streamCollector(streamBody).then((body: any) => {", "});", () -> {
84+
writer.write("const encoded = context.utf8Encoder(body);");
85+
writer.openBlock("if (encoded.length) {", "}", () -> {
86+
writer.write("return JSON.parse(encoded);");
87+
});
88+
writer.write("return {};");
89+
});
90+
});
91+
92+
writer.write("");
7993
}
8094

8195
@Override

packages/middleware-sdk-s3/src/validate-bucket-name.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
import { validateBucketName } from "./validate-bucket-name";
2-
import { SerializeHandler } from "@aws-sdk/types";
1+
import { validateBucketNameMiddleware } from "./validate-bucket-name";
32

4-
describe("validateBucketName", () => {
3+
describe("validateBucketNameMiddleware", () => {
54
const mockNextHandler = jest.fn();
6-
const composedHandler: SerializeHandler<any, any> = validateBucketName(
7-
mockNextHandler
8-
);
95

106
beforeEach(() => {
117
jest.clearAllMocks();
128
});
139

1410
it("throws error if Bucket parameter contains '/'", async () => {
11+
const handler = validateBucketNameMiddleware()(mockNextHandler, {} as any);
1512
const bucket = "bucket/part/of/key";
1613
let error;
1714
try {
18-
await composedHandler({
15+
await handler({
1916
input: {
2017
Bucket: bucket
2118
}
@@ -31,12 +28,13 @@ describe("validateBucketName", () => {
3128
});
3229

3330
it("doesn't throw error if Bucket parameter has no '/'", async () => {
31+
const handler = validateBucketNameMiddleware()(mockNextHandler, {} as any);
3432
const args = {
3533
input: {
3634
Bucket: "bucket"
3735
}
3836
};
39-
await composedHandler(args);
37+
await handler(args);
4038
expect(mockNextHandler.mock.calls.length).toBe(1);
4139
expect(mockNextHandler.mock.calls[0][0]).toEqual(args);
4240
});

0 commit comments

Comments
 (0)