Use SecretString in config where appropriate

This commit is contained in:
2026-07-14 20:32:25 -04:00
parent a976f04f7d
commit b4da87231d

View File

@@ -44,11 +44,11 @@ pub struct AuthConfig {
/// Build a connection URI from parts /// Build a connection URI from parts
fn format_uri( fn format_uri(
scheme: &str, scheme: &str,
username: &Option<String>, username: Option<&String>,
password: &Option<String>, password: Option<&String>,
host: &str, host: &str,
port: &Option<u16>, port: Option<u16>,
path: &Option<String>, path: Option<&String>,
) -> String { ) -> String {
let mut url = format!("{scheme}://"); let mut url = format!("{scheme}://");
@@ -92,14 +92,14 @@ impl DatabaseConfig {
#[serde(untagged)] #[serde(untagged)]
enum DatabaseConnectionConfig { enum DatabaseConnectionConfig {
FromUrl { FromUrl {
url: String, url: SecretString,
}, },
FromParts { FromParts {
host: String, host: String,
port: Option<u16>, port: Option<u16>,
database: Option<String>, database: Option<String>,
username: Option<String>, username: Option<String>,
password: Option<String>, password: Option<SecretString>,
}, },
} }
@@ -107,14 +107,21 @@ impl DatabaseConnectionConfig {
/// Convert this configuration into the Postgres connection URI /// Convert this configuration into the Postgres connection URI
pub fn as_uri(&self) -> String { pub fn as_uri(&self) -> String {
match self { match self {
Self::FromUrl { url } => url.clone(), Self::FromUrl { url } => url.expose().clone(),
Self::FromParts { Self::FromParts {
host, host,
port, port,
database, database,
username, username,
password, password,
} => format_uri("postgres", username, password, host, port, database), } => format_uri(
"postgres",
username.as_ref(),
password.as_ref().map(|s| s.expose()),
host,
*port,
database.as_ref(),
),
} }
} }
} }
@@ -123,7 +130,7 @@ impl DatabaseConnectionConfig {
#[serde(untagged)] #[serde(untagged)]
enum KeyValStoreConnectionConfig { enum KeyValStoreConnectionConfig {
FromUrl { FromUrl {
url: String, url: SecretString,
}, },
FromParts { FromParts {
scheme: Option<String>, scheme: Option<String>,
@@ -131,7 +138,7 @@ enum KeyValStoreConnectionConfig {
port: Option<u16>, port: Option<u16>,
database: Option<String>, database: Option<String>,
username: Option<String>, username: Option<String>,
password: Option<String>, password: Option<SecretString>,
}, },
} }
@@ -139,7 +146,7 @@ impl KeyValStoreConnectionConfig {
/// Convert this configuration into the Redis connection URI /// Convert this configuration into the Redis connection URI
pub fn as_uri(&self) -> String { pub fn as_uri(&self) -> String {
match self { match self {
Self::FromUrl { url } => url.clone(), Self::FromUrl { url } => url.expose().clone(),
Self::FromParts { Self::FromParts {
scheme, scheme,
host, host,
@@ -149,11 +156,11 @@ impl KeyValStoreConnectionConfig {
password, password,
} => format_uri( } => format_uri(
scheme.as_deref().unwrap_or("redis"), scheme.as_deref().unwrap_or("redis"),
username, username.as_ref(),
password, password.as_ref().map(|s| s.expose().clone()).as_ref(),
host, host,
port, *port,
database, database.as_ref(),
), ),
} }
} }