Skip to content

Commit 9f04714

Browse files
authored
fix(client-s3): revert MRAP customizations (#2759)
The @aws-sdk/[email protected] released with MRAP customization that instroduces `aws-crt` dependency. The dependency takes up too much disk space that blocks Lambda users deploying S3 client with certain deployers. Rollback the change to unblock these users. The MRAP users that's not affected by the dependency size can ping to the older version `@aws-sdk/[email protected]`
1 parent f1bf6fa commit 9f04714

15 files changed

+72
-106
lines changed

packages/signature-v4/src/SignatureV4.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ import { createScope, getSigningKey } from "./credentialDerivation";
3737
import { getCanonicalHeaders } from "./getCanonicalHeaders";
3838
import { getCanonicalQuery } from "./getCanonicalQuery";
3939
import { getPayloadHash } from "./getPayloadHash";
40-
import { hasHeader } from "./headerUtil";
40+
import { hasHeader } from "./hasHeader";
4141
import { moveHeadersToQuery } from "./moveHeadersToQuery";
42-
import { normalizeCredentialsProvider, normalizeRegionProvider } from "./normalizeProvider";
4342
import { prepareRequest } from "./prepareRequest";
4443
import { iso8601 } from "./utilDate";
4544

@@ -318,3 +317,21 @@ const formatDate = (now: DateInput): { longDate: string; shortDate: string } =>
318317
};
319318

320319
const getCanonicalHeaderList = (headers: object): string => Object.keys(headers).sort().join(";");
320+
321+
const normalizeRegionProvider = (region: string | Provider<string>): Provider<string> => {
322+
if (typeof region === "string") {
323+
const promisified = Promise.resolve(region);
324+
return () => promisified;
325+
} else {
326+
return region;
327+
}
328+
};
329+
330+
const normalizeCredentialsProvider = (credentials: Credentials | Provider<Credentials>): Provider<Credentials> => {
331+
if (typeof credentials === "object") {
332+
const promisified = Promise.resolve(credentials);
333+
return () => promisified;
334+
} else {
335+
return credentials;
336+
}
337+
};

packages/signature-v4/src/cloneRequest.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import { HttpRequest, QueryParameterBag } from "@aws-sdk/types";
33
/**
44
* @internal
55
*/
6-
export const cloneRequest = ({ headers, query, ...rest }: HttpRequest): HttpRequest => ({
7-
...rest,
8-
headers: { ...headers },
9-
query: query ? cloneQuery(query) : undefined,
10-
});
6+
export function cloneRequest({ headers, query, ...rest }: HttpRequest): HttpRequest {
7+
return {
8+
...rest,
9+
headers: { ...headers },
10+
query: query ? cloneQuery(query) : undefined,
11+
};
12+
}
1113

