diff options
Diffstat (limited to 'crates/turtle/src/atuin_server')
| -rw-r--r-- | crates/turtle/src/atuin_server/database/db/mod.rs | 2 | ||||
| -rw-r--r-- | crates/turtle/src/atuin_server/database/db/wrappers.rs | 2 | ||||
| -rw-r--r-- | crates/turtle/src/atuin_server/database/mod.rs | 24 |
3 files changed, 15 insertions, 13 deletions
diff --git a/crates/turtle/src/atuin_server/database/db/mod.rs b/crates/turtle/src/atuin_server/database/db/mod.rs index 5b3c169b..47dbd6d1 100644 --- a/crates/turtle/src/atuin_server/database/db/mod.rs +++ b/crates/turtle/src/atuin_server/database/db/mod.rs @@ -17,7 +17,7 @@ mod wrappers; const MIN_PG_VERSION: u32 = 14; #[derive(Clone)] -pub struct ServerPostgres { +pub(crate) struct ServerPostgres { pool: sqlx::Pool<sqlx::postgres::Postgres>, /// Optional read replica pool for read-only queries read_pool: Option<sqlx::Pool<sqlx::postgres::Postgres>>, diff --git a/crates/turtle/src/atuin_server/database/db/wrappers.rs b/crates/turtle/src/atuin_server/database/db/wrappers.rs index 8a52d56e..0a7b6ff3 100644 --- a/crates/turtle/src/atuin_server/database/db/wrappers.rs +++ b/crates/turtle/src/atuin_server/database/db/wrappers.rs @@ -1,7 +1,7 @@ use crate::atuin_common::record::{EncryptedData, Host, Record}; use sqlx::{Row, postgres::PgRow}; -pub struct DbRecord(pub Record<EncryptedData>); +pub(crate) struct DbRecord(pub Record<EncryptedData>); impl<'a> ::sqlx::FromRow<'a, PgRow> for DbRecord { fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> { diff --git a/crates/turtle/src/atuin_server/database/mod.rs b/crates/turtle/src/atuin_server/database/mod.rs index bb64767a..43fe5c3b 100644 --- a/crates/turtle/src/atuin_server/database/mod.rs +++ b/crates/turtle/src/atuin_server/database/mod.rs @@ -14,29 +14,29 @@ pub(crate) enum DbError { impl Display for DbError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - DbError::NotFound => write!(f, "Not found"), - DbError::Other(report) => write!(f, "Other: {report}"), + Self::NotFound => write!(f, "Not found"), + Self::Other(report) => write!(f, "Other: {report}"), } } } impl From<time::error::ComponentRange> for DbError { fn from(error: time::error::ComponentRange) -> Self { - DbError::Other(error.into()) + Self::Other(error.into()) } } impl From<time::error::Error> for DbError { fn from(error: time::error::Error) -> Self { - DbError::Other(error.into()) + Self::Other(error.into()) } } impl From<sqlx::Error> for DbError { fn from(error: sqlx::Error) -> Self { match error { - sqlx::Error::RowNotFound => DbError::NotFound, - error => DbError::Other(error.into()), + sqlx::Error::RowNotFound => Self::NotFound, + error => Self::Other(error.into()), } } } @@ -54,6 +54,7 @@ pub(crate) enum DbType { #[derive(Clone, Deserialize, Serialize)] pub(crate) struct DbSettings { pub(crate) db_uri: String, + /// Optional URI for read replicas. If set, read-only queries will use this connection. pub(crate) read_db_uri: Option<String>, } @@ -69,12 +70,13 @@ impl DbSettings { } fn redact_db_uri(uri: &str) -> String { - url::Url::parse(uri) - .map(|mut url| { - let _ = url.set_password(Some("****")); + url::Url::parse(uri).map_or_else( + |_| uri.to_string(), + |mut url| { + url.set_password(Some("****")).expect("should be possible"); url.to_string() - }) - .unwrap_or_else(|_| uri.to_string()) + }, + ) } // Do our best to redact passwords so they're not logged in the event of an error. |
