lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.86k stars 908 forks source link

Use and respect the passfile connection parameter #1129

Closed keymon closed 12 months ago

keymon commented 1 year ago

The postgres documentation[1] regarding the password file, states that:

password file to use can be specified using the connection parameter passfile or the environment variable PGPASSFILE.

The current implementation of lib/pq only respects the environment variable PGPASSFILE. This is not correct, but also limiting, as the PGPASSFILE is global and we might want to use different files for different clients in the same program.

Fixing that is easy, by just checking the parameter passfile first, and if not, pull the value from PGPASSFILE.

[1] https://www.postgresql.org/docs/current/libpq-pgpass.html

How to test

Start a postgres

docker run --name libpq-postgres \
    --net host \
    -e POSTGRES_DB=pqgotest \
    -e POSTGRES_USER=$(whoami) \
    -e POSTGRES_HOST_AUTH_METHOD="trust" \
    -d postgres

Run the test go test -run TestPgpass -v .

keymon commented 1 year ago

thanks for your contribution! Thank you for looking at it and the review!