From 590af6b7572bf315776edf5f6e1b3cb87708d564 Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 2 Jan 2024 13:43:01 -0500 Subject: [PATCH] feat: add credential scope field (#1122) --- .changeset/happy-adults-complain.md | 6 ++++++ .../src/adaptors/createConfigValueProvider.spec.ts | 11 +++++++++++ .../src/adaptors/createConfigValueProvider.ts | 7 +++++++ packages/types/src/identity/awsCredentialIdentity.ts | 5 +++++ 4 files changed, 29 insertions(+) create mode 100644 .changeset/happy-adults-complain.md diff --git a/.changeset/happy-adults-complain.md b/.changeset/happy-adults-complain.md new file mode 100644 index 00000000000..9b33dd5d3fc --- /dev/null +++ b/.changeset/happy-adults-complain.md @@ -0,0 +1,6 @@ +--- +"@smithy/middleware-endpoint": minor +"@smithy/types": minor +--- + +support credential scope diff --git a/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts b/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts index ee3e1f08e17..dbc54f35106 100644 --- a/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts +++ b/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.spec.ts @@ -20,6 +20,17 @@ describe(createConfigValueProvider.name, () => { expect(await createConfigValueProvider("x", "a", config)()).toEqual(1); }); + it("uses a special lookup for CredentialScope", async () => { + const config = { + credentials: async () => { + return { + credentialScope: "cred-scope", + }; + }, + }; + expect(await createConfigValueProvider("credentialScope", "CredentialScope", config)()).toEqual("cred-scope"); + }); + it("should normalize endpoint objects into URLs", async () => { const sampleUrl = "https://aws.amazon.com/"; const config = { diff --git a/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts b/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts index 8088791acab..f376a52587c 100644 --- a/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts +++ b/packages/middleware-endpoint/src/adaptors/createConfigValueProvider.ts @@ -24,6 +24,13 @@ export const createConfigValueProvider = } return configValue; }; + if (configKey === "credentialScope" || canonicalEndpointParamKey === "CredentialScope") { + return async () => { + const credentials = typeof config.credentials === "function" ? await config.credentials() : config.credentials; + const configValue: string = credentials?.credentialScope ?? credentials?.CredentialScope; + return configValue; + }; + } if (configKey === "endpoint" || canonicalEndpointParamKey === "endpoint") { return async () => { const endpoint = await configProvider(); diff --git a/packages/types/src/identity/awsCredentialIdentity.ts b/packages/types/src/identity/awsCredentialIdentity.ts index 035d61012d9..21a28ef13be 100644 --- a/packages/types/src/identity/awsCredentialIdentity.ts +++ b/packages/types/src/identity/awsCredentialIdentity.ts @@ -19,6 +19,11 @@ export interface AwsCredentialIdentity extends Identity { * present for temporary credentials. */ readonly sessionToken?: string; + + /** + * AWS credential scope for this set of credentials. + */ + readonly credentialScope?: string; } /**