Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redact database URL password #2441

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion aggregator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub trait BinaryConfig: Debug + DeserializeOwned {
#[derivative(Debug)]
pub struct DbConfig {
/// URL at which to connect to the database.
#[derivative(Debug(format_with = "std::fmt::Display::fmt"))]
#[derivative(Debug(format_with = "format_database_url"))]
pub url: Url,

/// Timeout in seconds to apply when creating, waiting for, or recycling
Expand Down Expand Up @@ -94,6 +94,19 @@ impl DbConfig {
}
}

/// Makes a best-effort attempt to redact the password from the database URL, so that it is safe
/// to display in logs.
fn format_database_url(url: &Url, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match url.password() {
Some(_) => {
let mut url = url.clone();
let _ = url.set_password(Some("REDACTED"));
fmt.write_str(url.as_str())
}
None => fmt.write_str(url.as_str()),
}
}

/// Configuration options for the Taskprov extension. This extension is
/// described in [draft-wang-ppm-dap-taskprov][spec], although its configuration
/// options are implementation-specific.
Expand Down
Loading