Skip to content

Commit 4976448

Browse files
committed
feat: allow tls
1 parent 7ff0791 commit 4976448

File tree

4 files changed

+216
-10
lines changed

4 files changed

+216
-10
lines changed

Cargo.lock

Lines changed: 199 additions & 0 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ crate-type = ["cdylib"]
1212
bb8 = "0.8.6"
1313
bb8-postgres = "0.8.1"
1414
geojson = "0.24.1"
15-
pgstac = { version = "0.2.2", git = "https://github.com/stac-utils/stac-rs" }
15+
pgstac = { version = "0.2.2", git = "https://github.com/stac-utils/stac-rs", features = [
16+
"tls",
17+
] }
1618
pyo3 = "0.23.2"
1719
pyo3-async-runtimes = { version = "0.23.0", features = [
1820
"tokio",

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use bb8::{Pool, RunError};
44
use bb8_postgres::PostgresConnectionManager;
5-
use pgstac::Pgstac;
5+
use pgstac::{make_unverified_tls, MakeRustlsConnect, Pgstac};
66
use pyo3::{
77
create_exception,
88
exceptions::{PyException, PyValueError},
@@ -18,7 +18,7 @@ use tokio_postgres::{Config, NoTls};
1818
create_exception!(pgstacrs, PgstacError, PyException);
1919
create_exception!(pgstacrs, StacError, PyException);
2020

21-
type PgstacPool = Pool<PostgresConnectionManager<NoTls>>;
21+
type PgstacPool = Pool<PostgresConnectionManager<MakeRustlsConnect>>;
2222

2323
#[derive(Debug, Error)]
2424
enum Error {
@@ -68,7 +68,7 @@ impl Client {
6868
let config: Config = params
6969
.parse()
7070
.map_err(|err: <Config as FromStr>::Err| PyValueError::new_err(err.to_string()))?;
71-
let manager = PostgresConnectionManager::new(config.clone(), NoTls);
71+
let manager = PostgresConnectionManager::new(config.clone(), make_unverified_tls());
7272
pyo3_async_runtimes::tokio::future_into_py(py, async move {
7373
{
7474
// Quick connection to get better errors, bb8 will just time out
@@ -308,7 +308,7 @@ impl Client {
308308
fn run<'a, F, T>(
309309
&self,
310310
py: Python<'a>,
311-
f: impl FnOnce(Pool<PostgresConnectionManager<NoTls>>) -> F + Send + 'static,
311+
f: impl FnOnce(Pool<PostgresConnectionManager<MakeRustlsConnect>>) -> F + Send + 'static,
312312
) -> PyResult<Bound<'a, PyAny>>
313313
where
314314
F: Future<Output = Result<T>> + Send,

tests/conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from pathlib import Path
3-
from typing import Any, AsyncIterator, Iterator, cast
3+
from typing import Any, Iterator, cast
44

55
import pytest
66
from pgstacrs import Client
@@ -38,7 +38,7 @@ def pgstac(
3838

3939

4040
@pytest.fixture
41-
async def client(pgstac: PostgreSQLExecutor) -> AsyncIterator[Client]:
41+
def database_janitor(pgstac: PostgreSQLExecutor) -> Iterator[DatabaseJanitor]:
4242
with DatabaseJanitor(
4343
user=pgstac.user,
4444
host=pgstac.host,
@@ -48,9 +48,14 @@ async def client(pgstac: PostgreSQLExecutor) -> AsyncIterator[Client]:
4848
dbname="pypgstac_test",
4949
template_dbname=pgstac.template_dbname,
5050
) as database_janitor:
51-
yield await Client.open(
52-
f"user={database_janitor.user} host={database_janitor.host} port={database_janitor.port} dbname={database_janitor.dbname} password={database_janitor.password}"
53-
)
51+
yield database_janitor
52+
53+
54+
@pytest.fixture
55+
async def client(database_janitor: DatabaseJanitor) -> Client:
56+
return await Client.open(
57+
f"user={database_janitor.user} host={database_janitor.host} port={database_janitor.port} dbname={database_janitor.dbname} password={database_janitor.password}"
58+
)
5459

5560

5661
@pytest.fixture

0 commit comments

Comments
 (0)