Skip to content

Commit 590af6b

Browse files
authored
feat: add credential scope field (#1122)
1 parent cb044e7 commit 590af6b

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

.changeset/happy-adults-complain.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@smithy/middleware-endpoint": minor
3+
"@smithy/types": minor
4+
---
5+
6+
support credential scope

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ describe(createConfigValueProvider.name, () => {
2020
expect(await createConfigValueProvider("x", "a", config)()).toEqual(1);
2121
});
2222

23+
it("uses a special lookup for CredentialScope", async () => {
24+
const config = {
25+
credentials: async () => {
26+
return {
27+
credentialScope: "cred-scope",
28+
};
29+
},
30+
};
31+
expect(await createConfigValueProvider("credentialScope", "CredentialScope", config)()).toEqual("cred-scope");
32+
});
33+
2334
it("should normalize endpoint objects into URLs", async () => {
2435
const sampleUrl = "https://aws.amazon.com/";
2536
const config = {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export const createConfigValueProvider = <Config extends Record<string, unknown>
2424
}
2525
return configValue;
2626
};
27+
if (configKey === "credentialScope" || canonicalEndpointParamKey === "CredentialScope") {
28+
return async () => {
29+
const credentials = typeof config.credentials === "function" ? await config.credentials() : config.credentials;
30+
const configValue: string = credentials?.credentialScope ?? credentials?.CredentialScope;
31+
return configValue;
32+
};
33+
}
2734
if (configKey === "endpoint" || canonicalEndpointParamKey === "endpoint") {
2835
return async () => {
2936
const endpoint = await configProvider();

packages/types/src/identity/awsCredentialIdentity.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export interface AwsCredentialIdentity extends Identity {
1919
* present for temporary credentials.
2020
*/
2121
readonly sessionToken?: string;
22+
23+
/**
24+
* AWS credential scope for this set of credentials.
25+
*/
26+
readonly credentialScope?: string;
2227
}
2328

2429
/**

0 commit comments

Comments
 (0)