Always use tls connector for postgres

This commit is contained in:
Alexander Olofsson
2021-02-02 18:30:27 +01:00
parent 8e691aec1f
commit 9720b19332
3 changed files with 8 additions and 43 deletions

36
Cargo.lock generated
View File

@@ -1,14 +1,5 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "ansi_term" name = "ansi_term"
version = "0.11.0" version = "0.11.0"
@@ -630,12 +621,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a"
[[package]]
name = "once_cell"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"
version = "0.2.3" version = "0.2.3"
@@ -913,21 +898,18 @@ checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.4.3" version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" checksum = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8"
dependencies = [ dependencies = [
"aho-corasick",
"memchr",
"regex-syntax", "regex-syntax",
"thread_local",
] ]
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.22" version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" checksum = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
@@ -1058,7 +1040,6 @@ dependencies = [
"postgres-openssl", "postgres-openssl",
"rand", "rand",
"rayon", "rayon",
"regex",
"state-map", "state-map",
"string_cache", "string_cache",
] ]
@@ -1081,15 +1062,6 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "thread_local"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8208a331e1cb318dd5bd76951d2b8fc48ca38a69f5f4e4af1b6a9f8c6236915"
dependencies = [
"once_cell",
]
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "0.2.11" version = "0.2.11"

View File

@@ -14,7 +14,6 @@ postgres = "0.17.0"
postgres-openssl = "0.3.0" postgres-openssl = "0.3.0"
rand = "0.7.2" rand = "0.7.2"
rayon = "1.3.0" rayon = "1.3.0"
regex = "1.4.3"
string_cache = "0.8.0" string_cache = "0.8.0"
[dependencies.state-map] [dependencies.state-map]

View File

@@ -17,7 +17,6 @@ use postgres::{fallible_iterator::FallibleIterator, Client};
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode}; use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
use postgres_openssl::MakeTlsConnector; use postgres_openssl::MakeTlsConnector;
use rand::{distributions::Alphanumeric, thread_rng, Rng}; use rand::{distributions::Alphanumeric, thread_rng, Rng};
use regex::Regex;
use std::{borrow::Cow, collections::BTreeMap, fmt, iter}; use std::{borrow::Cow, collections::BTreeMap, fmt, iter};
use super::StateGroupEntry; use super::StateGroupEntry;
@@ -31,16 +30,11 @@ pub fn get_data_from_db(
) -> BTreeMap<i64, StateGroupEntry> { ) -> BTreeMap<i64, StateGroupEntry> {
let mut client : postgres::Client; let mut client : postgres::Client;
if db_url.contains("sslmode=") {
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(SslVerifyMode::NONE); builder.set_verify(SslVerifyMode::NONE);
let connector = MakeTlsConnector::new(builder.build()); let connector = MakeTlsConnector::new(builder.build());
let re = Regex::new(r"(?:sslmode=[^&]+&|\??sslmode=[^&]+)").unwrap(); client = Client::connect(db_url, connector).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); let mut state_group_map = get_initial_data_from_db(&mut client, room_id, max_state_group);