Skip to content

Commit 4a40961

Browse files
authored
feat: add support for accountId in configValueProvider (#1252)
* feat: add support for accountId in configValueProvider * chore: add changeset
1 parent ab12d79 commit 4a40961

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.changeset/brown-bags-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/middleware-endpoint": minor
3+
---
4+
5+
add support for accountId in configValueProvider

packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ describe(createConfigValueProvider.name, () => {
3131
expect(await createConfigValueProvider("credentialScope", "CredentialScope", config)()).toEqual("cred-scope");
3232
});
3333

34+
it("uses a special lookup for accountId", async () => {
35+
const config = {
36+
credentials: async () => {
37+
return {
38+
accountId: "123456789012",
39+
};
40+
},
41+
};
42+
expect(await createConfigValueProvider("accountId", "AccountId", config)()).toEqual("123456789012");
43+
});
44+
3445
it("should normalize endpoint objects into URLs", async () => {
3546
const sampleUrl = "https://aws.amazon.com/";
3647
const config = {

packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export const createConfigValueProvider = <Config extends Record<string, unknown>
3131
return configValue;
3232
};
3333
}
34+
35+
if (configKey === "accountId" || canonicalEndpointParamKey === "AccountId") {
36+
return async () => {
37+
const credentials = typeof config.credentials === "function" ? await config.credentials() : config.credentials;
38+
const configValue: string = credentials?.accountId ?? credentials?.AccountId;
39+
return configValue;
40+
};
41+
}
42+
3443
if (configKey === "endpoint" || canonicalEndpointParamKey === "endpoint") {
3544
return async () => {
3645
const endpoint = await configProvider();

0 commit comments

Comments
 (0)