-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(endpoint): endpoints 2.0 existing package changes (#3947)
* feat(endpoint): endpoints 2.0 existing package changes * feat(endpoint): enable middleware stack identification * feat(endpoint): update existing packages for endpoints v2 * feat(endpoint): address PR style comments * feat(endpoint): fixes to types * feat(endpoint): additional fixes from testing * feat(endpoint): s3 presigned post fixes for endpoints 2.0 * feat(endpoint): unit test fixes * feat(endpoint): type fixes * feat(endpoint): types and docs updates * feat(endpoint): s3 bucket name forcePathStyle * feat(endpoint): type fix * feat(endpoint): java code format * feat(endpoint): type fix Co-authored-by: AllanZhengYP <[email protected]>
- Loading branch information
1 parent
f91b252
commit df99fc3
Showing
36 changed files
with
566 additions
and
184 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
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
77 changes: 77 additions & 0 deletions
77
packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.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,77 @@ | ||
import { EndpointParameters, EndpointV2, HandlerExecutionContext } from "@aws-sdk/types"; | ||
|
||
import { EndpointResolvedConfig } from "../resolveEndpointConfig"; | ||
import { EndpointParameterInstructions } from "../types"; | ||
|
||
export type EndpointParameterInstructionsSupplier = Partial<{ | ||
getEndpointParameterInstructions(): EndpointParameterInstructions; | ||
}>; | ||
|
||
/** | ||
* This step in the endpoint resolution process is exposed as a function | ||
* to allow packages such as signers, lib-upload, etc. to get | ||
* the V2 Endpoint associated to an instance of some api operation command | ||
* without needing to send it or resolve its middleware stack. | ||
* | ||
* @private | ||
* @param commandInput - the input of the Command in question. | ||
* @param instructionsSupplier - this is typically a Command constructor. A static function supplying the | ||
* endpoint parameter instructions will exist for commands in services | ||
* having an endpoints ruleset trait. | ||
* @param clientConfig - config of the service client. | ||
* @param context - optional context. | ||
*/ | ||
export const getEndpointFromInstructions = async < | ||
T extends EndpointParameters, | ||
CommandInput extends Record<string, unknown>, | ||
Config extends Record<string, unknown> | ||
>( | ||
commandInput: CommandInput, | ||
instructionsSupplier: EndpointParameterInstructionsSupplier, | ||
clientConfig: Partial<EndpointResolvedConfig<T>> & Config, | ||
context?: HandlerExecutionContext | ||
): Promise<EndpointV2> => { | ||
const endpointParams: EndpointParameters = {}; | ||
const instructions: EndpointParameterInstructions = | ||
(instructionsSupplier.getEndpointParameterInstructions || (() => null))() || {}; | ||
|
||
if (typeof clientConfig.endpointProvider !== "function") { | ||
throw new Error("config.endpointProvider is not set."); | ||
} | ||
|
||
for (const [name, instruction] of Object.entries(instructions)) { | ||
switch (instruction.type) { | ||
case "staticContextParams": | ||
endpointParams[name] = instruction.value; | ||
break; | ||
case "contextParams": | ||
endpointParams[name] = commandInput[instruction.name] as string | boolean; | ||
break; | ||
case "clientContextParams": | ||
case "builtInParams": | ||
endpointParams[name] = await createConfigProvider<Config>(instruction.name, clientConfig)(); | ||
break; | ||
default: | ||
throw new Error("Unrecognized endpoint parameter instruction: " + JSON.stringify(instruction)); | ||
} | ||
} | ||
|
||
const endpoint: EndpointV2 = clientConfig.endpointProvider!(endpointParams as T, context); | ||
|
||
return endpoint; | ||
}; | ||
|
||
/** | ||
* Normalize some key of the client config to an async provider. | ||
* @private | ||
*/ | ||
const createConfigProvider = <Config extends Record<string, unknown>>(configKey: string, config: Config) => { | ||
const configProvider = async () => { | ||
const configValue: unknown = config[configKey]; | ||
if (typeof configValue === "function") { | ||
return configValue(); | ||
} | ||
return configValue; | ||
}; | ||
return configProvider; | ||
}; |
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,2 @@ | ||
export * from "./getEndpointFromInstructions"; | ||
export * from "./toEndpointV1"; |
Oops, something went wrong.