Update CodeWhisperer server to use bearer tokens instead of IAM credentials #539
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change demonstrates how we can let the IDE extension resolve and provide bearer tokens into language servers. This way, language servers do not have to maintain an identical bearer token implementation, which can drift over time. This change is the bearer token counterpart to #523, which worked with IAM based credentials.
When the server is started with a specific command line argument, the server waits to receive the encryption key over stdin before listening for the LSP protocol. Extensions then pass a marker through the LSP Initialization message. When the server detects this marker, it registers custom notification handlers that will be used to receive credentials and bearer tokens. The extension then pushes credentials and bearer tokens (using custom notification messages) whenever the credential state changes. In this way, the server always has credentials/tokens available for use. At times when no credentials/tokens can be resolved, the server's credentials/tokens are "un-set".
The sample CodeWhisperer language server has been updated to use bearer tokens. In the future, we will need a language server that can use either the IAM credentials or bearer tokens with CodeWhisperer. I have left the IAM credentials related code commented out (in lsp/server/aws-lsp-codewhisperer/src/language-server/codeWhispererService.ts). It is left as a future exercise to make the language server support both modes based on initialization.
The sample VS Code extension has been updated with a command to obtain a bearer token, then push it to the language server. Much of this code was copied from the AWS Toolkit for VS Code repo. The following files are largely copied from that repo, and can be skipped while reviewing this change:
This concept is subject to additional changes before its initial release.
This change also deletes
lsp/client/vscode/package-lock.json
which addresses the repo'snpm audit
warnings. This should be okay because the sample vscode client is a part of the "monorepo" configuration, and useslsp/package-lock.json
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.