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

URL param support for redis adapter #131

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

guruor
Copy link

@guruor guruor commented Apr 29, 2023

This should be better alternative to #129

Test case:

:echo db#adapter#dispatch("redis://localhost:6482/0?c&no-auth-warning", "interactive")

Result:

['redis-cli', '-c', '--no-auth-warning', '-h', 'localhost', '-p', '6482', '-n', '0']

@tpope
Copy link
Owner

tpope commented Apr 30, 2023

This is indeed a better approach. But we should limit it to connection parameters; half or more of these (e.g., eval) have no business being in a connection URI. And we don't need single character aliases.

@guruor
Copy link
Author

guruor commented May 1, 2023

@tpope I just went through the redis-cli --help to get the non-boolean flags and added here.
You are right we can limit to only connection parameters. I think few flags like cert, key, cacert, capath and tls-ciphers should be sufficient. I might be missing some crucial flags here but we can add those later when there is a need of it.

I added single character flag support because few of the flag are single character but not alias like u,r,i,d,D and c.

@guruor
Copy link
Author

guruor commented May 7, 2023

@tpope Have added the suggested changes, please review once again and let me know if any other change is required.

@tpope
Copy link
Owner

tpope commented May 7, 2023

Didn't notice those single character options weren't aliases. But they don't really seem necessary to me, with the possible exception of -c. I would drop all of them; if someone wants -c we can add it back.

- These are not really required
- We mainly needed to handle -c for cluster mode, which is already being handled by the
else case
@guruor
Copy link
Author

guruor commented May 8, 2023

@tpope Removed the other single char flags (u, r, i, d and D) and weren't explicitly handling the -c anyways. Now we are good to go.

" Specifying only connection releated flag here, missing flags can be added later
if k =~# '^\%(cert\|key\|cacert\|capath\|tls-ciphers\|tls-ciphersuites\)$' && v isnot# 1
call add(cmd, '--' . k . '=' . v)
elseif v =~# '^[1Tt]$'
Copy link
Owner

Choose a reason for hiding this comment

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

This would make sense to have a k check too, no? That is k ==# 'tls' && v =~# '^[1Tt]', or something similar.

Copy link
Author

Choose a reason for hiding this comment

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

Idea was to check the non-boolean flags explicitly and else case would always handle boolean flags.

Copy link
Owner

Choose a reason for hiding this comment

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

Is there an upside to doing it that way? The downside would be it could potentially pass a non-Boolean option as Boolean, resulting in a potentially confusing error message.

Copy link
Author

Choose a reason for hiding this comment

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

No upside, just some laziness in handling it 😉 , will add the parameters mentioned in help doc explicitly.

@hiberabyss
Copy link
Contributor

Options like no-auth-warning should be set globally. Set it for every connection is tiresome.

@tpope
Copy link
Owner

tpope commented May 17, 2023

  --no-auth-warning  Don't show warning message when using password on command
                     line interface.

Reading this description, yes, the fix for this option isn't a configuration option or a URL parameter, we should just pass it by default (or better, fix it to pass the password as an environment variable).

@hiberabyss
Copy link
Contributor

Pass password by environment is a good idea. The mysql warning could also be suppressed via environment password like MYSQL_PWD=pass mysql -u user -h host.

- Added appropriate error message with instruction to check the `dadbod-redis` help
@guruor guruor requested a review from tpope May 25, 2023 07:22
@guruor
Copy link
Author

guruor commented Jun 8, 2023

@tpope Had pushed the updated changes, I think it is ready to merge now.
let me know if you still have any suggestion or concerns.

@guruor
Copy link
Author

guruor commented Jul 10, 2023

@tpope Were you able to check the new changes?

@guruor
Copy link
Author

guruor commented Aug 4, 2023

@tpope bumping it once again, apologies for spamming. Just wanted to make sure if it being checked.

doc/dadbod.txt Outdated
@@ -169,6 +169,9 @@ Redis ~
Redis doesn't have a username, so use a dummy one in the URL if a password is
required.

Query parameters such as `c`, `cert`, `key`, `cacert`, `capath`, `tls-ciphers` and
Copy link
Owner

Choose a reason for hiding this comment

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

This line is too long. Use textwidth=78, as seen in the modeline.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

elseif k ==# 'c' && v =~# '^[1Tt]$'
" Some non-alias single char flags like `-c` needs to be passed
" with single hyphen `-` char
if len(k) == 1
Copy link
Owner

Choose a reason for hiding this comment

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

This check is redundant, as k ==# 'c' implies len(k) == 1.

" Specifying only connection releated flag here, missing flags can be added later
if k =~# '^\%(cert\|key\|cacert\|capath\|tls-ciphers\|tls-ciphersuites\)$' && v isnot# 1
call add(cmd, '--' . k . '=' . v)
elseif k ==# 'c' && v =~# '^[1Tt]$'
Copy link
Owner

Choose a reason for hiding this comment

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

Drop the $ so that c=true can be used.

Comment on lines +24 to +25
else
throw 'DB: unsupport URL param `' . k . '` in URL ' . a:url . ', Check `:help dadbod-redis`'
Copy link
Owner

Choose a reason for hiding this comment

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

Drop this.

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