Skip to content

Commit

Permalink
Merge customizations for S3
Browse files Browse the repository at this point in the history
  • Loading branch information
awstools committed Jan 15, 2025
1 parent 9ec4c95 commit 2a78a0b
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/crc64-nvme-crt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/crt-loader": "*",
"@aws-sdk/middleware-flexible-checksums": "*",
"@smithy/types": "^4.0.0",
"@smithy/util-utf8": "^4.0.0",
"tslib": "^2.6.2"
Expand Down
7 changes: 6 additions & 1 deletion packages/crc64-nvme-crt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
// ToDo: set implementation in middleware-flexible-checksums container.
import { crc64NvmeCrtContainer } from "@aws-sdk/middleware-flexible-checksums";

import { CrtCrc64Nvme } from "./CrtCrc64Nvme";

crc64NvmeCrtContainer.CrtCrc64Nvme = CrtCrc64Nvme;

export * from "./CrtCrc64Nvme";
1 change: 1 addition & 0 deletions packages/middleware-flexible-checksums/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export enum ChecksumAlgorithm {
MD5 = "MD5",
CRC32 = "CRC32",
CRC32C = "CRC32C",
CRC64NVME = "CRC64NVME",
SHA1 = "SHA1",
SHA256 = "SHA256",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ChecksumConstructor } from "@smithy/types";

/**
* @public
*
* \@aws-sdk/crc64-nvme-crt will install the constructor in this
* container if it is installed.
*
* This avoids a runtime-require being interpreted statically by bundlers.
*
*/
export const crc64NvmeCrtContainer: {
CrtCrc64Nvme: null | ChecksumConstructor;
} = {
CrtCrc64Nvme: null,
};
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export const flexibleChecksumsMiddleware =
case ChecksumAlgorithm.CRC32C:
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V");
break;
case ChecksumAlgorithm.CRC64NVME:
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W");
break;
case ChecksumAlgorithm.SHA1:
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X");
break;
Expand Down
1 change: 1 addition & 0 deletions packages/middleware-flexible-checksums/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS";
export * from "./NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS";
export * from "./constants";
export * from "./crc64-nvme-crt-container";
export * from "./flexibleChecksumsMiddleware";
export * from "./getFlexibleChecksumsPlugin";
export * from "./resolveFlexibleChecksumsConfig";
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Required for testing CRC64NVME
import "@aws-sdk/crc64-nvme-crt";

