Skip to content

Commit

Permalink
Hide pg connection password (#907)
Browse files Browse the repository at this point in the history
the output now looks like this, with the password being shown as `_`
instead of a real value.

<code>Connecting to Config { user: Some("myname"), password: Some(_),
dbname: Some("db"), options: None, application_name: None, ssl_mode:
Prefer, host: [Tcp("localhost")], hostaddr: [], port: [5411],
connect_timeout: None, tcp_user_timeout: None, keepalives: true,
keepalives_idle: 7200s, keepalives_interval: None, keepalives_retries:
None, target_session_attrs: Any, channel_binding: Prefer }</code>


Fix #902
  • Loading branch information
nyurik authored Sep 29, 2023
1 parent f52cd3c commit 73edd19
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions martin/src/pg/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use log::{info, warn};
use semver::Version;

use crate::pg::config::PgConfig;
use crate::pg::tls::{make_connector, parse_conn_str};
use crate::pg::tls::{make_connector, parse_conn_str, SslModeOverride};
use crate::pg::PgError::{
BadPostgisVersion, PostgisTooOld, PostgresError, PostgresPoolBuildError, PostgresPoolConnError,
};
Expand All @@ -28,8 +28,12 @@ pub struct PgPool {
impl PgPool {
pub async fn new(config: &PgConfig) -> Result<Self> {
let conn_str = config.connection_string.as_ref().unwrap().as_str();
info!("Connecting to {conn_str}");
let (pg_cfg, ssl_mode) = parse_conn_str(conn_str)?;
if matches!(ssl_mode, SslModeOverride::Unmodified(_)) {
info!("Connecting to {pg_cfg:?}");
} else {
info!("Connecting to {pg_cfg:?} with ssl_mode={ssl_mode:?}");
}

let id = pg_cfg.get_dbname().map_or_else(
|| format!("{:?}", pg_cfg.get_hosts()[0]),
Expand Down

0 comments on commit 73edd19

Please sign in to comment.