Use environment and pgpass to connect to PostgreSQL#385
Draft
Natureshadow wants to merge 3 commits intoArchmonger:masterfrom
Draft
Use environment and pgpass to connect to PostgreSQL#385Natureshadow wants to merge 3 commits intoArchmonger:masterfrom
Natureshadow wants to merge 3 commits intoArchmonger:masterfrom
Conversation
ddf7822 to
a8bf3fd
Compare
a8bf3fd to
1c4f627
Compare
Owner
|
The master branch needs to be re-merged into this PR Also, we only support Django > 3.2 now. Would you like to rewrite this to utilize |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #384.
Instead of building a command-line that might be subject to a row of issues (the command-line used before carried the database password in plaintext, making it available to everyone with read access to the system, we now build a copy of the environment with all the libpq variables that are needed prefilled. The password is written into a
.pgpassfile as suggested by the PostgreSQL docs.This also makes the call more compatible with various setups. For instance, a hostname is not mandatory — pg_dump can connect through the UNIX socket in /var/run as well.
In order to make all that re-usable and easy to read and understand, I decided to pack the environment generation
and .pgpass file handling in a context manager. Someone else (or me, later on, if I get bored) might want to copy it for MySQL and MongoDB.