12-
export const cloneQuery = (query: QueryParameterBag): QueryParameterBag =>
13-
Object.keys(query).reduce((carry: QueryParameterBag, paramName: string) => {
14+
function cloneQuery(query: QueryParameterBag): QueryParameterBag {
15+
return Object.keys(query).reduce((carry: QueryParameterBag, paramName: string) => {
1416
const param = query[paramName];
1517
return {
1618
...carry,
1719
[paramName]: Array.isArray(param) ? [...param] : param,
1820
};
1921
}, {});
22+
}

packages/signature-v4/src/constants.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
55
export const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
66
export const SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
77
export const TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
8-
export const REGION_SET_PARAM = "X-Amz-Region-Set";
98

109
export const AUTH_HEADER = "authorization";
1110
export const AMZ_DATE_HEADER = AMZ_DATE_QUERY_PARAM.toLowerCase();
@@ -41,7 +40,6 @@ export const SEC_HEADER_PATTERN = /^sec-/;
4140
export const UNSIGNABLE_PATTERNS = [/^proxy-/i, /^sec-/i];
4241

4342
export const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
44-
export const ALGORITHM_IDENTIFIER_V4A = "AWS4-ECDSA-P256-SHA256";
4543

4644
export const EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
4745

packages/signature-v4/src/credentialDerivation.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ const cacheQueue: Array<string> = [];
1313
* @param region The AWS region in which the service resides.
1414
* @param service The service to which the signed request is being sent.
1515
*/
16-
export const createScope = (shortDate: string, region: string, service: string): string =>
17-
`${shortDate}/${region}/${service}/${KEY_TYPE_IDENTIFIER}`;
16+
export function createScope(shortDate: string, region: string, service: string): string {
17+
return `${shortDate}/${region}/${service}/${KEY_TYPE_IDENTIFIER}`;
18+
}
1819

1920
/**
2021
* Derive a signing key from its composite parts
@@ -56,15 +57,15 @@ export const getSigningKey = async (
5657
/**
5758
* @internal
5859
*/
59-
export const clearCredentialCache = (): void => {
60+
export function clearCredentialCache(): void {
6061
cacheQueue.length = 0;
6162
Object.keys(signingKeyCache).forEach((cacheKey) => {
6263
delete signingKeyCache[cacheKey];
6364
});
64-
};
65+
}
6566

66-
const hmac = (ctor: HashConstructor, secret: SourceData, data: SourceData): Promise<Uint8Array> => {
67+
function hmac(ctor: HashConstructor, secret: SourceData, data: SourceData): Promise<Uint8Array> {
6768
const hash = new ctor(secret);
6869
hash.update(data);
6970
return hash.digest();
70-
};
71+
}

packages/signature-v4/src/getCanonicalHeaders.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { HeaderBag, HttpRequest } from "@aws-sdk/types";
33
import { ALWAYS_UNSIGNABLE_HEADERS, PROXY_HEADER_PATTERN, SEC_HEADER_PATTERN } from "./constants";
44

55
/**
6-
* @private
6+
* @internal
77
*/
8-
export const getCanonicalHeaders = (
8+
export function getCanonicalHeaders(
99
{ headers }: HttpRequest,
1010
unsignableHeaders?: Set<string>,
1111
signableHeaders?: Set<string>
12-
): HeaderBag => {
12+
): HeaderBag {
1313
const canonical: HeaderBag = {};
1414
for (const headerName of Object.keys(headers).sort()) {
1515
const canonicalHeaderName = headerName.toLowerCase();
@@ -28,4 +28,4 @@ export const getCanonicalHeaders = (
2828
}
2929

3030
return canonical;
31-
};
31+
}

packages/signature-v4/src/getCanonicalQuery.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { escapeUri } from "@aws-sdk/util-uri-escape";
44
import { SIGNATURE_HEADER } from "./constants";
55

66
/**
7-
* @private
7+
* @internal
88
*/
9-
export const getCanonicalQuery = ({ query = {} }: HttpRequest): string => {
9+
export function getCanonicalQuery({ query = {} }: HttpRequest): string {
1010
const keys: Array<string> = [];
1111
const serialized: { [key: string]: string } = {};
1212
for (const key of Object.keys(query).sort()) {
@@ -34,4 +34,4 @@ export const getCanonicalQuery = ({ query = {} }: HttpRequest): string => {
3434
.map((key) => serialized[key])
3535
.filter((serialized) => serialized) // omit any falsy values
3636
.join("&");
37-
};
37+
}

packages/signature-v4/src/getPayloadHash.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { toHex } from "@aws-sdk/util-hex-encoding";
55
import { SHA256_HEADER, UNSIGNED_PAYLOAD } from "./constants";
66

77
/**
8-
* @private
8+
* @internal
99
*/
10-
export const getPayloadHash = async (
10+
export async function getPayloadHash(
1111
{ headers, body }: HttpRequest,
1212
hashConstructor: HashConstructor
13-
): Promise<string> => {
13+
): Promise<string> {
1414
for (const headerName of Object.keys(headers)) {
1515
if (headerName.toLowerCase() === SHA256_HEADER) {
1616
return headers[headerName];
@@ -29,4 +29,4 @@ export const getPayloadHash = async (
2929
// body is unsignable. Attempt to send the request with an unsigned payload,
3030
// which may or may not be accepted by the service.
3131
return UNSIGNED_PAYLOAD;
32-
};
32+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { HeaderBag } from "@aws-sdk/types";
2+
3+
export function hasHeader(soughtHeader: string, headers: HeaderBag): boolean {
4+
soughtHeader = soughtHeader.toLowerCase();
5+
for (const headerName of Object.keys(headers)) {
6+
if (soughtHeader === headerName.toLowerCase()) {
7+
return true;
8+
}
9+
}
10+
11+
return false;
12+
}

packages/signature-v4/src/headerUtil.ts

-34
This file was deleted.

packages/signature-v4/src/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
export * from "./credentialDerivation";
2-
export { getCanonicalHeaders } from "./getCanonicalHeaders";
3-
export { getCanonicalQuery } from "./getCanonicalQuery";
4-
export { getPayloadHash } from "./getPayloadHash";
5-
export { moveHeadersToQuery } from "./moveHeadersToQuery";
6-
export { prepareRequest } from "./prepareRequest";
7-
export { normalizeCredentialsProvider, normalizeRegionProvider } from "./normalizeProvider";
82
export * from "./SignatureV4";

packages/signature-v4/src/moveHeadersToQuery.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { HttpRequest, QueryParameterBag } from "@aws-sdk/types";
33
import { cloneRequest } from "./cloneRequest";
44

55
/**
6-
* @private
6+
* @internal
77
*/
8-
export const moveHeadersToQuery = (
8+
export function moveHeadersToQuery(
99
request: HttpRequest,
1010
options: { unhoistableHeaders?: Set<string> } = {}
11-
): HttpRequest & { query: QueryParameterBag } => {
11+
): HttpRequest & { query: QueryParameterBag } {
1212
const { headers, query = {} as QueryParameterBag } =
1313
typeof (request as any).clone === "function" ? (request as any).clone() : cloneRequest(request);
1414
for (const name of Object.keys(headers)) {
@@ -24,4 +24,4 @@ export const moveHeadersToQuery = (
2424
headers,
2525
query,
2626
};
27-
};
27+
}

packages/signature-v4/src/normalizeProvider.ts

-27
This file was deleted.

packages/signature-v4/src/prepareRequest.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { cloneRequest } from "./cloneRequest";
44
import { GENERATED_HEADERS } from "./constants";
55

66
/**
7-
* @private
7+
* @internal
88
*/
9-
export const prepareRequest = (request: HttpRequest): HttpRequest => {
9+
export function prepareRequest(request: HttpRequest): HttpRequest {
1010
// Create a clone of the request object that does not clone the body
1111
request = typeof (request as any).clone === "function" ? (request as any).clone() : cloneRequest(request);
1212

@@ -17,4 +17,4 @@ export const prepareRequest = (request: HttpRequest): HttpRequest => {
1717
}
1818

1919
return request;
20-
};
20+
}

packages/signature-v4/src/utilDate.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
export const iso8601 = (time: number | string | Date): string =>
2-
toDate(time)
1+
export function iso8601(time: number | string | Date): string {
2+
return toDate(time)
33
.toISOString()
44
.replace(/\.\d{3}Z$/, "Z");
5+
}
56

6-
export const toDate = (time: number | string | Date): Date => {
7+
export function toDate(time: number | string | Date): Date {
78
if (typeof time === "number") {
89
return new Date(time * 1000);
910
}
@@ -16,4 +17,4 @@ export const toDate = (time: number | string | Date): Date => {
1617
}
1718

1819
return time;
19-
};
20+
}

packages/signature-v4/tsconfig.cjs.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"declarationDir": "./dist/types",
55
"rootDir": "./src",
66
"outDir": "./dist/cjs",
7+
"noUnusedLocals": true,
78
"baseUrl": "."
89
},
910
"extends": "../../tsconfig.cjs.json",

0 commit comments

Comments
 (0)