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

feat: glacier checksum middleware #789

Merged
merged 8 commits into from
Jan 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clients/client-glacier/GlacierClient.ts
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ import {
Encoder as __Encoder,
HashConstructor as __HashConstructor,
HttpHandlerOptions as __HttpHandlerOptions,
HttpRequest as __HttpRequest,
MetadataBearer as __MetadataBearer,
Provider as __Provider,
StreamCollector as __StreamCollector,
@@ -249,6 +250,14 @@ export interface ClientDefaults
* Fetch related hostname, signing name or signing region with given region.
*/
regionInfoProvider?: RegionInfoProvider;

/**
* Function that returns body checksums.
*/
bodyChecksumGenerator?: (
request: __HttpRequest,
options: { sha256: __HashConstructor; utf8Decoder: __Decoder }
) => Promise<[string, string]>;
}

export type GlacierClientConfig = Partial<
4 changes: 3 additions & 1 deletion clients/client-glacier/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { bodyChecksumGenerator } from "@aws-sdk/body-checksum-browser";
import { invalidFunction } from "@aws-sdk/invalid-dependency";
import { Sha256 } from "@aws-crypto/sha256-browser";
import { FetchHttpHandler } from "@aws-sdk/fetch-http-handler";
@@ -26,5 +27,6 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
runtime: "browser",
signingName: "glacier",
credentialDefaultProvider: invalidFunction("Credential is missing") as any,
regionDefaultProvider: invalidFunction("Region is missing") as any
regionDefaultProvider: invalidFunction("Region is missing") as any,
bodyChecksumGenerator
};
4 changes: 3 additions & 1 deletion clients/client-glacier/runtimeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { bodyChecksumGenerator } from "@aws-sdk/body-checksum-node";
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provider";
import { Hash } from "@aws-sdk/hash-node";
@@ -27,5 +28,6 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
runtime: "node",
signingName: "glacier",
credentialDefaultProvider,
regionDefaultProvider
regionDefaultProvider,
bodyChecksumGenerator
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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 java.util.Set;
import java.util.logging.Logger;
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;

/**
* Adds blobReader dependency if needed.
*/
public class AddBodyChecksumGeneratorDependency implements TypeScriptIntegration {
private static final Set<String> SERVICE_IDS = SetUtils.of("Glacier");

private static final Logger LOGGER = Logger.getLogger(AddBodyChecksumGeneratorDependency.class.getName());

@Override
public void addConfigInterfaceFields(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
TypeScriptWriter writer
) {
if (!needsBodyChecksumGeneratorDep(settings.getService(model))) {
return;
}
writer.addImport("HttpRequest", "__HttpRequest", "@aws-sdk/types");
writer.writeDocs("Function that returns body checksums.");
writer.write("bodyChecksumGenerator?: (request: __HttpRequest, options: { sha256: __HashConstructor; "
+ "utf8Decoder: __Decoder }) => Promise<[string, string]>;\n");
}

@Override
public void addRuntimeConfigValues(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
TypeScriptWriter writer,
LanguageTarget target
) {
if (!needsBodyChecksumGeneratorDep(settings.getService(model))) {
return;
}

switch (target) {
case NODE:
writeNodeConfig(writer);
break;
case BROWSER:
writeBrowserConfig(writer);
break;
default:
LOGGER.info("Unknown JavaScript target: " + target);
}
}

private void writeNodeConfig(TypeScriptWriter writer) {
writer.addDependency(AwsDependency.BODY_CHECKSUM_GENERATOR_NODE);
writer.addImport("bodyChecksumGenerator", "bodyChecksumGenerator",
AwsDependency.BODY_CHECKSUM_GENERATOR_NODE.packageName);
writer.write("bodyChecksumGenerator,");
}

private void writeBrowserConfig(TypeScriptWriter writer) {
writer.addDependency(AwsDependency.BODY_CHECKSUM_GENERATOR_BROWSER);
writer.addImport("bodyChecksumGenerator", "bodyChecksumGenerator",
AwsDependency.BODY_CHECKSUM_GENERATOR_BROWSER.packageName);
writer.write("bodyChecksumGenerator,");
}

private static boolean needsBodyChecksumGeneratorDep(ServiceShape service) {
String serviceId = service.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse("");
return SERVICE_IDS.contains(serviceId);
}
}
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ public enum AwsDependency implements SymbolDependencyContainer {
BODY_CHECKSUM(NORMAL_DEPENDENCY, "@aws-sdk/middleware-apply-body-checksum", "^1.0.0-alpha.1"),
MIDDLEWARE_HOST_HEADER(NORMAL_DEPENDENCY, "@aws-sdk/middleware-host-header", "^1.0.0-alpha.1"),
SQS_MIDDLEWARE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-sqs", "^1.0.0-alpha.0"),
BODY_CHECKSUM_GENERATOR_BROWSER(NORMAL_DEPENDENCY, "@aws-sdk/body-checksum-browser", "^1.0.0-alpha.0"),
BODY_CHECKSUM_GENERATOR_NODE(NORMAL_DEPENDENCY, "@aws-sdk/body-checksum-node", "^1.0.0-alpha.0"),
XML_BUILDER(NORMAL_DEPENDENCY, "@aws-sdk/xml-builder", "^1.0.0-alpha.1"),
XML_PARSER(NORMAL_DEPENDENCY, "pixl-xml", "^1.0.13"),
XML_PARSER_TYPES(DEV_DEPENDENCY, "@types/pixl-xml", "^1.0.1"),
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public void addConfigInterfaceFields(
) {
writer.addImport("RegionInfoProvider", "RegionInfoProvider", TypeScriptDependency.AWS_SDK_TYPES.packageName);
writer.writeDocs("Fetch related hostname, signing name or signing region with given region.");
writer.write("regionInfoProvider?: RegionInfoProvider;");
writer.write("regionInfoProvider?: RegionInfoProvider;\n");
}

@Override
Original file line number Diff line number Diff line change
@@ -6,3 +6,4 @@ software.amazon.smithy.aws.typescript.codegen.AwsServiceIdIntegration
software.amazon.smithy.aws.typescript.codegen.AwsPackageFixturesGeneratorIntegration
software.amazon.smithy.aws.typescript.codegen.AddMd5HashDependency
software.amazon.smithy.aws.typescript.codegen.AddStreamHasherDependency
software.amazon.smithy.aws.typescript.codegen.AddBodyChecksumGeneratorDependency
8 changes: 8 additions & 0 deletions packages/body-checksum-browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules/
/build/
/coverage/
/docs/
*.tsbuildinfo
*.tgz
*.log
package-lock.json
13 changes: 13 additions & 0 deletions packages/body-checksum-browser/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/src/
/coverage/
/docs/
tsconfig.test.json
*.tsbuildinfo

*.spec.js
*.spec.d.ts
*.spec.js.map

*.fixture.js
*.fixture.d.ts
*.fixture.js.map
4 changes: 4 additions & 0 deletions packages/body-checksum-browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
Loading