Skip to content

Commit

Permalink
feat: set settings (#22)
Browse files Browse the repository at this point in the history
This lets us set the base url.

- Closes #21
  • Loading branch information
gadomski authored Jan 3, 2025
1 parent 84f8bed commit 7d3ea43
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 30 deletions.
52 changes: 25 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ name = "pgstacrs"
crate-type = ["cdylib"]

[dependencies]
bb8 = "0.8.6"
bb8-postgres = "0.8.1"
bb8 = "0.9.0"
bb8-postgres = "0.9.0"
geojson = "0.24.1"
pgstac = { version = "0.2.2", git = "https://github.com/stac-utils/stac-rs" }
pyo3 = "0.23.2"
Expand All @@ -21,7 +21,7 @@ pyo3-async-runtimes = { version = "0.23.0", features = [
pyo3-log = "0.12.1"
pythonize = "0.23.0"
serde_json = "1.0.134"
stac-api = { version = "0.6.2", features = [
stac-api = { version = "0.7.0", features = [
"python",
], git = "https://github.com/stac-utils/stac-rs" }
stac = { version = "0.11.0", git = "https://github.com/stac-utils/stac-rs" }
Expand Down
9 changes: 9 additions & 0 deletions pgstacrs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ class Client:
It is recommended to use filter instead, if possible.
limit: The page size returned from the server.
"""

async def print_config(self) -> None:
"""Prints the postgresql configuration.
Redacts the password
"""

async def set_setting(self, key: str, value: str) -> None:
"""Sets a pgstac setting.
Args:
key: The setting name, e.g. `base_url`
value: The setting value, e.g. `http://pgstacrs.test`
"""

async def get_version(self) -> str:
"""Returns the pgstac version.
Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ impl Client {
})
}

fn set_setting<'a>(
&self,
py: Python<'a>,
key: String,
value: String,
) -> PyResult<Bound<'a, PyAny>> {
self.run(py, |pool| async move {
let connection = pool.get().await?;
connection.set_pgstac_setting(&key, &value).await?;
Ok(())
})
}

fn get_collection<'a>(&self, py: Python<'a>, id: String) -> PyResult<Bound<'a, PyAny>> {
self.run(py, |pool| async move {
let connection = pool.get().await?;
Expand Down
24 changes: 24 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ async def test_empty_search(client: Client) -> None:
}


async def test_base_url(client: Client) -> None:
await client.set_setting("base_url", "http://pgstacrs.test")
search = await client.search()
version = await client.get_version()
if version.startswith("0.9"):
assert search == {
"features": [],
"links": [
{
"href": "http://pgstacrs.test/",
"rel": "root",
"type": "application/json",
},
{
"href": "http://pgstacrs.test/search",
"rel": "self",
"type": "application/json",
},
],
"numberReturned": 0,
"type": "FeatureCollection",
}


async def test_search(
client: Client, collection: dict[str, Any], item: dict[str, Any]
) -> None:
Expand Down

0 comments on commit 7d3ea43

Please sign in to comment.