depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit 19b478344ed125aa200048332f0e47341ed1f957
parent 9e77cc62ed0cd54eeb7229d291e3396c27dcd25e
Author: Antoine A <>
Date:   Thu, 28 Nov 2024 16:57:56 +0100

Check sqlx postgres config while parsing

Diffstat:
MCargo.lock | 1+
Mcommon/Cargo.toml | 1+
Mcommon/src/config.rs | 12++++++++++--
Mwire-gateway/src/main.rs | 4++--
4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -529,6 +529,7 @@ dependencies = [ "serde", "serde_json", "serde_with", + "sqlx", "taler-common", "thiserror 1.0.69", "uri-pack", diff --git a/common/Cargo.toml b/common/Cargo.toml @@ -36,3 +36,4 @@ uri-pack = { path = "../uri-pack" } # Exponential backoff generator exponential-backoff = "1.2.0" taler-common = { path = "../taler-common" } +sqlx = "*" diff --git a/common/src/config.rs b/common/src/config.rs @@ -14,6 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ use ini::{Ini, Properties}; +use sqlx::postgres::PgConnectOptions; use std::{ path::{Path, PathBuf}, process::Command, @@ -87,8 +88,8 @@ impl TalerConfig { required(self.section(), "DB_URL", postgres) } - pub fn db_config_raw(&self) -> String { - required(self.section(), "DB_URL", string) + pub fn db_config_sqlx(&self) -> PgConnectOptions { + required(self.section(), "DB_URL", postgres_sqlx) } pub fn base_url(&self) -> Url { @@ -205,3 +206,10 @@ pub fn postgres(properties: &Properties, name: &str) -> Option<postgres::Config> .or_fail(|e| format!("config {}={} is not a valid postgres url: {}", name, s, e)) }) } + +pub fn postgres_sqlx(properties: &Properties, name: &str) -> Option<PgConnectOptions> { + properties.get(name).map(|s| { + PgConnectOptions::from_str(s) + .or_fail(|e| format!("config {}={} is not a valid postgres url: {}", name, s, e)) + }) +} diff --git a/wire-gateway/src/main.rs b/wire-gateway/src/main.rs @@ -246,8 +246,8 @@ async fn main() { common::log::log::warn!("Running with test admin endpoint unsuitable for production"); // Parse postgres url - let db_config = taler_config.db_config_raw(); - let pool = PgPool::connect(&db_config).await.unwrap(); + let db_config = taler_config.db_config_sqlx(); + let pool = PgPool::connect_with(db_config).await.unwrap(); let payto = taler_config.payto(); let state = Arc::new(ServerState {