Skip to content

Commit ae68e70

Browse files
authored
fix: update tipg startup for 1.0 (#144)
resolves #143
1 parent 6acefbc commit ae68e70

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

Diff for: lib/tipg-api/runtime/src/handler.py

+17-30
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,24 @@
66
import os
77

88
from mangum import Mangum
9+
from tipg.collections import register_collection_catalog
10+
from tipg.database import connect_to_db
11+
from tipg.main import app
12+
from tipg.settings import (
13+
CustomSQLSettings,
14+
DatabaseSettings,
15+
PostgresSettings,
16+
)
917
from utils import get_secret_dict
1018

1119
secret = get_secret_dict(secret_arn_env_var="PGSTAC_SECRET_ARN")
12-
os.environ.update(
13-
{
14-
"postgres_host": secret["host"],
15-
"postgres_dbname": secret["dbname"],
16-
"postgres_user": secret["username"],
17-
"postgres_pass": secret["password"],
18-
"postgres_port": str(secret["port"]),
19-
}
20-
)
21-
22-
from tipg.collections import register_collection_catalog # noqa: E402
23-
from tipg.database import connect_to_db # noqa: E402
24-
25-
# skipping linting rule that wants all imports at the top
26-
from tipg.main import app # noqa: E402
27-
from tipg.settings import (
28-
CustomSQLSettings, # noqa: E402
29-
DatabaseSettings, # noqa: E402
30-
PostgresSettings, # noqa: E402; noqa: E402
20+
postgres_settings = PostgresSettings(
21+
postgres_host=secret["host"],
22+
postgres_dbname=secret["dbname"],
23+
postgres_user=secret["username"],
24+
postgres_pass=secret["password"],
25+
postgres_port=int(secret["port"]),
3126
)
32-
33-
postgres_settings = PostgresSettings()
3427
db_settings = DatabaseSettings()
3528
custom_sql_settings = CustomSQLSettings()
3629

@@ -40,20 +33,14 @@ async def startup_event() -> None:
4033
"""Connect to database on startup."""
4134
await connect_to_db(
4235
app,
43-
settings=postgres_settings,
4436
schemas=db_settings.schemas,
37+
tipg_schema=db_settings.tipg_schema,
4538
user_sql_files=custom_sql_settings.sql_files,
39+
settings=postgres_settings,
4640
)
4741
await register_collection_catalog(
4842
app,
49-
schemas=db_settings.schemas,
50-
tables=db_settings.tables,
51-
exclude_tables=db_settings.exclude_tables,
52-
exclude_table_schemas=db_settings.exclude_table_schemas,
53-
functions=db_settings.functions,
54-
exclude_functions=db_settings.exclude_functions,
55-
exclude_function_schemas=db_settings.exclude_function_schemas,
56-
spatial=db_settings.only_spatial_tables,
43+
db_settings=db_settings,
5744
)
5845

5946

Diff for: lib/titiler-pgstac-api/runtime/src/handler.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@
66
import os
77

88
from mangum import Mangum
9+
from titiler.pgstac.db import connect_to_db
10+
from titiler.pgstac.main import app
11+
from titiler.pgstac.settings import PostgresSettings
912
from utils import get_secret_dict
1013

1114
secret = get_secret_dict(secret_arn_env_var="PGSTAC_SECRET_ARN")
12-
os.environ.update(
13-
{
14-
"postgres_host": secret["host"],
15-
"postgres_dbname": secret["dbname"],
16-
"postgres_user": secret["username"],
17-
"postgres_pass": secret["password"],
18-
"postgres_port": str(secret["port"]),
19-
}
15+
postgres_settings = PostgresSettings(
16+
postgres_host=secret["host"],
17+
postgres_dbname=secret["dbname"],
18+
postgres_user=secret["username"],
19+
postgres_pass=secret["password"],
20+
postgres_port=int(secret["port"]),
2021
)
2122

22-
from titiler.pgstac.db import connect_to_db # noqa: E402
23-
from titiler.pgstac.main import app # noqa: E402
24-
2523

2624
@app.on_event("startup")
2725
async def startup_event() -> None:
2826
"""Connect to database on startup."""
29-
await connect_to_db(app)
27+
await connect_to_db(app, settings=postgres_settings)
3028

3129

3230
handler = Mangum(app, lifespan="off")

0 commit comments

Comments
 (0)