Skip to content

Commit

Permalink
Merge branch 'main' into feature/share_statement_cache_with_diesel
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich authored Jan 16, 2025
2 parents 4d349df + 7e0267b commit 45c8559
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
4 changes: 2 additions & 2 deletions examples/postgres/pooled-with-rustls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ edition = "2021"
diesel-async = { version = "0.5.0", path = "../../../", features = ["bb8", "postgres"] }
futures-util = "0.3.21"
rustls = "0.23.8"
rustls-native-certs = "0.7.1"
rustls-platform-verifier = "0.5.0"
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-postgres = "0.7.7"
tokio-postgres-rustls = "0.12.0"
tokio-postgres-rustls = "0.13.0"


[dependencies.diesel]
Expand Down
13 changes: 3 additions & 10 deletions examples/postgres/pooled-with-rustls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use diesel_async::pooled_connection::ManagerConfig;
use diesel_async::AsyncPgConnection;
use futures_util::future::BoxFuture;
use futures_util::FutureExt;
use rustls::ClientConfig;
use rustls_platform_verifier::ConfigVerifierExt;
use std::time::Duration;

#[tokio::main]
Expand Down Expand Up @@ -42,9 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConnection>> {
let fut = async {
// We first set up the way we want rustls to work.
let rustls_config = rustls::ClientConfig::builder()
.with_root_certificates(root_certs())
.with_no_client_auth();
let rustls_config = ClientConfig::with_platform_verifier();
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
let (client, conn) = tokio_postgres::connect(config, tls)
.await
Expand All @@ -54,10 +54,3 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
};
fut.boxed()
}

fn root_certs() -> rustls::RootCertStore {
let mut roots = rustls::RootCertStore::empty();
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
roots.add_parsable_certificates(certs);
roots
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ edition = "2021"
[dependencies]
diesel-async = { version = "0.5.0", path = "../../../", features = ["bb8", "postgres", "async-connection-wrapper"] }
futures-util = "0.3.21"
rustls = "0.23.10"
rustls-native-certs = "0.7.1"
rustls = "0.23.8"
rustls-platform-verifier = "0.5.0"
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-postgres = "0.7.7"
tokio-postgres-rustls = "0.12.0"
tokio-postgres-rustls = "0.13.0"

[dependencies.diesel]
version = "2.2.0"
Expand Down
13 changes: 3 additions & 10 deletions examples/postgres/run-pending-migrations-with-rustls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use diesel_async::AsyncPgConnection;
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use futures_util::future::BoxFuture;
use futures_util::FutureExt;
use rustls::ClientConfig;
use rustls_platform_verifier::ConfigVerifierExt;

pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();

Expand All @@ -28,9 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConnection>> {
let fut = async {
// We first set up the way we want rustls to work.
let rustls_config = rustls::ClientConfig::builder()
.with_root_certificates(root_certs())
.with_no_client_auth();
let rustls_config = ClientConfig::with_platform_verifier();
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
let (client, conn) = tokio_postgres::connect(config, tls)
.await
Expand All @@ -39,10 +39,3 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
};
fut.boxed()
}

fn root_certs() -> rustls::RootCertStore {
let mut roots = rustls::RootCertStore::empty();
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
roots.add_parsable_certificates(certs);
roots
}

0 comments on commit 45c8559

Please sign in to comment.