Skip to content
Closed
Show file tree
Hide file tree
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
21 changes: 7 additions & 14 deletions engine/packages/pools/src/db/udb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,16 @@ impl Deref for UdbPool {
pub async fn setup(config: Config) -> Result<Option<UdbPool>> {
let db_driver = match config.database() {
config::Database::Postgres(pg) => {
let (ssl_root_cert_path, ssl_client_cert_path, ssl_client_key_path) =
if let Some(ssl) = &pg.ssl {
(
ssl.root_cert_path.clone(),
ssl.client_cert_path.clone(),
ssl.client_key_path.clone(),
)
} else {
(None, None, None)
};

let postgres_config = universaldb::driver::postgres::PostgresConfig {
connection_string: pg.url.read().clone(),
unstable_disable_lock_customization: pg.unstable_disable_lock_customization,
ssl_root_cert_path,
ssl_client_cert_path,
ssl_client_key_path,
ssl_config: pg.ssl.as_ref().map(|ssl| {
universaldb::driver::postgres::PostgresSslConfig {
ssl_root_cert_path: ssl.root_cert_path.clone(),
ssl_client_cert_path: ssl.client_cert_path.clone(),
ssl_client_key_path: ssl.client_key_path.clone(),
}
}),
};

Arc::new(
Expand Down
38 changes: 24 additions & 14 deletions engine/packages/universaldb/src/driver/postgres/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const GC_INTERVAL: Duration = Duration::from_secs(5);
pub struct PostgresConfig {
pub connection_string: String,
pub unstable_disable_lock_customization: bool,
pub ssl_config: Option<PostgresSslConfig>,
}

#[derive(Clone, Debug)]
pub struct PostgresSslConfig {
pub ssl_root_cert_path: Option<PathBuf>,
pub ssl_client_cert_path: Option<PathBuf>,
pub ssl_client_key_path: Option<PathBuf>,
Expand All @@ -41,9 +46,7 @@ impl PostgresConfig {
Self {
connection_string,
unstable_disable_lock_customization: false,
ssl_root_cert_path: None,
ssl_client_cert_path: None,
ssl_client_key_path: None,
ssl_config: None,
}
}
}
Expand Down Expand Up @@ -77,17 +80,24 @@ impl PostgresDatabaseDriver {

tracing::debug!("creating Postgres pool");

let tls_config = build_tls_config(
config.ssl_root_cert_path.as_ref(),
config.ssl_client_cert_path.as_ref(),
config.ssl_client_key_path.as_ref(),
)?;

let tls = MakeRustlsConnect::new(tls_config);

let pool = pool_config
.create_pool(Some(Runtime::Tokio1), tls)
.context("failed to create postgres connection pool")?;
let pool = if let Some(config) = &config.ssl_config {
let tls_config = build_tls_config(
config.ssl_root_cert_path.as_ref(),
config.ssl_client_cert_path.as_ref(),
config.ssl_client_key_path.as_ref(),
)?;
let tls = MakeRustlsConnect::new(tls_config);

pool_config
.create_pool(Some(Runtime::Tokio1), tls)
.context("failed to create postgres connection pool")?
} else {
let tls = tokio_postgres::NoTls;

pool_config
.create_pool(Some(Runtime::Tokio1), tls)
.context("failed to create postgres connection pool")?
};

tracing::debug!("Getting Postgres connection from pool");
// Get a connection from the pool to create the table
Expand Down
2 changes: 1 addition & 1 deletion engine/packages/universaldb/src/driver/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod database;
mod transaction;
mod transaction_task;

pub use database::{PostgresConfig, PostgresDatabaseDriver};
pub use database::{PostgresConfig, PostgresDatabaseDriver, PostgresSslConfig};
Loading