Skip to content

Commit ab64d95

Browse files
authored
Require ssl connection with db (#98)
1 parent dca9ed1 commit ab64d95

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

configurations/development/config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ username = "username"
1919
password = "password"
2020
database = "test"
2121
max_connections = 5
22+
use_ssl = false

packages/storage/src/postgres.rs

+9
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@ pub struct DbConfig {
2424
pub database: String,
2525
/// The maximum number of connections allowed in the connection pool.
2626
pub max_connections: u32,
27+
/// Whether to use SSL when connecting to the `PostgreSQL` server.
28+
pub use_ssl: bool,
2729
}
2830

2931
impl Postgres {
3032
pub async fn connect(opt: &DbConfig) -> ports::storage::Result<Self> {
33+
let ssl_mode = if opt.use_ssl {
34+
sqlx::postgres::PgSslMode::Require
35+
} else {
36+
sqlx::postgres::PgSslMode::Disable
37+
};
38+
3139
let options = PgConnectOptions::new()
40+
.ssl_mode(ssl_mode)
3241
.username(&opt.username)
3342
.password(&opt.password)
3443
.database(&opt.database)

packages/storage/src/test_instance.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl PostgresProcess {
111111
password: self.password.clone(),
112112
database: self.initial_db.clone(),
113113
max_connections: 5,
114+
use_ssl: false,
114115
};
115116
let db = Postgres::connect(&config).await?;
116117

0 commit comments

Comments
 (0)