Skip to content

Commit 32dbb7e

Browse files
authored
Merge branch 'master' into add-nginx-container
2 parents 114154a + 15b21b0 commit 32dbb7e

File tree

16 files changed

+256
-59
lines changed

16 files changed

+256
-59
lines changed

.github/workflows/cicd.yaml

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
name: stac-fastapi
22
on:
33
push:
4-
branches: [ master ]
4+
branches: [master]
55
pull_request:
6-
branches: [ master ]
6+
branches: [master]
77

88
jobs:
99
test:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: [ '3.8', '3.9', '3.10']
13+
python-version: ["3.8", "3.9", "3.10"]
1414
timeout-minutes: 10
1515

1616
services:
1717
db_service:
18-
image: bitner/pgstac:0.2.7
18+
image: ghcr.io/stac-utils/pgstac:v0.6.12
1919
env:
2020
POSTGRES_USER: username
2121
POSTGRES_PASSWORD: password
2222
POSTGRES_DB: postgis
2323
POSTGRES_HOST: localhost
2424
POSTGRES_PORT: 5432
25+
PGUSER: username
26+
PGPASSWORD: password
27+
PGDATABASE: postgis
2528
ALLOW_IP_RANGE: 0.0.0.0/0
2629
# Set health checks to wait until postgres has started
2730
options: >-
@@ -118,9 +121,69 @@ jobs:
118121
POSTGRES_HOST_READER: localhost
119122
POSTGRES_HOST_WRITER: localhost
120123
POSTGRES_PORT: 5432
124+
125+
validate:
126+
runs-on: ubuntu-latest
127+
strategy:
128+
fail-fast: false
129+
matrix:
130+
backend: ["sqlalchemy", "pgstac"]
131+
services:
132+
pgstac:
133+
image: ghcr.io/stac-utils/pgstac:v0.6.11
134+
env:
135+
POSTGRES_USER: username
136+
POSTGRES_PASSWORD: password
137+
POSTGRES_DB: postgis
138+
PGUSER: username
139+
PGPASSWORD: password
140+
PGDATABASE: postgis
141+
options: >-
142+
--health-cmd pg_isready
143+
--health-interval 10s
144+
--health-timeout 5s
145+
--health-retries 5
146+
ports:
147+
- 5432:5432
148+
steps:
149+
- name: Check out repository code
150+
uses: actions/checkout@v3
151+
- name: Setup Python
152+
uses: actions/setup-python@v3
153+
with:
154+
python-version: "3.10"
155+
cache: pip
156+
cache-dependency-path: stac_fastapi/pgstac/setup.cfg
157+
- name: Install stac-fastapi and stac-api-validator
158+
run: pip install ./stac_fastapi/api ./stac_fastapi/types ./stac_fastapi/${{ matrix.backend }}[server] stac-api-validator==0.4.1
159+
- name: Run migration
160+
if: ${{ matrix.backend == 'sqlalchemy' }}
161+
run: cd stac_fastapi/sqlalchemy && alembic upgrade head
162+
env:
163+
POSTGRES_USER: username
164+
POSTGRES_PASS: password
165+
POSTGRES_DBNAME: postgis
166+
POSTGRES_HOST: localhost
167+
POSTGRES_PORT: 5432
168+
- name: Load data and validate
169+
run: python -m stac_fastapi.${{ matrix.backend }}.app & ./scripts/wait-for-it.sh localhost:8080 && python ./scripts/ingest_joplin.py http://localhost:8080 && ./scripts/validate http://localhost:8080
170+
env:
171+
POSTGRES_USER: username
172+
POSTGRES_PASS: password
173+
POSTGRES_DBNAME: postgis
174+
POSTGRES_HOST_READER: localhost
175+
POSTGRES_HOST_WRITER: localhost
176+
POSTGRES_PORT: 5432
177+
PGUSER: username
178+
PGPASSWORD: password
179+
PGHOST: localhost
180+
PGDATABASE: postgis
181+
APP_HOST: 0.0.0.0
182+
APP_PORT: 8080
183+
121184
test-docs:
122185
runs-on: ubuntu-latest
123186
steps:
124187
- uses: actions/checkout@v3
125188
- name: Test generating docs
126-
run: make docs
189+
run: make docs

