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: credentials: only decrypt credentials in the context(s) needed #908

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

g-linville
Copy link
Member

@g-linville g-linville commented Nov 18, 2024

There is some serious slowness in credentials when encryption is on and the number of stored credentials is greater than approximately 100. This is caused by a call to Get in the GetAll function in our credential store implementation. Calling Get for a credential results in a decryption operation. Even when trying to list credentials in just one context, the implementation of GetAll was resulting in the server decrypting every credential in the database, instead of just the ones in the requested context. This PR fixes that, by Geting only the credentials that will actually be returned to the user.

Comment on lines -87 to -92
for serverAddress := range newCredAddresses {
ac, err := h.Get(serverAddress)
if err != nil {
return nil, err
result[toolNameWithCtx(toolName, ctx)] = types.AuthConfig{
Username: val,
ServerAddress: serverAddress,
}
result[serverAddress] = ac
Copy link
Member Author

@g-linville g-linville Nov 18, 2024

Choose a reason for hiding this comment

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

This loop is the main thing I needed to fix. Calling h.Get results in the credential getting possibly decrypted. I refactored this so that we no longer call h.Get here in the GetAll function, and instead individually get the details for credentials that we are actually going to return to the user.

Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville marked this pull request as ready for review November 18, 2024 19:59
@ibuildthecloud ibuildthecloud merged commit 51c4b5b into gptscript-ai:main Nov 18, 2024
10 checks passed
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.

2 participants