-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(middleware-user-agent): update to user agent 2.1 spec
- Loading branch information
Showing
19 changed files
with
220 additions
and
12 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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./emitWarningIfUnsupportedVersion"; | ||
export * from "./setFeature"; |
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,10 @@ | ||
import { AwsHandlerExecutionContext } from "@aws-sdk/types"; | ||
|
||
import { setFeature } from "./setFeature"; | ||
|
||
describe(setFeature.name, () => { | ||
it("creates the context object path if needed", () => { | ||
const context: AwsHandlerExecutionContext = {}; | ||
setFeature(context, "ACCOUNT_ID_ENDPOINT", "O"); | ||
}); | ||
}); |
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,26 @@ | ||
import type { AwsHandlerExecutionContext, AwsSdkFeatures } from "@aws-sdk/types"; | ||
|
||
/** | ||
* @internal | ||
* Indicates to the request context that a given feature is active. | ||
* | ||
* @param context - handler execution context. | ||
* @param feature - readable name of feature. | ||
* @param value - encoding value of feature. This is required because the | ||
* specification asks the SDK not to include a runtime lookup of all | ||
* the feature identifiers. | ||
*/ | ||
export function setFeature<F extends keyof AwsSdkFeatures>( | ||
context: AwsHandlerExecutionContext, | ||
feature: F, | ||
value: AwsSdkFeatures[F] | ||
) { | ||
if (!context.__aws_sdk_context) { | ||
context.__aws_sdk_context = { | ||
features: {}, | ||
}; | ||
} else if (!context.__aws_sdk_context.features) { | ||
context.__aws_sdk_context.features = {}; | ||
} | ||
context.__aws_sdk_context.features![feature] = value; | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/middleware-user-agent/src/encode-features.spec.ts
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,26 @@ | ||
import { encodeFeatures } from "./encode-features"; | ||
|
||
describe(encodeFeatures.name, () => { | ||
it("encodes empty features", () => { | ||
expect(encodeFeatures({})).toEqual(""); | ||
}); | ||
|
||
it("encodes features", () => { | ||
expect( | ||
encodeFeatures({ | ||
A: "A", | ||
z: "z", | ||
} as any) | ||
).toEqual("A,z"); | ||
}); | ||
|
||
it("drops values that would exceed 1024 bytes", () => { | ||
expect( | ||
encodeFeatures({ | ||
A: "A".repeat(512), | ||
B: "B".repeat(511), | ||
z: "z", | ||
} as any) | ||
).toEqual("A".repeat(512) + "," + "B".repeat(511)); | ||
}); | ||
}); |
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,28 @@ | ||
import type { AwsSdkFeatures } from "@aws-sdk/types"; | ||
|
||
const BYTE_LIMIT = 1024; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function encodeFeatures(features: AwsSdkFeatures): string { | ||
let buffer = ""; | ||
|
||
// currently all possible values are 1 byte, | ||
// so string length is used. | ||
|
||
for (const key in features) { | ||
const val = features[key as keyof typeof features]!; | ||
if (buffer.length + val!.length + 1 <= BYTE_LIMIT) { | ||
if (buffer.length) { | ||
buffer += "," + val; | ||
} else { | ||
buffer += val; | ||
} | ||
continue; | ||
} | ||
break; | ||
} | ||
|
||
return buffer; | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @internal | ||
*/ | ||
export type AwsSdkFeatures = Partial<{ | ||
RESOURCE_MODEL: "A"; | ||
WAITER: "B"; | ||
PAGINATOR: "C"; | ||
RETRY_MODE_LEGACY: "D"; | ||
RETRY_MODE_STANDARD: "E"; | ||
RETRY_MODE_ADAPTIVE: "F"; | ||
// S3_TRANSFER: "G"; // not applicable. | ||
// S3_CRYPTO_V1N: "H"; // not applicable. | ||
// S3_CRYPTO_V2: "I"; // not applicable. | ||
S3_EXPRESS_BUCKET: "J"; | ||
S3_ACCESS_GRANTS: "K"; | ||
GZIP_REQUEST_COMPRESSION: "L"; | ||
PROTOCOL_RPC_V2_CBOR: "M"; | ||
ENDPOINT_OVERRIDE: "N"; | ||
ACCOUNT_ID_ENDPOINT: "O"; | ||
ACCOUNT_ID_MODE_PREFERRED: "P"; | ||
ACCOUNT_ID_MODE_DISABLED: "Q"; | ||
ACCOUNT_ID_MODE_REQUIRED: "R"; | ||
SIGV4A_SIGNING: "S"; | ||
RESOLVED_ACCOUNT_ID: "T"; | ||
FLEXIBLE_CHECKSUMS_REQ_CRC32: "U"; | ||
FLEXIBLE_CHECKSUMS_REQ_CRC32C: "V"; | ||
FLEXIBLE_CHECKSUMS_REQ_CRC64: "W"; | ||
FLEXIBLE_CHECKSUMS_REQ_SHA1: "X"; | ||
FLEXIBLE_CHECKSUMS_REQ_SHA256: "Y"; | ||
FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED: "Z"; | ||
FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED: "a"; | ||
FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED: "b"; | ||
FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED: "c"; | ||
DDB_MAPPER: "d"; | ||
CREDENTIALS_CODE: "e"; | ||
// CREDENTIALS_JVM_SYSTEM_PROPERTIES: "f"; // not applicable. | ||
CREDENTIALS_ENV_VARS: "g"; | ||
CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN: "h"; | ||
CREDENTIALS_STS_ASSUME_ROLE: "i"; | ||
CREDENTIALS_STS_ASSUME_ROLE_SAML: "j"; | ||
CREDENTIALS_STS_ASSUME_ROLE_WEB_ID: "k"; | ||
CREDENTIALS_STS_FEDERATION_TOKEN: "l"; | ||
CREDENTIALS_STS_SESSION_TOKEN: "m"; | ||
CREDENTIALS_PROFILE: "n"; | ||
CREDENTIALS_PROFILE_SOURCE_PROFILE: "o"; | ||
CREDENTIALS_PROFILE_NAMED_PROVIDER: "p"; | ||
CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN: "q"; | ||
CREDENTIALS_PROFILE_SSO: "r"; | ||
CREDENTIALS_SSO: "s"; | ||
CREDENTIALS_PROFILE_SSO_LEGACY: "t"; | ||
CREDENTIALS_SSO_LEGACY: "u"; | ||
CREDENTIALS_PROFILE_PROCESS: "v"; | ||
CREDENTIALS_PROCESS: "w"; | ||
CREDENTIALS_BOTO2_CONFIG_FILE: "x"; | ||
CREDENTIALS_AWS_SDK_STORE: "y"; | ||
CREDENTIALS_HTTP: "z"; | ||
CREDENTIALS_IMDS: "0"; | ||
}>; |
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 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 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 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 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./defaultUserAgent"; | ||
export * from "./nodeAppIdConfigOptions"; | ||
export * from "./nodeAppIdConfigOptions"; |