2020-05-08 04:52:25 +00:00
|
|
|
import secrets
|
2020-10-07 15:18:43 +00:00
|
|
|
|
2020-05-30 18:09:02 +00:00
|
|
|
from typing import Any, Dict, Optional
|
2020-05-08 04:52:25 +00:00
|
|
|
|
2020-10-07 15:18:43 +00:00
|
|
|
from dotenv import load_dotenv
|
2020-05-30 18:09:02 +00:00
|
|
|
from pydantic import BaseSettings, PostgresDsn, validator
|
2020-05-08 04:52:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Settings(BaseSettings):
|
2020-05-30 18:09:02 +00:00
|
|
|
# openssl rand -hex 32
|
2020-05-08 04:52:25 +00:00
|
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
2020-06-30 06:02:09 +00:00
|
|
|
MIDDLEWARE_SECRET_KEY: str = secrets.token_urlsafe(5)
|
2020-05-30 18:09:02 +00:00
|
|
|
ALGORITHM: str = "HS256"
|
|
|
|
JWT_TOKEN_EXPIRE_MINUTES: int = 30
|
|
|
|
HOST: str = "0.0.0.0"
|
|
|
|
PORT: int = 80
|
|
|
|
DEBUG: bool = False
|
|
|
|
LOG_LEVEL: str = "NOTSET"
|
|
|
|
POSTGRES_SERVER: str = ""
|
2020-05-08 04:52:25 +00:00
|
|
|
POSTGRES_USER: str = "postgres"
|
2020-05-30 18:09:02 +00:00
|
|
|
POSTGRES_PASSWORD: str = ""
|
|
|
|
POSTGRES_DB: str = ""
|
|
|
|
SQLALCHEMY_DATABASE_URI: Optional[str] = None
|
2020-05-08 04:52:25 +00:00
|
|
|
|
|
|
|
@validator("SQLALCHEMY_DATABASE_URI", pre=True)
|
|
|
|
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
|
|
|
|
if isinstance(v, str):
|
|
|
|
return v
|
|
|
|
return PostgresDsn.build(
|
|
|
|
scheme="postgresql",
|
|
|
|
user=values.get("POSTGRES_USER"),
|
|
|
|
password=values.get("POSTGRES_PASSWORD"),
|
|
|
|
host=values.get("POSTGRES_SERVER"),
|
|
|
|
path=f"/{values.get('POSTGRES_DB') or ''}",
|
|
|
|
)
|
|
|
|
|
2020-05-30 18:09:02 +00:00
|
|
|
ALEMBIC_LOG_LEVEL: str = "INFO"
|
|
|
|
ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN"
|
|
|
|
|
2020-05-08 04:52:25 +00:00
|
|
|
class Config:
|
|
|
|
case_sensitive = True
|
2020-05-31 09:11:11 +00:00
|
|
|
env_file = ".env"
|
2020-05-08 04:52:25 +00:00
|
|
|
|
|
|
|
|
2020-05-30 18:09:02 +00:00
|
|
|
load_dotenv()
|
2020-05-08 04:52:25 +00:00
|
|
|
settings = Settings()
|