CHANGES.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# Changelog
22

3-
## Unreleased
3+
## [Unreleased]
44

55
### Added
66

77
### Changed
88

9+
* Updated CI to test against [pgstac v0.6.12](https://github.com/stac-utils/pgstac/releases/tag/v0.6.12) ([#511](https://github.com/stac-utils/stac-fastapi/pull/511))
10+
911
### Removed
1012

1113
### Fixed
1214

13-
## [2.4.3]
15+
* Allow url encoded values for `query` in GET requests ([#504](https://github.com/stac-utils/stac-fastapi/pull/504))
16+
* Fix path in `register_update_item` docstring ([507](https://github.com/stac-utils/stac-fastapi/pull/507))
17+
18+
## [2.4.3] - 2022-11-25
1419

1520
### Added
1621

@@ -22,8 +27,7 @@
2227

2328
### Fixed
2429

25-
26-
## [2.4.2]
30+
## [2.4.2] - 2022-11-25
2731

2832
### Added
2933

@@ -44,7 +48,7 @@
4448
* Fix pgstac backend for /queryables endpoint to return 404 for non-existent collections ([#482](https://github.com/stac-utils/stac-fastapi/pull/482))
4549
* `/collection/{collection_id}/items` endpoints now return geojson media type ([#488](https://github.com/stac-utils/stac-fastapi/pull/488))
4650

47-
## [2.4.1]
51+
## [2.4.1] - 2022-08-05
4852

4953
### Added
5054

@@ -56,7 +60,7 @@
5660

5761
* `ciso8601` fails to build in some environments, instead use `pyiso8601` to parse datetimes.
5862

59-
## [2.4.0]
63+
## [2.4.0] - 2022-08-04
6064

6165
### Added
6266

@@ -102,7 +106,7 @@
102106
* PGStac Backend Transactions endpoints return added Item/Collection instead of Item/Collection from request ([#424](https://github.com/stac-utils/stac-fastapi/pull/424))
103107
* Application no longer breaks on startup when pagination extension is not included ([#444](https://github.com/stac-utils/stac-fastapi/pull/444))
104108

105-
## [2.3.0]
109+
## [2.3.0] - 2022-01-18
106110

107111
### Added
108112

@@ -135,7 +139,7 @@
135139
* Expanded on tests to ensure properly testing get and post searches ([#318](https://github.com/stac-utils/stac-fastapi/pull/318))
136140
* Ensure invalid datetimes result in 400s ([#323](https://github.com/stac-utils/stac-fastapi/pull/323))
137141

138-
## [2.2.0]
142+
## [2.2.0] - 2021-10-19
139143

140144
### Added
141145

@@ -148,7 +152,7 @@
148152
* Update pgstac to 0.4.0 ([#308](https://github.com/stac-utils/stac-fastapi/pull/308))
149153
* Update get_item in sqlalchemy backend to allow for querying for items with same ids but in different collections. ([#275](https://github.com/stac-utils/stac-fastapi/pull/275))
150154

151-
## [2.1.1]
155+
## [2.1.1] - 2021-09-23
152156

153157
### Added
154158

@@ -165,7 +169,7 @@
165169
* Add `stac_version` to default search attributes ([#268](https://github.com/stac-utils/stac-fastapi/pull/268))
166170
* pgstac backend specifies collection_id when fetching a single item ([#279](https://github.com/stac-utils/stac-fastapi/pull/270))
167171

168-
## [2.1.0]
172+
## [2.1.0] - 2021-08-26
169173

170174
### Added
171175

@@ -195,17 +199,13 @@
195199
* Correct response codes for bad/unusable bboxes ([#235](https://github.com/stac-utils/stac-fastapi/pull/235))
196200
* Update pgstac to return 400 on invalid date parameter ([#240](https://github.com/stac-utils/stac-fastapi/pull/240))
197201

198-
## [2.0.0]
199-
200-
_2021-07_
202+
## [2.0.0] - 2021-07-26
201203

202204
* Refactor stac-fastapi into submodules ([#106](https://github.com/)stac-utils/stac-fastapi/pull/106)
203205
* Add pgstac backend ([#126](https://github.com/stac-utils/stac-fastapi/pull/126))
204206
* Upgrade to stac-pydantic 2.0.0 and stac-spec 1.0.0 ([#181](https://github.com/stac-utils/stac-fastapi/pull/181))
205207

206-
## [1.1.0]
207-
208-
_2021-01-28_
208+
## [1.1.0] - 2021-01-28
209209

210210
* Improve how the library declares API extensions ([#54](https://github.com/stac-utils/arturo-stac-api/pull/54))
211211
* Add postgres bulk transactions client ([#59](https://github.com/stac-utils/arturo-stac-api/pull/59))
@@ -214,12 +214,16 @@ _2021-01-28_
214214
* Remove postgres database connection from API layer ([#74](https://github.com/stac-utils/arturo-stac-api/pull/74))
215215
* Fix `pre-commit` config ([#75](https://github.com/stac-utils/arturo-stac-api/pull/75))
216216

217-
## [1.0.0]
218-
219-
_2020-09-25_
217+
## [1.0.0] - 2020-09-28
220218

221219
* First PyPi release!
222220

221+
[Unreleased]: <https://github.com/stac-utils/stac-fastapi/compare/2.4.3..master>
222+
[2.4.3]: <https://github.com/stac-utils/stac-fastapi/compare/2.4.2..2.4.3>
223+
[2.4.2]: <https://github.com/stac-utils/stac-fastapi/compare/2.4.1..2.4.2>
224+
[2.4.1]: <https://github.com/stac-utils/stac-fastapi/compare/2.4.0..2.4.1>
225+
[2.4.0]: <https://github.com/stac-utils/stac-fastapi/compare/2.3.0..2.4.0>
226+
[2.3.0]: <https://github.com/stac-utils/stac-fastapi/compare/2.2.0..2.3.0>
223227
[2.2.0]: <https://github.com/stac-utils/stac-fastapi/compare/2.1.1..2.2.0>
224228
[2.1.1]: <https://github.com/stac-utils/stac-fastapi/compare/2.1.0..2.1.1>
225229
[2.1.0]: <https://github.com/stac-utils/stac-fastapi/compare/2.1.0..main>

docker-compose.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ services:
3838
- ./scripts:/app/scripts
3939
depends_on:
4040
- database
41-
command:
42-
bash -c "./scripts/wait-for-it.sh database:5432 && python -m stac_fastapi.sqlalchemy.app"
41+
command: bash -c "./scripts/wait-for-it.sh database:5432 && python -m stac_fastapi.sqlalchemy.app"
4342

4443
app-pgstac:
4544
container_name: stac-fastapi-pgstac
@@ -71,12 +70,11 @@ services:
7170
- ./scripts:/app/scripts
7271
depends_on:
7372
- database
74-
command:
75-
bash -c "./scripts/wait-for-it.sh database:5432 && python -m stac_fastapi.pgstac.app"
73+
command: bash -c "./scripts/wait-for-it.sh database:5432 && python -m stac_fastapi.pgstac.app"
7674

7775
database:
7876
container_name: stac-db
79-
image: ghcr.io/stac-utils/pgstac:v0.6.10
77+
image: ghcr.io/stac-utils/pgstac:v0.6.12
8078
environment:
8179
- POSTGRES_USER=username
8280
- POSTGRES_PASSWORD=password

scripts/validate

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Validate a STAC server using [stac-api-validator](https://github.com/stac-utils/stac-api-validator).
4+
#
5+
# Assumptions:
6+
#
7+
# - You have stac-api-validator installed, e.g. via `pip install stac-api-validator`
8+
# - You've loaded the joplin data, probably using `python ./scripts/ingest_joplin.py http://localhost:8080``
9+
#
10+
# Currently, item-search is not checked, because it crashes stac-api-validator (probably a problem on our side).
11+
12+
set -e
13+
14+
if [ $# -eq 0 ]; then
15+
root_url=http://localhost:8080
16+
else
17+
root_url="$1"
18+
fi
19+
geometry='{"type":"Polygon","coordinates":[[[-94.6884155,37.0595608],[-94.6884155,37.0332547],[-94.6554565,37.0332547],[-94.6554565,37.0595608],[-94.6884155,37.0595608]]]}'
20+
21+
stac-api-validator --root-url "$root_url" \
22+
--conformance core \
23+
--conformance collections \
24+
--conformance features \
25+
--conformance filter \
26+
--collection joplin \
27+
--geometry "$geometry"
28+
# --conformance item-search # currently breaks stac-api-validator

stac_fastapi/api/stac_fastapi/api/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ def register_get_item(self):
158158
name="Get Item",
159159
path="/collections/{collection_id}/items/{item_id}",
160160
response_model=Item if self.settings.enable_response_models else None,
161-
response_class=self.response_class,
161+
response_class=GeoJSONResponse,
162162
response_model_exclude_unset=True,
163163
response_model_exclude_none=True,
164164
methods=["GET"],
165165
endpoint=create_async_endpoint(
166-
self.client.get_item, ItemUri, self.response_class
166+
self.client.get_item, ItemUri, GeoJSONResponse
167167
),
168168
)
169169

stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def register_create_item(self):
7373
)
7474

7575
def register_update_item(self):
76-
"""Register update item endpoint (PUT /collections/{collection_id}/items)."""
76+
"""Register update item endpoint (PUT /collections/{collection_id}/items/{item_id})."""
7777
self.router.add_api_route(
7878
name="Update Item",
7979
path="/collections/{collection_id}/items/{item_id}",

stac_fastapi/pgstac/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"httpx",
3232
],
3333
"docs": ["mkdocs", "mkdocs-material", "pdocs"],
34-
"server": ["uvicorn[standard]==0.17.0"],
34+
"server": ["uvicorn[standard]==0.17.0.post1"],
3535
"awslambda": ["mangum"],
3636
}
3737

stac_fastapi/pgstac/stac_fastapi/pgstac/core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from datetime import datetime
44
from typing import Any, Dict, List, Optional, Union
5-
from urllib.parse import urljoin
5+
from urllib.parse import unquote_plus, urljoin
66

77
import attr
88
import orjson
@@ -18,7 +18,12 @@
1818
from starlette.requests import Request
1919

2020
from stac_fastapi.pgstac.config import Settings
21-
from stac_fastapi.pgstac.models.links import CollectionLinks, ItemLinks, PagingLinks
21+
from stac_fastapi.pgstac.models.links import (
22+
CollectionLinks,
23+
ItemCollectionLinks,
24+
ItemLinks,
25+
PagingLinks,
26+
)
2227
from stac_fastapi.pgstac.types.search import PgstacSearch
2328
from stac_fastapi.pgstac.utils import filter_fields
2429
from stac_fastapi.types.core import AsyncBaseCoreClient
@@ -286,7 +291,7 @@ async def item_collection(
286291
**clean,
287292
)
288293
item_collection = await self._search_base(req, **kwargs)
289-
links = await CollectionLinks(
294+
links = await ItemCollectionLinks(
290295
collection_id=collection_id, request=kwargs["request"]
291296
).get_links(extra_links=item_collection["links"])
292297
item_collection["links"] = links
@@ -372,7 +377,7 @@ async def get_search(
372377
"bbox": bbox,
373378
"limit": limit,
374379
"token": token,
375-
"query": orjson.loads(query) if query else query,
380+
"query": orjson.loads(unquote_plus(query)) if query else query,
376381
}
377382

378383
if filter:

stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ def link_items(self) -> Dict:
206206
)
207207

208208

209+
@attr.s
210+
class ItemCollectionLinks(CollectionLinksBase):
211+
"""Create inferred links specific to collections."""
212+
213+
def link_self(self) -> Dict:
214+
"""Return the self link."""
215+
return dict(
216+
rel=Relations.self.value,
217+
type=MimeTypes.geojson.value,
218+
href=self.resolve(f"collections/{self.collection_id}/items"),
219+
)
220+
221+
def link_parent(self) -> Dict:
222+
"""Create the `parent` link."""
223+
return self.collection_link(rel=Relations.parent.value)
224+
225+
def link_collection(self) -> Dict:
226+
"""Create the `collection` link."""
227+
return self.collection_link()
228+
229+
209230
@attr.s
210231
class ItemLinks(CollectionLinksBase):
211232
"""Create inferred links specific to items."""

0 commit comments

Comments
 (0)