Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): wrap credentialDefaultProvider with normalizeProvider #5592

Merged

Conversation

syall
Copy link
Contributor

@syall syall commented Dec 15, 2023

Issue

Issue number, if available, prefixed with "#"

#5591

Description

What does this implement/fix? Explain your changes.

Wrap credentialDefaultProvider with normalizeProvider.

Testing

How was this change tested?

Using the repro from: #5591, and also testing it without a configured credentialDefaultProvider:

const { STSClient, GetCallerIdentityCommand } = require("@aws-sdk/client-sts")

const client = new STSClient({
    "region": "us-west-2"
})
const command = new GetCallerIdentityCommand({})

client.send(command).then((res) => { console.log(res) }).catch((err) => { console.log("ERR:", err) })

Additional context

Add any other context about the PR here.

When passing in defaultProvider like done in the repro, the types are actually NOT compatible.

// defaultProvider matches
defaultProvider: (init?: DefaultProviderInit) => MemoizedProvider<AwsCredentialIdentity>;

// credentialDefaultProvider type on clients
credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider;

If you pass in like in the repro:

let { getDefaultRoleAssumerWithWebIdentity, STSClient, GetCallerIdentityCommand } = require("@aws-sdk/client-sts")
let { defaultProvider } = require("@aws-sdk/credential-provider-node")

// This is actually type `MemoizedProvider<AwsCredentialIdentity>`, not `(input: any) => AwsCredentialIdentityProvider`
const provider = defaultProvider({"roleAssumerWithWebIdentity": getDefaultRoleAssumerWithWebIdentity})
const client = new STSClient({
    "credentialDefaultProvider": provider,
    "region": "us-west-2"
})
const command = new GetCallerIdentityCommand({})

client.send(command).then((res) => { console.log(res) }).catch((err) => { console.log("ERR:", err) })

To make the types work, the code should be like this

let { getDefaultRoleAssumerWithWebIdentity, STSClient, GetCallerIdentityCommand } = require("@aws-sdk/client-sts")
let { defaultProvider } = require("@aws-sdk/credential-provider-node")

// Make it match `(input: any) => AwsCredentialIdentityProvider` by wrapping it in a function
const provider = () =>  defaultProvider({"roleAssumerWithWebIdentity": getDefaultRoleAssumerWithWebIdentity})
const client = new STSClient({
    "credentialDefaultProvider": provider,
    "region": "us-west-2"
})
const command = new GetCallerIdentityCommand({})

client.send(command).then((res) => { console.log(res) }).catch((err) => { console.log("ERR:", err) })

This PR is to ensure existing code still works, but should not be encouraged.

Checklist

  • If you wrote E2E tests, are they resilient to concurrent I/O?
  • If adding new public functions, did you add the @public tag and enable doc generation on the package?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@syall syall marked this pull request as ready for review December 15, 2023 23:11
@syall syall requested a review from a team as a code owner December 15, 2023 23:11
@syall syall force-pushed the ts-ia-fix-aws-sdk-sigv4-credential-default-provider branch from 5349dc6 to 995dea8 Compare December 15, 2023 23:51
@syall syall merged commit 9faa8ad into aws:main Dec 16, 2023
2 checks passed
@syall syall deleted the ts-ia-fix-aws-sdk-sigv4-credential-default-provider branch December 16, 2023 00:06
@syall syall changed the title fix(core): wrap credentialDefaultProvider with memoizeIdentityProvider fix(core): wrap credentialDefaultProvider with normalizeProvider Dec 16, 2023
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants