-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate and apply ApplyMd5BodyChecksumMiddleware (#493)
* feat: add md5 body checksum middleware * feat: add ApplyMd5BodyChecksum plugin
- Loading branch information
Showing
22 changed files
with
421 additions
and
259 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
84 changes: 84 additions & 0 deletions
84
...gen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddMd5HashDependency.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,84 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import software.amazon.smithy.aws.traits.ServiceTrait; | ||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.typescript.codegen.LanguageTarget; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
import software.amazon.smithy.utils.SetUtils; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Adds Md5Hash if needed. | ||
*/ | ||
public class AddMd5HashDependency implements TypeScriptIntegration { | ||
private static final Set<String> SERVICE_IDS = SetUtils.of("S3", "SQS"); | ||
|
||
@Override | ||
public void addConfigInterfaceFields( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer | ||
) { | ||
if (!needsMd5Dep(settings.getService(model))) { | ||
return; | ||
} | ||
|
||
writer.addImport("HashConstructor", "__HashConstructor", "@aws-sdk/types"); | ||
writer.writeDocs("A constructor for a class implementing the @aws-sdk/types.Hash interface \n" | ||
+ "that computes MD5 hashes"); | ||
writer.write("md5?: __HashConstructor;\n"); | ||
} | ||
|
||
@Override | ||
public void addRuntimeConfigValues( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer, | ||
LanguageTarget target | ||
) { | ||
if (!needsMd5Dep(settings.getService(model))) { | ||
return; | ||
} | ||
|
||
switch (target) { | ||
case NODE: | ||
writer.addImport("HashConstructor", "__HashConstructor", "@aws-sdk/types"); | ||
writer.write("md5: Hash.bind(null, \"md5\"),"); | ||
break; | ||
case BROWSER: | ||
writer.addDependency(AwsDependency.MD5_BROWSER); | ||
writer.addImport("Md5", "Md5", AwsDependency.MD5_BROWSER.packageName); | ||
writer.write("md5: Md5,"); | ||
break; | ||
default: | ||
// do nothing | ||
} | ||
} | ||
|
||
private static boolean needsMd5Dep(ServiceShape service) { | ||
String serviceId = service.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse(""); | ||
return SERVICE_IDS.contains(serviceId); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...rc/main/java/software/amazon/smithy/aws/typescript/codegen/AddStreamHasherDependency.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,86 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import software.amazon.smithy.aws.traits.ServiceTrait; | ||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.typescript.codegen.LanguageTarget; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
|
||
/** | ||
* Adds StreamHasher if needed. | ||
*/ | ||
public class AddStreamHasherDependency implements TypeScriptIntegration { | ||
|
||
@Override | ||
public void addConfigInterfaceFields( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer | ||
) { | ||
if (!needsStreamHasher(settings.getService(model))) { | ||
return; | ||
} | ||
|
||
writer.addImport("Readable", "Readable", "stream"); | ||
writer.addImport("StreamHasher", "__StreamHasher", "@aws-sdk/types"); | ||
writer.writeDocs("A function that, given a hash constructor and a stream, calculates the \n" | ||
+ "hash of the streamed value"); | ||
writer.write("streamHasher?: __StreamHasher<Readable|Blob>;\n"); | ||
} | ||
|
||
@Override | ||
public void addRuntimeConfigValues( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer, | ||
LanguageTarget target | ||
) { | ||
if (!needsStreamHasher(settings.getService(model))) { | ||
return; | ||
} | ||
|
||
switch (target) { | ||
case NODE: | ||
writer.addDependency(AwsDependency.STREAM_HASHER_NODE); | ||
writer.addImport("calculateSha256", "streamHasher", AwsDependency.STREAM_HASHER_NODE.packageName); | ||
writer.write("streamHasher,"); | ||
break; | ||
case BROWSER: | ||
writer.addDependency(AwsDependency.STREAM_HASHER_BROWSER); | ||
writer.addImport("calculateSha256", "streamHasher", AwsDependency.STREAM_HASHER_BROWSER.packageName); | ||
writer.write("streamHasher,"); | ||
break; | ||
default: | ||
// do nothing | ||
} | ||
} | ||
|
||
private static boolean needsStreamHasher(ServiceShape service) { | ||
String serviceId = service.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse(""); | ||
if (serviceId.equals("S3")) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.