Skip to content

Commit 8e691ae

Browse files
committed
Support postgres with SSL requirements
This stupidly just strips any ?sslmode= arguments from the postgres URI and enables SSL without verification regardless of which mode the user specifies.
1 parent 1aac27e commit 8e691ae

File tree

3 files changed

+152
-15
lines changed

3 files changed

+152
-15
lines changed

Cargo.lock

Lines changed: 134 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ edition = "2018"
99
clap = "2.33.0"
1010
indicatif = "0.14.0"
1111
jemallocator = "0.3.2"
12+
openssl = "0.10.32"
1213
postgres = "0.17.0"
14+
postgres-openssl = "0.3.0"
1315
rand = "0.7.2"
1416
rayon = "1.3.0"
17+
regex = "1.4.3"
1518
string_cache = "0.8.0"
1619

1720
[dependencies.state-map]

src/database.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
use indicatif::{ProgressBar, ProgressStyle};
1616
use postgres::{fallible_iterator::FallibleIterator, Client};
17+
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
18+
use postgres_openssl::MakeTlsConnector;
1719
use rand::{distributions::Alphanumeric, thread_rng, Rng};
20+
use regex::Regex;
1821
use std::{borrow::Cow, collections::BTreeMap, fmt, iter};
1922

2023
use super::StateGroupEntry;
@@ -26,7 +29,18 @@ pub fn get_data_from_db(
2629
room_id: &str,
2730
max_state_group: Option<i64>,
2831
) -> BTreeMap<i64, StateGroupEntry> {
29-
let mut client = Client::connect(db_url, postgres::NoTls).unwrap();
32+
let mut client : postgres::Client;
33+
34+
if db_url.contains("sslmode=") {
35+
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
36+
builder.set_verify(SslVerifyMode::NONE);
37+
let connector = MakeTlsConnector::new(builder.build());
38+
39+
let re = Regex::new(r"(?:sslmode=[^&]+&|\??sslmode=[^&]+)").unwrap();
40+
client = Client::connect(&re.replace(db_url, ""), connector).unwrap();
41+
} else {
42+
client = Client::connect(db_url, postgres::NoTls).unwrap();
43+
}
3044

3145
let mut state_group_map = get_initial_data_from_db(&mut client, room_id, max_state_group);
3246

0 commit comments

Comments
 (0)