Expand environment variables in DSN aliases#1914
Conversation
|
Hi! This is an interesting idea but I have many thoughts and questions!
It seems to me that if Instead we should break down the DSN first, only applying variable substitution to values, not keys. Also it would be better to substitute only complete values rather than partial values. Also it would be better to limit to the Are you up for it? |
f43aacf to
03af290
Compare
|
Thanks for your comments. I really didn't give enough thought about the side effects you mentioned. Now I'm not even sure if my most recent update is the right way to do it. Probably the expansion helper should live somewhere more focused that in cli_runner.py
Right. You would leave the env expansion to the shell. That's what I'm currently doing in my wrapper script. And honestly, I could live with it. The reason why this came up is that I recently switched to having all keys and passwords in sops encrypted files that are injected into the environment using mise. After years of fiddling around this almost feels like magic. Now by using env vars for everything I have the absolute same connect string on every host for the same database. One single source of truth and it just works.
I might miss sth here, but no ... when there's no env expansion I would have to spread passwords all over the place again. As I said, I'm hesitant about this PR but at least there would be
Thanks |
|
@n8himmel thanks for your responsiveness! mise is more and more popular. I would welcome more direct integration with mise. "feels like magic" is also good! Yes, we could organize things a little differently. For instance using dataclasses instead of tuples — but it looks good. Let's ship it. I did a release just as you were working and introduced a conflict in |
|
released in https://github.com/dbcli/mycli/releases/tag/v1.76.0 ! |
Description
Expand configured
[alias_dsn]values withos.path.expandvarsafter alias lookup and before URL parsing. This allows aliases to keep DSN components such as credentials, hosts, ports, or database names in environment variables.This adds coverage for both
--dsn <alias>and positional alias usage, and documents$VAR/${VAR}support in the sample config.Checklist
changelog.mdfile.AUTHORSfile (or it's already there).uv run --extra dev -- ruff check uv run --extra dev -- ruff format uv run --extra dev -- mypy --install-types --non-interactive .Additional focused test run: