Skip to content

Commit

Permalink
Add logging variable to app
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed May 10, 2024
1 parent 334069c commit 39d43f7
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions tad/core/config.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
import secrets
import warnings
from typing import Annotated, Any, Literal, TypeVar
from typing import Any, TypeVar

from pydantic import (
AnyUrl,
BeforeValidator,
computed_field,
model_validator,
)
from pydantic_core import MultiHostUrl
from pydantic_settings import BaseSettings, SettingsConfigDict

from tad.core.exceptions import SettingsError
from tad.core.types import DatabaseSchemaType, EnvironmentType, LoggingLevelType

# Self type is not available in Python 3.10 so create our own with TypeVar
SelfSettings = TypeVar("SelfSettings", bound="Settings")


def parse_cors(v: Any) -> list[str] | str:
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, list | str):
return v
raise ValueError(v)


class Settings(BaseSettings):
# todo(berry): investigate yaml, toml or json file support for SettingsConfigDict
model_config = SettingsConfigDict(env_file=".env", env_ignore_empty=True, extra="ignore")
SECRET_KEY: str = secrets.token_urlsafe(32)

DOMAIN: str = "localhost"
ENVIRONMENT: Literal["local", "staging", "production"] = "local"
ENVIRONMENT: EnvironmentType = "local"

@computed_field # type: ignore[misc]
@property
Expand All @@ -40,16 +31,18 @@ def server_host(self) -> str:
return f"http://{self.DOMAIN}"
return f"https://{self.DOMAIN}"

BACKEND_CORS_ORIGINS: Annotated[list[AnyUrl] | str, BeforeValidator(parse_cors)] = []
VERSION: str = "0.1.0"

LOGGING_LEVEL: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"
LOGGING_LEVEL: LoggingLevelType = "INFO"
LOGGING_CONFIG: dict[str, Any] | None = None

PROJECT_NAME: str = "TAD"
PROJECT_DESCRIPTION: str = "Transparency of Algorithmic Decision making"

STATIC_DIR: str = "tad/static"

# todo(berry): create submodel for database settings
APP_DATABASE_SCHEME: Literal["sqlite", "postgresql", "mysql", "oracle"] = "sqlite"
APP_DATABASE_SCHEME: DatabaseSchemaType = "sqlite"
APP_DATABASE_SERVER: str = "db"
APP_DATABASE_PORT: int = 5432
APP_DATABASE_USER: str = "tad"
Expand Down

0 comments on commit 39d43f7

Please sign in to comment.