Skip to content

Commit

Permalink
feat: add credential scope field (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Jan 2, 2024
1 parent cb044e7 commit 590af6b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/happy-adults-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/middleware-endpoint": minor
"@smithy/types": minor
---

support credential scope
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const createConfigValueProvider = <Config extends Record<string, unknown>
}
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();
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/identity/awsCredentialIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 590af6b

Please sign in to comment.