Skip to content

Commit c4a02a6

Browse files
committed
Merge branch 'main' of https://github.com/stac-utils/stac-fastapi-pgstac into patch/collection-search-paging
2 parents 576a9dc + 7135059 commit c4a02a6

File tree

8 files changed

+61
-13
lines changed

8 files changed

+61
-13
lines changed

.github/workflows/cicd.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
14+
include:
15+
- {python: '3.12', pypgstac: '0.9.*'}
16+
- {python: '3.12', pypgstac: '0.8.*'}
17+
- {python: '3.11', pypgstac: '0.8.*'}
18+
- {python: '3.9', pypgstac: '0.8.*'}
19+
- {python: '3.8', pypgstac: '0.8.*'}
20+
1521
timeout-minutes: 20
1622

1723
steps:
@@ -22,12 +28,12 @@ jobs:
2228
- name: Setup Python
2329
uses: actions/setup-python@v5
2430
with:
25-
python-version: ${{ matrix.python-version }}
31+
python-version: ${{ matrix.python }}
2632
cache: pip
2733
cache-dependency-path: setup.py
2834

2935
- name: Lint code
30-
if: ${{ matrix.python-version == 3.11 }}
36+
if: ${{ matrix.python == 3.11 }}
3137
run: |
3238
python -m pip install pre-commit
3339
pre-commit run --all-files
@@ -39,6 +45,7 @@ jobs:
3945
run: |
4046
python -m pip install --upgrade pip
4147
python -m pip install .[dev,server]
48+
python -m pip install "pypgstac==${{ matrix.pypgstac }}"
4249
4350
- name: Run test suite
4451
run: python -m pytest --cov stac_fastapi.pgstac --cov-report xml --cov-report term-missing

.github/workflows/packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
images: ghcr.io/stac-utils/stac-fastapi-pgstac
3030
- name: Build and push Docker image
31-
uses: docker/build-push-action@v6.7.0
31+
uses: docker/build-push-action@v6.9.0
3232
with:
3333
context: .
3434
file: Dockerfile

CHANGES.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
## [Unreleased]
44

