xo / usql

Universal command-line interface for SQL databases
MIT License
8.88k stars 347 forks source link

Credentials from .usqlpass file are not used #326

Closed usommerl closed 2 years ago

usommerl commented 2 years ago

First of all thanks for this handy tool! I'm just playing around with it for an hour so maybe I'm just too dumb to use it and this isn't really a software problem. Here is my issue:

I'm using usql to connect to a CockroachDB Serverless instance and this is working fine when I provide the full connection string which includes the credentials:

usql 'cockroach://myuser:mypass@free-tier5.gcp-europe-west1.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full&options=--cluster%3Dmycluster-3361'

Connected with driver postgres (PostgreSQL 13.0.0)
Type "help" for help.

cr:myuser@free-tier5.gcp-europe-west1.cockroachlabs.cloud:26257/defaultdb=>

What I really would like to do is to move the credentials in the ~/.usqlpass file like so:

# format is:
# protocol:host:port:dbname:user:pass
cockroach:*:*:*:myuser:mypass

However, the client does not seem to pick up this information when I try to connect:

usql 'cockroach://myuser@free-tier5.gcp-europe-west1.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full&options=--cluster%3Dmycluster-3361'
error: pq: 28000: password authentication failed for user myuser

Am I doing something wrong or is this a bug? Can I somehow check whether the ~/.usqlpass file is read at all?

usql --version
usql 0.10.0
kenshaw commented 2 years ago

Try cockroachdb. If that doesn't work, just use the postgres name, as cockroach is just an alias for the postgres driver.

usommerl commented 2 years ago

@kenshaw It works when I use cockroachdb. Thanks a lot!

I assumed I could use any scheme alias in the .usqlpass file, but that is not the case. Is there a general rule on which identifier can be used in this file? Maybe the documentation could be improved in this regard?

kenshaw commented 2 years ago

It needs to be the primary name. I chose to do it that way for a number of reasons. The rule is that it can't be an alias on the dburl documentation.