import { ChecksumAlgorithm, S3 } from "@aws-sdk/client-s3";
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
import { Readable, Transform } from "stream";
Expand All @@ -24,6 +27,10 @@ describe("middleware-flexible-checksums", () => {
["abc", ChecksumAlgorithm.CRC32C, "Nks/tw=="],
["Hello world", ChecksumAlgorithm.CRC32C, "crUfeA=="],

["", ChecksumAlgorithm.CRC64NVME, "AAAAAAAAAAA="],
["abc", ChecksumAlgorithm.CRC64NVME, "BeXKuz/B+us="],
["Hello world", ChecksumAlgorithm.CRC64NVME, "OOJZ0D8xKts="],

["", ChecksumAlgorithm.SHA1, "2jmj7l5rSw0yVb/vlWAYkK/YBwk="],
["abc", ChecksumAlgorithm.SHA1, "qZk+NkcGgWq6PiVxeFDCbJzQ2J0="],
["Hello world", ChecksumAlgorithm.SHA1, "e1AsOh9IyGCa4hLN+2Od7jlnP14="],
Expand Down Expand Up @@ -209,6 +216,7 @@ describe("middleware-flexible-checksums", () => {
["SHA1", "X"],
["CRC32", "U"],
["CRC32C", "V"],
["CRC64NVME", "W"],
].forEach(([algo, id]) => {
it(`should feature-detect checksum ${algo}=${id}`, async () => {
const client = new S3({ region: "us-west-2", logger });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AwsCrc32c } from "@aws-crypto/crc32c";
import { describe, expect, test as it, vi } from "vitest";

import { ChecksumAlgorithm } from "./constants";
import { crc64NvmeCrtContainer } from "./crc64-nvme-crt-container";
import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction";

Expand All @@ -21,4 +22,19 @@ describe(selectChecksumAlgorithmFunction.name, () => {
])("testing %s", (checksumAlgorithm, output) => {
expect(selectChecksumAlgorithmFunction(checksumAlgorithm, mockConfig as any)).toEqual(output);
});

it("throws an error for unsupported checksum algorithm", () => {
expect(() => selectChecksumAlgorithmFunction("UNSUPPORTED" as any, mockConfig as any)).toThrow();
});

it("throws error if crc64NvmeCrtContainer.CrtCrc64Nvme is not a function", () => {
expect(() => selectChecksumAlgorithmFunction(ChecksumAlgorithm.CRC64NVME, mockConfig as any)).toThrow();
});

it("returns crc64NvmeCrtContainer.CrtCrc64Nvme if available from container", () => {
crc64NvmeCrtContainer.CrtCrc64Nvme = vi.fn();
expect(selectChecksumAlgorithmFunction(ChecksumAlgorithm.CRC64NVME, mockConfig as any)).toEqual(
crc64NvmeCrtContainer.CrtCrc64Nvme
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChecksumConstructor, HashConstructor } from "@smithy/types";

import { PreviouslyResolved } from "./configuration";
import { ChecksumAlgorithm } from "./constants";
import { crc64NvmeCrtContainer } from "./crc64-nvme-crt-container";
import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";

/**
Expand All @@ -19,6 +20,17 @@ export const selectChecksumAlgorithmFunction = (
return getCrc32ChecksumAlgorithmFunction();
case ChecksumAlgorithm.CRC32C:
return AwsCrc32c;
case ChecksumAlgorithm.CRC64NVME:
if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") {
throw new Error(
`Please check whether you have installed the "@aws-sdk/crc64-nvme-crt" package explicitly. \n` +
`You must also register the package by calling [require("@aws-sdk/crc64-nvme-crt");] ` +
`or an ESM equivalent such as [import "@aws-sdk/crc64-nvme-crt";]. \n` +
"For more information please go to " +
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"
);
}
return crc64NvmeCrtContainer.CrtCrc64Nvme;
case ChecksumAlgorithm.SHA1:
return config.sha1;
case ChecksumAlgorithm.SHA256:
Expand Down
2 changes: 2 additions & 0 deletions packages/middleware-flexible-checksums/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ChecksumAlgorithm } from "./constants";
export const CLIENT_SUPPORTED_ALGORITHMS = [
ChecksumAlgorithm.CRC32,
ChecksumAlgorithm.CRC32C,
ChecksumAlgorithm.CRC64NVME,
ChecksumAlgorithm.SHA1,
ChecksumAlgorithm.SHA256,
];
Expand All @@ -18,4 +19,5 @@ export const PRIORITY_ORDER_ALGORITHMS = [
ChecksumAlgorithm.SHA1,
ChecksumAlgorithm.CRC32,
ChecksumAlgorithm.CRC32C,
ChecksumAlgorithm.CRC64NVME,
];
13 changes: 12 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23199,6 +23199,7 @@ __metadata:
resolution: "@aws-sdk/crc64-nvme-crt@workspace:packages/crc64-nvme-crt"
dependencies:
"@aws-sdk/crt-loader": "npm:*"
"@aws-sdk/middleware-flexible-checksums": "npm:*"
"@smithy/types": "npm:^4.0.0"
"@smithy/util-base64": "npm:^4.0.0"
"@smithy/util-utf8": "npm:^4.0.0"
Expand Down Expand Up @@ -24954,7 +24955,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/types@npm:^7.0.0, @babel/types@npm:^7.20.7, @babel/types@npm:^7.25.9, @babel/types@npm:^7.26.0, @babel/types@npm:^7.26.3, @babel/types@npm:^7.3.3":
"@babel/types@npm:^7.0.0, @babel/types@npm:^7.20.7, @babel/types@npm:^7.25.9, @babel/types@npm:^7.26.0, @babel/types@npm:^7.3.3":
version: 7.26.0
resolution: "@babel/types@npm:7.26.0"
dependencies:
"@babel/helper-string-parser": "npm:^7.25.9"
"@babel/helper-validator-identifier": "npm:^7.25.9"
checksum: 10c0/b694f41ad1597127e16024d766c33a641508aad037abd08d0d1f73af753e1119fa03b4a107d04b5f92cc19c095a594660547ae9bead1db2299212d644b0a5cb8
languageName: node
linkType: hard

"@babel/types@npm:^7.26.3":
version: 7.26.3
resolution: "@babel/types@npm:7.26.3"
dependencies:
Expand Down

0 comments on commit 2a78a0b

Please sign in to comment.