55
- Fix Docker compose file, so example data can be loaded into database (author @zstatmanweil, <https://github.com/stac-utils/stac-fastapi-pgstac/pull/142>)
6+
- Handle `next` and `dev` tokens now returned as links from pgstac>=0.9.0 (author @zstatmanweil, https://github.com/stac-utils/stac-fastapi-pgstac/pull/140)
67
- Add collection search extension ([#139](https://github.com/stac-utils/stac-fastapi-pgstac/pull/139))
78
- keep `/search` and `/collections` extensions separate ([#158](https://github.com/stac-utils/stac-fastapi-pgstac/pull/158))
89
- Fix `filter` extension implementation in `CoreCrudClient`
10+
- update `pypgstac` requirement to `>=0.8,<0.10`
11+
- set `pypgstac==0.9.*` for test requirements
12+
13+
## [3.0.1] - 2024-11-14
14+
- Enable runtime `CORS` configuration using environment variables (`CORS_ORIGIN="https://...,https://..."`, `CORS_METHODS="PUT,OPTIONS"`) (https://github.com/stac-utils/stac-fastapi-pgstac/pull/168)
915

1016
## [3.0.0] - 2024-08-02
1117

@@ -338,7 +344,8 @@ As a part of this release, this repository was extracted from the main
338344

339345
- First PyPi release!
340346

341-
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.0..main>
347+
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.1..main>
348+
[3.0.1]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.0..3.0.1>
342349
[3.0.0]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/2.5.0..3.0.0>
343350
[2.5.0]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/2.4.11..2.5.0>
344351
[2.4.11]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/2.4.10..2.4.11>

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ services:
4646

4747
database:
4848
container_name: stac-db
49-
image: ghcr.io/stac-utils/pgstac:v0.8.5
49+
image: ghcr.io/stac-utils/pgstac:v0.9.1
5050
environment:
5151
- POSTGRES_USER=username
5252
- POSTGRES_PASSWORD=password

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
"buildpg",
1818
"brotli_asgi",
1919
"pygeofilter>=0.2",
20-
"pypgstac==0.8.*",
20+
"pypgstac>=0.8,<0.10",
2121
]
2222

2323
extra_reqs = {
2424
"dev": [
2525
"pystac[validation]",
26-
"pypgstac[psycopg]==0.8.*",
26+
"pypgstac[psycopg]==0.9.*",
2727
"pytest-postgresql",
2828
"pytest",
2929
"pytest-cov",
30-
"pytest-asyncio>=0.17,<0.23.0",
30+
"pytest-asyncio>=0.17,<0.25.0",
3131
"pre-commit",
3232
"requests",
3333
"shapely",
@@ -36,7 +36,7 @@
3636
"wheel",
3737
],
3838
"docs": ["mkdocs", "mkdocs-material", "pdocs"],
39-
"server": ["uvicorn[standard]==0.19.0"],
39+
"server": ["uvicorn[standard]==0.32.0"],
4040
"awslambda": ["mangum"],
4141
}
4242

stac_fastapi/pgstac/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
import os
99

10+
from brotli_asgi import BrotliMiddleware
1011
from fastapi.responses import ORJSONResponse
1112
from stac_fastapi.api.app import StacApi
13+
from stac_fastapi.api.middleware import CORSMiddleware, ProxyHeaderMiddleware
1214
from stac_fastapi.api.models import (
1315
EmptyRequest,
1416
ItemCollectionUri,
@@ -26,6 +28,7 @@
2628
)
2729
from stac_fastapi.extensions.core.collection_search import CollectionSearchExtension
2830
from stac_fastapi.extensions.third_party import BulkTransactionExtension
31+
from starlette.middleware import Middleware
2932

3033
from stac_fastapi.pgstac.config import Settings
3134
from stac_fastapi.pgstac.core import CoreCrudClient
@@ -111,6 +114,15 @@
111114
search_get_request_model=get_request_model,
112115
search_post_request_model=post_request_model,
113116
collections_get_request_model=collections_get_request_model,
117+
middlewares=[
118+
Middleware(BrotliMiddleware),
119+
Middleware(ProxyHeaderMiddleware),
120+
Middleware(
121+
CORSMiddleware,
122+
allow_origins=settings.cors_origins,
123+
allow_methods=settings.cors_methods,
124+
),
125+
],
114126
)
115127
app = api.app
116128

stac_fastapi/pgstac/config.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List, Type
44
from urllib.parse import quote_plus as quote
55

6-
from pydantic import BaseModel
6+
from pydantic import BaseModel, field_validator
77
from pydantic_settings import SettingsConfigDict
88
from stac_fastapi.types.config import ApiSettings
99

@@ -75,8 +75,21 @@ class Settings(ApiSettings):
7575
base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache
7676
invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
7777

78+
cors_origins: str = "*"
79+
cors_methods: str = "GET,POST,OPTIONS"
80+
7881
testing: bool = False
7982

83+
@field_validator("cors_origins")
84+
def parse_cors_origin(cls, v):
85+
"""Parse CORS origins."""
86+
return [origin.strip() for origin in v.split(",")]
87+
88+
@field_validator("cors_methods")
89+
def parse_cors_methods(cls, v):
90+
"""Parse CORS methods."""
91+
return [method.strip() for method in v.split(",")]
92+
8093
@property
8194
def reader_connection_string(self):
8295
"""Create reader psql connection string."""

stac_fastapi/pgstac/core.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,17 @@ async def _search_base( # noqa: C901
252252
f"Datetime parameter {search_request.datetime} is invalid."
253253
) from e
254254

255-
next: Optional[str] = items.pop("next", None)
256-
prev: Optional[str] = items.pop("prev", None)
255+
# Starting in pgstac 0.9.0, the `next` and `prev` tokens are returned in spec-compliant links with method GET
256+
next_from_link: Optional[str] = None
257+
prev_from_link: Optional[str] = None
258+
for link in items.get("links", []):
259+
if link.get("rel") == "next":
260+
next_from_link = link.get("href").split("token=next:")[1]
261+
if link.get("rel") == "prev":
262+
prev_from_link = link.get("href").split("token=prev:")[1]
263+
264+
next: Optional[str] = items.pop("next", next_from_link)
265+
prev: Optional[str] = items.pop("prev", prev_from_link)
257266
collection = ItemCollection(**items)
258267

259268
fields = getattr(search_request, "fields", None)

0 commit comments

Comments
 (0)