config.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = "api.ptt.cx"
  10. SERVER_HOST: AnyHttpUrl = "https://api.ptt.cx"
  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] = ['http://localhost']
  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 = "Ark Backend"
  23. SENTRY_DSN: Optional[HttpUrl] = ""
  24. IMG_PATH: str = "/var/www/ArkCard-Linebot/ArkCard-web/img/nft/"
  25. IMG_HOST: AnyHttpUrl = "https://ark.cards/img/nft/"
  26. @validator("SENTRY_DSN", pre=True)
  27. def sentry_dsn_can_be_blank(cls, v: str) -> Optional[str]:
  28. if len(v) == 0:
  29. return None
  30. return v
  31. SQLALCHEMY_DATABASE_URI = "mysql+pymysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4"
  32. # POSTGRES_SERVER: str
  33. # POSTGRES_USER: str
  34. # POSTGRES_PASSWORD: str
  35. # POSTGRES_DB: str
  36. # SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None
  37. # @validator("SQLALCHEMY_DATABASE_URI", pre=True)
  38. # def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
  39. # if isinstance(v, str):
  40. # return v
  41. # return PostgresDsn.build(
  42. # scheme="postgresql",
  43. # user=values.get("POSTGRES_USER"),
  44. # password=values.get("POSTGRES_PASSWORD"),
  45. # host=values.get("POSTGRES_SERVER"),
  46. # path=f"/{values.get('POSTGRES_DB') or ''}",
  47. # )
  48. SMTP_TLS: bool = True
  49. SMTP_PORT: Optional[int] = 465
  50. SMTP_HOST: Optional[str] = 'smtp.gmail.com'
  51. SMTP_USER: Optional[str] = ''
  52. SMTP_PASSWORD: Optional[str] = 'ckmspyijofyavuwg'
  53. EMAILS_FROM_EMAIL: Optional[EmailStr] = 'verify@choozmo.com'
  54. EMAILS_FROM_NAME: Optional[str] = 'Choozmo Team'
  55. @validator("EMAILS_FROM_NAME")
  56. def get_project_name(cls, v: Optional[str], values: Dict[str, Any]) -> str:
  57. if not v:
  58. return values["PROJECT_NAME"]
  59. return v
  60. EMAIL_RESET_TOKEN_EXPIRE_HOURS: int = 48
  61. EMAIL_TEMPLATES_DIR: str = "/home/conrad/creator/app/email-templates/build"
  62. # EMAIL_TEMPLATES_DIR: str = "/app/app/email-templates/build"
  63. EMAILS_ENABLED: bool = True
  64. @validator("EMAILS_ENABLED", pre=True)
  65. def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool:
  66. return bool(
  67. values.get("SMTP_HOST")
  68. and values.get("SMTP_PORT")
  69. and values.get("EMAILS_FROM_EMAIL")
  70. )
  71. EMAIL_TEST_USER: EmailStr = "conradlan@choozmo.com" # type: ignore
  72. FIRST_SUPERUSER: EmailStr = "conradlan@choozmo.com"
  73. FIRST_SUPERUSER_PASSWORD: str = "test123"
  74. USERS_OPEN_REGISTRATION: bool = True
  75. class Config:
  76. case_sensitive = True
  77. settings = Settings()