fix: masked postgres password in logs

This commit is contained in:
khorshuheng 2024-10-24 00:34:31 +08:00
parent d4b77c3c27
commit 16fb9584f9
3 changed files with 26 additions and 3 deletions

View File

@ -3,7 +3,7 @@ use collab_stream::client::CONTROL_STREAM_KEY;
use infra::env_util::get_env_var;
use serde::Deserialize;
use sqlx::postgres::{PgConnectOptions, PgSslMode};
use std::str::FromStr;
use std::{fmt::Display, str::FromStr};
#[derive(Debug, Clone)]
pub struct Config {
@ -64,6 +64,17 @@ impl DatabaseSetting {
}
}
impl Display for DatabaseSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let masked_pg_conn_opts = self.pg_conn_opts.clone().password("********");
write!(
f,
"DatabaseSetting {{ pg_conn_opts: {:?}, require_ssl: {}, max_connections: {} }}",
masked_pg_conn_opts, self.require_ssl, self.max_connections
)
}
}
#[derive(Debug, Clone)]
pub struct StreamSetting {
/// The key of the stream that contains control event, [CollabControlEvent].

View File

@ -4,7 +4,7 @@ use mailer::config::MailerSetting;
use secrecy::Secret;
use serde::Deserialize;
use sqlx::postgres::{PgConnectOptions, PgSslMode};
use std::str::FromStr;
use std::{fmt::Display, str::FromStr};
#[derive(Debug, Clone)]
pub struct Config {
@ -79,6 +79,17 @@ impl DatabaseSetting {
}
}
impl Display for DatabaseSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let masked_pg_conn_opts = self.pg_conn_opts.clone().password("********");
write!(
f,
"DatabaseSetting {{ pg_conn_opts: {:?}, require_ssl: {}, max_connections: {} }}",
masked_pg_conn_opts, self.require_ssl, self.max_connections
)
}
}
#[derive(Debug, Clone)]
pub struct StreamSetting {
/// The key of the stream that contains control event, [CollabControlEvent].

View File

@ -115,10 +115,11 @@ pub struct DatabaseSetting {
impl Display for DatabaseSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let masked_pg_conn_opts = self.pg_conn_opts.clone().password("********");
write!(
f,
"DatabaseSetting {{ pg_conn_opts: {:?}, require_ssl: {}, max_connections: {} }}",
self.pg_conn_opts, self.require_ssl, self.max_connections
masked_pg_conn_opts, self.require_ssl, self.max_connections
)
}
}