Skip to content

Commit f45c26b

Browse files
authored
feat(release)!: upgrade stac-fastapi (#492)
1 parent f2187e8 commit f45c26b

File tree

4 files changed

+15
-41
lines changed

4 files changed

+15
-41
lines changed

database/runtime/handler.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,6 @@ def create_permissions(cursor, db_name: str, username: str) -> None:
129129
)
130130

131131

132-
def enable_context(cursor) -> None:
133-
"""Enable context extension for actual and estimated matches in item search and associated optimizations."""
134-
cursor.execute(
135-
sql.SQL(
136-
"INSERT INTO pgstac.pgstac_settings (name, value) "
137-
" VALUES "
138-
" ('context', 'auto'),"
139-
" ('context_estimated_count', '100000'),"
140-
" ('context_estimated_cost', '100000'),"
141-
" ('context_stats_ttl', '1 day')"
142-
" ON CONFLICT ON CONSTRAINT pgstac_settings_pkey DO UPDATE SET value = excluded.value;"
143-
)
144-
)
145-
146-
147132
def register_extensions(cursor) -> None:
148133
"""Add PostGIS extension."""
149134
cursor.execute(sql.SQL("CREATE EXTENSION IF NOT EXISTS postgis;"))
@@ -454,15 +439,6 @@ def handler(event, context):
454439
username=user_params["username"],
455440
)
456441

457-
with psycopg.connect(stac_db_conninfo, autocommit=True) as conn:
458-
with conn.cursor() as cur:
459-
print(
460-
"Enabling and configuring item search context in pgstac_settings..."
461-
)
462-
enable_context(
463-
cursor=cur,
464-
)
465-
466442
print("Adding mosaic index...")
467443
with psycopg.connect(
468444
stac_db_admin_dsn,

stac_api/runtime/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
inst_reqs = [
1111
"boto3",
12-
"stac-fastapi.api~=3.0",
13-
"stac-fastapi.types~=3.0",
14-
"stac-fastapi.extensions~=3.0",
15-
"stac-fastapi.pgstac~=3.0",
12+
"stac-fastapi.api~=5.0",
13+
"stac-fastapi.types~=5.0",
14+
"stac-fastapi.extensions~=5.0",
15+
"stac-fastapi.pgstac~=5.0",
1616
"jinja2>=2.11.2,<4.0.0",
1717
"starlette-cramjam>=0.3.2,<0.4",
1818
"importlib_resources>=1.1.0;python_version<='3.11'", # https://github.com/cogeotiff/rio-tiler/pull/379

stac_api/runtime/src/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
@asynccontextmanager
4646
async def lifespan(app: FastAPI):
4747
"""Get a database connection on startup, close it on shutdown."""
48-
await connect_to_db(app)
48+
await connect_to_db(app, postgres_settings=api_settings.postgres_settings)
4949
yield
5050
await close_db_connection(app)
5151

@@ -70,9 +70,9 @@ async def lifespan(app: FastAPI):
7070
),
7171
title=f"{api_settings.project_name} STAC API",
7272
description=api_settings.project_description,
73-
settings=api_settings.load_postgres_settings(),
73+
settings=api_settings,
7474
extensions=PgStacExtensions,
75-
client=VedaCrudClient(post_request_model=POSTModel),
75+
client=VedaCrudClient(pgstac_search_model=POSTModel),
7676
search_get_request_model=GETModel,
7777
search_post_request_model=POSTModel,
7878
items_get_request_model=items_get_request_model,

stac_api/runtime/src/config.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
TransactionExtension,
2929
)
3030
from stac_fastapi.extensions.third_party import BulkTransactionExtension
31-
from stac_fastapi.pgstac.config import Settings
31+
from stac_fastapi.pgstac.config import PostgresSettings, Settings
3232
from stac_fastapi.pgstac.transactions import BulkTransactionsClient, TransactionsClient
3333
from stac_fastapi.pgstac.types.search import PgstacSearch
3434

@@ -57,7 +57,7 @@ def get_secret_dict(secret_name: str):
5757
return json.loads(base64.b64decode(get_secret_value_response["SecretBinary"]))
5858

5959

60-
class _ApiSettings(BaseSettings):
60+
class _ApiSettings(Settings):
6161
"""API settings"""
6262

6363
project_name: Optional[str] = "veda"
@@ -82,22 +82,20 @@ def parse_cors_origin(cls, v):
8282
"""Parse CORS origins."""
8383
return [origin.strip() for origin in v.split(",")]
8484

85-
def load_postgres_settings(self) -> "Settings":
86-
"""Load postgres connection params from AWS secret"""
87-
85+
@property
86+
def postgres_settings(self) -> PostgresSettings:
87+
"""Load postgres connection params from AWS secret."""
8888
if self.pgstac_secret_arn:
8989
secret = get_secret_dict(self.pgstac_secret_arn)
90-
91-
return Settings(
90+
return PostgresSettings(
9291
postgres_host_reader=secret["host"],
9392
postgres_host_writer=secret["host"],
9493
postgres_dbname=secret["dbname"],
9594
postgres_user=secret["username"],
9695
postgres_pass=secret["password"],
9796
postgres_port=secret["port"],
9897
)
99-
else:
100-
return Settings()
98+
return PostgresSettings()
10199

102100
model_config = SettingsConfigDict(
103101
env_file=".env", env_prefix="VEDA_STAC_", extra="ignore"
@@ -159,7 +157,7 @@ def TilesApiSettings() -> _TilesApiSettings:
159157
BulkTransactionExtension(client=BulkTransactionsClient()),
160158
TransactionExtension(
161159
client=TransactionsClient(),
162-
settings=ApiSettings().load_postgres_settings(),
160+
settings=api_settings,
163161
response_class=ORJSONResponse,
164162
),
165163
]

0 commit comments

Comments
 (0)