-
Notifications
You must be signed in to change notification settings - Fork 32
update pcstac to use stac-fastapi 5.0 and stac-fastapi-pgstac 4.0 #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8d47cd1
c8d35dd
1b76532
46cb213
08fce89
f2d0f32
f8f318d
97e4cdb
18557cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| APP_ROOT_PATH=/stac | ||
| APP_HOST=0.0.0.0 | ||
| APP_PORT=8081 | ||
| FORWARDED_ALLOW_IPS=* | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,16 @@ | |
| from fastapi import HTTPException, Request | ||
| from stac_fastapi.pgstac.core import CoreCrudClient | ||
| from stac_fastapi.types.errors import NotFoundError | ||
| from stac_fastapi.types.requests import get_base_url | ||
| from stac_fastapi.types.stac import ( | ||
| Collection, | ||
| Collections, | ||
| Item, | ||
| ItemCollection, | ||
| LandingPage, | ||
| ) | ||
| from stac_pydantic.links import Relations | ||
| from stac_pydantic.shared import MimeTypes | ||
|
|
||
| from pccommon.config import get_all_render_configs, get_render_config | ||
| from pccommon.config.collections import DefaultRenderConfig | ||
|
|
@@ -220,7 +223,7 @@ async def _fetch() -> ItemCollection: | |
| search_request.collections is None | ||
| and "collection=" not in str(request.url) | ||
| and '{"property":"collection"}' | ||
| not in orjson.dumps(search_request.filter).decode("utf-8") | ||
| not in orjson.dumps(search_request.filter_expr).decode("utf-8") | ||
| ): | ||
| raise HTTPException(status_code=422, detail="collection is required") | ||
|
|
||
|
|
@@ -238,11 +241,87 @@ async def _fetch() -> ItemCollection: | |
| return await cached_result(_fetch, cache_key, request) | ||
|
|
||
| async def landing_page(self, request: Request, **kwargs: Any) -> LandingPage: | ||
| _super: CoreCrudClient = super() | ||
| """Landing page.""" | ||
|
|
||
| async def _fetch() -> LandingPage: | ||
| landing = await _super.landing_page(request=request, **kwargs) | ||
| return landing | ||
| """Landing page. | ||
|
|
||
| NOTE: we need a custom landing page implementation | ||
| to avoid the call to `all_collections` method. | ||
|
|
||
| TODO: replace this with: | ||
| ``` | ||
| _super: CoreCrudClient = super() | ||
|
|
||
| async def _fetch() -> LandingPage: | ||
| landing = await _super.landing_page(request=request, **kwargs) | ||
| return landing | ||
| ``` | ||
| when switching to stac-fastapi >=v5.1. | ||
|
|
||
| """ | ||
| base_url = get_base_url(request) | ||
|
|
||
| landing_page = self._landing_page( | ||
| base_url=base_url, | ||
| conformance_classes=self.conformance_classes(), | ||
| extension_schemas=[], | ||
| ) | ||
|
|
||
| # Add Queryables link | ||
| if self.extension_is_enabled( | ||
| "FilterExtension" | ||
| ) or self.extension_is_enabled("SearchFilterExtension"): | ||
| landing_page["links"].append( | ||
| { | ||
| "rel": Relations.queryables.value, | ||
| "type": MimeTypes.jsonschema.value, | ||
| "title": "Queryables available for this Catalog", | ||
| "href": urljoin(base_url, "queryables"), | ||
| "method": "GET", | ||
| } | ||
| ) | ||
|
|
||
| # Add Aggregation links | ||
| if self.extension_is_enabled("AggregationExtension"): | ||
| landing_page["links"].extend( | ||
| [ | ||
| { | ||
| "rel": "aggregate", | ||
| "type": "application/json", | ||
| "title": "Aggregate", | ||
| "href": urljoin(base_url, "aggregate"), | ||
| }, | ||
| { | ||
| "rel": "aggregations", | ||
| "type": "application/json", | ||
| "title": "Aggregations", | ||
| "href": urljoin(base_url, "aggregations"), | ||
| }, | ||
| ] | ||
| ) | ||
|
|
||
| # Add OpenAPI URL | ||
| landing_page["links"].append( | ||
| { | ||
| "rel": Relations.service_desc.value, | ||
| "type": MimeTypes.openapi.value, | ||
| "title": "OpenAPI service description", | ||
| "href": str(request.url_for("openapi")), | ||
| } | ||
| ) | ||
|
|
||
| # Add human readable service-doc | ||
| landing_page["links"].append( | ||
| { | ||
| "rel": Relations.service_doc.value, | ||
| "type": MimeTypes.html.value, | ||
| "title": "OpenAPI service documentation", | ||
| "href": str(request.url_for("swagger_ui_html")), | ||
| } | ||
| ) | ||
|
|
||
| return LandingPage(**landing_page) | ||
|
|
||
| return await cached_result(_fetch, CACHE_KEY_LANDING_PAGE, request) | ||
|
|
||
|
|
@@ -303,6 +382,6 @@ def create( | |
| title=API_TITLE, | ||
| description=API_DESCRIPTION, | ||
| extra_conformance_classes=extra_conformance_classes, | ||
| post_request_model=post_request_model, | ||
| pgstac_search_model=post_request_model, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ref: https://github.com/stac-utils/stac-fastapi-pgstac/blob/main/CHANGES.md#400---2025-02-03 |
||
| ) | ||
| return it | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ | |
| client=PCFiltersClient(), | ||
| conformance_classes=[ | ||
| FilterConformanceClasses.FILTER, | ||
| FilterConformanceClasses.ITEM_SEARCH_FILTER, | ||
| FilterConformanceClasses.SEARCH, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ref: renamed filter.FilterConformanceClasses.ITEM_SEARCH_FILTER -> filter.FilterConformanceClasses.SEARCH |
||
| FilterConformanceClasses.BASIC_CQL2, | ||
| FilterConformanceClasses.CQL2_JSON, | ||
| FilterConformanceClasses.CQL2_TEXT, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| from fastapi.exceptions import RequestValidationError, StarletteHTTPException | ||
| from fastapi.openapi.utils import get_openapi | ||
| from fastapi.responses import ORJSONResponse | ||
| from stac_fastapi.api.app import StacApi as PCStacApi | ||
| from stac_fastapi.api.errors import DEFAULT_STATUS_CODES | ||
| from stac_fastapi.api.middleware import ProxyHeaderMiddleware | ||
| from stac_fastapi.api.models import ( | ||
|
|
@@ -29,13 +30,13 @@ | |
| from pccommon.middleware import TraceMiddleware, add_timeout, http_exception_handler | ||
| from pccommon.openapi import fixup_schema | ||
| from pccommon.redis import connect_to_redis | ||
| from pcstac.api import PCStacApi | ||
| from pcstac.client import PCClient | ||
| from pcstac.config import ( | ||
| API_DESCRIPTION, | ||
| API_TITLE, | ||
| API_VERSION, | ||
| EXTENSIONS, | ||
| STAC_API_VERSION, | ||
| get_settings, | ||
| ) | ||
| from pcstac.errors import PC_DEFAULT_STATUS_CODES | ||
|
|
@@ -92,6 +93,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator: | |
| db_min_conn_size=app_settings.db_min_conn_size, | ||
| base_item_cache=RedisBaseItemCache, | ||
| debug=DEBUG, | ||
| root_path=APP_ROOT_PATH, | ||
| ), | ||
| client=PCClient.create(post_request_model=search_post_request_model), | ||
| extensions=EXTENSIONS, | ||
|
|
@@ -148,9 +150,15 @@ def custom_openapi() -> Dict[str, Any]: | |
| return app.openapi_schema | ||
| else: | ||
| schema = get_openapi( | ||
| title="Planetary Computer STAC API", | ||
| title=API_TITLE, | ||
| version=app_settings.api_version, | ||
| routes=app.routes, | ||
| ) | ||
| app.openapi_schema = fixup_schema(app.root_path, schema) | ||
| return schema | ||
| fixed_schema = fixup_schema( | ||
| app.root_path, schema, tag=f"STAC API {STAC_API_VERSION}" | ||
| ) | ||
| app.openapi_schema = fixed_schema | ||
| return fixed_schema | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is maybe the biggest change with this PR that doesn't seem well tested in tests |
||
|
|
||
|
|
||
| app.openapi = custom_openapi # type: ignore | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: https://github.com/stac-utils/stac-fastapi-pgstac/blob/main/CHANGES.md#400---2025-02-03