Skip to content

Commit d2fc97d

Browse files
authored
Merge pull request #163 from Brobb954/main
Update Rustls example and add to README for clarification
2 parents 74867bd + 3d5cf55 commit d2fc97d

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,21 @@ jobs:
4141
run: |
4242
echo "RUST_TEST_THREADS=1" >> $GITHUB_ENV
4343
44+
- name: Set environment variables
45+
shell: bash
46+
if: matrix.backend == 'postgres' && matrix.os == 'windows-2019'
47+
run: |
48+
echo "AWS_LC_SYS_NO_ASM=1"
49+
4450
- name: Set environment variables
4551
shell: bash
4652
if: matrix.rust == 'nightly'
4753
run: |
4854
echo "RUSTFLAGS=--cap-lints=warn" >> $GITHUB_ENV
4955
56+
- uses: ilammy/setup-nasm@v1
57+
if: matrix.backend == 'postgres' && matrix.os == 'windows-2019'
58+
5059
- name: Install postgres (Linux)
5160
if: runner.os == 'Linux' && matrix.backend == 'postgres'
5261
run: |

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ let mut conn = pool.get().await?;
168168
let res = users::table.select(User::as_select()).load::(&mut conn).await?;
169169
```
170170

171+
## Diesel-Async with Secure Database
172+
173+
In the event of using this crate with a `sslmode=require` flag, it will be necessary to build a TLS cert.
174+
There is an example provided for doing this using the `rustls` crate in the `postgres` examples folder.
175+
171176
## Crate Feature Flags
172177

173178
Diesel-async offers several configurable features:

examples/postgres/pooled-with-rustls/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
diesel = { version = "2.1.0", default-features = false, features = ["postgres"] }
9+
diesel = { version = "2.2.0", default-features = false, features = ["postgres"] }
1010
diesel-async = { version = "0.4.0", path = "../../../", features = ["bb8", "postgres"] }
1111
futures-util = "0.3.21"
12-
rustls = "0.20.8"
13-
rustls-native-certs = "0.6.2"
12+
rustls = "0.23.8"
13+
rustls-native-certs = "0.7.1"
1414
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
1515
tokio-postgres = "0.7.7"
16-
tokio-postgres-rustls = "0.9.0"
16+
tokio-postgres-rustls = "0.12.0"

examples/postgres/pooled-with-rustls/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
4343
let fut = async {
4444
// We first set up the way we want rustls to work.
4545
let rustls_config = rustls::ClientConfig::builder()
46-
.with_safe_defaults()
4746
.with_root_certificates(root_certs())
4847
.with_no_client_auth();
4948
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
@@ -63,7 +62,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
6362
fn root_certs() -> rustls::RootCertStore {
6463
let mut roots = rustls::RootCertStore::empty();
6564
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
66-
let certs: Vec<_> = certs.into_iter().map(|cert| cert.0).collect();
67-
roots.add_parsable_certificates(&certs);
65+
roots.add_parsable_certificates(certs);
6866
roots
6967
}

examples/postgres/run-pending-migrations-with-rustls/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
diesel = { version = "2.1.0", default-features = false, features = ["postgres"] }
9+
diesel = { version = "2.2.0", default-features = false, features = ["postgres"] }
1010
diesel-async = { version = "0.4.0", path = "../../../", features = ["bb8", "postgres", "async-connection-wrapper"] }
11-
diesel_migrations = "2.1.0"
11+
diesel_migrations = "2.2.0"
1212
futures-util = "0.3.21"
13-
rustls = "0.20.8"
14-
rustls-native-certs = "0.6.2"
13+
rustls = "0.23.10"
14+
rustls-native-certs = "0.7.1"
1515
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
1616
tokio-postgres = "0.7.7"
17-
tokio-postgres-rustls = "0.9.0"
17+
tokio-postgres-rustls = "0.12.0"

examples/postgres/run-pending-migrations-with-rustls/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
2929
let fut = async {
3030
// We first set up the way we want rustls to work.
3131
let rustls_config = rustls::ClientConfig::builder()
32-
.with_safe_defaults()
3332
.with_root_certificates(root_certs())
3433
.with_no_client_auth();
3534
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
@@ -49,7 +48,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
4948
fn root_certs() -> rustls::RootCertStore {
5049
let mut roots = rustls::RootCertStore::empty();
5150
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
52-
let certs: Vec<_> = certs.into_iter().map(|cert| cert.0).collect();
53-
roots.add_parsable_certificates(&certs);
51+
roots.add_parsable_certificates(certs);
5452
roots
5553
}

0 commit comments

Comments
 (0)