From 7d3ea4374441762438e819ea6c517c6426fe9eda Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Fri, 3 Jan 2025 12:01:37 -0700 Subject: [PATCH] feat: set settings (#22) This lets us set the base url. - Closes #21 --- Cargo.lock | 52 +++++++++++++++++++++----------------------- Cargo.toml | 6 ++--- pgstacrs.pyi | 9 ++++++++ src/lib.rs | 13 +++++++++++ tests/test_search.py | 24 ++++++++++++++++++++ 5 files changed, 74 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2967347..cf5e8f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,9 +77,9 @@ checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "1b1244b10dcd56c92219da4e14caa97e312079e185f04ba3eea25061561dc0a0" dependencies = [ "proc-macro2", "quote", @@ -152,11 +152,10 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bb8" -version = "0.8.6" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89aabfae550a5c44b43ab941844ffcd2e993cb6900b342debf59e9ea74acdb8" +checksum = "212d8b8e1a22743d9241575c6ba822cf9c8fef34771c86ab7e477a4fbfd254e5" dependencies = [ - "async-trait", "futures-util", "parking_lot", "tokio", @@ -164,11 +163,10 @@ dependencies = [ [[package]] name = "bb8-postgres" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ac82c42eb30889b5c4ee4763a24b8c566518171ebea648cd7e3bc532c60680" +checksum = "e570e6557cd0f88d28d32afa76644873271a70dc22656df565b2021c4036aa9c" dependencies = [ - "async-trait", "bb8", "tokio", "tokio-postgres", @@ -258,9 +256,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.5" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" +checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7" dependencies = [ "jobserver", "libc", @@ -438,7 +436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1135,7 +1133,7 @@ dependencies = [ [[package]] name = "pgstac" version = "0.2.2" -source = "git+https://github.com/stac-utils/stac-rs#55703cef7777581ad2adb2bc9aa4ad8fef3e2e47" +source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" dependencies = [ "serde", "serde_json", @@ -1384,9 +1382,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -1496,7 +1494,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1546,18 +1544,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -1661,8 +1659,8 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stac" -version = "0.11.0" -source = "git+https://github.com/stac-utils/stac-rs#55703cef7777581ad2adb2bc9aa4ad8fef3e2e47" +version = "0.11.1" +source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" dependencies = [ "bytes", "chrono", @@ -1679,8 +1677,8 @@ dependencies = [ [[package]] name = "stac-api" -version = "0.6.2" -source = "git+https://github.com/stac-utils/stac-rs#55703cef7777581ad2adb2bc9aa4ad8fef3e2e47" +version = "0.7.0" +source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" dependencies = [ "chrono", "cql2", @@ -1699,8 +1697,8 @@ dependencies = [ [[package]] name = "stac-derive" -version = "0.1.0" -source = "git+https://github.com/stac-utils/stac-rs#55703cef7777581ad2adb2bc9aa4ad8fef3e2e47" +version = "0.2.0" +source = "git+https://github.com/stac-utils/stac-rs#94693e3e8e732018769861214e1cab9767c9a674" dependencies = [ "quote", "syn", @@ -1725,9 +1723,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.91" +version = "2.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" +checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 517eba3..fbeab59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" } diff --git a/pgstacrs.pyi b/pgstacrs.pyi index c077536..3d51d3b 100644 --- a/pgstacrs.pyi +++ b/pgstacrs.pyi @@ -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. diff --git a/src/lib.rs b/src/lib.rs index 33f173f..145ccfa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,6 +104,19 @@ impl Client { }) } + fn set_setting<'a>( + &self, + py: Python<'a>, + key: String, + value: String, + ) -> PyResult> { + 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> { self.run(py, |pool| async move { let connection = pool.get().await?; diff --git a/tests/test_search.py b/tests/test_search.py index 9184d79..2bb17b7 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -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: