config.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import secrets
  2. from typing import Any, Dict, List, Optional, Union
  3. from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, PostgresDsn, validator
  4. class Settings(BaseSettings):
  5. API_V1_STR: str = "/api/v1"
  6. SECRET_KEY: str = secrets.token_urlsafe(32)
  7. # 60 minutes * 24 hours * 8 days = 8 days
  8. ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
  9. SERVER_NAME: str = "www.choozmo.com"
  10. SERVER_HOST: AnyHttpUrl = "https://www.choozmo.com" #test
  11. # BACKEND_CORS_ORIGINS is a JSON-formatted list of origins
  12. # e.g: '["http://localhost", "http://localhost:4200", "http://localhost:3000", \
  13. # "http://localhost:8080", "http://local.dockertoolbox.tiangolo.com"]'
  14. BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
  15. @validator("BACKEND_CORS_ORIGINS", pre=True)
  16. def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
  17. if isinstance(v, str) and not v.startswith("["):
  18. return [i.strip() for i in v.split(",")]
  19. elif isinstance(v, (list, str)):
  20. return v
  21. raise ValueError(v)
  22. PROJECT_NAME: str = "creator"
  23. SENTRY_DSN: Optional[HttpUrl] = ""
  24. @validator("SENTRY_DSN", pre=True)
  25. def sentry_dsn_can_be_blank(cls, v: str) -> Optional[str]:
  26. if len(v) == 0:
  27. return None
  28. return v
  29. SQLALCHEMY_DATABASE_URI = "mysql+pymysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4"
  30. # POSTGRES_SERVER: str
  31. # POSTGRES_USER: str
  32. # POSTGRES_PASSWORD: str
  33. # POSTGRES_DB: str
  34. # SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None
  35. # @validator("SQLALCHEMY_DATABASE_URI", pre=True)
  36. # def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
  37. # if isinstance(v, str):
  38. # return v
  39. # return PostgresDsn.build(
  40. # scheme="postgresql",
  41. # user=values.get("POSTGRES_USER"),
  42. # password=values.get("POSTGRES_PASSWORD"),
  43. # host=values.get("POSTGRES_SERVER"),
  44. # path=f"/{values.get('POSTGRES_DB') or ''}",
  45. # )
  46. SMTP_TLS: bool = True
  47. SMTP_PORT: Optional[int] = 465
  48. SMTP_HOST: Optional[str] = 'smtp.gmail.com'
  49. SMTP_USER: Optional[str] = 'verify@choozmo.com'
  50. SMTP_PASSWORD: Optional[str] = 'ckmspyijofyavuwg'
  51. EMAILS_FROM_EMAIL: Optional[EmailStr] = 'verify@choozmo.com'
  52. EMAILS_FROM_NAME: Optional[str] = 'Choozmo Team'
  53. @validator("EMAILS_FROM_NAME")
  54. def get_project_name(cls, v: Optional[str], values: Dict[str, Any]) -> str:
  55. if not v:
  56. return values["PROJECT_NAME"]
  57. return v
  58. EMAIL_RESET_TOKEN_EXPIRE_HOURS: int = 48
  59. EMAIL_TEMPLATES_DIR: str = "/home/conrad/creator/app/email-templates/build"
  60. # EMAIL_TEMPLATES_DIR: str = "/app/app/email-templates/build"
  61. EMAILS_ENABLED: bool = True
  62. @validator("EMAILS_ENABLED", pre=True)
  63. def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool:
  64. return bool(
  65. values.get("SMTP_HOST")
  66. and values.get("SMTP_PORT")
  67. and values.get("EMAILS_FROM_EMAIL")
  68. )
  69. EMAIL_TEST_USER: EmailStr = "conradlan@choozmo.com" # type: ignore
  70. FIRST_SUPERUSER: EmailStr = "conradlan@choozmo.com"
  71. FIRST_SUPERUSER_PASSWORD: str = "test123"
  72. USERS_OPEN_REGISTRATION: bool = True
  73. class Config:
  74. case_sensitive = True
  75. settings = Settings()