Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 13 additions & 12 deletions infrastructure/handlers/vector_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,35 @@
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")
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")
Expand Down
67 changes: 26 additions & 41 deletions runtimes/eoapi/vector/eoapi/vector/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)


Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion runtimes/eoapi/vector/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"tipg==0.9.0",
"tipg==1.0.1",
"eoapi.auth-utils>=0.2.0",
"boto3"
]
Expand Down