From a3ab0d0531cc12cba897e791dc6ee018b17f4d46 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Fri, 21 Mar 2025 09:56:00 +0100 Subject: [PATCH] update tipg version --- .github/workflows/tests/test_vector.py | 6 +- infrastructure/handlers/vector_handler.py | 25 +++++---- runtimes/eoapi/vector/eoapi/vector/app.py | 67 +++++++++-------------- runtimes/eoapi/vector/pyproject.toml | 2 +- 4 files changed, 44 insertions(+), 56 deletions(-) diff --git a/.github/workflows/tests/test_vector.py b/.github/workflows/tests/test_vector.py index 4b21048..cd68cbf 100644 --- a/.github/workflows/tests/test_vector.py +++ b/.github/workflows/tests/test_vector.py @@ -86,11 +86,13 @@ def test_vector_api(): assert item["id"] == "noaa-emergency-response" # OGC Tiles - resp = httpx.get(f"{vector_endpoint}/collections/public.my_data/tiles/0/0/0") + resp = httpx.get( + f"{vector_endpoint}/collections/public.my_data/tiles/WebMercatorQuad/0/0/0" + ) assert resp.status_code == 200 resp = httpx.get( - f"{vector_endpoint}/collections/pg_temp.pgstac_collections_view/tilejson.json" + f"{vector_endpoint}/collections/pg_temp.pgstac_collections_view/tiles/WebMercatorQuad/tilejson.json" ) assert resp.status_code == 200 diff --git a/infrastructure/handlers/vector_handler.py b/infrastructure/handlers/vector_handler.py index e507dba..c93a5dd 100644 --- a/infrastructure/handlers/vector_handler.py +++ b/infrastructure/handlers/vector_handler.py @@ -10,13 +10,22 @@ from mangum import Mangum from tipg.collections import register_collection_catalog from tipg.database import connect_to_db +from tipg.settings import DatabaseSettings logging.getLogger("mangum.lifespan").setLevel(logging.ERROR) logging.getLogger("mangum.http").setLevel(logging.ERROR) CUSTOM_SQL_DIRECTORY = resources_files("eoapi.vector") / "sql" -sql_files = list(CUSTOM_SQL_DIRECTORY.glob("*.sql")) # type: ignore + +db_settings = DatabaseSettings( + # For the Tables' Catalog we only use the `public` schema + schemas=["public"], + # We exclude public functions + exclude_function_schemas=["public"], + # We allow non-spatial tables + spatial=False, +) @app.on_event("startup") @@ -24,20 +33,12 @@ async def startup_event() -> None: """Connect to database on startup.""" await connect_to_db( app, - settings=PostgresSettings(), # We enable both pgstac and public schemas (pgstac will be used by custom functions) schemas=["pgstac", "public"], - user_sql_files=sql_files, - ) - await register_collection_catalog( - app, - # For the Tables' Catalog we only use the `public` schema - schemas=["public"], - # We exclude public functions - exclude_function_schemas=["public"], - # We allow non-spatial tables - spatial=False, + user_sql_files=list(CUSTOM_SQL_DIRECTORY.glob("*.sql")), # type: ignore + settings=PostgresSettings(), ) + await register_collection_catalog(app, db_settings=db_settings) handler = Mangum(app, lifespan="off") diff --git a/runtimes/eoapi/vector/eoapi/vector/app.py b/runtimes/eoapi/vector/eoapi/vector/app.py index a1618f2..e21c147 100644 --- a/runtimes/eoapi/vector/eoapi/vector/app.py +++ b/runtimes/eoapi/vector/eoapi/vector/app.py @@ -15,6 +15,7 @@ from tipg.errors import DEFAULT_STATUS_CODES, add_exception_handlers from tipg.factory import Endpoints as TiPgEndpoints from tipg.middleware import CacheControlMiddleware, CatalogUpdateMiddleware +from tipg.settings import DatabaseSettings from . import __version__ as eoapi_vector_version from .config import ApiSettings, PostgresSettings @@ -24,25 +25,18 @@ settings = ApiSettings() auth_settings = OpenIdConnectSettings() +db_settings = DatabaseSettings( + # For the Tables' Catalog we only use the `public` schema + schemas=["public"], + # We exclude public functions + exclude_function_schemas=["public"], + # We allow non-spatial tables + spatial=False, +) + # Logs -init_logging( - debug=settings.debug, - loggers={ - "botocore.credentials": { - "level": "CRITICAL", - "propagate": False, - }, - "botocore.utils": { - "level": "CRITICAL", - "propagate": False, - }, - "rio-tiler": { - "level": "ERROR", - "propagate": False, - }, - }, -) +init_logging(debug=settings.debug) logger = logging.getLogger(__name__) @@ -52,22 +46,14 @@ async def lifespan(app: FastAPI): logger.debug("Connecting to db...") await connect_to_db( app, - settings=PostgresSettings(), # We enable both pgstac and public schemas (pgstac will be used by custom functions) schemas=["pgstac", "public"], user_sql_files=list(CUSTOM_SQL_DIRECTORY.glob("*.sql")), # type: ignore + settings=PostgresSettings(), ) logger.debug("Registering collection catalog...") - await register_collection_catalog( - app, - # For the Tables' Catalog we only use the `public` schema - schemas=["public"], - # We exclude public functions - exclude_function_schemas=["public"], - # We allow non-spatial tables - spatial=False, - ) + await register_collection_catalog(app, db_settings=db_settings) yield @@ -126,9 +112,7 @@ async def lifespan(app: FastAPI): CatalogUpdateMiddleware, func=register_collection_catalog, ttl=settings.catalog_ttl, - schemas=["public"], - exclude_function_schemas=["public"], - spatial=False, + db_settings=db_settings, ) add_exception_handlers(app, DEFAULT_STATUS_CODES) @@ -143,7 +127,17 @@ async def lifespan(app: FastAPI): ) def ping(): """Health check.""" - return {"ping": "pong!"} + from pyproj import __proj_version__ as proj_version # noqa + from pyproj import __version__ as pyproj_version # noqa + from tipg import __version__ as tipg_version # noqa + + return { + "versions": { + "tipg": tipg_version, + "proj": proj_version, + "pyproj": pyproj_version, + }, + } if settings.debug: @@ -156,16 +150,7 @@ async def raw_catalog(request: Request): @app.get("/refresh", include_in_schema=False) async def refresh(request: Request): """Return parsed catalog data for testing.""" - await register_collection_catalog( - request.app, - # For the Tables' Catalog we only use the `public` schema - schemas=["public"], - # We exclude public functions - exclude_function_schemas=["public"], - # We allow non-spatial tables - spatial=False, - ) - + await register_collection_catalog(request.app, db_settings=db_settings) return request.app.state.collection_catalog diff --git a/runtimes/eoapi/vector/pyproject.toml b/runtimes/eoapi/vector/pyproject.toml index 0e8f88b..3b2aa02 100644 --- a/runtimes/eoapi/vector/pyproject.toml +++ b/runtimes/eoapi/vector/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ ] dynamic = ["version"] dependencies = [ - "tipg==0.9.0", + "tipg==1.0.1", "eoapi.auth-utils>=0.2.0", "boto3" ]