diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-05-17 13:39:05 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-05-17 15:13:43 +0200 |
commit | 3ca72a47678f9d57c40630d99382e0014317d95c (patch) | |
tree | 6169566791e425624498c61aa305e48672a2f74e | |
parent | f5ba5d8f510fcb73c87dea9962850ca3bbfb7fc0 (diff) |
Fix: Do not print database password in debug log
This fix is backported from commit 3b1701075a0591ea8d349b4b3fcfff2140185159.
From the original commit message:
We have to manually implement Debug here, because otherwise we would
print the database password in the debug output, which is CLEARLY a bad
idea.
Hence, change the debug!() call in the establish_connection() function
to (debug-)print `self` and hand-implement the `Debug` trait.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
(cherry picked from commit 3b1701075a0591ea8d349b4b3fcfff2140185159)
-rw-r--r-- | src/db/connection.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/db/connection.rs b/src/db/connection.rs index 33de9e7..d159a05 100644 --- a/src/db/connection.rs +++ b/src/db/connection.rs @@ -18,7 +18,7 @@ use log::debug; use crate::config::Configuration; -#[derive(Debug, Getters)] +#[derive(Getters)] pub struct DbConnectionConfig { #[getset(get = "pub")] database_host: String, @@ -49,6 +49,17 @@ impl Into<String> for DbConnectionConfig { } } +impl std::fmt::Debug for DbConnectionConfig { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + write!(f, "postgres://{user}:PASSWORD@{host}:{port}/{name}", + host = self.database_host, + port = self.database_port, + user = self.database_user, + name = self.database_name, + ) + } +} + pub fn parse_db_connection_config(config: &Configuration, cli: &ArgMatches) -> DbConnectionConfig { fn find_value<F>(cli: &ArgMatches, key: &str, alternative: F) -> String where @@ -77,7 +88,7 @@ pub fn parse_db_connection_config(config: &Configuration, cli: &ArgMatches) -> D } pub fn establish_connection(conn_config: DbConnectionConfig) -> Result<PgConnection> { + debug!("Trying to connect to database: {:?}", conn_config); let database_uri: String = conn_config.into(); - debug!("Trying to connect to database: {}", database_uri); PgConnection::establish(&database_uri).map_err(Error::from) } |