kristijanhusak / vim-dadbod-ui

Simple UI for https://github.com/tpope/vim-dadbod
MIT License
1.36k stars 70 forks source link

Unable to connect using password with special characters #232

Closed german-muzquiz closed 1 month ago

german-muzquiz commented 1 month ago

I'm unable to establish a connection to a postgres database hosted in AWS RDS that has the special character $ as part of the password. The error I'm getting is ...The password that was provided for the role postgres is wrong....

I tried escaping the $ symbol using %24 with no success, and I'm able to establish the connection using raw vim-dadbod with the escaped password.

The url that I'm using is postgresql://postgres:[REDACTED]@127.0.0.1:5432

kristijanhusak commented 1 month ago

Does it happen only with AWS RDS or also with a local database? How are you adding a connection, through the "Add connections", env variable, vim variable, or something else? It works for me locally when I connect to a docker db.

Is the URL you provided just an example how the URL looks? It points to localhost, and you are mentioning that there is an issue with RDS.

german-muzquiz commented 1 month ago

I'm just starting with the plugin so I didn't know there were other means for providing the connection, I'll take a look to see if those work

kristijanhusak commented 1 month ago

I'm assuming that SSH tunnel is the issue. Did you try using https://github.com/pbogut/vim-dadbod-ssh ?

german-muzquiz commented 1 month ago

Actually I use AWS session manager to establish the tunnel because the bastion server is not public, so is not an actual SSH connection but rather a command like this:

aws ssm start-session --target ${INSTANCE_ID} --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "{\"portNumber\":[\"${PORT}\"],\"localPortNumber\":[\"${L_PORT}\"],\"host\":[\"${HOST}\"]}"

However I wonder why it also fails for local postgres launched with docker

kristijanhusak commented 1 month ago

Does everything work locally or on RDS when there is no $ in the password? Also, what system are you using?

german-muzquiz commented 1 month ago

Confirmed that it works locally when there is no $ in the password. I cannot change the RDS password though.

Vim version:

~/code % vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Apr 18 2024 20:05:12)
macOS version - arm64
Included patches: 1-350
Compiled by Homebrew
kristijanhusak commented 1 month ago

Can you try applying this patch to your local vim-dadbod-ui installation and try it again?

diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim
index d944db7..419fd29 100644
--- a/autoload/db_ui.vim
+++ b/autoload/db_ui.vim
@@ -422,7 +422,7 @@ endfunction
 " we don't want to do.
 function db_ui#resolve(url) abort
   let parsed_url = db#url#parse(a:url)
-  let ignored_resolve_schemes = ['ssh']
+  let ignored_resolve_schemes = ['ssh', 'postgres', 'postgresql']

   if index(ignored_resolve_schemes, get(parsed_url, 'scheme', '')) > -1
     return a:url

If you added a connection through "Add connection", delete and re-add it.

german-muzquiz commented 1 month ago

Cool, after adding that patch I was able to connect using the escaped password with $

kristijanhusak commented 1 month ago

Ok, thanks for testing it. I'll fix it and let you know to give it another test.

kristijanhusak commented 1 month ago

I pushed a change to master. Can you pull latest changes and see if it works?

wstewarttennes commented 1 month ago

@kristijanhusak I am experiencing this issue as well with a # in the DB connection string -- I'm on the most recent pull and it's giving me this when running :DBUI:

Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: function db_ui#open[1]..<SNR>55_init[2]..4[25]..6[10]..7[35]..
17, line 6: Vim(if):E716: Key not present in Dictionary: "path !=? '/'"
kristijanhusak commented 1 month ago

@wstewarttennes in which part of db connection string? Did it work before this change? Does vim-dadbod directly work?

wstewarttennes commented 1 month ago

@kristijanhusak thanks for the quick reply, in the password field -- I have solved this by using %23 instead of the # symbol in the password string (this can fixed for other special characters in a similar matter). I believe this is also present in vim-dadbod directly (I was able to reproduce error using the :DB command). See this issue: https://github.com/tpope/vim-dadbod/issues/103

german-muzquiz commented 1 month ago

I confirm that the issue was fixed in the latest pull.

kristijanhusak commented 1 month ago

Ok great, thanks!