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: prevent override of client request listeners in CodeWhispererServiceIAM #784

Conversation

francescoopiccoli
Copy link
Contributor

Problem

Prevent override of client request listeners in CodeWhispererServiceIAM in case any listener was setup before.

Solution

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@francescoopiccoli francescoopiccoli marked this pull request as ready for review February 17, 2025 09:22
@francescoopiccoli francescoopiccoli requested a review from a team as a code owner February 17, 2025 09:22
httpRequest.headers['x-amzn-codewhisperer-optout'] = `${!this.shareCodeWhispererContentWithAWS}`
// Avoid overwriting any existing client listeners
const clientRequestListeners = this.client.setupRequestListeners
this.client.setupRequestListeners = (request: Request<unknown, AWSError>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this with caching original listeners? Would using similar implementation as for CodeWhispererServiceToken work

onRequestSetup: [
req => {
req.on('build', ({ httpRequest }) => {
const creds = credentialsProvider.getCredentials('bearer') as BearerCredentials
if (!creds?.token) {
throw new Error('Authorization failed, bearer token is not set')
}
httpRequest.headers['Authorization'] = `Bearer ${creds.token}`
httpRequest.headers['x-amzn-codewhisperer-optout'] = `${!this.shareCodeWhispererContentWithAWS}`
})
?

Copy link
Contributor Author

@francescoopiccoli francescoopiccoli Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested but I am confident that it would work as well. I am fine with going with that approach if you think it's better, but I would be curious to know why you think it is better, apart from consistency with the the token client implementation.
I did consider that approach before opening the PR, but it felt like it was adding more complexity as you need to extend the options (see here), and you still do cache the original listeners from my understanding (see here)

@francescoopiccoli francescoopiccoli merged commit cd85931 into main Feb 17, 2025
7 checks passed
@francescoopiccoli francescoopiccoli deleted the frapicc/fix-override-client-listener-codewhisperer-service-iam branch February 17, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants