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.
This commit is contained in:
Alexander Olofsson
2021-01-30 20:29:58 +01:00
parent 1aac27ebb6
commit 8e691aec1f
3 changed files with 152 additions and 15 deletions

View File

@@ -14,7 +14,10 @@
use indicatif::{ProgressBar, ProgressStyle};
use postgres::{fallible_iterator::FallibleIterator, Client};
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
use postgres_openssl::MakeTlsConnector;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use regex::Regex;
use std::{borrow::Cow, collections::BTreeMap, fmt, iter};
use super::StateGroupEntry;
@@ -26,7 +29,18 @@ pub fn get_data_from_db(
room_id: &str,
max_state_group: Option<i64>,
) -> BTreeMap<i64, StateGroupEntry> {
let mut client = Client::connect(db_url, postgres::NoTls).unwrap();
let mut client : postgres::Client;
if db_url.contains("sslmode=") {
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(SslVerifyMode::NONE);
let connector = MakeTlsConnector::new(builder.build());
let re = Regex::new(r"(?:sslmode=[^&]+&|\??sslmode=[^&]+)").unwrap();
client = Client::connect(&re.replace(db_url, ""), connector).unwrap();
} else {
client = Client::connect(db_url, postgres::NoTls).unwrap();
}
let mut state_group_map = get_initial_data_from_db(&mut client, room_id, max_state_group);