Skip to content

Commit 4bde7d2

Browse files
TheSandwichMakrTheSandwichMakr
authored andcommitted
Omit passwords from debug output
1 parent fb6e19a commit 4bde7d2

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tokio-postgres/src/config.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) enum Host {
5353
Unix(PathBuf),
5454
}
5555

56-
#[derive(Debug, Clone, PartialEq)]
56+
#[derive(Clone, PartialEq)]
5757
pub(crate) struct Inner {
5858
pub(crate) user: Option<String>,
5959
pub(crate) password: Option<Vec<u8>>,
@@ -69,6 +69,45 @@ pub(crate) struct Inner {
6969
pub(crate) target_session_attrs: TargetSessionAttrs,
7070
}
7171

72+
// Omit password from debug output
73+
impl fmt::Debug for Inner {
74+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75+
write!(
76+
f,
77+
"Inner {{ \
78+
user: {:?}, \
79+
password: {}, \
80+
dbname: {:?}, \
81+
options: {:?}, \
82+
application_name: {:?}, \
83+
ssl_mode: {:?}, \
84+
host: {:?}, \
85+
port: {:?}, \
86+
connect_timeout: {:?}, \
87+
keepalives: {:?}, \
88+
keepalives_idle: {:?}, \
89+
target_session_attrs: {:?} \
90+
}}",
91+
self.user,
92+
if self.password.is_some() {
93+
"Some(_)"
94+
} else {
95+
"None"
96+
},
97+
self.dbname,
98+
self.options,
99+
self.application_name,
100+
self.ssl_mode,
101+
self.host,
102+
self.port,
103+
self.connect_timeout,
104+
self.keepalives,
105+
self.keepalives_idle,
106+
self.target_session_attrs
107+
)
108+
}
109+
}
110+
72111
/// Connection configuration.
73112
///
74113
/// Configuration can be parsed from libpq-style connection strings. These strings come in two formats:

0 commit comments

Comments
 (0)