Skip to content

Commit

Permalink
Configurable server_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
drnextgis committed Mar 22, 2024
1 parent a1b0633 commit 9f69b33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 15 additions & 0 deletions stac_fastapi/pgstac/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Type
from urllib.parse import quote

from pydantic import BaseModel, Extra
from stac_fastapi.types.config import ApiSettings

from stac_fastapi.pgstac.types.base_item_cache import (
Expand Down Expand Up @@ -32,6 +33,13 @@
]


class ServerSettings(BaseModel, extra=Extra.allow):
"""Server runtime parameters."""

search_path: str = "pgstac,public"
application_name: str = "pgstac"


class Settings(ApiSettings):
"""Postgres-specific API settings.
Expand All @@ -58,6 +66,8 @@ class Settings(ApiSettings):
db_max_queries: int = 50000
db_max_inactive_conn_lifetime: float = 300

server_settings: ServerSettings = ServerSettings()

use_api_hydrate: bool = False
base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache
invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
Expand All @@ -78,3 +88,8 @@ def writer_connection_string(self):
def testing_connection_string(self):
"""Create testing psql connection string."""
return f"postgresql://{self.postgres_user}:{quote(self.postgres_pass)}@{self.postgres_host_writer}:{self.postgres_port}/pgstactestdb"

class Config(ApiSettings.Config):
"""Model config."""

env_nested_delimiter = "__"
5 changes: 1 addition & 4 deletions stac_fastapi/pgstac/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ async def create_pool(self, connection_string: str, settings):
max_queries=settings.db_max_queries,
max_inactive_connection_lifetime=settings.db_max_inactive_conn_lifetime,
init=con_init,
server_settings={
"search_path": "pgstac,public",
"application_name": "pgstac",
},
server_settings=settings.server_settings.dict(),
)
return pool

0 comments on commit 9f69b33

Please sign in to comment.