Skip to content

Commit 7d3ea43

Browse files
authored
feat: set settings (#22)
This lets us set the base url. - Closes #21
1 parent 84f8bed commit 7d3ea43

File tree

5 files changed

+74
-30
lines changed

5 files changed

+74
-30
lines changed

Cargo.lock

Lines changed: 25 additions & 27 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ name = "pgstacrs"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
bb8 = "0.8.6"
13-
bb8-postgres = "0.8.1"
12+
bb8 = "0.9.0"
13+
bb8-postgres = "0.9.0"
1414
geojson = "0.24.1"
1515
pgstac = { version = "0.2.2", git = "https://github.com/stac-utils/stac-rs" }
1616
pyo3 = "0.23.2"
@@ -21,7 +21,7 @@ pyo3-async-runtimes = { version = "0.23.0", features = [
2121
pyo3-log = "0.12.1"
2222
pythonize = "0.23.0"
2323
serde_json = "1.0.134"
24-
stac-api = { version = "0.6.2", features = [
24+
stac-api = { version = "0.7.0", features = [
2525
"python",
2626
], git = "https://github.com/stac-utils/stac-rs" }
2727
stac = { version = "0.11.0", git = "https://github.com/stac-utils/stac-rs" }

pgstacrs.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,21 @@ class Client:
6060
It is recommended to use filter instead, if possible.
6161
limit: The page size returned from the server.
6262
"""
63+
6364
async def print_config(self) -> None:
6465
"""Prints the postgresql configuration.
6566
6667
Redacts the password
6768
"""
6869

70+
async def set_setting(self, key: str, value: str) -> None:
71+
"""Sets a pgstac setting.
72+
73+
Args:
74+
key: The setting name, e.g. `base_url`
75+
value: The setting value, e.g. `http://pgstacrs.test`
76+
"""
77+
6978
async def get_version(self) -> str:
7079
"""Returns the pgstac version.
7180

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ impl Client {
104104
})
105105
}
106106

107+
fn set_setting<'a>(
108+
&self,
109+
py: Python<'a>,
110+
key: String,
111+
value: String,
112+
) -> PyResult<Bound<'a, PyAny>> {
113+
self.run(py, |pool| async move {
114+
let connection = pool.get().await?;
115+
connection.set_pgstac_setting(&key, &value).await?;
116+
Ok(())
117+
})
118+
}
119+
107120
fn get_collection<'a>(&self, py: Python<'a>, id: String) -> PyResult<Bound<'a, PyAny>> {
108121
self.run(py, |pool| async move {
109122
let connection = pool.get().await?;

tests/test_search.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ async def test_empty_search(client: Client) -> None:
2626
}
2727

2828

29+
async def test_base_url(client: Client) -> None:
30+
await client.set_setting("base_url", "http://pgstacrs.test")
31+
search = await client.search()
32+
version = await client.get_version()
33+
if version.startswith("0.9"):
34+
assert search == {
35+
"features": [],
36+
"links": [
37+
{
38+
"href": "http://pgstacrs.test/",
39+
"rel": "root",
40+
"type": "application/json",
41+
},
42+
{
43+
"href": "http://pgstacrs.test/search",
44+
"rel": "self",
45+
"type": "application/json",
46+
},
47+
],
48+
"numberReturned": 0,
49+
"type": "FeatureCollection",
50+
}
51+
52+
2953
async def test_search(
3054
client: Client, collection: dict[str, Any], item: dict[str, Any]
3155
) -> None:

0 commit comments

Comments
 (0)