Refine runtime config and redirect settings
This commit is contained in:
+20
-5
@@ -7,10 +7,9 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
class Settings(BaseSettings):
|
||||
app_name: str = "Home Automation Backend (Python)"
|
||||
app_env: str = "development"
|
||||
app_env: str = "production"
|
||||
app_debug: bool = False
|
||||
app_host: str = "0.0.0.0"
|
||||
app_port: int = 8000
|
||||
app_hostname: str = "localhost:8000"
|
||||
app_database_url: str = "sqlite:///./data/app.db"
|
||||
|
||||
location_database_url: str = "sqlite:///./data/locationRecorder.db"
|
||||
@@ -18,7 +17,6 @@ class Settings(BaseSettings):
|
||||
|
||||
ticktick_client_id: str = ""
|
||||
ticktick_client_secret: str = ""
|
||||
ticktick_redirect_uri: str = ""
|
||||
ticktick_token: str = ""
|
||||
|
||||
home_assistant_base_url: str = ""
|
||||
@@ -32,12 +30,13 @@ class Settings(BaseSettings):
|
||||
auth_bootstrap_password: str = "admin"
|
||||
auth_session_cookie_name: str = "home_automation_session"
|
||||
auth_session_ttl_hours: int = 12
|
||||
auth_cookie_secure_override: bool | None = None
|
||||
auth_cookie_secure_override: bool | None = True
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
@computed_field
|
||||
@@ -45,6 +44,22 @@ class Settings(BaseSettings):
|
||||
def is_development(self) -> bool:
|
||||
return self.app_env.lower() == "development"
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def app_base_url(self) -> str:
|
||||
hostname = self.app_hostname.strip().rstrip("/")
|
||||
if not hostname:
|
||||
return ""
|
||||
scheme = "http" if self.is_development else "https"
|
||||
return f"{scheme}://{hostname}"
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def ticktick_redirect_uri(self) -> str:
|
||||
if not self.app_base_url:
|
||||
return ""
|
||||
return f"{self.app_base_url}/ticktick/auth/code"
|
||||
|
||||
@staticmethod
|
||||
def _sqlite_path_from_url(database_url: str) -> Path | None:
|
||||
prefix = "sqlite:///"
|
||||
|
||||
Reference in New Issue
Block a user