Server: basic implementation. Not tested => no python installed; bugfix in ESP (uvicorn on port 8090)

This commit is contained in:
Thomas Karner committed 2026-09-20 23:49:40 +02:00
1 parent 3694cdf207
commit 8a51e3d95e
38 files changed
+2442 -21

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
"""Configuration.
Every value comes from the environment (TODO.md Phase 1.2). Nothing is read
from a committed config file, and no path, host or secret is baked into code.
systemd supplies these via ``EnvironmentFile=/etc/poorbird/poorbird.env``; for
local development a ``.env`` in the working directory is picked up as well.
"""
from __future__ import annotations
from functools import lru_cache
from pathlib import Path
from typing import Literal
from pydantic import SecretStr
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_prefix="POORBIRD_",
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
# --- database ---------------------------------------------------------
# Loopback TCP with scram-sha-256, deliberately not a Unix socket: a socket
# is the one genuinely container-hostile choice (TODO.md Phase 1.2).
database_url: str = "postgresql+psycopg://poorbird:poorbird@127.0.0.1:5432/poorbird"
db_pool_size: int = 5
db_echo: bool = False
# --- http -------------------------------------------------------------
api_host: str = "127.0.0.1"
api_port: int = 8080
# --- storage ----------------------------------------------------------
# A small number of explicit top-level directories, never scattered under
# the app dir: these are the future volume mounts.
#
# image_root is the single source of truth for the image path. Caddy reads
# the same value, because the auth-checked handoff (SPEC 3.3) needs the app
# and the proxy to agree on where the bytes live.
image_root: Path = Path("/srv/poorbird/images")
thumb_root: Path = Path("/srv/poorbird/thumbs")
state_dir: Path = Path("/var/lib/poorbird")
# --- devices ----------------------------------------------------------
# Shared bootstrap secret presented by a device in X-Enroll-Secret.
# See firmware/API.md: do NOT rotate this without shipping new firmware,
# or you remove the last-resort recovery path for a mounted camera.
enroll_secret: SecretStr = SecretStr("")
# --- worker -----------------------------------------------------------
worker_poll_interval_s: float = 2.0
worker_batch_size: int = 1
job_max_attempts: int = 3
# --- logging ----------------------------------------------------------
# Always to stdout/stderr. journald catches it now; a log driver would
# catch it later. Never app-managed log files.
log_level: str = "INFO"
log_format: Literal["text", "json"] = "text"
@property
def enroll_secret_is_set(self) -> bool:
return bool(self.enroll_secret.get_secret_value())
def storage_paths(self) -> list[Path]:
return [self.image_root, self.thumb_root, self.state_dir]
@lru_cache
def get_settings() -> Settings:
return Settings()