piersolenski / wtf.nvim

Delicious diagnostic debugging in Neovim 🤤
400 stars 9 forks source link

Add Feature for Secure API Key Retrieval #22

Closed vhespanha closed 3 months ago

vhespanha commented 4 months ago

Hey there,

I added a new feature to my fork and thought I'd open a PR since it's really small.

Main Changes

Additional Changes

Thanks!

piersolenski commented 4 months ago

Hey! This is an awesome addition, and would benefit me personally as I use Bitwarden. I can see a few areas with room for improvement:

  1. I think it might be worth removing the openai_api_key method of setting the key. It's confused people in the past, and it currently leads to three conflicting ways to set it. It's also not the safest, as you might accidentally commit it to git. Perhaps it's worth deprecating in favour of this new openai_api_key_cmd (as well as still allowing the env variable, as per how https://github.com/jackMort/ChatGPT.nvim/ does it).
  2. It would be cool if we could get the key once the first time the plugin is initiated, rather than getting the value each time, as it's blocking behaviour. It's probably not noticeable with pass, but with other password managers (such as Bitwarden, Lastpass) the whole Neovim session freezes for a few seconds until the command finishes running. Ideally even the first time it ran, the behaviour could be asynchronous to avoid this. You could emulate this locally by making a simple executable:
    
    #!/bin/bash

sleep 5 echo "$OPENAI_API_KEY"


3. It would be good to handle what happens if the output of the command fails, currently it pastes the error into the buffer itself with Bitwarden.
vhespanha commented 4 months ago

Thanks for the suggestions! I'll work on these over the next few days.

The ChatGPT plugin I mentioned earlier has an async implementation similar to what you suggested. It was committed by the guy from Dreams of Code. I'll try to create something similar, niw considering the freezing issue with non-local password managers.

I'll improve the error handling, reviewing other password managers to address potential edge cases.

piersolenski commented 3 months ago

Hey @vhespanha did you run into any issues with this, in case myself or someone else wants to pick it up in the future? I agree it would be cool functionality!

vhespanha commented 3 months ago

Hey!!

I definitely still want to do this one, I ended up forgetting about it for a while but it's still something I'm willing to work on.

If you or anyone else also want to implement this, then by all means go for it and I'll make sure to collaborate, I'm unemployed right now so it is a good time for me to take another look at it.

piersolenski commented 3 months ago

That'd be awesome, feel free to reopen the PR. I'd be up for working on it too, I have quite bad Long COVID currently so I only have small windows of opportunity to do open source currently - but happy to collaborate on it now or pick it up in the future.