Skip to content

Commit

Permalink
feat(client-dynamodb): Generate account endpoint for DynamoDB request…
Browse files Browse the repository at this point in the history
…s when the account ID is available
  • Loading branch information
awstools committed Sep 20, 2024
1 parent 118987c commit a39132c
Show file tree
Hide file tree
Showing 7 changed files with 1,293 additions and 69 deletions.
6 changes: 6 additions & 0 deletions clients/client-dynamodb/src/DynamoDBClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// smithy-typescript generated code
import { AccountIdEndpointMode } from "@aws-sdk/core/account-id-endpoint";
import {
EndpointDiscoveryInputConfig,
EndpointDiscoveryResolvedConfig,
Expand Down Expand Up @@ -402,6 +403,11 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
*/
region?: string | __Provider<string>;

/**
* Defines if the AWS AccountId will be used for endpoint routing.
*/
accountIdEndpointMode?: AccountIdEndpointMode | __Provider<AccountIdEndpointMode>;

/**
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
* @internal
Expand Down
6 changes: 6 additions & 0 deletions clients/client-dynamodb/src/endpoint/EndpointParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface ClientInputEndpointParameters {
useDualstackEndpoint?: boolean | Provider<boolean>;
useFipsEndpoint?: boolean | Provider<boolean>;
endpoint?: string | Provider<string> | Endpoint | Provider<Endpoint> | EndpointV2 | Provider<EndpointV2>;
accountId?: string | Provider<string>;
accountIdEndpointMode?: string | Provider<string>;
}

export type ClientResolvedEndpointParameters = ClientInputEndpointParameters & {
Expand All @@ -28,14 +30,18 @@ export const resolveClientEndpointParameters = <T>(

export const commonParams = {
UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
AccountId: { type: "builtInParams", name: "accountId" },
Endpoint: { type: "builtInParams", name: "endpoint" },
Region: { type: "builtInParams", name: "region" },
UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
AccountIdEndpointMode: { type: "builtInParams", name: "accountIdEndpointMode" },
} as const;

export interface EndpointParameters extends __EndpointParameters {
Region?: string;
UseDualStack?: boolean;
UseFIPS?: boolean;
Endpoint?: string;
AccountId?: string;
AccountIdEndpointMode?: string;
}
2 changes: 1 addition & 1 deletion clients/client-dynamodb/src/endpoint/endpointResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ruleSet } from "./ruleset";

const cache = new EndpointCache({
size: 50,
params: ["Endpoint", "Region", "UseDualStack", "UseFIPS"],
params: ["AccountId", "AccountIdEndpointMode", "Endpoint", "Region", "UseDualStack", "UseFIPS"],
});

export const defaultEndpointResolver = (
Expand Down
67 changes: 41 additions & 26 deletions clients/client-dynamodb/src/endpoint/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,46 @@ import { RuleSetObject } from "@smithy/types";
or see "smithy.rules#endpointRuleSet"
in codegen/sdk-codegen/aws-models/dynamodb.json */

const w="required",
x="fn",
y="argv",
z="ref";
const a=true,
const H="required",
I="type",
J="fn",
K="argv",
L="ref",
M="url",
N="properties",
O="headers";
const a=false,
b="isSet",
c="booleanEquals",
d="error",
e="endpoint",
f="tree",
g="PartitionResult",
h="getAttr",
i="stringEquals",
j={[w]:false,"type":"String"},
k={[w]:true,"default":false,"type":"Boolean"},
l={[z]:"Endpoint"},
m={[x]:c,[y]:[{[z]:"UseFIPS"},true]},
n={[x]:c,[y]:[{[z]:"UseDualStack"},true]},
o={},
p={[z]:"Region"},
q={[x]:h,[y]:[{[z]:g},"supportsFIPS"]},
r={[z]:g},
s={[x]:c,[y]:[true,{[x]:h,[y]:[r,"supportsDualStack"]}]},
t=[m],
u=[n],
v=[p];
const _data={version:"1.0",parameters:{Region:j,UseDualStack:k,UseFIPS:k,Endpoint:j},rules:[{conditions:[{[x]:b,[y]:[l]}],rules:[{conditions:t,error:"Invalid Configuration: FIPS and custom endpoint are not supported",type:d},{conditions:u,error:"Invalid Configuration: Dualstack and custom endpoint are not supported",type:d},{endpoint:{url:l,properties:o,headers:o},type:e}],type:f},{conditions:[{[x]:b,[y]:v}],rules:[{conditions:[{[x]:"aws.partition",[y]:v,assign:g}],rules:[{conditions:[m,n],rules:[{conditions:[{[x]:c,[y]:[a,q]},s],rules:[{endpoint:{url:"https://dynamodb-fips.{Region}.{PartitionResult#dualStackDnsSuffix}",properties:o,headers:o},type:e}],type:f},{error:"FIPS and DualStack are enabled, but this partition does not support one or both",type:d}],type:f},{conditions:t,rules:[{conditions:[{[x]:c,[y]:[q,a]}],rules:[{conditions:[{[x]:i,[y]:[{[x]:h,[y]:[r,"name"]},"aws-us-gov"]}],endpoint:{url:"https://dynamodb.{Region}.amazonaws.com",properties:o,headers:o},type:e},{endpoint:{url:"https://dynamodb-fips.{Region}.{PartitionResult#dnsSuffix}",properties:o,headers:o},type:e}],type:f},{error:"FIPS is enabled but this partition does not support FIPS",type:d}],type:f},{conditions:u,rules:[{conditions:[s],rules:[{endpoint:{url:"https://dynamodb.{Region}.{PartitionResult#dualStackDnsSuffix}",properties:o,headers:o},type:e}],type:f},{error:"DualStack is enabled but this partition does not support DualStack",type:d}],type:f},{conditions:[{[x]:i,[y]:[p,"local"]}],endpoint:{url:"http://localhost:8000",properties:{authSchemes:[{name:"sigv4",signingName:"dynamodb",signingRegion:"us-east-1"}]},headers:o},type:e},{endpoint:{url:"https://dynamodb.{Region}.{PartitionResult#dnsSuffix}",properties:o,headers:o},type:e}],type:f}],type:f},{error:"Invalid Configuration: Missing Region",type:d}]};
c="error",
d="endpoint",
e="tree",
f="PartitionResult",
g="stringEquals",
h="not",
i={[H]:false,[I]:"String"},
j={[H]:true,"default":false,[I]:"Boolean"},
k={[J]:"booleanEquals",[K]:[{[L]:"UseFIPS"},true]},
l={[J]:"booleanEquals",[K]:[{[L]:"UseDualStack"},true]},
m={},
n={[L]:"Region"},
o={[J]:b,[K]:[{[L]:"AccountIdEndpointMode"}]},
p={[L]:"AccountIdEndpointMode"},
q={[J]:b,[K]:[{[L]:"AccountId"}]},
r={[L]:"AccountId"},
s={[J]:g,[K]:[{[J]:"getAttr",[K]:[{[L]:f},"name"]},"aws"]},
t={[J]:"getAttr",[K]:[{[L]:f},"name"]},
u={[J]:h,[K]:[k]},
v={[J]:h,[K]:[l]},
w={[J]:"booleanEquals",[K]:[{[J]:"getAttr",[K]:[{[L]:f},"supportsFIPS"]},true]},
x={[J]:"booleanEquals",[K]:[{[J]:"getAttr",[K]:[{[L]:f},"supportsDualStack"]},true]},
y={[M]:"https://dynamodb-fips.{Region}.{PartitionResult#dualStackDnsSuffix}",[N]:{},[O]:{}},
z={"conditions":[o,{[J]:g,[K]:[p,"disabled"]}],[d]:{[M]:"https://dynamodb.{Region}.{PartitionResult#dnsSuffix}",[N]:{},[O]:{}},[I]:d},
A={[d]:{[M]:"https://dynamodb.{Region}.{PartitionResult#dnsSuffix}",[N]:{},[O]:{}},[I]:d},
B={[M]:"https://dynamodb-fips.{Region}.{PartitionResult#dnsSuffix}",[N]:{},[O]:{}},
C={[M]:"https://dynamodb.{Region}.{PartitionResult#dualStackDnsSuffix}",[N]:{},[O]:{}},
D=[k],
E=[l],
F=[n],
G=[o,{[J]:g,[K]:[p,"disabled"]}];
const _data={version:"1.0",parameters:{Region:i,UseDualStack:j,UseFIPS:j,Endpoint:i,AccountId:i,AccountIdEndpointMode:i},rules:[{conditions:[{[J]:b,[K]:[{[L]:"Endpoint"}]}],rules:[{conditions:D,error:"Invalid Configuration: FIPS and custom endpoint are not supported",[I]:c},{conditions:E,error:"Invalid Configuration: Dualstack and custom endpoint are not supported",[I]:c},{endpoint:{[M]:"{Endpoint}",[N]:m,[O]:m},[I]:d}],[I]:e},{conditions:[{[J]:b,[K]:F}],rules:[{conditions:[{[J]:"aws.partition",[K]:F,assign:f}],rules:[{conditions:[{[J]:g,[K]:[n,"local"]}],rules:[{conditions:D,error:"Invalid Configuration: FIPS and local endpoint are not supported",[I]:c},{conditions:E,error:"Invalid Configuration: Dualstack and local endpoint are not supported",[I]:c},{endpoint:{[M]:"http://localhost:8000",[N]:{authSchemes:[{name:"sigv4",signingName:"dynamodb",signingRegion:"us-east-1"}]},[O]:m},[I]:d}],[I]:e},{conditions:[o,{[J]:g,[K]:[p,"required"]},{[J]:h,[K]:[q]}],error:"AccountIdEndpointMode is required but no AccountID was provided or able to be loaded.",[I]:c},{conditions:[q,s,u,v,{[J]:h,[K]:[{[J]:"isValidHostLabel",[K]:[r,a]}]}],error:"Credentials-sourced account ID parameter is invalid",[I]:c},{conditions:[k,l],rules:[{conditions:[w,x],rules:[{conditions:G,endpoint:y,[I]:d},{endpoint:y,[I]:d}],[I]:e},{error:"FIPS and DualStack are enabled, but this partition does not support one or both",[I]:c}],[I]:e},{conditions:D,rules:[{conditions:[w],rules:[{conditions:[{[J]:g,[K]:[t,"aws-us-gov"]}],rules:[z,A],[I]:e},{conditions:G,endpoint:B,[I]:d},{endpoint:B,[I]:d}],[I]:e},{error:"FIPS is enabled but this partition does not support FIPS",[I]:c}],[I]:e},{conditions:E,rules:[{conditions:[x],rules:[{conditions:G,endpoint:C,[I]:d},{endpoint:C,[I]:d}],[I]:e},{error:"DualStack is enabled but this partition does not support DualStack",[I]:c}],[I]:e},z,{conditions:[q,s,u,v],endpoint:{[M]:"https://{AccountId}.ddb.{Region}.{PartitionResult#dnsSuffix}",[N]:m,[O]:m},[I]:d},A],[I]:e}],[I]:e},{error:"Invalid Configuration: Missing Region",[I]:c}]};
export const ruleSet: RuleSetObject = _data;
2 changes: 2 additions & 0 deletions clients/client-dynamodb/src/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import packageInfo from "../package.json"; // eslint-disable-line

import { Sha256 } from "@aws-crypto/sha256-browser";
import { DEFAULT_ACCOUNT_ID_ENDPOINT_MODE } from "@aws-sdk/core/account-id-endpoint";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { DEFAULT_USE_DUALSTACK_ENDPOINT, DEFAULT_USE_FIPS_ENDPOINT } from "@smithy/config-resolver";
import { FetchHttpHandler as RequestHandler, streamCollector } from "@smithy/fetch-http-handler";
Expand All @@ -26,6 +27,7 @@ export const getRuntimeConfig = (config: DynamoDBClientConfig) => {
...config,
runtime: "browser",
defaultsMode,
accountIdEndpointMode: config?.accountIdEndpointMode ?? (() => Promise.resolve(DEFAULT_ACCOUNT_ID_ENDPOINT_MODE)),
bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config?.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
Expand Down
3 changes: 3 additions & 0 deletions clients/client-dynamodb/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import packageInfo from "../package.json"; // eslint-disable-line

import { emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
import { NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS } from "@aws-sdk/core/account-id-endpoint";
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
import { NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS } from "@aws-sdk/middleware-endpoint-discovery";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
Expand Down Expand Up @@ -38,6 +39,8 @@ export const getRuntimeConfig = (config: DynamoDBClientConfig) => {
...config,
runtime: "node",
defaultsMode,
accountIdEndpointMode:
config?.accountIdEndpointMode ?? loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS),
bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider: config?.credentialDefaultProvider ?? credentialDefaultProvider,
defaultUserAgentProvider:
Expand Down
Loading

0 comments on commit a39132c

Please sign in to comment.