Skip to content

Commit

Permalink
feat: add support for accountId in configValueProvider (#1252)
Browse files Browse the repository at this point in the history
* feat: add support for accountId in configValueProvider

* chore: add changeset
  • Loading branch information
siddsriv authored Jul 24, 2024
1 parent ab12d79 commit 4a40961
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-bags-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/middleware-endpoint": minor
---

add support for accountId in configValueProvider
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ describe(createConfigValueProvider.name, () => {
expect(await createConfigValueProvider("credentialScope", "CredentialScope", config)()).toEqual("cred-scope");
});

it("uses a special lookup for accountId", async () => {
const config = {
credentials: async () => {
return {
accountId: "123456789012",
};
},
};
expect(await createConfigValueProvider("accountId", "AccountId", config)()).toEqual("123456789012");
});

it("should normalize endpoint objects into URLs", async () => {
const sampleUrl = "https://aws.amazon.com/";
const config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export const createConfigValueProvider = <Config extends Record<string, unknown>
return configValue;
};
}

if (configKey === "accountId" || canonicalEndpointParamKey === "AccountId") {
return async () => {
const credentials = typeof config.credentials === "function" ? await config.credentials() : config.credentials;
const configValue: string = credentials?.accountId ?? credentials?.AccountId;
return configValue;
};
}

if (configKey === "endpoint" || canonicalEndpointParamKey === "endpoint") {
return async () => {
const endpoint = await configProvider();
Expand Down

0 comments on commit 4a40961

Please sign in to comment.