init: new structure + fix lint errors
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
# App
|
||||
debug: bool = Field(default=True, alias="DEBUG")
|
||||
cors_allowed_origins: list[str] = Field(
|
||||
default_factory=lambda: ["http://localhost:3000", "http://localhost:8000"],
|
||||
alias="CORS_ALLOWED_ORIGINS",
|
||||
)
|
||||
|
||||
# JWT
|
||||
jwt_secret_key: str = Field(default="dev-secret", alias="JWT_SECRET_KEY")
|
||||
jwt_algorithm: str = Field(default="HS256", alias="JWT_ALGORITHM")
|
||||
jwt_access_ttl_minutes: int = Field(default=60, alias="JWT_ACCESS_TTL_MINUTES")
|
||||
jwt_refresh_ttl_days: int = Field(default=30, alias="JWT_REFRESH_TTL_DAYS")
|
||||
|
||||
# DB
|
||||
postgres_user: str = Field(default="postgres", alias="POSTGRES_USER")
|
||||
postgres_password: str = Field(default="postgres", alias="POSTGRES_PASSWORD")
|
||||
postgres_host: str = Field(default="localhost", alias="POSTGRES_HOST")
|
||||
postgres_port: int = Field(default=5332, alias="POSTGRES_PORT")
|
||||
postgres_database: str = Field(
|
||||
default="coffee_project_db", alias="POSTGRES_DATABASE"
|
||||
)
|
||||
|
||||
database_url: str | None = Field(default=None, alias="DATABASE_URL")
|
||||
|
||||
# Storage
|
||||
storage_backend: str = Field(default="S3", alias="STORAGE_BACKEND")
|
||||
|
||||
s3_access_key: str | None = Field(default=None, alias="S3_ACCESS_KEY")
|
||||
s3_secret_key: str | None = Field(default=None, alias="S3_SECRET_KEY")
|
||||
s3_bucket_name: str = Field(default="coffee-bucket", alias="S3_BUCKET_NAME")
|
||||
|
||||
# Internal endpoint is used by the API container to talk to MinIO/S3.
|
||||
s3_endpoint_url_internal: str | None = Field(
|
||||
default=None, alias="S3_ENDPOINT_URL_INTERNAL"
|
||||
)
|
||||
# Public endpoint is only used to generate browser-accessible URLs.
|
||||
s3_endpoint_url_public: str | None = Field(
|
||||
default=None, alias="S3_ENDPOINT_URL_PUBLIC"
|
||||
)
|
||||
|
||||
s3_presign_expires_seconds: int = Field(default=3600, alias="S3_PRESIGN_EXPIRES")
|
||||
|
||||
local_storage_dir: Path = Field(
|
||||
default=Path("./.local_storage"), alias="LOCAL_STORAGE_DIR"
|
||||
)
|
||||
|
||||
# External services
|
||||
remotion_service_url: str = Field(
|
||||
default="http://localhost:8001", alias="REMOTION_SERVICE_URL"
|
||||
)
|
||||
|
||||
transcription_models_dir: Path = Field(
|
||||
default=Path("./.artifacts/Models/transcription"),
|
||||
alias="TRANSCRIPTION_MODELS_DIR",
|
||||
)
|
||||
|
||||
google_service_key_path: Path = Field(
|
||||
default=Path("./.s_data/keyapispeech.json"),
|
||||
alias="GOOGLE_APPLICATION_CREDENTIALS",
|
||||
)
|
||||
|
||||
def get_database_url(self) -> str:
|
||||
if self.database_url:
|
||||
return self.database_url
|
||||
return (
|
||||
f"postgresql+asyncpg://{self.postgres_user}:{self.postgres_password}"
|
||||
f"@{self.postgres_host}:{self.postgres_port}/{self.postgres_database}"
|
||||
)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
Reference in New Issue
Block a user